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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 return web_graphics_context_->insertSyncPoint(); | 129 return web_graphics_context_->insertSyncPoint(); |
129 } | 130 } |
130 virtual void WaitSyncPoint(uint32 sync_point) OVERRIDE { | 131 virtual void WaitSyncPoint(uint32 sync_point) OVERRIDE { |
131 web_graphics_context_->waitSyncPoint(sync_point); | 132 web_graphics_context_->waitSyncPoint(sync_point); |
132 } | 133 } |
133 | 134 |
134 private: | 135 private: |
135 blink::WebGraphicsContext3D* web_graphics_context_; | 136 blink::WebGraphicsContext3D* web_graphics_context_; |
136 }; | 137 }; |
137 | 138 |
| 139 // Used for calls to decryptor_ready_cb where the result can be ignored. |
| 140 void DoNothing(bool) { |
| 141 } |
| 142 |
138 } // namespace | 143 } // namespace |
139 | 144 |
140 namespace content { | 145 namespace content { |
141 | 146 |
142 class BufferedDataSourceHostImpl; | 147 class BufferedDataSourceHostImpl; |
143 | 148 |
144 #define COMPILE_ASSERT_MATCHING_ENUM(name) \ | 149 #define COMPILE_ASSERT_MATCHING_ENUM(name) \ |
145 COMPILE_ASSERT(static_cast<int>(WebMediaPlayer::CORSMode ## name) == \ | 150 COMPILE_ASSERT(static_cast<int>(WebMediaPlayer::CORSMode ## name) == \ |
146 static_cast<int>(BufferedResourceLoader::k ## name), \ | 151 static_cast<int>(BufferedResourceLoader::k ## name), \ |
147 mismatching_enums) | 152 mismatching_enums) |
(...skipping 620 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
768 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnKeyError), | 773 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnKeyError), |
769 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnKeyMessage))); | 774 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnKeyMessage))); |
770 } | 775 } |
771 | 776 |
772 GURL security_origin(frame_->document().securityOrigin().toString()); | 777 GURL security_origin(frame_->document().securityOrigin().toString()); |
773 if (!proxy_decryptor_->InitializeCDM(key_system, security_origin)) | 778 if (!proxy_decryptor_->InitializeCDM(key_system, security_origin)) |
774 return WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported; | 779 return WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported; |
775 | 780 |
776 if (proxy_decryptor_ && !decryptor_ready_cb_.is_null()) { | 781 if (proxy_decryptor_ && !decryptor_ready_cb_.is_null()) { |
777 base::ResetAndReturn(&decryptor_ready_cb_) | 782 base::ResetAndReturn(&decryptor_ready_cb_) |
778 .Run(proxy_decryptor_->GetDecryptor()); | 783 .Run(proxy_decryptor_->GetDecryptor(), base::Bind(DoNothing)); |
779 } | 784 } |
780 | 785 |
781 current_key_system_ = key_system; | 786 current_key_system_ = key_system; |
782 } else if (key_system != current_key_system_) { | 787 } else if (key_system != current_key_system_) { |
783 return WebMediaPlayer::MediaKeyExceptionInvalidPlayerState; | 788 return WebMediaPlayer::MediaKeyExceptionInvalidPlayerState; |
784 } | 789 } |
785 | 790 |
786 std::string init_data_type = init_data_type_; | 791 std::string init_data_type = init_data_type_; |
787 if (init_data_type.empty()) | 792 if (init_data_type.empty()) |
788 init_data_type = GuessInitDataType(init_data, init_data_length); | 793 init_data_type = GuessInitDataType(init_data, init_data_length); |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
881 blink::WebContentDecryptionModule* cdm) { | 886 blink::WebContentDecryptionModule* cdm) { |
882 DCHECK(main_loop_->BelongsToCurrentThread()); | 887 DCHECK(main_loop_->BelongsToCurrentThread()); |
883 | 888 |
884 // TODO(xhwang): Support setMediaKeys(0) if necessary: http://crbug.com/330324 | 889 // TODO(xhwang): Support setMediaKeys(0) if necessary: http://crbug.com/330324 |
885 if (!cdm) | 890 if (!cdm) |
886 return; | 891 return; |
887 | 892 |
888 web_cdm_ = ToWebContentDecryptionModuleImpl(cdm); | 893 web_cdm_ = ToWebContentDecryptionModuleImpl(cdm); |
889 | 894 |
890 if (web_cdm_ && !decryptor_ready_cb_.is_null()) | 895 if (web_cdm_ && !decryptor_ready_cb_.is_null()) |
891 base::ResetAndReturn(&decryptor_ready_cb_).Run(web_cdm_->GetDecryptor()); | 896 base::ResetAndReturn(&decryptor_ready_cb_) |
| 897 .Run(web_cdm_->GetDecryptor(), base::Bind(DoNothing)); |
| 898 } |
| 899 |
| 900 void WebMediaPlayerImpl::setContentDecryptionModule( |
| 901 blink::WebContentDecryptionModule* cdm, |
| 902 blink::WebContentDecryptionModuleResult result) { |
| 903 DCHECK(main_loop_->BelongsToCurrentThread()); |
| 904 |
| 905 // TODO(xhwang): Support setMediaKeys(0) if necessary: http://crbug.com/330324 |
| 906 if (!cdm) { |
| 907 result.completeWithError( |
| 908 blink::WebContentDecryptionModuleExceptionNotSupportedError, |
| 909 0, |
| 910 "Null MediaKeys object is not supported."); |
| 911 return; |
| 912 } |
| 913 |
| 914 web_cdm_ = ToWebContentDecryptionModuleImpl(cdm); |
| 915 |
| 916 if (web_cdm_ && !decryptor_ready_cb_.is_null()) { |
| 917 base::ResetAndReturn(&decryptor_ready_cb_) |
| 918 .Run(web_cdm_->GetDecryptor(), |
| 919 BIND_TO_RENDER_LOOP1( |
| 920 &WebMediaPlayerImpl::ContentDecryptionModuleAttached, result)); |
| 921 } else { |
| 922 // No pipeline/decoder connected, so resolve the promise. When something |
| 923 // is connected, setting the CDM will happen in SetDecryptorReadyCB(). |
| 924 ContentDecryptionModuleAttached(result, true); |
| 925 } |
| 926 } |
| 927 |
| 928 void WebMediaPlayerImpl::setContentDecryptionModuleSync( |
| 929 blink::WebContentDecryptionModule* cdm) { |
| 930 DCHECK(main_loop_->BelongsToCurrentThread()); |
| 931 |
| 932 // Used when loading media and no pipeline/decoder attached yet. |
| 933 DCHECK(decryptor_ready_cb_.is_null()); |
| 934 |
| 935 web_cdm_ = ToWebContentDecryptionModuleImpl(cdm); |
| 936 } |
| 937 |
| 938 void WebMediaPlayerImpl::ContentDecryptionModuleAttached( |
| 939 blink::WebContentDecryptionModuleResult result, |
| 940 bool success) { |
| 941 if (success) { |
| 942 result.complete(); |
| 943 return; |
| 944 } |
| 945 |
| 946 result.completeWithError( |
| 947 blink::WebContentDecryptionModuleExceptionNotSupportedError, |
| 948 0, |
| 949 "Unable to set MediaKeys object"); |
892 } | 950 } |
893 | 951 |
894 void WebMediaPlayerImpl::OnPipelineSeeked(bool time_changed, | 952 void WebMediaPlayerImpl::OnPipelineSeeked(bool time_changed, |
895 PipelineStatus status) { | 953 PipelineStatus status) { |
896 DVLOG(1) << __FUNCTION__ << "(" << time_changed << ", " << status << ")"; | 954 DVLOG(1) << __FUNCTION__ << "(" << time_changed << ", " << status << ")"; |
897 DCHECK(main_loop_->BelongsToCurrentThread()); | 955 DCHECK(main_loop_->BelongsToCurrentThread()); |
898 seeking_ = false; | 956 seeking_ = false; |
899 if (pending_seek_) { | 957 if (pending_seek_) { |
900 pending_seek_ = false; | 958 pending_seek_ = false; |
901 seek(pending_seek_seconds_); | 959 seek(pending_seek_seconds_); |
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1280 base::Unretained(compositor_), | 1338 base::Unretained(compositor_), |
1281 frame)); | 1339 frame)); |
1282 } | 1340 } |
1283 | 1341 |
1284 void WebMediaPlayerImpl::SetDecryptorReadyCB( | 1342 void WebMediaPlayerImpl::SetDecryptorReadyCB( |
1285 const media::DecryptorReadyCB& decryptor_ready_cb) { | 1343 const media::DecryptorReadyCB& decryptor_ready_cb) { |
1286 DCHECK(main_loop_->BelongsToCurrentThread()); | 1344 DCHECK(main_loop_->BelongsToCurrentThread()); |
1287 | 1345 |
1288 // Cancels the previous decryptor request. | 1346 // Cancels the previous decryptor request. |
1289 if (decryptor_ready_cb.is_null()) { | 1347 if (decryptor_ready_cb.is_null()) { |
1290 if (!decryptor_ready_cb_.is_null()) | 1348 if (!decryptor_ready_cb_.is_null()) { |
1291 base::ResetAndReturn(&decryptor_ready_cb_).Run(NULL); | 1349 base::ResetAndReturn(&decryptor_ready_cb_) |
| 1350 .Run(NULL, base::Bind(DoNothing)); |
| 1351 } |
1292 return; | 1352 return; |
1293 } | 1353 } |
1294 | 1354 |
1295 // TODO(xhwang): Support multiple decryptor notification request (e.g. from | 1355 // TODO(xhwang): Support multiple decryptor notification request (e.g. from |
1296 // video and audio). The current implementation is okay for the current | 1356 // video and audio). The current implementation is okay for the current |
1297 // media pipeline since we initialize audio and video decoders in sequence. | 1357 // media pipeline since we initialize audio and video decoders in sequence. |
1298 // But WebMediaPlayerImpl should not depend on media pipeline's implementation | 1358 // But WebMediaPlayerImpl should not depend on media pipeline's implementation |
1299 // detail. | 1359 // detail. |
1300 DCHECK(decryptor_ready_cb_.is_null()); | 1360 DCHECK(decryptor_ready_cb_.is_null()); |
1301 | 1361 |
1302 // Mixed use of prefixed and unprefixed EME APIs is disallowed by Blink. | 1362 // Mixed use of prefixed and unprefixed EME APIs is disallowed by Blink. |
1303 DCHECK(!proxy_decryptor_ || !web_cdm_); | 1363 DCHECK(!proxy_decryptor_ || !web_cdm_); |
1304 | 1364 |
1305 if (proxy_decryptor_) { | 1365 if (proxy_decryptor_) { |
1306 decryptor_ready_cb.Run(proxy_decryptor_->GetDecryptor()); | 1366 decryptor_ready_cb.Run(proxy_decryptor_->GetDecryptor(), |
| 1367 base::Bind(DoNothing)); |
1307 return; | 1368 return; |
1308 } | 1369 } |
1309 | 1370 |
1310 if (web_cdm_) { | 1371 if (web_cdm_) { |
1311 decryptor_ready_cb.Run(web_cdm_->GetDecryptor()); | 1372 decryptor_ready_cb.Run(web_cdm_->GetDecryptor(), base::Bind(DoNothing)); |
1312 return; | 1373 return; |
1313 } | 1374 } |
1314 | 1375 |
1315 decryptor_ready_cb_ = decryptor_ready_cb; | 1376 decryptor_ready_cb_ = decryptor_ready_cb; |
1316 } | 1377 } |
1317 | 1378 |
1318 static void GetCurrentFrameAndSignal( | 1379 static void GetCurrentFrameAndSignal( |
1319 VideoFrameCompositor* compositor, | 1380 VideoFrameCompositor* compositor, |
1320 scoped_refptr<media::VideoFrame>* video_frame_out, | 1381 scoped_refptr<media::VideoFrame>* video_frame_out, |
1321 base::WaitableEvent* event) { | 1382 base::WaitableEvent* event) { |
(...skipping 15 matching lines...) Expand all Loading... |
1337 compositor_task_runner_->PostTask(FROM_HERE, | 1398 compositor_task_runner_->PostTask(FROM_HERE, |
1338 base::Bind(&GetCurrentFrameAndSignal, | 1399 base::Bind(&GetCurrentFrameAndSignal, |
1339 base::Unretained(compositor_), | 1400 base::Unretained(compositor_), |
1340 &video_frame, | 1401 &video_frame, |
1341 &event)); | 1402 &event)); |
1342 event.Wait(); | 1403 event.Wait(); |
1343 return video_frame; | 1404 return video_frame; |
1344 } | 1405 } |
1345 | 1406 |
1346 } // namespace content | 1407 } // namespace content |
OLD | NEW |