From 444b6dc1aa4257bc4b3d83eb1c97caf77ce970fe Mon Sep 17 00:00:00 2001 From: Oleksandr Khodos Date: Tue, 16 Jan 2024 16:32:57 +0200 Subject: [PATCH 1/6] Add default segment duration to config --- include/packager/live_packager.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/packager/live_packager.h b/include/packager/live_packager.h index 8ce80d46251..0ecd7e57058 100644 --- a/include/packager/live_packager.h +++ b/include/packager/live_packager.h @@ -79,7 +79,7 @@ struct LiveConfig { OutputFormat format; TrackType track_type; // TOOD: do we need non-integer durations? - double segment_duration_sec; + double segment_duration_sec = 5.0; // TODO: should we allow for keys to be hex string? std::vector iv; From 4e80a1caa300959ba56b605b5f0f7f0364ec7790 Mon Sep 17 00:00:00 2001 From: Oleksandr Khodos Date: Tue, 16 Jan 2024 16:38:46 +0200 Subject: [PATCH 2/6] Fix typo --- include/packager/live_packager.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/packager/live_packager.h b/include/packager/live_packager.h index 0ecd7e57058..edbd6376865 100644 --- a/include/packager/live_packager.h +++ b/include/packager/live_packager.h @@ -78,7 +78,7 @@ struct LiveConfig { OutputFormat format; TrackType track_type; - // TOOD: do we need non-integer durations? + // TODO(david): do we need non-integer durations? double segment_duration_sec = 5.0; // TODO: should we allow for keys to be hex string? From a00a6a72758eb6a0a75a8a43c6fecb262d516c75 Mon Sep 17 00:00:00 2001 From: Oleksandr Khodos Date: Wed, 17 Jan 2024 13:07:56 +0200 Subject: [PATCH 3/6] Solidify segment duration --- include/packager/live_packager.h | 2 -- packager/live_packager.cc | 6 ++++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/packager/live_packager.h b/include/packager/live_packager.h index edbd6376865..a96b9735fa1 100644 --- a/include/packager/live_packager.h +++ b/include/packager/live_packager.h @@ -78,8 +78,6 @@ struct LiveConfig { OutputFormat format; TrackType track_type; - // TODO(david): do we need non-integer durations? - double segment_duration_sec = 5.0; // TODO: should we allow for keys to be hex string? std::vector iv; diff --git a/packager/live_packager.cc b/packager/live_packager.cc index 036b49ff7fa..1bbda839598 100644 --- a/packager/live_packager.cc +++ b/packager/live_packager.cc @@ -25,6 +25,8 @@ namespace { using StreamDescriptors = std::vector; +constexpr double SEGMENT_DURATION = 5.0; + const std::string INPUT_FNAME = "memory://input_file"; const std::string INIT_SEGMENT_FNAME = "init.mp4"; @@ -247,7 +249,7 @@ Status LivePackager::PackageInit(const Segment& init_segment, shaka::PackagingParams packaging_params; packaging_params.chunking_params.segment_duration_in_seconds = - config_.segment_duration_sec; + SEGMENT_DURATION; // in order to enable init packaging as a separate execution. packaging_params.init_segment_only = true; @@ -306,7 +308,7 @@ Status LivePackager::Package(const Segment& init_segment, shaka::PackagingParams packaging_params; packaging_params.chunking_params.segment_duration_in_seconds = - config_.segment_duration_sec; + SEGMENT_DURATION; packaging_params.mp4_output_params.sequence_number = config_.segment_number; From c7335c7dcc50d44990baaf962191d47ff5fdbc60 Mon Sep 17 00:00:00 2001 From: Oleksandr Khodos Date: Thu, 18 Jan 2024 16:18:34 +0200 Subject: [PATCH 4/6] Fix tests --- packager/live_packager_test.cc | 3 --- 1 file changed, 3 deletions(-) diff --git a/packager/live_packager_test.cc b/packager/live_packager_test.cc index acabc144f61..a6d390cc315 100644 --- a/packager/live_packager_test.cc +++ b/packager/live_packager_test.cc @@ -35,7 +35,6 @@ const uint8_t kIv[]{ 0x08, 0x09, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, }; -const double kSegmentDurationInSeconds = 5.0; const int kNumSegments = 10; std::filesystem::path GetTestDataFilePath(const std::string& name) { @@ -246,7 +245,6 @@ class LivePackagerBaseTest : public ::testing::Test { void SetupLivePackagerConfig(const LiveConfig& config) { LiveConfig new_live_config = config; - new_live_config.segment_duration_sec = kSegmentDurationInSeconds; switch (new_live_config.protection_scheme) { case LiveConfig::EncryptionScheme::NONE: break; @@ -369,7 +367,6 @@ TEST_F(LivePackagerBaseTest, CustomMoofSequenceNumber) { live_config.format = LiveConfig::OutputFormat::FMP4; live_config.track_type = LiveConfig::TrackType::VIDEO; live_config.protection_scheme = LiveConfig::EncryptionScheme::NONE; - live_config.segment_duration_sec = kSegmentDurationInSeconds; for (unsigned int i = 0; i < kNumSegments; i++) { live_config.segment_number = i + 1; From 79dae2033ed4a647c176071e0b6dee8135adc077 Mon Sep 17 00:00:00 2001 From: Oleksandr Khodos Date: Thu, 18 Jan 2024 19:03:57 +0200 Subject: [PATCH 5/6] Add comment to default segment duration --- packager/live_packager.cc | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packager/live_packager.cc b/packager/live_packager.cc index 1bbda839598..70eb78518fa 100644 --- a/packager/live_packager.cc +++ b/packager/live_packager.cc @@ -25,7 +25,9 @@ namespace { using StreamDescriptors = std::vector; -constexpr double SEGMENT_DURATION = 5.0; +// Shaka requires a non-zero value for segment duration otherwise it throws an error. +// For our use-case of packaging segments individually, this value has no effect. +constexpr double DEFAULT_SEGMENT_DURATION = 5.0; const std::string INPUT_FNAME = "memory://input_file"; const std::string INIT_SEGMENT_FNAME = "init.mp4"; @@ -249,7 +251,7 @@ Status LivePackager::PackageInit(const Segment& init_segment, shaka::PackagingParams packaging_params; packaging_params.chunking_params.segment_duration_in_seconds = - SEGMENT_DURATION; + DEFAULT_SEGMENT_DURATION; // in order to enable init packaging as a separate execution. packaging_params.init_segment_only = true; @@ -308,7 +310,7 @@ Status LivePackager::Package(const Segment& init_segment, shaka::PackagingParams packaging_params; packaging_params.chunking_params.segment_duration_in_seconds = - SEGMENT_DURATION; + DEFAULT_SEGMENT_DURATION; packaging_params.mp4_output_params.sequence_number = config_.segment_number; From 90cb6cfe505c49c12c70d2961bd7d7c3992e3e6c Mon Sep 17 00:00:00 2001 From: David Chen <89227356+chenda6@users.noreply.github.com> Date: Mon, 22 Jan 2024 11:22:10 -0800 Subject: [PATCH 6/6] feat: add m2ts_offset_ms to LiveConfig (#15) --- include/packager/live_packager.h | 5 +++++ packager/live_packager.cc | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/include/packager/live_packager.h b/include/packager/live_packager.h index ad749fab4a6..0665ab4af3c 100644 --- a/include/packager/live_packager.h +++ b/include/packager/live_packager.h @@ -91,6 +91,11 @@ struct LiveConfig { /// For M2TS output: /// It is be used to set the continuity counter (TODO: UNIMPLEMENTED). uint32_t segment_number = 0; + + /// The offset to be applied to transport stream (e.g. MPEG2-TS, HLS packed + /// audio) timestamps to compensate for possible negative timestamps in the + /// input. + int32_t m2ts_offset_ms = 0; }; class LivePackager { diff --git a/packager/live_packager.cc b/packager/live_packager.cc index b07256a031e..7e9291d46c2 100644 --- a/packager/live_packager.cc +++ b/packager/live_packager.cc @@ -263,6 +263,8 @@ Status LivePackager::PackageInit(const Segment& init_segment, DEFAULT_SEGMENT_DURATION; packaging_params.mp4_output_params.include_pssh_in_stream = false; + packaging_params.transport_stream_timestamp_offset_ms = + config_.m2ts_offset_ms; // in order to enable init packaging as a separate execution. packaging_params.init_segment_only = true; @@ -325,6 +327,8 @@ Status LivePackager::Package(const Segment& init_segment, packaging_params.mp4_output_params.sequence_number = config_.segment_number; packaging_params.mp4_output_params.include_pssh_in_stream = false; + packaging_params.transport_stream_timestamp_offset_ms = + config_.m2ts_offset_ms; EncryptionParams& encryption_params = packaging_params.encryption_params; // As a side effect of InitializeEncryption, encryption_params will be