2014年5月7日水曜日

avcodec_open2でエラー(-1)

ある日、こんな不思議なエラーが発生するようになって、なんでかなぁ~って
avcodecのソースを眺めてみました。

すると...以下のようなソースが

/* If there is a user-supplied mutex locking routine, call it. */
if (lockmgr_cb) {
if ((*lockmgr_cb)(&codec_mutex, AV_LOCK_OBTAIN))
return -1;
}

entangled_thread_counter++;
if (entangled_thread_counter != 1) {
av_log(avctx, AV_LOG_ERROR, "insufficient thread locking around avcodec_open/close()\n");
ret = -1;
goto end;
}

えっ、排他制御を勝手にやってくれないの?
av_lockmgr_registerで排他制御用の関数を登録したら解決しました。

pthread使って勝手にやってくれれば良いのに、何か拘りがあるのかなぁ?
不思議です。