bool
ContentTimePeriod::overlaps (ContentTimePeriod const & other) const
{
- return (from < other.to && to > other.from);
+ return (from < other.to && to >= other.from);
}
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;
}
return _first_video;
}
- bool has_subtitle_during (ContentTimePeriod) const;
+ std::list<ContentTimePeriod> subtitles_during (ContentTimePeriod) const;
private:
friend class ffmpeg_pts_offset_test;
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);
}
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;
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;
}
bool pass ();
private:
- bool has_subtitle_during (ContentTimePeriod) const;
+ std::list<ContentTimePeriod> subtitles_during (ContentTimePeriod) const;
size_t _next;
};
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 */
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;
};