From bd98436241f02376b617d56ad2eefb6ef3d78207 Mon Sep 17 00:00:00 2001 From: KongQun Yang Date: Fri, 27 Jul 2018 15:50:41 -0700 Subject: [PATCH] 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 --- .../output.mpd | 30 +++++++++--------- .../bear-640x360-audio-1.m4s | Bin 17156 -> 17156 bytes .../bear-640x360-video-1.m4s | Bin 99445 -> 99445 bytes .../bear-640x360-audio-1.m4s | Bin 17156 -> 17156 bytes .../bear-640x360-video-1.m4s | Bin 99445 -> 99445 bytes packager/media/base/widevine_key_source.cc | 5 +-- .../base/widevine_key_source_unittest.cc | 9 ++++-- packager/media/crypto/encryption_handler.cc | 6 ++-- 8 files changed, 28 insertions(+), 22 deletions(-) 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 5f6ea3d243..0feb548297 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 @@ -7,8 +7,8 @@ AAAANHBzc2gBAAAAEHfv7MCyTQKs4zweUuL7SwAAAAExMjM0NTY3ODkwMTIzNDU2AAAAAA== - - + + @@ -23,8 +23,8 @@ - - + + @@ -37,17 +37,7 @@ AAAANHBzc2gBAAAAEHfv7MCyTQKs4zweUuL7SwAAAAExMjM0NTY3ODkwMTIzNDU2AAAAAA== - - - - - - - - - - - + @@ -57,6 +47,16 @@ + + + + + + + + + + diff --git a/packager/app/test/testdata/live-profile-and-key-rotation-and-non-dash-if-iop/bear-640x360-audio-1.m4s b/packager/app/test/testdata/live-profile-and-key-rotation-and-non-dash-if-iop/bear-640x360-audio-1.m4s index 9996ce2afd15772cd8eb1cb715f449f101ea5732..f88b004a5e3b4e4219503d855cb433c745e1d97b 100644 GIT binary patch delta 31 icmZo^V{B<-+|a-%U}$7)Vrph?VQBziZJxkb;s^ka3<#3| delta 31 icmZo^V{B<-+|a-%U}0%sXk=_+Y6cHp^-6=1tgnYn6|qxF&Z`j0LEYmxc~qF diff --git a/packager/app/test/testdata/live-profile-and-key-rotation/bear-640x360-audio-1.m4s b/packager/app/test/testdata/live-profile-and-key-rotation/bear-640x360-audio-1.m4s index 9996ce2afd15772cd8eb1cb715f449f101ea5732..f88b004a5e3b4e4219503d855cb433c745e1d97b 100644 GIT binary patch delta 31 icmZo^V{B<-+|a-%U}$7)Vrph?VQBziZJxkb;s^ka3<#3| delta 31 icmZo^V{B<-+|a-%U}0%sXk=_+Y6cHp^-6=1tgnYn6|qxF&Z`j0LEYmxc~qF diff --git a/packager/media/base/widevine_key_source.cc b/packager/media/base/widevine_key_source.cc index 2df58243b7..c914d1926d 100644 --- a/packager/media/base/widevine_key_source.cc +++ b/packager/media/base/widevine_key_source.cc @@ -221,8 +221,9 @@ Status WidevineKeySource::GetCryptoPeriodKey(uint32_t crypto_period_index, first_crypto_period_index_ = crypto_period_index ? crypto_period_index - 1 : 0; DCHECK(!key_pool_); - key_pool_.reset(new EncryptionKeyQueue(crypto_period_count_, - first_crypto_period_index_)); + const size_t queue_size = crypto_period_count_ * 10; + key_pool_.reset( + new EncryptionKeyQueue(queue_size, first_crypto_period_index_)); start_key_production_.Signal(); key_production_started_ = true; } diff --git a/packager/media/base/widevine_key_source_unittest.cc b/packager/media/base/widevine_key_source_unittest.cc index 5a3a4f4eec..a0f11f7639 100644 --- a/packager/media/base/widevine_key_source_unittest.cc +++ b/packager/media/base/widevine_key_source_unittest.cc @@ -564,9 +564,9 @@ TEST_P(WidevineKeySourceParameterizedTest, KeyRotationTest) { const uint32_t kCryptoPeriodCount = 10; // Array of indexes to be checked. const uint32_t kCryptoPeriodIndexes[] = { - kFirstCryptoPeriodIndex, 17, 37, 38, 36, 39}; - // Derived from kCryptoPeriodIndexes: ceiling((39 - 8 ) / 10). - const uint32_t kCryptoIterations = 4; + kFirstCryptoPeriodIndex, 17, 37, 38, 36, 89}; + // Derived from kCryptoPeriodIndexes: ceiling((89 - 8 ) / 10). + const uint32_t kCryptoIterations = 9; // Generate expectations in sequence. InSequence dummy; @@ -597,6 +597,9 @@ TEST_P(WidevineKeySourceParameterizedTest, KeyRotationTest) { EXPECT_CALL(*mock_key_fetcher_, FetchKeys(_, _, _)) .WillOnce(DoAll(SetArgPointee<2>(mock_response), Return(Status::OK))); } + // Fail future requests. + EXPECT_CALL(*mock_request_signer_, GenerateSignature(_, _)) + .WillRepeatedly(Return(false)); CreateWidevineKeySource(); widevine_key_source_->set_signer(std::move(mock_request_signer_)); diff --git a/packager/media/crypto/encryption_handler.cc b/packager/media/crypto/encryption_handler.cc index 86f67ec22d..3d23acf952 100644 --- a/packager/media/crypto/encryption_handler.cc +++ b/packager/media/crypto/encryption_handler.cc @@ -227,8 +227,10 @@ Status EncryptionHandler::ProcessMediaSample( // need to be encrypted, so we can signal encryption metadata earlier to // allows clients to prefetch the keys. if (check_new_crypto_period_) { - const int64_t current_crypto_period_index = - clear_sample->dts() / crypto_period_duration_; + // |dts| can be negative, e.g. after EditList adjustments. Normalized to 0 + // in that case. + const int64_t dts = std::max(clear_sample->dts(), static_cast(0)); + const int64_t current_crypto_period_index = dts / crypto_period_duration_; if (current_crypto_period_index != prev_crypto_period_index_) { EncryptionKey encryption_key; Status status = key_source_->GetCryptoPeriodKey(