diff options
| author | Carl Hetherington <cth@carlh.net> | 2014-02-21 10:25:00 +0000 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2014-02-21 10:25:00 +0000 |
| commit | cd34ac8e2e5a835b5907a8a67b241e29240eb7b9 (patch) | |
| tree | fbefd9b43461831084178c43a4eb352e4fe7aac3 | |
| parent | 353507afb5ed4249d554a4e8e7e78d9076fb0e40 (diff) | |
Another small clean-up.
| -rw-r--r-- | src/lib/ffmpeg_content.cc | 10 | ||||
| -rw-r--r-- | src/lib/ffmpeg_content.h | 5 | ||||
| -rw-r--r-- | src/lib/ffmpeg_decoder.cc | 4 | ||||
| -rw-r--r-- | src/lib/ffmpeg_examiner.cc | 10 | ||||
| -rw-r--r-- | src/lib/ffmpeg_examiner.h | 2 |
5 files changed, 16 insertions, 15 deletions
diff --git a/src/lib/ffmpeg_content.cc b/src/lib/ffmpeg_content.cc index 221a262ef..2c888baaf 100644 --- a/src/lib/ffmpeg_content.cc +++ b/src/lib/ffmpeg_content.cc @@ -393,22 +393,22 @@ FFmpegAudioStream::as_xml (xmlpp::Node* root) const mapping.as_xml (root->add_child("Mapping")); } -int -FFmpegStream::index (AVFormatContext const * fc) const +bool +FFmpegStream::uses_index (AVFormatContext const * fc, int index) const { if (_legacy_id) { - return id; + return id == index; } size_t i = 0; while (i < fc->nb_streams) { if (fc->streams[i]->id == id) { - return i; + return int (i) == index; } ++i; } - assert (false); + return false; } AVStream * diff --git a/src/lib/ffmpeg_content.h b/src/lib/ffmpeg_content.h index b1f2abcea..d1aa3a0b5 100644 --- a/src/lib/ffmpeg_content.h +++ b/src/lib/ffmpeg_content.h @@ -46,9 +46,10 @@ public: void as_xml (xmlpp::Node *) const; /** @param c An AVFormatContext. - * @return Stream index within the AVFormatContext. + * @param index A stream index within the AVFormatContext. + * @return true if this FFmpegStream uses the given stream index. */ - int index (AVFormatContext const * c) const; + bool uses_index (AVFormatContext const * c, int index) const; AVStream* stream (AVFormatContext const * c) const; std::string name; diff --git a/src/lib/ffmpeg_decoder.cc b/src/lib/ffmpeg_decoder.cc index 587c79495..16da64c60 100644 --- a/src/lib/ffmpeg_decoder.cc +++ b/src/lib/ffmpeg_decoder.cc @@ -172,9 +172,9 @@ FFmpegDecoder::pass () if (si == _video_stream && _decode_video) { decode_video_packet (); - } else if (_ffmpeg_content->audio_stream() && si == _ffmpeg_content->audio_stream()->index (_format_context) && _decode_audio) { + } else if (_ffmpeg_content->audio_stream() && _ffmpeg_content->audio_stream()->uses_index (_format_context, si) && _decode_audio) { decode_audio_packet (); - } else if (_ffmpeg_content->subtitle_stream() && si == _ffmpeg_content->subtitle_stream()->index (_format_context) && film->with_subtitles ()) { + } else if (_ffmpeg_content->subtitle_stream() && _ffmpeg_content->subtitle_stream()->uses_index (_format_context, si) && film->with_subtitles ()) { decode_subtitle_packet (); } diff --git a/src/lib/ffmpeg_examiner.cc b/src/lib/ffmpeg_examiner.cc index a63090d12..ec090ed61 100644 --- a/src/lib/ffmpeg_examiner.cc +++ b/src/lib/ffmpeg_examiner.cc @@ -75,13 +75,13 @@ FFmpegExaminer::FFmpegExaminer (shared_ptr<const FFmpegContent> c) if (_packet.stream_index == _video_stream && !_first_video) { if (avcodec_decode_video2 (context, _frame, &frame_finished, &_packet) >= 0 && frame_finished) { - _first_video = frame_time (_video_stream); + _first_video = frame_time (_format_context->streams[_video_stream]); } } else { for (size_t i = 0; i < _audio_streams.size(); ++i) { - if (_packet.stream_index == _audio_streams[i]->index (_format_context) && !_audio_streams[i]->first_audio) { + if (_audio_streams[i]->uses_index (_format_context, _packet.stream_index) && !_audio_streams[i]->first_audio) { if (avcodec_decode_audio4 (context, _frame, &frame_finished, &_packet) >= 0 && frame_finished) { - _audio_streams[i]->first_audio = frame_time (_audio_streams[i]->index (_format_context)); + _audio_streams[i]->first_audio = frame_time (_audio_streams[i]->stream (_format_context)); } } } @@ -103,13 +103,13 @@ FFmpegExaminer::FFmpegExaminer (shared_ptr<const FFmpegContent> c) } optional<double> -FFmpegExaminer::frame_time (int stream) const +FFmpegExaminer::frame_time (AVStream* s) const { optional<double> t; int64_t const bet = av_frame_get_best_effort_timestamp (_frame); if (bet != AV_NOPTS_VALUE) { - t = bet * av_q2d (_format_context->streams[stream]->time_base); + t = bet * av_q2d (s->time_base); } return t; diff --git a/src/lib/ffmpeg_examiner.h b/src/lib/ffmpeg_examiner.h index 4de475d2a..369dac29c 100644 --- a/src/lib/ffmpeg_examiner.h +++ b/src/lib/ffmpeg_examiner.h @@ -49,7 +49,7 @@ private: std::string stream_name (AVStream* s) const; std::string audio_stream_name (AVStream* s) const; std::string subtitle_stream_name (AVStream* s) const; - boost::optional<double> frame_time (int) const; + boost::optional<double> frame_time (AVStream* s) const; std::vector<boost::shared_ptr<FFmpegSubtitleStream> > _subtitle_streams; std::vector<boost::shared_ptr<FFmpegAudioStream> > _audio_streams; |
