summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2014-07-02 18:10:58 +0100
committerCarl Hetherington <cth@carlh.net>2014-07-02 18:10:58 +0100
commitc88a8a6ec6b396dc90d40a4843160d616a45db76 (patch)
treeb58c18fdb6c7946446ae244747fa7b4461fd9661 /src/lib
parent712f8144f1992364d79a80b2b586248423f7ac11 (diff)
Hopefully improve subtitle decoder seeking etc.
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/dcpomatic_time.cc2
-rw-r--r--src/lib/ffmpeg_content.cc14
-rw-r--r--src/lib/ffmpeg_content.h2
-rw-r--r--src/lib/ffmpeg_decoder.cc6
-rw-r--r--src/lib/ffmpeg_decoder.h2
-rw-r--r--src/lib/subrip_decoder.cc10
-rw-r--r--src/lib/subrip_decoder.h2
-rw-r--r--src/lib/subtitle_decoder.cc13
-rw-r--r--src/lib/subtitle_decoder.h2
9 files changed, 30 insertions, 23 deletions
diff --git a/src/lib/dcpomatic_time.cc b/src/lib/dcpomatic_time.cc
index ae4dea44f..dcdfd97da 100644
--- a/src/lib/dcpomatic_time.cc
+++ b/src/lib/dcpomatic_time.cc
@@ -53,5 +53,5 @@ operator<< (ostream& s, DCPTime t)
bool
ContentTimePeriod::overlaps (ContentTimePeriod const & other) const
{
- return (from < other.to && to > other.from);
+ return (from < other.to && to >= other.from);
}
diff --git a/src/lib/ffmpeg_content.cc b/src/lib/ffmpeg_content.cc
index a12f45a30..f97e324bb 100644
--- a/src/lib/ffmpeg_content.cc
+++ b/src/lib/ffmpeg_content.cc
@@ -396,20 +396,22 @@ FFmpegContent::audio_analysis_path () const
return p;
}
-bool
-FFmpegContent::has_subtitle_during (ContentTimePeriod period) const
+list<ContentTimePeriod>
+FFmpegContent::subtitles_during (ContentTimePeriod period) const
{
+ list<ContentTimePeriod> d;
+
shared_ptr<FFmpegSubtitleStream> stream = subtitle_stream ();
if (!stream) {
- return false;
+ return d;
}
/* XXX: inefficient */
for (vector<ContentTimePeriod>::const_iterator i = stream->periods.begin(); i != stream->periods.end(); ++i) {
- if (i->from <= period.to && i->to >= period.from) {
- return true;
+ if (period.overlaps (*i)) {
+ d.push_back (*i);
}
}
- return false;
+ return d;
}
diff --git a/src/lib/ffmpeg_content.h b/src/lib/ffmpeg_content.h
index 367c30103..dbb207959 100644
--- a/src/lib/ffmpeg_content.h
+++ b/src/lib/ffmpeg_content.h
@@ -108,7 +108,7 @@ public:
return _first_video;
}
- bool has_subtitle_during (ContentTimePeriod) const;
+ std::list<ContentTimePeriod> subtitles_during (ContentTimePeriod) const;
private:
friend class ffmpeg_pts_offset_test;
diff --git a/src/lib/ffmpeg_decoder.cc b/src/lib/ffmpeg_decoder.cc
index 885bd0e85..668cab885 100644
--- a/src/lib/ffmpeg_decoder.cc
+++ b/src/lib/ffmpeg_decoder.cc
@@ -481,8 +481,8 @@ FFmpegDecoder::decode_subtitle_packet ()
avsubtitle_free (&sub);
}
-bool
-FFmpegDecoder::has_subtitle_during (ContentTimePeriod p) const
+list<ContentTimePeriod>
+FFmpegDecoder::subtitles_during (ContentTimePeriod p) const
{
- return _ffmpeg_content->has_subtitle_during (p);
+ return _ffmpeg_content->subtitles_during (p);
}
diff --git a/src/lib/ffmpeg_decoder.h b/src/lib/ffmpeg_decoder.h
index d6cb8c246..15811d5b9 100644
--- a/src/lib/ffmpeg_decoder.h
+++ b/src/lib/ffmpeg_decoder.h
@@ -66,7 +66,7 @@ private:
void maybe_add_subtitle ();
boost::shared_ptr<AudioBuffers> deinterleave_audio (uint8_t** data, int size);
- bool has_subtitle_during (ContentTimePeriod) const;
+ std::list<ContentTimePeriod> subtitles_during (ContentTimePeriod) const;
boost::shared_ptr<Log> _log;
diff --git a/src/lib/subrip_decoder.cc b/src/lib/subrip_decoder.cc
index 3d971fd4b..370118d30 100644
--- a/src/lib/subrip_decoder.cc
+++ b/src/lib/subrip_decoder.cc
@@ -79,16 +79,18 @@ SubRipDecoder::pass ()
return false;
}
-bool
-SubRipDecoder::has_subtitle_during (ContentTimePeriod p) const
+list<ContentTimePeriod>
+SubRipDecoder::subtitles_during (ContentTimePeriod p) const
{
/* XXX: inefficient */
+ list<ContentTimePeriod> d;
+
for (vector<SubRipSubtitle>::const_iterator i = _subtitles.begin(); i != _subtitles.end(); ++i) {
if (p.overlaps (i->period)) {
- return true;
+ d.push_back (i->period);
}
}
- return false;
+ return d;
}
diff --git a/src/lib/subrip_decoder.h b/src/lib/subrip_decoder.h
index d6c6e6bc2..927ccc728 100644
--- a/src/lib/subrip_decoder.h
+++ b/src/lib/subrip_decoder.h
@@ -35,7 +35,7 @@ protected:
bool pass ();
private:
- bool has_subtitle_during (ContentTimePeriod) const;
+ std::list<ContentTimePeriod> subtitles_during (ContentTimePeriod) const;
size_t _next;
};
diff --git a/src/lib/subtitle_decoder.cc b/src/lib/subtitle_decoder.cc
index 1b789fdab..b8cb3e5c8 100644
--- a/src/lib/subtitle_decoder.cc
+++ b/src/lib/subtitle_decoder.cc
@@ -51,20 +51,23 @@ template <class T>
list<T>
SubtitleDecoder::get (list<T> const & subs, ContentTimePeriod period)
{
- if (!has_subtitle_during (period)) {
+ /* Get the full periods of the subtitles that are showing during the specified period */
+ list<ContentTimePeriod> sp = subtitles_during (period);
+ if (sp.empty ()) {
+ /* Nothing in this period */
return list<T> ();
}
- if (subs.empty() || period.from < subs.front().period().from || period.to > (subs.back().period().to + ContentTime::from_seconds (10))) {
- /* Either we have no decoded data, or what we do have is a long way from what we want: seek */
- seek (period.from, true);
+ /* Seek if what we want is before what we have, or more than a reasonable amount after */
+ if (subs.empty() || sp.back().to < subs.front().period().from || sp.front().from > (subs.back().period().to + ContentTime::from_seconds (5))) {
+ seek (sp.front().from, true);
}
/* Now enough pass() calls will either:
* (a) give us what we want, or
* (b) hit the end of the decoder.
*/
- while (!pass() && (subs.empty() || (subs.front().period().from > period.from || period.to < subs.back().period().to))) {}
+ while (!pass() && (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/subtitle_decoder.h b/src/lib/subtitle_decoder.h
index 3f06afae3..51faca97f 100644
--- a/src/lib/subtitle_decoder.h
+++ b/src/lib/subtitle_decoder.h
@@ -51,7 +51,7 @@ private:
template <class T>
std::list<T> get (std::list<T> const & subs, ContentTimePeriod period);
- virtual bool has_subtitle_during (ContentTimePeriod) const = 0;
+ virtual std::list<ContentTimePeriod> subtitles_during (ContentTimePeriod) const = 0;
boost::shared_ptr<const SubtitleContent> _subtitle_content;
};