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) { | |
ddorwin
2014/08/04 18:59:08
Is there a reason not to use the base:: version?
jrummell
2014/08/07 01:54:24
The base version doesn't have any parameters.
| |
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 628 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
776 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnKeyError), | 781 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnKeyError), |
777 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnKeyMessage))); | 782 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnKeyMessage))); |
778 } | 783 } |
779 | 784 |
780 GURL security_origin(frame_->document().securityOrigin().toString()); | 785 GURL security_origin(frame_->document().securityOrigin().toString()); |
781 if (!proxy_decryptor_->InitializeCDM(key_system, security_origin)) | 786 if (!proxy_decryptor_->InitializeCDM(key_system, security_origin)) |
782 return WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported; | 787 return WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported; |
783 | 788 |
784 if (proxy_decryptor_ && !decryptor_ready_cb_.is_null()) { | 789 if (proxy_decryptor_ && !decryptor_ready_cb_.is_null()) { |
785 base::ResetAndReturn(&decryptor_ready_cb_) | 790 base::ResetAndReturn(&decryptor_ready_cb_) |
786 .Run(proxy_decryptor_->GetDecryptor()); | 791 .Run(proxy_decryptor_->GetDecryptor(), base::Bind(DoNothing)); |
787 } | 792 } |
788 | 793 |
789 current_key_system_ = key_system; | 794 current_key_system_ = key_system; |
790 } else if (key_system != current_key_system_) { | 795 } else if (key_system != current_key_system_) { |
791 return WebMediaPlayer::MediaKeyExceptionInvalidPlayerState; | 796 return WebMediaPlayer::MediaKeyExceptionInvalidPlayerState; |
792 } | 797 } |
793 | 798 |
794 std::string init_data_type = init_data_type_; | 799 std::string init_data_type = init_data_type_; |
795 if (init_data_type.empty()) | 800 if (init_data_type.empty()) |
796 init_data_type = GuessInitDataType(init_data, init_data_length); | 801 init_data_type = GuessInitDataType(init_data, init_data_length); |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
878 if (!IsConcreteSupportedKeySystem(key_system)) | 883 if (!IsConcreteSupportedKeySystem(key_system)) |
879 return WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported; | 884 return WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported; |
880 | 885 |
881 if (current_key_system_.empty() || key_system != current_key_system_) | 886 if (current_key_system_.empty() || key_system != current_key_system_) |
882 return WebMediaPlayer::MediaKeyExceptionInvalidPlayerState; | 887 return WebMediaPlayer::MediaKeyExceptionInvalidPlayerState; |
883 | 888 |
884 proxy_decryptor_->CancelKeyRequest(session_id); | 889 proxy_decryptor_->CancelKeyRequest(session_id); |
885 return WebMediaPlayer::MediaKeyExceptionNoError; | 890 return WebMediaPlayer::MediaKeyExceptionNoError; |
886 } | 891 } |
887 | 892 |
888 void WebMediaPlayerImpl::setContentDecryptionModule( | 893 void WebMediaPlayerImpl::setContentDecryptionModule( |
ddorwin
2014/08/04 18:59:08
This will need a new name, though. Also, we should
jrummell
2014/08/07 01:54:24
Done.
| |
889 blink::WebContentDecryptionModule* cdm) { | 894 blink::WebContentDecryptionModule* cdm) { |
890 DCHECK(main_loop_->BelongsToCurrentThread()); | 895 DCHECK(main_loop_->BelongsToCurrentThread()); |
891 | 896 |
892 // TODO(xhwang): Support setMediaKeys(0) if necessary: http://crbug.com/330324 | 897 // TODO(xhwang): Support setMediaKeys(0) if necessary: http://crbug.com/330324 |
893 if (!cdm) | 898 if (!cdm) |
894 return; | 899 return; |
895 | 900 |
896 web_cdm_ = ToWebContentDecryptionModuleImpl(cdm); | 901 web_cdm_ = ToWebContentDecryptionModuleImpl(cdm); |
897 | 902 |
898 if (web_cdm_ && !decryptor_ready_cb_.is_null()) | 903 if (web_cdm_ && !decryptor_ready_cb_.is_null()) |
899 base::ResetAndReturn(&decryptor_ready_cb_).Run(web_cdm_->GetDecryptor()); | 904 base::ResetAndReturn(&decryptor_ready_cb_) |
905 .Run(web_cdm_->GetDecryptor(), base::Bind(DoNothing)); | |
906 } | |
907 | |
908 void WebMediaPlayerImpl::setContentDecryptionModule( | |
909 blink::WebContentDecryptionModule* cdm, | |
910 blink::WebContentDecryptionModuleResult result) { | |
911 DCHECK(main_loop_->BelongsToCurrentThread()); | |
912 | |
913 // TODO(xhwang): Support setMediaKeys(0) if necessary: http://crbug.com/330324 | |
914 if (!cdm) { | |
915 result.completeWithError( | |
916 blink::WebContentDecryptionModuleExceptionNotSupportedError, | |
917 0, | |
918 "Null MediaKeys object is not supported."); | |
919 return; | |
920 } | |
921 | |
922 web_cdm_ = ToWebContentDecryptionModuleImpl(cdm); | |
923 | |
924 if (web_cdm_ && !decryptor_ready_cb_.is_null()) { | |
925 base::ResetAndReturn(&decryptor_ready_cb_) | |
926 .Run(web_cdm_->GetDecryptor(), | |
927 BIND_TO_RENDER_LOOP1( | |
928 &WebMediaPlayerImpl::ContentDecryptionModuleAttached, result)); | |
929 } else { | |
930 // No pipeline/decoder connected, so resolve the promise. When something | |
ddorwin
2014/08/04 18:59:08
I thought WMPI did not exist until .src was specif
jrummell
2014/08/07 01:54:24
Done.
| |
931 // is connected, setting the CDM will happen in SetDecryptorReadyCB(). | |
932 ContentDecryptionModuleAttached(result, true); | |
933 } | |
934 } | |
935 | |
936 void WebMediaPlayerImpl::ContentDecryptionModuleAttached( | |
937 blink::WebContentDecryptionModuleResult result, | |
938 bool success) { | |
939 if (success) | |
940 result.complete(); | |
941 else | |
942 result.completeWithError( | |
943 blink::WebContentDecryptionModuleExceptionNotSupportedError, | |
944 0, | |
945 "Unable to set MediaKeys object"); | |
900 } | 946 } |
901 | 947 |
902 void WebMediaPlayerImpl::OnPipelineSeeked(bool time_changed, | 948 void WebMediaPlayerImpl::OnPipelineSeeked(bool time_changed, |
903 PipelineStatus status) { | 949 PipelineStatus status) { |
904 DVLOG(1) << __FUNCTION__ << "(" << time_changed << ", " << status << ")"; | 950 DVLOG(1) << __FUNCTION__ << "(" << time_changed << ", " << status << ")"; |
905 DCHECK(main_loop_->BelongsToCurrentThread()); | 951 DCHECK(main_loop_->BelongsToCurrentThread()); |
906 seeking_ = false; | 952 seeking_ = false; |
907 if (pending_seek_) { | 953 if (pending_seek_) { |
908 pending_seek_ = false; | 954 pending_seek_ = false; |
909 seek(pending_seek_seconds_); | 955 seek(pending_seek_seconds_); |
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1281 frame)); | 1327 frame)); |
1282 } | 1328 } |
1283 | 1329 |
1284 void WebMediaPlayerImpl::SetDecryptorReadyCB( | 1330 void WebMediaPlayerImpl::SetDecryptorReadyCB( |
1285 const media::DecryptorReadyCB& decryptor_ready_cb) { | 1331 const media::DecryptorReadyCB& decryptor_ready_cb) { |
1286 DCHECK(main_loop_->BelongsToCurrentThread()); | 1332 DCHECK(main_loop_->BelongsToCurrentThread()); |
1287 | 1333 |
1288 // Cancels the previous decryptor request. | 1334 // Cancels the previous decryptor request. |
1289 if (decryptor_ready_cb.is_null()) { | 1335 if (decryptor_ready_cb.is_null()) { |
1290 if (!decryptor_ready_cb_.is_null()) | 1336 if (!decryptor_ready_cb_.is_null()) |
1291 base::ResetAndReturn(&decryptor_ready_cb_).Run(NULL); | 1337 base::ResetAndReturn(&decryptor_ready_cb_) |
1338 .Run(NULL, base::Bind(DoNothing)); | |
1292 return; | 1339 return; |
1293 } | 1340 } |
1294 | 1341 |
1295 // TODO(xhwang): Support multiple decryptor notification request (e.g. from | 1342 // TODO(xhwang): Support multiple decryptor notification request (e.g. from |
1296 // video and audio). The current implementation is okay for the current | 1343 // video and audio). The current implementation is okay for the current |
1297 // media pipeline since we initialize audio and video decoders in sequence. | 1344 // media pipeline since we initialize audio and video decoders in sequence. |
1298 // But WebMediaPlayerImpl should not depend on media pipeline's implementation | 1345 // But WebMediaPlayerImpl should not depend on media pipeline's implementation |
1299 // detail. | 1346 // detail. |
1300 DCHECK(decryptor_ready_cb_.is_null()); | 1347 DCHECK(decryptor_ready_cb_.is_null()); |
1301 | 1348 |
1302 // Mixed use of prefixed and unprefixed EME APIs is disallowed by Blink. | 1349 // Mixed use of prefixed and unprefixed EME APIs is disallowed by Blink. |
1303 DCHECK(!proxy_decryptor_ || !web_cdm_); | 1350 DCHECK(!proxy_decryptor_ || !web_cdm_); |
1304 | 1351 |
1305 if (proxy_decryptor_) { | 1352 if (proxy_decryptor_) { |
1306 decryptor_ready_cb.Run(proxy_decryptor_->GetDecryptor()); | 1353 decryptor_ready_cb.Run(proxy_decryptor_->GetDecryptor(), |
1354 base::Bind(DoNothing)); | |
1307 return; | 1355 return; |
1308 } | 1356 } |
1309 | 1357 |
1310 if (web_cdm_) { | 1358 if (web_cdm_) { |
1311 decryptor_ready_cb.Run(web_cdm_->GetDecryptor()); | 1359 decryptor_ready_cb.Run(web_cdm_->GetDecryptor(), base::Bind(DoNothing)); |
1312 return; | 1360 return; |
1313 } | 1361 } |
1314 | 1362 |
1315 decryptor_ready_cb_ = decryptor_ready_cb; | 1363 decryptor_ready_cb_ = decryptor_ready_cb; |
1316 } | 1364 } |
1317 | 1365 |
1318 static void GetCurrentFrameAndSignal( | 1366 static void GetCurrentFrameAndSignal( |
1319 VideoFrameCompositor* compositor, | 1367 VideoFrameCompositor* compositor, |
1320 scoped_refptr<media::VideoFrame>* video_frame_out, | 1368 scoped_refptr<media::VideoFrame>* video_frame_out, |
1321 base::WaitableEvent* event) { | 1369 base::WaitableEvent* event) { |
(...skipping 15 matching lines...) Expand all Loading... | |
1337 compositor_task_runner_->PostTask(FROM_HERE, | 1385 compositor_task_runner_->PostTask(FROM_HERE, |
1338 base::Bind(&GetCurrentFrameAndSignal, | 1386 base::Bind(&GetCurrentFrameAndSignal, |
1339 base::Unretained(compositor_), | 1387 base::Unretained(compositor_), |
1340 &video_frame, | 1388 &video_frame, |
1341 &event)); | 1389 &event)); |
1342 event.Wait(); | 1390 event.Wait(); |
1343 return video_frame; | 1391 return video_frame; |
1344 } | 1392 } |
1345 | 1393 |
1346 } // namespace content | 1394 } // namespace content |
OLD | NEW |