X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fplayer.cc;h=7bf78c905248487e2e9d3723c38d267827e4a11b;hb=02f028d271677b3b3669b5cdfda1597108a34b80;hp=8cc1849e865f0909001a55374954bca5fbe48247;hpb=ec7c27b80a07bffcdb175512fa6d3811c277d959;p=dcpomatic.git diff --git a/src/lib/player.cc b/src/lib/player.cc index 8cc1849e8..7bf78c905 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 @@ -22,18 +22,23 @@ #include "film.h" #include "ffmpeg_decoder.h" #include "ffmpeg_content.h" -#include "still_image_decoder.h" -#include "still_image_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 "job.h" #include "image.h" +#include "image_proxy.h" #include "ratio.h" #include "resampler.h" #include "log.h" #include "scaler.h" +#include "player_video_frame.h" +#include "frame_rate_change.h" + +#define LOG_GENERAL(...) _film->log()->log (String::compose (__VA_ARGS__), Log::TYPE_GENERAL); using std::list; using std::cout; @@ -46,47 +51,6 @@ using boost::shared_ptr; using boost::weak_ptr; using boost::dynamic_pointer_cast; -//#define DEBUG_PLAYER 1 - -class Piece -{ -public: - Piece (shared_ptr c) - : content (c) - , video_position (c->start ()) - , audio_position (c->start ()) - {} - - Piece (shared_ptr c, shared_ptr d) - : content (c) - , decoder (d) - , video_position (c->start ()) - , audio_position (c->start ()) - {} - - shared_ptr content; - shared_ptr decoder; - Time video_position; - Time audio_position; -}; - -#ifdef DEBUG_PLAYER -std::ostream& operator<<(std::ostream& s, Piece const & p) -{ - if (dynamic_pointer_cast (p.content)) { - s << "\tffmpeg "; - } else if (dynamic_pointer_cast (p.content)) { - s << "\tstill image"; - } else if (dynamic_pointer_cast (p.content)) { - s << "\tsndfile "; - } - - s << " at " << p.content->start() << " until " << p.content->end(); - - return s; -} -#endif - Player::Player (shared_ptr f, shared_ptr p) : _film (f) , _playlist (p) @@ -95,12 +59,13 @@ Player::Player (shared_ptr f, shared_ptr p) , _have_valid_pieces (false) , _video_position (0) , _audio_position (0) - , _audio_buffers (f->audio_channels(), 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) { - _playlist->Changed.connect (bind (&Player::playlist_changed, this)); - _playlist->ContentChanged.connect (bind (&Player::content_changed, this, _1, _2, _3)); - _film->Changed.connect (bind (&Player::film_changed, this, _1)); - set_video_container_size (_film->container()->size (_film->full_frame ())); + _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 (_film->frame_size ()); } void @@ -120,13 +85,8 @@ Player::pass () { if (!_have_valid_pieces) { setup_pieces (); - _have_valid_pieces = true; } -#ifdef DEBUG_PLAYER - cout << "= PASS\n"; -#endif - Time earliest_t = TIME_MAX; shared_ptr earliest; enum { @@ -135,11 +95,14 @@ Player::pass () } type = VIDEO; for (list >::iterator i = _pieces.begin(); i != _pieces.end(); ++i) { - if ((*i)->decoder->done ()) { + if ((*i)->decoder->done () || (*i)->content->length_after_trim() == 0) { continue; } - if (_video && dynamic_pointer_cast ((*i)->decoder)) { + shared_ptr vd = dynamic_pointer_cast ((*i)->decoder); + shared_ptr ad = dynamic_pointer_cast ((*i)->decoder); + + if (_video && vd) { if ((*i)->video_position < earliest_t) { earliest_t = (*i)->video_position; earliest = *i; @@ -147,7 +110,7 @@ Player::pass () } } - if (_audio && dynamic_pointer_cast ((*i)->decoder)) { + if (_audio && ad && ad->has_audio ()) { if ((*i)->audio_position < earliest_t) { earliest_t = (*i)->audio_position; earliest = *i; @@ -157,10 +120,6 @@ Player::pass () } if (!earliest) { -#ifdef DEBUG_PLAYER - cout << "no earliest piece.\n"; -#endif - flush (); return true; } @@ -168,30 +127,22 @@ Player::pass () switch (type) { case VIDEO: if (earliest_t > _video_position) { -#ifdef DEBUG_PLAYER - cout << "no video here; emitting black frame (earliest=" << earliest_t << ", video_position=" << _video_position << ").\n"; -#endif emit_black (); } else { -#ifdef DEBUG_PLAYER - cout << "Pass " << *earliest << "\n"; -#endif - earliest->decoder->pass (); + if (earliest->repeating ()) { + earliest->repeat (this); + } else { + earliest->decoder->pass (); + } } break; case AUDIO: if (earliest_t > _audio_position) { -#ifdef DEBUG_PLAYER - cout << "no audio here; emitting silence.\n"; -#endif emit_silence (_film->time_to_audio_frames (earliest_t - _audio_position)); } else { -#ifdef DEBUG_PLAYER - cout << "Pass " << *earliest << "\n"; -#endif earliest->decoder->pass (); - + if (earliest->decoder->done()) { shared_ptr ac = dynamic_pointer_cast (earliest->content); assert (ac); @@ -199,7 +150,7 @@ Player::pass () if (re) { shared_ptr b = re->flush (); if (b->frames ()) { - process_audio (earliest, b, ac->audio_length ()); + process_audio (earliest, b, ac->audio_length (), true); } } } @@ -207,16 +158,42 @@ Player::pass () break; } -#ifdef DEBUG_PLAYER - cout << "\tpost pass " << _video_position << " " << _audio_position << "\n"; -#endif + if (_audio) { + boost::optional