+
+void
+Player::emit_black ()
+{
+#ifdef DCPOMATIC_DEBUG
+ _last_video.reset ();
+#endif
+
+ Video (_black_frame, EYES_BOTH, ColourConversion(), _last_emit_was_black, _video_position);
+ _video_position += _film->video_frames_to_time (1);
+ _last_emit_was_black = true;
+}
+
+void
+Player::emit_silence (OutputAudioFrame most)
+{
+ if (most == 0) {
+ return;
+ }
+
+ OutputAudioFrame N = min (most, _film->audio_frame_rate() / 2);
+ shared_ptr<AudioBuffers> silence (new AudioBuffers (_film->audio_channels(), N));
+ silence->make_silent ();
+ Audio (silence, _audio_position);
+ _audio_position += _film->audio_frames_to_time (N);
+}
+
+void
+Player::film_changed (Film::Property p)
+{
+ /* Here we should notice Film properties that affect our output, and
+ alert listeners that our output now would be different to how it was
+ last time we were run.
+ */
+
+ if (p == Film::SCALER || p == Film::WITH_SUBTITLES || p == Film::CONTAINER) {
+ Changed (false);
+ }
+}
+
+void
+Player::process_subtitle (weak_ptr<Piece> weak_piece, shared_ptr<Image> image, dcpomatic::Rect<double> rect, Time from, Time to)
+{
+ _in_subtitle.piece = weak_piece;
+ _in_subtitle.image = image;
+ _in_subtitle.rect = rect;
+ _in_subtitle.from = from;
+ _in_subtitle.to = to;
+
+ update_subtitle ();
+}
+
+void
+Player::update_subtitle ()
+{
+ shared_ptr<Piece> piece = _in_subtitle.piece.lock ();
+ if (!piece) {
+ return;
+ }
+
+ if (!_in_subtitle.image) {
+ _out_subtitle.image.reset ();
+ return;
+ }
+
+ shared_ptr<SubtitleContent> sc = dynamic_pointer_cast<SubtitleContent> (piece->content);
+ assert (sc);
+
+ dcpomatic::Rect<double> in_rect = _in_subtitle.rect;
+ libdcp::Size scaled_size;
+
+ in_rect.y += sc->subtitle_offset ();
+
+ /* We will scale the subtitle up to fit _video_container_size, and also by the additional subtitle_scale */
+ scaled_size.width = in_rect.width * _video_container_size.width * sc->subtitle_scale ();
+ scaled_size.height = in_rect.height * _video_container_size.height * sc->subtitle_scale ();
+
+ /* Then we need a corrective translation, consisting of two parts:
+ *
+ * 1. that which is the result of the scaling of the subtitle by _video_container_size; this will be
+ * rect.x * _video_container_size.width and rect.y * _video_container_size.height.
+ *
+ * 2. that to shift the origin of the scale by subtitle_scale to the centre of the subtitle; this will be
+ * (width_before_subtitle_scale * (1 - subtitle_scale) / 2) and
+ * (height_before_subtitle_scale * (1 - subtitle_scale) / 2).
+ *
+ * Combining these two translations gives these expressions.
+ */
+
+ _out_subtitle.position.x = rint (_video_container_size.width * (in_rect.x + (in_rect.width * (1 - sc->subtitle_scale ()) / 2)));
+ _out_subtitle.position.y = rint (_video_container_size.height * (in_rect.y + (in_rect.height * (1 - sc->subtitle_scale ()) / 2)));
+
+ _out_subtitle.image = _in_subtitle.image->scale (
+ scaled_size,
+ Scaler::from_id ("bicubic"),
+ _in_subtitle.image->pixel_format (),
+ true
+ );
+ _out_subtitle.from = _in_subtitle.from + piece->content->position ();
+ _out_subtitle.to = _in_subtitle.to + piece->content->position ();
+}
+
+/** Re-emit the last frame that was emitted, using current settings for crop, ratio, scaler and subtitles.
+ * @return false if this could not be done.
+ */
+bool
+Player::repeat_last_video ()
+{
+ if (!_last_incoming_video.image) {
+ return false;
+ }
+
+ process_video (
+ _last_incoming_video.weak_piece,
+ _last_incoming_video.image,
+ _last_incoming_video.eyes,
+ _last_incoming_video.same,
+ _last_incoming_video.frame,
+ _last_incoming_video.extra
+ );
+
+ return true;
+}