From b9cee5bab06b073cff91b8ca618a6452a354a45e Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Mon, 1 Mar 2021 21:12:47 +0100 Subject: [PATCH] Key _next_time with the audio stream pointer. --- src/lib/ffmpeg_decoder.cc | 21 +++++++++++---------- src/lib/ffmpeg_decoder.h | 4 ++-- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/lib/ffmpeg_decoder.cc b/src/lib/ffmpeg_decoder.cc index c91a2f2e7..9b65e5639 100644 --- a/src/lib/ffmpeg_decoder.cc +++ b/src/lib/ffmpeg_decoder.cc @@ -101,7 +101,9 @@ FFmpegDecoder::FFmpegDecoder (shared_ptr film, shared_ptr(this, c->only_text(), ContentTime())); } - _next_time.resize (_format_context->nb_streams); + for (auto i: c->ffmpeg_audio_streams()) { + _next_time[i] = {}; + } } @@ -423,7 +425,7 @@ DCPOMATIC_ENABLE_WARNINGS _have_current_subtitle = false; for (auto& i: _next_time) { - i = optional(); + i.second = {}; } } @@ -447,7 +449,7 @@ FFmpegDecoder::audio_stream_from_index (int index) const void -FFmpegDecoder::process_audio_frame (shared_ptr stream, int stream_index, int64_t packet_pts) +FFmpegDecoder::process_audio_frame (shared_ptr stream, int64_t packet_pts) { auto data = deinterleave_audio (stream); @@ -457,8 +459,8 @@ FFmpegDecoder::process_audio_frame (shared_ptr stream, int st that have AV_NOPTS_VALUE we need to work out the timestamp ourselves. This is particularly noticeable with TrueHD streams (see #1111). */ - if (_next_time[stream_index]) { - ct = *_next_time[stream_index]; + if (_next_time[stream]) { + ct = *_next_time[stream]; } } else { ct = ContentTime::from_seconds ( @@ -467,7 +469,7 @@ FFmpegDecoder::process_audio_frame (shared_ptr stream, int st + _pts_offset; } - _next_time[stream_index] = ct + ContentTime::from_frames(data->frames(), stream->frame_rate()); + _next_time[stream] = ct + ContentTime::from_frames(data->frames(), stream->frame_rate()); if (ct < ContentTime()) { /* Discard audio data that comes before time 0 */ @@ -482,7 +484,7 @@ FFmpegDecoder::process_audio_frame (shared_ptr stream, int st "Crazy timestamp %1 for %2 samples in stream %3 packet pts %4 (ts=%5 tb=%6, off=%7)", to_string(ct), data->frames(), - stream_index, + stream->id(), packet_pts, _frame->best_effort_timestamp, av_q2d(stream->stream(_format_context)->time_base), @@ -500,8 +502,7 @@ FFmpegDecoder::process_audio_frame (shared_ptr stream, int st void FFmpegDecoder::decode_audio_packet (AVPacket* packet) { - int const stream_index = packet->stream_index; - auto stream = audio_stream_from_index (stream_index); + auto stream = audio_stream_from_index (packet->stream_index); if (!stream) { return; } @@ -533,7 +534,7 @@ FFmpegDecoder::decode_audio_packet (AVPacket* packet) } if (frame_finished) { - process_audio_frame (stream, stream_index, copy_packet.pts); + process_audio_frame (stream, copy_packet.pts); } copy_packet.data += decode_result; diff --git a/src/lib/ffmpeg_decoder.h b/src/lib/ffmpeg_decoder.h index 58120da33..a0a93c9a0 100644 --- a/src/lib/ffmpeg_decoder.h +++ b/src/lib/ffmpeg_decoder.h @@ -58,7 +58,7 @@ private: int bytes_per_audio_sample (std::shared_ptr stream) const; std::shared_ptr audio_stream_from_index (int index) const; - void process_audio_frame (std::shared_ptr stream, int stream_index, int64_t packet_pts); + void process_audio_frame (std::shared_ptr stream, int64_t packet_pts); bool decode_video_packet (AVPacket* packet); void decode_audio_packet (AVPacket* packet); @@ -80,5 +80,5 @@ private: std::shared_ptr _black_image; - std::vector > _next_time; + std::map, boost::optional> _next_time; }; -- 2.30.2