<div dir="ltr">Hi,<div><br></div><div>Background of my problem:</div><div>I've got an app that has multiple video streams. I'm not sure which part of my app is creating too many threads, but the performance critical section of my app is getting context switched a lot. I believe there is a thread pool per av codec context, so I thought I could start there. The solution for this I believe is to ask ffmpeg to use my threads that I pinned as a thread pool by setting the execute and execute2 function pointer variables in AVCodecContext.</div><div><br></div><div>Current problem:</div><div>Here is the example of my AVCodecContext creation stripped of error checking (further uses of AVCodecContext do work and behave as expected, just the specified handlers are not called):</div><div><br></div><div>AVCodec* codec = /*properly init, tested that works*/;</div><div>AVCodecContext* context = avcodec_alloc_context3(codec_);</div><div>context_->execute = &thread_execute;<br>context_->execute2 = &thread_execute2;<br>context_->thread_count = 0;<br>context_->thread_type = FF_THREAD_SLICE;<br>context_->active_thread_type = FF_THREAD_SLICE;<br></div><div><br></div><div>avcodec_open2(context, codec, NULL);</div><div><br></div><div>/* some usage which works afterwards*/</div><div><br></div><div>The problem is that the functions thread_execute and thread_execute2 are not called. The codec library used is libx264 (checked that it is the one loaded). </div><div><br></div><div>Could you please advise on where I should search for errors in my code (why the execute handler function is not called)?</div><div><br></div><div>Here are the functions I specified:</div><div><br></div><div><br>int thread_execute(AVCodecContext* s, int (*func)(AVCodecContext *c2, void *arg2), void* arg, int* ret, int count, int size)<br>{<br>    // Do it all serially for now<br>    for (int k = 0; k < count; ++k)<br>    {<br>        ret[k] = func(s, arg);<br>    }<br><br>    return 0;<br>}<br><br>int thread_execute2(AVCodecContext* s, int (*func)(AVCodecContext* c2, void* arg2, int, int), void* arg, int* ret, int count)<br>{<br>    // Do it all serially for now<br>    for (int k = 0; k < count; ++k)<br>    {<br>        ret[k] = func(s, arg, k, count);<br>    }<br><br>    return 0;<br>}<br></div><div><br></div><div>I have tried setting debug points into the functions I created, but they do not hit (I used the debug build of my app). Print statements were not executed either. I have also verified via debugger that the handlers are not changed after calling avcodec_open2.</div><div><br></div><div>Best,</div><div>Olzhas</div></div>