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 "content/renderer/media/android/webmediaplayer_android.h" | 5 #include "content/renderer/media/android/webmediaplayer_android.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
15 #include "base/metrics/histogram.h" | 15 #include "base/metrics/histogram.h" |
16 #include "base/strings/string_number_conversions.h" | 16 #include "base/strings/string_number_conversions.h" |
17 #include "cc/layers/video_layer.h" | 17 #include "cc/layers/video_layer.h" |
18 #include "content/public/common/content_client.h" | 18 #include "content/public/common/content_client.h" |
19 #include "content/public/renderer/render_frame.h" | 19 #include "content/public/renderer/render_frame.h" |
20 #include "content/renderer/media/android/proxy_media_keys.h" | |
21 #include "content/renderer/media/android/renderer_demuxer_android.h" | 20 #include "content/renderer/media/android/renderer_demuxer_android.h" |
22 #include "content/renderer/media/android/renderer_media_player_manager.h" | 21 #include "content/renderer/media/android/renderer_media_player_manager.h" |
23 #include "content/renderer/media/crypto/key_systems.h" | 22 #include "content/renderer/media/crypto/key_systems.h" |
| 23 #include "content/renderer/media/webcontentdecryptionmodule_impl.h" |
24 #include "content/renderer/media/webmediaplayer_delegate.h" | 24 #include "content/renderer/media/webmediaplayer_delegate.h" |
25 #include "content/renderer/media/webmediaplayer_util.h" | 25 #include "content/renderer/media/webmediaplayer_util.h" |
26 #include "content/renderer/render_frame_impl.h" | 26 #include "content/renderer/render_frame_impl.h" |
27 #include "content/renderer/render_thread_impl.h" | 27 #include "content/renderer/render_thread_impl.h" |
28 #include "gpu/GLES2/gl2extchromium.h" | 28 #include "gpu/GLES2/gl2extchromium.h" |
29 #include "gpu/command_buffer/client/gles2_interface.h" | 29 #include "gpu/command_buffer/client/gles2_interface.h" |
30 #include "gpu/command_buffer/common/mailbox_holder.h" | 30 #include "gpu/command_buffer/common/mailbox_holder.h" |
31 #include "grit/content_resources.h" | 31 #include "grit/content_resources.h" |
32 #include "media/base/android/media_player_android.h" | 32 #include "media/base/android/media_player_android.h" |
33 #include "media/base/bind_to_current_loop.h" | 33 #include "media/base/bind_to_current_loop.h" |
| 34 // TODO(xhwang): Remove when we remove prefixed EME implementation. |
| 35 #include "media/base/media_keys.h" |
34 #include "media/base/media_switches.h" | 36 #include "media/base/media_switches.h" |
35 #include "media/base/video_frame.h" | 37 #include "media/base/video_frame.h" |
36 #include "net/base/mime_util.h" | 38 #include "net/base/mime_util.h" |
37 #include "third_party/WebKit/public/platform/WebMediaPlayerClient.h" | 39 #include "third_party/WebKit/public/platform/WebMediaPlayerClient.h" |
38 #include "third_party/WebKit/public/platform/WebString.h" | 40 #include "third_party/WebKit/public/platform/WebString.h" |
39 #include "third_party/WebKit/public/platform/WebURL.h" | 41 #include "third_party/WebKit/public/platform/WebURL.h" |
40 #include "third_party/WebKit/public/web/WebDocument.h" | 42 #include "third_party/WebKit/public/web/WebDocument.h" |
41 #include "third_party/WebKit/public/web/WebFrame.h" | 43 #include "third_party/WebKit/public/web/WebFrame.h" |
42 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" | 44 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" |
43 #include "third_party/WebKit/public/web/WebView.h" | 45 #include "third_party/WebKit/public/web/WebView.h" |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 has_media_metadata_(false), | 113 has_media_metadata_(false), |
112 has_media_info_(false), | 114 has_media_info_(false), |
113 stream_texture_factory_(factory), | 115 stream_texture_factory_(factory), |
114 needs_external_surface_(false), | 116 needs_external_surface_(false), |
115 video_frame_provider_client_(NULL), | 117 video_frame_provider_client_(NULL), |
116 pending_playback_(false), | 118 pending_playback_(false), |
117 player_type_(MEDIA_PLAYER_TYPE_URL), | 119 player_type_(MEDIA_PLAYER_TYPE_URL), |
118 current_time_(0), | 120 current_time_(0), |
119 is_remote_(false), | 121 is_remote_(false), |
120 media_log_(media_log), | 122 media_log_(media_log), |
| 123 web_cdm_(NULL), |
121 weak_factory_(this) { | 124 weak_factory_(this) { |
122 DCHECK(manager_); | 125 DCHECK(manager_); |
123 | 126 |
124 DCHECK(main_thread_checker_.CalledOnValidThread()); | 127 DCHECK(main_thread_checker_.CalledOnValidThread()); |
125 | 128 |
126 player_id_ = manager_->RegisterMediaPlayer(this); | 129 player_id_ = manager_->RegisterMediaPlayer(this); |
127 | 130 |
128 #if defined(VIDEO_HOLE) | 131 #if defined(VIDEO_HOLE) |
129 // Defer stream texture creation until we are sure it's necessary. | 132 // Defer stream texture creation until we are sure it's necessary. |
130 needs_establish_peer_ = false; | 133 needs_establish_peer_ = false; |
(...skipping 1068 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1199 | 1202 |
1200 // We do not support run-time switching between key systems for now. | 1203 // We do not support run-time switching between key systems for now. |
1201 if (current_key_system_.empty()) { | 1204 if (current_key_system_.empty()) { |
1202 if (!proxy_decryptor_) { | 1205 if (!proxy_decryptor_) { |
1203 proxy_decryptor_.reset(new ProxyDecryptor( | 1206 proxy_decryptor_.reset(new ProxyDecryptor( |
1204 #if defined(ENABLE_PEPPER_CDMS) | 1207 #if defined(ENABLE_PEPPER_CDMS) |
1205 client_, | 1208 client_, |
1206 frame_, | 1209 frame_, |
1207 #else | 1210 #else |
1208 manager_, | 1211 manager_, |
1209 player_id_, // TODO(xhwang): Use cdm_id when MediaKeys are | |
1210 // separated from WebMediaPlayer. | |
1211 #endif // defined(ENABLE_PEPPER_CDMS) | 1212 #endif // defined(ENABLE_PEPPER_CDMS) |
1212 base::Bind(&WebMediaPlayerAndroid::OnKeyAdded, | 1213 base::Bind(&WebMediaPlayerAndroid::OnKeyAdded, |
1213 weak_factory_.GetWeakPtr()), | 1214 weak_factory_.GetWeakPtr()), |
1214 base::Bind(&WebMediaPlayerAndroid::OnKeyError, | 1215 base::Bind(&WebMediaPlayerAndroid::OnKeyError, |
1215 weak_factory_.GetWeakPtr()), | 1216 weak_factory_.GetWeakPtr()), |
1216 base::Bind(&WebMediaPlayerAndroid::OnKeyMessage, | 1217 base::Bind(&WebMediaPlayerAndroid::OnKeyMessage, |
1217 weak_factory_.GetWeakPtr()))); | 1218 weak_factory_.GetWeakPtr()))); |
1218 } | 1219 } |
1219 | 1220 |
1220 if (!proxy_decryptor_->InitializeCDM(key_system, | 1221 if (!proxy_decryptor_->InitializeCDM(key_system, |
1221 frame_->document().url())) { | 1222 frame_->document().url())) { |
1222 return WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported; | 1223 return WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported; |
1223 } | 1224 } |
1224 | 1225 |
1225 if (proxy_decryptor_ && !decryptor_ready_cb_.is_null()) { | 1226 if (!decryptor_ready_cb_.is_null()) { |
1226 base::ResetAndReturn(&decryptor_ready_cb_) | 1227 base::ResetAndReturn(&decryptor_ready_cb_) |
1227 .Run(proxy_decryptor_->GetDecryptor()); | 1228 .Run(proxy_decryptor_->GetDecryptor()); |
1228 } | 1229 } |
1229 | 1230 |
| 1231 manager_->SetCdm(player_id_, proxy_decryptor_->GetCdmId()); |
1230 current_key_system_ = key_system; | 1232 current_key_system_ = key_system; |
1231 } else if (key_system != current_key_system_) { | 1233 } else if (key_system != current_key_system_) { |
1232 return WebMediaPlayer::MediaKeyExceptionInvalidPlayerState; | 1234 return WebMediaPlayer::MediaKeyExceptionInvalidPlayerState; |
1233 } | 1235 } |
1234 | 1236 |
1235 // TODO(xhwang): We assume all streams are from the same container (thus have | 1237 // TODO(xhwang): We assume all streams are from the same container (thus have |
1236 // the same "type") for now. In the future, the "type" should be passed down | 1238 // the same "type") for now. In the future, the "type" should be passed down |
1237 // from the application. | 1239 // from the application. |
1238 if (!proxy_decryptor_->GenerateKeyRequest( | 1240 if (!proxy_decryptor_->GenerateKeyRequest( |
1239 init_data_type_, init_data, init_data_length)) { | 1241 init_data_type_, init_data, init_data_length)) { |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1315 if (!IsKeySystemSupported(key_system)) | 1317 if (!IsKeySystemSupported(key_system)) |
1316 return WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported; | 1318 return WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported; |
1317 | 1319 |
1318 if (current_key_system_.empty() || key_system != current_key_system_) | 1320 if (current_key_system_.empty() || key_system != current_key_system_) |
1319 return WebMediaPlayer::MediaKeyExceptionInvalidPlayerState; | 1321 return WebMediaPlayer::MediaKeyExceptionInvalidPlayerState; |
1320 | 1322 |
1321 proxy_decryptor_->CancelKeyRequest(session_id); | 1323 proxy_decryptor_->CancelKeyRequest(session_id); |
1322 return WebMediaPlayer::MediaKeyExceptionNoError; | 1324 return WebMediaPlayer::MediaKeyExceptionNoError; |
1323 } | 1325 } |
1324 | 1326 |
| 1327 void WebMediaPlayerAndroid::setContentDecryptionModule( |
| 1328 blink::WebContentDecryptionModule* cdm) { |
| 1329 DCHECK(main_loop_->BelongsToCurrentThread()); |
| 1330 |
| 1331 // TODO(xhwang): Support setMediaKeys(0) if necessary: http://crbug.com/330324 |
| 1332 if (!cdm) |
| 1333 return; |
| 1334 |
| 1335 web_cdm_ = ToWebContentDecryptionModuleImpl(cdm); |
| 1336 if (!web_cdm_) |
| 1337 return; |
| 1338 |
| 1339 if (!decryptor_ready_cb_.is_null()) |
| 1340 base::ResetAndReturn(&decryptor_ready_cb_).Run(web_cdm_->GetDecryptor()); |
| 1341 |
| 1342 manager_->SetCdm(player_id_, web_cdm_->GetCdmId()); |
| 1343 } |
| 1344 |
1325 void WebMediaPlayerAndroid::OnKeyAdded(const std::string& session_id) { | 1345 void WebMediaPlayerAndroid::OnKeyAdded(const std::string& session_id) { |
1326 EmeUMAHistogramCounts(current_key_system_, "KeyAdded", 1); | 1346 EmeUMAHistogramCounts(current_key_system_, "KeyAdded", 1); |
1327 | 1347 |
1328 client_->keyAdded( | 1348 client_->keyAdded( |
1329 WebString::fromUTF8(GetPrefixedKeySystemName(current_key_system_)), | 1349 WebString::fromUTF8(GetPrefixedKeySystemName(current_key_system_)), |
1330 WebString::fromUTF8(session_id)); | 1350 WebString::fromUTF8(session_id)); |
1331 } | 1351 } |
1332 | 1352 |
1333 void WebMediaPlayerAndroid::OnKeyError(const std::string& session_id, | 1353 void WebMediaPlayerAndroid::OnKeyError(const std::string& session_id, |
1334 media::MediaKeys::KeyError error_code, | 1354 media::MediaKeys::KeyError error_code, |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1403 return; | 1423 return; |
1404 } | 1424 } |
1405 | 1425 |
1406 // TODO(xhwang): Support multiple decryptor notification request (e.g. from | 1426 // TODO(xhwang): Support multiple decryptor notification request (e.g. from |
1407 // video and audio). The current implementation is okay for the current | 1427 // video and audio). The current implementation is okay for the current |
1408 // media pipeline since we initialize audio and video decoders in sequence. | 1428 // media pipeline since we initialize audio and video decoders in sequence. |
1409 // But WebMediaPlayerImpl should not depend on media pipeline's implementation | 1429 // But WebMediaPlayerImpl should not depend on media pipeline's implementation |
1410 // detail. | 1430 // detail. |
1411 DCHECK(decryptor_ready_cb_.is_null()); | 1431 DCHECK(decryptor_ready_cb_.is_null()); |
1412 | 1432 |
| 1433 // Mixed use of prefixed and unprefixed EME APIs is disallowed by Blink. |
| 1434 DCHECK(!proxy_decryptor_ || !web_cdm_); |
| 1435 |
1413 if (proxy_decryptor_) { | 1436 if (proxy_decryptor_) { |
1414 decryptor_ready_cb.Run(proxy_decryptor_->GetDecryptor()); | 1437 decryptor_ready_cb.Run(proxy_decryptor_->GetDecryptor()); |
1415 return; | 1438 return; |
1416 } | 1439 } |
1417 | 1440 |
1418 // TODO(xhwang): Also notify |web_cdm_| when we implement | 1441 if (web_cdm_) { |
1419 // setContentDecryptionModule(). See: http://crbug.com/224786 | 1442 decryptor_ready_cb.Run(web_cdm_->GetDecryptor()); |
| 1443 return; |
| 1444 } |
1420 | 1445 |
1421 decryptor_ready_cb_ = decryptor_ready_cb; | 1446 decryptor_ready_cb_ = decryptor_ready_cb; |
1422 } | 1447 } |
1423 | 1448 |
1424 void WebMediaPlayerAndroid::DoReleaseRemotePlaybackTexture(uint32 sync_point) { | 1449 void WebMediaPlayerAndroid::DoReleaseRemotePlaybackTexture(uint32 sync_point) { |
1425 DCHECK(main_thread_checker_.CalledOnValidThread()); | 1450 DCHECK(main_thread_checker_.CalledOnValidThread()); |
1426 DCHECK(remote_playback_texture_id_); | 1451 DCHECK(remote_playback_texture_id_); |
1427 | 1452 |
1428 GLES2Interface* gl = stream_texture_factory_->ContextGL(); | 1453 GLES2Interface* gl = stream_texture_factory_->ContextGL(); |
1429 | 1454 |
(...skipping 12 matching lines...) Expand all Loading... |
1442 | 1467 |
1443 void WebMediaPlayerAndroid::exitFullscreen() { | 1468 void WebMediaPlayerAndroid::exitFullscreen() { |
1444 manager_->ExitFullscreen(player_id_); | 1469 manager_->ExitFullscreen(player_id_); |
1445 } | 1470 } |
1446 | 1471 |
1447 bool WebMediaPlayerAndroid::canEnterFullscreen() const { | 1472 bool WebMediaPlayerAndroid::canEnterFullscreen() const { |
1448 return manager_->CanEnterFullscreen(frame_); | 1473 return manager_->CanEnterFullscreen(frame_); |
1449 } | 1474 } |
1450 | 1475 |
1451 } // namespace content | 1476 } // namespace content |
OLD | NEW |