/*
- Copyright (C) 2013-2014 Carl Hetherington <cth@carlh.net>
+ Copyright (C) 2013-2017 Carl Hetherington <cth@carlh.net>
- This program is free software; you can redistribute it and/or modify
+ This file is part of DCP-o-matic.
+
+ DCP-o-matic is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
- This program is distributed in the hope that it will be useful,
+ DCP-o-matic is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ along with DCP-o-matic. If not, see <http://www.gnu.org/licenses/>.
*/
-#include <stdint.h>
#include "player.h"
#include "film.h"
-#include "ffmpeg_decoder.h"
-#include "ffmpeg_content.h"
-#include "image_decoder.h"
-#include "image_content.h"
-#include "sndfile_decoder.h"
-#include "sndfile_content.h"
-#include "subtitle_content.h"
-#include "playlist.h"
+#include "audio_buffers.h"
+#include "content_audio.h"
+#include "dcp_content.h"
#include "job.h"
#include "image.h"
-#include "image_proxy.h"
+#include "raw_image_proxy.h"
#include "ratio.h"
-#include "resampler.h"
#include "log.h"
-#include "scaler.h"
-#include "player_video_frame.h"
+#include "render_subtitles.h"
+#include "config.h"
+#include "content_video.h"
+#include "player_video.h"
#include "frame_rate_change.h"
+#include "audio_processor.h"
+#include "playlist.h"
+#include "referenced_reel_asset.h"
+#include "decoder_factory.h"
+#include "decoder.h"
+#include "video_decoder.h"
+#include "audio_decoder.h"
+#include "subtitle_content.h"
+#include "subtitle_decoder.h"
+#include "ffmpeg_content.h"
+#include "audio_content.h"
+#include "content_subtitle.h"
+#include "dcp_decoder.h"
+#include "image_decoder.h"
+#include "resampler.h"
+#include "compose.hpp"
+#include <dcp/reel.h>
+#include <dcp/reel_sound_asset.h>
+#include <dcp/reel_subtitle_asset.h>
+#include <dcp/reel_picture_asset.h>
+#include <boost/foreach.hpp>
+#include <stdint.h>
+#include <algorithm>
+#include <iostream>
+
+#include "i18n.h"
-#define LOG_GENERAL(...) _film->log()->log (String::compose (__VA_ARGS__), Log::TYPE_GENERAL);
+#define LOG_GENERAL(...) _film->log()->log (String::compose (__VA_ARGS__), LogEntry::TYPE_GENERAL);
using std::list;
using std::cout;
using std::min;
using std::max;
+using std::min;
using std::vector;
using std::pair;
using std::map;
+using std::make_pair;
+using std::copy;
using boost::shared_ptr;
using boost::weak_ptr;
using boost::dynamic_pointer_cast;
+using boost::optional;
+using boost::scoped_ptr;
-Player::Player (shared_ptr<const Film> f, shared_ptr<const Playlist> p)
- : _film (f)
- , _playlist (p)
- , _video (true)
- , _audio (true)
+Player::Player (shared_ptr<const Film> film, shared_ptr<const Playlist> playlist)
+ : _film (film)
+ , _playlist (playlist)
, _have_valid_pieces (false)
- , _video_position (0)
- , _audio_position (0)
- , _audio_merger (f->audio_channels(), bind (&Film::time_to_audio_frames, f.get(), _1), bind (&Film::audio_frames_to_time, f.get(), _1))
- , _last_emit_was_black (false)
+ , _ignore_video (false)
+ , _ignore_audio (false)
+ , _always_burn_subtitles (false)
+ , _fast (false)
+ , _play_referenced (false)
+ , _audio_merger (_film->audio_frame_rate())
{
- _playlist_changed_connection = _playlist->Changed.connect (bind (&Player::playlist_changed, this));
- _playlist_content_changed_connection = _playlist->ContentChanged.connect (bind (&Player::content_changed, this, _1, _2, _3));
_film_changed_connection = _film->Changed.connect (bind (&Player::film_changed, this, _1));
+ _playlist_changed_connection = _playlist->Changed.connect (bind (&Player::playlist_changed, this));
+ _playlist_content_changed_connection = _playlist->ContentChanged.connect (bind (&Player::playlist_content_changed, this, _1, _2, _3));
set_video_container_size (_film->frame_size ());
-}
-void
-Player::disable_video ()
-{
- _video = false;
+ film_changed (Film::AUDIO_PROCESSOR);
+
+ seek (DCPTime (), true);
}
void
-Player::disable_audio ()
+Player::setup_pieces ()
{
- _audio = false;
-}
+ _pieces.clear ();
-bool
-Player::pass ()
-{
- if (!_have_valid_pieces) {
- setup_pieces ();
- }
+ BOOST_FOREACH (shared_ptr<Content> i, _playlist->content ()) {
- Time earliest_t = TIME_MAX;
- shared_ptr<Piece> earliest;
- enum {
- VIDEO,
- AUDIO
- } type = VIDEO;
+ if (!i->paths_valid ()) {
+ continue;
+ }
+
+ shared_ptr<Decoder> decoder = decoder_factory (i, _film->log());
+ FrameRateChange frc (i->active_video_frame_rate(), _film->video_frame_rate());
- for (list<shared_ptr<Piece> >::iterator i = _pieces.begin(); i != _pieces.end(); ++i) {
- if ((*i)->decoder->done () || (*i)->content->length_after_trim() == 0) {
+ if (!decoder) {
+ /* Not something that we can decode; e.g. Atmos content */
continue;
}
- shared_ptr<VideoDecoder> vd = dynamic_pointer_cast<VideoDecoder> ((*i)->decoder);
- shared_ptr<AudioDecoder> ad = dynamic_pointer_cast<AudioDecoder> ((*i)->decoder);
+ if (decoder->video && _ignore_video) {
+ decoder->video->set_ignore ();
+ }
- if (_video && vd) {
- if ((*i)->video_position < earliest_t) {
- earliest_t = (*i)->video_position;
- earliest = *i;
- type = VIDEO;
- }
+ if (decoder->audio && _ignore_audio) {
+ decoder->audio->set_ignore ();
}
- if (_audio && ad && ad->has_audio ()) {
- if ((*i)->audio_position < earliest_t) {
- earliest_t = (*i)->audio_position;
- earliest = *i;
- type = AUDIO;
- }
+ shared_ptr<DCPDecoder> dcp = dynamic_pointer_cast<DCPDecoder> (decoder);
+ if (dcp && _play_referenced) {
+ dcp->set_decode_referenced ();
}
- }
- if (!earliest) {
- flush ();
- return true;
- }
+ shared_ptr<Piece> piece (new Piece (i, decoder, frc));
+ _pieces.push_back (piece);
- switch (type) {
- case VIDEO:
- if (earliest_t > _video_position) {
- emit_black ();
- } else {
- if (earliest->repeating ()) {
- earliest->repeat (this);
- } else {
- earliest->decoder->pass ();
- }
+ if (decoder->video) {
+ decoder->video->Data.connect (bind (&Player::video, this, weak_ptr<Piece> (piece), _1));
}
- break;
-
- case AUDIO:
- if (earliest_t > _audio_position) {
- emit_silence (_film->time_to_audio_frames (earliest_t - _audio_position));
- } else {
- earliest->decoder->pass ();
-
- if (earliest->decoder->done()) {
- shared_ptr<AudioContent> ac = dynamic_pointer_cast<AudioContent> (earliest->content);
- assert (ac);
- shared_ptr<Resampler> re = resampler (ac, false);
- if (re) {
- shared_ptr<const AudioBuffers> b = re->flush ();
- if (b->frames ()) {
- process_audio (
- earliest,
- b,
- ac->audio_length() * ac->output_audio_frame_rate() / ac->content_audio_frame_rate(),
- true
- );
- }
- }
- }
+
+ if (decoder->audio) {
+ decoder->audio->Data.connect (bind (&Player::audio, this, weak_ptr<Piece> (piece), _1, _2));
}
- break;
- }
- if (_audio) {
- boost::optional<Time> audio_done_up_to;
- for (list<shared_ptr<Piece> >::iterator i = _pieces.begin(); i != _pieces.end(); ++i) {
- if ((*i)->decoder->done ()) {
- continue;
- }
+ if (decoder->subtitle) {
+ decoder->subtitle->ImageData.connect (bind (&Player::image_subtitle, this, weak_ptr<Piece> (piece), _1));
+ decoder->subtitle->TextData.connect (bind (&Player::text_subtitle, this, weak_ptr<Piece> (piece), _1));
+ }
+ }
- shared_ptr<AudioDecoder> ad = dynamic_pointer_cast<AudioDecoder> ((*i)->decoder);
- if (ad && ad->has_audio ()) {
- audio_done_up_to = min (audio_done_up_to.get_value_or (TIME_MAX), (*i)->audio_position);
+ BOOST_FOREACH (shared_ptr<Piece> i, _pieces) {
+ if (i->content->audio) {
+ BOOST_FOREACH (AudioStreamPtr j, i->content->audio->streams()) {
+ _stream_states[j] = StreamState (i, i->content->position ());
}
}
+ }
- if (audio_done_up_to) {
- TimedAudioBuffers<Time> tb = _audio_merger.pull (audio_done_up_to.get ());
- Audio (tb.audio, tb.time);
- _audio_position += _film->audio_frames_to_time (tb.audio->frames ());
+ if (!_play_referenced) {
+ BOOST_FOREACH (shared_ptr<Piece> i, _pieces) {
+ shared_ptr<DCPContent> dc = dynamic_pointer_cast<DCPContent> (i->content);
+ if (dc) {
+ if (dc->reference_video()) {
+ _no_video.push_back (DCPTimePeriod (dc->position(), dc->end()));
+ }
+ if (dc->reference_audio()) {
+ _no_audio.push_back (DCPTimePeriod (dc->position(), dc->end()));
+ }
+ }
}
}
-
- return false;
+
+ _have_valid_pieces = true;
}
-/** @param extra Amount of extra time to add to the content frame's time (for repeat) */
void
-Player::process_video (weak_ptr<Piece> weak_piece, shared_ptr<const ImageProxy> image, Eyes eyes, Part part, bool same, VideoContent::Frame frame, Time extra)
-{
- /* Keep a note of what came in so that we can repeat it if required */
- _last_incoming_video.weak_piece = weak_piece;
- _last_incoming_video.image = image;
- _last_incoming_video.eyes = eyes;
- _last_incoming_video.part = part;
- _last_incoming_video.same = same;
- _last_incoming_video.frame = frame;
- _last_incoming_video.extra = extra;
-
- shared_ptr<Piece> piece = weak_piece.lock ();
- if (!piece) {
+Player::playlist_content_changed (weak_ptr<Content> w, int property, bool frequent)
+{
+ shared_ptr<Content> c = w.lock ();
+ if (!c) {
return;
}
- shared_ptr<VideoContent> content = dynamic_pointer_cast<VideoContent> (piece->content);
- assert (content);
+ if (
+ property == ContentProperty::POSITION ||
+ property == ContentProperty::LENGTH ||
+ property == ContentProperty::TRIM_START ||
+ property == ContentProperty::TRIM_END ||
+ property == ContentProperty::PATH ||
+ property == VideoContentProperty::FRAME_TYPE ||
+ property == DCPContentProperty::NEEDS_ASSETS ||
+ property == DCPContentProperty::NEEDS_KDM ||
+ property == SubtitleContentProperty::COLOUR ||
+ property == SubtitleContentProperty::OUTLINE ||
+ property == SubtitleContentProperty::SHADOW ||
+ property == SubtitleContentProperty::EFFECT_COLOUR ||
+ property == FFmpegContentProperty::SUBTITLE_STREAM ||
+ property == VideoContentProperty::COLOUR_CONVERSION
+ ) {
- FrameRateChange frc (content->video_frame_rate(), _film->video_frame_rate());
- if (frc.skip && (frame % 2) == 1) {
- return;
+ _have_valid_pieces = false;
+ Changed (frequent);
+
+ } else if (
+ property == SubtitleContentProperty::LINE_SPACING ||
+ property == SubtitleContentProperty::OUTLINE_WIDTH ||
+ property == SubtitleContentProperty::Y_SCALE ||
+ property == SubtitleContentProperty::FADE_IN ||
+ property == SubtitleContentProperty::FADE_OUT ||
+ property == ContentProperty::VIDEO_FRAME_RATE ||
+ property == SubtitleContentProperty::USE ||
+ property == SubtitleContentProperty::X_OFFSET ||
+ property == SubtitleContentProperty::Y_OFFSET ||
+ property == SubtitleContentProperty::X_SCALE ||
+ property == SubtitleContentProperty::FONTS ||
+ property == VideoContentProperty::CROP ||
+ property == VideoContentProperty::SCALE ||
+ property == VideoContentProperty::FADE_IN ||
+ property == VideoContentProperty::FADE_OUT
+ ) {
+
+ Changed (frequent);
}
+}
- Time const relative_time = (frame * frc.factor() * TIME_HZ / _film->video_frame_rate());
- if (content->trimmed (relative_time)) {
+void
+Player::set_video_container_size (dcp::Size s)
+{
+ if (s == _video_container_size) {
return;
}
- Time const time = content->position() + relative_time + extra - content->trim_start ();
- libdcp::Size const image_size = content->scale().size (content, _video_container_size, _film->frame_size ());
+ _video_container_size = s;
- shared_ptr<PlayerVideoFrame> pi (
- new PlayerVideoFrame (
- image,
- content->crop(),
- image_size,
- _video_container_size,
- _film->scaler(),
- eyes,
- part,
- content->colour_conversion()
- )
- );
-
- if (_film->with_subtitles ()) {
- for (list<Subtitle>::const_iterator i = _subtitles.begin(); i != _subtitles.end(); ++i) {
- if (i->covers (time)) {
- /* This may be true for more than one of _subtitles, but the last (latest-starting)
- one is the one we want to use, so that's ok.
- */
- Position<int> const container_offset (
- (_video_container_size.width - image_size.width) / 2,
- (_video_container_size.height - image_size.width) / 2
- );
-
- pi->set_subtitle (i->out_image(), i->out_position() + container_offset);
- }
+ _black_image.reset (new Image (AV_PIX_FMT_RGB24, _video_container_size, true));
+ _black_image->make_black ();
+
+ Changed (false);
+}
+
+void
+Player::playlist_changed ()
+{
+ _have_valid_pieces = false;
+ Changed (false);
+}
+
+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::CONTAINER) {
+ Changed (false);
+ } else if (p == Film::VIDEO_FRAME_RATE) {
+ /* Pieces contain a FrameRateChange which contains the DCP frame rate,
+ so we need new pieces here.
+ */
+ _have_valid_pieces = false;
+ Changed (false);
+ } else if (p == Film::AUDIO_PROCESSOR) {
+ if (_film->audio_processor ()) {
+ _audio_processor = _film->audio_processor()->clone (_film->audio_frame_rate ());
}
}
+}
- /* Clear out old subtitles */
- for (list<Subtitle>::iterator i = _subtitles.begin(); i != _subtitles.end(); ) {
- list<Subtitle>::iterator j = i;
- ++j;
-
- if (i->ends_before (time)) {
- _subtitles.erase (i);
+list<PositionImage>
+Player::transform_image_subtitles (list<ImageSubtitle> subs) const
+{
+ list<PositionImage> all;
+
+ for (list<ImageSubtitle>::const_iterator i = subs.begin(); i != subs.end(); ++i) {
+ if (!i->image) {
+ continue;
}
- i = j;
+ /* We will scale the subtitle up to fit _video_container_size */
+ dcp::Size scaled_size (i->rectangle.width * _video_container_size.width, i->rectangle.height * _video_container_size.height);
+
+ /* 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_x_scale) / 2) and
+ * (height_before_subtitle_scale * (1 - subtitle_y_scale) / 2).
+ *
+ * Combining these two translations gives these expressions.
+ */
+
+ all.push_back (
+ PositionImage (
+ i->image->scale (
+ scaled_size,
+ dcp::YUV_TO_RGB_REC601,
+ i->image->pixel_format (),
+ true,
+ _fast
+ ),
+ Position<int> (
+ lrint (_video_container_size.width * i->rectangle.x),
+ lrint (_video_container_size.height * i->rectangle.y)
+ )
+ )
+ );
}
-#ifdef DCPOMATIC_DEBUG
- _last_video = piece->content;
-#endif
+ return all;
+}
- Video (pi, same, time);
+shared_ptr<PlayerVideo>
+Player::black_player_video_frame () const
+{
+ return shared_ptr<PlayerVideo> (
+ new PlayerVideo (
+ shared_ptr<const ImageProxy> (new RawImageProxy (_black_image)),
+ Crop (),
+ optional<double> (),
+ _video_container_size,
+ _video_container_size,
+ EYES_BOTH,
+ PART_WHOLE,
+ PresetColourConversion::all().front().conversion
+ )
+ );
+}
+
+Frame
+Player::dcp_to_content_video (shared_ptr<const Piece> piece, DCPTime t) const
+{
+ DCPTime s = t - piece->content->position ();
+ s = min (piece->content->length_after_trim(), s);
+ s = max (DCPTime(), s + DCPTime (piece->content->trim_start(), piece->frc));
+
+ /* It might seem more logical here to convert s to a ContentTime (using the FrameRateChange)
+ then convert that ContentTime to frames at the content's rate. However this fails for
+ situations like content at 29.9978733fps, DCP at 30fps. The accuracy of the Time type is not
+ enough to distinguish between the two with low values of time (e.g. 3200 in Time units).
+
+ Instead we convert the DCPTime using the DCP video rate then account for any skip/repeat.
+ */
+ return s.frames_floor (piece->frc.dcp) / piece->frc.factor ();
+}
+
+DCPTime
+Player::content_video_to_dcp (shared_ptr<const Piece> piece, Frame f) const
+{
+ /* See comment in dcp_to_content_video */
+ DCPTime const d = DCPTime::from_frames (f * piece->frc.factor(), piece->frc.dcp) - DCPTime (piece->content->trim_start (), piece->frc);
+ return max (DCPTime (), d + piece->content->position ());
+}
- _last_emit_was_black = false;
- _video_position = piece->video_position = (time + TIME_HZ / _film->video_frame_rate());
+Frame
+Player::dcp_to_resampled_audio (shared_ptr<const Piece> piece, DCPTime t) const
+{
+ DCPTime s = t - piece->content->position ();
+ s = min (piece->content->length_after_trim(), s);
+ /* See notes in dcp_to_content_video */
+ return max (DCPTime (), DCPTime (piece->content->trim_start (), piece->frc) + s).frames_floor (_film->audio_frame_rate ());
+}
- if (frc.repeat > 1 && !piece->repeating ()) {
- piece->set_repeat (_last_incoming_video, frc.repeat - 1);
+DCPTime
+Player::resampled_audio_to_dcp (shared_ptr<const Piece> piece, Frame f) const
+{
+ /* See comment in dcp_to_content_video */
+ DCPTime const d = DCPTime::from_frames (f, _film->audio_frame_rate()) - DCPTime (piece->content->trim_start(), piece->frc);
+ return max (DCPTime (), d + piece->content->position ());
+}
+
+ContentTime
+Player::dcp_to_content_time (shared_ptr<const Piece> piece, DCPTime t) const
+{
+ DCPTime s = t - piece->content->position ();
+ s = min (piece->content->length_after_trim(), s);
+ return max (ContentTime (), ContentTime (s, piece->frc) + piece->content->trim_start());
+}
+
+DCPTime
+Player::content_time_to_dcp (shared_ptr<const Piece> piece, ContentTime t) const
+{
+ return max (DCPTime (), DCPTime (t - piece->content->trim_start(), piece->frc) + piece->content->position());
+}
+
+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) {
+ if (p->content->subtitle) {
+ /* XXX: things may go wrong if there are duplicate font IDs
+ with different font files.
+ */
+ list<shared_ptr<Font> > f = p->content->subtitle->fonts ();
+ copy (f.begin(), f.end(), back_inserter (fonts));
+ }
+ }
+
+ return fonts;
}
-/** @param already_resampled true if this data has already been through the chain up to the resampler */
+/** Set this player never to produce any video data */
void
-Player::process_audio (weak_ptr<Piece> weak_piece, shared_ptr<const AudioBuffers> audio, AudioContent::Frame frame, bool already_resampled)
+Player::set_ignore_video ()
{
- shared_ptr<Piece> piece = weak_piece.lock ();
- if (!piece) {
- return;
- }
+ _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.
+ */
+void
+Player::set_always_burn_subtitles (bool burn)
+{
+ _always_burn_subtitles = burn;
+}
- shared_ptr<AudioContent> content = dynamic_pointer_cast<AudioContent> (piece->content);
- assert (content);
+void
+Player::set_fast ()
+{
+ _fast = true;
+ _have_valid_pieces = false;
+}
+
+void
+Player::set_play_referenced ()
+{
+ _play_referenced = true;
+ _have_valid_pieces = false;
+}
+
+list<ReferencedReelAsset>
+Player::get_reel_assets ()
+{
+ list<ReferencedReelAsset> a;
- if (!already_resampled) {
- /* Gain */
- if (content->audio_gain() != 0) {
- shared_ptr<AudioBuffers> gain (new AudioBuffers (audio));
- gain->apply_gain (content->audio_gain ());
- audio = gain;
+ BOOST_FOREACH (shared_ptr<Content> i, _playlist->content ()) {
+ shared_ptr<DCPContent> j = dynamic_pointer_cast<DCPContent> (i);
+ if (!j) {
+ continue;
}
-
- /* Resample */
- if (content->content_audio_frame_rate() != content->output_audio_frame_rate()) {
- shared_ptr<Resampler> r = resampler (content, true);
- pair<shared_ptr<const AudioBuffers>, AudioContent::Frame> ro = r->run (audio, frame);
- audio = ro.first;
- frame = ro.second;
+
+ scoped_ptr<DCPDecoder> decoder;
+ try {
+ decoder.reset (new DCPDecoder (j, _film->log()));
+ } catch (...) {
+ return a;
}
- }
-
- Time const relative_time = _film->audio_frames_to_time (frame);
- if (content->trimmed (relative_time)) {
- return;
- }
+ int64_t offset = 0;
+ BOOST_FOREACH (shared_ptr<dcp::Reel> k, decoder->reels()) {
+
+ DCPOMATIC_ASSERT (j->video_frame_rate ());
+ double const cfr = j->video_frame_rate().get();
+ Frame const trim_start = j->trim_start().frames_round (cfr);
+ Frame const trim_end = j->trim_end().frames_round (cfr);
+ int const ffr = _film->video_frame_rate ();
+
+ DCPTime const from = i->position() + DCPTime::from_frames (offset, _film->video_frame_rate());
+ if (j->reference_video ()) {
+ shared_ptr<dcp::ReelAsset> ra = k->main_picture ();
+ DCPOMATIC_ASSERT (ra);
+ ra->set_entry_point (ra->entry_point() + trim_start);
+ ra->set_duration (ra->duration() - trim_start - trim_end);
+ a.push_back (
+ ReferencedReelAsset (ra, DCPTimePeriod (from, from + DCPTime::from_frames (ra->duration(), ffr)))
+ );
+ }
- Time time = content->position() + (content->audio_delay() * TIME_HZ / 1000) + relative_time - content->trim_start ();
-
- /* Remap channels */
- shared_ptr<AudioBuffers> dcp_mapped (new AudioBuffers (_film->audio_channels(), audio->frames()));
- dcp_mapped->make_silent ();
+ if (j->reference_audio ()) {
+ shared_ptr<dcp::ReelAsset> ra = k->main_sound ();
+ DCPOMATIC_ASSERT (ra);
+ ra->set_entry_point (ra->entry_point() + trim_start);
+ ra->set_duration (ra->duration() - trim_start - trim_end);
+ a.push_back (
+ ReferencedReelAsset (ra, DCPTimePeriod (from, from + DCPTime::from_frames (ra->duration(), ffr)))
+ );
+ }
- AudioMapping map = content->audio_mapping ();
- for (int i = 0; i < map.content_channels(); ++i) {
- for (int j = 0; j < _film->audio_channels(); ++j) {
- if (map.get (i, static_cast<libdcp::Channel> (j)) > 0) {
- dcp_mapped->accumulate_channel (
- audio.get(),
- i,
- static_cast<libdcp::Channel> (j),
- map.get (i, static_cast<libdcp::Channel> (j))
+ if (j->reference_subtitle ()) {
+ shared_ptr<dcp::ReelAsset> ra = k->main_subtitle ();
+ DCPOMATIC_ASSERT (ra);
+ ra->set_entry_point (ra->entry_point() + trim_start);
+ ra->set_duration (ra->duration() - trim_start - trim_end);
+ a.push_back (
+ ReferencedReelAsset (ra, DCPTimePeriod (from, from + DCPTime::from_frames (ra->duration(), ffr)))
);
}
+
+ /* Assume that main picture duration is the length of the reel */
+ offset += k->main_picture()->duration ();
}
}
- audio = dcp_mapped;
-
- /* We must cut off anything that comes before the start of all time */
- if (time < 0) {
- int const frames = - time * _film->audio_frame_rate() / TIME_HZ;
- if (frames >= audio->frames ()) {
- return;
- }
+ return a;
+}
- shared_ptr<AudioBuffers> trimmed (new AudioBuffers (audio->channels(), audio->frames() - frames));
- trimmed->copy_from (audio.get(), audio->frames() - frames, frames, 0);
+list<shared_ptr<Piece> >
+Player::overlaps (DCPTime from, DCPTime to, boost::function<bool (Content *)> valid)
+{
+ if (!_have_valid_pieces) {
+ setup_pieces ();
+ }
- audio = trimmed;
- time = 0;
+ list<shared_ptr<Piece> > overlaps;
+ BOOST_FOREACH (shared_ptr<Piece> i, _pieces) {
+ if (valid (i->content.get ()) && i->content->position() < to && i->content->end() > from) {
+ overlaps.push_back (i);
+ }
}
- _audio_merger.push (audio, time);
- piece->audio_position += _film->audio_frames_to_time (audio->frames ());
+ return overlaps;
}
-void
-Player::flush ()
+bool
+Player::pass ()
{
- TimedAudioBuffers<Time> tb = _audio_merger.flush ();
- if (_audio && tb.audio) {
- Audio (tb.audio, tb.time);
- _audio_position += _film->audio_frames_to_time (tb.audio->frames ());
+ if (!_have_valid_pieces) {
+ setup_pieces ();
}
- while (_video && _video_position < _audio_position) {
- emit_black ();
+ shared_ptr<Piece> earliest;
+ DCPTime earliest_content;
+
+ BOOST_FOREACH (shared_ptr<Piece> i, _pieces) {
+ if (!i->done) {
+ DCPTime const t = i->content->position() + DCPTime (i->decoder->position(), i->frc);
+ if (!earliest || t < earliest_content) {
+ earliest_content = t;
+ earliest = i;
+ }
+ }
}
- while (_audio && _audio_position < _video_position) {
- emit_silence (_film->time_to_audio_frames (_video_position - _audio_position));
+ if (!earliest) {
+ /* No more content; fill up with silent black */
+ DCPTimePeriod remaining_video (DCPTime(), _playlist->length());
+ if (_last_time) {
+ remaining_video.from = _last_time.get() + one_video_frame();
+ }
+ fill_video (remaining_video);
+ fill_audio (DCPTimePeriod (_last_audio_time, _playlist->length()));
+ return true;
}
-
+
+ earliest->done = earliest->decoder->pass ();
+ if (earliest->done && earliest->content->audio) {
+ /* Flush the Player audio system for this piece */
+ BOOST_FOREACH (AudioStreamPtr i, earliest->content->audio->streams()) {
+ audio_flush (earliest, i);
+ }
+ }
+
+ /* Emit any audio that is ready */
+
+ DCPTime pull_from = _playlist->length ();
+ for (map<AudioStreamPtr, StreamState>::const_iterator i = _stream_states.begin(); i != _stream_states.end(); ++i) {
+ if (!i->second.piece->done && i->second.last_push_end < pull_from) {
+ pull_from = i->second.last_push_end;
+ }
+ }
+
+ list<pair<shared_ptr<AudioBuffers>, DCPTime> > audio = _audio_merger.pull (pull_from);
+ for (list<pair<shared_ptr<AudioBuffers>, DCPTime> >::iterator i = audio.begin(); i != audio.end(); ++i) {
+ DCPOMATIC_ASSERT (i->second >= _last_audio_time);
+ fill_audio (DCPTimePeriod (_last_audio_time, i->second));
+ Audio (i->first, i->second);
+ _last_audio_time = i->second + DCPTime::from_frames(i->first->frames(), _film->audio_frame_rate());
+ }
+
+ return false;
}
-/** Seek so that the next pass() will yield (approximately) the requested frame.
- * Pass accurate = true to try harder to get close to the request.
- * @return true on error
- */
void
-Player::seek (Time t, bool accurate)
+Player::video (weak_ptr<Piece> wp, ContentVideo video)
{
- if (!_have_valid_pieces) {
- setup_pieces ();
+ shared_ptr<Piece> piece = wp.lock ();
+ if (!piece) {
+ return;
}
- if (_pieces.empty ()) {
+ FrameRateChange frc(piece->content->active_video_frame_rate(), _film->video_frame_rate());
+ if (frc.skip && (video.frame % 2) == 1) {
return;
}
- for (list<shared_ptr<Piece> >::iterator i = _pieces.begin(); i != _pieces.end(); ++i) {
- shared_ptr<VideoContent> vc = dynamic_pointer_cast<VideoContent> ((*i)->content);
- if (!vc) {
+ /* Time and period of the frame we will emit */
+ DCPTime const time = content_video_to_dcp (piece, video.frame);
+ DCPTimePeriod const period (time, time + one_video_frame());
+
+ /* Discard if it's outside the content's period */
+ if (time < piece->content->position() || time >= piece->content->end()) {
+ return;
+ }
+
+ /* Get any subtitles */
+
+ optional<PositionImage> subtitles;
+
+ for (list<pair<PlayerSubtitles, DCPTimePeriod> >::const_iterator i = _subtitles.begin(); i != _subtitles.end(); ++i) {
+
+ if (!i->second.overlap (period)) {
continue;
}
- /* s is the offset of t from the start position of this content */
- Time s = t - vc->position ();
- s = max (static_cast<Time> (0), s);
- s = min (vc->length_after_trim(), s);
+ list<PositionImage> sub_images;
- /* Hence set the piece positions to the `global' time */
- (*i)->video_position = (*i)->audio_position = vc->position() + s;
+ /* Image subtitles */
+ list<PositionImage> c = transform_image_subtitles (i->first.image);
+ copy (c.begin(), c.end(), back_inserter (sub_images));
- /* And seek the decoder */
- dynamic_pointer_cast<VideoDecoder>((*i)->decoder)->seek (
- vc->time_to_content_video_frames (s + vc->trim_start ()), accurate
- );
+ /* Text subtitles (rendered to an image) */
+ if (!i->first.text.empty ()) {
+ list<PositionImage> s = render_subtitles (i->first.text, i->first.fonts, _video_container_size, time);
+ copy (s.begin (), s.end (), back_inserter (sub_images));
+ }
+
+ if (!sub_images.empty ()) {
+ subtitles = merge (sub_images);
+ }
+ }
+
+ /* Fill gaps */
+
+ if (_last_time) {
+ fill_video (DCPTimePeriod (_last_time.get() + one_video_frame(), time));
+ }
+
+ _last_video.reset (
+ new PlayerVideo (
+ video.image,
+ piece->content->video->crop (),
+ piece->content->video->fade (video.frame),
+ piece->content->video->scale().size (
+ piece->content->video, _video_container_size, _film->frame_size ()
+ ),
+ _video_container_size,
+ video.eyes,
+ video.part,
+ piece->content->video->colour_conversion ()
+ )
+ );
- (*i)->reset_repeat ();
+ if (subtitles) {
+ _last_video->set_subtitle (subtitles.get ());
}
- _video_position = _audio_position = t;
+ _last_time = time;
+
+ Video (_last_video, *_last_time);
+
+ /* Discard any subtitles we no longer need */
- /* XXX: don't seek audio because we don't need to... */
+ for (list<pair<PlayerSubtitles, DCPTimePeriod> >::iterator i = _subtitles.begin (); i != _subtitles.end(); ) {
+ list<pair<PlayerSubtitles, DCPTimePeriod> >::iterator tmp = i;
+ ++tmp;
+
+ if (i->second.to < time) {
+ _subtitles.erase (i);
+ }
+
+ i = tmp;
+ }
}
void
-Player::setup_pieces ()
+Player::audio_flush (shared_ptr<Piece> piece, AudioStreamPtr stream)
{
- list<shared_ptr<Piece> > old_pieces = _pieces;
+ shared_ptr<AudioContent> content = piece->content->audio;
+ DCPOMATIC_ASSERT (content);
- _pieces.clear ();
+ shared_ptr<Resampler> r = resampler (content, stream, false);
+ if (!r) {
+ return;
+ }
- ContentList content = _playlist->content ();
- sort (content.begin(), content.end(), ContentSorter ());
+ pair<shared_ptr<const AudioBuffers>, Frame> ro = r->flush ();
+ ContentAudio content_audio;
+ content_audio.audio = ro.first;
+ content_audio.frame = ro.second;
- for (ContentList::iterator i = content.begin(); i != content.end(); ++i) {
+ /* Compute time in the DCP */
+ DCPTime time = resampled_audio_to_dcp (piece, content_audio.frame) + DCPTime::from_seconds (content->delay() / 1000.0);
- if (!(*i)->paths_valid ()) {
- continue;
- }
+ audio_transform (content, stream, content_audio, time);
+}
- shared_ptr<Piece> piece (new Piece (*i));
-
- /* XXX: into content? */
-
- shared_ptr<const FFmpegContent> fc = dynamic_pointer_cast<const FFmpegContent> (*i);
- if (fc) {
- shared_ptr<FFmpegDecoder> fd (new FFmpegDecoder (_film, fc, _video, _audio));
-
- fd->Video.connect (bind (&Player::process_video, this, weak_ptr<Piece> (piece), _1, _2, _3, _4, _5, 0));
- fd->Audio.connect (bind (&Player::process_audio, this, weak_ptr<Piece> (piece), _1, _2, false));
- fd->Subtitle.connect (bind (&Player::process_subtitle, this, weak_ptr<Piece> (piece), _1, _2, _3, _4));
-
- fd->seek (fc->time_to_content_video_frames (fc->trim_start ()), true);
- piece->decoder = fd;
- }
-
- shared_ptr<const ImageContent> ic = dynamic_pointer_cast<const ImageContent> (*i);
- if (ic) {
- bool reusing = false;
-
- /* See if we can re-use an old ImageDecoder */
- for (list<shared_ptr<Piece> >::const_iterator j = old_pieces.begin(); j != old_pieces.end(); ++j) {
- shared_ptr<ImageDecoder> imd = dynamic_pointer_cast<ImageDecoder> ((*j)->decoder);
- if (imd && imd->content() == ic) {
- piece = *j;
- reusing = true;
- }
- }
+/** Do our common processing on some audio */
+void
+Player::audio_transform (shared_ptr<AudioContent> content, AudioStreamPtr stream, ContentAudio content_audio, DCPTime time)
+{
+ /* Gain */
+
+ if (content->gain() != 0) {
+ shared_ptr<AudioBuffers> gain (new AudioBuffers (content_audio.audio));
+ gain->apply_gain (content->gain ());
+ content_audio.audio = gain;
+ }
+
+ /* Remap */
- if (!reusing) {
- shared_ptr<ImageDecoder> id (new ImageDecoder (_film, ic));
- id->Video.connect (bind (&Player::process_video, this, weak_ptr<Piece> (piece), _1, _2, _3, _4, _5, 0));
- piece->decoder = id;
+ shared_ptr<AudioBuffers> dcp_mapped (new AudioBuffers (_film->audio_channels(), content_audio.audio->frames()));
+ dcp_mapped->make_silent ();
+
+ AudioMapping map = stream->mapping ();
+ for (int i = 0; i < map.input_channels(); ++i) {
+ for (int j = 0; j < dcp_mapped->channels(); ++j) {
+ if (map.get (i, static_cast<dcp::Channel> (j)) > 0) {
+ dcp_mapped->accumulate_channel (
+ content_audio.audio.get(),
+ i,
+ static_cast<dcp::Channel> (j),
+ map.get (i, static_cast<dcp::Channel> (j))
+ );
}
}
+ }
- shared_ptr<const SndfileContent> sc = dynamic_pointer_cast<const SndfileContent> (*i);
- if (sc) {
- shared_ptr<AudioDecoder> sd (new SndfileDecoder (_film, sc));
- sd->Audio.connect (bind (&Player::process_audio, this, weak_ptr<Piece> (piece), _1, _2, false));
+ content_audio.audio = dcp_mapped;
- piece->decoder = sd;
- }
+ /* Process */
- _pieces.push_back (piece);
+ if (_audio_processor) {
+ content_audio.audio = _audio_processor->run (content_audio.audio, _film->audio_channels ());
}
- _have_valid_pieces = true;
+ /* Push */
+
+ _audio_merger.push (content_audio.audio, time);
+ DCPOMATIC_ASSERT (_stream_states.find (stream) != _stream_states.end ());
+ _stream_states[stream].last_push_end = time + DCPTime::from_frames (content_audio.audio->frames(), _film->audio_frame_rate());
}
void
-Player::content_changed (weak_ptr<Content> w, int property, bool frequent)
+Player::audio (weak_ptr<Piece> wp, AudioStreamPtr stream, ContentAudio content_audio)
{
- shared_ptr<Content> c = w.lock ();
- if (!c) {
+ shared_ptr<Piece> piece = wp.lock ();
+ if (!piece) {
return;
}
- if (
- property == ContentProperty::POSITION || property == ContentProperty::LENGTH ||
- property == ContentProperty::TRIM_START || property == ContentProperty::TRIM_END ||
- property == VideoContentProperty::VIDEO_FRAME_TYPE
- ) {
-
- _have_valid_pieces = false;
- Changed (frequent);
+ shared_ptr<AudioContent> content = piece->content->audio;
+ DCPOMATIC_ASSERT (content);
- } else if (
- property == SubtitleContentProperty::SUBTITLE_X_OFFSET ||
- property == SubtitleContentProperty::SUBTITLE_Y_OFFSET ||
- property == SubtitleContentProperty::SUBTITLE_X_SCALE ||
- property == SubtitleContentProperty::SUBTITLE_Y_SCALE
- ) {
+ /* Resample */
+ if (stream->frame_rate() != content->resampled_frame_rate()) {
+ shared_ptr<Resampler> r = resampler (content, stream, true);
+ pair<shared_ptr<const AudioBuffers>, Frame> ro = r->run (content_audio.audio, content_audio.frame);
+ content_audio.audio = ro.first;
+ content_audio.frame = ro.second;
+ }
- for (list<Subtitle>::iterator i = _subtitles.begin(); i != _subtitles.end(); ++i) {
- i->update (_film, _video_container_size);
+ /* Compute time in the DCP */
+ DCPTime time = resampled_audio_to_dcp (piece, content_audio.frame) + DCPTime::from_seconds (content->delay() / 1000.0);
+ /* And the end of this block in the DCP */
+ DCPTime end = time + DCPTime::from_frames(content_audio.audio->frames(), content->resampled_frame_rate());
+
+ /* Remove anything that comes before the start or after the end of the content */
+ if (time < piece->content->position()) {
+ DCPTime const discard_time = piece->content->position() - time;
+ Frame discard_frames = discard_time.frames_round(_film->audio_frame_rate());
+ Frame remaining_frames = content_audio.audio->frames() - discard_frames;
+ if (remaining_frames <= 0) {
+ /* This audio is entirely discarded */
+ return;
}
-
- Changed (frequent);
+ shared_ptr<AudioBuffers> cut (new AudioBuffers (content_audio.audio->channels(), remaining_frames));
+ cut->copy_from (content_audio.audio.get(), remaining_frames, discard_frames, 0);
+ content_audio.audio = cut;
+ time += discard_time;
+ } else if (time > piece->content->end()) {
+ /* Discard it all */
+ return;
+ } else if (end > piece->content->end()) {
+ Frame const remaining_frames = DCPTime(piece->content->end() - time).frames_round(_film->audio_frame_rate());
+ shared_ptr<AudioBuffers> cut (new AudioBuffers (content_audio.audio->channels(), remaining_frames));
+ cut->copy_from (content_audio.audio.get(), remaining_frames, 0, 0);
+ content_audio.audio = cut;
+ }
- } else if (
- property == VideoContentProperty::VIDEO_CROP || property == VideoContentProperty::VIDEO_SCALE ||
- property == VideoContentProperty::VIDEO_FRAME_RATE
- ) {
-
- Changed (frequent);
+ audio_transform (content, stream, content_audio, time);
+}
+
+void
+Player::image_subtitle (weak_ptr<Piece> wp, ContentImageSubtitle subtitle)
+{
+ shared_ptr<Piece> piece = wp.lock ();
+ if (!piece) {
+ return;
+ }
- } else if (property == ContentProperty::PATH) {
+ /* Apply content's subtitle offsets */
+ subtitle.sub.rectangle.x += piece->content->subtitle->x_offset ();
+ subtitle.sub.rectangle.y += piece->content->subtitle->y_offset ();
- _have_valid_pieces = false;
- Changed (frequent);
+ /* Apply content's subtitle scale */
+ subtitle.sub.rectangle.width *= piece->content->subtitle->x_scale ();
+ subtitle.sub.rectangle.height *= piece->content->subtitle->y_scale ();
+
+ /* Apply a corrective translation to keep the subtitle centred after that scale */
+ subtitle.sub.rectangle.x -= subtitle.sub.rectangle.width * (piece->content->subtitle->x_scale() - 1);
+ subtitle.sub.rectangle.y -= subtitle.sub.rectangle.height * (piece->content->subtitle->y_scale() - 1);
+
+ PlayerSubtitles ps;
+ ps.image.push_back (subtitle.sub);
+ DCPTimePeriod period (content_time_to_dcp (piece, subtitle.period().from), content_time_to_dcp (piece, subtitle.period().to));
+
+ if (piece->content->subtitle->use() && (piece->content->subtitle->burn() || _always_burn_subtitles)) {
+ _subtitles.push_back (make_pair (ps, period));
+ } else {
+ Subtitle (ps, period);
}
}
void
-Player::playlist_changed ()
+Player::text_subtitle (weak_ptr<Piece> wp, ContentTextSubtitle subtitle)
{
- _have_valid_pieces = false;
- Changed (false);
+ shared_ptr<Piece> piece = wp.lock ();
+ if (!piece) {
+ return;
+ }
+
+ PlayerSubtitles ps;
+ DCPTimePeriod const period (content_time_to_dcp (piece, subtitle.period().from), content_time_to_dcp (piece, subtitle.period().to));
+
+ BOOST_FOREACH (dcp::SubtitleString s, subtitle.subs) {
+ s.set_h_position (s.h_position() + piece->content->subtitle->x_offset ());
+ s.set_v_position (s.v_position() + piece->content->subtitle->y_offset ());
+ float const xs = piece->content->subtitle->x_scale();
+ float const ys = piece->content->subtitle->y_scale();
+ float size = s.size();
+
+ /* Adjust size to express the common part of the scaling;
+ e.g. if xs = ys = 0.5 we scale size by 2.
+ */
+ if (xs > 1e-5 && ys > 1e-5) {
+ size *= 1 / min (1 / xs, 1 / ys);
+ }
+ s.set_size (size);
+
+ /* Then express aspect ratio changes */
+ if (fabs (1.0 - xs / ys) > dcp::ASPECT_ADJUST_EPSILON) {
+ s.set_aspect_adjust (xs / ys);
+ }
+
+ s.set_in (dcp::Time(period.from.seconds(), 1000));
+ s.set_out (dcp::Time(period.to.seconds(), 1000));
+ ps.text.push_back (SubtitleString (s, piece->content->subtitle->outline_width()));
+ ps.add_fonts (piece->content->subtitle->fonts ());
+ }
+
+ if (piece->content->subtitle->use() && (piece->content->subtitle->burn() || _always_burn_subtitles)) {
+ _subtitles.push_back (make_pair (ps, period));
+ } else {
+ Subtitle (ps, period);
+ }
}
void
-Player::set_video_container_size (libdcp::Size s)
+Player::seek (DCPTime time, bool accurate)
{
- _video_container_size = s;
+ if (_audio_processor) {
+ _audio_processor->flush ();
+ }
- shared_ptr<Image> im (new Image (PIX_FMT_RGB24, _video_container_size, true));
- im->make_black ();
-
- _black_frame.reset (
- new PlayerVideoFrame (
- shared_ptr<ImageProxy> (new RawImageProxy (im, _film->log ())),
- Crop(),
- _video_container_size,
- _video_container_size,
- Scaler::from_id ("bicubic"),
- EYES_BOTH,
- PART_WHOLE,
- ColourConversion ()
- )
- );
+ BOOST_FOREACH (shared_ptr<Piece> i, _pieces) {
+ if (i->content->position() <= time && time < i->content->end()) {
+ i->decoder->seek (dcp_to_content_time (i, time), accurate);
+ i->done = false;
+ }
+ }
+
+ if (accurate) {
+ _last_time = time - one_video_frame ();
+ } else {
+ _last_time = optional<DCPTime> ();
+ }
}
shared_ptr<Resampler>
-Player::resampler (shared_ptr<AudioContent> c, bool create)
+Player::resampler (shared_ptr<const AudioContent> content, AudioStreamPtr stream, bool create)
{
- map<shared_ptr<AudioContent>, shared_ptr<Resampler> >::iterator i = _resamplers.find (c);
+ ResamplerMap::const_iterator i = _resamplers.find (make_pair (content, stream));
if (i != _resamplers.end ()) {
return i->second;
}
}
LOG_GENERAL (
- "Creating new resampler for %1 to %2 with %3 channels", c->content_audio_frame_rate(), c->output_audio_frame_rate(), c->audio_channels()
+ "Creating new resampler from %1 to %2 with %3 channels",
+ stream->frame_rate(),
+ content->resampled_frame_rate(),
+ stream->channels()
);
- shared_ptr<Resampler> r (new Resampler (c->content_audio_frame_rate(), c->output_audio_frame_rate(), c->audio_channels()));
- _resamplers[c] = r;
- return r;
-}
-
-void
-Player::emit_black ()
-{
-#ifdef DCPOMATIC_DEBUG
- _last_video.reset ();
-#endif
-
- Video (_black_frame, _last_emit_was_black, _video_position);
- _video_position += _film->video_frames_to_time (1);
- _last_emit_was_black = true;
-}
+ shared_ptr<Resampler> r (
+ new Resampler (stream->frame_rate(), content->resampled_frame_rate(), stream->channels())
+ );
-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);
+ _resamplers[make_pair(content, stream)] = r;
+ return r;
}
void
-Player::film_changed (Film::Property p)
+Player::fill_video (DCPTimePeriod period)
{
- /* 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 || p == Film::VIDEO_FRAME_RATE) {
- Changed (false);
+ /* XXX: this may not work for 3D */
+ BOOST_FOREACH (DCPTimePeriod i, subtract(period, _no_video)) {
+ for (DCPTime j = i.from; j < i.to; j += one_video_frame()) {
+ if (_playlist->video_content_at(j) && _last_video) {
+ Video (shared_ptr<PlayerVideo> (new PlayerVideo (*_last_video)), j);
+ } else {
+ Video (black_player_video_frame(), j);
+ }
+ }
}
}
void
-Player::process_subtitle (weak_ptr<Piece> weak_piece, shared_ptr<Image> image, dcpomatic::Rect<double> rect, Time from, Time to)
+Player::fill_audio (DCPTimePeriod period)
{
- if (!image) {
- /* A null image means that we should stop any current subtitles at `from' */
- for (list<Subtitle>::iterator i = _subtitles.begin(); i != _subtitles.end(); ++i) {
- i->set_stop (from);
+ BOOST_FOREACH (DCPTimePeriod i, subtract(period, _no_audio)) {
+ DCPTime t = i.from;
+ while (t < i.to) {
+ DCPTime block = min (DCPTime::from_seconds (0.5), i.to - t);
+ Frame const samples = block.frames_round(_film->audio_frame_rate());
+ if (samples) {
+ shared_ptr<AudioBuffers> silence (new AudioBuffers (_film->audio_channels(), samples));
+ silence->make_silent ();
+ Audio (silence, t);
+ }
+ t += block;
}
- } else {
- _subtitles.push_back (Subtitle (_film, _video_container_size, weak_piece, image, rect, from, to));
}
}
-/** 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 ()
+DCPTime
+Player::one_video_frame () const
{
- if (!_last_incoming_video.image || !_have_valid_pieces) {
- return false;
- }
-
- process_video (
- _last_incoming_video.weak_piece,
- _last_incoming_video.image,
- _last_incoming_video.eyes,
- _last_incoming_video.part,
- _last_incoming_video.same,
- _last_incoming_video.frame,
- _last_incoming_video.extra
- );
-
- return true;
+ return DCPTime::from_frames (1, _film->video_frame_rate ());
}