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 616 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
764 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnKeyError), | 769 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnKeyError), |
765 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnKeyMessage))); | 770 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnKeyMessage))); |
766 } | 771 } |
767 | 772 |
768 GURL security_origin(frame_->document().securityOrigin().toString()); | 773 GURL security_origin(frame_->document().securityOrigin().toString()); |
769 if (!proxy_decryptor_->InitializeCDM(key_system, security_origin)) | 774 if (!proxy_decryptor_->InitializeCDM(key_system, security_origin)) |
770 return WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported; | 775 return WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported; |
771 | 776 |
772 if (proxy_decryptor_ && !decryptor_ready_cb_.is_null()) { | 777 if (proxy_decryptor_ && !decryptor_ready_cb_.is_null()) { |
773 base::ResetAndReturn(&decryptor_ready_cb_) | 778 base::ResetAndReturn(&decryptor_ready_cb_) |
774 .Run(proxy_decryptor_->GetDecryptor()); | 779 .Run(proxy_decryptor_->GetDecryptor(), base::Bind(DoNothing)); |
775 } | 780 } |
776 | 781 |
777 current_key_system_ = key_system; | 782 current_key_system_ = key_system; |
778 } else if (key_system != current_key_system_) { | 783 } else if (key_system != current_key_system_) { |
779 return WebMediaPlayer::MediaKeyExceptionInvalidPlayerState; | 784 return WebMediaPlayer::MediaKeyExceptionInvalidPlayerState; |
780 } | 785 } |
781 | 786 |
782 std::string init_data_type = init_data_type_; | 787 std::string init_data_type = init_data_type_; |
783 if (init_data_type.empty()) | 788 if (init_data_type.empty()) |
784 init_data_type = GuessInitDataType(init_data, init_data_length); | 789 init_data_type = GuessInitDataType(init_data, init_data_length); |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
877 blink::WebContentDecryptionModule* cdm) { | 882 blink::WebContentDecryptionModule* cdm) { |
878 DCHECK(main_loop_->BelongsToCurrentThread()); | 883 DCHECK(main_loop_->BelongsToCurrentThread()); |
879 | 884 |
880 // TODO(xhwang): Support setMediaKeys(0) if necessary: http://crbug.com/330324 | 885 // TODO(xhwang): Support setMediaKeys(0) if necessary: http://crbug.com/330324 |
881 if (!cdm) | 886 if (!cdm) |
882 return; | 887 return; |
883 | 888 |
884 web_cdm_ = ToWebContentDecryptionModuleImpl(cdm); | 889 web_cdm_ = ToWebContentDecryptionModuleImpl(cdm); |
885 | 890 |
886 if (web_cdm_ && !decryptor_ready_cb_.is_null()) | 891 if (web_cdm_ && !decryptor_ready_cb_.is_null()) |
887 base::ResetAndReturn(&decryptor_ready_cb_).Run(web_cdm_->GetDecryptor()); | 892 base::ResetAndReturn(&decryptor_ready_cb_) |
| 893 .Run(web_cdm_->GetDecryptor(), base::Bind(DoNothing)); |
| 894 } |
| 895 |
| 896 void WebMediaPlayerImpl::setContentDecryptionModule( |
| 897 blink::WebContentDecryptionModule* cdm, |
| 898 blink::WebContentDecryptionModuleResult result) { |
| 899 DCHECK(main_loop_->BelongsToCurrentThread()); |
| 900 |
| 901 // TODO(xhwang): Support setMediaKeys(0) if necessary: http://crbug.com/330324 |
| 902 if (!cdm) { |
| 903 result.completeWithError( |
| 904 blink::WebContentDecryptionModuleExceptionNotSupportedError, |
| 905 0, |
| 906 "Null MediaKeys object is not supported."); |
| 907 return; |
| 908 } |
| 909 |
| 910 web_cdm_ = ToWebContentDecryptionModuleImpl(cdm); |
| 911 |
| 912 if (web_cdm_ && !decryptor_ready_cb_.is_null()) { |
| 913 base::ResetAndReturn(&decryptor_ready_cb_) |
| 914 .Run(web_cdm_->GetDecryptor(), |
| 915 BIND_TO_RENDER_LOOP1( |
| 916 &WebMediaPlayerImpl::ContentDecryptionModuleAttached, result)); |
| 917 } else { |
| 918 // No pipeline/decoder connected, so resolve the promise. When something |
| 919 // is connected, setting the CDM will happen in SetDecryptorReadyCB(). |
| 920 ContentDecryptionModuleAttached(result, true); |
| 921 } |
| 922 } |
| 923 |
| 924 void WebMediaPlayerImpl::setContentDecryptionModuleSync( |
| 925 blink::WebContentDecryptionModule* cdm) { |
| 926 DCHECK(main_loop_->BelongsToCurrentThread()); |
| 927 |
| 928 // Used when loading media and no pipeline/decoder attached yet. |
| 929 DCHECK(decryptor_ready_cb_.is_null()); |
| 930 |
| 931 web_cdm_ = ToWebContentDecryptionModuleImpl(cdm); |
| 932 } |
| 933 |
| 934 void WebMediaPlayerImpl::ContentDecryptionModuleAttached( |
| 935 blink::WebContentDecryptionModuleResult result, |
| 936 bool success) { |
| 937 if (success) { |
| 938 result.complete(); |
| 939 return; |
| 940 } |
| 941 |
| 942 result.completeWithError( |
| 943 blink::WebContentDecryptionModuleExceptionNotSupportedError, |
| 944 0, |
| 945 "Unable to set MediaKeys object"); |
888 } | 946 } |
889 | 947 |
890 void WebMediaPlayerImpl::OnPipelineSeeked(bool time_changed, | 948 void WebMediaPlayerImpl::OnPipelineSeeked(bool time_changed, |
891 PipelineStatus status) { | 949 PipelineStatus status) { |
892 DVLOG(1) << __FUNCTION__ << "(" << time_changed << ", " << status << ")"; | 950 DVLOG(1) << __FUNCTION__ << "(" << time_changed << ", " << status << ")"; |
893 DCHECK(main_loop_->BelongsToCurrentThread()); | 951 DCHECK(main_loop_->BelongsToCurrentThread()); |
894 seeking_ = false; | 952 seeking_ = false; |
895 if (pending_seek_) { | 953 if (pending_seek_) { |
896 pending_seek_ = false; | 954 pending_seek_ = false; |
897 seek(pending_seek_seconds_); | 955 seek(pending_seek_seconds_); |
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1268 base::Unretained(compositor_), | 1326 base::Unretained(compositor_), |
1269 frame)); | 1327 frame)); |
1270 } | 1328 } |
1271 | 1329 |
1272 void WebMediaPlayerImpl::SetDecryptorReadyCB( | 1330 void WebMediaPlayerImpl::SetDecryptorReadyCB( |
1273 const media::DecryptorReadyCB& decryptor_ready_cb) { | 1331 const media::DecryptorReadyCB& decryptor_ready_cb) { |
1274 DCHECK(main_loop_->BelongsToCurrentThread()); | 1332 DCHECK(main_loop_->BelongsToCurrentThread()); |
1275 | 1333 |
1276 // Cancels the previous decryptor request. | 1334 // Cancels the previous decryptor request. |
1277 if (decryptor_ready_cb.is_null()) { | 1335 if (decryptor_ready_cb.is_null()) { |
1278 if (!decryptor_ready_cb_.is_null()) | 1336 if (!decryptor_ready_cb_.is_null()) { |
1279 base::ResetAndReturn(&decryptor_ready_cb_).Run(NULL); | 1337 base::ResetAndReturn(&decryptor_ready_cb_) |
| 1338 .Run(NULL, base::Bind(DoNothing)); |
| 1339 } |
1280 return; | 1340 return; |
1281 } | 1341 } |
1282 | 1342 |
1283 // TODO(xhwang): Support multiple decryptor notification request (e.g. from | 1343 // TODO(xhwang): Support multiple decryptor notification request (e.g. from |
1284 // video and audio). The current implementation is okay for the current | 1344 // video and audio). The current implementation is okay for the current |
1285 // media pipeline since we initialize audio and video decoders in sequence. | 1345 // media pipeline since we initialize audio and video decoders in sequence. |
1286 // But WebMediaPlayerImpl should not depend on media pipeline's implementation | 1346 // But WebMediaPlayerImpl should not depend on media pipeline's implementation |
1287 // detail. | 1347 // detail. |
1288 DCHECK(decryptor_ready_cb_.is_null()); | 1348 DCHECK(decryptor_ready_cb_.is_null()); |
1289 | 1349 |
1290 // Mixed use of prefixed and unprefixed EME APIs is disallowed by Blink. | 1350 // Mixed use of prefixed and unprefixed EME APIs is disallowed by Blink. |
1291 DCHECK(!proxy_decryptor_ || !web_cdm_); | 1351 DCHECK(!proxy_decryptor_ || !web_cdm_); |
1292 | 1352 |
1293 if (proxy_decryptor_) { | 1353 if (proxy_decryptor_) { |
1294 decryptor_ready_cb.Run(proxy_decryptor_->GetDecryptor()); | 1354 decryptor_ready_cb.Run(proxy_decryptor_->GetDecryptor(), |
| 1355 base::Bind(DoNothing)); |
1295 return; | 1356 return; |
1296 } | 1357 } |
1297 | 1358 |
1298 if (web_cdm_) { | 1359 if (web_cdm_) { |
1299 decryptor_ready_cb.Run(web_cdm_->GetDecryptor()); | 1360 decryptor_ready_cb.Run(web_cdm_->GetDecryptor(), base::Bind(DoNothing)); |
1300 return; | 1361 return; |
1301 } | 1362 } |
1302 | 1363 |
1303 decryptor_ready_cb_ = decryptor_ready_cb; | 1364 decryptor_ready_cb_ = decryptor_ready_cb; |
1304 } | 1365 } |
1305 | 1366 |
1306 static void GetCurrentFrameAndSignal( | 1367 static void GetCurrentFrameAndSignal( |
1307 VideoFrameCompositor* compositor, | 1368 VideoFrameCompositor* compositor, |
1308 scoped_refptr<media::VideoFrame>* video_frame_out, | 1369 scoped_refptr<media::VideoFrame>* video_frame_out, |
1309 base::WaitableEvent* event) { | 1370 base::WaitableEvent* event) { |
(...skipping 15 matching lines...) Expand all Loading... |
1325 compositor_task_runner_->PostTask(FROM_HERE, | 1386 compositor_task_runner_->PostTask(FROM_HERE, |
1326 base::Bind(&GetCurrentFrameAndSignal, | 1387 base::Bind(&GetCurrentFrameAndSignal, |
1327 base::Unretained(compositor_), | 1388 base::Unretained(compositor_), |
1328 &video_frame, | 1389 &video_frame, |
1329 &event)); | 1390 &event)); |
1330 event.Wait(); | 1391 event.Wait(); |
1331 return video_frame; | 1392 return video_frame; |
1332 } | 1393 } |
1333 | 1394 |
1334 } // namespace content | 1395 } // namespace content |
OLD | NEW |