WIP: more
[dcpomatic.git] / src / lib / player.cc
index ee0a07411d157d39c7c956081c3febe3c2452706..7e915296ed1dfc06dc16b0535557671d85cebe53 100644 (file)
@@ -277,7 +277,11 @@ Player::setup_pieces_unlocked ()
                        }
                }
 
-               auto piece = make_shared<Piece>(_film, i, decoder, frc, _fast);
+               vector<Piece::Pair> content = {
+                       Piece::Pair(i, decoder)
+               };
+
+               auto piece = make_shared<Piece>(_film, content, frc, _fast);
                _pieces.push_back (piece);
 
                if (i->video) {
@@ -812,15 +816,6 @@ Player::video (weak_ptr<Piece> wp, PieceVideo video)
                return;
        }
 
-       if (!piece->use_video()) {
-               return;
-       }
-
-       auto frc = piece->frame_rate_change();
-       if (frc.skip && (video.frame % 2) == 1) {
-               return;
-       }
-
        LOG_DEBUG_PLAYER("Received video frame %1 at %2", video.frame, to_string(video.time));
 
        /* Discard if it's before the content's period or the last accurate seek.  We can't discard
@@ -831,10 +826,6 @@ Player::video (weak_ptr<Piece> wp, PieceVideo video)
                return;
        }
 
-       if (piece->ignore_video_at(video.time)) {
-               return;
-       }
-
        /* Fill gaps that we discover now that we have some video which needs to be emitted.
           This is where we need to fill to.
        */
@@ -890,6 +881,7 @@ Player::video (weak_ptr<Piece> wp, PieceVideo video)
        _last_video[wp] = piece->player_video (video, _video_container_size);
 
        DCPTime t = video.time;
+       auto const frc = piece->frame_rate_change();
        for (int i = 0; i < frc.repeat; ++i) {
                if (t < piece->end()) {
                        emit_video (_last_video[wp], t);
@@ -909,29 +901,30 @@ Player::audio (weak_ptr<Piece> wp, PieceAudio audio)
                return;
        }
 
-       int const rfr = piece->resampled_audio_frame_rate ();
+       LOG_DEBUG_PLAYER("Received audio at %1", to_string(audio.time));
 
-       /* Compute time in the DCP */
-       auto time = piece->resampled_audio_to_dcp (audio.frame);
-       LOG_DEBUG_PLAYER("Received audio frame %1 at %2", audio.frame, to_string(time));
+       /* The end of this block in the DCP */
+       int const rfr = piece->resampled_audio_frame_rate ();
+       auto end = audio.time + DCPTime::from_frames(audio.audio->frames(), rfr);
 
-       /* And the end of this block in the DCP */
-       auto end = time + DCPTime::from_frames(audio.audio->frames(), rfr);
+       /* XXX: is this still necessary? don't the checks in Piece take care of this now?
+        * Maybe replace with some assertions & run tests.
+        */
 
        /* Remove anything that comes before the start or after the end of the content */
-       if (time < piece->position()) {
-               auto cut = discard_audio (audio.audio, time, piece->position());
+       if (audio.time < piece->position()) {
+               auto cut = discard_audio (audio.audio, audio.time, piece->position());
                if (!cut.first) {
                        /* This audio is entirely discarded */
                        return;
                }
                audio.audio = cut.first;
-               time = cut.second;
-       } else if (time > piece->end()) {
+               audio.time = cut.second;
+       } else if (audio.time > piece->end()) {
                /* Discard it all */
                return;
        } else if (end > piece->end()) {
-               Frame const remaining_frames = DCPTime(piece->end() - time).frames_round(rfr);
+               Frame const remaining_frames = DCPTime(piece->end() - audio.time).frames_round(rfr);
                if (remaining_frames == 0) {
                        return;
                }
@@ -950,18 +943,18 @@ Player::audio (weak_ptr<Piece> wp, PieceAudio audio)
 
        /* Remap */
 
-       audio.audio = remap (audio.audio, _film->audio_channels(), audio.stream->mapping());
+       audio.audio = remap (audio.audio, _film->audio_channels(), audio.mapping);
 
        /* Process */
 
        if (_audio_processor) {
-               audio.audio = _audio_processor->run (audio.audio, _film->audio_channels ());
+               audio.audio = _audio_processor->run (audio.audio, _film->audio_channels());
        }
 
        /* Push */
 
-       _audio_merger.push (audio.audio, time);
-       piece->set_last_push_end (audio.stream, time + DCPTime::from_frames(audio.audio->frames(), _film->audio_frame_rate()));
+       _audio_merger.push (audio.audio, audio.time);
+       piece->set_last_push_end (audio.stream, audio.time + DCPTime::from_frames(audio.audio->frames(), _film->audio_frame_rate()));
 }