Cleanup: extract pass_atmos().
[dcpomatic.git] / src / lib / dcp_decoder.cc
index 7baf05dadc6e40b6872fade1534cc287431ce720..9f1a80160062dcc33decdf95395075f2b3a8be28 100644 (file)
@@ -183,18 +183,49 @@ DCPDecoder::pass_video(Frame frame, dcp::Size size)
 }
 
 
-bool
+void
+DCPDecoder::pass_audio(Frame frame, double video_frame_rate)
+{
+       auto const entry_point = (*_reel)->main_sound()->entry_point().get_value_or(0);
+       auto sf = _sound_reader->get_frame (entry_point + frame);
+       auto from = sf->data ();
+
+       int const channels = _dcp_content->audio->stream()->channels ();
+       int const frames = sf->size() / (3 * channels);
+       auto data = make_shared<AudioBuffers>(channels, frames);
+       auto data_data = data->data();
+       for (int i = 0; i < frames; ++i) {
+               for (int j = 0; j < channels; ++j) {
+                       data_data[j][i] = static_cast<int> ((from[0] << 8) | (from[1] << 16) | (from[2] << 24)) / static_cast<float> (INT_MAX - 256);
+                       from += 3;
+               }
+       }
+
+       audio->emit(film(), _dcp_content->audio->stream(), data, ContentTime::from_frames(_offset, video_frame_rate) + _next);
+}
+
+
+void
+DCPDecoder::pass_atmos(Frame frame)
+{
+       DCPOMATIC_ASSERT (_atmos_metadata);
+       auto const entry_point = (*_reel)->atmos()->entry_point().get_value_or(0);
+       atmos->emit (film(), _atmos_reader->get_frame(entry_point + frame), _offset + frame, *_atmos_metadata);
+}
+
+
+Decoder::PassResult
 DCPDecoder::pass ()
 {
        if (!_dcp_content->can_be_played()) {
-               return true;
+               return PassResult::finished();
        }
 
        if (_reel == _reels.end()) {
                if (audio) {
                        audio->flush ();
                }
-               return true;
+               return PassResult::finished();
        }
 
        auto const vfr = _dcp_content->active_video_frame_rate (film());
@@ -215,28 +246,11 @@ DCPDecoder::pass ()
        }
 
        if (_sound_reader && (_decode_referenced || !_dcp_content->reference_audio())) {
-               auto const entry_point = (*_reel)->main_sound()->entry_point().get_value_or(0);
-               auto sf = _sound_reader->get_frame (entry_point + frame);
-               auto from = sf->data ();
-
-               int const channels = _dcp_content->audio->stream()->channels ();
-               int const frames = sf->size() / (3 * channels);
-               auto data = make_shared<AudioBuffers>(channels, frames);
-               auto data_data = data->data();
-               for (int i = 0; i < frames; ++i) {
-                       for (int j = 0; j < channels; ++j) {
-                               data_data[j][i] = static_cast<int> ((from[0] << 8) | (from[1] << 16) | (from[2] << 24)) / static_cast<float> (INT_MAX - 256);
-                               from += 3;
-                       }
-               }
-
-               audio->emit (film(), _dcp_content->audio->stream(), data, ContentTime::from_frames (_offset, vfr) + _next);
+               pass_audio(frame, vfr);
        }
 
        if (_atmos_reader) {
-               DCPOMATIC_ASSERT (_atmos_metadata);
-               auto const entry_point = (*_reel)->atmos()->entry_point().get_value_or(0);
-               atmos->emit (film(), _atmos_reader->get_frame(entry_point + frame), _offset + frame, *_atmos_metadata);
+               pass_atmos(frame);
        }
 
        _next += ContentTime::from_frames (1, vfr);
@@ -248,7 +262,7 @@ DCPDecoder::pass ()
                }
        }
 
-       return false;
+       return PassResult::ok();
 }