[FFmpeg-cvslog] Merge commit '9e4a5eb51b9f3b2bff0ef08e0074b7fe4893075d'

James Almer git at videolan.org
Sat Oct 28 20:03:17 EEST 2017


ffmpeg | branch: master | James Almer <jamrial at gmail.com> | Sat Oct 28 14:01:25 2017 -0300| [1e5669457f6072f6bfb0e15aaeb958b44a742833] | committer: James Almer

Merge commit '9e4a5eb51b9f3b2bff0ef08e0074b7fe4893075d'

* commit '9e4a5eb51b9f3b2bff0ef08e0074b7fe4893075d':
  avformat: Free the internal codec context at the end

Merged-by: James Almer <jamrial at gmail.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=1e5669457f6072f6bfb0e15aaeb958b44a742833
---

 libavformat/utils.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/libavformat/utils.c b/libavformat/utils.c
index 6dbc48d54d..0ab2f61eb0 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -3875,12 +3875,6 @@ FF_ENABLE_DEPRECATION_WARNINGS
         }
     }
 
-    // close codecs which were opened in try_decode_frame()
-    for (i = 0; i < ic->nb_streams; i++) {
-        st = ic->streams[i];
-        avcodec_close(st->internal->avctx);
-    }
-
     ff_rfps_calculate(ic);
 
     for (i = 0; i < ic->nb_streams; i++) {
@@ -4071,6 +4065,7 @@ find_stream_info_err:
         st = ic->streams[i];
         if (st->info)
             av_freep(&st->info->duration_error);
+        avcodec_close(ic->streams[i]->internal->avctx);
         av_freep(&ic->streams[i]->info);
         av_bsf_free(&ic->streams[i]->internal->extract_extradata.bsf);
         av_packet_free(&ic->streams[i]->internal->extract_extradata.pkt);


======================================================================

diff --cc libavformat/utils.c
index 6dbc48d54d,eaba473914..0ab2f61eb0
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@@ -3824,65 -2466,6 +3824,59 @@@ FF_ENABLE_DEPRECATION_WARNING
          count++;
      }
  
 +    if (eof_reached) {
 +        int stream_index;
 +        for (stream_index = 0; stream_index < ic->nb_streams; stream_index++) {
 +            st = ic->streams[stream_index];
 +            avctx = st->internal->avctx;
 +            if (!has_codec_parameters(st, NULL)) {
 +                const AVCodec *codec = find_probe_decoder(ic, st, st->codecpar->codec_id);
 +                if (codec && !avctx->codec) {
 +                    AVDictionary *opts = NULL;
 +                    if (ic->codec_whitelist)
 +                        av_dict_set(&opts, "codec_whitelist", ic->codec_whitelist, 0);
 +                    if (avcodec_open2(avctx, codec, (options && stream_index < orig_nb_streams) ? &options[stream_index] : &opts) < 0)
 +                        av_log(ic, AV_LOG_WARNING,
 +                               "Failed to open codec in %s\n",__FUNCTION__);
 +                    av_dict_free(&opts);
 +                }
 +            }
 +
 +            // EOF already reached while reading the stream above.
 +            // So continue with reoordering DTS with whatever delay we have.
 +            if (ic->internal->packet_buffer && !has_decode_delay_been_guessed(st)) {
 +                update_dts_from_pts(ic, stream_index, ic->internal->packet_buffer);
 +            }
 +        }
 +    }
 +
 +    if (flush_codecs) {
 +        AVPacket empty_pkt = { 0 };
 +        int err = 0;
 +        av_init_packet(&empty_pkt);
 +
 +        for (i = 0; i < ic->nb_streams; i++) {
 +
 +            st = ic->streams[i];
 +
 +            /* flush the decoders */
 +            if (st->info->found_decoder == 1) {
 +                do {
 +                    err = try_decode_frame(ic, st, &empty_pkt,
 +                                            (options && i < orig_nb_streams)
 +                                            ? &options[i] : NULL);
 +                } while (err > 0 && !has_codec_parameters(st, NULL));
 +
 +                if (err < 0) {
 +                    av_log(ic, AV_LOG_INFO,
 +                        "decoding for stream %d failed\n", st->index);
 +                }
 +            }
 +        }
 +    }
 +
-     // close codecs which were opened in try_decode_frame()
-     for (i = 0; i < ic->nb_streams; i++) {
-         st = ic->streams[i];
-         avcodec_close(st->internal->avctx);
-     }
- 
 +    ff_rfps_calculate(ic);
 +
      for (i = 0; i < ic->nb_streams; i++) {
          st = ic->streams[i];
          avctx = st->internal->avctx;
@@@ -4066,11 -2561,11 +4060,12 @@@ FF_ENABLE_DEPRECATION_WARNING
          st->internal->avctx_inited = 0;
      }
  
 -    estimate_timings(ic, old_offset);
 -
  find_stream_info_err:
      for (i = 0; i < ic->nb_streams; i++) {
 +        st = ic->streams[i];
 +        if (st->info)
 +            av_freep(&st->info->duration_error);
+         avcodec_close(ic->streams[i]->internal->avctx);
          av_freep(&ic->streams[i]->info);
          av_bsf_free(&ic->streams[i]->internal->extract_extradata.bsf);
          av_packet_free(&ic->streams[i]->internal->extract_extradata.pkt);



More information about the ffmpeg-cvslog mailing list