Normalize crypto_period_index to 0 for negative timestamp

It is possible to see a negative timestamp if the input mp4 file
contains EditList.

Also increase the queue size for EncryptionKey to be able to handle
smaller crypto_period_duration during testing.

Change-Id: I68278bf482d6662e771d9b80f4d5409605065aac
This commit is contained in:
KongQun Yang 2018-07-27 15:50:41 -07:00
parent 51d39d96a1
commit bd98436241
8 changed files with 28 additions and 22 deletions

View File

@ -7,8 +7,8 @@
<ContentProtection schemeIdUri="urn:uuid:1077efec-c0b2-4d02-ace3-3c1e52e2fb4b"> <ContentProtection schemeIdUri="urn:uuid:1077efec-c0b2-4d02-ace3-3c1e52e2fb4b">
<cenc:pssh>AAAANHBzc2gBAAAAEHfv7MCyTQKs4zweUuL7SwAAAAExMjM0NTY3ODkwMTIzNDU2AAAAAA==</cenc:pssh> <cenc:pssh>AAAANHBzc2gBAAAAEHfv7MCyTQKs4zweUuL7SwAAAAExMjM0NTY3ODkwMTIzNDU2AAAAAA==</cenc:pssh>
</ContentProtection> </ContentProtection>
<Representation id="0" bandwidth="978382" codecs="avc1.64001e" mimeType="video/mp4" sar="1:1" width="640" height="360"> <Representation id="0" bandwidth="2632184" codecs="avc1.64001f" mimeType="video/mp4" sar="1:1" width="1280" height="720">
<SegmentTemplate timescale="30000" initialization="bear-640x360-video-init.mp4" media="bear-640x360-video-$Number$.m4s" startNumber="1"> <SegmentTemplate timescale="30000" initialization="bear-1280x720-video-init.mp4" media="bear-1280x720-video-$Number$.m4s" startNumber="1">
<SegmentTimeline> <SegmentTimeline>
<S t="0" d="30030" r="1"/> <S t="0" d="30030" r="1"/>
<S t="60060" d="22022"/> <S t="60060" d="22022"/>
@ -23,8 +23,8 @@
</SegmentTimeline> </SegmentTimeline>
</SegmentTemplate> </SegmentTemplate>
</Representation> </Representation>
<Representation id="2" bandwidth="2632184" codecs="avc1.64001f" mimeType="video/mp4" sar="1:1" width="1280" height="720"> <Representation id="2" bandwidth="978382" codecs="avc1.64001e" mimeType="video/mp4" sar="1:1" width="640" height="360">
<SegmentTemplate timescale="30000" initialization="bear-1280x720-video-init.mp4" media="bear-1280x720-video-$Number$.m4s" startNumber="1"> <SegmentTemplate timescale="30000" initialization="bear-640x360-video-init.mp4" media="bear-640x360-video-$Number$.m4s" startNumber="1">
<SegmentTimeline> <SegmentTimeline>
<S t="0" d="30030" r="1"/> <S t="0" d="30030" r="1"/>
<S t="60060" d="22022"/> <S t="60060" d="22022"/>
@ -37,17 +37,7 @@
<ContentProtection schemeIdUri="urn:uuid:1077efec-c0b2-4d02-ace3-3c1e52e2fb4b"> <ContentProtection schemeIdUri="urn:uuid:1077efec-c0b2-4d02-ace3-3c1e52e2fb4b">
<cenc:pssh>AAAANHBzc2gBAAAAEHfv7MCyTQKs4zweUuL7SwAAAAExMjM0NTY3ODkwMTIzNDU2AAAAAA==</cenc:pssh> <cenc:pssh>AAAANHBzc2gBAAAAEHfv7MCyTQKs4zweUuL7SwAAAAExMjM0NTY3ODkwMTIzNDU2AAAAAA==</cenc:pssh>
</ContentProtection> </ContentProtection>
<Representation id="3" bandwidth="134015" codecs="mp4a.40.2" mimeType="audio/mp4" audioSamplingRate="44100"> <Representation id="3" bandwidth="134272" codecs="mp4a.40.2" mimeType="audio/mp4" audioSamplingRate="44100">
<AudioChannelConfiguration schemeIdUri="urn:mpeg:dash:23003:3:audio_channel_configuration:2011" value="2"/>
<SegmentTemplate timescale="44100" initialization="bear-320x180-audio-init.mp4" media="bear-320x180-audio-$Number$.m4s" startNumber="1">
<SegmentTimeline>
<S t="0" d="45056"/>
<S t="45056" d="44032"/>
<S t="89088" d="33792"/>
</SegmentTimeline>
</SegmentTemplate>
</Representation>
<Representation id="4" bandwidth="134272" codecs="mp4a.40.2" mimeType="audio/mp4" audioSamplingRate="44100">
<AudioChannelConfiguration schemeIdUri="urn:mpeg:dash:23003:3:audio_channel_configuration:2011" value="2"/> <AudioChannelConfiguration schemeIdUri="urn:mpeg:dash:23003:3:audio_channel_configuration:2011" value="2"/>
<SegmentTemplate timescale="44100" initialization="bear-1280x720-audio-init.mp4" media="bear-1280x720-audio-$Number$.m4s" startNumber="1"> <SegmentTemplate timescale="44100" initialization="bear-1280x720-audio-init.mp4" media="bear-1280x720-audio-$Number$.m4s" startNumber="1">
<SegmentTimeline> <SegmentTimeline>
@ -57,6 +47,16 @@
</SegmentTimeline> </SegmentTimeline>
</SegmentTemplate> </SegmentTemplate>
</Representation> </Representation>
<Representation id="4" bandwidth="134015" codecs="mp4a.40.2" mimeType="audio/mp4" audioSamplingRate="44100">
<AudioChannelConfiguration schemeIdUri="urn:mpeg:dash:23003:3:audio_channel_configuration:2011" value="2"/>
<SegmentTemplate timescale="44100" initialization="bear-320x180-audio-init.mp4" media="bear-320x180-audio-$Number$.m4s" startNumber="1">
<SegmentTimeline>
<S t="0" d="45056"/>
<S t="45056" d="44032"/>
<S t="89088" d="33792"/>
</SegmentTimeline>
</SegmentTemplate>
</Representation>
<Representation id="5" bandwidth="134272" codecs="mp4a.40.2" mimeType="audio/mp4" audioSamplingRate="44100"> <Representation id="5" bandwidth="134272" codecs="mp4a.40.2" mimeType="audio/mp4" audioSamplingRate="44100">
<AudioChannelConfiguration schemeIdUri="urn:mpeg:dash:23003:3:audio_channel_configuration:2011" value="2"/> <AudioChannelConfiguration schemeIdUri="urn:mpeg:dash:23003:3:audio_channel_configuration:2011" value="2"/>
<SegmentTemplate timescale="44100" initialization="bear-640x360-audio-init.mp4" media="bear-640x360-audio-$Number$.m4s" startNumber="1"> <SegmentTemplate timescale="44100" initialization="bear-640x360-audio-init.mp4" media="bear-640x360-audio-$Number$.m4s" startNumber="1">

