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

Side by Side Diff: media/blink/webmediaplayer_impl.cc

Issue 2402563002: Keep reference to CDM to avoid it's premature destruction (Closed)
Patch Set: Created 4 years, 2 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 "media/blink/webmediaplayer_impl.h" 5 #include "media/blink/webmediaplayer_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 #include <limits> 9 #include <limits>
10 #include <string> 10 #include <string>
(...skipping 19 matching lines...) Expand all
30 #include "media/audio/null_audio_sink.h" 30 #include "media/audio/null_audio_sink.h"
31 #include "media/base/bind_to_current_loop.h" 31 #include "media/base/bind_to_current_loop.h"
32 #include "media/base/cdm_context.h" 32 #include "media/base/cdm_context.h"
33 #include "media/base/limits.h" 33 #include "media/base/limits.h"
34 #include "media/base/media_content_type.h" 34 #include "media/base/media_content_type.h"
35 #include "media/base/media_log.h" 35 #include "media/base/media_log.h"
36 #include "media/base/media_switches.h" 36 #include "media/base/media_switches.h"
37 #include "media/base/text_renderer.h" 37 #include "media/base/text_renderer.h"
38 #include "media/base/timestamp_constants.h" 38 #include "media/base/timestamp_constants.h"
39 #include "media/base/video_frame.h" 39 #include "media/base/video_frame.h"
40 #include "media/blink/cdm_session_adapter.h"
40 #include "media/blink/texttrack_impl.h" 41 #include "media/blink/texttrack_impl.h"
41 #include "media/blink/watch_time_reporter.h" 42 #include "media/blink/watch_time_reporter.h"
42 #include "media/blink/webaudiosourceprovider_impl.h" 43 #include "media/blink/webaudiosourceprovider_impl.h"
43 #include "media/blink/webcontentdecryptionmodule_impl.h" 44 #include "media/blink/webcontentdecryptionmodule_impl.h"
44 #include "media/blink/webinbandtexttrack_impl.h" 45 #include "media/blink/webinbandtexttrack_impl.h"
45 #include "media/blink/webmediaplayer_delegate.h" 46 #include "media/blink/webmediaplayer_delegate.h"
46 #include "media/blink/webmediaplayer_util.h" 47 #include "media/blink/webmediaplayer_util.h"
47 #include "media/blink/webmediasource_impl.h" 48 #include "media/blink/webmediasource_impl.h"
48 #include "media/filters/chunk_demuxer.h" 49 #include "media/filters/chunk_demuxer.h"
49 #include "media/filters/ffmpeg_demuxer.h" 50 #include "media/filters/ffmpeg_demuxer.h"
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 disable_fullscreen_video_overlays_ = 239 disable_fullscreen_video_overlays_ =
239 !base::FeatureList::IsEnabled(media::kOverlayFullscreenVideo); 240 !base::FeatureList::IsEnabled(media::kOverlayFullscreenVideo);
240 241
241 if (delegate_) 242 if (delegate_)
242 delegate_id_ = delegate_->AddObserver(this); 243 delegate_id_ = delegate_->AddObserver(this);
243 244
244 media_log_->AddEvent( 245 media_log_->AddEvent(
245 media_log_->CreateEvent(MediaLogEvent::WEBMEDIAPLAYER_CREATED)); 246 media_log_->CreateEvent(MediaLogEvent::WEBMEDIAPLAYER_CREATED));
246 247
247 if (params.initial_cdm()) { 248 if (params.initial_cdm()) {
248 SetCdm(base::Bind(&IgnoreCdmAttached), 249 SetCdm(ToWebContentDecryptionModuleImpl(params.initial_cdm()),
249 ToWebContentDecryptionModuleImpl(params.initial_cdm()) 250 base::Bind(&IgnoreCdmAttached));
250 ->GetCdmContext());
251 } 251 }
252 252
253 // TODO(xhwang): When we use an external Renderer, many methods won't work, 253 // TODO(xhwang): When we use an external Renderer, many methods won't work,
254 // e.g. GetCurrentFrameFromCompositor(). See http://crbug.com/434861 254 // e.g. GetCurrentFrameFromCompositor(). See http://crbug.com/434861
255 255
256 // Use the null sink if no sink was provided. 256 // Use the null sink if no sink was provided.
257 audio_source_provider_ = new WebAudioSourceProviderImpl( 257 audio_source_provider_ = new WebAudioSourceProviderImpl(
258 params.audio_renderer_sink().get() 258 params.audio_renderer_sink().get()
259 ? params.audio_renderer_sink() 259 ? params.audio_renderer_sink()
260 : new NullAudioSink(media_task_runner_)); 260 : new NullAudioSink(media_task_runner_));
(...skipping 627 matching lines...) Expand 10 before | Expand all | Expand 10 after
888 // multiple simultaneous calls. 888 // multiple simultaneous calls.
889 DCHECK(!set_cdm_result_); 889 DCHECK(!set_cdm_result_);
890 set_cdm_result_.reset(new blink::WebContentDecryptionModuleResult(result)); 890 set_cdm_result_.reset(new blink::WebContentDecryptionModuleResult(result));
891 891
892 // Recreate the watch time reporter if necessary. 892 // Recreate the watch time reporter if necessary.
893 const bool was_encrypted = is_encrypted_; 893 const bool was_encrypted = is_encrypted_;
894 is_encrypted_ = true; 894 is_encrypted_ = true;
895 if (!was_encrypted && watch_time_reporter_) 895 if (!was_encrypted && watch_time_reporter_)
896 CreateWatchTimeReporter(); 896 CreateWatchTimeReporter();
897 897
898 SetCdm(BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnCdmAttached), 898 SetCdm(ToWebContentDecryptionModuleImpl(cdm),
899 ToWebContentDecryptionModuleImpl(cdm)->GetCdmContext()); 899 BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnCdmAttached));
900 } 900 }
901 901
902 void WebMediaPlayerImpl::OnEncryptedMediaInitData( 902 void WebMediaPlayerImpl::OnEncryptedMediaInitData(
903 EmeInitDataType init_data_type, 903 EmeInitDataType init_data_type,
904 const std::vector<uint8_t>& init_data) { 904 const std::vector<uint8_t>& init_data) {
905 DCHECK(init_data_type != EmeInitDataType::UNKNOWN); 905 DCHECK(init_data_type != EmeInitDataType::UNKNOWN);
906 906
907 // TODO(xhwang): Update this UMA name. https://crbug.com/589251 907 // TODO(xhwang): Update this UMA name. https://crbug.com/589251
908 UMA_HISTOGRAM_COUNTS("Media.EME.NeedKey", 1); 908 UMA_HISTOGRAM_COUNTS("Media.EME.NeedKey", 1);
909 909
(...skipping 29 matching lines...) Expand all
939 blink::WebString::fromUTF8(track->label()), 939 blink::WebString::fromUTF8(track->label()),
940 blink::WebString::fromUTF8(track->language()), 940 blink::WebString::fromUTF8(track->language()),
941 /*selected*/ true); 941 /*selected*/ true);
942 } else { 942 } else {
943 // Text tracks are not supported through this code path yet. 943 // Text tracks are not supported through this code path yet.
944 NOTREACHED(); 944 NOTREACHED();
945 } 945 }
946 } 946 }
947 } 947 }
948 948
949 void WebMediaPlayerImpl::SetCdm(const CdmAttachedCB& cdm_attached_cb, 949 void WebMediaPlayerImpl::SetCdm(WebContentDecryptionModuleImpl* cdm,
950 CdmContext* cdm_context) { 950 const CdmAttachedCB& cdm_attached_cb) {
951 if (!cdm) {
952 cdm_attached_cb.Run(false);
953 return;
954 }
955
956 CdmContext* cdm_context = cdm->GetCdmContext();
951 if (!cdm_context) { 957 if (!cdm_context) {
952 cdm_attached_cb.Run(false); 958 cdm_attached_cb.Run(false);
953 return; 959 return;
954 } 960 }
955 961
962 // Keep a reference to the CDM, as it shouldn't be destroyed until after the
963 // pipeline is done with it.
964 cdm_adapter_ = cdm->GetCdmAdapterReference();
965
956 // If CDM initialization succeeded, tell the pipeline about it. 966 // If CDM initialization succeeded, tell the pipeline about it.
957 pipeline_.SetCdm(cdm_context, cdm_attached_cb); 967 pipeline_.SetCdm(cdm_context, cdm_attached_cb);
958 } 968 }
959 969
960 void WebMediaPlayerImpl::OnCdmAttached(bool success) { 970 void WebMediaPlayerImpl::OnCdmAttached(bool success) {
961 if (success) { 971 if (success) {
962 set_cdm_result_->complete(); 972 set_cdm_result_->complete();
963 set_cdm_result_.reset(); 973 set_cdm_result_.reset();
964 is_cdm_attached_ = true; 974 is_cdm_attached_ = true;
965 return; 975 return;
966 } 976 }
967 977
968 set_cdm_result_->completeWithError( 978 set_cdm_result_->completeWithError(
969 blink::WebContentDecryptionModuleExceptionNotSupportedError, 0, 979 blink::WebContentDecryptionModuleExceptionNotSupportedError, 0,
970 "Unable to set MediaKeys object"); 980 "Unable to set MediaKeys object");
971 set_cdm_result_.reset(); 981 set_cdm_result_.reset();
982 cdm_adapter_ = nullptr;
972 } 983 }
973 984
974 void WebMediaPlayerImpl::OnPipelineSeeked(bool time_updated) { 985 void WebMediaPlayerImpl::OnPipelineSeeked(bool time_updated) {
975 seeking_ = false; 986 seeking_ = false;
976 seek_time_ = base::TimeDelta(); 987 seek_time_ = base::TimeDelta();
977 if (paused_) { 988 if (paused_) {
978 #if defined(OS_ANDROID) // WMPI_CAST 989 #if defined(OS_ANDROID) // WMPI_CAST
979 if (isRemote()) { 990 if (isRemote()) {
980 paused_time_ = base::TimeDelta::FromSecondsD(cast_impl_.currentTime()); 991 paused_time_ = base::TimeDelta::FromSecondsD(cast_impl_.currentTime());
981 } else { 992 } else {
(...skipping 833 matching lines...) Expand 10 before | Expand all | Expand 10 after
1815 pipeline_metadata_.natural_size, 1826 pipeline_metadata_.natural_size,
1816 base::Bind(&GetCurrentTimeInternal, this))); 1827 base::Bind(&GetCurrentTimeInternal, this)));
1817 watch_time_reporter_->OnVolumeChange(volume_); 1828 watch_time_reporter_->OnVolumeChange(volume_);
1818 if (delegate_ && delegate_->IsHidden()) 1829 if (delegate_ && delegate_->IsHidden())
1819 watch_time_reporter_->OnHidden(); 1830 watch_time_reporter_->OnHidden();
1820 else 1831 else
1821 watch_time_reporter_->OnShown(); 1832 watch_time_reporter_->OnShown();
1822 } 1833 }
1823 1834
1824 } // namespace media 1835 } // namespace media
OLDNEW
« media/blink/webmediaplayer_impl.h ('K') | « media/blink/webmediaplayer_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698