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::setContentDecryptionModuleSync( | |
ddorwin
2014/08/07 19:52:04
order
jrummell
2014/08/08 20:58:28
Done.
| |
897 blink::WebContentDecryptionModule* cdm) { | |
898 DCHECK(main_loop_->BelongsToCurrentThread()); | |
899 DCHECK(decryptor_ready_cb_.is_null()); | |
900 | |
901 web_cdm_ = ToWebContentDecryptionModuleImpl(cdm); | |
902 } | |
903 | |
904 void WebMediaPlayerImpl::setContentDecryptionModule( | |
905 blink::WebContentDecryptionModule* cdm, | |
906 blink::WebContentDecryptionModuleResult result) { | |
907 DCHECK(main_loop_->BelongsToCurrentThread()); | |
908 | |
909 // TODO(xhwang): Support setMediaKeys(0) if necessary: http://crbug.com/330324 | |
910 if (!cdm) { | |
911 result.completeWithError( | |
912 blink::WebContentDecryptionModuleExceptionNotSupportedError, | |
913 0, | |
914 "Null MediaKeys object is not supported."); | |
915 return; | |
916 } | |
917 | |
918 web_cdm_ = ToWebContentDecryptionModuleImpl(cdm); | |
919 | |
920 if (web_cdm_ && !decryptor_ready_cb_.is_null()) { | |
921 base::ResetAndReturn(&decryptor_ready_cb_) | |
922 .Run(web_cdm_->GetDecryptor(), | |
923 BIND_TO_RENDER_LOOP1( | |
924 &WebMediaPlayerImpl::ContentDecryptionModuleAttached, result)); | |
925 } else { | |
926 // No pipeline/decoder connected, so resolve the promise. When something | |
927 // is connected, setting the CDM will happen in SetDecryptorReadyCB(). | |
928 ContentDecryptionModuleAttached(result, true); | |
929 } | |
930 } | |
931 | |
932 void WebMediaPlayerImpl::ContentDecryptionModuleAttached( | |
933 blink::WebContentDecryptionModuleResult result, | |
934 bool success) { | |
935 if (success) | |
936 result.complete(); | |
937 else | |
938 result.completeWithError( | |
939 blink::WebContentDecryptionModuleExceptionNotSupportedError, | |
940 0, | |
941 "Unable to set MediaKeys object"); | |
888 } | 942 } |
889 | 943 |
890 void WebMediaPlayerImpl::OnPipelineSeeked(bool time_changed, | 944 void WebMediaPlayerImpl::OnPipelineSeeked(bool time_changed, |
891 PipelineStatus status) { | 945 PipelineStatus status) { |
892 DVLOG(1) << __FUNCTION__ << "(" << time_changed << ", " << status << ")"; | 946 DVLOG(1) << __FUNCTION__ << "(" << time_changed << ", " << status << ")"; |
893 DCHECK(main_loop_->BelongsToCurrentThread()); | 947 DCHECK(main_loop_->BelongsToCurrentThread()); |
894 seeking_ = false; | 948 seeking_ = false; |
895 if (pending_seek_) { | 949 if (pending_seek_) { |
896 pending_seek_ = false; | 950 pending_seek_ = false; |
897 seek(pending_seek_seconds_); | 951 seek(pending_seek_seconds_); |
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1269 frame)); | 1323 frame)); |
1270 } | 1324 } |
1271 | 1325 |
1272 void WebMediaPlayerImpl::SetDecryptorReadyCB( | 1326 void WebMediaPlayerImpl::SetDecryptorReadyCB( |
1273 const media::DecryptorReadyCB& decryptor_ready_cb) { | 1327 const media::DecryptorReadyCB& decryptor_ready_cb) { |
1274 DCHECK(main_loop_->BelongsToCurrentThread()); | 1328 DCHECK(main_loop_->BelongsToCurrentThread()); |
1275 | 1329 |
1276 // Cancels the previous decryptor request. | 1330 // Cancels the previous decryptor request. |
1277 if (decryptor_ready_cb.is_null()) { | 1331 if (decryptor_ready_cb.is_null()) { |
1278 if (!decryptor_ready_cb_.is_null()) | 1332 if (!decryptor_ready_cb_.is_null()) |
1279 base::ResetAndReturn(&decryptor_ready_cb_).Run(NULL); | 1333 base::ResetAndReturn(&decryptor_ready_cb_) |
1334 .Run(NULL, base::Bind(DoNothing)); | |
1280 return; | 1335 return; |
1281 } | 1336 } |
1282 | 1337 |
1283 // TODO(xhwang): Support multiple decryptor notification request (e.g. from | 1338 // TODO(xhwang): Support multiple decryptor notification request (e.g. from |
1284 // video and audio). The current implementation is okay for the current | 1339 // video and audio). The current implementation is okay for the current |
1285 // media pipeline since we initialize audio and video decoders in sequence. | 1340 // media pipeline since we initialize audio and video decoders in sequence. |
1286 // But WebMediaPlayerImpl should not depend on media pipeline's implementation | 1341 // But WebMediaPlayerImpl should not depend on media pipeline's implementation |
1287 // detail. | 1342 // detail. |
1288 DCHECK(decryptor_ready_cb_.is_null()); | 1343 DCHECK(decryptor_ready_cb_.is_null()); |
1289 | 1344 |
1290 // Mixed use of prefixed and unprefixed EME APIs is disallowed by Blink. | 1345 // Mixed use of prefixed and unprefixed EME APIs is disallowed by Blink. |
1291 DCHECK(!proxy_decryptor_ || !web_cdm_); | 1346 DCHECK(!proxy_decryptor_ || !web_cdm_); |
1292 | 1347 |
1293 if (proxy_decryptor_) { | 1348 if (proxy_decryptor_) { |
1294 decryptor_ready_cb.Run(proxy_decryptor_->GetDecryptor()); | 1349 decryptor_ready_cb.Run(proxy_decryptor_->GetDecryptor(), |
1350 base::Bind(DoNothing)); | |
1295 return; | 1351 return; |
1296 } | 1352 } |
1297 | 1353 |
1298 if (web_cdm_) { | 1354 if (web_cdm_) { |
1299 decryptor_ready_cb.Run(web_cdm_->GetDecryptor()); | 1355 decryptor_ready_cb.Run(web_cdm_->GetDecryptor(), base::Bind(DoNothing)); |
1300 return; | 1356 return; |
1301 } | 1357 } |
1302 | 1358 |
1303 decryptor_ready_cb_ = decryptor_ready_cb; | 1359 decryptor_ready_cb_ = decryptor_ready_cb; |
1304 } | 1360 } |
1305 | 1361 |
1306 static void GetCurrentFrameAndSignal( | 1362 static void GetCurrentFrameAndSignal( |
1307 VideoFrameCompositor* compositor, | 1363 VideoFrameCompositor* compositor, |
1308 scoped_refptr<media::VideoFrame>* video_frame_out, | 1364 scoped_refptr<media::VideoFrame>* video_frame_out, |
1309 base::WaitableEvent* event) { | 1365 base::WaitableEvent* event) { |
(...skipping 15 matching lines...) Expand all Loading... | |
1325 compositor_task_runner_->PostTask(FROM_HERE, | 1381 compositor_task_runner_->PostTask(FROM_HERE, |
1326 base::Bind(&GetCurrentFrameAndSignal, | 1382 base::Bind(&GetCurrentFrameAndSignal, |
1327 base::Unretained(compositor_), | 1383 base::Unretained(compositor_), |
1328 &video_frame, | 1384 &video_frame, |
1329 &event)); | 1385 &event)); |
1330 event.Wait(); | 1386 event.Wait(); |
1331 return video_frame; | 1387 return video_frame; |
1332 } | 1388 } |
1333 | 1389 |
1334 } // namespace content | 1390 } // namespace content |
OLD | NEW |