From 36efdb98659ffe71c37e448a8a991bb4bdc1f97b Mon Sep 17 00:00:00 2001 From: "lee.fordyce" Date: Mon, 13 May 2024 11:12:58 -0600 Subject: [PATCH 1/3] fix: retain mehd box after re-encryption --- packager/live_packager_test.cc | 21 +++++++++++++++++++++ packager/media/formats/mp4/mp4_muxer.cc | 4 ++++ 2 files changed, 25 insertions(+) diff --git a/packager/live_packager_test.cc b/packager/live_packager_test.cc index 0332b86545..cc2ddf5bf4 100644 --- a/packager/live_packager_test.cc +++ b/packager/live_packager_test.cc @@ -844,6 +844,27 @@ TEST_F(LivePackagerBaseTest, VerifyPrdDecryptReEncrypt) { } } +TEST_F(LivePackagerBaseTest, MehdBoxIncluded) { + std::vector init_segment_buffer = + ReadTestDataFile("encrypted/prd_data/init.mp4"); + ASSERT_FALSE(init_segment_buffer.empty()); + + LiveConfig live_config; + live_config.format = LiveConfig::OutputFormat::FMP4; + live_config.track_type = LiveConfig::TrackType::VIDEO; + live_config.protection_scheme = LiveConfig::EncryptionScheme::CENC; + live_config.decryption_key = HexStringToVector(kKeyHex); + live_config.decryption_key_id = HexStringToVector(kKeyIdHex); + SetupLivePackagerConfig(live_config); + + SegmentData init_seg(init_segment_buffer.data(), + init_segment_buffer.size()); + SegmentBuffer actual_buf; + const auto status = live_packager_->PackageInit(init_seg, actual_buf); + ASSERT_EQ(Status::OK, status); + ASSERT_GT(actual_buf.Size(), 0); +} + TEST_F(LivePackagerBaseTest, EncryptionFailure) { std::vector init_segment_buffer = ReadTestDataFile("input/init.mp4"); ASSERT_FALSE(init_segment_buffer.empty()); diff --git a/packager/media/formats/mp4/mp4_muxer.cc b/packager/media/formats/mp4/mp4_muxer.cc index 013e58f8fc..7f4d8ff413 100644 --- a/packager/media/formats/mp4/mp4_muxer.cc +++ b/packager/media/formats/mp4/mp4_muxer.cc @@ -246,6 +246,8 @@ Status MP4Muxer::DelayInitializeMuxer() { // supported yet. if (codec_fourcc != FOURCC_avc3 && codec_fourcc != FOURCC_hev1) ftyp->compatible_brands.push_back(FOURCC_cmfc); + + moov->extends.header.fragment_duration = streams()[0].get()->duration(); } moov->header.creation_time = IsoTimeNow(); @@ -254,6 +256,8 @@ Status MP4Muxer::DelayInitializeMuxer() { moov->tracks.resize(streams().size()); moov->extends.tracks.resize(streams().size()); +// const StreamInfo* stream_info = streams()[0].get(); +// moov->extends.header.fragment_duration = stream_info->duration(); // Initialize tracks. for (uint32_t i = 0; i < streams().size(); ++i) { From 921a7a7df0b20ed0d2743ff55dead7873b8e5aa1 Mon Sep 17 00:00:00 2001 From: "lee.fordyce" Date: Mon, 13 May 2024 12:20:08 -0600 Subject: [PATCH 2/3] fix: retain mehd box after re-encryption --- packager/live_packager_test.cc | 10 ++++++++-- packager/media/formats/mp4/mp4_muxer.cc | 3 +-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/packager/live_packager_test.cc b/packager/live_packager_test.cc index e276b1b2ef..c248b22654 100644 --- a/packager/live_packager_test.cc +++ b/packager/live_packager_test.cc @@ -915,12 +915,18 @@ TEST_F(LivePackagerBaseTest, MehdBoxIncluded) { live_config.decryption_key_id = HexStringToVector(kKeyIdHex); SetupLivePackagerConfig(live_config); - SegmentData init_seg(init_segment_buffer.data(), - init_segment_buffer.size()); + SegmentData init_seg(init_segment_buffer.data(), init_segment_buffer.size()); SegmentBuffer actual_buf; const auto status = live_packager_->PackageInit(init_seg, actual_buf); ASSERT_EQ(Status::OK, status); ASSERT_GT(actual_buf.Size(), 0); + + media::mp4::Movie exp_moov; + ASSERT_TRUE(GetBox(init_seg, exp_moov)); + media::mp4::Movie act_moov; + ASSERT_TRUE(GetBox(actual_buf, act_moov)); + + ASSERT_EQ(exp_moov.extends.header, act_moov.extends.header); } TEST_F(LivePackagerBaseTest, EncryptionFailure) { diff --git a/packager/media/formats/mp4/mp4_muxer.cc b/packager/media/formats/mp4/mp4_muxer.cc index fe482175fa..676582a4b4 100644 --- a/packager/media/formats/mp4/mp4_muxer.cc +++ b/packager/media/formats/mp4/mp4_muxer.cc @@ -247,6 +247,7 @@ Status MP4Muxer::DelayInitializeMuxer() { if (codec_fourcc != FOURCC_avc3 && codec_fourcc != FOURCC_hev1) ftyp->compatible_brands.push_back(FOURCC_cmfc); + // Carry over movie extends header duration from init segment. moov->extends.header.fragment_duration = streams()[0].get()->duration(); } @@ -256,8 +257,6 @@ Status MP4Muxer::DelayInitializeMuxer() { moov->tracks.resize(streams().size()); moov->extends.tracks.resize(streams().size()); -// const StreamInfo* stream_info = streams()[0].get(); -// moov->extends.header.fragment_duration = stream_info->duration(); // Initialize tracks. for (uint32_t i = 0; i < streams().size(); ++i) { From b38aa61ff30770c38509e1cf4938c678a905d20e Mon Sep 17 00:00:00 2001 From: "lee.fordyce" Date: Mon, 13 May 2024 14:08:35 -0600 Subject: [PATCH 3/3] fix: PR feedback --- packager/live_packager_test.cc | 28 +--------------------------- 1 file changed, 1 insertion(+), 27 deletions(-) diff --git a/packager/live_packager_test.cc b/packager/live_packager_test.cc index c248b22654..0f52678125 100644 --- a/packager/live_packager_test.cc +++ b/packager/live_packager_test.cc @@ -893,6 +893,7 @@ TEST_F(LivePackagerBaseTest, EditListAfterRepackage) { ASSERT_TRUE(GetBox(init_seg, exp_moov)); media::mp4::Movie act_moov; ASSERT_TRUE(GetBox(actual_buf, act_moov)); + ASSERT_EQ(exp_moov.extends.header, act_moov.extends.header); ASSERT_EQ(exp_moov.tracks.size(), act_moov.tracks.size()); for (size_t i(0); i < exp_moov.tracks.size(); ++i) { @@ -902,33 +903,6 @@ TEST_F(LivePackagerBaseTest, EditListAfterRepackage) { } } -TEST_F(LivePackagerBaseTest, MehdBoxIncluded) { - std::vector init_segment_buffer = - ReadTestDataFile("encrypted/prd_data/init.mp4"); - ASSERT_FALSE(init_segment_buffer.empty()); - - LiveConfig live_config; - live_config.format = LiveConfig::OutputFormat::FMP4; - live_config.track_type = LiveConfig::TrackType::VIDEO; - live_config.protection_scheme = LiveConfig::EncryptionScheme::CENC; - live_config.decryption_key = HexStringToVector(kKeyHex); - live_config.decryption_key_id = HexStringToVector(kKeyIdHex); - SetupLivePackagerConfig(live_config); - - SegmentData init_seg(init_segment_buffer.data(), init_segment_buffer.size()); - SegmentBuffer actual_buf; - const auto status = live_packager_->PackageInit(init_seg, actual_buf); - ASSERT_EQ(Status::OK, status); - ASSERT_GT(actual_buf.Size(), 0); - - media::mp4::Movie exp_moov; - ASSERT_TRUE(GetBox(init_seg, exp_moov)); - media::mp4::Movie act_moov; - ASSERT_TRUE(GetBox(actual_buf, act_moov)); - - ASSERT_EQ(exp_moov.extends.header, act_moov.extends.header); -} - TEST_F(LivePackagerBaseTest, EncryptionFailure) { std::vector init_segment_buffer = ReadTestDataFile("input/init.mp4"); ASSERT_FALSE(init_segment_buffer.empty());