2012年3月10日 星期六

[ffmpeg] 0.9 版後的新式 interrupt

這次試著更新專案內的 ffmpeg 至最新的 tag 版本 n0.9。發現專案內的『deprecated』比以往更多,但還都是能編譯的狀態。依慣例得確認一下在最新的 source code 裡,那些 deprecated 是真的被移除。於是編了 master branch 上的 code,發現 io interrupt callback 的寫法已經不再相容舊版了。

對於 ffmpeg 文件常跟不上 source code 的狀態,這連 changelog 也沒有記載這件事,我們可以簡單 diff n0.9 與前一版找出改變的部分,能利用一定會用到 io interrupt callback 的 ffmpeg.c 來作 diff:

.
-static int decode_interrupt_cb(void)
+static int decode_interrupt_cb(void *ctx)
{
- q_pressed += read_key() == 'q';
- return q_pressed > 1;
+ return received_nb_signals > 1;
}
-static int ffmpeg_exit(int ret)
+static const AVIOInterruptCB int_cb = { decode_interrupt_cb, NULL };
view raw example.diff hosted with ❤ by GitHub
.

舊式的 io interrupt callback 是一個 global function pointer:
.
// set global callback (old style)
// callback type=> int (*interrupt_cb)(void)
avio_set_interrupt_cb(decode_interrupt_cb);
view raw old-style.c hosted with ❤ by GitHub
.

新式的 io interrupt callback 使用一個 struct 包起來,設定在各別的 AVFormatContext:
.
// set callback to AVFormatContext*->interrupt_callback
// callback type=> int (*interrupt_cb)(void*)
// interrupt_callback type=> AVIOInterruptCB
// ex: static const AVIOInterruptCB int_cb = { decode_interrupt_cb, NULL };
oc->interrupt_callback = int_cb;
view raw new-style.c hosted with ❤ by GitHub
.

要修改的部分雖然不太多,但 callback function 的參數有改,這是得注意的部分 :D

沒有留言:

張貼留言