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

Side by Side Diff: media/cdm/ppapi/cdm_wrapper.h

Issue 131653003: Support LoadSession() in MediaKeys and PPP_ContentDecryptor_Private interface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: comments addressed 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 #ifndef MEDIA_CDM_PPAPI_CDM_WRAPPER_H_ 5 #ifndef MEDIA_CDM_PPAPI_CDM_WRAPPER_H_
6 #define MEDIA_CDM_PPAPI_CDM_WRAPPER_H_ 6 #define MEDIA_CDM_PPAPI_CDM_WRAPPER_H_
7 7
8 #include <map> 8 #include <map>
9 #include <queue> 9 #include <queue>
10 #include <string> 10 #include <string>
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 }; 46 };
47 47
48 static CdmWrapper* Create(const char* key_system, 48 static CdmWrapper* Create(const char* key_system,
49 uint32_t key_system_size, 49 uint32_t key_system_size,
50 GetCdmHostFunc get_cdm_host_func, 50 GetCdmHostFunc get_cdm_host_func,
51 void* user_data); 51 void* user_data);
52 52
53 virtual ~CdmWrapper() {}; 53 virtual ~CdmWrapper() {};
54 54
55 virtual void CreateSession(uint32_t session_id, 55 virtual void CreateSession(uint32_t session_id,
56 const char* type, 56 const char* content_type,
57 uint32_t type_size, 57 uint32_t content_type_size,
58 const uint8_t* init_data, 58 const uint8_t* init_data,
59 uint32_t init_data_size) = 0; 59 uint32_t init_data_size) = 0;
60 // Returns whether LoadSesson() is supported by the CDM.
61 // TODO(xhwang): Remove the return value when CDM_1 and CDM_2 are deprecated.
62 virtual bool LoadSession(uint32_t session_id,
63 const char* web_session_id,
64 uint32_t web_session_id_size) = 0;
60 virtual Result UpdateSession(uint32_t session_id, 65 virtual Result UpdateSession(uint32_t session_id,
61 const uint8_t* response, 66 const uint8_t* response,
62 uint32_t response_size) = 0; 67 uint32_t response_size) = 0;
63 virtual Result ReleaseSession(uint32_t session_id) = 0; 68 virtual Result ReleaseSession(uint32_t session_id) = 0;
64 virtual void TimerExpired(void* context) = 0; 69 virtual void TimerExpired(void* context) = 0;
65 virtual cdm::Status Decrypt(const cdm::InputBuffer& encrypted_buffer, 70 virtual cdm::Status Decrypt(const cdm::InputBuffer& encrypted_buffer,
66 cdm::DecryptedBlock* decrypted_buffer) = 0; 71 cdm::DecryptedBlock* decrypted_buffer) = 0;
67 virtual cdm::Status InitializeAudioDecoder( 72 virtual cdm::Status InitializeAudioDecoder(
68 const cdm::AudioDecoderConfig& audio_decoder_config) = 0; 73 const cdm::AudioDecoderConfig& audio_decoder_config) = 0;
69 virtual cdm::Status InitializeVideoDecoder( 74 virtual cdm::Status InitializeVideoDecoder(
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 146
142 return new CdmWrapperImpl<CdmInterface>( 147 return new CdmWrapperImpl<CdmInterface>(
143 static_cast<CdmInterface*>(cdm_instance)); 148 static_cast<CdmInterface*>(cdm_instance));
144 } 149 }
145 150
146 virtual ~CdmWrapperImpl() { 151 virtual ~CdmWrapperImpl() {
147 cdm_->Destroy(); 152 cdm_->Destroy();
148 } 153 }
149 154
150 virtual void CreateSession(uint32_t session_id, 155 virtual void CreateSession(uint32_t session_id,
151 const char* type, 156 const char* content_type,
152 uint32_t type_size, 157 uint32_t content_type_size,
153 const uint8_t* init_data, 158 const uint8_t* init_data,
154 uint32_t init_data_size) OVERRIDE { 159 uint32_t init_data_size) OVERRIDE {
155 // TODO(xhwang): Update the full MediaKeys stack to support LoadSession. 160 cdm_->CreateSession(
156 // See: http://crbug.com/338831 161 session_id, content_type, content_type_size, init_data, init_data_size);
157 const uint8_t kPrefixedApiLoadSessionHeader[] = "LOAD_SESSION|"; 162 }
158 const size_t kPrefixedApiLoadSessionHeaderSize =
159 sizeof(kPrefixedApiLoadSessionHeader) - 1;
160 163
161 if (init_data_size > kPrefixedApiLoadSessionHeaderSize && 164 virtual bool LoadSession(uint32_t session_id,
162 std::equal(init_data, 165 const char* web_session_id,
163 init_data + kPrefixedApiLoadSessionHeaderSize, 166 uint32_t web_session_id_size) OVERRIDE {
164 kPrefixedApiLoadSessionHeader)) { 167 cdm_->LoadSession(session_id, web_session_id, web_session_id_size);
165 cdm_->LoadSession(session_id, 168 return true;
166 reinterpret_cast<const char*>(
167 init_data + kPrefixedApiLoadSessionHeaderSize),
168 init_data_size - kPrefixedApiLoadSessionHeaderSize);
169 return;
170 }
171
172 cdm_->CreateSession(session_id, type, type_size, init_data, init_data_size);
173 } 169 }
174 170
175 virtual Result UpdateSession(uint32_t session_id, 171 virtual Result UpdateSession(uint32_t session_id,
176 const uint8_t* response, 172 const uint8_t* response,
177 uint32_t response_size) OVERRIDE { 173 uint32_t response_size) OVERRIDE {
178 cdm_->UpdateSession(session_id, response, response_size); 174 cdm_->UpdateSession(session_id, response, response_size);
179 return NO_ACTION; 175 return NO_ACTION;
180 } 176 }
181 177
182 virtual Result ReleaseSession(uint32_t session_id) OVERRIDE { 178 virtual Result ReleaseSession(uint32_t session_id) OVERRIDE {
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 // string from using the wrong session_id. 257 // string from using the wrong session_id.
262 if (!web_session_id.empty()) { 258 if (!web_session_id.empty()) {
263 PP_DCHECK(session_map_.find(session_id) == session_map_.end()); 259 PP_DCHECK(session_map_.find(session_id) == session_map_.end());
264 session_map_[session_id] = web_session_id; 260 session_map_[session_id] = web_session_id;
265 } 261 }
266 262
267 return session_id; 263 return session_id;
268 } 264 }
269 265
270 const std::string LookupWebSessionId(uint32_t session_id) { 266 const std::string LookupWebSessionId(uint32_t session_id) {
271 // Session may not exist if error happens during CreateSession(). 267 // Session may not exist if error happens during CreateSession() or
268 // LoadSession().
272 SessionMap::iterator it = session_map_.find(session_id); 269 SessionMap::iterator it = session_map_.find(session_id);
273 return (it != session_map_.end()) ? it->second : std::string(); 270 return (it != session_map_.end()) ? it->second : std::string();
274 } 271 }
275 272
276 private: 273 private:
277 CdmWrapperImpl(CdmInterface* cdm) : cdm_(cdm) { 274 CdmWrapperImpl(CdmInterface* cdm) : cdm_(cdm) {
278 PP_DCHECK(cdm_); 275 PP_DCHECK(cdm_);
279 } 276 }
280 277
281 CdmInterface* cdm_; 278 CdmInterface* cdm_;
282 279
283 DISALLOW_COPY_AND_ASSIGN(CdmWrapperImpl); 280 DISALLOW_COPY_AND_ASSIGN(CdmWrapperImpl);
284 }; 281 };
285 282
286 // For ContentDecryptionModule_1 and ContentDecryptionModule_2, 283 // For ContentDecryptionModule_1 and ContentDecryptionModule_2,
287 // CreateSession(), UpdateSession(), and ReleaseSession() call methods 284 // CreateSession(), LoadSession(), UpdateSession(), and ReleaseSession() call
288 // are incompatible with ContentDecryptionModule_4. Use the following 285 // methods are incompatible with ContentDecryptionModule_4. Use the following
289 // templated functions to handle this. 286 // templated functions to handle this.
290 287
291 template <class CdmInterface> 288 template <class CdmInterface>
292 void PrefixedGenerateKeyRequest(CdmWrapper* wrapper, 289 void PrefixedGenerateKeyRequest(CdmWrapper* wrapper,
293 CdmInterface* cdm, 290 CdmInterface* cdm,
294 uint32_t session_id, 291 uint32_t session_id,
295 const char* type, 292 const char* content_type,
296 uint32_t type_size, 293 uint32_t content_type_size,
297 const uint8_t* init_data, 294 const uint8_t* init_data,
298 uint32_t init_data_size) { 295 uint32_t init_data_size) {
299 // As it is possible for CDMs to reply synchronously during the call to 296 // As it is possible for CDMs to reply synchronously during the call to
300 // GenerateKeyRequest(), keep track of |session_id|. 297 // GenerateKeyRequest(), keep track of |session_id|.
301 wrapper->current_key_request_session_id_ = session_id; 298 wrapper->current_key_request_session_id_ = session_id;
302 299
303 cdm::Status status = 300 cdm::Status status = cdm->GenerateKeyRequest(
304 cdm->GenerateKeyRequest(type, type_size, init_data, init_data_size); 301 content_type, content_type_size, init_data, init_data_size);
305 PP_DCHECK(status == cdm::kSuccess || status == cdm::kSessionError); 302 PP_DCHECK(status == cdm::kSuccess || status == cdm::kSessionError);
306 if (status != cdm::kSuccess) { 303 if (status != cdm::kSuccess) {
307 // If GenerateKeyRequest() failed, no subsequent asynchronous replies 304 // If GenerateKeyRequest() failed, no subsequent asynchronous replies
308 // will be sent. Verify that a response was sent synchronously. 305 // will be sent. Verify that a response was sent synchronously.
309 PP_DCHECK(wrapper->current_key_request_session_id_ == 306 PP_DCHECK(wrapper->current_key_request_session_id_ ==
310 CdmWrapper::kInvalidSessionId); 307 CdmWrapper::kInvalidSessionId);
311 wrapper->current_key_request_session_id_ = CdmWrapper::kInvalidSessionId; 308 wrapper->current_key_request_session_id_ = CdmWrapper::kInvalidSessionId;
312 return; 309 return;
313 } 310 }
314 311
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 } 368 }
372 369
373 return CdmWrapper::NO_ACTION; 370 return CdmWrapper::NO_ACTION;
374 } 371 }
375 372
376 // Specializations for ContentDecryptionModule_1. 373 // Specializations for ContentDecryptionModule_1.
377 374
378 template <> 375 template <>
379 void CdmWrapperImpl<cdm::ContentDecryptionModule_1>::CreateSession( 376 void CdmWrapperImpl<cdm::ContentDecryptionModule_1>::CreateSession(
380 uint32_t session_id, 377 uint32_t session_id,
381 const char* type, 378 const char* content_type,
382 uint32_t type_size, 379 uint32_t content_type_size,
383 const uint8_t* init_data, 380 const uint8_t* init_data,
384 uint32_t init_data_size) { 381 uint32_t init_data_size) {
385 PrefixedGenerateKeyRequest( 382 PrefixedGenerateKeyRequest(this,
386 this, cdm_, session_id, type, type_size, init_data, init_data_size); 383 cdm_,
384 session_id,
385 content_type,
386 content_type_size,
387 init_data,
388 init_data_size);
387 } 389 }
388 390
389 template <> 391 template <>
392 bool CdmWrapperImpl<cdm::ContentDecryptionModule_1>::LoadSession(
393 uint32_t session_id,
394 const char* web_session_id,
395 uint32_t web_session_id_size) {
396 return false;
397 }
398
399 template <>
390 CdmWrapper::Result CdmWrapperImpl< 400 CdmWrapper::Result CdmWrapperImpl<
391 cdm::ContentDecryptionModule_1>::UpdateSession(uint32_t session_id, 401 cdm::ContentDecryptionModule_1>::UpdateSession(uint32_t session_id,
392 const uint8_t* response, 402 const uint8_t* response,
393 uint32_t response_size) { 403 uint32_t response_size) {
394 return PrefixedAddKey(this, cdm_, session_id, response, response_size); 404 return PrefixedAddKey(this, cdm_, session_id, response, response_size);
395 } 405 }
396 406
397 template <> 407 template <>
398 CdmWrapper::Result CdmWrapperImpl< 408 CdmWrapper::Result CdmWrapperImpl<
399 cdm::ContentDecryptionModule_1>::ReleaseSession(uint32_t session_id) { 409 cdm::ContentDecryptionModule_1>::ReleaseSession(uint32_t session_id) {
(...skipping 24 matching lines...) Expand all
424 audio_frames->SetFrameBuffer(audio_frames_1.PassFrameBuffer()); 434 audio_frames->SetFrameBuffer(audio_frames_1.PassFrameBuffer());
425 audio_frames->SetFormat(cdm::kAudioFormatS16); 435 audio_frames->SetFormat(cdm::kAudioFormatS16);
426 return cdm::kSuccess; 436 return cdm::kSuccess;
427 } 437 }
428 438
429 // Specializations for ContentDecryptionModule_2. 439 // Specializations for ContentDecryptionModule_2.
430 440
431 template <> 441 template <>
432 void CdmWrapperImpl<cdm::ContentDecryptionModule_2>::CreateSession( 442 void CdmWrapperImpl<cdm::ContentDecryptionModule_2>::CreateSession(
433 uint32_t session_id, 443 uint32_t session_id,
434 const char* type, 444 const char* content_type,
435 uint32_t type_size, 445 uint32_t content_type_size,
436 const uint8_t* init_data, 446 const uint8_t* init_data,
437 uint32_t init_data_size) { 447 uint32_t init_data_size) {
438 PrefixedGenerateKeyRequest( 448 PrefixedGenerateKeyRequest(this,
439 this, cdm_, session_id, type, type_size, init_data, init_data_size); 449 cdm_,
450 session_id,
451 content_type,
452 content_type_size,
453 init_data,
454 init_data_size);
440 } 455 }
441 456
442 template <> 457 template <>
458 bool CdmWrapperImpl<cdm::ContentDecryptionModule_2>::LoadSession(
459 uint32_t session_id,
460 const char* web_session_id,
461 uint32_t web_session_id_size) {
462 return false;
463 }
464
465 template <>
443 CdmWrapper::Result CdmWrapperImpl< 466 CdmWrapper::Result CdmWrapperImpl<
444 cdm::ContentDecryptionModule_2>::UpdateSession(uint32_t session_id, 467 cdm::ContentDecryptionModule_2>::UpdateSession(uint32_t session_id,
445 const uint8_t* response, 468 const uint8_t* response,
446 uint32_t response_size) { 469 uint32_t response_size) {
447 return PrefixedAddKey(this, cdm_, session_id, response, response_size); 470 return PrefixedAddKey(this, cdm_, session_id, response, response_size);
448 } 471 }
449 472
450 template <> 473 template <>
451 CdmWrapper::Result CdmWrapperImpl< 474 CdmWrapper::Result CdmWrapperImpl<
452 cdm::ContentDecryptionModule_2>::ReleaseSession(uint32_t session_id) { 475 cdm::ContentDecryptionModule_2>::ReleaseSession(uint32_t session_id) {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
498 // stub implementations for new or modified methods that the older CDM interface 521 // stub implementations for new or modified methods that the older CDM interface
499 // does not have. 522 // does not have.
500 // Also update supported_cdm_versions.h. 523 // Also update supported_cdm_versions.h.
501 COMPILE_ASSERT(cdm::ContentDecryptionModule::kVersion == 524 COMPILE_ASSERT(cdm::ContentDecryptionModule::kVersion ==
502 cdm::ContentDecryptionModule_4::kVersion, 525 cdm::ContentDecryptionModule_4::kVersion,
503 ensure_cdm_wrapper_templates_have_old_version_support); 526 ensure_cdm_wrapper_templates_have_old_version_support);
504 527
505 } // namespace media 528 } // namespace media
506 529
507 #endif // MEDIA_CDM_PPAPI_CDM_WRAPPER_H_ 530 #endif // MEDIA_CDM_PPAPI_CDM_WRAPPER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698