Remove PassReason stuff.
[dcpomatic.git] / src / lib / dcp_subtitle_decoder.cc
1 /*
2     Copyright (C) 2014 Carl Hetherington <cth@carlh.net>
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #include "dcp_subtitle_decoder.h"
21 #include "dcp_subtitle_content.h"
22 #include <dcp/interop_subtitle_asset.h>
23
24 using std::list;
25 using std::cout;
26 using boost::shared_ptr;
27
28 DCPSubtitleDecoder::DCPSubtitleDecoder (shared_ptr<const DCPSubtitleContent> content)
29         : SubtitleDecoder (content)
30 {
31         shared_ptr<dcp::SubtitleAsset> c (load (content->path (0)));
32         _subtitles = c->subtitles ();
33         _next = _subtitles.begin ();
34 }
35
36 void
37 DCPSubtitleDecoder::seek (ContentTime time, bool accurate)
38 {
39         SubtitleDecoder::seek (time, accurate);
40
41         _next = _subtitles.begin ();
42         list<dcp::SubtitleString>::const_iterator i = _subtitles.begin ();
43         while (i != _subtitles.end() && ContentTime::from_seconds (_next->in().as_seconds()) < time) {
44                 ++i;
45         }
46 }
47
48 bool
49 DCPSubtitleDecoder::pass ()
50 {
51         if (_next == _subtitles.end ()) {
52                 return true;
53         }
54
55         list<dcp::SubtitleString> s;
56         s.push_back (*_next);
57         text_subtitle (s);
58         ++_next;
59
60         return false;
61 }
62
63 list<ContentTimePeriod>
64 DCPSubtitleDecoder::image_subtitles_during (ContentTimePeriod, bool) const
65 {
66         return list<ContentTimePeriod> ();
67 }
68         
69 list<ContentTimePeriod>
70 DCPSubtitleDecoder::text_subtitles_during (ContentTimePeriod p, bool starting) const
71 {
72         /* XXX: inefficient */
73
74         list<ContentTimePeriod> d;
75
76         for (list<dcp::SubtitleString>::const_iterator i = _subtitles.begin(); i != _subtitles.end(); ++i) {
77                 ContentTimePeriod period (
78                         ContentTime::from_seconds (i->in().as_seconds ()),
79                         ContentTime::from_seconds (i->out().as_seconds ())
80                         );
81                 
82                 if ((starting && p.contains (period.from)) || (!starting && p.overlaps (period))) {
83                         d.push_back (period);
84                 }
85         }
86
87         return d;
88 }
89