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

Unified Diff: media/blink/webmediaplayer_impl.cc

Issue 2402563002: Keep reference to CDM to avoid it's premature destruction (Closed)
Patch Set: nits 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « media/blink/webmediaplayer_impl.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/blink/webmediaplayer_impl.cc
diff --git a/media/blink/webmediaplayer_impl.cc b/media/blink/webmediaplayer_impl.cc
index 7c67743e982b430e3c7794a1e1d2a3310806ee3c..cdebe7739579127cc1db0a4aadd49269324e37b7 100644
--- a/media/blink/webmediaplayer_impl.cc
+++ b/media/blink/webmediaplayer_impl.cc
@@ -32,6 +32,7 @@
#include "media/base/cdm_context.h"
#include "media/base/limits.h"
#include "media/base/media_content_type.h"
+#include "media/base/media_keys.h"
#include "media/base/media_log.h"
#include "media/base/media_switches.h"
#include "media/base/text_renderer.h"
@@ -215,7 +216,6 @@ WebMediaPlayerImpl::WebMediaPlayerImpl(
? params.compositor_task_runner()
: base::ThreadTaskRunnerHandle::Get()),
compositor_(new VideoFrameCompositor(compositor_task_runner_)),
- is_cdm_attached_(false),
#if defined(OS_ANDROID) // WMPI_CAST
cast_impl_(this, client_, params.context_3d_cb()),
#endif
@@ -244,11 +244,8 @@ WebMediaPlayerImpl::WebMediaPlayerImpl(
media_log_->AddEvent(
media_log_->CreateEvent(MediaLogEvent::WEBMEDIAPLAYER_CREATED));
- if (params.initial_cdm()) {
- SetCdm(base::Bind(&IgnoreCdmAttached),
- ToWebContentDecryptionModuleImpl(params.initial_cdm())
- ->GetCdmContext());
- }
+ if (params.initial_cdm())
+ SetCdm(params.initial_cdm());
// TODO(xhwang): When we use an external Renderer, many methods won't work,
// e.g. GetCurrentFrameFromCompositor(). See http://crbug.com/434861
@@ -780,7 +777,7 @@ void WebMediaPlayerImpl::paint(blink::WebCanvas* canvas,
DCHECK(main_task_runner_->BelongsToCurrentThread());
TRACE_EVENT0("media", "WebMediaPlayerImpl:paint");
- if (is_cdm_attached_)
+ if (cdm_)
return;
scoped_refptr<VideoFrame> video_frame = GetCurrentFrameFromCompositor();
@@ -895,8 +892,7 @@ void WebMediaPlayerImpl::setContentDecryptionModule(
if (!was_encrypted && watch_time_reporter_)
CreateWatchTimeReporter();
- SetCdm(BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnCdmAttached),
- ToWebContentDecryptionModuleImpl(cdm)->GetCdmContext());
+ SetCdm(cdm);
}
void WebMediaPlayerImpl::OnEncryptedMediaInitData(
@@ -946,29 +942,54 @@ void WebMediaPlayerImpl::OnFFmpegMediaTracksUpdated(
}
}
-void WebMediaPlayerImpl::SetCdm(const CdmAttachedCB& cdm_attached_cb,
- CdmContext* cdm_context) {
+void WebMediaPlayerImpl::SetCdm(blink::WebContentDecryptionModule* cdm) {
+ DCHECK(main_task_runner_->BelongsToCurrentThread());
+ DCHECK(cdm);
+ scoped_refptr<MediaKeys> cdm_reference =
+ ToWebContentDecryptionModuleImpl(cdm)->GetCdm();
+ if (!cdm_reference) {
+ NOTREACHED();
+ OnCdmAttached(false);
+ return;
+ }
+
+ CdmContext* cdm_context = cdm_reference->GetCdmContext();
if (!cdm_context) {
- cdm_attached_cb.Run(false);
+ OnCdmAttached(false);
return;
}
- // If CDM initialization succeeded, tell the pipeline about it.
- pipeline_.SetCdm(cdm_context, cdm_attached_cb);
+ // Keep the reference to the CDM, as it shouldn't be destroyed until
+ // after the pipeline is done with the |cdm_context|.
+ pending_cdm_ = std::move(cdm_reference);
+ pipeline_.SetCdm(cdm_context,
+ base::Bind(&WebMediaPlayerImpl::OnCdmAttached, AsWeakPtr()));
}
void WebMediaPlayerImpl::OnCdmAttached(bool success) {
+ DCHECK(main_task_runner_->BelongsToCurrentThread());
+ DCHECK(pending_cdm_);
+
+ // If the CDM is set from the constructor there is no promise
+ // (|set_cdm_result_|) to fulfill.
if (success) {
- set_cdm_result_->complete();
- set_cdm_result_.reset();
- is_cdm_attached_ = true;
+ // This will release the previously attached CDM (if any).
+ cdm_ = std::move(pending_cdm_);
+ if (set_cdm_result_) {
+ set_cdm_result_->complete();
+ set_cdm_result_.reset();
+ }
+
return;
}
- set_cdm_result_->completeWithError(
- blink::WebContentDecryptionModuleExceptionNotSupportedError, 0,
- "Unable to set MediaKeys object");
- set_cdm_result_.reset();
+ pending_cdm_ = nullptr;
+ if (set_cdm_result_) {
+ set_cdm_result_->completeWithError(
+ blink::WebContentDecryptionModuleExceptionNotSupportedError, 0,
+ "Unable to set MediaKeys object");
+ set_cdm_result_.reset();
+ }
}
void WebMediaPlayerImpl::OnPipelineSeeked(bool time_updated) {
« no previous file with comments | « media/blink/webmediaplayer_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698