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

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

Issue 518353002: Remove CDM_5 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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
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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 // Since the callbacks don't come through this interface, cdm_adapter needs to 96 // Since the callbacks don't come through this interface, cdm_adapter needs to
97 // create the mapping (and delete it on release). 97 // create the mapping (and delete it on release).
98 // TODO(jrummell): Remove these once Host_4 interface is removed. 98 // TODO(jrummell): Remove these once Host_4 interface is removed.
99 virtual uint32_t LookupPromiseId(uint32_t session_id) = 0; 99 virtual uint32_t LookupPromiseId(uint32_t session_id) = 0;
100 virtual void AssignWebSessionId(uint32_t session_id, 100 virtual void AssignWebSessionId(uint32_t session_id,
101 const char* web_session_id, 101 const char* web_session_id,
102 uint32_t web_session_id_size) = 0; 102 uint32_t web_session_id_size) = 0;
103 virtual std::string LookupWebSessionId(uint32_t session_id) = 0; 103 virtual std::string LookupWebSessionId(uint32_t session_id) = 0;
104 virtual void DropWebSessionId(std::string web_session_id) = 0; 104 virtual void DropWebSessionId(std::string web_session_id) = 0;
105 105
106 // Helper functions for the cdm::Host_4 and cdm::Host_5 methods. 106 // Helper functions for the cdm::Host_4 methods.
107 // CDMs using cdm::Host_6 will call OnSessionUsableKeys() as necessary when 107 // CDMs using cdm::Host_6 will call OnSessionUsableKeys() as necessary when
108 // resolving LoadSession() and UpdateSession(). This needs to be simulated 108 // resolving LoadSession() and UpdateSession(). This needs to be simulated
109 // for the older CDMs. These must not be called for cdm::Host_6 and later. 109 // for the older CDMs. These must not be called for cdm::Host_6 and later.
110 // TODO(jrummell): Remove these once Host_4 and Host_5 interfaces are removed. 110 // TODO(jrummell): Remove these once Host_4 interface is removed.
111 111
112 // Query whether a SessionUsableKeys event is necessary for the specified 112 // Query whether a SessionUsableKeys event is necessary for the specified
113 // |promise_id|. Returns true if needed and |web_session_id| is updated, 113 // |promise_id|. Returns true if needed and |web_session_id| is updated,
114 // otherwise returns false. 114 // otherwise returns false.
115 virtual bool SessionUsableKeysEventNeeded(uint32_t promise_id, 115 virtual bool SessionUsableKeysEventNeeded(uint32_t promise_id,
116 std::string* web_session_id) = 0; 116 std::string* web_session_id) = 0;
117 117
118 // Used to indicate that a SessionUsableKeys event is required for the 118 // Used to indicate that a SessionUsableKeys event is required for the
119 // specified |promise_id| and associated |web_session_id|. 119 // specified |promise_id| and associated |web_session_id|.
120 virtual void SetSessionUsableKeysEventNeeded( 120 virtual void SetSessionUsableKeysEventNeeded(
121 uint32_t promise_id, 121 uint32_t promise_id,
122 const char* web_session_id, 122 const char* web_session_id,
123 uint32_t web_session_id_size) = 0; 123 uint32_t web_session_id_size) = 0;
124 124
125 // cdm::Host_6 introduces InputBuffer_2 (aka InputBuffer). cdm::Host_4 and 125 // cdm::Host_6 introduces InputBuffer_2 (aka InputBuffer). cdm::Host_4
126 // cdm::Host_5 methods still use InputBuffer_1, so this helper function 126 // methods still use InputBuffer_1, so this helper function
127 // converts InputBuffer_2 to InputBuffer_1. 127 // converts InputBuffer_2 to InputBuffer_1.
128 // TODO(jrummell): Remove these once Host_4 and Host_5 interfaces are removed. 128 // TODO(jrummell): Remove these once Host_4 interfaces is removed.
129 virtual void ConvertInputBuffer(const cdm::InputBuffer& v2, 129 virtual void ConvertInputBuffer(const cdm::InputBuffer& v2,
130 cdm::InputBuffer_1* v1) = 0; 130 cdm::InputBuffer_1* v1) = 0;
131 131
132 // Prior to CDM_6, |init_data_type| was a content type. This helper convererts 132 // Prior to CDM_6, |init_data_type| was a content type. This helper convererts
133 // an |init_data_type| to a content type. 133 // an |init_data_type| to a content type.
134 // TODO(sandersd): Remove once Host_4 and Host_5 interfaces are removed. 134 // TODO(sandersd): Remove once Host_4 interface is removed.
135 virtual std::string ConvertInitDataTypeToContentType( 135 virtual std::string ConvertInitDataTypeToContentType(
136 const std::string& init_data_type) const = 0; 136 const std::string& init_data_type) const = 0;
137 137
138 protected: 138 protected:
139 CdmWrapper() {} 139 CdmWrapper() {}
140 140
141 private: 141 private:
142 DISALLOW_COPY_AND_ASSIGN(CdmWrapper); 142 DISALLOW_COPY_AND_ASSIGN(CdmWrapper);
143 }; 143 };
144 144
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 template <> 504 template <>
505 cdm::Status 505 cdm::Status
506 CdmWrapperImpl<cdm::ContentDecryptionModule_4>::DecryptAndDecodeSamples( 506 CdmWrapperImpl<cdm::ContentDecryptionModule_4>::DecryptAndDecodeSamples(
507 const cdm::InputBuffer& encrypted_buffer, 507 const cdm::InputBuffer& encrypted_buffer,
508 cdm::AudioFrames* audio_frames) { 508 cdm::AudioFrames* audio_frames) {
509 cdm::InputBuffer_1 buffer; 509 cdm::InputBuffer_1 buffer;
510 ConvertInputBuffer(encrypted_buffer, &buffer); 510 ConvertInputBuffer(encrypted_buffer, &buffer);
511 return cdm_->DecryptAndDecodeSamples(buffer, audio_frames); 511 return cdm_->DecryptAndDecodeSamples(buffer, audio_frames);
512 } 512 }
513 513
514 // Overrides for the cdm::Host_5 methods.
515 // TODO(jrummell): Remove these once Host_5 interface is removed.
516
517 template <>
518 void CdmWrapperImpl<cdm::ContentDecryptionModule_5>::CreateSession(
519 uint32_t promise_id,
520 const char* init_data_type,
521 uint32_t init_data_type_size,
522 const uint8_t* init_data,
523 uint32_t init_data_size,
524 cdm::SessionType session_type) {
525 std::string converted_init_data_type = ConvertInitDataTypeToContentType(
526 std::string(init_data_type, init_data_type_size));
527 // TODO(jrummell): Remove this code once |session_type| is passed through
528 // Pepper. When removing, add the header back in for CDM4.
529 PP_DCHECK(session_type == cdm::kTemporary);
530 const char kPersistentSessionHeader[] = "PERSISTENT|";
531 if (HasHeader(init_data, init_data_size, kPersistentSessionHeader)) {
532 cdm_->CreateSession(promise_id,
533 converted_init_data_type.data(),
534 converted_init_data_type.length(),
535 init_data + strlen(kPersistentSessionHeader),
536 init_data_size - strlen(kPersistentSessionHeader),
537 cdm::kPersistent);
538 return;
539 }
540
541 cdm_->CreateSession(promise_id,
542 converted_init_data_type.data(),
543 converted_init_data_type.length(),
544 init_data,
545 init_data_size,
546 session_type);
547 }
548
549 template <>
550 void CdmWrapperImpl<cdm::ContentDecryptionModule_5>::LoadSession(
551 uint32_t promise_id,
552 const char* web_session_id,
553 uint32_t web_session_id_size) {
554 // As CDM_5 doesn't support OnSessionUsableKeysChange(), make sure to generate
555 // one when the promise is resolved. This may be overly aggressive.
556 SetSessionUsableKeysEventNeeded(
557 promise_id, web_session_id, web_session_id_size);
558 cdm_->LoadSession(promise_id, web_session_id, web_session_id_size);
559 }
560
561 template <>
562 void CdmWrapperImpl<cdm::ContentDecryptionModule_5>::UpdateSession(
563 uint32_t promise_id,
564 const char* web_session_id,
565 uint32_t web_session_id_size,
566 const uint8_t* response,
567 uint32_t response_size) {
568 // As CDM_5 doesn't support OnSessionUsableKeysChange(), make sure to generate
569 // one when the promise is resolved. This may be overly aggressive.
570 SetSessionUsableKeysEventNeeded(
571 promise_id, web_session_id, web_session_id_size);
572 cdm_->UpdateSession(
573 promise_id, web_session_id, web_session_id_size, response, response_size);
574 }
575
576 template <>
577 bool CdmWrapperImpl<cdm::ContentDecryptionModule_5>::CloseSession(
578 uint32_t promise_id,
579 const char* web_session_id,
580 uint32_t web_session_id_size) {
581 return false;
582 }
583
584 template <>
585 void CdmWrapperImpl<cdm::ContentDecryptionModule_5>::RemoveSession(
586 uint32_t promise_id,
587 const char* web_session_id,
588 uint32_t web_session_id_size) {
589 cdm_->ReleaseSession(promise_id, web_session_id, web_session_id_size);
590 }
591
592 template <>
593 bool CdmWrapperImpl<cdm::ContentDecryptionModule_5>::GetUsableKeyIds(
594 uint32_t promise_id,
595 const char* web_session_id,
596 uint32_t web_session_id_size) {
597 return false;
598 }
599
600 template <>
601 cdm::Status CdmWrapperImpl<cdm::ContentDecryptionModule_5>::Decrypt(
602 const cdm::InputBuffer& encrypted_buffer,
603 cdm::DecryptedBlock* decrypted_buffer) {
604 cdm::InputBuffer_1 buffer;
605 ConvertInputBuffer(encrypted_buffer, &buffer);
606 return cdm_->Decrypt(buffer, decrypted_buffer);
607 }
608
609 template <>
610 cdm::Status
611 CdmWrapperImpl<cdm::ContentDecryptionModule_5>::DecryptAndDecodeFrame(
612 const cdm::InputBuffer& encrypted_buffer,
613 cdm::VideoFrame* video_frame) {
614 cdm::InputBuffer_1 buffer;
615 ConvertInputBuffer(encrypted_buffer, &buffer);
616 return cdm_->DecryptAndDecodeFrame(buffer, video_frame);
617 }
618
619 template <>
620 cdm::Status
621 CdmWrapperImpl<cdm::ContentDecryptionModule_5>::DecryptAndDecodeSamples(
622 const cdm::InputBuffer& encrypted_buffer,
623 cdm::AudioFrames* audio_frames) {
624 cdm::InputBuffer_1 buffer;
625 ConvertInputBuffer(encrypted_buffer, &buffer);
626 return cdm_->DecryptAndDecodeSamples(buffer, audio_frames);
627 }
628
xhwang 2014/08/29 23:40:46 hooray!
jrummell 2014/08/29 23:52:19 Acknowledged.
629 CdmWrapper* CdmWrapper::Create(const char* key_system, 514 CdmWrapper* CdmWrapper::Create(const char* key_system,
630 uint32_t key_system_size, 515 uint32_t key_system_size,
631 GetCdmHostFunc get_cdm_host_func, 516 GetCdmHostFunc get_cdm_host_func,
632 void* user_data) { 517 void* user_data) {
633 COMPILE_ASSERT(cdm::ContentDecryptionModule::kVersion == 518 COMPILE_ASSERT(cdm::ContentDecryptionModule::kVersion ==
634 cdm::ContentDecryptionModule_6::kVersion, 519 cdm::ContentDecryptionModule_6::kVersion,
635 update_code_below); 520 update_code_below);
636 521
637 // Ensure IsSupportedCdmInterfaceVersion() matches this implementation. 522 // Ensure IsSupportedCdmInterfaceVersion() matches this implementation.
638 // Always update this DCHECK when updating this function. 523 // Always update this DCHECK when updating this function.
(...skipping 10 matching lines...) Expand all
649 534
650 // Try to create the CDM using the latest CDM interface version. 535 // Try to create the CDM using the latest CDM interface version.
651 CdmWrapper* cdm_wrapper = 536 CdmWrapper* cdm_wrapper =
652 CdmWrapperImpl<cdm::ContentDecryptionModule>::Create( 537 CdmWrapperImpl<cdm::ContentDecryptionModule>::Create(
653 key_system, key_system_size, get_cdm_host_func, user_data); 538 key_system, key_system_size, get_cdm_host_func, user_data);
654 if (cdm_wrapper) 539 if (cdm_wrapper)
655 return cdm_wrapper; 540 return cdm_wrapper;
656 541
657 // If |cdm_wrapper| is NULL, try to create the CDM using older supported 542 // If |cdm_wrapper| is NULL, try to create the CDM using older supported
658 // versions of the CDM interface. 543 // versions of the CDM interface.
659 cdm_wrapper = CdmWrapperImpl<cdm::ContentDecryptionModule_5>::Create(
660 key_system, key_system_size, get_cdm_host_func, user_data);
661 if (cdm_wrapper)
662 return cdm_wrapper;
663
664 cdm_wrapper = CdmWrapperImpl<cdm::ContentDecryptionModule_4>::Create( 544 cdm_wrapper = CdmWrapperImpl<cdm::ContentDecryptionModule_4>::Create(
665 key_system, key_system_size, get_cdm_host_func, user_data); 545 key_system, key_system_size, get_cdm_host_func, user_data);
666 return cdm_wrapper; 546 return cdm_wrapper;
667 } 547 }
668 548
669 // When updating the CdmAdapter, ensure you've updated the CdmWrapper to contain 549 // When updating the CdmAdapter, ensure you've updated the CdmWrapper to contain
670 // stub implementations for new or modified methods that the older CDM interface 550 // stub implementations for new or modified methods that the older CDM interface
671 // does not have. 551 // does not have.
672 // Also update supported_cdm_versions.h. 552 // Also update supported_cdm_versions.h.
673 COMPILE_ASSERT(cdm::ContentDecryptionModule::kVersion == 553 COMPILE_ASSERT(cdm::ContentDecryptionModule::kVersion ==
674 cdm::ContentDecryptionModule_6::kVersion, 554 cdm::ContentDecryptionModule_6::kVersion,
675 ensure_cdm_wrapper_templates_have_old_version_support); 555 ensure_cdm_wrapper_templates_have_old_version_support);
676 556
677 } // namespace media 557 } // namespace media
678 558
679 #endif // MEDIA_CDM_PPAPI_CDM_WRAPPER_H_ 559 #endif // MEDIA_CDM_PPAPI_CDM_WRAPPER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698