[Libav-user] calling av_register_all() twice makes libav stuck.

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

[Libav-user] calling av_register_all() twice makes libav stuck.

易源
Hi,

I tried to call av_register_all() multiple times, and it works well
for old lib version, but now it will cause the following call to
avformat_open_input() stuck forever.

After examining the code for libavformat, I found that there was
a code change about Mar, 2017 that changed av_register_all()
to use pthread_once(), and it seems that the guarding variable
for once-control failed to protect register_all() to be called
multiple times. Refer to the following code:

void av_register_all(void)
{
    AVOnce control = AV_ONCE_INIT;

    ff_thread_once(&control, register_all);
}

Should it be a static or a global variable here?

The reason it will cause avformat_open_input() to be stuck
forever is that each time register_all() is called,
ff_register_rtp_dynamic_payload_handlers() will also be called.
It will cause the linked list rtp_first_dynamic_payload_handler
to become a loop. When we call avformat_open_input() it will
try to find the rtp handler in this linked list, and if unfortunately
there is no matched handler in the list, it will loop forever.


Thanks!
Yuan Yi


 


_______________________________________________
Libav-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/libav-user
Reply | Threaded
Open this post in threaded view
|

Re: calling av_register_all() twice makes libav stuck.

Gabriele Greco-2

    AVOnce control = AV_ONCE_INIT;

    ff_thread_once(&control, register_all);
}

Should it be a static or a global variable here?


Considering that AVOnce is defined as 'char' it seems a bug to me too. 


--
Bye,
 Gabry


_______________________________________________
Libav-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/libav-user
Reply | Threaded
Open this post in threaded view
|

Re: calling av_register_all() twice makes libav stuck.

Hendrik Leppkes
On Mon, May 22, 2017 at 11:04 AM, Gabriele Greco
<[hidden email]> wrote:

>>
>>     AVOnce control = AV_ONCE_INIT;
>>
>>     ff_thread_once(&control, register_all);
>> }
>>
>> Should it be a static or a global variable here?
>>
>
> Considering that AVOnce is defined as 'char' it seems a bug to me too.
>

You are correct, this should be a static variable. I'm sending a patch.

- Hendrik
_______________________________________________
Libav-user mailing list
[hidden email]
http://ffmpeg.org/mailman/listinfo/libav-user