summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2015-10-16 14:38:44 +0100
committerCarl Hetherington <cth@carlh.net>2015-10-16 14:38:44 +0100
commit9e025d3f85f9d6d855b3d5e6c90bca0eac3a3d49 (patch)
treeafc3e4a093a357bc7144a554c139e71b05fca9c5 /src/lib
parente7811b466eff496db7f63842df2fa4a4410afe14 (diff)
Avoid decoding other packets when looking for subs.
The "accumulation" of, for example, video data when we are looking for audio data is an *optimisation* to reduce the number of seeks. It should not be necessary for correctness (the output should be right even if we never kept anything except what we were looking for). Doing this accumulation is not always an optimisation; sometimes not doing it is better. Avoiding it when going back for subtitles is one of these cases.
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/audio_decoder_stream.cc4
-rw-r--r--src/lib/dcp_decoder.cc6
-rw-r--r--src/lib/dcp_decoder.h2
-rw-r--r--src/lib/dcp_subtitle_decoder.cc2
-rw-r--r--src/lib/dcp_subtitle_decoder.h2
-rw-r--r--src/lib/decoder.h8
-rw-r--r--src/lib/ffmpeg_decoder.cc6
-rw-r--r--src/lib/ffmpeg_decoder.h2
-rw-r--r--src/lib/image_decoder.cc2
-rw-r--r--src/lib/image_decoder.h2
-rw-r--r--src/lib/sndfile_decoder.cc2
-rw-r--r--src/lib/sndfile_decoder.h2
-rw-r--r--src/lib/subrip_decoder.cc2
-rw-r--r--src/lib/subrip_decoder.h2
-rw-r--r--src/lib/subtitle_decoder.cc2
-rw-r--r--src/lib/video_decoder.cc4
16 files changed, 28 insertions, 22 deletions
diff --git a/src/lib/audio_decoder_stream.cc b/src/lib/audio_decoder_stream.cc
index 274bf2d54..4d1a5e4c5 100644
--- a/src/lib/audio_decoder_stream.cc
+++ b/src/lib/audio_decoder_stream.cc
@@ -87,7 +87,7 @@ AudioDecoderStream::get (Frame frame, Frame length, bool accurate)
/* Keep stuffing data into _decoded until we have enough data, or the subclass does not want to give us any more */
while (
(_decoded.frame > frame || (_decoded.frame + _decoded.audio->frames()) < end) &&
- !_decoder->pass ()
+ !_decoder->pass (Decoder::PASS_REASON_AUDIO)
)
{}
@@ -95,7 +95,7 @@ AudioDecoderStream::get (Frame frame, Frame length, bool accurate)
} else {
while (
_decoded.audio->frames() < length &&
- !_decoder->pass ()
+ !_decoder->pass (Decoder::PASS_REASON_AUDIO)
)
{}
diff --git a/src/lib/dcp_decoder.cc b/src/lib/dcp_decoder.cc
index 21eb2f7ea..ada0d01d1 100644
--- a/src/lib/dcp_decoder.cc
+++ b/src/lib/dcp_decoder.cc
@@ -59,7 +59,7 @@ DCPDecoder::DCPDecoder (shared_ptr<const DCPContent> c, bool fast)
}
bool
-DCPDecoder::pass ()
+DCPDecoder::pass (PassReason reason)
{
if (_reel == _reels.end () || !_dcp_content->can_be_played ()) {
return true;
@@ -68,7 +68,7 @@ DCPDecoder::pass ()
double const vfr = _dcp_content->video_frame_rate ();
int64_t const frame = _next.frames_round (vfr);
- if ((*_reel)->main_picture ()) {
+ if ((*_reel)->main_picture () && reason != PASS_REASON_SUBTITLE) {
shared_ptr<dcp::PictureAsset> asset = (*_reel)->main_picture()->asset ();
shared_ptr<dcp::MonoPictureAsset> mono = dynamic_pointer_cast<dcp::MonoPictureAsset> (asset);
shared_ptr<dcp::StereoPictureAsset> stereo = dynamic_pointer_cast<dcp::StereoPictureAsset> (asset);
@@ -88,7 +88,7 @@ DCPDecoder::pass ()
}
}
- if ((*_reel)->main_sound ()) {
+ if ((*_reel)->main_sound () && reason != PASS_REASON_SUBTITLE) {
int64_t const entry_point = (*_reel)->main_sound()->entry_point ();
shared_ptr<const dcp::SoundFrame> sf = (*_reel)->main_sound()->asset()->get_frame (entry_point + frame);
uint8_t const * from = sf->data ();
diff --git a/src/lib/dcp_decoder.h b/src/lib/dcp_decoder.h
index 6fdbd946a..8ec80c2af 100644
--- a/src/lib/dcp_decoder.h
+++ b/src/lib/dcp_decoder.h
@@ -44,7 +44,7 @@ public:
private:
friend struct dcp_subtitle_within_dcp_test;
- bool pass ();
+ bool pass (PassReason);
void seek (ContentTime t, bool accurate);
std::list<ContentTimePeriod> image_subtitles_during (ContentTimePeriod, bool starting) const;
diff --git a/src/lib/dcp_subtitle_decoder.cc b/src/lib/dcp_subtitle_decoder.cc
index 1c6b973d6..0f1cda209 100644
--- a/src/lib/dcp_subtitle_decoder.cc
+++ b/src/lib/dcp_subtitle_decoder.cc
@@ -47,7 +47,7 @@ DCPSubtitleDecoder::seek (ContentTime time, bool accurate)
}
bool
-DCPSubtitleDecoder::pass ()
+DCPSubtitleDecoder::pass (PassReason)
{
if (_next == _subtitles.end ()) {
return true;
diff --git a/src/lib/dcp_subtitle_decoder.h b/src/lib/dcp_subtitle_decoder.h
index fb2213fa2..30bb896e0 100644
--- a/src/lib/dcp_subtitle_decoder.h
+++ b/src/lib/dcp_subtitle_decoder.h
@@ -28,7 +28,7 @@ public:
DCPSubtitleDecoder (boost::shared_ptr<const DCPSubtitleContent>);
protected:
- bool pass ();
+ bool pass (PassReason);
void seek (ContentTime time, bool accurate);
private:
diff --git a/src/lib/decoder.h b/src/lib/decoder.h
index 8378373c6..9e5573662 100644
--- a/src/lib/decoder.h
+++ b/src/lib/decoder.h
@@ -51,7 +51,13 @@ protected:
*/
virtual void seek (ContentTime time, bool accurate) = 0;
- virtual bool pass () = 0;
+ enum PassReason {
+ PASS_REASON_VIDEO,
+ PASS_REASON_AUDIO,
+ PASS_REASON_SUBTITLE
+ };
+
+ virtual bool pass (PassReason) = 0;
};
#endif
diff --git a/src/lib/ffmpeg_decoder.cc b/src/lib/ffmpeg_decoder.cc
index 72a3d02b4..ee9d9eecb 100644
--- a/src/lib/ffmpeg_decoder.cc
+++ b/src/lib/ffmpeg_decoder.cc
@@ -89,7 +89,7 @@ FFmpegDecoder::flush ()
}
bool
-FFmpegDecoder::pass ()
+FFmpegDecoder::pass (PassReason reason)
{
int r = av_read_frame (_format_context, &_packet);
@@ -112,11 +112,11 @@ FFmpegDecoder::pass ()
int const si = _packet.stream_index;
shared_ptr<const FFmpegContent> fc = _ffmpeg_content;
- if (si == _video_stream && !_ignore_video) {
+ if (si == _video_stream && !_ignore_video && reason != PASS_REASON_SUBTITLE) {
decode_video_packet ();
} else if (fc->subtitle_stream() && fc->subtitle_stream()->uses_index (_format_context, si)) {
decode_subtitle_packet ();
- } else {
+ } else if (reason != PASS_REASON_SUBTITLE) {
decode_audio_packet ();
}
diff --git a/src/lib/ffmpeg_decoder.h b/src/lib/ffmpeg_decoder.h
index 5475be612..ce5267936 100644
--- a/src/lib/ffmpeg_decoder.h
+++ b/src/lib/ffmpeg_decoder.h
@@ -49,7 +49,7 @@ public:
private:
friend struct ::ffmpeg_pts_offset_test;
- bool pass ();
+ bool pass (PassReason);
void seek (ContentTime time, bool);
void flush ();
diff --git a/src/lib/image_decoder.cc b/src/lib/image_decoder.cc
index db7c5401f..94c0dfd45 100644
--- a/src/lib/image_decoder.cc
+++ b/src/lib/image_decoder.cc
@@ -43,7 +43,7 @@ ImageDecoder::ImageDecoder (shared_ptr<const ImageContent> c)
}
bool
-ImageDecoder::pass ()
+ImageDecoder::pass (PassReason)
{
if (_video_position >= _image_content->video_length()) {
return true;
diff --git a/src/lib/image_decoder.h b/src/lib/image_decoder.h
index 4d96306a8..4ce75a20d 100644
--- a/src/lib/image_decoder.h
+++ b/src/lib/image_decoder.h
@@ -31,7 +31,7 @@ public:
}
private:
- bool pass ();
+ bool pass (PassReason);
void seek (ContentTime, bool);
boost::shared_ptr<const ImageContent> _image_content;
diff --git a/src/lib/sndfile_decoder.cc b/src/lib/sndfile_decoder.cc
index 49633dd1f..7986e3c73 100644
--- a/src/lib/sndfile_decoder.cc
+++ b/src/lib/sndfile_decoder.cc
@@ -48,7 +48,7 @@ SndfileDecoder::~SndfileDecoder ()
}
bool
-SndfileDecoder::pass ()
+SndfileDecoder::pass (PassReason)
{
if (_remaining == 0) {
return true;
diff --git a/src/lib/sndfile_decoder.h b/src/lib/sndfile_decoder.h
index da9016ee0..a9d2935b6 100644
--- a/src/lib/sndfile_decoder.h
+++ b/src/lib/sndfile_decoder.h
@@ -29,7 +29,7 @@ public:
~SndfileDecoder ();
private:
- bool pass ();
+ bool pass (PassReason);
void seek (ContentTime, bool);
int64_t _done;
diff --git a/src/lib/subrip_decoder.cc b/src/lib/subrip_decoder.cc
index 32d50d86b..3c93292a1 100644
--- a/src/lib/subrip_decoder.cc
+++ b/src/lib/subrip_decoder.cc
@@ -49,7 +49,7 @@ SubRipDecoder::seek (ContentTime time, bool accurate)
}
bool
-SubRipDecoder::pass ()
+SubRipDecoder::pass (PassReason)
{
if (_next >= _subtitles.size ()) {
return true;
diff --git a/src/lib/subrip_decoder.h b/src/lib/subrip_decoder.h
index db8374c5c..b899b5dd8 100644
--- a/src/lib/subrip_decoder.h
+++ b/src/lib/subrip_decoder.h
@@ -32,7 +32,7 @@ public:
protected:
void seek (ContentTime time, bool accurate);
- bool pass ();
+ bool pass (PassReason);
private:
std::list<ContentTimePeriod> image_subtitles_during (ContentTimePeriod, bool starting) const;
diff --git a/src/lib/subtitle_decoder.cc b/src/lib/subtitle_decoder.cc
index a95964f47..30b8661ae 100644
--- a/src/lib/subtitle_decoder.cc
+++ b/src/lib/subtitle_decoder.cc
@@ -79,7 +79,7 @@ SubtitleDecoder::get (list<T> const & subs, list<ContentTimePeriod> const & sp,
* (a) give us what we want, or
* (b) hit the end of the decoder.
*/
- while (!pass () && (subs.empty() || (subs.back().period().to < sp.back().to))) {}
+ while (!pass(PASS_REASON_SUBTITLE) && (subs.empty() || (subs.back().period().to < sp.back().to))) {}
/* Now look for what we wanted in the data we have collected */
/* XXX: inefficient */
diff --git a/src/lib/video_decoder.cc b/src/lib/video_decoder.cc
index 02f8fa0ac..4b9272413 100644
--- a/src/lib/video_decoder.cc
+++ b/src/lib/video_decoder.cc
@@ -98,7 +98,7 @@ VideoDecoder::get_video (Frame frame, bool accurate)
break;
}
- if (pass ()) {
+ if (pass (PASS_REASON_VIDEO)) {
/* The decoder has nothing more for us */
break;
}
@@ -115,7 +115,7 @@ VideoDecoder::get_video (Frame frame, bool accurate)
dec = decoded_video (frame);
} else {
/* Any frame will do: use the first one that comes out of pass() */
- while (_decoded_video.empty() && !pass ()) {}
+ while (_decoded_video.empty() && !pass (PASS_REASON_VIDEO)) {}
if (!_decoded_video.empty ()) {
dec.push_back (_decoded_video.front ());
}