diff mbox series

[FFmpeg-devel,v3,1/3] lavc/decode: Warp get_hw_config function

Message ID 20220823081929.413947-1-fei.w.wang@intel.com
State New
Headers show
Series [FFmpeg-devel,v3,1/3] lavc/decode: Warp get_hw_config function | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Wang, Fei W Aug. 23, 2022, 8:19 a.m. UTC
From: Linjie Fu <linjie.fu@intel.com>

Wrap the procedure of getting the hardware config from a pixel format
into a function.

Signed-off-by: Linjie Fu <linjie.fu@intel.com>
Signed-off-by: Fei Wang <fei.w.wang@intel.com>
---
 libavcodec/decode.c | 31 +++++++++++++++++++------------
 1 file changed, 19 insertions(+), 12 deletions(-)

Comments

Wang, Fei W Aug. 31, 2022, 1:20 a.m. UTC | #1
On Tue, 2022-08-23 at 16:19 +0800, Fei Wang wrote:
> From: Linjie Fu <linjie.fu@intel.com>
> 
> Wrap the procedure of getting the hardware config from a pixel format
> into a function.
> 
> Signed-off-by: Linjie Fu <linjie.fu@intel.com>
> Signed-off-by: Fei Wang <fei.w.wang@intel.com>
> ---
>  libavcodec/decode.c | 31 +++++++++++++++++++------------
>  1 file changed, 19 insertions(+), 12 deletions(-)
> 
> diff --git a/libavcodec/decode.c b/libavcodec/decode.c
> index 75373989c6..3b69426c09 100644
> --- a/libavcodec/decode.c
> +++ b/libavcodec/decode.c
> @@ -1156,6 +1156,24 @@ static void hwaccel_uninit(AVCodecContext
> *avctx)
>      av_buffer_unref(&avctx->hw_frames_ctx);
>  }
>  
> +static const AVCodecHWConfigInternal *get_hw_config(AVCodecContext
> *avctx, enum AVPixelFormat fmt)
> +{
> +    const AVCodecHWConfigInternal *hw_config;
> +
> +    if (!ffcodec(avctx->codec)->hw_configs)
> +        return NULL;
> +
> +    for (int i = 0;; i++) {
> +        hw_config = ffcodec(avctx->codec)->hw_configs[i];
> +        if (!hw_config)
> +            return NULL;
> +        if (hw_config->public.pix_fmt == fmt)
> +            return hw_config;
> +    }
> +
> +    return NULL;
> +}
> +
>  int ff_get_format(AVCodecContext *avctx, const enum AVPixelFormat
> *fmt)
>  {
>      const AVPixFmtDescriptor *desc;
> @@ -1213,18 +1231,7 @@ int ff_get_format(AVCodecContext *avctx, const
> enum AVPixelFormat *fmt)
>              break;
>          }
>  
> -        if (ffcodec(avctx->codec)->hw_configs) {
> -            for (i = 0;; i++) {
> -                hw_config = ffcodec(avctx->codec)->hw_configs[i];
> -                if (!hw_config)
> -                    break;
> -                if (hw_config->public.pix_fmt == user_choice)
> -                    break;
> -            }
> -        } else {
> -            hw_config = NULL;
> -        }
> -
> +        hw_config = get_hw_config(avctx, user_choice);
>          if (!hw_config) {
>              // No config available, so no extra setup required.
>              ret = user_choice;

Ping, any more comments on V3?

Thanks
Fei
Xiang, Haihao Sept. 7, 2022, 8:47 a.m. UTC | #2
On Wed, 2022-08-31 at 01:20 +0000, Wang, Fei W wrote:
> On Tue, 2022-08-23 at 16:19 +0800, Fei Wang wrote:
> > From: Linjie Fu <linjie.fu@intel.com>
> > 
> > Wrap the procedure of getting the hardware config from a pixel format
> > into a function.
> > 
> > Signed-off-by: Linjie Fu <linjie.fu@intel.com>
> > Signed-off-by: Fei Wang <fei.w.wang@intel.com>
> > ---
> >  libavcodec/decode.c | 31 +++++++++++++++++++------------
> >  1 file changed, 19 insertions(+), 12 deletions(-)
> > 
> > diff --git a/libavcodec/decode.c b/libavcodec/decode.c
> > index 75373989c6..3b69426c09 100644
> > --- a/libavcodec/decode.c
> > +++ b/libavcodec/decode.c
> > @@ -1156,6 +1156,24 @@ static void hwaccel_uninit(AVCodecContext
> > *avctx)
> >      av_buffer_unref(&avctx->hw_frames_ctx);
> >  }
> >  
> > +static const AVCodecHWConfigInternal *get_hw_config(AVCodecContext
> > *avctx, enum AVPixelFormat fmt)
> > +{
> > +    const AVCodecHWConfigInternal *hw_config;
> > +
> > +    if (!ffcodec(avctx->codec)->hw_configs)
> > +        return NULL;
> > +
> > +    for (int i = 0;; i++) {
> > +        hw_config = ffcodec(avctx->codec)->hw_configs[i];
> > +        if (!hw_config)
> > +            return NULL;
> > +        if (hw_config->public.pix_fmt == fmt)
> > +            return hw_config;
> > +    }
> > +
> > +    return NULL;
> > +}
> > +
> >  int ff_get_format(AVCodecContext *avctx, const enum AVPixelFormat
> > *fmt)
> >  {
> >      const AVPixFmtDescriptor *desc;
> > @@ -1213,18 +1231,7 @@ int ff_get_format(AVCodecContext *avctx, const
> > enum AVPixelFormat *fmt)
> >              break;
> >          }
> >  
> > -        if (ffcodec(avctx->codec)->hw_configs) {
> > -            for (i = 0;; i++) {
> > -                hw_config = ffcodec(avctx->codec)->hw_configs[i];
> > -                if (!hw_config)
> > -                    break;
> > -                if (hw_config->public.pix_fmt == user_choice)
> > -                    break;
> > -            }
> > -        } else {
> > -            hw_config = NULL;
> > -        }
> > -
> > +        hw_config = get_hw_config(avctx, user_choice);
> >          if (!hw_config) {
> >              // No config available, so no extra setup required.
> >              ret = user_choice;
> 
> Ping, any more comments on V3?
> 

The patchset LGTM and works well for me, I'll apply this patchset if no more
comment.

-Haihao
Mark Thompson Sept. 7, 2022, 10:13 p.m. UTC | #3
On 07/09/2022 09:47, Xiang, Haihao wrote:
> On Wed, 2022-08-31 at 01:20 +0000, Wang, Fei W wrote:
>> On Tue, 2022-08-23 at 16:19 +0800, Fei Wang wrote:
>>> From: Linjie Fu <linjie.fu@intel.com>
>>>
>>> Wrap the procedure of getting the hardware config from a pixel format
>>> into a function.
>>>
>>> Signed-off-by: Linjie Fu <linjie.fu@intel.com>
>>> Signed-off-by: Fei Wang <fei.w.wang@intel.com>
>>> ---
>>>   libavcodec/decode.c | 31 +++++++++++++++++++------------
>>>   1 file changed, 19 insertions(+), 12 deletions(-)
>>>
>>> diff --git a/libavcodec/decode.c b/libavcodec/decode.c
>>> index 75373989c6..3b69426c09 100644
>>> --- a/libavcodec/decode.c
>>> +++ b/libavcodec/decode.c
>>> @@ -1156,6 +1156,24 @@ static void hwaccel_uninit(AVCodecContext
>>> *avctx)
>>>       av_buffer_unref(&avctx->hw_frames_ctx);
>>>   }
>>>   
>>> +static const AVCodecHWConfigInternal *get_hw_config(AVCodecContext
>>> *avctx, enum AVPixelFormat fmt)
>>> +{
>>> +    const AVCodecHWConfigInternal *hw_config;
>>> +
>>> +    if (!ffcodec(avctx->codec)->hw_configs)
>>> +        return NULL;
>>> +
>>> +    for (int i = 0;; i++) {
>>> +        hw_config = ffcodec(avctx->codec)->hw_configs[i];
>>> +        if (!hw_config)
>>> +            return NULL;
>>> +        if (hw_config->public.pix_fmt == fmt)
>>> +            return hw_config;
>>> +    }
>>> +
>>> +    return NULL;
>>> +}
>>> +
>>>   int ff_get_format(AVCodecContext *avctx, const enum AVPixelFormat
>>> *fmt)
>>>   {
>>>       const AVPixFmtDescriptor *desc;
>>> @@ -1213,18 +1231,7 @@ int ff_get_format(AVCodecContext *avctx, const
>>> enum AVPixelFormat *fmt)
>>>               break;
>>>           }
>>>   
>>> -        if (ffcodec(avctx->codec)->hw_configs) {
>>> -            for (i = 0;; i++) {
>>> -                hw_config = ffcodec(avctx->codec)->hw_configs[i];
>>> -                if (!hw_config)
>>> -                    break;
>>> -                if (hw_config->public.pix_fmt == user_choice)
>>> -                    break;
>>> -            }
>>> -        } else {
>>> -            hw_config = NULL;
>>> -        }
>>> -
>>> +        hw_config = get_hw_config(avctx, user_choice);
>>>           if (!hw_config) {
>>>               // No config available, so no extra setup required.
>>>               ret = user_choice;
>>
>> Ping, any more comments on V3?
>>
> 
> The patchset LGTM and works well for me, I'll apply this patchset if no more
> comment.

See <https://lists.ffmpeg.org/pipermail/ffmpeg-devel/2022-September/301124.html>.
diff mbox series

Patch

diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index 75373989c6..3b69426c09 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -1156,6 +1156,24 @@  static void hwaccel_uninit(AVCodecContext *avctx)
     av_buffer_unref(&avctx->hw_frames_ctx);
 }
 
+static const AVCodecHWConfigInternal *get_hw_config(AVCodecContext *avctx, enum AVPixelFormat fmt)
+{
+    const AVCodecHWConfigInternal *hw_config;
+
+    if (!ffcodec(avctx->codec)->hw_configs)
+        return NULL;
+
+    for (int i = 0;; i++) {
+        hw_config = ffcodec(avctx->codec)->hw_configs[i];
+        if (!hw_config)
+            return NULL;
+        if (hw_config->public.pix_fmt == fmt)
+            return hw_config;
+    }
+
+    return NULL;
+}
+
 int ff_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt)
 {
     const AVPixFmtDescriptor *desc;
@@ -1213,18 +1231,7 @@  int ff_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt)
             break;
         }
 
-        if (ffcodec(avctx->codec)->hw_configs) {
-            for (i = 0;; i++) {
-                hw_config = ffcodec(avctx->codec)->hw_configs[i];
-                if (!hw_config)
-                    break;
-                if (hw_config->public.pix_fmt == user_choice)
-                    break;
-            }
-        } else {
-            hw_config = NULL;
-        }
-
+        hw_config = get_hw_config(avctx, user_choice);
         if (!hw_config) {
             // No config available, so no extra setup required.
             ret = user_choice;