View File

@ -221,8 +221,9 @@ Status WidevineKeySource::GetCryptoPeriodKey(uint32_t crypto_period_index,
first_crypto_period_index_ = first_crypto_period_index_ =
crypto_period_index ? crypto_period_index - 1 : 0; crypto_period_index ? crypto_period_index - 1 : 0;
DCHECK(!key_pool_); DCHECK(!key_pool_);
key_pool_.reset(new EncryptionKeyQueue(crypto_period_count_, const size_t queue_size = crypto_period_count_ * 10;
first_crypto_period_index_)); key_pool_.reset(
new EncryptionKeyQueue(queue_size, first_crypto_period_index_));
start_key_production_.Signal(); start_key_production_.Signal();
key_production_started_ = true; key_production_started_ = true;
} }

View File

@ -564,9 +564,9 @@ TEST_P(WidevineKeySourceParameterizedTest, KeyRotationTest) {
const uint32_t kCryptoPeriodCount = 10; const uint32_t kCryptoPeriodCount = 10;
// Array of indexes to be checked. // Array of indexes to be checked.
const uint32_t kCryptoPeriodIndexes[] = { const uint32_t kCryptoPeriodIndexes[] = {
kFirstCryptoPeriodIndex, 17, 37, 38, 36, 39}; kFirstCryptoPeriodIndex, 17, 37, 38, 36, 89};
// Derived from kCryptoPeriodIndexes: ceiling((39 - 8 ) / 10). // Derived from kCryptoPeriodIndexes: ceiling((89 - 8 ) / 10).
const uint32_t kCryptoIterations = 4; const uint32_t kCryptoIterations = 9;
// Generate expectations in sequence. // Generate expectations in sequence.
InSequence dummy; InSequence dummy;
@ -597,6 +597,9 @@ TEST_P(WidevineKeySourceParameterizedTest, KeyRotationTest) {
EXPECT_CALL(*mock_key_fetcher_, FetchKeys(_, _, _)) EXPECT_CALL(*mock_key_fetcher_, FetchKeys(_, _, _))
.WillOnce(DoAll(SetArgPointee<2>(mock_response), Return(Status::OK))); .WillOnce(DoAll(SetArgPointee<2>(mock_response), Return(Status::OK)));
} }
// Fail future requests.
EXPECT_CALL(*mock_request_signer_, GenerateSignature(_, _))
.WillRepeatedly(Return(false));
CreateWidevineKeySource(); CreateWidevineKeySource();
widevine_key_source_->set_signer(std::move(mock_request_signer_)); widevine_key_source_->set_signer(std::move(mock_request_signer_));

View File

@ -227,8 +227,10 @@ Status EncryptionHandler::ProcessMediaSample(
// need to be encrypted, so we can signal encryption metadata earlier to // need to be encrypted, so we can signal encryption metadata earlier to
// allows clients to prefetch the keys. // allows clients to prefetch the keys.
if (check_new_crypto_period_) { if (check_new_crypto_period_) {
const int64_t current_crypto_period_index = // |dts| can be negative, e.g. after EditList adjustments. Normalized to 0
clear_sample->dts() / crypto_period_duration_; // in that case.
const int64_t dts = std::max(clear_sample->dts(), static_cast<int64_t>(0));
const int64_t current_crypto_period_index = dts / crypto_period_duration_;
if (current_crypto_period_index != prev_crypto_period_index_) { if (current_crypto_period_index != prev_crypto_period_index_) {
EncryptionKey encryption_key; EncryptionKey encryption_key;
Status status = key_source_->GetCryptoPeriodKey( Status status = key_source_->GetCryptoPeriodKey(