diff mbox series

[FFmpeg-devel] avformat/utils: Combine identical statements

Message ID HE1PR0301MB2154B721B68881AB46619C348F4E9@HE1PR0301MB2154.eurprd03.prod.outlook.com
State Accepted
Commit a10c47acc29e5dc2c6b5278d0dcef225865f6341
Headers show
Series [FFmpeg-devel] avformat/utils: Combine identical statements
Related show

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

Andreas Rheinhardt April 14, 2021, 9:20 p.m. UTC
This would only make a difference in case the first attempt to
initialize the encoder failed and the second succeeded. The only
reason I can think of for this to happen is that the options (in
particular the codec whitelist) are not used for the second try
and that obviously implies that we should not even try a second time
to open the decoder.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavformat/utils.c | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)

Comments

Andreas Rheinhardt April 16, 2021, 11:05 a.m. UTC | #1
Andreas Rheinhardt:
> This would only make a difference in case the first attempt to
> initialize the encoder failed and the second succeeded. The only
> reason I can think of for this to happen is that the options (in
> particular the codec whitelist) are not used for the second try
> and that obviously implies that we should not even try a second time
> to open the decoder.
> 
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
> ---
>  libavformat/utils.c | 12 +++---------
>  1 file changed, 3 insertions(+), 9 deletions(-)
> 
> diff --git a/libavformat/utils.c b/libavformat/utils.c
> index d9971d7fd3..d4ec3d0190 100644
> --- a/libavformat/utils.c
> +++ b/libavformat/utils.c
> @@ -3747,16 +3747,10 @@ FF_ENABLE_DEPRECATION_WARNINGS
>          if (ic->codec_whitelist)
>              av_dict_set(options ? &options[i] : &thread_opt, "codec_whitelist", ic->codec_whitelist, 0);
>  
> -        /* Ensure that subtitle_header is properly set. */
> -        if (st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE
> -            && codec && !avctx->codec) {
> -            if (avcodec_open2(avctx, codec, options ? &options[i] : &thread_opt) < 0)
> -                av_log(ic, AV_LOG_WARNING,
> -                       "Failed to open codec in %s\n",__FUNCTION__);
> -        }
> -
>          // Try to just open decoders, in case this is enough to get parameters.
> -        if (!has_codec_parameters(st, NULL) && st->internal->request_probe <= 0) {
> +        // Also ensure that subtitle_header is properly set.
> +        if (!has_codec_parameters(st, NULL) && st->internal->request_probe <= 0 ||
> +            st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE) {
>              if (codec && !avctx->codec)
>                  if (avcodec_open2(avctx, codec, options ? &options[i] : &thread_opt) < 0)
>                      av_log(ic, AV_LOG_WARNING,
> 
Will apply tomorrow unless there are objections.

- Andreas
diff mbox series

Patch

diff --git a/libavformat/utils.c b/libavformat/utils.c
index d9971d7fd3..d4ec3d0190 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -3747,16 +3747,10 @@  FF_ENABLE_DEPRECATION_WARNINGS
         if (ic->codec_whitelist)
             av_dict_set(options ? &options[i] : &thread_opt, "codec_whitelist", ic->codec_whitelist, 0);
 
-        /* Ensure that subtitle_header is properly set. */
-        if (st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE
-            && codec && !avctx->codec) {
-            if (avcodec_open2(avctx, codec, options ? &options[i] : &thread_opt) < 0)
-                av_log(ic, AV_LOG_WARNING,
-                       "Failed to open codec in %s\n",__FUNCTION__);
-        }
-
         // Try to just open decoders, in case this is enough to get parameters.
-        if (!has_codec_parameters(st, NULL) && st->internal->request_probe <= 0) {
+        // Also ensure that subtitle_header is properly set.
+        if (!has_codec_parameters(st, NULL) && st->internal->request_probe <= 0 ||
+            st->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE) {
             if (codec && !avctx->codec)
                 if (avcodec_open2(avctx, codec, options ? &options[i] : &thread_opt) < 0)
                     av_log(ic, AV_LOG_WARNING,