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

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

Issue 2568463003: media: Rename MediaKeys to ContentDecryptionModule (Closed)
Patch Set: comments addressed Created 4 years 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 | « media/remoting/rpc/proto_utils_unittest.cc ('k') | media/test/pipeline_integration_test_base.h » ('j') | 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 <stddef.h> 5 #include <stddef.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 7
8 #include <memory> 8 #include <memory>
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/memory/ptr_util.h" 14 #include "base/memory/ptr_util.h"
15 #include "base/memory/ref_counted.h" 15 #include "base/memory/ref_counted.h"
16 #include "base/run_loop.h" 16 #include "base/run_loop.h"
17 #include "base/strings/string_split.h" 17 #include "base/strings/string_split.h"
18 #include "base/strings/string_util.h" 18 #include "base/strings/string_util.h"
19 #include "base/threading/thread_task_runner_handle.h" 19 #include "base/threading/thread_task_runner_handle.h"
20 #include "build/build_config.h" 20 #include "build/build_config.h"
21 #include "media/base/cdm_callback_promise.h" 21 #include "media/base/cdm_callback_promise.h"
22 #include "media/base/cdm_context.h" 22 #include "media/base/cdm_context.h"
23 #include "media/base/cdm_key_information.h" 23 #include "media/base/cdm_key_information.h"
24 #include "media/base/content_decryption_module.h"
24 #include "media/base/decoder_buffer.h" 25 #include "media/base/decoder_buffer.h"
25 #include "media/base/media.h" 26 #include "media/base/media.h"
26 #include "media/base/media_keys.h"
27 #include "media/base/media_switches.h" 27 #include "media/base/media_switches.h"
28 #include "media/base/media_tracks.h" 28 #include "media/base/media_tracks.h"
29 #include "media/base/test_data_util.h" 29 #include "media/base/test_data_util.h"
30 #include "media/base/timestamp_constants.h" 30 #include "media/base/timestamp_constants.h"
31 #include "media/cdm/aes_decryptor.h" 31 #include "media/cdm/aes_decryptor.h"
32 #include "media/cdm/json_web_key.h" 32 #include "media/cdm/json_web_key.h"
33 #include "media/filters/chunk_demuxer.h" 33 #include "media/filters/chunk_demuxer.h"
34 #include "media/renderers/renderer_impl.h" 34 #include "media/renderers/renderer_impl.h"
35 #include "media/test/pipeline_integration_test_base.h" 35 #include "media/test/pipeline_integration_test_base.h"
36 #include "testing/gmock/include/gmock/gmock.h" 36 #include "testing/gmock/include/gmock/gmock.h"
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 188
189 // Note: Tests using this class only exercise the DecryptingDemuxerStream path. 189 // Note: Tests using this class only exercise the DecryptingDemuxerStream path.
190 // They do not exercise the Decrypting{Audio|Video}Decoder path. 190 // They do not exercise the Decrypting{Audio|Video}Decoder path.
191 class FakeEncryptedMedia { 191 class FakeEncryptedMedia {
192 public: 192 public:
193 // Defines the behavior of the "app" that responds to EME events. 193 // Defines the behavior of the "app" that responds to EME events.
194 class AppBase { 194 class AppBase {
195 public: 195 public:
196 virtual ~AppBase() {} 196 virtual ~AppBase() {}
197 197
198 virtual void OnSessionMessage(const std::string& session_id, 198 virtual void OnSessionMessage(
199 MediaKeys::MessageType message_type, 199 const std::string& session_id,
200 const std::vector<uint8_t>& message, 200 ContentDecryptionModule::MessageType message_type,
201 AesDecryptor* decryptor) = 0; 201 const std::vector<uint8_t>& message,
202 AesDecryptor* decryptor) = 0;
202 203
203 virtual void OnSessionClosed(const std::string& session_id) = 0; 204 virtual void OnSessionClosed(const std::string& session_id) = 0;
204 205
205 virtual void OnSessionKeysChange(const std::string& session_id, 206 virtual void OnSessionKeysChange(const std::string& session_id,
206 bool has_additional_usable_key, 207 bool has_additional_usable_key,
207 CdmKeysInfo keys_info) = 0; 208 CdmKeysInfo keys_info) = 0;
208 209
209 virtual void OnEncryptedMediaInitData(EmeInitDataType init_data_type, 210 virtual void OnEncryptedMediaInitData(EmeInitDataType init_data_type,
210 const std::vector<uint8_t>& init_data, 211 const std::vector<uint8_t>& init_data,
211 AesDecryptor* decryptor) = 0; 212 AesDecryptor* decryptor) = 0;
212 }; 213 };
213 214
214 FakeEncryptedMedia(AppBase* app) 215 FakeEncryptedMedia(AppBase* app)
215 : decryptor_(new AesDecryptor( 216 : decryptor_(new AesDecryptor(
216 GURL::EmptyGURL(), 217 GURL::EmptyGURL(),
217 base::Bind(&FakeEncryptedMedia::OnSessionMessage, 218 base::Bind(&FakeEncryptedMedia::OnSessionMessage,
218 base::Unretained(this)), 219 base::Unretained(this)),
219 base::Bind(&FakeEncryptedMedia::OnSessionClosed, 220 base::Bind(&FakeEncryptedMedia::OnSessionClosed,
220 base::Unretained(this)), 221 base::Unretained(this)),
221 base::Bind(&FakeEncryptedMedia::OnSessionKeysChange, 222 base::Bind(&FakeEncryptedMedia::OnSessionKeysChange,
222 base::Unretained(this)))), 223 base::Unretained(this)))),
223 cdm_context_(decryptor_.get()), 224 cdm_context_(decryptor_.get()),
224 app_(app) {} 225 app_(app) {}
225 226
226 CdmContext* GetCdmContext() { return &cdm_context_; } 227 CdmContext* GetCdmContext() { return &cdm_context_; }
227 228
228 // Callbacks for firing session events. Delegate to |app_|. 229 // Callbacks for firing session events. Delegate to |app_|.
229 void OnSessionMessage(const std::string& session_id, 230 void OnSessionMessage(const std::string& session_id,
230 MediaKeys::MessageType message_type, 231 ContentDecryptionModule::MessageType message_type,
231 const std::vector<uint8_t>& message) { 232 const std::vector<uint8_t>& message) {
232 app_->OnSessionMessage(session_id, message_type, message, decryptor_.get()); 233 app_->OnSessionMessage(session_id, message_type, message, decryptor_.get());
233 } 234 }
234 235
235 void OnSessionClosed(const std::string& session_id) { 236 void OnSessionClosed(const std::string& session_id) {
236 app_->OnSessionClosed(session_id); 237 app_->OnSessionClosed(session_id);
237 } 238 }
238 239
239 void OnSessionKeysChange(const std::string& session_id, 240 void OnSessionKeysChange(const std::string& session_id,
240 bool has_additional_usable_key, 241 bool has_additional_usable_key,
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 std::unique_ptr<media::NewSessionCdmPromise> promise( 304 std::unique_ptr<media::NewSessionCdmPromise> promise(
304 new media::CdmCallbackPromise<std::string>( 305 new media::CdmCallbackPromise<std::string>(
305 base::Bind(&KeyProvidingApp::OnResolveWithSession, 306 base::Bind(&KeyProvidingApp::OnResolveWithSession,
306 base::Unretained(this), expected), 307 base::Unretained(this), expected),
307 base::Bind(&KeyProvidingApp::OnReject, base::Unretained(this), 308 base::Bind(&KeyProvidingApp::OnReject, base::Unretained(this),
308 expected))); 309 expected)));
309 return promise; 310 return promise;
310 } 311 }
311 312
312 void OnSessionMessage(const std::string& session_id, 313 void OnSessionMessage(const std::string& session_id,
313 MediaKeys::MessageType message_type, 314 ContentDecryptionModule::MessageType message_type,
314 const std::vector<uint8_t>& message, 315 const std::vector<uint8_t>& message,
315 AesDecryptor* decryptor) override { 316 AesDecryptor* decryptor) override {
316 EXPECT_FALSE(session_id.empty()); 317 EXPECT_FALSE(session_id.empty());
317 EXPECT_FALSE(message.empty()); 318 EXPECT_FALSE(message.empty());
318 EXPECT_EQ(current_session_id_, session_id); 319 EXPECT_EQ(current_session_id_, session_id);
319 EXPECT_EQ(MediaKeys::MessageType::LICENSE_REQUEST, message_type); 320 EXPECT_EQ(ContentDecryptionModule::MessageType::LICENSE_REQUEST,
321 message_type);
320 322
321 // Extract the key ID from |message|. For Clear Key this is a JSON object 323 // Extract the key ID from |message|. For Clear Key this is a JSON object
322 // containing a set of "kids". There should only be 1 key ID in |message|. 324 // containing a set of "kids". There should only be 1 key ID in |message|.
323 std::string message_string(message.begin(), message.end()); 325 std::string message_string(message.begin(), message.end());
324 KeyIdList key_ids; 326 KeyIdList key_ids;
325 std::string error_message; 327 std::string error_message;
326 EXPECT_TRUE(ExtractKeyIdsFromKeyIdsInitData(message_string, &key_ids, 328 EXPECT_TRUE(ExtractKeyIdsFromKeyIdsInitData(message_string, &key_ids,
327 &error_message)) 329 &error_message))
328 << error_message; 330 << error_message;
329 EXPECT_EQ(1u, key_ids.size()); 331 EXPECT_EQ(1u, key_ids.size());
(...skipping 25 matching lines...) Expand all
355 const std::vector<uint8_t>& init_data, 357 const std::vector<uint8_t>& init_data,
356 AesDecryptor* decryptor) override { 358 AesDecryptor* decryptor) override {
357 // Since only 1 session is created, skip the request if the |init_data| 359 // Since only 1 session is created, skip the request if the |init_data|
358 // has been seen before (no need to add the same key again). 360 // has been seen before (no need to add the same key again).
359 if (init_data == prev_init_data_) 361 if (init_data == prev_init_data_)
360 return; 362 return;
361 prev_init_data_ = init_data; 363 prev_init_data_ = init_data;
362 364
363 if (current_session_id_.empty()) { 365 if (current_session_id_.empty()) {
364 decryptor->CreateSessionAndGenerateRequest( 366 decryptor->CreateSessionAndGenerateRequest(
365 MediaKeys::TEMPORARY_SESSION, init_data_type, init_data, 367 ContentDecryptionModule::TEMPORARY_SESSION, init_data_type, init_data,
366 CreateSessionPromise(RESOLVED)); 368 CreateSessionPromise(RESOLVED));
367 EXPECT_FALSE(current_session_id_.empty()); 369 EXPECT_FALSE(current_session_id_.empty());
368 } 370 }
369 } 371 }
370 372
371 virtual bool LookupKey(const std::vector<uint8_t>& key_id, 373 virtual bool LookupKey(const std::vector<uint8_t>& key_id,
372 std::vector<uint8_t>* key) { 374 std::vector<uint8_t>* key) {
373 // No key rotation. 375 // No key rotation.
374 return LookupTestKeyVector(key_id, false, key); 376 return LookupTestKeyVector(key_id, false, key);
375 } 377 }
(...skipping 13 matching lines...) Expand all
389 391
390 void OnEncryptedMediaInitData(EmeInitDataType init_data_type, 392 void OnEncryptedMediaInitData(EmeInitDataType init_data_type,
391 const std::vector<uint8_t>& init_data, 393 const std::vector<uint8_t>& init_data,
392 AesDecryptor* decryptor) override { 394 AesDecryptor* decryptor) override {
393 // Skip the request if the |init_data| has been seen. 395 // Skip the request if the |init_data| has been seen.
394 if (init_data == prev_init_data_) 396 if (init_data == prev_init_data_)
395 return; 397 return;
396 prev_init_data_ = init_data; 398 prev_init_data_ = init_data;
397 ++num_distinct_need_key_calls_; 399 ++num_distinct_need_key_calls_;
398 400
399 decryptor->CreateSessionAndGenerateRequest(MediaKeys::TEMPORARY_SESSION, 401 decryptor->CreateSessionAndGenerateRequest(
400 init_data_type, init_data, 402 ContentDecryptionModule::TEMPORARY_SESSION, init_data_type, init_data,
401 CreateSessionPromise(RESOLVED)); 403 CreateSessionPromise(RESOLVED));
402 } 404 }
403 405
404 bool LookupKey(const std::vector<uint8_t>& key_id, 406 bool LookupKey(const std::vector<uint8_t>& key_id,
405 std::vector<uint8_t>* key) override { 407 std::vector<uint8_t>* key) override {
406 // With key rotation. 408 // With key rotation.
407 return LookupTestKeyVector(key_id, true, key); 409 return LookupTestKeyVector(key_id, true, key);
408 } 410 }
409 411
410 uint32_t num_distinct_need_key_calls_; 412 uint32_t num_distinct_need_key_calls_;
411 }; 413 };
412 414
413 // Ignores the encrypted event and does not perform a license request. 415 // Ignores the encrypted event and does not perform a license request.
414 class NoResponseApp : public FakeEncryptedMedia::AppBase { 416 class NoResponseApp : public FakeEncryptedMedia::AppBase {
415 public: 417 public:
416 void OnSessionMessage(const std::string& session_id, 418 void OnSessionMessage(const std::string& session_id,
417 MediaKeys::MessageType message_type, 419 ContentDecryptionModule::MessageType message_type,
418 const std::vector<uint8_t>& message, 420 const std::vector<uint8_t>& message,
419 AesDecryptor* decryptor) override { 421 AesDecryptor* decryptor) override {
420 EXPECT_FALSE(session_id.empty()); 422 EXPECT_FALSE(session_id.empty());
421 EXPECT_FALSE(message.empty()); 423 EXPECT_FALSE(message.empty());
422 FAIL() << "Unexpected Message"; 424 FAIL() << "Unexpected Message";
423 } 425 }
424 426
425 void OnSessionClosed(const std::string& session_id) override { 427 void OnSessionClosed(const std::string& session_id) override {
426 EXPECT_FALSE(session_id.empty()); 428 EXPECT_FALSE(session_id.empty());
427 FAIL() << "Unexpected Closed"; 429 FAIL() << "Unexpected Closed";
(...skipping 2121 matching lines...) Expand 10 before | Expand all | Expand 10 after
2549 2551
2550 TEST_F(PipelineIntegrationTest, BasicPlaybackPositiveStartTime) { 2552 TEST_F(PipelineIntegrationTest, BasicPlaybackPositiveStartTime) {
2551 ASSERT_EQ(PIPELINE_OK, Start("nonzero-start-time.webm")); 2553 ASSERT_EQ(PIPELINE_OK, Start("nonzero-start-time.webm"));
2552 Play(); 2554 Play();
2553 ASSERT_TRUE(WaitUntilOnEnded()); 2555 ASSERT_TRUE(WaitUntilOnEnded());
2554 ASSERT_EQ(base::TimeDelta::FromMicroseconds(396000), 2556 ASSERT_EQ(base::TimeDelta::FromMicroseconds(396000),
2555 demuxer_->GetStartTime()); 2557 demuxer_->GetStartTime());
2556 } 2558 }
2557 2559
2558 } // namespace media 2560 } // namespace media
OLDNEW
« no previous file with comments | « media/remoting/rpc/proto_utils_unittest.cc ('k') | media/test/pipeline_integration_test_base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698