X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fplayer.cc;h=60686e78178e00276513e248a51a97623c861764;hb=69efa47dbd1684c897f780c80fd68bdc05c817f4;hp=786180a6a5f27d6e50331a1530a43b70e253f22f;hpb=c77dabbe4e6bb031edf4aa82f5e890fe605bafe1;p=dcpomatic.git diff --git a/src/lib/player.cc b/src/lib/player.cc index 786180a6a..60686e781 100644 --- a/src/lib/player.cc +++ b/src/lib/player.cc @@ -17,6 +17,7 @@ */ +#include #include "player.h" #include "film.h" #include "ffmpeg_decoder.h" @@ -57,7 +58,6 @@ Player::Player (shared_ptr f, shared_ptr p) , _playlist (p) , _video (true) , _audio (true) - , _subtitles (true) , _have_valid_pieces (false) , _position (0) , _audio_buffers (f->dcp_audio_channels(), 0) @@ -79,12 +79,6 @@ Player::disable_audio () _audio = false; } -void -Player::disable_subtitles () -{ - _subtitles = false; -} - bool Player::pass () { @@ -101,8 +95,12 @@ Player::pass () shared_ptr earliest; for (list >::iterator i = _pieces.begin(); i != _pieces.end(); ++i) { -// cout << "check " << (*i)->content->file() << " start=" << (*i)->content->start() << ", next=" << (*i)->decoder->next() << ", end=" << (*i)->content->end() << "\n"; - if (((*i)->decoder->next() + (*i)->content->start()) >= (*i)->content->end()) { + cout << "check " << (*i)->content->file() + << " start=" << (*i)->content->start() + << ", position=" << (*i)->decoder->position() + << ", end=" << (*i)->content->end() << "\n"; + + if ((*i)->decoder->done ()) { continue; } @@ -110,15 +108,16 @@ Player::pass () continue; } - Time const t = (*i)->content->start() + (*i)->decoder->next(); + Time const t = (*i)->content->start() + (*i)->decoder->position(); if (t < earliest_t) { -// cout << "\t candidate; " << t << " " << (t / TIME_HZ) << ".\n"; + cout << "\t candidate; " << t << " " << (t / TIME_HZ) << ".\n"; earliest_t = t; earliest = *i; } } if (!earliest) { + flush (); return true; } @@ -137,14 +136,14 @@ Player::pass () } earliest->decoder->pass (); - _position = earliest->content->start() + earliest->decoder->next (); + _position = earliest->content->start() + earliest->decoder->position (); cout << "\tpassed to " << _position << " " << (_position / TIME_HZ) << "\n"; return false; } void -Player::process_video (weak_ptr weak_content, shared_ptr image, bool same, shared_ptr sub, Time time) +Player::process_video (weak_ptr weak_content, shared_ptr image, bool same, Time time) { shared_ptr content = weak_content.lock (); if (!content) { @@ -153,7 +152,7 @@ Player::process_video (weak_ptr weak_content, shared_ptr i time += content->start (); - Video (image, same, sub, time); + Video (image, same, time); } void @@ -172,8 +171,8 @@ Player::process_audio (weak_ptr weak_content, shared_ptr _next_audio) { /* We can emit some audio from our buffers */ - assert (_film->time_to_audio_frames (time - _next_audio) <= _audio_buffers.frames()); OutputAudioFrame const N = _film->time_to_audio_frames (time - _next_audio); + assert (N <= _audio_buffers.frames()); shared_ptr emit (new AudioBuffers (_audio_buffers.channels(), N)); emit->copy_from (&_audio_buffers, N, 0, 0); Audio (emit, _next_audio); @@ -189,6 +188,19 @@ Player::process_audio (weak_ptr weak_content, shared_ptrframes()); _audio_buffers.accumulate_frames (audio.get(), 0, 0, audio->frames ()); + _audio_buffers.set_frames (_audio_buffers.frames() + audio->frames()); +} + +void +Player::flush () +{ + if (_audio_buffers.frames() > 0) { + shared_ptr emit (new AudioBuffers (_audio_buffers.channels(), _audio_buffers.frames())); + emit->copy_from (&_audio_buffers, _audio_buffers.frames(), 0, 0); + Audio (emit, _next_audio); + _next_audio += _film->audio_frames_to_time (_audio_buffers.frames ()); + _audio_buffers.set_frames (0); + } } /** @return true on error */ @@ -234,8 +246,9 @@ void Player::add_black_piece (Time s, Time len) { shared_ptr nc (new NullContent (_film, s, len)); + nc->set_ratio (_film->container ()); shared_ptr bd (new BlackDecoder (_film, nc)); - bd->Video.connect (bind (&Player::process_video, this, nc, _1, _2, _3, _4)); + bd->Video.connect (bind (&Player::process_video, this, nc, _1, _2, _3)); _pieces.push_back (shared_ptr (new Piece (nc, bd))); cout << "\tblack @ " << s << " -- " << (s + len) << "\n"; } @@ -251,14 +264,6 @@ Player::add_silent_piece (Time s, Time len) } -struct ContentSorter -{ - bool operator() (shared_ptr a, shared_ptr b) - { - return a->start() < b->start(); - } -}; - void Player::setup_pieces () { @@ -279,10 +284,13 @@ Player::setup_pieces () shared_ptr fc = dynamic_pointer_cast (*i); if (fc) { - shared_ptr fd (new FFmpegDecoder (_film, fc, _video, _audio, _subtitles)); + shared_ptr fd (new FFmpegDecoder (_film, fc, _video, _audio)); - fd->Video.connect (bind (&Player::process_video, this, *i, _1, _2, _3, _4)); + fd->Video.connect (bind (&Player::process_video, this, *i, _1, _2, _3)); fd->Audio.connect (bind (&Player::process_audio, this, *i, _1, _2)); + if (_video_container_size) { + fd->set_video_container_size (_video_container_size.get ()); + } decoder = fd; cout << "\tFFmpeg @ " << fc->start() << " -- " << fc->end() << "\n"; @@ -302,7 +310,10 @@ Player::setup_pieces () if (!id) { id.reset (new ImageMagickDecoder (_film, ic)); - id->Video.connect (bind (&Player::process_video, this, *i, _1, _2, _3, _4)); + id->Video.connect (bind (&Player::process_video, this, *i, _1, _2, _3)); + if (_video_container_size) { + id->set_video_container_size (_video_container_size.get ()); + } } decoder = id; @@ -332,9 +343,11 @@ Player::setup_pieces () if (diff > 0) { add_black_piece (video_pos, diff); } - video_pos = (*i)->content->end(); - } else { + } + + shared_ptr ac = dynamic_pointer_cast ((*i)->content); + if (ac && ac->audio_channels()) { Time const diff = (*i)->content->start() - audio_pos; if (diff > 0) { add_silent_piece (video_pos, diff); @@ -358,7 +371,7 @@ Player::content_changed (weak_ptr w, int p) return; } - if (p == ContentProperty::START || p == VideoContentProperty::VIDEO_LENGTH) { + if (p == ContentProperty::START || p == ContentProperty::LENGTH) { _have_valid_pieces = false; } } @@ -368,3 +381,15 @@ Player::playlist_changed () { _have_valid_pieces = false; } + +void +Player::set_video_container_size (libdcp::Size s) +{ + _video_container_size = s; + for (list >::iterator i = _pieces.begin(); i != _pieces.end(); ++i) { + shared_ptr vd = dynamic_pointer_cast ((*i)->decoder); + if (vd) { + vd->set_video_container_size (s); + } + } +}