X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fplayer.cc;h=cb6d519842c5c6cfce1ac92d5f1fe83f74a04e0c;hb=d8d7ddd4c39e3ea347afd1fccc037d8b0a31bc87;hp=310e91b6c1fd814b59a3acc0dcfc77cfa4c8d9e9;hpb=5d65df7ebdc96c658a6b7042e639cb395f91bfeb;p=dcpomatic.git diff --git a/src/lib/player.cc b/src/lib/player.cc index 310e91b6c..06f9e1365 100644 --- a/src/lib/player.cc +++ b/src/lib/player.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2013 Carl Hetherington + Copyright (C) 2013-2014 Carl Hetherington This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -18,625 +18,561 @@ */ #include +#include #include "player.h" #include "film.h" #include "ffmpeg_decoder.h" +#include "audio_buffers.h" #include "ffmpeg_content.h" -#include "still_image_decoder.h" -#include "still_image_content.h" -#include "moving_image_decoder.h" -#include "moving_image_content.h" +#include "image_decoder.h" +#include "image_content.h" #include "sndfile_decoder.h" #include "sndfile_content.h" #include "subtitle_content.h" +#include "subrip_decoder.h" +#include "subrip_content.h" +#include "dcp_content.h" #include "playlist.h" #include "job.h" #include "image.h" +#include "raw_image_proxy.h" #include "ratio.h" -#include "resampler.h" #include "log.h" #include "scaler.h" +#include "render_subtitles.h" +#include "config.h" +#include "content_video.h" +#include "player_video.h" +#include "frame_rate_change.h" +#include "dcp_content.h" +#include "dcp_decoder.h" +#include "dcp_subtitle_content.h" +#include "dcp_subtitle_decoder.h" + +#define LOG_GENERAL(...) _film->log()->log (String::compose (__VA_ARGS__), Log::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 boost::shared_ptr; using boost::weak_ptr; using boost::dynamic_pointer_cast; - -class Piece -{ -public: - Piece (shared_ptr c) - : content (c) - , video_position (c->position ()) - , audio_position (c->position ()) - {} - - Piece (shared_ptr c, shared_ptr d) - : content (c) - , decoder (d) - , video_position (c->position ()) - , audio_position (c->position ()) - {} - - shared_ptr content; - shared_ptr decoder; - Time video_position; - Time audio_position; -}; +using boost::optional; Player::Player (shared_ptr f, shared_ptr p) : _film (f) , _playlist (p) - , _video (true) - , _audio (true) , _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) + , _approximate_size (false) { _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)); - set_video_container_size (fit_ratio_within (_film->container()->ratio (), _film->full_frame ())); -} - -void -Player::disable_video () -{ - _video = false; + set_video_container_size (_film->frame_size ()); } void -Player::disable_audio () +Player::setup_pieces () { - _audio = false; -} + list > old_pieces = _pieces; + _pieces.clear (); -bool -Player::pass () -{ - if (!_have_valid_pieces) { - setup_pieces (); - _have_valid_pieces = true; - } + ContentList content = _playlist->content (); - Time earliest_t = TIME_MAX; - shared_ptr earliest; - enum { - VIDEO, - AUDIO - } type = VIDEO; + for (ContentList::iterator i = content.begin(); i != content.end(); ++i) { - for (list >::iterator i = _pieces.begin(); i != _pieces.end(); ++i) { - if ((*i)->decoder->done ()) { + if (!(*i)->paths_valid ()) { continue; } - - if (_video && dynamic_pointer_cast ((*i)->decoder)) { - if ((*i)->video_position < earliest_t) { - earliest_t = (*i)->video_position; - earliest = *i; - type = VIDEO; + + shared_ptr decoder; + optional frc; + + /* Work out a FrameRateChange for the best overlap video for this content, in case we need it below */ + DCPTime best_overlap_t; + shared_ptr best_overlap; + for (ContentList::iterator j = content.begin(); j != content.end(); ++j) { + shared_ptr vc = dynamic_pointer_cast (*j); + if (!vc) { + continue; + } + + DCPTime const overlap = max (vc->position(), (*i)->position()) - min (vc->end(), (*i)->end()); + if (overlap > best_overlap_t) { + best_overlap = vc; + best_overlap_t = overlap; } } - if (_audio && dynamic_pointer_cast ((*i)->decoder)) { - if ((*i)->audio_position < earliest_t) { - earliest_t = (*i)->audio_position; - earliest = *i; - type = AUDIO; - } + optional best_overlap_frc; + if (best_overlap) { + best_overlap_frc = FrameRateChange (best_overlap->video_frame_rate(), _film->video_frame_rate ()); + } else { + /* No video overlap; e.g. if the DCP is just audio */ + best_overlap_frc = FrameRateChange (_film->video_frame_rate(), _film->video_frame_rate ()); } - } - if (!earliest) { - flush (); - return true; - } + /* FFmpeg */ + shared_ptr fc = dynamic_pointer_cast (*i); + if (fc) { + decoder.reset (new FFmpegDecoder (fc, _film->log())); + frc = FrameRateChange (fc->video_frame_rate(), _film->video_frame_rate()); + } - switch (type) { - case VIDEO: - if (earliest_t > _video_position) { - emit_black (); - } else { - earliest->decoder->pass (); + shared_ptr dc = dynamic_pointer_cast (*i); + if (dc) { + decoder.reset (new DCPDecoder (dc, _film->log ())); + frc = FrameRateChange (dc->video_frame_rate(), _film->video_frame_rate()); } - 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 ac = dynamic_pointer_cast (earliest->content); - assert (ac); - shared_ptr re = resampler (ac, false); - if (re) { - shared_ptr b = re->flush (); - if (b->frames ()) { - process_audio (earliest, b, ac->audio_length ()); - } + /* ImageContent */ + shared_ptr ic = dynamic_pointer_cast (*i); + if (ic) { + /* See if we can re-use an old ImageDecoder */ + for (list >::const_iterator j = old_pieces.begin(); j != old_pieces.end(); ++j) { + shared_ptr imd = dynamic_pointer_cast ((*j)->decoder); + if (imd && imd->content() == ic) { + decoder = imd; } } - } - break; - } - if (_audio) { - Time audio_done_up_to = TIME_MAX; - for (list >::iterator i = _pieces.begin(); i != _pieces.end(); ++i) { - if (dynamic_pointer_cast ((*i)->decoder)) { - audio_done_up_to = min (audio_done_up_to, (*i)->audio_position); + if (!decoder) { + decoder.reset (new ImageDecoder (ic)); } - } - TimedAudioBuffers