X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fplayer.cc;h=d62d8f8b6408bf66b95ddb7eb08f1c51bea3aae0;hb=d487ee606113a2b4bbab1810758e9777792f1cac;hp=357c69e82d2d3c1e7d997e0ae600d831b82d6425;hpb=3e1ae9934f3b908943c90db523ae2332022b5f1d;p=dcpomatic.git diff --git a/src/lib/player.cc b/src/lib/player.cc index 357c69e82..d62d8f8b6 100644 --- a/src/lib/player.cc +++ b/src/lib/player.cc @@ -75,7 +75,7 @@ Player::pass () bool done = true; - if (_video_decoder < _video_decoders.size ()) { + if (_video && _video_decoder < _video_decoders.size ()) { /* Run video decoder; this may also produce audio */ @@ -87,7 +87,9 @@ Player::pass () done = false; } - } else if (!_video && _playlist->audio_from() == Playlist::AUDIO_FFMPEG && _sequential_audio_decoder < _audio_decoders.size ()) { + } + + if (!_video && _audio && _playlist->audio_from() == Playlist::AUDIO_FFMPEG && _sequential_audio_decoder < _audio_decoders.size ()) { /* We're not producing video, so we may need to run FFmpeg content to get the audio */ @@ -99,8 +101,10 @@ Player::pass () done = false; } - } else if (_playlist->audio_from() == Playlist::AUDIO_SNDFILE) { + } + if (_audio && _playlist->audio_from() == Playlist::AUDIO_SNDFILE) { + /* We're getting audio from SndfileContent */ for (vector >::iterator i = _audio_decoders.begin(); i != _audio_decoders.end(); ++i) { @@ -130,13 +134,13 @@ Player::set_progress (shared_ptr job) } void -Player::process_video (shared_ptr i, bool same, shared_ptr s, double t) +Player::process_video (shared_ptr i, bool same, shared_ptr s, double t) { Video (i, same, s, _video_start[_video_decoder] + t); } void -Player::process_audio (weak_ptr c, shared_ptr b, double t) +Player::process_audio (weak_ptr c, shared_ptr b, double t) { AudioMapping mapping = _film->audio_mapping (); if (!_audio_buffers) { @@ -172,6 +176,10 @@ Player::seek (double t) _have_valid_decoders = true; } + if (_video_decoders.empty ()) { + return true; + } + /* Find the decoder that contains this position */ _video_decoder = 0; while (1) { @@ -221,67 +229,69 @@ Player::setup_decoders () double video_so_far = 0; double audio_so_far = 0; - - list > vc = _playlist->video (); - for (list >::iterator i = vc.begin(); i != vc.end(); ++i) { - - shared_ptr video_content; - shared_ptr audio_content; - shared_ptr video_decoder; - shared_ptr audio_decoder; - - /* XXX: into content? */ - - shared_ptr fc = dynamic_pointer_cast (*i); - if (fc) { - shared_ptr fd ( - new FFmpegDecoder ( - _film, fc, _video, - _audio && _playlist->audio_from() == Playlist::AUDIO_FFMPEG, - _subtitles - ) - ); + + for (int l = 0; l < _playlist->loop(); ++l) { + list > vc = _playlist->video (); + for (list >::iterator i = vc.begin(); i != vc.end(); ++i) { - video_content = fc; - audio_content = fc; - video_decoder = fd; - audio_decoder = fd; - } - - shared_ptr ic = dynamic_pointer_cast (*i); - if (ic) { - video_content = ic; - video_decoder.reset (new ImageMagickDecoder (_film, ic)); + shared_ptr video_content; + shared_ptr audio_content; + shared_ptr video_decoder; + shared_ptr audio_decoder; + + /* XXX: into content? */ + + shared_ptr fc = dynamic_pointer_cast (*i); + if (fc) { + shared_ptr fd ( + new FFmpegDecoder ( + _film, fc, _video, + _audio && _playlist->audio_from() == Playlist::AUDIO_FFMPEG, + _subtitles + ) + ); + + video_content = fc; + audio_content = fc; + video_decoder = fd; + audio_decoder = fd; + } + + shared_ptr ic = dynamic_pointer_cast (*i); + if (ic) { + video_content = ic; + video_decoder.reset (new ImageMagickDecoder (_film, ic)); + } + + video_decoder->connect_video (shared_from_this ()); + _video_decoders.push_back (video_decoder); + _video_start.push_back (video_so_far); + video_so_far += video_content->video_length() / video_content->video_frame_rate(); + + if (audio_decoder && _playlist->audio_from() == Playlist::AUDIO_FFMPEG) { + audio_decoder->Audio.connect (bind (&Player::process_audio, this, audio_content, _1, _2)); + _audio_decoders.push_back (audio_decoder); + _audio_start.push_back (audio_so_far); + audio_so_far += double(audio_content->audio_length()) / audio_content->audio_frame_rate(); + } } - video_decoder->connect_video (shared_from_this ()); - _video_decoders.push_back (video_decoder); - _video_start.push_back (video_so_far); - video_so_far += video_content->video_length() / video_content->video_frame_rate(); - - if (audio_decoder && _playlist->audio_from() == Playlist::AUDIO_FFMPEG) { - audio_decoder->Audio.connect (bind (&Player::process_audio, this, audio_content, _1, _2)); - _audio_decoders.push_back (audio_decoder); - _audio_start.push_back (audio_so_far); - audio_so_far += double(audio_content->audio_length()) / audio_content->audio_frame_rate(); - } - } - - _video_decoder = 0; - _sequential_audio_decoder = 0; - - if (_playlist->audio_from() == Playlist::AUDIO_SNDFILE) { + _video_decoder = 0; + _sequential_audio_decoder = 0; - list > ac = _playlist->audio (); - for (list >::iterator i = ac.begin(); i != ac.end(); ++i) { + if (_playlist->audio_from() == Playlist::AUDIO_SNDFILE) { - shared_ptr sc = dynamic_pointer_cast (*i); - assert (sc); - - shared_ptr d (new SndfileDecoder (_film, sc)); - d->Audio.connect (bind (&Player::process_audio, this, sc, _1, _2)); - _audio_decoders.push_back (d); - _audio_start.push_back (audio_so_far); + list > ac = _playlist->audio (); + for (list >::iterator i = ac.begin(); i != ac.end(); ++i) { + + shared_ptr sc = dynamic_pointer_cast (*i); + assert (sc); + + shared_ptr d (new SndfileDecoder (_film, sc)); + d->Audio.connect (bind (&Player::process_audio, this, sc, _1, _2)); + _audio_decoders.push_back (d); + _audio_start.push_back (audio_so_far); + } } } } @@ -301,10 +311,7 @@ Player::content_changed (weak_ptr w, int p) } if (p == VideoContentProperty::VIDEO_LENGTH) { - if (dynamic_pointer_cast (c)) { - /* FFmpeg content length changes are serious; we need new decoders */ - _have_valid_decoders = false; - } + _have_valid_decoders = false; } }