From 6a68937320fa76ce213c648845abc73983fc1849 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Wed, 13 Dec 2017 22:04:49 +0000 Subject: [PATCH] Setup SubtitleDecoder::_position correctly (in some cases). --- src/lib/dcp_decoder.cc | 3 ++- src/lib/dcp_subtitle_decoder.cc | 8 ++++++-- src/lib/ffmpeg_decoder.cc | 3 ++- src/lib/subtitle_decoder.cc | 4 +++- src/lib/subtitle_decoder.h | 7 ++----- src/lib/text_subtitle_decoder.cc | 6 +++++- 6 files changed, 20 insertions(+), 11 deletions(-) diff --git a/src/lib/dcp_decoder.cc b/src/lib/dcp_decoder.cc index 44053c5df..1a4896fe7 100644 --- a/src/lib/dcp_decoder.cc +++ b/src/lib/dcp_decoder.cc @@ -59,7 +59,8 @@ DCPDecoder::DCPDecoder (shared_ptr c, shared_ptr log, boo audio.reset (new AudioDecoder (this, c->audio, log, fast)); } if (c->subtitle) { - subtitle.reset (new SubtitleDecoder (this, c->subtitle, log)); + /* XXX: this time here should be the time of the first subtitle, not 0 */ + subtitle.reset (new SubtitleDecoder (this, c->subtitle, log, ContentTime())); } shared_ptr cpl; diff --git a/src/lib/dcp_subtitle_decoder.cc b/src/lib/dcp_subtitle_decoder.cc index 04b264192..965f9db61 100644 --- a/src/lib/dcp_subtitle_decoder.cc +++ b/src/lib/dcp_subtitle_decoder.cc @@ -30,11 +30,15 @@ using boost::bind; DCPSubtitleDecoder::DCPSubtitleDecoder (shared_ptr content, shared_ptr log) { - subtitle.reset (new SubtitleDecoder (this, content->subtitle, log)); - shared_ptr c (load (content->path (0))); _subtitles = c->subtitles (); _next = _subtitles.begin (); + + ContentTime first; + if (_next != _subtitles.end()) { + first = content_time_period(*_next).from; + } + subtitle.reset (new SubtitleDecoder (this, content->subtitle, log, first)); } void diff --git a/src/lib/ffmpeg_decoder.cc b/src/lib/ffmpeg_decoder.cc index 378b59901..0d6ac383f 100644 --- a/src/lib/ffmpeg_decoder.cc +++ b/src/lib/ffmpeg_decoder.cc @@ -98,7 +98,8 @@ FFmpegDecoder::FFmpegDecoder (shared_ptr c, shared_ptr } if (c->subtitle) { - subtitle.reset (new SubtitleDecoder (this, c->subtitle, log)); + /* XXX: this time here should be the time of the first subtitle, not 0 */ + subtitle.reset (new SubtitleDecoder (this, c->subtitle, log, ContentTime())); } _next_time.resize (_format_context->nb_streams); diff --git a/src/lib/subtitle_decoder.cc b/src/lib/subtitle_decoder.cc index 802c9ef84..5838d167b 100644 --- a/src/lib/subtitle_decoder.cc +++ b/src/lib/subtitle_decoder.cc @@ -40,10 +40,12 @@ using boost::function; SubtitleDecoder::SubtitleDecoder ( Decoder* parent, shared_ptr c, - shared_ptr log + shared_ptr log, + ContentTime first ) : DecoderPart (parent, log) , _content (c) + , _position (first) { } diff --git a/src/lib/subtitle_decoder.h b/src/lib/subtitle_decoder.h index 9740b06e8..c1f171b1f 100644 --- a/src/lib/subtitle_decoder.h +++ b/src/lib/subtitle_decoder.h @@ -38,14 +38,11 @@ class Image; class SubtitleDecoder : public DecoderPart { public: - /** Second parameter to the _during functions is true if we - * want only subtitles that start during the period, - * otherwise we want subtitles that overlap the period. - */ SubtitleDecoder ( Decoder* parent, boost::shared_ptr, - boost::shared_ptr log + boost::shared_ptr log, + ContentTime first ); ContentTime position () const { diff --git a/src/lib/text_subtitle_decoder.cc b/src/lib/text_subtitle_decoder.cc index 846c3016e..6188d524f 100644 --- a/src/lib/text_subtitle_decoder.cc +++ b/src/lib/text_subtitle_decoder.cc @@ -38,7 +38,11 @@ TextSubtitleDecoder::TextSubtitleDecoder (shared_ptr : TextSubtitle (content) , _next (0) { - subtitle.reset (new SubtitleDecoder (this, content->subtitle, log)); + ContentTime first; + if (!_subtitles.empty()) { + first = content_time_period(_subtitles[0]).from; + } + subtitle.reset (new SubtitleDecoder (this, content->subtitle, log, first)); } void -- 2.30.2