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

Side by Side Diff: media/cdm/ppapi/cdm_adapter.cc

Issue 446693004: Add support for CDM_6. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add comments Created 6 years, 4 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 #include "media/cdm/ppapi/cdm_adapter.h" 5 #include "media/cdm/ppapi/cdm_adapter.h"
6 6
7 #include "media/cdm/ppapi/cdm_file_io_impl.h" 7 #include "media/cdm/ppapi/cdm_file_io_impl.h"
8 #include "media/cdm/ppapi/cdm_helpers.h" 8 #include "media/cdm/ppapi/cdm_helpers.h"
9 #include "media/cdm/ppapi/cdm_logging.h" 9 #include "media/cdm/ppapi/cdm_logging.h"
10 #include "media/cdm/ppapi/supported_cdm_versions.h" 10 #include "media/cdm/ppapi/supported_cdm_versions.h"
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 378
379 cdm_->UpdateSession(promise_id, 379 cdm_->UpdateSession(promise_id,
380 web_session_id.data(), 380 web_session_id.data(),
381 web_session_id.length(), 381 web_session_id.length(),
382 response_ptr, 382 response_ptr,
383 response_size); 383 response_size);
384 } 384 }
385 385
386 void CdmAdapter::ReleaseSession(uint32_t promise_id, 386 void CdmAdapter::ReleaseSession(uint32_t promise_id,
387 const std::string& web_session_id) { 387 const std::string& web_session_id) {
388 cdm_->ReleaseSession( 388 cdm_->CloseSession(
389 promise_id, web_session_id.data(), web_session_id.length()); 389 promise_id, web_session_id.data(), web_session_id.length());
390 } 390 }
391 391
392 void CdmAdapter::RemoveSession(uint32_t promise_id,
393 const std::string& web_session_id) {
394 if (!cdm_->RemoveSession(
395 promise_id, web_session_id.data(), web_session_id.length())) {
396 // CDM_4 and CDM_5 don't support this method, so reject the promise.
397 RejectPromise(promise_id, cdm::kNotSupportedError, 0, "Not implemented.");
398 }
399 }
400
401 void CdmAdapter::GetUsableKeyIds(uint32_t promise_id,
402 const std::string& web_session_id) {
403 if (!cdm_->GetUsableKeyIds(
404 promise_id, web_session_id.data(), web_session_id.length())) {
405 // CDM_4 and CDM_5 don't support this method, so reject the promise.
406 RejectPromise(promise_id, cdm::kNotSupportedError, 0, "Not implemented.");
407 }
408 }
409
392 // Note: In the following decryption/decoding related functions, errors are NOT 410 // Note: In the following decryption/decoding related functions, errors are NOT
393 // reported via KeyError, but are reported via corresponding PPB calls. 411 // reported via KeyError, but are reported via corresponding PPB calls.
394 412
395 void CdmAdapter::Decrypt(pp::Buffer_Dev encrypted_buffer, 413 void CdmAdapter::Decrypt(pp::Buffer_Dev encrypted_buffer,
396 const PP_EncryptedBlockInfo& encrypted_block_info) { 414 const PP_EncryptedBlockInfo& encrypted_block_info) {
397 PP_DCHECK(!encrypted_buffer.is_null()); 415 PP_DCHECK(!encrypted_buffer.is_null());
398 416
399 // Release a buffer that the caller indicated it is finished with. 417 // Release a buffer that the caller indicated it is finished with.
400 allocator_.Release(encrypted_block_info.tracking_info.buffer_id); 418 allocator_.Release(encrypted_block_info.tracking_info.buffer_id);
401 419
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
660 std::string web_session_id = cdm_->LookupWebSessionId(session_id); 678 std::string web_session_id = cdm_->LookupWebSessionId(session_id);
661 OnSessionError(web_session_id.data(), 679 OnSessionError(web_session_id.data(),
662 web_session_id.length(), 680 web_session_id.length(),
663 error, 681 error,
664 system_code, 682 system_code,
665 NULL, 683 NULL,
666 0); 684 0);
667 } 685 }
668 } 686 }
669 687
670 // cdm::Host_5 methods 688 // cdm::Host_5 and cdm::Host_6 methods
671 689
672 cdm::Time CdmAdapter::GetCurrentTime() { 690 cdm::Time CdmAdapter::GetCurrentTime() {
691 return GetCurrentWallTime();
692 }
693
694 cdm::Time CdmAdapter::GetCurrentWallTime() {
673 return pp::Module::Get()->core()->GetTime(); 695 return pp::Module::Get()->core()->GetTime();
674 } 696 }
675 697
676 void CdmAdapter::OnResolvePromise(uint32_t promise_id) { 698 void CdmAdapter::OnResolvePromise(uint32_t promise_id) {
677 PostOnMain(callback_factory_.NewCallback( 699 PostOnMain(callback_factory_.NewCallback(
678 &CdmAdapter::SendPromiseResolvedInternal, promise_id)); 700 &CdmAdapter::SendPromiseResolvedInternal, promise_id));
701
702 // CDM_5 doesn't support OnSessionKeysChange(), so simulate one if requested.
703 // Passing "true" which may result in false positives for retrying.
704 std::string session_id;
705 if (cdm_->SessionUsableKeysEventNeeded(promise_id, &session_id))
706 OnSessionKeysChange(session_id.data(), session_id.length(), true);
679 } 707 }
680 708
681 void CdmAdapter::OnResolveNewSessionPromise(uint32_t promise_id, 709 void CdmAdapter::OnResolveNewSessionPromise(uint32_t promise_id,
682 const char* web_session_id, 710 const char* web_session_id,
683 uint32_t web_session_id_length) { 711 uint32_t web_session_id_length) {
684 PostOnMain(callback_factory_.NewCallback( 712 PostOnMain(callback_factory_.NewCallback(
685 &CdmAdapter::SendPromiseResolvedWithSessionInternal, 713 &CdmAdapter::SendPromiseResolvedWithSessionInternal,
686 promise_id, 714 promise_id,
687 std::string(web_session_id, web_session_id_length))); 715 std::string(web_session_id, web_session_id_length)));
716
717 // CDM_5 doesn't support OnSessionKeysChange(), so simulate one if requested.
718 // Passing "true" which may result in false positives for retrying.
719 std::string session_id;
720 if (cdm_->SessionUsableKeysEventNeeded(promise_id, &session_id))
721 OnSessionKeysChange(web_session_id, web_session_id_length, true);
722 }
723
724 void CdmAdapter::OnResolveKeyIdsPromise(uint32_t promise_id,
725 const cdm::BinaryData* usable_key_ids,
726 uint32_t usable_key_ids_length) {
727 std::vector<std::vector<uint8> > key_ids;
728 for (uint32_t i = 0; i < usable_key_ids_length; ++i) {
729 key_ids.push_back(
730 std::vector<uint8>(usable_key_ids[i].data,
731 usable_key_ids[i].data + usable_key_ids[i].length));
732 }
733 PostOnMain(callback_factory_.NewCallback(
734 &CdmAdapter::SendPromiseResolvedWithUsableKeyIdsInternal,
735 promise_id,
736 key_ids));
688 } 737 }
689 738
690 void CdmAdapter::OnRejectPromise(uint32_t promise_id, 739 void CdmAdapter::OnRejectPromise(uint32_t promise_id,
691 cdm::Error error, 740 cdm::Error error,
692 uint32_t system_code, 741 uint32_t system_code,
693 const char* error_message, 742 const char* error_message,
694 uint32_t error_message_length) { 743 uint32_t error_message_length) {
695 RejectPromise(promise_id, 744 RejectPromise(promise_id,
696 error, 745 error,
697 system_code, 746 system_code,
(...skipping 19 matching lines...) Expand all
717 PostOnMain(callback_factory_.NewCallback( 766 PostOnMain(callback_factory_.NewCallback(
718 &CdmAdapter::SendSessionMessageInternal, 767 &CdmAdapter::SendSessionMessageInternal,
719 std::string(web_session_id, web_session_id_length), 768 std::string(web_session_id, web_session_id_length),
720 std::vector<uint8>(message, message + message_length), 769 std::vector<uint8>(message, message + message_length),
721 std::string(destination_url, destination_url_length))); 770 std::string(destination_url, destination_url_length)));
722 } 771 }
723 772
724 void CdmAdapter::OnSessionKeysChange(const char* web_session_id, 773 void CdmAdapter::OnSessionKeysChange(const char* web_session_id,
725 uint32_t web_session_id_length, 774 uint32_t web_session_id_length,
726 bool has_additional_usable_key) { 775 bool has_additional_usable_key) {
727 // TODO(jrummell): Implement this event in subsequent CL 776 OnSessionUsableKeysChange(
728 // (http://crbug.com/370251). 777 web_session_id, web_session_id_length, has_additional_usable_key);
729 PP_NOTREACHED(); 778 }
779
780 void CdmAdapter::OnSessionUsableKeysChange(const char* web_session_id,
781 uint32_t web_session_id_length,
782 bool has_additional_usable_key) {
783 PostOnMain(callback_factory_.NewCallback(
784 &CdmAdapter::SendSessionUsableKeysChangeInternal,
785 std::string(web_session_id, web_session_id_length),
786 has_additional_usable_key));
730 } 787 }
731 788
732 void CdmAdapter::OnExpirationChange(const char* web_session_id, 789 void CdmAdapter::OnExpirationChange(const char* web_session_id,
733 uint32_t web_session_id_length, 790 uint32_t web_session_id_length,
734 cdm::Time new_expiry_time) { 791 cdm::Time new_expiry_time) {
735 // TODO(jrummell): Implement this event in subsequent CL 792 PostOnMain(callback_factory_.NewCallback(
736 // (http://crbug.com/370251). 793 &CdmAdapter::SendExpirationChangeInternal,
737 PP_NOTREACHED(); 794 std::string(web_session_id, web_session_id_length),
795 new_expiry_time));
738 } 796 }
739 797
740 void CdmAdapter::OnSessionReady(const char* web_session_id, 798 void CdmAdapter::OnSessionReady(const char* web_session_id,
741 uint32_t web_session_id_length) { 799 uint32_t web_session_id_length) {
742 PostOnMain(callback_factory_.NewCallback( 800 PostOnMain(callback_factory_.NewCallback(
743 &CdmAdapter::SendSessionReadyInternal, 801 &CdmAdapter::SendSessionReadyInternal,
744 std::string(web_session_id, web_session_id_length))); 802 std::string(web_session_id, web_session_id_length)));
745 } 803 }
746 804
747 void CdmAdapter::OnSessionClosed(const char* web_session_id, 805 void CdmAdapter::OnSessionClosed(const char* web_session_id,
(...skipping 27 matching lines...) Expand all
775 833
776 void CdmAdapter::SendPromiseResolvedWithSessionInternal( 834 void CdmAdapter::SendPromiseResolvedWithSessionInternal(
777 int32_t result, 835 int32_t result,
778 uint32_t promise_id, 836 uint32_t promise_id,
779 const std::string& web_session_id) { 837 const std::string& web_session_id) {
780 PP_DCHECK(result == PP_OK); 838 PP_DCHECK(result == PP_OK);
781 pp::ContentDecryptor_Private::PromiseResolvedWithSession(promise_id, 839 pp::ContentDecryptor_Private::PromiseResolvedWithSession(promise_id,
782 web_session_id); 840 web_session_id);
783 } 841 }
784 842
843 void CdmAdapter::SendPromiseResolvedWithUsableKeyIdsInternal(
844 int32_t result,
845 uint32_t promise_id,
846 std::vector<std::vector<uint8> > key_ids) {
847 PP_DCHECK(result == PP_OK);
848 // TODO(jrummell): Implement this event in subsequent CL.
849 // (http://crbug.com/358271).
850 }
851
785 void CdmAdapter::SendPromiseRejectedInternal(int32_t result, 852 void CdmAdapter::SendPromiseRejectedInternal(int32_t result,
786 uint32_t promise_id, 853 uint32_t promise_id,
787 const SessionError& error) { 854 const SessionError& error) {
788 PP_DCHECK(result == PP_OK); 855 PP_DCHECK(result == PP_OK);
789 pp::ContentDecryptor_Private::PromiseRejected( 856 pp::ContentDecryptor_Private::PromiseRejected(
790 promise_id, 857 promise_id,
791 CdmExceptionTypeToPpCdmExceptionType(error.error), 858 CdmExceptionTypeToPpCdmExceptionType(error.error),
792 error.system_code, 859 error.system_code,
793 error.error_description); 860 error.error_description);
794 } 861 }
(...skipping 30 matching lines...) Expand all
825 const std::string& web_session_id, 892 const std::string& web_session_id,
826 const SessionError& error) { 893 const SessionError& error) {
827 PP_DCHECK(result == PP_OK); 894 PP_DCHECK(result == PP_OK);
828 pp::ContentDecryptor_Private::SessionError( 895 pp::ContentDecryptor_Private::SessionError(
829 web_session_id, 896 web_session_id,
830 CdmExceptionTypeToPpCdmExceptionType(error.error), 897 CdmExceptionTypeToPpCdmExceptionType(error.error),
831 error.system_code, 898 error.system_code,
832 error.error_description); 899 error.error_description);
833 } 900 }
834 901
902 void CdmAdapter::SendSessionUsableKeysChangeInternal(
903 int32_t result,
904 const std::string& web_session_id,
905 bool has_additional_usable_key) {
906 PP_DCHECK(result == PP_OK);
907 // TODO(jrummell): Implement this event in subsequent CL.
908 // (http://crbug.com/358271).
909 }
910
911 void CdmAdapter::SendExpirationChangeInternal(int32_t result,
912 const std::string& web_session_id,
913 cdm::Time new_expiry_time) {
914 PP_DCHECK(result == PP_OK);
915 // TODO(jrummell): Implement this event in subsequent CL.
916 // (http://crbug.com/358271).
917 }
918
835 void CdmAdapter::DeliverBlock(int32_t result, 919 void CdmAdapter::DeliverBlock(int32_t result,
836 const cdm::Status& status, 920 const cdm::Status& status,
837 const LinkedDecryptedBlock& decrypted_block, 921 const LinkedDecryptedBlock& decrypted_block,
838 const PP_DecryptTrackingInfo& tracking_info) { 922 const PP_DecryptTrackingInfo& tracking_info) {
839 PP_DCHECK(result == PP_OK); 923 PP_DCHECK(result == PP_OK);
840 PP_DecryptedBlockInfo decrypted_block_info = {}; 924 PP_DecryptedBlockInfo decrypted_block_info = {};
841 decrypted_block_info.tracking_info = tracking_info; 925 decrypted_block_info.tracking_info = tracking_info;
842 decrypted_block_info.tracking_info.timestamp = decrypted_block->Timestamp(); 926 decrypted_block_info.tracking_info.timestamp = decrypted_block->Timestamp();
843 decrypted_block_info.tracking_info.buffer_id = 0; 927 decrypted_block_info.tracking_info.buffer_id = 0;
844 decrypted_block_info.data_size = 0; 928 decrypted_block_info.data_size = 0;
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after
1207 : error(error), 1291 : error(error),
1208 system_code(system_code), 1292 system_code(system_code),
1209 error_description(error_description) { 1293 error_description(error_description) {
1210 } 1294 }
1211 1295
1212 void* GetCdmHost(int host_interface_version, void* user_data) { 1296 void* GetCdmHost(int host_interface_version, void* user_data) {
1213 if (!host_interface_version || !user_data) 1297 if (!host_interface_version || !user_data)
1214 return NULL; 1298 return NULL;
1215 1299
1216 COMPILE_ASSERT( 1300 COMPILE_ASSERT(
1217 cdm::ContentDecryptionModule::Host::kVersion == cdm::Host_5::kVersion, 1301 cdm::ContentDecryptionModule::Host::kVersion == cdm::Host_6::kVersion,
1218 update_code_below); 1302 update_code_below);
1219 1303
1220 // Ensure IsSupportedCdmHostVersion matches implementation of this function. 1304 // Ensure IsSupportedCdmHostVersion matches implementation of this function.
1221 // Always update this DCHECK when updating this function. 1305 // Always update this DCHECK when updating this function.
1222 // If this check fails, update this function and DCHECK or update 1306 // If this check fails, update this function and DCHECK or update
1223 // IsSupportedCdmHostVersion. 1307 // IsSupportedCdmHostVersion.
1224 1308
1225 PP_DCHECK( 1309 PP_DCHECK(
1226 // Future version is not supported. 1310 // Future version is not supported.
1227 !IsSupportedCdmHostVersion(cdm::Host_5::kVersion + 1) && 1311 !IsSupportedCdmHostVersion(cdm::Host_6::kVersion + 1) &&
1228 // Current version is supported. 1312 // Current version is supported.
1313 IsSupportedCdmHostVersion(cdm::Host_6::kVersion) &&
1314 // Include all previous supported versions (if any) here.
1229 IsSupportedCdmHostVersion(cdm::Host_5::kVersion) && 1315 IsSupportedCdmHostVersion(cdm::Host_5::kVersion) &&
1230 // Include all previous supported versions (if any) here.
1231 IsSupportedCdmHostVersion(cdm::Host_4::kVersion) && 1316 IsSupportedCdmHostVersion(cdm::Host_4::kVersion) &&
1232 // One older than the oldest supported version is not supported. 1317 // One older than the oldest supported version is not supported.
1233 !IsSupportedCdmHostVersion(cdm::Host_4::kVersion - 1)); 1318 !IsSupportedCdmHostVersion(cdm::Host_4::kVersion - 1));
1234 PP_DCHECK(IsSupportedCdmHostVersion(host_interface_version)); 1319 PP_DCHECK(IsSupportedCdmHostVersion(host_interface_version));
1235 1320
1236 CdmAdapter* cdm_adapter = static_cast<CdmAdapter*>(user_data); 1321 CdmAdapter* cdm_adapter = static_cast<CdmAdapter*>(user_data);
1237 CDM_DLOG() << "Create CDM Host with version " << host_interface_version; 1322 CDM_DLOG() << "Create CDM Host with version " << host_interface_version;
1238 switch (host_interface_version) { 1323 switch (host_interface_version) {
1239 case cdm::Host_4::kVersion: 1324 case cdm::Host_4::kVersion:
1240 return static_cast<cdm::Host_4*>(cdm_adapter); 1325 return static_cast<cdm::Host_4*>(cdm_adapter);
1241 case cdm::Host_5::kVersion: 1326 case cdm::Host_5::kVersion:
1242 return static_cast<cdm::Host_5*>(cdm_adapter); 1327 return static_cast<cdm::Host_5*>(cdm_adapter);
1328 case cdm::Host_6::kVersion:
1329 return static_cast<cdm::Host_6*>(cdm_adapter);
1243 default: 1330 default:
1244 PP_NOTREACHED(); 1331 PP_NOTREACHED();
1245 return NULL; 1332 return NULL;
1246 } 1333 }
1247 } 1334 }
1248 1335
1249 // This object is the global object representing this plugin library as long 1336 // This object is the global object representing this plugin library as long
1250 // as it is loaded. 1337 // as it is loaded.
1251 class CdmAdapterModule : public pp::Module { 1338 class CdmAdapterModule : public pp::Module {
1252 public: 1339 public:
(...skipping 17 matching lines...) Expand all
1270 } // namespace media 1357 } // namespace media
1271 1358
1272 namespace pp { 1359 namespace pp {
1273 1360
1274 // Factory function for your specialization of the Module object. 1361 // Factory function for your specialization of the Module object.
1275 Module* CreateModule() { 1362 Module* CreateModule() {
1276 return new media::CdmAdapterModule(); 1363 return new media::CdmAdapterModule();
1277 } 1364 }
1278 1365
1279 } // namespace pp 1366 } // namespace pp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698