From 1522079eb8e93323fdf7fd8d8f96e0b71914311e Mon Sep 17 00:00:00 2001 From: Anthony Lu Date: Wed, 2 Sep 2020 23:16:25 +0000 Subject: [PATCH 1/3] use second sample in webm and mp4 formats --- packager/media/formats/mp4/segmenter.cc | 6 ++++-- packager/media/formats/mp4/segmenter.h | 5 +++-- packager/media/formats/webm/segmenter.cc | 12 +++++++----- packager/media/formats/webm/segmenter.h | 3 ++- 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/packager/media/formats/mp4/segmenter.cc b/packager/media/formats/mp4/segmenter.cc index cce500dea49..5a8a9147193 100644 --- a/packager/media/formats/mp4/segmenter.cc +++ b/packager/media/formats/mp4/segmenter.cc @@ -138,8 +138,10 @@ Status Segmenter::AddSample(size_t stream_id, const MediaSample& sample) { if (!status.ok()) return status; - if (sample_duration_ == 0) - sample_duration_ = sample.duration(); + if (num_samples_ < 2) { + sample_durations_[num_samples_] = sample.duration(); + num_samples_++; + } stream_durations_[stream_id] += sample.duration(); return Status::OK; } diff --git a/packager/media/formats/mp4/segmenter.h b/packager/media/formats/mp4/segmenter.h index 724c12ef6fc..febdfb1fa1e 100644 --- a/packager/media/formats/mp4/segmenter.h +++ b/packager/media/formats/mp4/segmenter.h @@ -98,7 +98,7 @@ class Segmenter { /// @return The sample duration in the timescale of the media. /// Returns 0 if no samples are added yet. - uint32_t sample_duration() const { return sample_duration_; } + uint32_t sample_duration() const { return sample_durations_[1]; } protected: /// Update segmentation progress using ProgressListener. @@ -144,7 +144,8 @@ class Segmenter { ProgressListener* progress_listener_ = nullptr; uint64_t progress_target_ = 0u; uint64_t accumulated_progress_ = 0u; - uint32_t sample_duration_ = 0u; + uint32_t sample_durations_[2] = {0, 0}; + uint32_t num_samples_ = 0u; std::vector stream_durations_; std::vector key_frame_infos_; diff --git a/packager/media/formats/webm/segmenter.cc b/packager/media/formats/webm/segmenter.cc index b3ffdcfb188..e2479e0bc44 100644 --- a/packager/media/formats/webm/segmenter.cc +++ b/packager/media/formats/webm/segmenter.cc @@ -161,11 +161,13 @@ Status Segmenter::Finalize() { Status Segmenter::AddSample(const MediaSample& source_sample) { std::shared_ptr sample(source_sample.Clone()); - if (sample_duration_ == 0) { - first_timestamp_ = sample->pts(); - sample_duration_ = sample->duration(); - if (muxer_listener_) - muxer_listener_->OnSampleDurationReady(sample_duration_); + if (num_samples_ < 2) { + if (num_samples_ == 0) + first_timestamp_ = sample->pts(); + else + muxer_listener_->OnSampleDurationReady(sample_durations_[num_samples_]); + sample_durations_[num_samples_] = sample->duration(); + num_samples_++; } UpdateProgress(sample->duration()); diff --git a/packager/media/formats/webm/segmenter.h b/packager/media/formats/webm/segmenter.h index f6c7c2184d1..2ab0bcc21fa 100644 --- a/packager/media/formats/webm/segmenter.h +++ b/packager/media/formats/webm/segmenter.h @@ -139,7 +139,8 @@ class Segmenter { uint64_t progress_target_ = 0; uint64_t accumulated_progress_ = 0; uint64_t first_timestamp_ = 0; - int64_t sample_duration_ = 0; + int64_t sample_durations_[2] = {0, 0}; + int64_t num_samples_ = 0; // The position (in bytes) of the start of the Segment payload in the init // file. This is also the size of the header before the SeekHead. uint64_t segment_payload_pos_ = 0; From 393c2c841689d16e670be1760f41a06c4cebc975 Mon Sep 17 00:00:00 2001 From: Anthony Lu Date: Thu, 3 Sep 2020 18:44:17 +0000 Subject: [PATCH 2/3] missed line --- packager/media/formats/webm/segmenter.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packager/media/formats/webm/segmenter.cc b/packager/media/formats/webm/segmenter.cc index e2479e0bc44..85c3101abe9 100644 --- a/packager/media/formats/webm/segmenter.cc +++ b/packager/media/formats/webm/segmenter.cc @@ -162,11 +162,11 @@ Status Segmenter::AddSample(const MediaSample& source_sample) { std::shared_ptr sample(source_sample.Clone()); if (num_samples_ < 2) { + sample_durations_[num_samples_] = sample->duration(); if (num_samples_ == 0) first_timestamp_ = sample->pts(); else muxer_listener_->OnSampleDurationReady(sample_durations_[num_samples_]); - sample_durations_[num_samples_] = sample->duration(); num_samples_++; } From 30a6aa85fd96bce195d29fdac5e8e878cb9de9bd Mon Sep 17 00:00:00 2001 From: Anthony Lu Date: Tue, 8 Sep 2020 23:48:32 +0000 Subject: [PATCH 3/3] end to end update --- .../output.mpd | 34 +++++++------- .../output.mpd | 4 +- .../output.m3u8 | 2 +- .../encryption-and-two-trick-plays/output.mpd | 4 +- .../hls-only-dash-only-captions/output.mpd | 20 ++++----- .../output.mpd | 24 +++++----- .../live-profile-with-webm/output.m3u8 | 2 +- .../live-profile-with-webm/output.mpd | 2 +- .../opus-vp9-mp4-with-encryption/output.mpd | 2 +- .../vp8-mp4-with-encryption/output.mpd | 2 +- .../app/test/testdata/vp8-webm/output.mpd | 2 +- .../vp9-webm-with-blockgroup/output.mpd | 2 +- .../app/test/testdata/vp9-webm/output.mpd | 2 +- .../vtt-text-to-mp4-with-ad-cues/output.mpd | 44 +++++++++---------- .../webm-subsample-encryption/output.mpd | 2 +- .../output.mpd | 2 +- .../testdata/webm-with-encryption/output.mpd | 2 +- packager/media/formats/mp4/segmenter.h | 4 +- packager/media/formats/webm/segmenter.cc | 2 +- packager/media/formats/webm/segmenter.h | 2 +- 20 files changed, 80 insertions(+), 80 deletions(-) diff --git a/packager/app/test/testdata/audio-video-with-codec-switching-encryption-trick-play/output.mpd b/packager/app/test/testdata/audio-video-with-codec-switching-encryption-trick-play/output.mpd index 54d9782cb8b..2ebb04eb3a4 100644 --- a/packager/app/test/testdata/audio-video-with-codec-switching-encryption-trick-play/output.mpd +++ b/packager/app/test/testdata/audio-video-with-codec-switching-encryption-trick-play/output.mpd @@ -2,28 +2,14 @@ - + AAAANHBzc2gBAAAAEHfv7MCyTQKs4zweUuL7SwAAAAExMjM0NTY3ODkwMTIzNDU2AAAAAA== - - bear-640x360-hevc-video.mp4 - - - - - - - - - AAAANHBzc2gBAAAAEHfv7MCyTQKs4zweUuL7SwAAAAExMjM0NTY3ODkwMTIzNDU2AAAAAA== - - - - + bear-640x360-video.mp4 @@ -36,6 +22,20 @@ + + + + AAAANHBzc2gBAAAAEHfv7MCyTQKs4zweUuL7SwAAAAExMjM0NTY3ODkwMTIzNDU2AAAAAA== + + + + + bear-640x360-hevc-video.mp4 + + + + + @@ -54,7 +54,7 @@ AAAANHBzc2gBAAAAEHfv7MCyTQKs4zweUuL7SwAAAAExMjM0NTY3ODkwMTIzNDU2AAAAAA== - + bear-1280x720-video-trick_play_factor_1.mp4 diff --git a/packager/app/test/testdata/audio-video-with-two-trick-play/output.mpd b/packager/app/test/testdata/audio-video-with-two-trick-play/output.mpd index 1585bc0a20d..5964d2ca93f 100644 --- a/packager/app/test/testdata/audio-video-with-two-trick-play/output.mpd +++ b/packager/app/test/testdata/audio-video-with-two-trick-play/output.mpd @@ -10,7 +10,7 @@ - + bear-640x360-video-trick_play_factor_1.mp4 @@ -18,7 +18,7 @@ - + bear-640x360-video-trick_play_factor_2.mp4 diff --git a/packager/app/test/testdata/ec3-and-hls-single-segment-mp4-encrypted/output.m3u8 b/packager/app/test/testdata/ec3-and-hls-single-segment-mp4-encrypted/output.m3u8 index e9f0f91a991..02affa152e9 100644 --- a/packager/app/test/testdata/ec3-and-hls-single-segment-mp4-encrypted/output.m3u8 +++ b/packager/app/test/testdata/ec3-and-hls-single-segment-mp4-encrypted/output.m3u8 @@ -5,7 +5,7 @@ #EXT-X-MEDIA:TYPE=AUDIO,URI="bear-640x360-ec3-audio.m3u8",GROUP-ID="default-audio-group",NAME="stream_0",AUTOSELECT=YES,CHANNELS="2" -#EXT-X-STREAM-INF:BANDWIDTH=1174214,AVERAGE-BANDWIDTH=1061802,CODECS="avc1.64001e,ec-3",RESOLUTION=640x360,FRAME-RATE=9.990,AUDIO="default-audio-group" +#EXT-X-STREAM-INF:BANDWIDTH=1174214,AVERAGE-BANDWIDTH=1061802,CODECS="avc1.64001e,ec-3",RESOLUTION=640x360,FRAME-RATE=29.970,AUDIO="default-audio-group" bear-640x360-ec3-video.m3u8 #EXT-X-I-FRAME-STREAM-INF:BANDWIDTH=218705,AVERAGE-BANDWIDTH=159315,CODECS="avc1.64001e",RESOLUTION=640x360,URI="bear-640x360-ec3-video-iframe.m3u8" diff --git a/packager/app/test/testdata/encryption-and-two-trick-plays/output.mpd b/packager/app/test/testdata/encryption-and-two-trick-plays/output.mpd index 537a83b4509..591ce22a6d1 100644 --- a/packager/app/test/testdata/encryption-and-two-trick-plays/output.mpd +++ b/packager/app/test/testdata/encryption-and-two-trick-plays/output.mpd @@ -14,7 +14,7 @@ - + AAAANHBzc2gBAAAAEHfv7MCyTQKs4zweUuL7SwAAAAExMjM0NTY3ODkwMTIzNDU2AAAAAA== @@ -26,7 +26,7 @@ - + bear-640x360-video-trick_play_factor_2.mp4 diff --git a/packager/app/test/testdata/hls-only-dash-only-captions/output.mpd b/packager/app/test/testdata/hls-only-dash-only-captions/output.mpd index bf21bef5d68..f126b6e4b27 100644 --- a/packager/app/test/testdata/hls-only-dash-only-captions/output.mpd +++ b/packager/app/test/testdata/hls-only-dash-only-captions/output.mpd @@ -2,22 +2,22 @@ - - - + + + + - - + - - - - + + + - + + diff --git a/packager/app/test/testdata/live-profile-and-encryption-and-mult-files/output.mpd b/packager/app/test/testdata/live-profile-and-encryption-and-mult-files/output.mpd index a233a9be505..c5c9507a872 100644 --- a/packager/app/test/testdata/live-profile-and-encryption-and-mult-files/output.mpd +++ b/packager/app/test/testdata/live-profile-and-encryption-and-mult-files/output.mpd @@ -15,19 +15,19 @@ - - + + - + - - + + - + @@ -37,23 +37,23 @@ AAAANHBzc2gBAAAAEHfv7MCyTQKs4zweUuL7SwAAAAExMjM0NTY3ODkwMTIzNDU2AAAAAA== - + - + - + - + - + - + diff --git a/packager/app/test/testdata/live-profile-with-webm/output.m3u8 b/packager/app/test/testdata/live-profile-with-webm/output.m3u8 index 491aaf1b4ac..b5c12fccb67 100644 --- a/packager/app/test/testdata/live-profile-with-webm/output.m3u8 +++ b/packager/app/test/testdata/live-profile-with-webm/output.m3u8 @@ -5,5 +5,5 @@ #EXT-X-MEDIA:TYPE=AUDIO,URI="stream_0.m3u8",GROUP-ID="default-audio-group",NAME="stream_0",AUTOSELECT=YES,CHANNELS="2" -#EXT-X-STREAM-INF:BANDWIDTH=556353,AVERAGE-BANDWIDTH=412719,CODECS="vp08.00.10.08.01.02.02.02.00,vorbis",RESOLUTION=640x360,FRAME-RATE=30.303,AUDIO="default-audio-group" +#EXT-X-STREAM-INF:BANDWIDTH=556353,AVERAGE-BANDWIDTH=412719,CODECS="vp08.00.10.08.01.02.02.02.00,vorbis",RESOLUTION=640x360,FRAME-RATE=29.412,AUDIO="default-audio-group" stream_1.m3u8 diff --git a/packager/app/test/testdata/live-profile-with-webm/output.mpd b/packager/app/test/testdata/live-profile-with-webm/output.mpd index acfdd31f70c..cf2f3ec4501 100644 --- a/packager/app/test/testdata/live-profile-with-webm/output.mpd +++ b/packager/app/test/testdata/live-profile-with-webm/output.mpd @@ -14,7 +14,7 @@ - + diff --git a/packager/app/test/testdata/opus-vp9-mp4-with-encryption/output.mpd b/packager/app/test/testdata/opus-vp9-mp4-with-encryption/output.mpd index 283e00ab9eb..1a8bab81124 100644 --- a/packager/app/test/testdata/opus-vp9-mp4-with-encryption/output.mpd +++ b/packager/app/test/testdata/opus-vp9-mp4-with-encryption/output.mpd @@ -15,7 +15,7 @@ - + AAAANHBzc2gBAAAAEHfv7MCyTQKs4zweUuL7SwAAAAExMjM0NTY3ODkwMTIzNDU2AAAAAA== diff --git a/packager/app/test/testdata/vp8-mp4-with-encryption/output.mpd b/packager/app/test/testdata/vp8-mp4-with-encryption/output.mpd index 1fe1015889a..a089915cad0 100644 --- a/packager/app/test/testdata/vp8-mp4-with-encryption/output.mpd +++ b/packager/app/test/testdata/vp8-mp4-with-encryption/output.mpd @@ -2,7 +2,7 @@ - + AAAANHBzc2gBAAAAEHfv7MCyTQKs4zweUuL7SwAAAAExMjM0NTY3ODkwMTIzNDU2AAAAAA== diff --git a/packager/app/test/testdata/vp8-webm/output.mpd b/packager/app/test/testdata/vp8-webm/output.mpd index 777ddf60cfb..fbd60e85d7f 100644 --- a/packager/app/test/testdata/vp8-webm/output.mpd +++ b/packager/app/test/testdata/vp8-webm/output.mpd @@ -2,7 +2,7 @@ - + bear-640x360-video.webm diff --git a/packager/app/test/testdata/vp9-webm-with-blockgroup/output.mpd b/packager/app/test/testdata/vp9-webm-with-blockgroup/output.mpd index cbd3526f737..18e61dd25f4 100644 --- a/packager/app/test/testdata/vp9-webm-with-blockgroup/output.mpd +++ b/packager/app/test/testdata/vp9-webm-with-blockgroup/output.mpd @@ -2,7 +2,7 @@ - + bear-vp9-blockgroup-video.webm diff --git a/packager/app/test/testdata/vp9-webm/output.mpd b/packager/app/test/testdata/vp9-webm/output.mpd index 5cc8a6deda0..8db6e15644c 100644 --- a/packager/app/test/testdata/vp9-webm/output.mpd +++ b/packager/app/test/testdata/vp9-webm/output.mpd @@ -11,7 +11,7 @@ - + bear-320x240-vp9-opus-video.webm diff --git a/packager/app/test/testdata/vtt-text-to-mp4-with-ad-cues/output.mpd b/packager/app/test/testdata/vtt-text-to-mp4-with-ad-cues/output.mpd index e51298416e6..e357f76f8e9 100644 --- a/packager/app/test/testdata/vtt-text-to-mp4-with-ad-cues/output.mpd +++ b/packager/app/test/testdata/vtt-text-to-mp4-with-ad-cues/output.mpd @@ -11,24 +11,24 @@ - - - - + + + + - - + + - - - - + + + + - - + + @@ -44,22 +44,22 @@ - - - - + + + + - + - - - - + + + + - + diff --git a/packager/app/test/testdata/webm-subsample-encryption/output.mpd b/packager/app/test/testdata/webm-subsample-encryption/output.mpd index 69140f2d58e..0bc203a8f6c 100644 --- a/packager/app/test/testdata/webm-subsample-encryption/output.mpd +++ b/packager/app/test/testdata/webm-subsample-encryption/output.mpd @@ -2,7 +2,7 @@ - + AAAANHBzc2gBAAAAEHfv7MCyTQKs4zweUuL7SwAAAAExMjM0NTY3ODkwMTIzNDU2AAAAAA== diff --git a/packager/app/test/testdata/webm-vp9-full-sample-encryption/output.mpd b/packager/app/test/testdata/webm-vp9-full-sample-encryption/output.mpd index 69140f2d58e..0bc203a8f6c 100644 --- a/packager/app/test/testdata/webm-vp9-full-sample-encryption/output.mpd +++ b/packager/app/test/testdata/webm-vp9-full-sample-encryption/output.mpd @@ -2,7 +2,7 @@ - + AAAANHBzc2gBAAAAEHfv7MCyTQKs4zweUuL7SwAAAAExMjM0NTY3ODkwMTIzNDU2AAAAAA== diff --git a/packager/app/test/testdata/webm-with-encryption/output.mpd b/packager/app/test/testdata/webm-with-encryption/output.mpd index c06555905b4..de6bb6106f5 100644 --- a/packager/app/test/testdata/webm-with-encryption/output.mpd +++ b/packager/app/test/testdata/webm-with-encryption/output.mpd @@ -2,7 +2,7 @@ - + AAAANHBzc2gBAAAAEHfv7MCyTQKs4zweUuL7SwAAAAExMjM0NTY3ODkwMTIzNDU2AAAAAA== diff --git a/packager/media/formats/mp4/segmenter.h b/packager/media/formats/mp4/segmenter.h index febdfb1fa1e..28fe5b04b4a 100644 --- a/packager/media/formats/mp4/segmenter.h +++ b/packager/media/formats/mp4/segmenter.h @@ -98,7 +98,7 @@ class Segmenter { /// @return The sample duration in the timescale of the media. /// Returns 0 if no samples are added yet. - uint32_t sample_duration() const { return sample_durations_[1]; } + int64_t sample_duration() const { return sample_durations_[1]; } protected: /// Update segmentation progress using ProgressListener. @@ -144,7 +144,7 @@ class Segmenter { ProgressListener* progress_listener_ = nullptr; uint64_t progress_target_ = 0u; uint64_t accumulated_progress_ = 0u; - uint32_t sample_durations_[2] = {0, 0}; + size_t sample_durations_[2] = {0, 0}; uint32_t num_samples_ = 0u; std::vector stream_durations_; std::vector key_frame_infos_; diff --git a/packager/media/formats/webm/segmenter.cc b/packager/media/formats/webm/segmenter.cc index 85c3101abe9..ba6f8f7130f 100644 --- a/packager/media/formats/webm/segmenter.cc +++ b/packager/media/formats/webm/segmenter.cc @@ -165,7 +165,7 @@ Status Segmenter::AddSample(const MediaSample& source_sample) { sample_durations_[num_samples_] = sample->duration(); if (num_samples_ == 0) first_timestamp_ = sample->pts(); - else + else if (muxer_listener_) muxer_listener_->OnSampleDurationReady(sample_durations_[num_samples_]); num_samples_++; } diff --git a/packager/media/formats/webm/segmenter.h b/packager/media/formats/webm/segmenter.h index 2ab0bcc21fa..d137b0283c5 100644 --- a/packager/media/formats/webm/segmenter.h +++ b/packager/media/formats/webm/segmenter.h @@ -139,7 +139,7 @@ class Segmenter { uint64_t progress_target_ = 0; uint64_t accumulated_progress_ = 0; uint64_t first_timestamp_ = 0; - int64_t sample_durations_[2] = {0, 0}; + size_t sample_durations_[2] = {0, 0}; int64_t num_samples_ = 0; // The position (in bytes) of the start of the Segment payload in the init // file. This is also the size of the header before the SeekHead.