Fix stream length for DCP content (#2688).
authorCarl Hetherington <cth@carlh.net>
Mon, 20 May 2024 13:21:51 +0000 (15:21 +0200)
committerCarl Hetherington <cth@carlh.net>
Tue, 21 May 2024 07:38:03 +0000 (09:38 +0200)
src/lib/dcp_examiner.cc
test/audio_content_test.cc

index 88c9a5b700a64e279c5b459610c29f70955ec1d3..ae5f9e9c08979534f906a41dd0bd850dce3c90e4 100644 (file)
@@ -167,7 +167,7 @@ DCPExaminer::DCPExaminer (shared_ptr<const DCPContent> content, bool tolerant)
 
                if (reel->main_sound()) {
                        _has_audio = true;
-                       _audio_length += reel->main_sound()->actual_duration();
+                       auto const edit_rate = reel->main_sound()->edit_rate();
 
                        if (!reel->main_sound()->asset_ref().resolved()) {
                                LOG_GENERAL("Main sound %1 of reel %2 is missing", reel->main_sound()->id(), reel->id());
@@ -192,6 +192,7 @@ DCPExaminer::DCPExaminer (shared_ptr<const DCPContent> content, bool tolerant)
                                }
 
                                _audio_language = try_to_parse_language (asset->language());
+                               _audio_length += reel->main_sound()->actual_duration() * (asset->sampling_rate() * edit_rate.denominator / edit_rate.numerator);
                        }
                }
 
index f2c095fabac671bc1e8b0888b83e4f7f366886dd..97f55d53a599c66c61dda4167770006c7d4475a8 100644 (file)
 
 
 #include "lib/audio_content.h"
+#include "lib/dcp_content.h"
 #include "lib/content_factory.h"
+#include "lib/film.h"
 #include "lib/maths_util.h"
 #include "lib/video_content.h"
 #include "test.h"
+#include <dcp/sound_asset.h>
+#include <dcp/sound_asset_reader.h>
 #include <boost/test/unit_test.hpp>
 
 
@@ -259,3 +263,27 @@ BOOST_AUTO_TEST_CASE (audio_content_fades_same_as_video)
        BOOST_CHECK(content->audio->fade_out() == dcpomatic::ContentTime::from_frames(81 * 48000 / 24, 48000));
 }
 
+
+
+BOOST_AUTO_TEST_CASE(fade_out_works_with_dcp_content)
+{
+       auto dcp = std::make_shared<DCPContent>(TestPaths::private_data() / "JourneyToJah_TLR-1_F_EN-DE-FR_CH_51_2K_LOK_20140225_DGL_SMPTE_OV");
+       auto film = new_test_film2("fade_out_works_with_dcp_content", { dcp });
+       dcp->audio->set_fade_out(dcpomatic::ContentTime::from_seconds(15));
+       make_and_verify_dcp(film);
+
+       int32_t max = 0;
+       dcp::SoundAsset sound(find_file(film->dir(film->dcp_name()), "pcm_"));
+       auto reader = sound.start_read();
+       for (auto i = 0; i < sound.intrinsic_duration(); ++i) {
+               auto frame = reader->get_frame(i);
+               for (auto j = 0; j < frame->channels(); ++j) {
+                       for (auto k = 0; k < frame->samples(); ++k) {
+                               max = std::max(max, frame->get(j, k));
+                       }
+               }
+       }
+
+       BOOST_CHECK(max > 2000);
+}
+