Chromium Code Reviews| 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/webmediaplayer_impl.h" | 5 #include "content/renderer/media/webmediaplayer_impl.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <limits> | 8 #include <limits> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 54 #include "media/filters/chunk_demuxer.h" | 54 #include "media/filters/chunk_demuxer.h" |
| 55 #include "media/filters/ffmpeg_audio_decoder.h" | 55 #include "media/filters/ffmpeg_audio_decoder.h" |
| 56 #include "media/filters/ffmpeg_demuxer.h" | 56 #include "media/filters/ffmpeg_demuxer.h" |
| 57 #include "media/filters/ffmpeg_video_decoder.h" | 57 #include "media/filters/ffmpeg_video_decoder.h" |
| 58 #include "media/filters/gpu_video_accelerator_factories.h" | 58 #include "media/filters/gpu_video_accelerator_factories.h" |
| 59 #include "media/filters/gpu_video_decoder.h" | 59 #include "media/filters/gpu_video_decoder.h" |
| 60 #include "media/filters/opus_audio_decoder.h" | 60 #include "media/filters/opus_audio_decoder.h" |
| 61 #include "media/filters/video_renderer_impl.h" | 61 #include "media/filters/video_renderer_impl.h" |
| 62 #include "media/filters/vpx_video_decoder.h" | 62 #include "media/filters/vpx_video_decoder.h" |
| 63 #include "third_party/WebKit/public/platform/WebContentDecryptionModule.h" | 63 #include "third_party/WebKit/public/platform/WebContentDecryptionModule.h" |
| 64 #include "third_party/WebKit/public/platform/WebContentDecryptionModuleResult.h" | |
| 64 #include "third_party/WebKit/public/platform/WebMediaSource.h" | 65 #include "third_party/WebKit/public/platform/WebMediaSource.h" |
| 65 #include "third_party/WebKit/public/platform/WebRect.h" | 66 #include "third_party/WebKit/public/platform/WebRect.h" |
| 66 #include "third_party/WebKit/public/platform/WebSize.h" | 67 #include "third_party/WebKit/public/platform/WebSize.h" |
| 67 #include "third_party/WebKit/public/platform/WebString.h" | 68 #include "third_party/WebKit/public/platform/WebString.h" |
| 68 #include "third_party/WebKit/public/platform/WebURL.h" | 69 #include "third_party/WebKit/public/platform/WebURL.h" |
| 69 #include "third_party/WebKit/public/web/WebDocument.h" | 70 #include "third_party/WebKit/public/web/WebDocument.h" |
| 70 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 71 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
| 71 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" | 72 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" |
| 72 #include "third_party/WebKit/public/web/WebSecurityOrigin.h" | 73 #include "third_party/WebKit/public/web/WebSecurityOrigin.h" |
| 73 #include "third_party/WebKit/public/web/WebView.h" | 74 #include "third_party/WebKit/public/web/WebView.h" |
| (...skipping 702 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 776 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnKeyError), | 777 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnKeyError), |
| 777 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnKeyMessage))); | 778 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnKeyMessage))); |
| 778 } | 779 } |
| 779 | 780 |
| 780 GURL security_origin(frame_->document().securityOrigin().toString()); | 781 GURL security_origin(frame_->document().securityOrigin().toString()); |
| 781 if (!proxy_decryptor_->InitializeCDM(key_system, security_origin)) | 782 if (!proxy_decryptor_->InitializeCDM(key_system, security_origin)) |
| 782 return WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported; | 783 return WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported; |
| 783 | 784 |
| 784 if (proxy_decryptor_ && !decryptor_ready_cb_.is_null()) { | 785 if (proxy_decryptor_ && !decryptor_ready_cb_.is_null()) { |
| 785 base::ResetAndReturn(&decryptor_ready_cb_) | 786 base::ResetAndReturn(&decryptor_ready_cb_) |
| 786 .Run(proxy_decryptor_->GetDecryptor()); | 787 .Run(proxy_decryptor_->GetDecryptor(), base::Bind(&base::DoNothing)); |
| 787 } | 788 } |
| 788 | 789 |
| 789 current_key_system_ = key_system; | 790 current_key_system_ = key_system; |
| 790 } else if (key_system != current_key_system_) { | 791 } else if (key_system != current_key_system_) { |
| 791 return WebMediaPlayer::MediaKeyExceptionInvalidPlayerState; | 792 return WebMediaPlayer::MediaKeyExceptionInvalidPlayerState; |
| 792 } | 793 } |
| 793 | 794 |
| 794 std::string init_data_type = init_data_type_; | 795 std::string init_data_type = init_data_type_; |
| 795 if (init_data_type.empty()) | 796 if (init_data_type.empty()) |
| 796 init_data_type = GuessInitDataType(init_data, init_data_length); | 797 init_data_type = GuessInitDataType(init_data, init_data_length); |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 881 if (current_key_system_.empty() || key_system != current_key_system_) | 882 if (current_key_system_.empty() || key_system != current_key_system_) |
| 882 return WebMediaPlayer::MediaKeyExceptionInvalidPlayerState; | 883 return WebMediaPlayer::MediaKeyExceptionInvalidPlayerState; |
| 883 | 884 |
| 884 proxy_decryptor_->CancelKeyRequest(session_id); | 885 proxy_decryptor_->CancelKeyRequest(session_id); |
| 885 return WebMediaPlayer::MediaKeyExceptionNoError; | 886 return WebMediaPlayer::MediaKeyExceptionNoError; |
| 886 } | 887 } |
| 887 | 888 |
| 888 void WebMediaPlayerImpl::setContentDecryptionModule( | 889 void WebMediaPlayerImpl::setContentDecryptionModule( |
| 889 blink::WebContentDecryptionModule* cdm) { | 890 blink::WebContentDecryptionModule* cdm) { |
| 890 DCHECK(main_loop_->BelongsToCurrentThread()); | 891 DCHECK(main_loop_->BelongsToCurrentThread()); |
| 892 // TODO(jrummell): Remove this method once blink starts calling with 2 | |
|
ddorwin
2014/07/30 22:35:45
Better in the header?
jrummell
2014/08/01 22:09:42
Based in comments for the blink review, we may kee
| |
| 893 // parameters. | |
| 891 | 894 |
| 892 // TODO(xhwang): Support setMediaKeys(0) if necessary: http://crbug.com/330324 | 895 // TODO(xhwang): Support setMediaKeys(0) if necessary: http://crbug.com/330324 |
| 893 if (!cdm) | 896 if (!cdm) |
| 894 return; | 897 return; |
| 895 | 898 |
| 896 web_cdm_ = ToWebContentDecryptionModuleImpl(cdm); | 899 web_cdm_ = ToWebContentDecryptionModuleImpl(cdm); |
| 897 | 900 |
| 898 if (web_cdm_ && !decryptor_ready_cb_.is_null()) | 901 if (web_cdm_ && !decryptor_ready_cb_.is_null()) |
| 899 base::ResetAndReturn(&decryptor_ready_cb_).Run(web_cdm_->GetDecryptor()); | 902 base::ResetAndReturn(&decryptor_ready_cb_) |
| 903 .Run(web_cdm_->GetDecryptor(), base::Bind(&base::DoNothing)); | |
| 904 } | |
| 905 | |
| 906 void WebMediaPlayerImpl::setContentDecryptionModule( | |
| 907 blink::WebContentDecryptionModule* cdm, | |
| 908 blink::WebContentDecryptionModuleResult result) { | |
| 909 DCHECK(main_loop_->BelongsToCurrentThread()); | |
| 910 | |
| 911 // TODO(xhwang): Support setMediaKeys(0) if necessary: http://crbug.com/330324 | |
| 912 if (!cdm) { | |
| 913 result.completeWithError( | |
| 914 blink::WebContentDecryptionModuleExceptionNotSupportedError, | |
| 915 0, | |
| 916 "Setting a null MediaKeys object not supported."); | |
|
ddorwin
2014/07/30 22:35:45
nit: s/not/is not/.
Or, to be more concise, just d
jrummell
2014/08/01 22:09:42
Done.
| |
| 917 return; | |
| 918 } | |
| 919 | |
| 920 web_cdm_ = ToWebContentDecryptionModuleImpl(cdm); | |
| 921 | |
| 922 if (web_cdm_ && !decryptor_ready_cb_.is_null()) { | |
| 923 base::ResetAndReturn(&decryptor_ready_cb_) | |
| 924 .Run(web_cdm_->GetDecryptor(), | |
| 925 BIND_TO_RENDER_LOOP1( | |
| 926 &WebMediaPlayerImpl::ContentDecryptionModuleSet, result)); | |
| 927 } else { | |
| 928 // No player, so setting CDM is complete. | |
|
ddorwin
2014/07/30 22:35:45
I don't think this comment is correct. WMPI is the
jrummell
2014/08/01 22:09:42
Comment updated. decryptor_ready_cb_ is null if .s
| |
| 929 ContentDecryptionModuleSet(result); | |
| 930 } | |
| 931 } | |
| 932 | |
| 933 void WebMediaPlayerImpl::ContentDecryptionModuleSet( | |
| 934 blink::WebContentDecryptionModuleResult result) { | |
| 935 result.complete(); | |
| 900 } | 936 } |
| 901 | 937 |
| 902 void WebMediaPlayerImpl::InvalidateOnMainThread() { | 938 void WebMediaPlayerImpl::InvalidateOnMainThread() { |
| 903 DCHECK(main_loop_->BelongsToCurrentThread()); | 939 DCHECK(main_loop_->BelongsToCurrentThread()); |
| 904 TRACE_EVENT0("media", "WebMediaPlayerImpl::InvalidateOnMainThread"); | 940 TRACE_EVENT0("media", "WebMediaPlayerImpl::InvalidateOnMainThread"); |
| 905 | 941 |
| 906 client_->repaint(); | 942 client_->repaint(); |
| 907 } | 943 } |
| 908 | 944 |
| 909 void WebMediaPlayerImpl::OnPipelineSeeked(bool time_changed, | 945 void WebMediaPlayerImpl::OnPipelineSeeked(bool time_changed, |
| (...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1308 frame)); | 1344 frame)); |
| 1309 } | 1345 } |
| 1310 | 1346 |
| 1311 void WebMediaPlayerImpl::SetDecryptorReadyCB( | 1347 void WebMediaPlayerImpl::SetDecryptorReadyCB( |
| 1312 const media::DecryptorReadyCB& decryptor_ready_cb) { | 1348 const media::DecryptorReadyCB& decryptor_ready_cb) { |
| 1313 DCHECK(main_loop_->BelongsToCurrentThread()); | 1349 DCHECK(main_loop_->BelongsToCurrentThread()); |
| 1314 | 1350 |
| 1315 // Cancels the previous decryptor request. | 1351 // Cancels the previous decryptor request. |
| 1316 if (decryptor_ready_cb.is_null()) { | 1352 if (decryptor_ready_cb.is_null()) { |
| 1317 if (!decryptor_ready_cb_.is_null()) | 1353 if (!decryptor_ready_cb_.is_null()) |
| 1318 base::ResetAndReturn(&decryptor_ready_cb_).Run(NULL); | 1354 base::ResetAndReturn(&decryptor_ready_cb_) |
| 1355 .Run(NULL, base::Bind(&base::DoNothing)); | |
|
ddorwin
2014/07/30 22:35:45
Don't we need to satisfy the promise in some way?
jrummell
2014/08/01 22:09:42
Here we are cancelling the previous request. There
| |
| 1319 return; | 1356 return; |
| 1320 } | 1357 } |
| 1321 | 1358 |
| 1322 // TODO(xhwang): Support multiple decryptor notification request (e.g. from | 1359 // TODO(xhwang): Support multiple decryptor notification request (e.g. from |
| 1323 // video and audio). The current implementation is okay for the current | 1360 // video and audio). The current implementation is okay for the current |
| 1324 // media pipeline since we initialize audio and video decoders in sequence. | 1361 // media pipeline since we initialize audio and video decoders in sequence. |
| 1325 // But WebMediaPlayerImpl should not depend on media pipeline's implementation | 1362 // But WebMediaPlayerImpl should not depend on media pipeline's implementation |
| 1326 // detail. | 1363 // detail. |
| 1327 DCHECK(decryptor_ready_cb_.is_null()); | 1364 DCHECK(decryptor_ready_cb_.is_null()); |
| 1328 | 1365 |
| 1329 // Mixed use of prefixed and unprefixed EME APIs is disallowed by Blink. | 1366 // Mixed use of prefixed and unprefixed EME APIs is disallowed by Blink. |
| 1330 DCHECK(!proxy_decryptor_ || !web_cdm_); | 1367 DCHECK(!proxy_decryptor_ || !web_cdm_); |
| 1331 | 1368 |
| 1332 if (proxy_decryptor_) { | 1369 if (proxy_decryptor_) { |
| 1333 decryptor_ready_cb.Run(proxy_decryptor_->GetDecryptor()); | 1370 decryptor_ready_cb.Run(proxy_decryptor_->GetDecryptor(), |
| 1371 base::Bind(&base::DoNothing)); | |
|
ddorwin
2014/07/30 22:35:45
prefixed only - so this is fine.
jrummell
2014/08/01 22:09:42
Acknowledged.
| |
| 1334 return; | 1372 return; |
| 1335 } | 1373 } |
| 1336 | 1374 |
| 1337 if (web_cdm_) { | 1375 if (web_cdm_) { |
| 1338 decryptor_ready_cb.Run(web_cdm_->GetDecryptor()); | 1376 decryptor_ready_cb.Run(web_cdm_->GetDecryptor(), |
|
ddorwin
2014/07/30 22:35:45
Maybe comment that there can be no outstanding set
jrummell
2014/08/01 22:09:42
Not sure what to comment here. setContentDecryptio
| |
| 1377 base::Bind(&base::DoNothing)); | |
| 1339 return; | 1378 return; |
| 1340 } | 1379 } |
| 1341 | 1380 |
| 1342 decryptor_ready_cb_ = decryptor_ready_cb; | 1381 decryptor_ready_cb_ = decryptor_ready_cb; |
| 1343 } | 1382 } |
| 1344 | 1383 |
| 1345 static void GetCurrentFrameAndSignal( | 1384 static void GetCurrentFrameAndSignal( |
| 1346 VideoFrameCompositor* compositor, | 1385 VideoFrameCompositor* compositor, |
| 1347 scoped_refptr<media::VideoFrame>* video_frame_out, | 1386 scoped_refptr<media::VideoFrame>* video_frame_out, |
| 1348 base::WaitableEvent* event) { | 1387 base::WaitableEvent* event) { |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 1364 compositor_task_runner_->PostTask(FROM_HERE, | 1403 compositor_task_runner_->PostTask(FROM_HERE, |
| 1365 base::Bind(&GetCurrentFrameAndSignal, | 1404 base::Bind(&GetCurrentFrameAndSignal, |
| 1366 base::Unretained(compositor_), | 1405 base::Unretained(compositor_), |
| 1367 &video_frame, | 1406 &video_frame, |
| 1368 &event)); | 1407 &event)); |
| 1369 event.Wait(); | 1408 event.Wait(); |
| 1370 return video_frame; | 1409 return video_frame; |
| 1371 } | 1410 } |
| 1372 | 1411 |
| 1373 } // namespace content | 1412 } // namespace content |
| OLD | NEW |