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 "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
18 #include "cc/layers/video_layer.h" | 18 #include "cc/layers/video_layer.h" |
19 #include "content/public/common/content_client.h" | 19 #include "content/public/common/content_client.h" |
20 #include "content/public/renderer/render_frame.h" | 20 #include "content/public/renderer/render_frame.h" |
21 #include "content/renderer/media/android/proxy_media_keys.h" | |
22 #include "content/renderer/media/android/renderer_demuxer_android.h" | 21 #include "content/renderer/media/android/renderer_demuxer_android.h" |
23 #include "content/renderer/media/android/renderer_media_player_manager.h" | 22 #include "content/renderer/media/android/renderer_media_player_manager.h" |
24 #include "content/renderer/media/crypto/key_systems.h" | 23 #include "content/renderer/media/crypto/key_systems.h" |
| 24 #include "content/renderer/media/webcontentdecryptionmodule_impl.h" |
25 #include "content/renderer/media/webmediaplayer_delegate.h" | 25 #include "content/renderer/media/webmediaplayer_delegate.h" |
26 #include "content/renderer/media/webmediaplayer_util.h" | 26 #include "content/renderer/media/webmediaplayer_util.h" |
27 #include "content/renderer/render_frame_impl.h" | 27 #include "content/renderer/render_frame_impl.h" |
28 #include "content/renderer/render_thread_impl.h" | 28 #include "content/renderer/render_thread_impl.h" |
29 #include "gpu/GLES2/gl2extchromium.h" | 29 #include "gpu/GLES2/gl2extchromium.h" |
30 #include "gpu/command_buffer/client/gles2_interface.h" | 30 #include "gpu/command_buffer/client/gles2_interface.h" |
31 #include "gpu/command_buffer/common/mailbox_holder.h" | 31 #include "gpu/command_buffer/common/mailbox_holder.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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 has_media_metadata_(false), | 101 has_media_metadata_(false), |
100 has_media_info_(false), | 102 has_media_info_(false), |
101 stream_texture_factory_(factory), | 103 stream_texture_factory_(factory), |
102 needs_external_surface_(false), | 104 needs_external_surface_(false), |
103 video_frame_provider_client_(NULL), | 105 video_frame_provider_client_(NULL), |
104 pending_playback_(false), | 106 pending_playback_(false), |
105 player_type_(MEDIA_PLAYER_TYPE_URL), | 107 player_type_(MEDIA_PLAYER_TYPE_URL), |
106 current_time_(0), | 108 current_time_(0), |
107 is_remote_(false), | 109 is_remote_(false), |
108 media_log_(media_log), | 110 media_log_(media_log), |
| 111 web_cdm_(NULL), |
109 weak_factory_(this) { | 112 weak_factory_(this) { |
110 DCHECK(manager_); | 113 DCHECK(manager_); |
111 | 114 |
112 DCHECK(main_thread_checker_.CalledOnValidThread()); | 115 DCHECK(main_thread_checker_.CalledOnValidThread()); |
113 | 116 |
114 player_id_ = manager_->RegisterMediaPlayer(this); | 117 player_id_ = manager_->RegisterMediaPlayer(this); |
115 | 118 |
116 #if defined(VIDEO_HOLE) | 119 #if defined(VIDEO_HOLE) |
117 // Defer stream texture creation until we are sure it's necessary. | 120 // Defer stream texture creation until we are sure it's necessary. |
118 needs_establish_peer_ = false; | 121 needs_establish_peer_ = false; |
(...skipping 1142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1261 | 1264 |
1262 // We do not support run-time switching between key systems for now. | 1265 // We do not support run-time switching between key systems for now. |
1263 if (current_key_system_.empty()) { | 1266 if (current_key_system_.empty()) { |
1264 if (!proxy_decryptor_) { | 1267 if (!proxy_decryptor_) { |
1265 proxy_decryptor_.reset(new ProxyDecryptor( | 1268 proxy_decryptor_.reset(new ProxyDecryptor( |
1266 #if defined(ENABLE_PEPPER_CDMS) | 1269 #if defined(ENABLE_PEPPER_CDMS) |
1267 client_, | 1270 client_, |
1268 frame_, | 1271 frame_, |
1269 #else | 1272 #else |
1270 manager_, | 1273 manager_, |
1271 player_id_, // TODO(xhwang): Use cdm_id when MediaKeys are | |
1272 // separated from WebMediaPlayer. | |
1273 #endif // defined(ENABLE_PEPPER_CDMS) | 1274 #endif // defined(ENABLE_PEPPER_CDMS) |
1274 base::Bind(&WebMediaPlayerAndroid::OnKeyAdded, | 1275 base::Bind(&WebMediaPlayerAndroid::OnKeyAdded, |
1275 weak_factory_.GetWeakPtr()), | 1276 weak_factory_.GetWeakPtr()), |
1276 base::Bind(&WebMediaPlayerAndroid::OnKeyError, | 1277 base::Bind(&WebMediaPlayerAndroid::OnKeyError, |
1277 weak_factory_.GetWeakPtr()), | 1278 weak_factory_.GetWeakPtr()), |
1278 base::Bind(&WebMediaPlayerAndroid::OnKeyMessage, | 1279 base::Bind(&WebMediaPlayerAndroid::OnKeyMessage, |
1279 weak_factory_.GetWeakPtr()))); | 1280 weak_factory_.GetWeakPtr()))); |
1280 } | 1281 } |
1281 | 1282 |
1282 if (!proxy_decryptor_->InitializeCDM(key_system, | 1283 if (!proxy_decryptor_->InitializeCDM(key_system, |
1283 frame_->document().url())) { | 1284 frame_->document().url())) { |
1284 return WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported; | 1285 return WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported; |
1285 } | 1286 } |
1286 | 1287 |
1287 if (proxy_decryptor_ && !decryptor_ready_cb_.is_null()) { | 1288 if (!decryptor_ready_cb_.is_null()) { |
1288 base::ResetAndReturn(&decryptor_ready_cb_) | 1289 base::ResetAndReturn(&decryptor_ready_cb_) |
1289 .Run(proxy_decryptor_->GetDecryptor()); | 1290 .Run(proxy_decryptor_->GetDecryptor()); |
1290 } | 1291 } |
1291 | 1292 |
| 1293 manager_->SetCdm(player_id_, proxy_decryptor_->GetCdmId()); |
1292 current_key_system_ = key_system; | 1294 current_key_system_ = key_system; |
1293 } else if (key_system != current_key_system_) { | 1295 } else if (key_system != current_key_system_) { |
1294 return WebMediaPlayer::MediaKeyExceptionInvalidPlayerState; | 1296 return WebMediaPlayer::MediaKeyExceptionInvalidPlayerState; |
1295 } | 1297 } |
1296 | 1298 |
1297 std::string init_data_type = init_data_type_; | 1299 std::string init_data_type = init_data_type_; |
1298 if (init_data_type.empty()) | 1300 if (init_data_type.empty()) |
1299 init_data_type = GuessInitDataType(init_data, init_data_length); | 1301 init_data_type = GuessInitDataType(init_data, init_data_length); |
1300 | 1302 |
1301 // TODO(xhwang): We assume all streams are from the same container (thus have | 1303 // TODO(xhwang): We assume all streams are from the same container (thus have |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1381 if (!IsKeySystemSupported(key_system)) | 1383 if (!IsKeySystemSupported(key_system)) |
1382 return WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported; | 1384 return WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported; |
1383 | 1385 |
1384 if (current_key_system_.empty() || key_system != current_key_system_) | 1386 if (current_key_system_.empty() || key_system != current_key_system_) |
1385 return WebMediaPlayer::MediaKeyExceptionInvalidPlayerState; | 1387 return WebMediaPlayer::MediaKeyExceptionInvalidPlayerState; |
1386 | 1388 |
1387 proxy_decryptor_->CancelKeyRequest(session_id); | 1389 proxy_decryptor_->CancelKeyRequest(session_id); |
1388 return WebMediaPlayer::MediaKeyExceptionNoError; | 1390 return WebMediaPlayer::MediaKeyExceptionNoError; |
1389 } | 1391 } |
1390 | 1392 |
| 1393 void WebMediaPlayerAndroid::setContentDecryptionModule( |
| 1394 blink::WebContentDecryptionModule* cdm) { |
| 1395 DCHECK(main_thread_checker_.CalledOnValidThread()); |
| 1396 |
| 1397 // TODO(xhwang): Support setMediaKeys(0) if necessary: http://crbug.com/330324 |
| 1398 if (!cdm) |
| 1399 return; |
| 1400 |
| 1401 web_cdm_ = ToWebContentDecryptionModuleImpl(cdm); |
| 1402 if (!web_cdm_) |
| 1403 return; |
| 1404 |
| 1405 if (!decryptor_ready_cb_.is_null()) |
| 1406 base::ResetAndReturn(&decryptor_ready_cb_).Run(web_cdm_->GetDecryptor()); |
| 1407 |
| 1408 manager_->SetCdm(player_id_, web_cdm_->GetCdmId()); |
| 1409 } |
| 1410 |
1391 void WebMediaPlayerAndroid::OnKeyAdded(const std::string& session_id) { | 1411 void WebMediaPlayerAndroid::OnKeyAdded(const std::string& session_id) { |
1392 EmeUMAHistogramCounts(current_key_system_, "KeyAdded", 1); | 1412 EmeUMAHistogramCounts(current_key_system_, "KeyAdded", 1); |
1393 | 1413 |
1394 client_->keyAdded( | 1414 client_->keyAdded( |
1395 WebString::fromUTF8(GetPrefixedKeySystemName(current_key_system_)), | 1415 WebString::fromUTF8(GetPrefixedKeySystemName(current_key_system_)), |
1396 WebString::fromUTF8(session_id)); | 1416 WebString::fromUTF8(session_id)); |
1397 } | 1417 } |
1398 | 1418 |
1399 void WebMediaPlayerAndroid::OnKeyError(const std::string& session_id, | 1419 void WebMediaPlayerAndroid::OnKeyError(const std::string& session_id, |
1400 media::MediaKeys::KeyError error_code, | 1420 media::MediaKeys::KeyError error_code, |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1469 return; | 1489 return; |
1470 } | 1490 } |
1471 | 1491 |
1472 // TODO(xhwang): Support multiple decryptor notification request (e.g. from | 1492 // TODO(xhwang): Support multiple decryptor notification request (e.g. from |
1473 // video and audio). The current implementation is okay for the current | 1493 // video and audio). The current implementation is okay for the current |
1474 // media pipeline since we initialize audio and video decoders in sequence. | 1494 // media pipeline since we initialize audio and video decoders in sequence. |
1475 // But WebMediaPlayerImpl should not depend on media pipeline's implementation | 1495 // But WebMediaPlayerImpl should not depend on media pipeline's implementation |
1476 // detail. | 1496 // detail. |
1477 DCHECK(decryptor_ready_cb_.is_null()); | 1497 DCHECK(decryptor_ready_cb_.is_null()); |
1478 | 1498 |
| 1499 // Mixed use of prefixed and unprefixed EME APIs is disallowed by Blink. |
| 1500 DCHECK(!proxy_decryptor_ || !web_cdm_); |
| 1501 |
1479 if (proxy_decryptor_) { | 1502 if (proxy_decryptor_) { |
1480 decryptor_ready_cb.Run(proxy_decryptor_->GetDecryptor()); | 1503 decryptor_ready_cb.Run(proxy_decryptor_->GetDecryptor()); |
1481 return; | 1504 return; |
1482 } | 1505 } |
1483 | 1506 |
1484 // TODO(xhwang): Also notify |web_cdm_| when we implement | 1507 if (web_cdm_) { |
1485 // setContentDecryptionModule(). See: http://crbug.com/224786 | 1508 decryptor_ready_cb.Run(web_cdm_->GetDecryptor()); |
| 1509 return; |
| 1510 } |
1486 | 1511 |
1487 decryptor_ready_cb_ = decryptor_ready_cb; | 1512 decryptor_ready_cb_ = decryptor_ready_cb; |
1488 } | 1513 } |
1489 | 1514 |
1490 void WebMediaPlayerAndroid::DoReleaseRemotePlaybackTexture( | 1515 void WebMediaPlayerAndroid::DoReleaseRemotePlaybackTexture( |
1491 scoped_ptr<gpu::MailboxHolder> mailbox_holder) { | 1516 scoped_ptr<gpu::MailboxHolder> mailbox_holder) { |
1492 DCHECK(main_thread_checker_.CalledOnValidThread()); | 1517 DCHECK(main_thread_checker_.CalledOnValidThread()); |
1493 DCHECK(remote_playback_texture_id_); | 1518 DCHECK(remote_playback_texture_id_); |
1494 | 1519 |
1495 GLES2Interface* gl = stream_texture_factory_->ContextGL(); | 1520 GLES2Interface* gl = stream_texture_factory_->ContextGL(); |
(...skipping 13 matching lines...) Expand all Loading... |
1509 | 1534 |
1510 void WebMediaPlayerAndroid::exitFullscreen() { | 1535 void WebMediaPlayerAndroid::exitFullscreen() { |
1511 manager_->ExitFullscreen(player_id_); | 1536 manager_->ExitFullscreen(player_id_); |
1512 } | 1537 } |
1513 | 1538 |
1514 bool WebMediaPlayerAndroid::canEnterFullscreen() const { | 1539 bool WebMediaPlayerAndroid::canEnterFullscreen() const { |
1515 return manager_->CanEnterFullscreen(frame_); | 1540 return manager_->CanEnterFullscreen(frame_); |
1516 } | 1541 } |
1517 | 1542 |
1518 } // namespace content | 1543 } // namespace content |
OLD | NEW |