| OLD | NEW |
| 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 886 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 897 GenerateKeyRequestInternal(key_system, init_data, init_data_length); | 897 GenerateKeyRequestInternal(key_system, init_data, init_data_length); |
| 898 ReportMediaKeyExceptionToUMA("generateKeyRequest", key_system, e); | 898 ReportMediaKeyExceptionToUMA("generateKeyRequest", key_system, e); |
| 899 return e; | 899 return e; |
| 900 } | 900 } |
| 901 | 901 |
| 902 WebMediaPlayer::MediaKeyException | 902 WebMediaPlayer::MediaKeyException |
| 903 WebMediaPlayerAndroid::GenerateKeyRequestInternal( | 903 WebMediaPlayerAndroid::GenerateKeyRequestInternal( |
| 904 const WebString& key_system, | 904 const WebString& key_system, |
| 905 const unsigned char* init_data, | 905 const unsigned char* init_data, |
| 906 unsigned init_data_length) { | 906 unsigned init_data_length) { |
| 907 DVLOG(1) << "generateKeyRequest: " << key_system.utf8().data() << ": " |
| 908 << std::string(reinterpret_cast<const char*>(init_data), |
| 909 static_cast<size_t>(init_data_length)); |
| 910 |
| 907 if (!IsSupportedKeySystem(key_system)) | 911 if (!IsSupportedKeySystem(key_system)) |
| 908 return WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported; | 912 return WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported; |
| 909 | 913 |
| 910 // We do not support run-time switching between key systems for now. | 914 // We do not support run-time switching between key systems for now. |
| 911 if (current_key_system_.isEmpty()) | 915 if (current_key_system_.isEmpty()) { |
| 916 #if defined(GOOGLE_TV) |
| 917 if (!decryptor_->InitializeCDM(key_system.utf8())) |
| 918 return WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported; |
| 919 #endif // defined(GOOGLE_TV |
| 912 current_key_system_ = key_system; | 920 current_key_system_ = key_system; |
| 913 else if (key_system != current_key_system_) | 921 } |
| 922 else if (key_system != current_key_system_) { |
| 914 return WebMediaPlayer::MediaKeyExceptionInvalidPlayerState; | 923 return WebMediaPlayer::MediaKeyExceptionInvalidPlayerState; |
| 915 | 924 } |
| 916 DVLOG(1) << "generateKeyRequest: " << key_system.utf8().data() << ": " | |
| 917 << std::string(reinterpret_cast<const char*>(init_data), | |
| 918 static_cast<size_t>(init_data_length)); | |
| 919 | 925 |
| 920 #if defined(GOOGLE_TV) | 926 #if defined(GOOGLE_TV) |
| 921 // TODO(xhwang): We assume all streams are from the same container (thus have | 927 // TODO(xhwang): We assume all streams are from the same container (thus have |
| 922 // the same "type") for now. In the future, the "type" should be passed down | 928 // the same "type") for now. In the future, the "type" should be passed down |
| 923 // from the application. | 929 // from the application. |
| 924 if (!decryptor_->GenerateKeyRequest(key_system.utf8(), | 930 if (!decryptor_->GenerateKeyRequest(key_system.utf8(), |
| 925 init_data_type_, | 931 init_data_type_, |
| 926 init_data, init_data_length)) { | 932 init_data, init_data_length)) { |
| 927 current_key_system_.reset(); | 933 current_key_system_.reset(); |
| 928 return WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported; | 934 return WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported; |
| 929 } | 935 } |
| 930 #else | 936 #else |
| 931 proxy_->GenerateKeyRequest( | 937 proxy_->GenerateKeyRequest( |
| 932 player_id_, | 938 player_id_, |
| 933 key_system.utf8(), | |
| 934 init_data_type_, | 939 init_data_type_, |
| 935 std::vector<uint8>(init_data, init_data + init_data_length)); | 940 std::vector<uint8>(init_data, init_data + init_data_length)); |
| 936 #endif // defined(GOOGLE_TV) | 941 #endif // defined(GOOGLE_TV) |
| 937 | 942 |
| 938 return WebMediaPlayer::MediaKeyExceptionNoError; | 943 return WebMediaPlayer::MediaKeyExceptionNoError; |
| 939 } | 944 } |
| 940 | 945 |
| 941 WebMediaPlayer::MediaKeyException WebMediaPlayerAndroid::addKey( | 946 WebMediaPlayer::MediaKeyException WebMediaPlayerAndroid::addKey( |
| 942 const WebString& key_system, | 947 const WebString& key_system, |
| 943 const unsigned char* key, | 948 const unsigned char* key, |
| 944 unsigned key_length, | 949 unsigned key_length, |
| 945 const unsigned char* init_data, | 950 const unsigned char* init_data, |
| 946 unsigned init_data_length, | 951 unsigned init_data_length, |
| 947 const WebString& session_id) { | 952 const WebString& session_id) { |
| 948 WebMediaPlayer::MediaKeyException e = AddKeyInternal( | 953 WebMediaPlayer::MediaKeyException e = AddKeyInternal( |
| 949 key_system, key, key_length, init_data, init_data_length, session_id); | 954 key_system, key, key_length, init_data, init_data_length, session_id); |
| 950 ReportMediaKeyExceptionToUMA("addKey", key_system, e); | 955 ReportMediaKeyExceptionToUMA("addKey", key_system, e); |
| 951 return e; | 956 return e; |
| 952 } | 957 } |
| 953 | 958 |
| 954 WebMediaPlayer::MediaKeyException WebMediaPlayerAndroid::AddKeyInternal( | 959 WebMediaPlayer::MediaKeyException WebMediaPlayerAndroid::AddKeyInternal( |
| 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 DCHECK(key); | 966 DCHECK(key); |
| 962 DCHECK_GT(key_length, 0u); | 967 DCHECK_GT(key_length, 0u); |
| 963 | |
| 964 if (!IsSupportedKeySystem(key_system)) | |
| 965 return WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported; | |
| 966 | |
| 967 if (current_key_system_.isEmpty() || key_system != current_key_system_) | |
| 968 return WebMediaPlayer::MediaKeyExceptionInvalidPlayerState; | |
| 969 | |
| 970 DVLOG(1) << "addKey: " << key_system.utf8().data() << ": " | 968 DVLOG(1) << "addKey: " << key_system.utf8().data() << ": " |
| 971 << std::string(reinterpret_cast<const char*>(key), | 969 << std::string(reinterpret_cast<const char*>(key), |
| 972 static_cast<size_t>(key_length)) << ", " | 970 static_cast<size_t>(key_length)) << ", " |
| 973 << std::string(reinterpret_cast<const char*>(init_data), | 971 << std::string(reinterpret_cast<const char*>(init_data), |
| 974 static_cast<size_t>(init_data_length)) | 972 static_cast<size_t>(init_data_length)) |
| 975 << " [" << session_id.utf8().data() << "]"; | 973 << " [" << session_id.utf8().data() << "]"; |
| 976 | 974 |
| 975 if (!IsSupportedKeySystem(key_system)) |
| 976 return WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported; |
| 977 |
| 978 if (current_key_system_.isEmpty() || key_system != current_key_system_) |
| 979 return WebMediaPlayer::MediaKeyExceptionInvalidPlayerState; |
| 980 |
| 977 #if defined(GOOGLE_TV) | 981 #if defined(GOOGLE_TV) |
| 978 decryptor_->AddKey(key_system.utf8(), key, key_length, | 982 decryptor_->AddKey(key, key_length, init_data, init_data_length, |
| 979 init_data, init_data_length, session_id.utf8()); | 983 session_id.utf8()); |
| 980 #else | 984 #else |
| 981 proxy_->AddKey(player_id_, | 985 proxy_->AddKey(player_id_, |
| 982 key_system.utf8(), | |
| 983 std::vector<uint8>(key, key + key_length), | 986 std::vector<uint8>(key, key + key_length), |
| 984 std::vector<uint8>(init_data, init_data + init_data_length), | 987 std::vector<uint8>(init_data, init_data + init_data_length), |
| 985 session_id.utf8()); | 988 session_id.utf8()); |
| 986 #endif // #if defined(GOOGLE_TV) | 989 #endif // #if defined(GOOGLE_TV) |
| 987 | 990 |
| 988 return WebMediaPlayer::MediaKeyExceptionNoError; | 991 return WebMediaPlayer::MediaKeyExceptionNoError; |
| 989 } | 992 } |
| 990 | 993 |
| 991 WebMediaPlayer::MediaKeyException WebMediaPlayerAndroid::cancelKeyRequest( | 994 WebMediaPlayer::MediaKeyException WebMediaPlayerAndroid::cancelKeyRequest( |
| 992 const WebString& key_system, | 995 const WebString& key_system, |
| 993 const WebString& session_id) { | 996 const WebString& session_id) { |
| 994 WebMediaPlayer::MediaKeyException e = | 997 WebMediaPlayer::MediaKeyException e = |
| 995 CancelKeyRequestInternal(key_system, session_id); | 998 CancelKeyRequestInternal(key_system, session_id); |
| 996 ReportMediaKeyExceptionToUMA("cancelKeyRequest", key_system, e); | 999 ReportMediaKeyExceptionToUMA("cancelKeyRequest", key_system, e); |
| 997 return e; | 1000 return e; |
| 998 } | 1001 } |
| 999 | 1002 |
| 1000 WebMediaPlayer::MediaKeyException | 1003 WebMediaPlayer::MediaKeyException |
| 1001 WebMediaPlayerAndroid::CancelKeyRequestInternal( | 1004 WebMediaPlayerAndroid::CancelKeyRequestInternal( |
| 1002 const WebString& key_system, | 1005 const WebString& key_system, |
| 1003 const WebString& session_id) { | 1006 const WebString& session_id) { |
| 1004 if (!IsSupportedKeySystem(key_system)) | 1007 if (!IsSupportedKeySystem(key_system)) |
| 1005 return WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported; | 1008 return WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported; |
| 1006 | 1009 |
| 1007 if (current_key_system_.isEmpty() || key_system != current_key_system_) | 1010 if (current_key_system_.isEmpty() || key_system != current_key_system_) |
| 1008 return WebMediaPlayer::MediaKeyExceptionInvalidPlayerState; | 1011 return WebMediaPlayer::MediaKeyExceptionInvalidPlayerState; |
| 1009 | 1012 |
| 1010 #if defined(GOOGLE_TV) | 1013 #if defined(GOOGLE_TV) |
| 1011 decryptor_->CancelKeyRequest(key_system.utf8(), session_id.utf8()); | 1014 decryptor_->CancelKeyRequest(session_id.utf8()); |
| 1012 #else | 1015 #else |
| 1013 proxy_->CancelKeyRequest(player_id_, key_system.utf8(), session_id.utf8()); | 1016 proxy_->CancelKeyRequest(player_id_, session_id.utf8()); |
| 1014 #endif // #if defined(GOOGLE_TV) | 1017 #endif // #if defined(GOOGLE_TV) |
| 1015 | 1018 |
| 1016 return WebMediaPlayer::MediaKeyExceptionNoError; | 1019 return WebMediaPlayer::MediaKeyExceptionNoError; |
| 1017 } | 1020 } |
| 1018 | 1021 |
| 1019 void WebMediaPlayerAndroid::OnKeyAdded(const std::string& key_system, | 1022 void WebMediaPlayerAndroid::OnKeyAdded(const std::string& session_id) { |
| 1020 const std::string& session_id) { | 1023 EmeUMAHistogramCounts(current_key_system_.utf8(), "KeyAdded", 1); |
| 1021 EmeUMAHistogramCounts(key_system, "KeyAdded", 1); | |
| 1022 | 1024 |
| 1023 if (media_source_delegate_) | 1025 if (media_source_delegate_) |
| 1024 media_source_delegate_->NotifyDemuxerReady(key_system); | 1026 media_source_delegate_->NotifyDemuxerReady(current_key_system_.utf8()); |
| 1025 | 1027 |
| 1026 client_->keyAdded(WebString::fromUTF8(key_system), | 1028 client_->keyAdded(current_key_system_, WebString::fromUTF8(session_id)); |
| 1027 WebString::fromUTF8(session_id)); | |
| 1028 } | 1029 } |
| 1029 | 1030 |
| 1030 void WebMediaPlayerAndroid::OnKeyError(const std::string& key_system, | 1031 void WebMediaPlayerAndroid::OnKeyError(const std::string& session_id, |
| 1031 const std::string& session_id, | |
| 1032 media::MediaKeys::KeyError error_code, | 1032 media::MediaKeys::KeyError error_code, |
| 1033 int system_code) { | 1033 int system_code) { |
| 1034 EmeUMAHistogramEnumeration( | 1034 EmeUMAHistogramEnumeration(current_key_system_.utf8(), "KeyError", |
| 1035 key_system, "KeyError", error_code, media::MediaKeys::kMaxKeyError); | 1035 error_code, media::MediaKeys::kMaxKeyError); |
| 1036 | 1036 |
| 1037 client_->keyError( | 1037 client_->keyError( |
| 1038 WebString::fromUTF8(key_system), | 1038 current_key_system_, |
| 1039 WebString::fromUTF8(session_id), | 1039 WebString::fromUTF8(session_id), |
| 1040 static_cast<WebKit::WebMediaPlayerClient::MediaKeyErrorCode>(error_code), | 1040 static_cast<WebKit::WebMediaPlayerClient::MediaKeyErrorCode>(error_code), |
| 1041 system_code); | 1041 system_code); |
| 1042 } | 1042 } |
| 1043 | 1043 |
| 1044 void WebMediaPlayerAndroid::OnKeyMessage(const std::string& key_system, | 1044 void WebMediaPlayerAndroid::OnKeyMessage(const std::string& session_id, |
| 1045 const std::string& session_id, | |
| 1046 const std::string& message, | 1045 const std::string& message, |
| 1047 const std::string& destination_url) { | 1046 const std::string& destination_url) { |
| 1048 const GURL destination_url_gurl(destination_url); | 1047 const GURL destination_url_gurl(destination_url); |
| 1049 DLOG_IF(WARNING, !destination_url.empty() && !destination_url_gurl.is_valid()) | 1048 DLOG_IF(WARNING, !destination_url.empty() && !destination_url_gurl.is_valid()) |
| 1050 << "Invalid URL in destination_url: " << destination_url; | 1049 << "Invalid URL in destination_url: " << destination_url; |
| 1051 | 1050 |
| 1052 client_->keyMessage(WebString::fromUTF8(key_system), | 1051 client_->keyMessage(current_key_system_, |
| 1053 WebString::fromUTF8(session_id), | 1052 WebString::fromUTF8(session_id), |
| 1054 reinterpret_cast<const uint8*>(message.data()), | 1053 reinterpret_cast<const uint8*>(message.data()), |
| 1055 message.size(), | 1054 message.size(), |
| 1056 destination_url_gurl); | 1055 destination_url_gurl); |
| 1057 } | 1056 } |
| 1058 | 1057 |
| 1059 void WebMediaPlayerAndroid::OnNeedKey(const std::string& key_system, | 1058 void WebMediaPlayerAndroid::OnNeedKey(const std::string& session_id, |
| 1060 const std::string& session_id, | |
| 1061 const std::string& type, | 1059 const std::string& type, |
| 1062 scoped_ptr<uint8[]> init_data, | 1060 scoped_ptr<uint8[]> init_data, |
| 1063 int init_data_size) { | 1061 int init_data_size) { |
| 1064 // Do not fire NeedKey event if encrypted media is not enabled. | 1062 // Do not fire NeedKey event if encrypted media is not enabled. |
| 1065 if (!WebKit::WebRuntimeFeatures::isEncryptedMediaEnabled() && | 1063 if (!WebKit::WebRuntimeFeatures::isEncryptedMediaEnabled() && |
| 1066 !WebKit::WebRuntimeFeatures::isLegacyEncryptedMediaEnabled()) { | 1064 !WebKit::WebRuntimeFeatures::isLegacyEncryptedMediaEnabled()) { |
| 1067 return; | 1065 return; |
| 1068 } | 1066 } |
| 1069 | 1067 |
| 1070 UMA_HISTOGRAM_COUNTS(kMediaEme + std::string("NeedKey"), 1); | 1068 UMA_HISTOGRAM_COUNTS(kMediaEme + std::string("NeedKey"), 1); |
| 1071 | 1069 |
| 1072 DCHECK(init_data_type_.empty() || type.empty() || type == init_data_type_); | 1070 DCHECK(init_data_type_.empty() || type.empty() || type == init_data_type_); |
| 1073 if (init_data_type_.empty()) | 1071 if (init_data_type_.empty()) |
| 1074 init_data_type_ = type; | 1072 init_data_type_ = type; |
| 1075 | 1073 |
| 1076 client_->keyNeeded(WebString::fromUTF8(key_system), | 1074 client_->keyNeeded(WebString(), |
| 1077 WebString::fromUTF8(session_id), | 1075 WebString::fromUTF8(session_id), |
| 1078 init_data.get(), | 1076 init_data.get(), |
| 1079 init_data_size); | 1077 init_data_size); |
| 1080 } | 1078 } |
| 1081 | 1079 |
| 1082 #if defined(GOOGLE_TV) | 1080 #if defined(GOOGLE_TV) |
| 1083 bool WebMediaPlayerAndroid::InjectMediaStream( | 1081 bool WebMediaPlayerAndroid::InjectMediaStream( |
| 1084 MediaStreamClient* media_stream_client, | 1082 MediaStreamClient* media_stream_client, |
| 1085 media::Demuxer* demuxer, | 1083 media::Demuxer* demuxer, |
| 1086 const base::Closure& destroy_demuxer_cb) { | 1084 const base::Closure& destroy_demuxer_cb) { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1109 | 1107 |
| 1110 void WebMediaPlayerAndroid::exitFullscreen() { | 1108 void WebMediaPlayerAndroid::exitFullscreen() { |
| 1111 proxy_->ExitFullscreen(player_id_); | 1109 proxy_->ExitFullscreen(player_id_); |
| 1112 } | 1110 } |
| 1113 | 1111 |
| 1114 bool WebMediaPlayerAndroid::canEnterFullscreen() const { | 1112 bool WebMediaPlayerAndroid::canEnterFullscreen() const { |
| 1115 return manager_->CanEnterFullscreen(frame_); | 1113 return manager_->CanEnterFullscreen(frame_); |
| 1116 } | 1114 } |
| 1117 | 1115 |
| 1118 } // namespace webkit_media | 1116 } // namespace webkit_media |
| OLD | NEW |