OLD | NEW |
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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/stl_util.h" |
8 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
9 #include "build/build_config.h" | 10 #include "build/build_config.h" |
10 #include "media/base/cdm_callback_promise.h" | 11 #include "media/base/cdm_callback_promise.h" |
11 #include "media/base/cdm_context.h" | 12 #include "media/base/cdm_context.h" |
12 #include "media/base/cdm_key_information.h" | 13 #include "media/base/cdm_key_information.h" |
13 #include "media/base/decoder_buffer.h" | 14 #include "media/base/decoder_buffer.h" |
14 #include "media/base/media.h" | 15 #include "media/base/media.h" |
15 #include "media/base/media_keys.h" | 16 #include "media/base/media_keys.h" |
16 #include "media/base/media_switches.h" | 17 #include "media/base/media_switches.h" |
17 #include "media/base/test_data_util.h" | 18 #include "media/base/test_data_util.h" |
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 return; | 311 return; |
311 prev_init_data_ = init_data; | 312 prev_init_data_ = init_data; |
312 | 313 |
313 if (current_session_id_.empty()) { | 314 if (current_session_id_.empty()) { |
314 if (init_data_type == EmeInitDataType::CENC) { | 315 if (init_data_type == EmeInitDataType::CENC) { |
315 // Since the 'cenc' files are not created with proper 'pssh' boxes, | 316 // Since the 'cenc' files are not created with proper 'pssh' boxes, |
316 // simply pretend that this is a webm file and pass the expected | 317 // simply pretend that this is a webm file and pass the expected |
317 // key ID as the init_data. | 318 // key ID as the init_data. |
318 // http://crbug.com/460308 | 319 // http://crbug.com/460308 |
319 decryptor->CreateSessionAndGenerateRequest( | 320 decryptor->CreateSessionAndGenerateRequest( |
320 MediaKeys::TEMPORARY_SESSION, EmeInitDataType::WEBM, kKeyId, | 321 MediaKeys::TEMPORARY_SESSION, EmeInitDataType::WEBM, |
321 arraysize(kKeyId), CreateSessionPromise(RESOLVED)); | 322 std::vector<uint8>(kKeyId, kKeyId + arraysize(kKeyId)), |
| 323 CreateSessionPromise(RESOLVED)); |
322 } else { | 324 } else { |
323 decryptor->CreateSessionAndGenerateRequest( | 325 decryptor->CreateSessionAndGenerateRequest( |
324 MediaKeys::TEMPORARY_SESSION, init_data_type, | 326 MediaKeys::TEMPORARY_SESSION, init_data_type, init_data, |
325 vector_as_array(&init_data), init_data.size(), | |
326 CreateSessionPromise(RESOLVED)); | 327 CreateSessionPromise(RESOLVED)); |
327 } | 328 } |
328 EXPECT_FALSE(current_session_id_.empty()); | 329 EXPECT_FALSE(current_session_id_.empty()); |
329 } | 330 } |
330 | 331 |
331 // Clear Key really needs the key ID from |init_data|. For WebM, they are | 332 // Clear Key really needs the key ID from |init_data|. For WebM, they are |
332 // the same, but this is not the case for ISO CENC (key ID embedded in a | 333 // the same, but this is not the case for ISO CENC (key ID embedded in a |
333 // 'pssh' box). Therefore, provide the correct key ID. | 334 // 'pssh' box). Therefore, provide the correct key ID. |
334 const uint8* key_id = vector_as_array(&init_data); | 335 const uint8* key_id = vector_as_array(&init_data); |
335 size_t key_id_length = init_data.size(); | 336 size_t key_id_length = init_data.size(); |
336 if (init_data_type == EmeInitDataType::CENC) { | 337 if (init_data_type == EmeInitDataType::CENC) { |
337 key_id = kKeyId; | 338 key_id = kKeyId; |
338 key_id_length = arraysize(kKeyId); | 339 key_id_length = arraysize(kKeyId); |
339 } | 340 } |
340 | 341 |
341 // Convert key into a JSON structure and then add it. | 342 // Convert key into a JSON structure and then add it. |
342 std::string jwk = GenerateJWKSet( | 343 std::string jwk = GenerateJWKSet( |
343 kSecretKey, arraysize(kSecretKey), key_id, key_id_length); | 344 kSecretKey, arraysize(kSecretKey), key_id, key_id_length); |
344 decryptor->UpdateSession(current_session_id_, | 345 decryptor->UpdateSession(current_session_id_, |
345 reinterpret_cast<const uint8*>(jwk.data()), | 346 std::vector<uint8>(jwk.begin(), jwk.end()), |
346 jwk.size(), | |
347 CreatePromise(RESOLVED)); | 347 CreatePromise(RESOLVED)); |
348 } | 348 } |
349 | 349 |
350 std::string current_session_id_; | 350 std::string current_session_id_; |
351 std::vector<uint8> prev_init_data_; | 351 std::vector<uint8> prev_init_data_; |
352 }; | 352 }; |
353 | 353 |
354 class RotatingKeyProvidingApp : public KeyProvidingApp { | 354 class RotatingKeyProvidingApp : public KeyProvidingApp { |
355 public: | 355 public: |
356 RotatingKeyProvidingApp() : num_distint_need_key_calls_(0) {} | 356 RotatingKeyProvidingApp() : num_distint_need_key_calls_(0) {} |
(...skipping 15 matching lines...) Expand all Loading... |
372 std::vector<uint8> key_id; | 372 std::vector<uint8> key_id; |
373 std::vector<uint8> key; | 373 std::vector<uint8> key; |
374 EXPECT_TRUE(GetKeyAndKeyId(init_data, &key, &key_id)); | 374 EXPECT_TRUE(GetKeyAndKeyId(init_data, &key, &key_id)); |
375 | 375 |
376 if (init_data_type == EmeInitDataType::CENC) { | 376 if (init_data_type == EmeInitDataType::CENC) { |
377 // Since the 'cenc' files are not created with proper 'pssh' boxes, | 377 // Since the 'cenc' files are not created with proper 'pssh' boxes, |
378 // simply pretend that this is a webm file and pass the expected | 378 // simply pretend that this is a webm file and pass the expected |
379 // key ID as the init_data. | 379 // key ID as the init_data. |
380 // http://crbug.com/460308 | 380 // http://crbug.com/460308 |
381 decryptor->CreateSessionAndGenerateRequest( | 381 decryptor->CreateSessionAndGenerateRequest( |
382 MediaKeys::TEMPORARY_SESSION, EmeInitDataType::WEBM, | 382 MediaKeys::TEMPORARY_SESSION, EmeInitDataType::WEBM, key_id, |
383 vector_as_array(&key_id), key_id.size(), | |
384 CreateSessionPromise(RESOLVED)); | 383 CreateSessionPromise(RESOLVED)); |
385 } else { | 384 } else { |
386 decryptor->CreateSessionAndGenerateRequest( | 385 decryptor->CreateSessionAndGenerateRequest( |
387 MediaKeys::TEMPORARY_SESSION, init_data_type, | 386 MediaKeys::TEMPORARY_SESSION, init_data_type, init_data, |
388 vector_as_array(&init_data), init_data.size(), | |
389 CreateSessionPromise(RESOLVED)); | 387 CreateSessionPromise(RESOLVED)); |
390 } | 388 } |
391 | 389 |
392 // Convert key into a JSON structure and then add it. | 390 // Convert key into a JSON structure and then add it. |
393 std::string jwk = GenerateJWKSet(vector_as_array(&key), | 391 std::string jwk = GenerateJWKSet(vector_as_array(&key), |
394 key.size(), | 392 key.size(), |
395 vector_as_array(&key_id), | 393 vector_as_array(&key_id), |
396 key_id.size()); | 394 key_id.size()); |
397 decryptor->UpdateSession(current_session_id_, | 395 decryptor->UpdateSession(current_session_id_, |
398 reinterpret_cast<const uint8*>(jwk.data()), | 396 std::vector<uint8>(jwk.begin(), jwk.end()), |
399 jwk.size(), | |
400 CreatePromise(RESOLVED)); | 397 CreatePromise(RESOLVED)); |
401 } | 398 } |
402 | 399 |
403 private: | 400 private: |
404 bool GetKeyAndKeyId(std::vector<uint8> init_data, | 401 bool GetKeyAndKeyId(std::vector<uint8> init_data, |
405 std::vector<uint8>* key, | 402 std::vector<uint8>* key, |
406 std::vector<uint8>* key_id) { | 403 std::vector<uint8>* key_id) { |
407 // For WebM, init_data is key_id; for ISO CENC, init_data should contain | 404 // For WebM, init_data is key_id; for ISO CENC, init_data should contain |
408 // the key_id. We assume key_id is in the end of init_data here (that is | 405 // the key_id. We assume key_id is in the end of init_data here (that is |
409 // only a reasonable assumption for WebM and clear key ISO CENC). | 406 // only a reasonable assumption for WebM and clear key ISO CENC). |
(...skipping 1327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1737 | 1734 |
1738 TEST_F(PipelineIntegrationTest, BasicPlaybackPositiveStartTime) { | 1735 TEST_F(PipelineIntegrationTest, BasicPlaybackPositiveStartTime) { |
1739 ASSERT_EQ(PIPELINE_OK, Start("nonzero-start-time.webm")); | 1736 ASSERT_EQ(PIPELINE_OK, Start("nonzero-start-time.webm")); |
1740 Play(); | 1737 Play(); |
1741 ASSERT_TRUE(WaitUntilOnEnded()); | 1738 ASSERT_TRUE(WaitUntilOnEnded()); |
1742 ASSERT_EQ(base::TimeDelta::FromMicroseconds(396000), | 1739 ASSERT_EQ(base::TimeDelta::FromMicroseconds(396000), |
1743 demuxer_->GetStartTime()); | 1740 demuxer_->GetStartTime()); |
1744 } | 1741 } |
1745 | 1742 |
1746 } // namespace media | 1743 } // namespace media |
OLD | NEW |