diff mbox

[FFmpeg-devel] Use AVOnce as a static variable consistently

Message ID 20170522100619.23600-1-h.leppkes@gmail.com
State Accepted
Commit 9fb293cfd8b758b98f1f535a2867c7bf3a324af6
Headers show

Commit Message

Hendrik Leppkes May 22, 2017, 10:06 a.m. UTC
Using AVOnce as a stack variable makes no sense as the state is lost
when the function exists.

This fixes repeated calls to av(filter/device)_register_all
---
 libavdevice/alldevices.c | 2 +-
 libavfilter/allfilters.c | 2 +-
 libavformat/allformats.c | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

Comments

wm4 May 22, 2017, 10:25 a.m. UTC | #1
On Mon, 22 May 2017 12:06:19 +0200
Hendrik Leppkes <h.leppkes@gmail.com> wrote:

> Using AVOnce as a stack variable makes no sense as the state is lost
> when the function exists.
> 
> This fixes repeated calls to av(filter/device)_register_all
> ---
>  libavdevice/alldevices.c | 2 +-
>  libavfilter/allfilters.c | 2 +-
>  libavformat/allformats.c | 2 +-
>  3 files changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/libavdevice/alldevices.c b/libavdevice/alldevices.c
> index 280a260bd3..a8ed53ae5d 100644
> --- a/libavdevice/alldevices.c
> +++ b/libavdevice/alldevices.c
> @@ -73,7 +73,7 @@ static void register_all(void)
>  
>  void avdevice_register_all(void)
>  {
> -    AVOnce control = AV_ONCE_INIT;
> +    static AVOnce control = AV_ONCE_INIT;
>  
>      ff_thread_once(&control, register_all);
>  }
> diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
> index 2bcfce77be..f8cd193dbe 100644
> --- a/libavfilter/allfilters.c
> +++ b/libavfilter/allfilters.c
> @@ -390,7 +390,7 @@ static void register_all(void)
>  
>  void avfilter_register_all(void)
>  {
> -    AVOnce control = AV_ONCE_INIT;
> +    static AVOnce control = AV_ONCE_INIT;
>  
>      ff_thread_once(&control, register_all);
>  }
> diff --git a/libavformat/allformats.c b/libavformat/allformats.c
> index 62661d14a4..b3ffe0f2b6 100644
> --- a/libavformat/allformats.c
> +++ b/libavformat/allformats.c
> @@ -385,7 +385,7 @@ static void register_all(void)
>  
>  void av_register_all(void)
>  {
> -    AVOnce control = AV_ONCE_INIT;
> +    static AVOnce control = AV_ONCE_INIT;
>  
>      ff_thread_once(&control, register_all);
>  }

That's a somewhat huge oversight. The fix looks correct, please push.
Hendrik Leppkes May 22, 2017, 10:39 a.m. UTC | #2
On Mon, May 22, 2017 at 12:25 PM, wm4 <nfxjfg@googlemail.com> wrote:
> On Mon, 22 May 2017 12:06:19 +0200
> Hendrik Leppkes <h.leppkes@gmail.com> wrote:
>
>> Using AVOnce as a stack variable makes no sense as the state is lost
>> when the function exists.
>>
>> This fixes repeated calls to av(filter/device)_register_all
>> ---
>>  libavdevice/alldevices.c | 2 +-
>>  libavfilter/allfilters.c | 2 +-
>>  libavformat/allformats.c | 2 +-
>>  3 files changed, 3 insertions(+), 3 deletions(-)
>>
>> diff --git a/libavdevice/alldevices.c b/libavdevice/alldevices.c
>> index 280a260bd3..a8ed53ae5d 100644
>> --- a/libavdevice/alldevices.c
>> +++ b/libavdevice/alldevices.c
>> @@ -73,7 +73,7 @@ static void register_all(void)
>>
>>  void avdevice_register_all(void)
>>  {
>> -    AVOnce control = AV_ONCE_INIT;
>> +    static AVOnce control = AV_ONCE_INIT;
>>
>>      ff_thread_once(&control, register_all);
>>  }
>> diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
>> index 2bcfce77be..f8cd193dbe 100644
>> --- a/libavfilter/allfilters.c
>> +++ b/libavfilter/allfilters.c
>> @@ -390,7 +390,7 @@ static void register_all(void)
>>
>>  void avfilter_register_all(void)
>>  {
>> -    AVOnce control = AV_ONCE_INIT;
>> +    static AVOnce control = AV_ONCE_INIT;
>>
>>      ff_thread_once(&control, register_all);
>>  }
>> diff --git a/libavformat/allformats.c b/libavformat/allformats.c
>> index 62661d14a4..b3ffe0f2b6 100644
>> --- a/libavformat/allformats.c
>> +++ b/libavformat/allformats.c
>> @@ -385,7 +385,7 @@ static void register_all(void)
>>
>>  void av_register_all(void)
>>  {
>> -    AVOnce control = AV_ONCE_INIT;
>> +    static AVOnce control = AV_ONCE_INIT;
>>
>>      ff_thread_once(&control, register_all);
>>  }
>
> That's a somewhat huge oversight. The fix looks correct, please push.

