+/** @param burnt true to return only subtitles to be burnt, false to return only
+ * subtitles that should not be burnt. This parameter will be ignored if
+ * _always_burn_subtitles is true; in this case, all subtitles will be returned.
+ */
+PlayerSubtitles
+Player::get_subtitles (DCPTime time, DCPTime length, bool starting, bool burnt, bool accurate)
+{
+ 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 () || (!_always_burn_subtitles && (burnt != subtitle_content->burn_subtitles ()))) {
+ continue;
+ }
+
+ shared_ptr<DCPContent> dcp_content = dynamic_pointer_cast<DCPContent> (subtitle_content);
+ if (dcp_content && dcp_content->reference_subtitle () && !_play_referenced) {
+ 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, accurate);
+ 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, accurate);
+ BOOST_FOREACH (ContentTextSubtitle& ts, text) {
+ BOOST_FOREACH (dcp::SubtitleString s, ts.subs) {
+ s.set_h_position (s.h_position() + subtitle_content->subtitle_x_offset ());
+ s.set_v_position (s.v_position() + subtitle_content->subtitle_y_offset ());
+ float const xs = subtitle_content->subtitle_x_scale();
+ float const ys = subtitle_content->subtitle_y_scale();
+ float const average = s.size() * (xs + ys) / 2;
+ s.set_size (average);
+ if (fabs (1.0 - xs / ys) > dcp::ASPECT_ADJUST_EPSILON) {
+ s.set_aspect_adjust (xs / ys);
+ }
+ s.set_in (dcp::Time(content_subtitle_to_dcp (*j, ts.period().from).seconds(), 1000));
+ s.set_out (dcp::Time(content_subtitle_to_dcp (*j, ts.period().to).seconds(), 1000));
+ ps.text.push_back (s);
+ ps.add_fonts (subtitle_content->fonts ());
+ }
+ }
+ }
+
+ 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;
+}
+
+/** Set this player never to produce any audio data */
+void
+Player::set_ignore_audio ()
+{
+ _ignore_audio = true;
+}
+
+/** Set whether or not this player should always burn text subtitles into the image,
+ * regardless of the content settings.
+ * @param burn true to always burn subtitles, false to obey content settings.
+ */