Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(569)

Side by Side Diff: media/filters/pipeline_integration_test.cc

Issue 263003003: Add mp4 key rotation tests in pipeline integration test (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "media/filters/pipeline_integration_test_base.h" 5 #include "media/filters/pipeline_integration_test_base.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 std::string jwk = GenerateJWKSet( 241 std::string jwk = GenerateJWKSet(
242 kSecretKey, arraysize(kSecretKey), key_id, key_id_length); 242 kSecretKey, arraysize(kSecretKey), key_id, key_id_length);
243 decryptor->UpdateSession(current_session_id_, 243 decryptor->UpdateSession(current_session_id_,
244 reinterpret_cast<const uint8*>(jwk.data()), 244 reinterpret_cast<const uint8*>(jwk.data()),
245 jwk.size()); 245 jwk.size());
246 } 246 }
247 247
248 uint32 current_session_id_; 248 uint32 current_session_id_;
249 }; 249 };
250 250
251 class RotatingKeyProvidingApp : public KeyProvidingApp {
252 public:
253 RotatingKeyProvidingApp() : num_distint_need_key_calls_(0) {}
254 virtual ~RotatingKeyProvidingApp() {
255 // Expect that NeedKey is fired multiple times with different |init_data|.
256 EXPECT_GT(num_distint_need_key_calls_, 1u);
257 }
258
259 virtual void NeedKey(const std::string& type,
260 const std::vector<uint8>& init_data,
261 AesDecryptor* decryptor) OVERRIDE {
262 // Skip the request if the |init_data| has been seen.
263 if (init_data == prev_init_data_)
264 return;
265 prev_init_data_ = init_data;
266 ++num_distint_need_key_calls_;
267
268 EXPECT_TRUE(decryptor->CreateSession(current_session_id_ + 1,
269 type,
270 vector_as_array(&init_data),
271 init_data.size()));
272
273 std::vector<uint8> key_id;
274 std::vector<uint8> key;
275 EXPECT_TRUE(GetKeyAndKeyId(init_data, &key, &key_id));
276
277 // Convert key into a JSON structure and then add it.
278 std::string jwk = GenerateJWKSet(vector_as_array(&key),
279 key.size(),
280 vector_as_array(&key_id),
281 key_id.size());
282 decryptor->UpdateSession(current_session_id_,
283 reinterpret_cast<const uint8*>(jwk.data()),
284 jwk.size());
285 }
286
287 private:
288 bool GetKeyAndKeyId(std::vector<uint8> init_data,
289 std::vector<uint8>* key,
290 std::vector<uint8>* key_id) {
291 // For WebM, init_data is key_id; for ISO CENC, init_data should contain
292 // the key_id. We assume key_id is in the end of init_data here (that is
293 // only a reasonable assumption for WebM and clear key ISO CENC).
294 DCHECK_GE(init_data.size(), arraysize(kKeyId));
295 std::vector<uint8> key_id_from_init_data(
296 init_data.end() - arraysize(kKeyId), init_data.end());
297
298 key->assign(kSecretKey, kSecretKey + arraysize(kSecretKey));
299 key_id->assign(kKeyId, kKeyId + arraysize(kKeyId));
300
301 // The Key and KeyId for this testing key provider are created by left
302 // rotating kSecretKey and kKeyId. Note that this implementation is only
303 // intended for testing purpose. The actual key rotation algorithm can be
304 // much more complicated.
305 // Find out the rotating position from |key_id_from_init_data| and apply on
306 // |key|.
307 for (size_t pos = 0; pos < arraysize(kKeyId); ++pos) {
308 std::rotate(key_id->begin(), key_id->begin() + pos, key_id->end());
309 if (*key_id == key_id_from_init_data) {
310 std::rotate(key->begin(), key->begin() + pos, key->end());
311 return true;
312 }
313 }
314 return false;
315 }
316
317 std::vector<uint8> prev_init_data_;
318 uint32 num_distint_need_key_calls_;
319 };
320
251 // Ignores needkey and does not perform a license request 321 // Ignores needkey and does not perform a license request
252 class NoResponseApp : public FakeEncryptedMedia::AppBase { 322 class NoResponseApp : public FakeEncryptedMedia::AppBase {
253 public: 323 public:
254 virtual void OnSessionCreated(uint32 session_id, 324 virtual void OnSessionCreated(uint32 session_id,
255 const std::string& web_session_id) OVERRIDE { 325 const std::string& web_session_id) OVERRIDE {
256 EXPECT_GT(session_id, 0u); 326 EXPECT_GT(session_id, 0u);
257 EXPECT_FALSE(web_session_id.empty()); 327 EXPECT_FALSE(web_session_id.empty());
258 } 328 }
259 329
260 virtual void OnSessionMessage(uint32 session_id, 330 virtual void OnSessionMessage(uint32 session_id,
(...skipping 725 matching lines...) Expand 10 before | Expand all | Expand 10 after
986 EXPECT_EQ(kAppendTimeMs + k1280IsoFileDurationMs, 1056 EXPECT_EQ(kAppendTimeMs + k1280IsoFileDurationMs,
987 pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds()); 1057 pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds());
988 1058
989 Play(); 1059 Play();
990 1060
991 EXPECT_TRUE(WaitUntilOnEnded()); 1061 EXPECT_TRUE(WaitUntilOnEnded());
992 source.Abort(); 1062 source.Abort();
993 Stop(); 1063 Stop();
994 } 1064 }
995 1065
1066 TEST_P(PipelineIntegrationTest,
1067 MediaSource_ConfigChange_Encrypted_MP4_CENC_KeyRotation_VideoOnly) {
1068 MockMediaSource source("bear-640x360-v_frag-cenc-key_rotation.mp4",
1069 kMP4Video, kAppendWholeFile, GetParam());
1070 FakeEncryptedMedia encrypted_media(new RotatingKeyProvidingApp());
1071 StartPipelineWithEncryptedMedia(&source, &encrypted_media);
1072
1073 scoped_refptr<DecoderBuffer> second_file =
1074 ReadTestDataFile("bear-1280x720-v_frag-cenc-key_rotation.mp4");
1075
1076 source.AppendAtTime(base::TimeDelta::FromSeconds(kAppendTimeSec),
1077 second_file->data(), second_file->data_size());
1078
1079 source.EndOfStream();
1080
1081 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size());
1082 EXPECT_EQ(0, pipeline_->GetBufferedTimeRanges().start(0).InMilliseconds());
1083 EXPECT_EQ(kAppendTimeMs + k1280IsoFileDurationMs,
1084 pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds());
1085
1086 Play();
1087
1088 EXPECT_TRUE(WaitUntilOnEnded());
1089 source.Abort();
1090 Stop();
1091 }
1092
996 // Config changes from clear to encrypted are not currently supported. 1093 // Config changes from clear to encrypted are not currently supported.
997 // TODO(ddorwin): Figure out why this CHECKs in AppendAtTime(). 1094 // TODO(ddorwin): Figure out why this CHECKs in AppendAtTime().
998 TEST_P(PipelineIntegrationTest, 1095 TEST_P(PipelineIntegrationTest,
999 DISABLED_MediaSource_ConfigChange_ClearThenEncrypted_MP4_CENC) { 1096 DISABLED_MediaSource_ConfigChange_ClearThenEncrypted_MP4_CENC) {
1000 MockMediaSource source("bear-640x360-av_frag.mp4", kMP4Video, 1097 MockMediaSource source("bear-640x360-av_frag.mp4", kMP4Video,
1001 kAppendWholeFile, GetParam()); 1098 kAppendWholeFile, GetParam());
1002 FakeEncryptedMedia encrypted_media(new KeyProvidingApp()); 1099 FakeEncryptedMedia encrypted_media(new KeyProvidingApp());
1003 StartPipelineWithEncryptedMedia(&source, &encrypted_media); 1100 StartPipelineWithEncryptedMedia(&source, &encrypted_media);
1004 1101
1005 scoped_refptr<DecoderBuffer> second_file = 1102 scoped_refptr<DecoderBuffer> second_file =
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
1196 EXPECT_EQ(k1280IsoAVC3FileDurationMs, 1293 EXPECT_EQ(k1280IsoAVC3FileDurationMs,
1197 pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds()); 1294 pipeline_->GetBufferedTimeRanges().end(0).InMilliseconds());
1198 1295
1199 Play(); 1296 Play();
1200 1297
1201 ASSERT_TRUE(WaitUntilOnEnded()); 1298 ASSERT_TRUE(WaitUntilOnEnded());
1202 source.Abort(); 1299 source.Abort();
1203 Stop(); 1300 Stop();
1204 } 1301 }
1205 1302
1303 TEST_P(PipelineIntegrationTest, EncryptedPlayback_MP4_CENC_KeyRotation_Video) {
1304 MockMediaSource source("bear-1280x720-v_frag-cenc-key_rotation.mp4",
1305 kMP4Video, kAppendWholeFile, GetParam());
1306 FakeEncryptedMedia encrypted_media(new RotatingKeyProvidingApp());
1307 StartPipelineWithEncryptedMedia(&source, &encrypted_media);
1308
1309 source.EndOfStream();
1310 ASSERT_EQ(PIPELINE_OK, pipeline_status_);
1311
1312 Play();
1313
1314 ASSERT_TRUE(WaitUntilOnEnded());
1315 source.Abort();
1316 Stop();
1317 }
1318
1319 TEST_P(PipelineIntegrationTest, EncryptedPlayback_MP4_CENC_KeyRotation_Audio) {
1320 MockMediaSource source("bear-1280x720-a_frag-cenc-key_rotation.mp4",
1321 kMP4Audio, kAppendWholeFile, GetParam());
1322 FakeEncryptedMedia encrypted_media(new RotatingKeyProvidingApp());
1323 StartPipelineWithEncryptedMedia(&source, &encrypted_media);
1324
1325 source.EndOfStream();
1326 ASSERT_EQ(PIPELINE_OK, pipeline_status_);
1327
1328 Play();
1329
1330 ASSERT_TRUE(WaitUntilOnEnded());
1331 source.Abort();
1332 Stop();
1333 }
1206 #endif 1334 #endif
1207 1335
1208 // TODO(acolwell): Fix flakiness http://crbug.com/117921 1336 // TODO(acolwell): Fix flakiness http://crbug.com/117921
1209 TEST_F(PipelineIntegrationTest, DISABLED_SeekWhilePaused) { 1337 TEST_F(PipelineIntegrationTest, DISABLED_SeekWhilePaused) {
1210 ASSERT_TRUE(Start(GetTestDataFilePath("bear-320x240.webm"), PIPELINE_OK)); 1338 ASSERT_TRUE(Start(GetTestDataFilePath("bear-320x240.webm"), PIPELINE_OK));
1211 1339
1212 base::TimeDelta duration(pipeline_->GetMediaDuration()); 1340 base::TimeDelta duration(pipeline_->GetMediaDuration());
1213 base::TimeDelta start_seek_time(duration / 4); 1341 base::TimeDelta start_seek_time(duration / 4);
1214 base::TimeDelta seek_time(duration * 3 / 4); 1342 base::TimeDelta seek_time(duration * 3 / 4);
1215 1343
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
1318 Play(); 1446 Play();
1319 ASSERT_TRUE(WaitUntilOnEnded()); 1447 ASSERT_TRUE(WaitUntilOnEnded());
1320 } 1448 }
1321 1449
1322 // TODO(wolenetz): Enable MSE testing of new frame processor based on this flag, 1450 // TODO(wolenetz): Enable MSE testing of new frame processor based on this flag,
1323 // once the new processor has landed. See http://crbug.com/249422. 1451 // once the new processor has landed. See http://crbug.com/249422.
1324 INSTANTIATE_TEST_CASE_P(LegacyFrameProcessor, PipelineIntegrationTest, 1452 INSTANTIATE_TEST_CASE_P(LegacyFrameProcessor, PipelineIntegrationTest,
1325 Values(true)); 1453 Values(true));
1326 1454
1327 } // namespace media 1455 } // namespace media
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698