Pushed and backported to 3.3 (3.2 did not have this yet).

- Hendrik
Steven Liu May 22, 2017, 10:46 a.m. UTC | #3
2017-05-22 18:06 GMT+08:00 Hendrik Leppkes <h.leppkes@gmail.com>:

> Using AVOnce as a stack variable makes no sense as the state is lost
> when the function exists.
>
> This fixes repeated calls to av(filter/device)_register_all
> ---
>  libavdevice/alldevices.c | 2 +-
>  libavfilter/allfilters.c | 2 +-
>  libavformat/allformats.c | 2 +-
>  3 files changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/libavdevice/alldevices.c b/libavdevice/alldevices.c
> index 280a260bd3..a8ed53ae5d 100644
> --- a/libavdevice/alldevices.c
> +++ b/libavdevice/alldevices.c
> @@ -73,7 +73,7 @@ static void register_all(void)
>
>  void avdevice_register_all(void)
>  {
> -    AVOnce control = AV_ONCE_INIT;
> +    static AVOnce control = AV_ONCE_INIT;
>
>      ff_thread_once(&control, register_all);
>  }
> diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
> index 2bcfce77be..f8cd193dbe 100644
> --- a/libavfilter/allfilters.c
> +++ b/libavfilter/allfilters.c
> @@ -390,7 +390,7 @@ static void register_all(void)
>
>  void avfilter_register_all(void)
>  {
> -    AVOnce control = AV_ONCE_INIT;
> +    static AVOnce control = AV_ONCE_INIT;
>
>      ff_thread_once(&control, register_all);
>  }
> diff --git a/libavformat/allformats.c b/libavformat/allformats.c
> index 62661d14a4..b3ffe0f2b6 100644
> --- a/libavformat/allformats.c
> +++ b/libavformat/allformats.c
> @@ -385,7 +385,7 @@ static void register_all(void)
>
>  void av_register_all(void)
>  {
> -    AVOnce control = AV_ONCE_INIT;
> +    static AVOnce control = AV_ONCE_INIT;
>
>      ff_thread_once(&control, register_all);
>  }
> --
> 2.12.2.windows.2
>

LGTM

>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
diff mbox

Patch

diff --git a/libavdevice/alldevices.c b/libavdevice/alldevices.c
index 280a260bd3..a8ed53ae5d 100644
--- a/libavdevice/alldevices.c
+++ b/libavdevice/alldevices.c
@@ -73,7 +73,7 @@  static void register_all(void)
 
 void avdevice_register_all(void)
 {
-    AVOnce control = AV_ONCE_INIT;
+    static AVOnce control = AV_ONCE_INIT;
 
     ff_thread_once(&control, register_all);
 }
diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index 2bcfce77be..f8cd193dbe 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -390,7 +390,7 @@  static void register_all(void)
 
 void avfilter_register_all(void)
 {
-    AVOnce control = AV_ONCE_INIT;
+    static AVOnce control = AV_ONCE_INIT;
 
     ff_thread_once(&control, register_all);
 }
diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index 62661d14a4..b3ffe0f2b6 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -385,7 +385,7 @@  static void register_all(void)
 
 void av_register_all(void)
 {
-    AVOnce control = AV_ONCE_INIT;
+    static AVOnce control = AV_ONCE_INIT;
 
     ff_thread_once(&control, register_all);
 }