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

Side by Side Diff: media/cdm/ppapi/external_clear_key/clear_key_cdm.cc

Issue 166273009: PpapiDecryptor: Call NewKeyCB on OnSessionReady(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 10 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/cdm/ppapi/external_clear_key/clear_key_cdm.h" 5 #include "media/cdm/ppapi/external_clear_key/clear_key_cdm.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cstring>
8 #include <sstream> 9 #include <sstream>
9 #include <string> 10 #include <string>
10 #include <vector> 11 #include <vector>
11 12
12 #include "base/bind.h" 13 #include "base/bind.h"
13 #include "base/debug/trace_event.h" 14 #include "base/debug/trace_event.h"
14 #include "base/logging.h" 15 #include "base/logging.h"
15 #include "base/time/time.h" 16 #include "base/time/time.h"
16 #include "media/base/decoder_buffer.h" 17 #include "media/base/decoder_buffer.h"
17 #include "media/base/decrypt_config.h" 18 #include "media/base/decrypt_config.h"
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 base::Bind(&ClearKeyCdm::OnSessionCreated, base::Unretained(this)), 190 base::Bind(&ClearKeyCdm::OnSessionCreated, base::Unretained(this)),
190 base::Bind(&ClearKeyCdm::OnSessionMessage, base::Unretained(this)), 191 base::Bind(&ClearKeyCdm::OnSessionMessage, base::Unretained(this)),
191 base::Bind(&ClearKeyCdm::OnSessionReady, base::Unretained(this)), 192 base::Bind(&ClearKeyCdm::OnSessionReady, base::Unretained(this)),
192 base::Bind(&ClearKeyCdm::OnSessionClosed, base::Unretained(this)), 193 base::Bind(&ClearKeyCdm::OnSessionClosed, base::Unretained(this)),
193 base::Bind(&ClearKeyCdm::OnSessionError, base::Unretained(this))), 194 base::Bind(&ClearKeyCdm::OnSessionError, base::Unretained(this))),
194 host_(host), 195 host_(host),
195 key_system_(key_system), 196 key_system_(key_system),
196 last_session_id_(MediaKeys::kInvalidSessionId), 197 last_session_id_(MediaKeys::kInvalidSessionId),
197 session_id_for_emulated_loadsession_(MediaKeys::kInvalidSessionId), 198 session_id_for_emulated_loadsession_(MediaKeys::kInvalidSessionId),
198 timer_delay_ms_(kInitialTimerDelayMs), 199 timer_delay_ms_(kInitialTimerDelayMs),
199 timer_set_(false) { 200 heartbeat_timer_set_(false) {
200 #if defined(CLEAR_KEY_CDM_USE_FAKE_AUDIO_DECODER) 201 #if defined(CLEAR_KEY_CDM_USE_FAKE_AUDIO_DECODER)
201 channel_count_ = 0; 202 channel_count_ = 0;
202 bits_per_channel_ = 0; 203 bits_per_channel_ = 0;
203 samples_per_second_ = 0; 204 samples_per_second_ = 0;
204 output_timestamp_base_in_microseconds_ = kNoTimestamp; 205 output_timestamp_base_in_microseconds_ = kNoTimestamp;
205 total_samples_generated_ = 0; 206 total_samples_generated_ = 0;
206 #endif // CLEAR_KEY_CDM_USE_FAKE_AUDIO_DECODER 207 #endif // CLEAR_KEY_CDM_USE_FAKE_AUDIO_DECODER
207 } 208 }
208 209
209 ClearKeyCdm::~ClearKeyCdm() {} 210 ClearKeyCdm::~ClearKeyCdm() {}
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 244
244 decryptor_.CreateSession(session_id, kLoadableSessionContentType, NULL, 0); 245 decryptor_.CreateSession(session_id, kLoadableSessionContentType, NULL, 0);
245 } 246 }
246 247
247 void ClearKeyCdm::UpdateSession(uint32 session_id, 248 void ClearKeyCdm::UpdateSession(uint32 session_id,
248 const uint8* response, 249 const uint8* response,
249 uint32 response_size) { 250 uint32 response_size) {
250 DVLOG(1) << __FUNCTION__; 251 DVLOG(1) << __FUNCTION__;
251 decryptor_.UpdateSession(session_id, response, response_size); 252 decryptor_.UpdateSession(session_id, response, response_size);
252 253
253 if (!timer_set_) { 254 if (!heartbeat_timer_set_) {
254 ScheduleNextHeartBeat(); 255 ScheduleNextHeartBeat();
255 timer_set_ = true; 256 heartbeat_timer_set_ = true;
256 } 257 }
257 } 258 }
258 259
259 void ClearKeyCdm::ReleaseSession(uint32 session_id) { 260 void ClearKeyCdm::ReleaseSession(uint32 session_id) {
260 DVLOG(1) << __FUNCTION__; 261 DVLOG(1) << __FUNCTION__;
261 decryptor_.ReleaseSession(session_id); 262 decryptor_.ReleaseSession(session_id);
262 } 263 }
263 264
264 void ClearKeyCdm::TimerExpired(void* context) { 265 void ClearKeyCdm::TimerExpired(void* context) {
266 if (context == &session_id_for_emulated_loadsession_) {
267 UpdateLoadableSession();
268 return;
269 }
270
265 std::string heartbeat_message; 271 std::string heartbeat_message;
ddorwin 2014/02/19 00:04:09 Should we add this before this line? DCHECK(heartb
xhwang 2014/02/19 00:24:23 Done.
266 if (!next_heartbeat_message_.empty() && 272 if (!next_heartbeat_message_.empty() &&
267 context == &next_heartbeat_message_[0]) { 273 context == &next_heartbeat_message_[0]) {
268 heartbeat_message = next_heartbeat_message_; 274 heartbeat_message = next_heartbeat_message_;
269 } else { 275 } else {
270 heartbeat_message = "ERROR: Invalid timer context found!"; 276 heartbeat_message = "ERROR: Invalid timer context found!";
271 } 277 }
272 278
273 // This URL is only used for testing the code path for defaultURL. 279 // This URL is only used for testing the code path for defaultURL.
274 // There is no service at this URL, so applications should ignore it. 280 // There is no service at this URL, so applications should ignore it.
275 const char url[] = "http://test.externalclearkey.chromium.org"; 281 const char url[] = "http://test.externalclearkey.chromium.org";
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 void ClearKeyCdm::OnPlatformChallengeResponse( 520 void ClearKeyCdm::OnPlatformChallengeResponse(
515 const cdm::PlatformChallengeResponse& response) { 521 const cdm::PlatformChallengeResponse& response) {
516 NOTIMPLEMENTED(); 522 NOTIMPLEMENTED();
517 } 523 }
518 524
519 void ClearKeyCdm::OnQueryOutputProtectionStatus( 525 void ClearKeyCdm::OnQueryOutputProtectionStatus(
520 uint32_t link_mask, uint32_t output_protection_mask) { 526 uint32_t link_mask, uint32_t output_protection_mask) {
521 NOTIMPLEMENTED(); 527 NOTIMPLEMENTED();
522 }; 528 };
523 529
524 void ClearKeyCdm::UpdateLoadableSession() { 530 void ClearKeyCdm::UpdateLoadableSession() {
ddorwin 2014/02/19 00:04:09 I think we need a better name for this. Update() i
xhwang 2014/02/19 00:24:23 Done.
525 std::string jwk_set = GenerateJWKSet(kLoadableSessionKey, 531 std::string jwk_set = GenerateJWKSet(kLoadableSessionKey,
526 sizeof(kLoadableSessionKey), 532 sizeof(kLoadableSessionKey),
527 kLoadableSessionKeyId, 533 kLoadableSessionKeyId,
528 sizeof(kLoadableSessionKeyId) - 1); 534 sizeof(kLoadableSessionKeyId) - 1);
529 // TODO(xhwang): This triggers OnSessionUpdated(). For prefixed EME support, 535 // TODO(xhwang): This triggers OnSessionUpdated(). For prefixed EME support,
530 // this is okay. Check WD EME support. 536 // this is okay. Check WD EME support.
531 decryptor_.UpdateSession(session_id_for_emulated_loadsession_, 537 decryptor_.UpdateSession(session_id_for_emulated_loadsession_,
532 reinterpret_cast<const uint8*>(jwk_set.data()), 538 reinterpret_cast<const uint8*>(jwk_set.data()),
533 jwk_set.size()); 539 jwk_set.size());
534 } 540 }
535 541
536 void ClearKeyCdm::OnSessionCreated(uint32 session_id, 542 void ClearKeyCdm::OnSessionCreated(uint32 session_id,
537 const std::string& web_session_id) { 543 const std::string& web_session_id) {
538 std::string new_web_session_id = web_session_id; 544 std::string new_web_session_id = web_session_id;
539 545
540 if (session_id == session_id_for_emulated_loadsession_) { 546 if (session_id == session_id_for_emulated_loadsession_) {
541 new_web_session_id = kLoadableWebSessionId; 547 // Delay UpdateLoadableSession() to test the case where Decrypt*() calls are
542 UpdateLoadableSession(); 548 // made before the session is fully loaded.
543 session_id_for_emulated_loadsession_ = MediaKeys::kInvalidSessionId; 549 const int64 kDelayToLoadSessionMs = 500;
xhwang 2014/02/18 23:19:16 Ideally we should keep the old test (where the del
550 host_->SetTimer(kDelayToLoadSessionMs,
551 &session_id_for_emulated_loadsession_);
ddorwin 2014/02/19 00:04:09 It might be nice to clarify somewhere that we're u
xhwang 2014/02/19 00:24:23 Done.
552 // Defer OnSessionCreated until the session is updated with
ddorwin 2014/02/19 00:04:09 ... until the loadable session is initialized?
xhwang 2014/02/19 00:24:23 Done.
553 // kLoadableSessionKey.
554 return;
544 } 555 }
545 556
546 host_->OnSessionCreated( 557 host_->OnSessionCreated(
547 session_id, new_web_session_id.data(), new_web_session_id.size()); 558 session_id, web_session_id.data(), web_session_id.size());
548 } 559 }
549 560
550 void ClearKeyCdm::OnSessionMessage(uint32 session_id, 561 void ClearKeyCdm::OnSessionMessage(uint32 session_id,
551 const std::vector<uint8>& message, 562 const std::vector<uint8>& message,
552 const std::string& destination_url) { 563 const std::string& destination_url) {
564 DVLOG(1) << "OnSessionMessage: " << message.size();
565
566 // Ignore the Message when we are waiting to update the loadable session.
ddorwin 2014/02/19 00:04:09 nit: Is upper case 'M' intentional?
xhwang 2014/02/19 00:24:23 Done.
567 if (session_id == session_id_for_emulated_loadsession_)
568 return;
569
553 host_->OnSessionMessage(session_id, 570 host_->OnSessionMessage(session_id,
554 reinterpret_cast<const char*>(message.data()), 571 reinterpret_cast<const char*>(message.data()),
555 message.size(), 572 message.size(),
556 destination_url.data(), 573 destination_url.data(),
557 destination_url.size()); 574 destination_url.size());
558 } 575 }
559 576
560 void ClearKeyCdm::OnSessionReady(uint32 session_id) { 577 void ClearKeyCdm::OnSessionReady(uint32 session_id) {
578 if (session_id == session_id_for_emulated_loadsession_) {
579 session_id_for_emulated_loadsession_ = MediaKeys::kInvalidSessionId;
580 host_->OnSessionCreated(
581 session_id, kLoadableWebSessionId, strlen(kLoadableWebSessionId));
582 }
583
561 host_->OnSessionReady(session_id); 584 host_->OnSessionReady(session_id);
562 } 585 }
563 586
564 void ClearKeyCdm::OnSessionClosed(uint32 session_id) { 587 void ClearKeyCdm::OnSessionClosed(uint32 session_id) {
565 host_->OnSessionClosed(session_id); 588 host_->OnSessionClosed(session_id);
566 } 589 }
567 590
568 void ClearKeyCdm::OnSessionError(uint32 session_id, 591 void ClearKeyCdm::OnSessionError(uint32 session_id,
569 media::MediaKeys::KeyError error_code, 592 media::MediaKeys::KeyError error_code,
570 int system_code) { 593 int system_code) {
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
640 663
641 void ClearKeyCdm::OnFileIOTestComplete(bool success) { 664 void ClearKeyCdm::OnFileIOTestComplete(bool success) {
642 DVLOG(1) << __FUNCTION__ << ": " << success; 665 DVLOG(1) << __FUNCTION__ << ": " << success;
643 std::string message = GetFileIOTestResultMessage(success); 666 std::string message = GetFileIOTestResultMessage(success);
644 host_->OnSessionMessage( 667 host_->OnSessionMessage(
645 last_session_id_, message.data(), message.size(), NULL, 0); 668 last_session_id_, message.data(), message.size(), NULL, 0);
646 file_io_test_runner_.reset(); 669 file_io_test_runner_.reset();
647 } 670 }
648 671
649 } // namespace media 672 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698