From 634ee65663bd2eae1745db31f111e732529b97b3 Mon Sep 17 00:00:00 2001 From: KongQun Yang Date: Mon, 2 Apr 2018 16:53:29 -0700 Subject: [PATCH] Generate a more accurate time in Period@duration Chrome internally uses time accurate to microseconds, which is implemented per MSE spec (https://www.w3.org/TR/media-source/). Generate Period@duration with better precision to avoid possible buffered range gaps in Chrome (possibly other browsers too), which may lead to other problems like playback stall. b/74238961 Fixes #368. Change-Id: I357a0f62b67f75c7ca044bb99ea4e3c8bbb6fecd --- packager/app/test/testdata/acc-he/output.mpd | 2 +- .../output.mpd | 2 +- .../audio-video-with-language-override/output.mpd | 2 +- .../audio-video-with-trick-play/output.mpd | 2 +- .../audio-video-with-two-trick-play/output.mpd | 2 +- packager/app/test/testdata/audio-video/output.mpd | 2 +- .../test/testdata/bear-640x360-av-cbcs-golden.mpd | 2 +- .../test/testdata/bear-640x360-av-cenc-golden.mpd | 2 +- .../bear-640x360-av-cenc-non-iop-golden.mpd | 2 +- .../testdata/encryption-and-ad-cues/output.mpd | 4 ++-- .../encryption-and-no-clear-lead/output.mpd | 2 +- .../encryption-and-no-pssh-in-stream/output.mpd | 2 +- .../testdata/encryption-and-trick-play/output.mpd | 2 +- .../encryption-and-two-trick-plays/output.mpd | 2 +- .../app/test/testdata/encryption-cbc-1/output.mpd | 2 +- .../app/test/testdata/encryption-cens/output.mpd | 2 +- .../output.mpd | 2 +- .../testdata/encryption-multi-keys/output.mpd | 2 +- .../encryption-of-only-video-stream/output.mpd | 2 +- .../encryption-using-fixed-key/output.mpd | 2 +- packager/app/test/testdata/encryption/output.mpd | 2 +- .../app/test/testdata/first-stream/output.mpd | 2 +- .../test/testdata/hevc-with-encryption/output.mpd | 2 +- .../live-static-profile-and-ad-cues/output.mpd | 4 ++-- .../test/testdata/live-static-profile/output.mpd | 2 +- .../opus-vp9-mp4-with-encryption/output.mpd | 2 +- .../app/test/testdata/video-audio-text/output.mpd | 2 +- packager/app/test/testdata/vorbis-webm/output.mpd | 2 +- .../testdata/vp8-mp4-with-encryption/output.mpd | 2 +- packager/app/test/testdata/vp8-webm/output.mpd | 2 +- .../testdata/vp9-webm-with-blockgroup/output.mpd | 2 +- packager/app/test/testdata/vp9-webm/output.mpd | 2 +- .../testdata/webm-subsample-encryption/output.mpd | 2 +- .../webm-vp9-full-sample-encryption/output.mpd | 2 +- .../test/testdata/webm-with-encryption/output.mpd | 2 +- .../output.mpd | 2 +- packager/app/test/testdata/wvm-input/output.mpd | 2 +- packager/mpd/base/mpd_utils.cc | 15 ++++++--------- packager/mpd/base/mpd_utils.h | 5 ----- packager/mpd/base/xml/xml_node.cc | 2 +- 40 files changed, 46 insertions(+), 54 deletions(-) diff --git a/packager/app/test/testdata/acc-he/output.mpd b/packager/app/test/testdata/acc-he/output.mpd index 1106893615..276c1d9ae2 100644 --- a/packager/app/test/testdata/acc-he/output.mpd +++ b/packager/app/test/testdata/acc-he/output.mpd @@ -1,6 +1,6 @@ - + diff --git a/packager/app/test/testdata/audio-video-with-language-override-with-subtag/output.mpd b/packager/app/test/testdata/audio-video-with-language-override-with-subtag/output.mpd index d29c8df8b5..0be5e0b9ca 100644 --- a/packager/app/test/testdata/audio-video-with-language-override-with-subtag/output.mpd +++ b/packager/app/test/testdata/audio-video-with-language-override-with-subtag/output.mpd @@ -1,6 +1,6 @@ - + diff --git a/packager/app/test/testdata/audio-video-with-language-override/output.mpd b/packager/app/test/testdata/audio-video-with-language-override/output.mpd index d29c8df8b5..0be5e0b9ca 100644 --- a/packager/app/test/testdata/audio-video-with-language-override/output.mpd +++ b/packager/app/test/testdata/audio-video-with-language-override/output.mpd @@ -1,6 +1,6 @@ - + diff --git a/packager/app/test/testdata/audio-video-with-trick-play/output.mpd b/packager/app/test/testdata/audio-video-with-trick-play/output.mpd index 2e5d2b6e3a..ad49391552 100644 --- a/packager/app/test/testdata/audio-video-with-trick-play/output.mpd +++ b/packager/app/test/testdata/audio-video-with-trick-play/output.mpd @@ -1,6 +1,6 @@ - + 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 3b460c01dd..17b7ff9db3 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 @@ -1,6 +1,6 @@ - + diff --git a/packager/app/test/testdata/audio-video/output.mpd b/packager/app/test/testdata/audio-video/output.mpd index 439c5f8a56..8ddaf172c8 100644 --- a/packager/app/test/testdata/audio-video/output.mpd +++ b/packager/app/test/testdata/audio-video/output.mpd @@ -1,6 +1,6 @@ - + diff --git a/packager/app/test/testdata/bear-640x360-av-cbcs-golden.mpd b/packager/app/test/testdata/bear-640x360-av-cbcs-golden.mpd index 180e0c3fc3..99cf60abf2 100644 --- a/packager/app/test/testdata/bear-640x360-av-cbcs-golden.mpd +++ b/packager/app/test/testdata/bear-640x360-av-cbcs-golden.mpd @@ -1,6 +1,6 @@ - + diff --git a/packager/app/test/testdata/bear-640x360-av-cenc-golden.mpd b/packager/app/test/testdata/bear-640x360-av-cenc-golden.mpd index 86dd31baee..fd79c082d7 100644 --- a/packager/app/test/testdata/bear-640x360-av-cenc-golden.mpd +++ b/packager/app/test/testdata/bear-640x360-av-cenc-golden.mpd @@ -1,6 +1,6 @@ - + diff --git a/packager/app/test/testdata/bear-640x360-av-cenc-non-iop-golden.mpd b/packager/app/test/testdata/bear-640x360-av-cenc-non-iop-golden.mpd index 26e917ef87..e7115967ab 100644 --- a/packager/app/test/testdata/bear-640x360-av-cenc-non-iop-golden.mpd +++ b/packager/app/test/testdata/bear-640x360-av-cenc-non-iop-golden.mpd @@ -1,6 +1,6 @@ - + diff --git a/packager/app/test/testdata/encryption-and-ad-cues/output.mpd b/packager/app/test/testdata/encryption-and-ad-cues/output.mpd index c908ddffb6..8a5dc7d887 100644 --- a/packager/app/test/testdata/encryption-and-ad-cues/output.mpd +++ b/packager/app/test/testdata/encryption-and-ad-cues/output.mpd @@ -1,6 +1,6 @@ - + @@ -28,7 +28,7 @@ - + diff --git a/packager/app/test/testdata/encryption-and-no-clear-lead/output.mpd b/packager/app/test/testdata/encryption-and-no-clear-lead/output.mpd index a5bb33e666..9d72c67203 100644 --- a/packager/app/test/testdata/encryption-and-no-clear-lead/output.mpd +++ b/packager/app/test/testdata/encryption-and-no-clear-lead/output.mpd @@ -1,6 +1,6 @@ - + diff --git a/packager/app/test/testdata/encryption-and-no-pssh-in-stream/output.mpd b/packager/app/test/testdata/encryption-and-no-pssh-in-stream/output.mpd index f79656db49..ffb3292a2d 100644 --- a/packager/app/test/testdata/encryption-and-no-pssh-in-stream/output.mpd +++ b/packager/app/test/testdata/encryption-and-no-pssh-in-stream/output.mpd @@ -1,6 +1,6 @@ - + diff --git a/packager/app/test/testdata/encryption-and-trick-play/output.mpd b/packager/app/test/testdata/encryption-and-trick-play/output.mpd index a6e4060da8..0969c57f85 100644 --- a/packager/app/test/testdata/encryption-and-trick-play/output.mpd +++ b/packager/app/test/testdata/encryption-and-trick-play/output.mpd @@ -1,6 +1,6 @@ - + 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 3a00aa367d..072a7b8ba6 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 @@ -1,6 +1,6 @@ - + diff --git a/packager/app/test/testdata/encryption-cbc-1/output.mpd b/packager/app/test/testdata/encryption-cbc-1/output.mpd index 0ae8520e08..840d146294 100644 --- a/packager/app/test/testdata/encryption-cbc-1/output.mpd +++ b/packager/app/test/testdata/encryption-cbc-1/output.mpd @@ -1,6 +1,6 @@ - + diff --git a/packager/app/test/testdata/encryption-cens/output.mpd b/packager/app/test/testdata/encryption-cens/output.mpd index 41ff5dd27f..2af43b290e 100644 --- a/packager/app/test/testdata/encryption-cens/output.mpd +++ b/packager/app/test/testdata/encryption-cens/output.mpd @@ -1,6 +1,6 @@ - + diff --git a/packager/app/test/testdata/encryption-multi-keys-with-stream-label/output.mpd b/packager/app/test/testdata/encryption-multi-keys-with-stream-label/output.mpd index 4a0f347933..b03313a45e 100644 --- a/packager/app/test/testdata/encryption-multi-keys-with-stream-label/output.mpd +++ b/packager/app/test/testdata/encryption-multi-keys-with-stream-label/output.mpd @@ -1,6 +1,6 @@ - + diff --git a/packager/app/test/testdata/encryption-multi-keys/output.mpd b/packager/app/test/testdata/encryption-multi-keys/output.mpd index 5a41ae8c6d..24841b16ab 100644 --- a/packager/app/test/testdata/encryption-multi-keys/output.mpd +++ b/packager/app/test/testdata/encryption-multi-keys/output.mpd @@ -1,6 +1,6 @@ - + diff --git a/packager/app/test/testdata/encryption-of-only-video-stream/output.mpd b/packager/app/test/testdata/encryption-of-only-video-stream/output.mpd index eaf51a8969..76e5680aa0 100644 --- a/packager/app/test/testdata/encryption-of-only-video-stream/output.mpd +++ b/packager/app/test/testdata/encryption-of-only-video-stream/output.mpd @@ -1,6 +1,6 @@ - + diff --git a/packager/app/test/testdata/encryption-using-fixed-key/output.mpd b/packager/app/test/testdata/encryption-using-fixed-key/output.mpd index 86dd31baee..fd79c082d7 100644 --- a/packager/app/test/testdata/encryption-using-fixed-key/output.mpd +++ b/packager/app/test/testdata/encryption-using-fixed-key/output.mpd @@ -1,6 +1,6 @@ - + diff --git a/packager/app/test/testdata/encryption/output.mpd b/packager/app/test/testdata/encryption/output.mpd index 86dd31baee..fd79c082d7 100644 --- a/packager/app/test/testdata/encryption/output.mpd +++ b/packager/app/test/testdata/encryption/output.mpd @@ -1,6 +1,6 @@ - + diff --git a/packager/app/test/testdata/first-stream/output.mpd b/packager/app/test/testdata/first-stream/output.mpd index fb984b99b1..32906dbcf9 100644 --- a/packager/app/test/testdata/first-stream/output.mpd +++ b/packager/app/test/testdata/first-stream/output.mpd @@ -1,6 +1,6 @@ - + diff --git a/packager/app/test/testdata/hevc-with-encryption/output.mpd b/packager/app/test/testdata/hevc-with-encryption/output.mpd index 181871f3f9..28268e9521 100644 --- a/packager/app/test/testdata/hevc-with-encryption/output.mpd +++ b/packager/app/test/testdata/hevc-with-encryption/output.mpd @@ -1,6 +1,6 @@ - + diff --git a/packager/app/test/testdata/live-static-profile-and-ad-cues/output.mpd b/packager/app/test/testdata/live-static-profile-and-ad-cues/output.mpd index 57fccba7d3..67589ed6f1 100644 --- a/packager/app/test/testdata/live-static-profile-and-ad-cues/output.mpd +++ b/packager/app/test/testdata/live-static-profile-and-ad-cues/output.mpd @@ -1,6 +1,6 @@ - + @@ -24,7 +24,7 @@ - + diff --git a/packager/app/test/testdata/live-static-profile/output.mpd b/packager/app/test/testdata/live-static-profile/output.mpd index 62fb42f2b0..6544f9a5bc 100644 --- a/packager/app/test/testdata/live-static-profile/output.mpd +++ b/packager/app/test/testdata/live-static-profile/output.mpd @@ -1,6 +1,6 @@ - + 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 e45f4b69ed..72210e76d3 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 @@ -1,6 +1,6 @@ - + diff --git a/packager/app/test/testdata/video-audio-text/output.mpd b/packager/app/test/testdata/video-audio-text/output.mpd index 5100875ffd..bc3952e791 100644 --- a/packager/app/test/testdata/video-audio-text/output.mpd +++ b/packager/app/test/testdata/video-audio-text/output.mpd @@ -1,6 +1,6 @@ - + diff --git a/packager/app/test/testdata/vorbis-webm/output.mpd b/packager/app/test/testdata/vorbis-webm/output.mpd index 94dbd388f8..4b8ced7f6f 100644 --- a/packager/app/test/testdata/vorbis-webm/output.mpd +++ b/packager/app/test/testdata/vorbis-webm/output.mpd @@ -1,6 +1,6 @@ - + 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 86accb25de..e2df7f0c9e 100644 --- a/packager/app/test/testdata/vp8-mp4-with-encryption/output.mpd +++ b/packager/app/test/testdata/vp8-mp4-with-encryption/output.mpd @@ -1,6 +1,6 @@ - + diff --git a/packager/app/test/testdata/vp8-webm/output.mpd b/packager/app/test/testdata/vp8-webm/output.mpd index 720151f188..e4a1fd8473 100644 --- a/packager/app/test/testdata/vp8-webm/output.mpd +++ b/packager/app/test/testdata/vp8-webm/output.mpd @@ -1,6 +1,6 @@ - + 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 5dffbdf421..57ca8e3ece 100644 --- a/packager/app/test/testdata/vp9-webm-with-blockgroup/output.mpd +++ b/packager/app/test/testdata/vp9-webm-with-blockgroup/output.mpd @@ -1,6 +1,6 @@ - + diff --git a/packager/app/test/testdata/vp9-webm/output.mpd b/packager/app/test/testdata/vp9-webm/output.mpd index 486673f553..7f61377760 100644 --- a/packager/app/test/testdata/vp9-webm/output.mpd +++ b/packager/app/test/testdata/vp9-webm/output.mpd @@ -1,6 +1,6 @@ - + diff --git a/packager/app/test/testdata/webm-subsample-encryption/output.mpd b/packager/app/test/testdata/webm-subsample-encryption/output.mpd index b51490fea9..50d2817883 100644 --- a/packager/app/test/testdata/webm-subsample-encryption/output.mpd +++ b/packager/app/test/testdata/webm-subsample-encryption/output.mpd @@ -1,6 +1,6 @@ - + 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 b51490fea9..50d2817883 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 @@ -1,6 +1,6 @@ - + diff --git a/packager/app/test/testdata/webm-with-encryption/output.mpd b/packager/app/test/testdata/webm-with-encryption/output.mpd index 9ba687e181..2e780a0818 100644 --- a/packager/app/test/testdata/webm-with-encryption/output.mpd +++ b/packager/app/test/testdata/webm-with-encryption/output.mpd @@ -1,6 +1,6 @@ - + diff --git a/packager/app/test/testdata/wvm-input-without-stripping-parameters-set-nalus/output.mpd b/packager/app/test/testdata/wvm-input-without-stripping-parameters-set-nalus/output.mpd index ab0e67668f..aaf48a7524 100644 --- a/packager/app/test/testdata/wvm-input-without-stripping-parameters-set-nalus/output.mpd +++ b/packager/app/test/testdata/wvm-input-without-stripping-parameters-set-nalus/output.mpd @@ -1,6 +1,6 @@ - + diff --git a/packager/app/test/testdata/wvm-input/output.mpd b/packager/app/test/testdata/wvm-input/output.mpd index f7e7772279..1c0e71ab9d 100644 --- a/packager/app/test/testdata/wvm-input/output.mpd +++ b/packager/app/test/testdata/wvm-input/output.mpd @@ -1,6 +1,6 @@ - + diff --git a/packager/mpd/base/mpd_utils.cc b/packager/mpd/base/mpd_utils.cc index afe6bb42a5..66dcf60e26 100644 --- a/packager/mpd/base/mpd_utils.cc +++ b/packager/mpd/base/mpd_utils.cc @@ -161,7 +161,12 @@ std::string GetAdaptationSetKey(const MediaInfo& media_info) { } std::string SecondsToXmlDuration(double seconds) { - return "PT" + DoubleToString(seconds) + "S"; + // Chrome internally uses time accurate to microseconds, which is implemented + // per MSE spec (https://www.w3.org/TR/media-source/). + // We need a string formatter that has at least microseconds accuracy for a + // normal video (with duration up to 3 hours). Chrome's DoubleToString + // implementation meets the requirement. + return "PT" + base::DoubleToString(seconds) + "S"; } bool GetDurationAttribute(xmlNodePtr node, float* duration) { @@ -196,14 +201,6 @@ bool OnlyOneTrue(bool b1, bool b2, bool b3) { return !MoreThanOneTrue(b1, b2, b3) && AtLeastOneTrue(b1, b2, b3); } -// Implement our own DoubleToString as base::DoubleToString uses third_party -// library dmg_fp. -std::string DoubleToString(double value) { - std::ostringstream stringstream; - stringstream << value; - return stringstream.str(); -} - // Coverts binary data into human readable UUID format. bool HexToUUID(const std::string& data, std::string* uuid_format) { DCHECK(uuid_format); diff --git a/packager/mpd/base/mpd_utils.h b/packager/mpd/base/mpd_utils.h index 38a26c3cec..02072f1297 100644 --- a/packager/mpd/base/mpd_utils.h +++ b/packager/mpd/base/mpd_utils.h @@ -58,11 +58,6 @@ bool MoreThanOneTrue(bool b1, bool b2, bool b3); bool AtLeastOneTrue(bool b1, bool b2, bool b3); bool OnlyOneTrue(bool b1, bool b2, bool b3); -/// Converts double to string. -/// @param value is the input double data. -/// @return value formatted in string. -std::string DoubleToString(double value); - /// Converts hex data to UUID format. Hex data must be size 16. /// @param data input hex data. /// @param uuid_format is the UUID format of the input. diff --git a/packager/mpd/base/xml/xml_node.cc b/packager/mpd/base/xml/xml_node.cc index a7a947c13a..34607162d6 100644 --- a/packager/mpd/base/xml/xml_node.cc +++ b/packager/mpd/base/xml/xml_node.cc @@ -121,7 +121,7 @@ void XmlNode::SetFloatingPointAttribute(const char* attribute_name, DCHECK(node_); DCHECK(attribute_name); xmlSetProp(node_.get(), BAD_CAST attribute_name, - BAD_CAST(DoubleToString(number).c_str())); + BAD_CAST(base::DoubleToString(number).c_str())); } void XmlNode::SetId(uint32_t id) {