+
+PlayerSubtitles
+Player::get_subtitles (DCPTime time, DCPTime length, bool starting)
+{
+ list<shared_ptr<Piece> > subs = overlaps<SubtitleContent> (time, time + length);
+
+ PlayerSubtitles ps (time, length);
+
+ for (list<shared_ptr<Piece> >::const_iterator j = subs.begin(); j != subs.end(); ++j) {
+ shared_ptr<SubtitleContent> subtitle_content = dynamic_pointer_cast<SubtitleContent> ((*j)->content);
+ if (!subtitle_content->use_subtitles ()) {
+ continue;
+ }
+
+ shared_ptr<SubtitleDecoder> subtitle_decoder = dynamic_pointer_cast<SubtitleDecoder> ((*j)->decoder);
+ ContentTime const from = dcp_to_content_subtitle (*j, time);
+ /* XXX: this video_frame_rate() should be the rate that the subtitle content has been prepared for */
+ ContentTime const to = from + ContentTime::from_frames (1, _film->video_frame_rate ());
+
+ list<ContentImageSubtitle> image = subtitle_decoder->get_image_subtitles (ContentTimePeriod (from, to), starting);
+ for (list<ContentImageSubtitle>::iterator i = image.begin(); i != image.end(); ++i) {
+
+ /* Apply content's subtitle offsets */
+ i->sub.rectangle.x += subtitle_content->subtitle_x_offset ();
+ i->sub.rectangle.y += subtitle_content->subtitle_y_offset ();
+
+ /* Apply content's subtitle scale */
+ i->sub.rectangle.width *= subtitle_content->subtitle_x_scale ();
+ i->sub.rectangle.height *= subtitle_content->subtitle_y_scale ();
+
+ /* Apply a corrective translation to keep the subtitle centred after that scale */
+ i->sub.rectangle.x -= i->sub.rectangle.width * (subtitle_content->subtitle_x_scale() - 1);
+ i->sub.rectangle.y -= i->sub.rectangle.height * (subtitle_content->subtitle_y_scale() - 1);
+
+ ps.image.push_back (i->sub);
+ }
+
+ list<ContentTextSubtitle> text = subtitle_decoder->get_text_subtitles (ContentTimePeriod (from, to), starting);
+ BOOST_FOREACH (ContentTextSubtitle& ts, text) {
+ BOOST_FOREACH (dcp::SubtitleString& s, ts.subs) {
+ s.set_v_position (s.v_position() + subtitle_content->subtitle_y_offset ());
+ s.set_size (s.size() * max (subtitle_content->subtitle_x_scale(), subtitle_content->subtitle_y_scale()));
+ ps.text.push_back (s);
+ }
+ }
+ }
+
+ return ps;
+}
+
+list<shared_ptr<Font> >
+Player::get_subtitle_fonts ()
+{
+ if (!_have_valid_pieces) {
+ setup_pieces ();
+ }
+
+ list<shared_ptr<Font> > fonts;
+ BOOST_FOREACH (shared_ptr<Piece>& p, _pieces) {
+ shared_ptr<SubtitleContent> sc = dynamic_pointer_cast<SubtitleContent> (p->content);
+ if (sc) {
+ /* XXX: things may go wrong if there are duplicate font IDs
+ with different font files.
+ */
+ list<shared_ptr<Font> > f = sc->fonts ();
+ copy (f.begin(), f.end(), back_inserter (fonts));
+ }
+ }
+
+ return fonts;
+}
+
+/** Set this player never to produce any video data */
+void
+Player::set_ignore_video ()
+{
+ _ignore_video = true;
+}