Add Piece::reference_dcp_audio().
[dcpomatic.git] / src / lib / player.cc
index 451a0018a57dfe6d07efdc166d88ebcb287495c6..086cfbbbd7b259d447a5e68d01abe364b5b8d8c6 100644 (file)
@@ -187,8 +187,9 @@ Player::setup_pieces_unlocked ()
 
                shared_ptr<Decoder> old_decoder;
                for (auto j: old_pieces) {
-                       if (j->content == i) {
-                               old_decoder = j->decoder;
+                       auto decoder = j->decoder_for(i);
+                       if (decoder) {
+                               old_decoder = decoder;
                                break;
                        }
                }
@@ -258,7 +259,7 @@ Player::setup_pieces_unlocked ()
        }
 
        for (auto i = _pieces.begin(); i != _pieces.end(); ++i) {
-               if ((*i)->use_video() && (*i)->content->video->frame_type() != VideoFrameType::THREE_D_LEFT && (*i)->content->video->frame_type() != VideoFrameType::THREE_D_RIGHT) {
+               if ((*i)->use_video() && (*i)->video_frame_type() != VideoFrameType::THREE_D_LEFT && (*i)->video_frame_type() != VideoFrameType::THREE_D_RIGHT) {
                        /* Look for content later in the content list with in-use video that overlaps this */
                        auto period = DCPTimePeriod((*i)->position(), (*i)->end(_film));
                        auto j = i;
@@ -584,7 +585,7 @@ Player::pass ()
                        continue;
                }
 
-               auto const t = i->content_time_to_dcp (max(i->decoder->position(), i->content->trim_start()));
+               auto const t = i->decoder_position ();
                if (t > i->end(_film)) {
                        i->done = true;
                } else {
@@ -625,15 +626,13 @@ Player::pass ()
        switch (which) {
        case CONTENT:
        {
-               LOG_DEBUG_PLAYER ("Calling pass() on %1", earliest_content->content->path(0));
-               earliest_content->done = earliest_content->decoder->pass ();
-               auto dcp = dynamic_pointer_cast<DCPContent>(earliest_content->content);
-               if (dcp && !_play_referenced && dcp->reference_audio()) {
+               earliest_content->pass();
+               if (!_play_referenced && earliest_content->reference_dcp_audio()) {
                        /* We are skipping some referenced DCP audio content, so we need to update _last_audio_time
                           to `hide' the fact that no audio was emitted during the referenced DCP (though
                           we need to behave as though it was).
                        */
-                       _last_audio_time = dcp->end (_film);
+                       _last_audio_time = earliest_content->end (_film);
                }
                break;
        }
@@ -869,9 +868,6 @@ Player::audio (weak_ptr<Piece> wp, AudioStreamPtr stream, ContentAudio content_a
                return;
        }
 
-       auto content = piece->content->audio;
-       DCPOMATIC_ASSERT (content);
-
        int const rfr = piece->resampled_audio_frame_rate (_film);
 
        /* Compute time in the DCP */
@@ -905,9 +901,9 @@ Player::audio (weak_ptr<Piece> wp, AudioStreamPtr stream, ContentAudio content_a
 
        /* Gain */
 
-       if (content->gain() != 0) {
+       if (piece->audio_gain() != 0) {
                auto gain = make_shared<AudioBuffers>(content_audio.audio);
-               gain->apply_gain (content->gain());
+               gain->apply_gain (piece->audio_gain());
                content_audio.audio = gain;
        }