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

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

Powered by Google App Engine
This is Rietveld 408576698