Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(207)

Side by Side Diff: content/renderer/media/webmediaplayer_impl.cc

Issue 416333011: Allow setContentDecryptionModule() to get called when setting is done. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: More changes Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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
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
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 // Used when loading media and no pipeline/decoder attached yet.
ddorwin 2014/08/08 21:15:26 this probably goes down one line
jrummell 2014/08/08 23:39:59 Done.
927 DCHECK(main_loop_->BelongsToCurrentThread());
928 DCHECK(decryptor_ready_cb_.is_null());
929
930 web_cdm_ = ToWebContentDecryptionModuleImpl(cdm);
931 }
932
933 void WebMediaPlayerImpl::ContentDecryptionModuleAttached(
934 blink::WebContentDecryptionModuleResult result,
935 bool success) {
936 if (success)
937 result.complete();
938 else
939 result.completeWithError(
940 blink::WebContentDecryptionModuleExceptionNotSupportedError,
941 0,
942 "Unable to set MediaKeys object");
888 } 943 }
889 944
890 void WebMediaPlayerImpl::OnPipelineSeeked(bool time_changed, 945 void WebMediaPlayerImpl::OnPipelineSeeked(bool time_changed,
891 PipelineStatus status) { 946 PipelineStatus status) {
892 DVLOG(1) << __FUNCTION__ << "(" << time_changed << ", " << status << ")"; 947 DVLOG(1) << __FUNCTION__ << "(" << time_changed << ", " << status << ")";
893 DCHECK(main_loop_->BelongsToCurrentThread()); 948 DCHECK(main_loop_->BelongsToCurrentThread());
894 seeking_ = false; 949 seeking_ = false;
895 if (pending_seek_) { 950 if (pending_seek_) {
896 pending_seek_ = false; 951 pending_seek_ = false;
897 seek(pending_seek_seconds_); 952 seek(pending_seek_seconds_);
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after
1269 frame)); 1324 frame));
1270 } 1325 }
1271 1326
1272 void WebMediaPlayerImpl::SetDecryptorReadyCB( 1327 void WebMediaPlayerImpl::SetDecryptorReadyCB(
1273 const media::DecryptorReadyCB& decryptor_ready_cb) { 1328 const media::DecryptorReadyCB& decryptor_ready_cb) {
1274 DCHECK(main_loop_->BelongsToCurrentThread()); 1329 DCHECK(main_loop_->BelongsToCurrentThread());
1275 1330
1276 // Cancels the previous decryptor request. 1331 // Cancels the previous decryptor request.
1277 if (decryptor_ready_cb.is_null()) { 1332 if (decryptor_ready_cb.is_null()) {
1278 if (!decryptor_ready_cb_.is_null()) 1333 if (!decryptor_ready_cb_.is_null())
1279 base::ResetAndReturn(&decryptor_ready_cb_).Run(NULL); 1334 base::ResetAndReturn(&decryptor_ready_cb_)
1335 .Run(NULL, base::Bind(DoNothing));
1280 return; 1336 return;
1281 } 1337 }
1282 1338
1283 // TODO(xhwang): Support multiple decryptor notification request (e.g. from 1339 // TODO(xhwang): Support multiple decryptor notification request (e.g. from
1284 // video and audio). The current implementation is okay for the current 1340 // video and audio). The current implementation is okay for the current
1285 // media pipeline since we initialize audio and video decoders in sequence. 1341 // media pipeline since we initialize audio and video decoders in sequence.
1286 // But WebMediaPlayerImpl should not depend on media pipeline's implementation 1342 // But WebMediaPlayerImpl should not depend on media pipeline's implementation
1287 // detail. 1343 // detail.
1288 DCHECK(decryptor_ready_cb_.is_null()); 1344 DCHECK(decryptor_ready_cb_.is_null());
1289 1345
1290 // Mixed use of prefixed and unprefixed EME APIs is disallowed by Blink. 1346 // Mixed use of prefixed and unprefixed EME APIs is disallowed by Blink.
1291 DCHECK(!proxy_decryptor_ || !web_cdm_); 1347 DCHECK(!proxy_decryptor_ || !web_cdm_);
1292 1348
1293 if (proxy_decryptor_) { 1349 if (proxy_decryptor_) {
1294 decryptor_ready_cb.Run(proxy_decryptor_->GetDecryptor()); 1350 decryptor_ready_cb.Run(proxy_decryptor_->GetDecryptor(),
1351 base::Bind(DoNothing));
1295 return; 1352 return;
1296 } 1353 }
1297 1354
1298 if (web_cdm_) { 1355 if (web_cdm_) {
1299 decryptor_ready_cb.Run(web_cdm_->GetDecryptor()); 1356 decryptor_ready_cb.Run(web_cdm_->GetDecryptor(), base::Bind(DoNothing));
1300 return; 1357 return;
1301 } 1358 }
1302 1359
1303 decryptor_ready_cb_ = decryptor_ready_cb; 1360 decryptor_ready_cb_ = decryptor_ready_cb;
1304 } 1361 }
1305 1362
1306 static void GetCurrentFrameAndSignal( 1363 static void GetCurrentFrameAndSignal(
1307 VideoFrameCompositor* compositor, 1364 VideoFrameCompositor* compositor,
1308 scoped_refptr<media::VideoFrame>* video_frame_out, 1365 scoped_refptr<media::VideoFrame>* video_frame_out,
1309 base::WaitableEvent* event) { 1366 base::WaitableEvent* event) {
(...skipping 15 matching lines...) Expand all
1325 compositor_task_runner_->PostTask(FROM_HERE, 1382 compositor_task_runner_->PostTask(FROM_HERE,
1326 base::Bind(&GetCurrentFrameAndSignal, 1383 base::Bind(&GetCurrentFrameAndSignal,
1327 base::Unretained(compositor_), 1384 base::Unretained(compositor_),
1328 &video_frame, 1385 &video_frame,
1329 &event)); 1386 &event));
1330 event.Wait(); 1387 event.Wait();
1331 return video_frame; 1388 return video_frame;
1332 } 1389 }
1333 1390
1334 } // namespace content 1391 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698