Message ID | 20220812125545.1229410-1-fei.w.wang@intel.com |
---|---|
State | New |
Headers | show |
Series | [FFmpeg-devel,v1,1/3] lavc/decode: Add get_hw_config function | expand |
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 |
The commit message is misleading - you are not adding code, you are moving code. Quoting Fei Wang (2022-08-12 14:55:43) > 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 | 33 +++++++++++++++++++++------------ > 1 file changed, 21 insertions(+), 12 deletions(-) > > diff --git a/libavcodec/decode.c b/libavcodec/decode.c > index 75373989c6..d66d5a4160 100644 > --- a/libavcodec/decode.c > +++ b/libavcodec/decode.c > @@ -1156,6 +1156,26 @@ 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; > + int i; Should be declared in the loop > + if (ffcodec(avctx->codec)->hw_configs) { > + for (i = 0;; i++) { > + hw_config = ffcodec(avctx->codec)->hw_configs[i]; > + if (!hw_config) > + break; return NULL; > + if (hw_config->public.pix_fmt == fmt) > + break; return hw_config; > + } > + } else { > + hw_config = NULL; > + } You can save one level of indentation by starting with if (!ffcodec(avctx->codec)->hw_configs) return NULL;
On Tue, 2022-08-16 at 13:22 +0200, Anton Khirnov wrote: > The commit message is misleading - you are not adding code, you are > moving code. > > Quoting Fei Wang (2022-08-12 14:55:43) > > 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 | 33 +++++++++++++++++++++------------ > > 1 file changed, 21 insertions(+), 12 deletions(-) > > > > diff --git a/libavcodec/decode.c b/libavcodec/decode.c > > index 75373989c6..d66d5a4160 100644 > > --- a/libavcodec/decode.c > > +++ b/libavcodec/decode.c > > @@ -1156,6 +1156,26 @@ 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; > > + int i; > > Should be declared in the loop > > > + if (ffcodec(avctx->codec)->hw_configs) { > > + for (i = 0;; i++) { > > + hw_config = ffcodec(avctx->codec)->hw_configs[i]; > > + if (!hw_config) > > + break; > > return NULL; > > > + if (hw_config->public.pix_fmt == fmt) > > + break; > > return hw_config; > > > + } > > + } else { > > + hw_config = NULL; > > + } > > You can save one level of indentation by starting with > > if (!ffcodec(avctx->codec)->hw_configs) > return NULL; Fix in V2. Thanks Fei >
diff --git a/libavcodec/decode.c b/libavcodec/decode.c index 75373989c6..d66d5a4160 100644 --- a/libavcodec/decode.c +++ b/libavcodec/decode.c @@ -1156,6 +1156,26 @@ 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; + int i; + + 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 == fmt) + break; + } + } else { + hw_config = NULL; + } + + return hw_config; +} + int ff_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt) { const AVPixFmtDescriptor *desc; @@ -1213,18 +1233,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;