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

Side by Side Diff: media/base/android/media_drm_bridge.cc

Issue 1534273002: Switch to standard integer types in media/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: more Created 5 years 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 (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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/base/android/media_drm_bridge.h" 5 #include "media/base/android/media_drm_bridge.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/android/build_info.h" 9 #include "base/android/build_info.h"
10 #include "base/android/jni_array.h" 10 #include "base/android/jni_array.h"
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 KEY_STATUS_INTERNAL_ERROR = 4, 58 KEY_STATUS_INTERNAL_ERROR = 4,
59 }; 59 };
60 60
61 // Converts jbyteArray (byte[] in Java) into std::string. 61 // Converts jbyteArray (byte[] in Java) into std::string.
62 std::string AsString(JNIEnv* env, jbyteArray j_byte_array) { 62 std::string AsString(JNIEnv* env, jbyteArray j_byte_array) {
63 std::vector<uint8_t> byte_vector; 63 std::vector<uint8_t> byte_vector;
64 JavaByteArrayToByteVector(env, j_byte_array, &byte_vector); 64 JavaByteArrayToByteVector(env, j_byte_array, &byte_vector);
65 return std::string(byte_vector.begin(), byte_vector.end()); 65 return std::string(byte_vector.begin(), byte_vector.end());
66 } 66 }
67 67
68 const uint8 kWidevineUuid[16] = { 68 const uint8_t kWidevineUuid[16] = {
69 0xED, 0xEF, 0x8B, 0xA9, 0x79, 0xD6, 0x4A, 0xCE, // 69 0xED, 0xEF, 0x8B, 0xA9, 0x79, 0xD6, 0x4A, 0xCE, //
70 0xA3, 0xC8, 0x27, 0xDC, 0xD5, 0x1D, 0x21, 0xED}; 70 0xA3, 0xC8, 0x27, 0xDC, 0xD5, 0x1D, 0x21, 0xED};
71 71
72 // Convert |init_data_type| to a string supported by MediaDRM. 72 // Convert |init_data_type| to a string supported by MediaDRM.
73 // "audio"/"video" does not matter, so use "video". 73 // "audio"/"video" does not matter, so use "video".
74 std::string ConvertInitDataType(media::EmeInitDataType init_data_type) { 74 std::string ConvertInitDataType(media::EmeInitDataType init_data_type) {
75 // TODO(jrummell/xhwang): EME init data types like "webm" and "cenc" are 75 // TODO(jrummell/xhwang): EME init data types like "webm" and "cenc" are
76 // supported in API level >=21 for Widevine key system. Switch to use those 76 // supported in API level >=21 for Widevine key system. Switch to use those
77 // strings when they are officially supported in Android for all key systems. 77 // strings when they are officially supported in Android for all key systems.
78 switch (init_data_type) { 78 switch (init_data_type) {
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 return ""; 213 return "";
214 } 214 }
215 215
216 } // namespace 216 } // namespace
217 217
218 // static 218 // static
219 bool MediaDrmBridge::IsAvailable() { 219 bool MediaDrmBridge::IsAvailable() {
220 if (base::android::BuildInfo::GetInstance()->sdk_int() < 19) 220 if (base::android::BuildInfo::GetInstance()->sdk_int() < 19)
221 return false; 221 return false;
222 222
223 int32 os_major_version = 0; 223 int32_t os_major_version = 0;
224 int32 os_minor_version = 0; 224 int32_t os_minor_version = 0;
225 int32 os_bugfix_version = 0; 225 int32_t os_bugfix_version = 0;
226 base::SysInfo::OperatingSystemVersionNumbers( 226 base::SysInfo::OperatingSystemVersionNumbers(
227 &os_major_version, &os_minor_version, &os_bugfix_version); 227 &os_major_version, &os_minor_version, &os_bugfix_version);
228 if (os_major_version == 4 && os_minor_version == 4 && os_bugfix_version == 0) 228 if (os_major_version == 4 && os_minor_version == 4 && os_bugfix_version == 0)
229 return false; 229 return false;
230 230
231 return true; 231 return true;
232 } 232 }
233 233
234 // static 234 // static
235 bool MediaDrmBridge::RegisterMediaDrmBridge(JNIEnv* env) { 235 bool MediaDrmBridge::RegisterMediaDrmBridge(JNIEnv* env) {
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 329
330 JNIEnv* env = AttachCurrentThread(); 330 JNIEnv* env = AttachCurrentThread();
331 ScopedJavaLocalRef<jbyteArray> j_init_data; 331 ScopedJavaLocalRef<jbyteArray> j_init_data;
332 ScopedJavaLocalRef<jobjectArray> j_optional_parameters; 332 ScopedJavaLocalRef<jobjectArray> j_optional_parameters;
333 333
334 MediaClientAndroid* client = GetMediaClientAndroid(); 334 MediaClientAndroid* client = GetMediaClientAndroid();
335 if (client) { 335 if (client) {
336 MediaDrmBridgeDelegate* delegate = 336 MediaDrmBridgeDelegate* delegate =
337 client->GetMediaDrmBridgeDelegate(scheme_uuid_); 337 client->GetMediaDrmBridgeDelegate(scheme_uuid_);
338 if (delegate) { 338 if (delegate) {
339 std::vector<uint8> init_data_from_delegate; 339 std::vector<uint8_t> init_data_from_delegate;
340 std::vector<std::string> optional_parameters_from_delegate; 340 std::vector<std::string> optional_parameters_from_delegate;
341 if (!delegate->OnCreateSession(init_data_type, init_data, 341 if (!delegate->OnCreateSession(init_data_type, init_data,
342 &init_data_from_delegate, 342 &init_data_from_delegate,
343 &optional_parameters_from_delegate)) { 343 &optional_parameters_from_delegate)) {
344 promise->reject(INVALID_ACCESS_ERROR, 0, "Invalid init data."); 344 promise->reject(INVALID_ACCESS_ERROR, 0, "Invalid init data.");
345 } 345 }
346 if (!init_data_from_delegate.empty()) { 346 if (!init_data_from_delegate.empty()) {
347 j_init_data = 347 j_init_data =
348 base::android::ToJavaByteArray(env, init_data_from_delegate.data(), 348 base::android::ToJavaByteArray(env, init_data_from_delegate.data(),
349 init_data_from_delegate.size()); 349 init_data_from_delegate.size());
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
573 573
574 void MediaDrmBridge::OnSessionMessage( 574 void MediaDrmBridge::OnSessionMessage(
575 JNIEnv* env, 575 JNIEnv* env,
576 const JavaParamRef<jobject>& j_media_drm, 576 const JavaParamRef<jobject>& j_media_drm,
577 const JavaParamRef<jbyteArray>& j_session_id, 577 const JavaParamRef<jbyteArray>& j_session_id,
578 jint j_message_type, 578 jint j_message_type,
579 const JavaParamRef<jbyteArray>& j_message, 579 const JavaParamRef<jbyteArray>& j_message,
580 const JavaParamRef<jstring>& j_legacy_destination_url) { 580 const JavaParamRef<jstring>& j_legacy_destination_url) {
581 DVLOG(2) << __FUNCTION__; 581 DVLOG(2) << __FUNCTION__;
582 582
583 std::vector<uint8> message; 583 std::vector<uint8_t> message;
584 JavaByteArrayToByteVector(env, j_message, &message); 584 JavaByteArrayToByteVector(env, j_message, &message);
585 GURL legacy_destination_url = 585 GURL legacy_destination_url =
586 GURL(ConvertJavaStringToUTF8(env, j_legacy_destination_url)); 586 GURL(ConvertJavaStringToUTF8(env, j_legacy_destination_url));
587 MediaKeys::MessageType message_type = 587 MediaKeys::MessageType message_type =
588 GetMessageType(static_cast<RequestType>(j_message_type)); 588 GetMessageType(static_cast<RequestType>(j_message_type));
589 589
590 task_runner_->PostTask( 590 task_runner_->PostTask(
591 FROM_HERE, base::Bind(session_message_cb_, AsString(env, j_session_id), 591 FROM_HERE, base::Bind(session_message_cb_, AsString(env, j_session_id),
592 message_type, message, legacy_destination_url)); 592 message_type, message, legacy_destination_url));
593 } 593 }
(...skipping 22 matching lines...) Expand all
616 616
617 size_t size = env->GetArrayLength(j_keys_info); 617 size_t size = env->GetArrayLength(j_keys_info);
618 DCHECK_GT(size, 0u); 618 DCHECK_GT(size, 0u);
619 619
620 for (size_t i = 0; i < size; ++i) { 620 for (size_t i = 0; i < size; ++i) {
621 ScopedJavaLocalRef<jobject> j_key_status( 621 ScopedJavaLocalRef<jobject> j_key_status(
622 env, env->GetObjectArrayElement(j_keys_info, i)); 622 env, env->GetObjectArrayElement(j_keys_info, i));
623 623
624 ScopedJavaLocalRef<jbyteArray> j_key_id = 624 ScopedJavaLocalRef<jbyteArray> j_key_id =
625 Java_KeyStatus_getKeyId(env, j_key_status.obj()); 625 Java_KeyStatus_getKeyId(env, j_key_status.obj());
626 std::vector<uint8> key_id; 626 std::vector<uint8_t> key_id;
627 JavaByteArrayToByteVector(env, j_key_id.obj(), &key_id); 627 JavaByteArrayToByteVector(env, j_key_id.obj(), &key_id);
628 DCHECK(!key_id.empty()); 628 DCHECK(!key_id.empty());
629 629
630 jint j_status_code = Java_KeyStatus_getStatusCode(env, j_key_status.obj()); 630 jint j_status_code = Java_KeyStatus_getStatusCode(env, j_key_status.obj());
631 CdmKeyInformation::KeyStatus key_status = 631 CdmKeyInformation::KeyStatus key_status =
632 ConvertKeyStatus(static_cast<KeyStatus>(j_status_code)); 632 ConvertKeyStatus(static_cast<KeyStatus>(j_status_code));
633 633
634 DVLOG(2) << __FUNCTION__ << "Key status change: " 634 DVLOG(2) << __FUNCTION__ << "Key status change: "
635 << base::HexEncode(&key_id[0], key_id.size()) << ", " 635 << base::HexEncode(&key_id[0], key_id.size()) << ", "
636 << key_status; 636 << key_status;
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
690 DCHECK(!reset_credentials_cb_.is_null()); 690 DCHECK(!reset_credentials_cb_.is_null());
691 task_runner_->PostTask( 691 task_runner_->PostTask(
692 FROM_HERE, 692 FROM_HERE,
693 base::Bind(base::ResetAndReturn(&reset_credentials_cb_), success)); 693 base::Bind(base::ResetAndReturn(&reset_credentials_cb_), success));
694 } 694 }
695 695
696 //------------------------------------------------------------------------------ 696 //------------------------------------------------------------------------------
697 // The following are private methods. 697 // The following are private methods.
698 698
699 MediaDrmBridge::MediaDrmBridge( 699 MediaDrmBridge::MediaDrmBridge(
700 const std::vector<uint8>& scheme_uuid, 700 const std::vector<uint8_t>& scheme_uuid,
701 SecurityLevel security_level, 701 SecurityLevel security_level,
702 const CreateFetcherCB& create_fetcher_cb, 702 const CreateFetcherCB& create_fetcher_cb,
703 const SessionMessageCB& session_message_cb, 703 const SessionMessageCB& session_message_cb,
704 const SessionClosedCB& session_closed_cb, 704 const SessionClosedCB& session_closed_cb,
705 const LegacySessionErrorCB& legacy_session_error_cb, 705 const LegacySessionErrorCB& legacy_session_error_cb,
706 const SessionKeysChangeCB& session_keys_change_cb, 706 const SessionKeysChangeCB& session_keys_change_cb,
707 const SessionExpirationUpdateCB& session_expiration_update_cb) 707 const SessionExpirationUpdateCB& session_expiration_update_cb)
708 : scheme_uuid_(scheme_uuid), 708 : scheme_uuid_(scheme_uuid),
709 create_fetcher_cb_(create_fetcher_cb), 709 create_fetcher_cb_(create_fetcher_cb),
710 session_message_cb_(session_message_cb), 710 session_message_cb_(session_message_cb),
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
824 JNIEnv* env = AttachCurrentThread(); 824 JNIEnv* env = AttachCurrentThread();
825 825
826 ScopedJavaLocalRef<jbyteArray> j_response = base::android::ToJavaByteArray( 826 ScopedJavaLocalRef<jbyteArray> j_response = base::android::ToJavaByteArray(
827 env, reinterpret_cast<const uint8_t*>(response.data()), response.size()); 827 env, reinterpret_cast<const uint8_t*>(response.data()), response.size());
828 828
829 Java_MediaDrmBridge_processProvisionResponse(env, j_media_drm_.obj(), success, 829 Java_MediaDrmBridge_processProvisionResponse(env, j_media_drm_.obj(), success,
830 j_response.obj()); 830 j_response.obj());
831 } 831 }
832 832
833 } // namespace media 833 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698