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 1121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1240 | 1243 |
1241 // We do not support run-time switching between key systems for now. | 1244 // We do not support run-time switching between key systems for now. |
1242 if (current_key_system_.empty()) { | 1245 if (current_key_system_.empty()) { |
1243 if (!proxy_decryptor_) { | 1246 if (!proxy_decryptor_) { |
1244 proxy_decryptor_.reset(new ProxyDecryptor( | 1247 proxy_decryptor_.reset(new ProxyDecryptor( |
1245 #if defined(ENABLE_PEPPER_CDMS) | 1248 #if defined(ENABLE_PEPPER_CDMS) |
1246 client_, | 1249 client_, |
1247 frame_, | 1250 frame_, |
1248 #else | 1251 #else |
1249 manager_, | 1252 manager_, |
1250 player_id_, // TODO(xhwang): Use cdm_id when MediaKeys are | |
1251 // separated from WebMediaPlayer. | |
1252 #endif // defined(ENABLE_PEPPER_CDMS) | 1253 #endif // defined(ENABLE_PEPPER_CDMS) |
1253 base::Bind(&WebMediaPlayerAndroid::OnKeyAdded, | 1254 base::Bind(&WebMediaPlayerAndroid::OnKeyAdded, |
1254 weak_factory_.GetWeakPtr()), | 1255 weak_factory_.GetWeakPtr()), |
1255 base::Bind(&WebMediaPlayerAndroid::OnKeyError, | 1256 base::Bind(&WebMediaPlayerAndroid::OnKeyError, |
1256 weak_factory_.GetWeakPtr()), | 1257 weak_factory_.GetWeakPtr()), |
1257 base::Bind(&WebMediaPlayerAndroid::OnKeyMessage, | 1258 base::Bind(&WebMediaPlayerAndroid::OnKeyMessage, |
1258 weak_factory_.GetWeakPtr()))); | 1259 weak_factory_.GetWeakPtr()))); |
1259 } | 1260 } |
1260 | 1261 |
1261 if (!proxy_decryptor_->InitializeCDM(key_system, | 1262 if (!proxy_decryptor_->InitializeCDM(key_system, |
1262 frame_->document().url())) { | 1263 frame_->document().url())) { |
1263 return WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported; | 1264 return WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported; |
1264 } | 1265 } |
1265 | 1266 |
1266 if (proxy_decryptor_ && !decryptor_ready_cb_.is_null()) { | 1267 if (!decryptor_ready_cb_.is_null()) { |
1267 base::ResetAndReturn(&decryptor_ready_cb_) | 1268 base::ResetAndReturn(&decryptor_ready_cb_) |
1268 .Run(proxy_decryptor_->GetDecryptor()); | 1269 .Run(proxy_decryptor_->GetDecryptor()); |
1269 } | 1270 } |
1270 | 1271 |
1272 manager_->SetCdm(player_id_, proxy_decryptor_->GetCdmId()); | |
ddorwin
2014/03/25 23:03:59
As mentioned before, It seems odd that we make thi
xhwang
2014/03/26 06:02:04
As mentioned earlier, if we check GetCdmId() befor
ddorwin
2014/03/26 19:25:59
Does this mean we'd move kInvalidCdmId up the stac
xhwang
2014/03/27 19:07:42
Added TODO in RMPM.
| |
1271 current_key_system_ = key_system; | 1273 current_key_system_ = key_system; |
1272 } else if (key_system != current_key_system_) { | 1274 } else if (key_system != current_key_system_) { |
1273 return WebMediaPlayer::MediaKeyExceptionInvalidPlayerState; | 1275 return WebMediaPlayer::MediaKeyExceptionInvalidPlayerState; |
1274 } | 1276 } |
1275 | 1277 |
1276 std::string init_data_type = init_data_type_; | 1278 std::string init_data_type = init_data_type_; |
1277 if (init_data_type.empty()) | 1279 if (init_data_type.empty()) |
1278 init_data_type = GuessInitDataType(init_data, init_data_length); | 1280 init_data_type = GuessInitDataType(init_data, init_data_length); |
1279 | 1281 |
1280 // TODO(xhwang): We assume all streams are from the same container (thus have | 1282 // 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... | |
1360 if (!IsKeySystemSupported(key_system)) | 1362 if (!IsKeySystemSupported(key_system)) |
1361 return WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported; | 1363 return WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported; |
1362 | 1364 |
1363 if (current_key_system_.empty() || key_system != current_key_system_) | 1365 if (current_key_system_.empty() || key_system != current_key_system_) |
1364 return WebMediaPlayer::MediaKeyExceptionInvalidPlayerState; | 1366 return WebMediaPlayer::MediaKeyExceptionInvalidPlayerState; |
1365 | 1367 |
1366 proxy_decryptor_->CancelKeyRequest(session_id); | 1368 proxy_decryptor_->CancelKeyRequest(session_id); |
1367 return WebMediaPlayer::MediaKeyExceptionNoError; | 1369 return WebMediaPlayer::MediaKeyExceptionNoError; |
1368 } | 1370 } |
1369 | 1371 |
1372 void WebMediaPlayerAndroid::setContentDecryptionModule( | |
1373 blink::WebContentDecryptionModule* cdm) { | |
ddorwin
2014/03/25 23:03:59
Why was DCHECK(main_loop_->BelongsToCurrentThread(
xhwang
2014/03/26 06:02:04
Because main_loop_ doesn't exist any more after re
| |
1374 // TODO(xhwang): Support setMediaKeys(0) if necessary: http://crbug.com/330324 | |
1375 if (!cdm) | |
1376 return; | |
1377 | |
1378 web_cdm_ = ToWebContentDecryptionModuleImpl(cdm); | |
1379 if (!web_cdm_) | |
1380 return; | |
1381 | |
1382 if (!decryptor_ready_cb_.is_null()) | |
1383 base::ResetAndReturn(&decryptor_ready_cb_).Run(web_cdm_->GetDecryptor()); | |
1384 | |
1385 manager_->SetCdm(player_id_, web_cdm_->GetCdmId()); | |
ddorwin
2014/03/25 23:03:59
Ditto from l1272, though we don't have an abstract
xhwang
2014/03/26 06:02:04
For Clear Key, GetCdmId is kInvalidCdmId and hence
| |
1386 } | |
1387 | |
1370 void WebMediaPlayerAndroid::OnKeyAdded(const std::string& session_id) { | 1388 void WebMediaPlayerAndroid::OnKeyAdded(const std::string& session_id) { |
1371 EmeUMAHistogramCounts(current_key_system_, "KeyAdded", 1); | 1389 EmeUMAHistogramCounts(current_key_system_, "KeyAdded", 1); |
1372 | 1390 |
1373 client_->keyAdded( | 1391 client_->keyAdded( |
1374 WebString::fromUTF8(GetPrefixedKeySystemName(current_key_system_)), | 1392 WebString::fromUTF8(GetPrefixedKeySystemName(current_key_system_)), |
1375 WebString::fromUTF8(session_id)); | 1393 WebString::fromUTF8(session_id)); |
1376 } | 1394 } |
1377 | 1395 |
1378 void WebMediaPlayerAndroid::OnKeyError(const std::string& session_id, | 1396 void WebMediaPlayerAndroid::OnKeyError(const std::string& session_id, |
1379 media::MediaKeys::KeyError error_code, | 1397 media::MediaKeys::KeyError error_code, |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1448 return; | 1466 return; |
1449 } | 1467 } |
1450 | 1468 |
1451 // TODO(xhwang): Support multiple decryptor notification request (e.g. from | 1469 // TODO(xhwang): Support multiple decryptor notification request (e.g. from |
1452 // video and audio). The current implementation is okay for the current | 1470 // video and audio). The current implementation is okay for the current |
1453 // media pipeline since we initialize audio and video decoders in sequence. | 1471 // media pipeline since we initialize audio and video decoders in sequence. |
1454 // But WebMediaPlayerImpl should not depend on media pipeline's implementation | 1472 // But WebMediaPlayerImpl should not depend on media pipeline's implementation |
1455 // detail. | 1473 // detail. |
1456 DCHECK(decryptor_ready_cb_.is_null()); | 1474 DCHECK(decryptor_ready_cb_.is_null()); |
1457 | 1475 |
1476 // Mixed use of prefixed and unprefixed EME APIs is disallowed by Blink. | |
1477 DCHECK(!proxy_decryptor_ || !web_cdm_); | |
1478 | |
1458 if (proxy_decryptor_) { | 1479 if (proxy_decryptor_) { |
1459 decryptor_ready_cb.Run(proxy_decryptor_->GetDecryptor()); | 1480 decryptor_ready_cb.Run(proxy_decryptor_->GetDecryptor()); |
1460 return; | 1481 return; |
1461 } | 1482 } |
1462 | 1483 |
1463 // TODO(xhwang): Also notify |web_cdm_| when we implement | 1484 if (web_cdm_) { |
1464 // setContentDecryptionModule(). See: http://crbug.com/224786 | 1485 decryptor_ready_cb.Run(web_cdm_->GetDecryptor()); |
1486 return; | |
1487 } | |
1465 | 1488 |
1466 decryptor_ready_cb_ = decryptor_ready_cb; | 1489 decryptor_ready_cb_ = decryptor_ready_cb; |
1467 } | 1490 } |
1468 | 1491 |
1469 void WebMediaPlayerAndroid::DoReleaseRemotePlaybackTexture( | 1492 void WebMediaPlayerAndroid::DoReleaseRemotePlaybackTexture( |
1470 scoped_ptr<gpu::MailboxHolder> mailbox_holder) { | 1493 scoped_ptr<gpu::MailboxHolder> mailbox_holder) { |
1471 DCHECK(main_thread_checker_.CalledOnValidThread()); | 1494 DCHECK(main_thread_checker_.CalledOnValidThread()); |
1472 DCHECK(remote_playback_texture_id_); | 1495 DCHECK(remote_playback_texture_id_); |
1473 | 1496 |
1474 GLES2Interface* gl = stream_texture_factory_->ContextGL(); | 1497 GLES2Interface* gl = stream_texture_factory_->ContextGL(); |
(...skipping 13 matching lines...) Expand all Loading... | |
1488 | 1511 |
1489 void WebMediaPlayerAndroid::exitFullscreen() { | 1512 void WebMediaPlayerAndroid::exitFullscreen() { |
1490 manager_->ExitFullscreen(player_id_); | 1513 manager_->ExitFullscreen(player_id_); |
1491 } | 1514 } |
1492 | 1515 |
1493 bool WebMediaPlayerAndroid::canEnterFullscreen() const { | 1516 bool WebMediaPlayerAndroid::canEnterFullscreen() const { |
1494 return manager_->CanEnterFullscreen(frame_); | 1517 return manager_->CanEnterFullscreen(frame_); |
1495 } | 1518 } |
1496 | 1519 |
1497 } // namespace content | 1520 } // namespace content |
OLD | NEW |