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

Side by Side Diff: webkit/renderer/media/android/webmediaplayer_android.cc

Issue 17289006: Separate CDM initialization from GenerateKeyRequest & remove key_system parameters. (Closed) Base URL: master
Patch Set: rebase only Created 7 years, 6 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 "webkit/renderer/media/android/webmediaplayer_android.h" 5 #include "webkit/renderer/media/android/webmediaplayer_android.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 899 matching lines...) Expand 10 before | Expand all | Expand 10 after
910 GenerateKeyRequestInternal(key_system, init_data, init_data_length); 910 GenerateKeyRequestInternal(key_system, init_data, init_data_length);
911 ReportMediaKeyExceptionToUMA("generateKeyRequest", key_system, e); 911 ReportMediaKeyExceptionToUMA("generateKeyRequest", key_system, e);
912 return e; 912 return e;
913 } 913 }
914 914
915 WebMediaPlayer::MediaKeyException 915 WebMediaPlayer::MediaKeyException
916 WebMediaPlayerAndroid::GenerateKeyRequestInternal( 916 WebMediaPlayerAndroid::GenerateKeyRequestInternal(
917 const WebString& key_system, 917 const WebString& key_system,
918 const unsigned char* init_data, 918 const unsigned char* init_data,
919 unsigned init_data_length) { 919 unsigned init_data_length) {
920 DVLOG(1) << "generateKeyRequest: " << key_system.utf8().data() << ": "
921 << std::string(reinterpret_cast<const char*>(init_data),
922 static_cast<size_t>(init_data_length));
923
920 if (!IsSupportedKeySystem(key_system)) 924 if (!IsSupportedKeySystem(key_system))
921 return WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported; 925 return WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported;
922 926
923 // We do not support run-time switching between key systems for now. 927 // We do not support run-time switching between key systems for now.
924 if (current_key_system_.isEmpty()) 928 if (current_key_system_.isEmpty()) {
929 #if defined(GOOGLE_TV)
930 if (!decryptor_->InitializeCDM(key_system.utf8()))
931 return WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported;
932 #endif // defined(GOOGLE_TV
925 current_key_system_ = key_system; 933 current_key_system_ = key_system;
926 else if (key_system != current_key_system_) 934 }
935 else if (key_system != current_key_system_) {
927 return WebMediaPlayer::MediaKeyExceptionInvalidPlayerState; 936 return WebMediaPlayer::MediaKeyExceptionInvalidPlayerState;
928 937 }
929 DVLOG(1) << "generateKeyRequest: " << key_system.utf8().data() << ": "
930 << std::string(reinterpret_cast<const char*>(init_data),
931 static_cast<size_t>(init_data_length));
932 938
933 #if defined(GOOGLE_TV) 939 #if defined(GOOGLE_TV)
934 // TODO(xhwang): We assume all streams are from the same container (thus have 940 // TODO(xhwang): We assume all streams are from the same container (thus have
935 // the same "type") for now. In the future, the "type" should be passed down 941 // the same "type") for now. In the future, the "type" should be passed down
936 // from the application. 942 // from the application.
937 if (!decryptor_->GenerateKeyRequest(key_system.utf8(), 943 if (!decryptor_->GenerateKeyRequest(key_system.utf8(),
938 init_data_type_, 944 init_data_type_,
939 init_data, init_data_length)) { 945 init_data, init_data_length)) {
940 current_key_system_.reset(); 946 current_key_system_.reset();
941 return WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported; 947 return WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported;
942 } 948 }
943 #else 949 #else
944 proxy_->GenerateKeyRequest( 950 proxy_->GenerateKeyRequest(
945 player_id_, 951 player_id_,
946 key_system.utf8(),
947 init_data_type_, 952 init_data_type_,
948 std::vector<uint8>(init_data, init_data + init_data_length)); 953 std::vector<uint8>(init_data, init_data + init_data_length));
949 #endif // defined(GOOGLE_TV) 954 #endif // defined(GOOGLE_TV)
950 955
951 return WebMediaPlayer::MediaKeyExceptionNoError; 956 return WebMediaPlayer::MediaKeyExceptionNoError;
952 } 957 }
953 958
954 WebMediaPlayer::MediaKeyException WebMediaPlayerAndroid::addKey( 959 WebMediaPlayer::MediaKeyException WebMediaPlayerAndroid::addKey(
955 const WebString& key_system, 960 const WebString& key_system,
956 const unsigned char* key, 961 const unsigned char* key,
957 unsigned key_length, 962 unsigned key_length,
958 const unsigned char* init_data, 963 const unsigned char* init_data,
959 unsigned init_data_length, 964 unsigned init_data_length,
960 const WebString& session_id) { 965 const WebString& session_id) {
961 WebMediaPlayer::MediaKeyException e = AddKeyInternal( 966 WebMediaPlayer::MediaKeyException e = AddKeyInternal(
962 key_system, key, key_length, init_data, init_data_length, session_id); 967 key_system, key, key_length, init_data, init_data_length, session_id);
963 ReportMediaKeyExceptionToUMA("addKey", key_system, e); 968 ReportMediaKeyExceptionToUMA("addKey", key_system, e);
964 return e; 969 return e;
965 } 970 }
966 971
967 WebMediaPlayer::MediaKeyException WebMediaPlayerAndroid::AddKeyInternal( 972 WebMediaPlayer::MediaKeyException WebMediaPlayerAndroid::AddKeyInternal(
968 const WebString& key_system, 973 const WebString& key_system,
969 const unsigned char* key, 974 const unsigned char* key,
970 unsigned key_length, 975 unsigned key_length,
971 const unsigned char* init_data, 976 const unsigned char* init_data,
972 unsigned init_data_length, 977 unsigned init_data_length,
973 const WebString& session_id) { 978 const WebString& session_id) {
974 DCHECK(key); 979 DCHECK(key);
975 DCHECK_GT(key_length, 0u); 980 DCHECK_GT(key_length, 0u);
976
977 if (!IsSupportedKeySystem(key_system))
978 return WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported;
979
980 if (current_key_system_.isEmpty() || key_system != current_key_system_)
981 return WebMediaPlayer::MediaKeyExceptionInvalidPlayerState;
982
983 DVLOG(1) << "addKey: " << key_system.utf8().data() << ": " 981 DVLOG(1) << "addKey: " << key_system.utf8().data() << ": "
984 << std::string(reinterpret_cast<const char*>(key), 982 << std::string(reinterpret_cast<const char*>(key),
985 static_cast<size_t>(key_length)) << ", " 983 static_cast<size_t>(key_length)) << ", "
986 << std::string(reinterpret_cast<const char*>(init_data), 984 << std::string(reinterpret_cast<const char*>(init_data),
987 static_cast<size_t>(init_data_length)) 985 static_cast<size_t>(init_data_length))
988 << " [" << session_id.utf8().data() << "]"; 986 << " [" << session_id.utf8().data() << "]";
989 987
988 if (!IsSupportedKeySystem(key_system))
989 return WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported;
990
991 if (current_key_system_.isEmpty() || key_system != current_key_system_)
992 return WebMediaPlayer::MediaKeyExceptionInvalidPlayerState;
993
990 #if defined(GOOGLE_TV) 994 #if defined(GOOGLE_TV)
991 decryptor_->AddKey(key_system.utf8(), key, key_length, 995 decryptor_->AddKey(key, key_length, init_data, init_data_length,
992 init_data, init_data_length, session_id.utf8()); 996 session_id.utf8());
993 #else 997 #else
994 proxy_->AddKey(player_id_, 998 proxy_->AddKey(player_id_,
995 key_system.utf8(),
996 std::vector<uint8>(key, key + key_length), 999 std::vector<uint8>(key, key + key_length),
997 std::vector<uint8>(init_data, init_data + init_data_length), 1000 std::vector<uint8>(init_data, init_data + init_data_length),
998 session_id.utf8()); 1001 session_id.utf8());
999 #endif // #if defined(GOOGLE_TV) 1002 #endif // #if defined(GOOGLE_TV)
1000 1003
1001 return WebMediaPlayer::MediaKeyExceptionNoError; 1004 return WebMediaPlayer::MediaKeyExceptionNoError;
1002 } 1005 }
1003 1006
1004 WebMediaPlayer::MediaKeyException WebMediaPlayerAndroid::cancelKeyRequest( 1007 WebMediaPlayer::MediaKeyException WebMediaPlayerAndroid::cancelKeyRequest(
1005 const WebString& key_system, 1008 const WebString& key_system,
1006 const WebString& session_id) { 1009 const WebString& session_id) {
1007 WebMediaPlayer::MediaKeyException e = 1010 WebMediaPlayer::MediaKeyException e =
1008 CancelKeyRequestInternal(key_system, session_id); 1011 CancelKeyRequestInternal(key_system, session_id);
1009 ReportMediaKeyExceptionToUMA("cancelKeyRequest", key_system, e); 1012 ReportMediaKeyExceptionToUMA("cancelKeyRequest", key_system, e);
1010 return e; 1013 return e;
1011 } 1014 }
1012 1015
1013 WebMediaPlayer::MediaKeyException 1016 WebMediaPlayer::MediaKeyException
1014 WebMediaPlayerAndroid::CancelKeyRequestInternal( 1017 WebMediaPlayerAndroid::CancelKeyRequestInternal(
1015 const WebString& key_system, 1018 const WebString& key_system,
1016 const WebString& session_id) { 1019 const WebString& session_id) {
1017 if (!IsSupportedKeySystem(key_system)) 1020 if (!IsSupportedKeySystem(key_system))
1018 return WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported; 1021 return WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported;
1019 1022
1020 if (current_key_system_.isEmpty() || key_system != current_key_system_) 1023 if (current_key_system_.isEmpty() || key_system != current_key_system_)
1021 return WebMediaPlayer::MediaKeyExceptionInvalidPlayerState; 1024 return WebMediaPlayer::MediaKeyExceptionInvalidPlayerState;
1022 1025
1023 #if defined(GOOGLE_TV) 1026 #if defined(GOOGLE_TV)
1024 decryptor_->CancelKeyRequest(key_system.utf8(), session_id.utf8()); 1027 decryptor_->CancelKeyRequest(session_id.utf8());
1025 #else 1028 #else
1026 proxy_->CancelKeyRequest(player_id_, key_system.utf8(), session_id.utf8()); 1029 proxy_->CancelKeyRequest(player_id_, session_id.utf8());
1027 #endif // #if defined(GOOGLE_TV) 1030 #endif // #if defined(GOOGLE_TV)
1028 1031
1029 return WebMediaPlayer::MediaKeyExceptionNoError; 1032 return WebMediaPlayer::MediaKeyExceptionNoError;
1030 } 1033 }
1031 1034
1032 void WebMediaPlayerAndroid::OnKeyAdded(const std::string& key_system, 1035 void WebMediaPlayerAndroid::OnKeyAdded(const std::string& session_id) {
1033 const std::string& session_id) { 1036 EmeUMAHistogramCounts(current_key_system_.utf8(), "KeyAdded", 1);
1034 EmeUMAHistogramCounts(key_system, "KeyAdded", 1);
1035 1037
1036 if (media_source_delegate_) 1038 if (media_source_delegate_)
1037 media_source_delegate_->NotifyDemuxerReady(key_system); 1039 media_source_delegate_->NotifyDemuxerReady(current_key_system_.utf8());
1038 1040
1039 client_->keyAdded(WebString::fromUTF8(key_system), 1041 client_->keyAdded(current_key_system_, WebString::fromUTF8(session_id));
1040 WebString::fromUTF8(session_id));
1041 } 1042 }
1042 1043
1043 void WebMediaPlayerAndroid::OnKeyError(const std::string& key_system, 1044 void WebMediaPlayerAndroid::OnKeyError(const std::string& session_id,
1044 const std::string& session_id,
1045 media::MediaKeys::KeyError error_code, 1045 media::MediaKeys::KeyError error_code,
1046 int system_code) { 1046 int system_code) {
1047 EmeUMAHistogramEnumeration( 1047 EmeUMAHistogramEnumeration(current_key_system_.utf8(), "KeyError",
1048 key_system, "KeyError", error_code, media::MediaKeys::kMaxKeyError); 1048 error_code, media::MediaKeys::kMaxKeyError);
1049 1049
1050 client_->keyError( 1050 client_->keyError(
1051 WebString::fromUTF8(key_system), 1051 current_key_system_,
1052 WebString::fromUTF8(session_id), 1052 WebString::fromUTF8(session_id),
1053 static_cast<WebKit::WebMediaPlayerClient::MediaKeyErrorCode>(error_code), 1053 static_cast<WebKit::WebMediaPlayerClient::MediaKeyErrorCode>(error_code),
1054 system_code); 1054 system_code);
1055 } 1055 }
1056 1056
1057 void WebMediaPlayerAndroid::OnKeyMessage(const std::string& key_system, 1057 void WebMediaPlayerAndroid::OnKeyMessage(const std::string& session_id,
1058 const std::string& session_id,
1059 const std::string& message, 1058 const std::string& message,
1060 const std::string& destination_url) { 1059 const std::string& destination_url) {
1061 const GURL destination_url_gurl(destination_url); 1060 const GURL destination_url_gurl(destination_url);
1062 DLOG_IF(WARNING, !destination_url.empty() && !destination_url_gurl.is_valid()) 1061 DLOG_IF(WARNING, !destination_url.empty() && !destination_url_gurl.is_valid())
1063 << "Invalid URL in destination_url: " << destination_url; 1062 << "Invalid URL in destination_url: " << destination_url;
1064 1063
1065 client_->keyMessage(WebString::fromUTF8(key_system), 1064 client_->keyMessage(current_key_system_,
1066 WebString::fromUTF8(session_id), 1065 WebString::fromUTF8(session_id),
1067 reinterpret_cast<const uint8*>(message.data()), 1066 reinterpret_cast<const uint8*>(message.data()),
1068 message.size(), 1067 message.size(),
1069 destination_url_gurl); 1068 destination_url_gurl);
1070 } 1069 }
1071 1070
1072 void WebMediaPlayerAndroid::OnNeedKey(const std::string& key_system, 1071 void WebMediaPlayerAndroid::OnNeedKey(const std::string& session_id,
1073 const std::string& session_id,
1074 const std::string& type, 1072 const std::string& type,
1075 scoped_ptr<uint8[]> init_data, 1073 scoped_ptr<uint8[]> init_data,
1076 int init_data_size) { 1074 int init_data_size) {
1077 // Do not fire NeedKey event if encrypted media is not enabled. 1075 // Do not fire NeedKey event if encrypted media is not enabled.
1078 if (!WebKit::WebRuntimeFeatures::isEncryptedMediaEnabled() && 1076 if (!WebKit::WebRuntimeFeatures::isEncryptedMediaEnabled() &&
1079 !WebKit::WebRuntimeFeatures::isLegacyEncryptedMediaEnabled()) { 1077 !WebKit::WebRuntimeFeatures::isLegacyEncryptedMediaEnabled()) {
1080 return; 1078 return;
1081 } 1079 }
1082 1080
1083 UMA_HISTOGRAM_COUNTS(kMediaEme + std::string("NeedKey"), 1); 1081 UMA_HISTOGRAM_COUNTS(kMediaEme + std::string("NeedKey"), 1);
1084 1082
1085 DCHECK(init_data_type_.empty() || type.empty() || type == init_data_type_); 1083 DCHECK(init_data_type_.empty() || type.empty() || type == init_data_type_);
1086 if (init_data_type_.empty()) 1084 if (init_data_type_.empty())
1087 init_data_type_ = type; 1085 init_data_type_ = type;
1088 1086
1089 client_->keyNeeded(WebString::fromUTF8(key_system), 1087 client_->keyNeeded(WebString(),
1090 WebString::fromUTF8(session_id), 1088 WebString::fromUTF8(session_id),
1091 init_data.get(), 1089 init_data.get(),
1092 init_data_size); 1090 init_data_size);
1093 } 1091 }
1094 1092
1095 #if defined(GOOGLE_TV) 1093 #if defined(GOOGLE_TV)
1096 bool WebMediaPlayerAndroid::InjectMediaStream( 1094 bool WebMediaPlayerAndroid::InjectMediaStream(
1097 MediaStreamClient* media_stream_client, 1095 MediaStreamClient* media_stream_client,
1098 media::Demuxer* demuxer, 1096 media::Demuxer* demuxer,
1099 const base::Closure& destroy_demuxer_cb) { 1097 const base::Closure& destroy_demuxer_cb) {
(...skipping 22 matching lines...) Expand all
1122 1120
1123 void WebMediaPlayerAndroid::exitFullscreen() { 1121 void WebMediaPlayerAndroid::exitFullscreen() {
1124 proxy_->ExitFullscreen(player_id_); 1122 proxy_->ExitFullscreen(player_id_);
1125 } 1123 }
1126 1124
1127 bool WebMediaPlayerAndroid::canEnterFullscreen() const { 1125 bool WebMediaPlayerAndroid::canEnterFullscreen() const {
1128 return manager_->CanEnterFullscreen(frame_); 1126 return manager_->CanEnterFullscreen(frame_);
1129 } 1127 }
1130 1128
1131 } // namespace webkit_media 1129 } // namespace webkit_media
OLDNEW
« no previous file with comments | « webkit/renderer/media/android/webmediaplayer_android.h ('k') | webkit/renderer/media/android/webmediaplayer_proxy_android.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698