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

Unified Diff: chromecast/media/cma/pipeline/av_pipeline_impl.cc

Issue 974623002: Chromecast: mitigate threading issue between AvPipeline/MediaKeys. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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 | « chromecast/media/cma/pipeline/av_pipeline_impl.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chromecast/media/cma/pipeline/av_pipeline_impl.cc
diff --git a/chromecast/media/cma/pipeline/av_pipeline_impl.cc b/chromecast/media/cma/pipeline/av_pipeline_impl.cc
index 2e2da54facea855610ce4925b4979c3927d82fbb..a90881cca58d9863dcbdc63cfb83acafd675cced 100644
--- a/chromecast/media/cma/pipeline/av_pipeline_impl.cc
+++ b/chromecast/media/cma/pipeline/av_pipeline_impl.cc
@@ -58,8 +58,11 @@ AvPipelineImpl::~AvPipelineImpl() {
DCHECK(thread_checker_.CalledOnValidThread());
media_component_device_->SetClient(MediaComponentDevice::Client());
- if (media_keys_ && media_keys_callback_id_ != kNoCallbackId)
- media_keys_->UnregisterPlayer(media_keys_callback_id_);
+ {
+ base::AutoLock lock(media_keys_lock_);
+ if (media_keys_ && media_keys_callback_id_ != kNoCallbackId)
+ media_keys_->UnregisterPlayer(media_keys_callback_id_);
+ }
}
void AvPipelineImpl::TransitionToState(State state) {
@@ -183,15 +186,18 @@ void AvPipelineImpl::SetCdm(BrowserCdmCast* media_keys) {
DCHECK(thread_checker_.CalledOnValidThread());
DCHECK(media_keys);
- if (media_keys_ && media_keys_callback_id_ != kNoCallbackId)
- media_keys_->UnregisterPlayer(media_keys_callback_id_);
-
- media_keys_ = media_keys;
- media_keys_callback_id_ = media_keys_->RegisterPlayer(
- ::media::BindToCurrentLoop(
- base::Bind(&AvPipelineImpl::OnCdmStateChanged, weak_this_)),
- ::media::BindToCurrentLoop(
- base::Bind(&AvPipelineImpl::OnCdmDestroyed, weak_this_)));
+ {
+ base::AutoLock lock(media_keys_lock_);
+ if (media_keys_ && media_keys_callback_id_ != kNoCallbackId)
+ media_keys_->UnregisterPlayer(media_keys_callback_id_);
+
+ media_keys_ = media_keys;
+ media_keys_callback_id_ = media_keys_->RegisterPlayer(
+ ::media::BindToCurrentLoop(
+ base::Bind(&AvPipelineImpl::OnCdmStateChanged, weak_this_)),
+ // CDM destruction requires immediate update; don't change threads.
lcwu1 2015/03/03 18:52:35 A more detailed explanation of why the unset_cb sh
gunsch 2015/03/03 23:04:19 Done.
+ base::Bind(&AvPipelineImpl::OnCdmDestroyed, weak_this_));
+ }
}
void AvPipelineImpl::OnEos() {
@@ -262,12 +268,15 @@ void AvPipelineImpl::ProcessPendingBuffer() {
// Verify that CDM has the key ID.
// Should not send the frame if the key ID is not available yet.
std::string key_id(pending_buffer_->decrypt_config()->key_id());
- if (!media_keys_) {
- CMALOG(kLogControl) << "No CDM for frame: pts="
- << pending_buffer_->timestamp().InMilliseconds();
- return;
+ {
+ base::AutoLock lock(media_keys_lock_);
+ if (!media_keys_) {
+ CMALOG(kLogControl) << "No CDM for frame: pts="
+ << pending_buffer_->timestamp().InMilliseconds();
+ return;
+ }
+ decrypt_context = media_keys_->GetDecryptContext(key_id);
}
- decrypt_context = media_keys_->GetDecryptContext(key_id);
if (!decrypt_context.get()) {
CMALOG(kLogControl) << "frame(pts="
<< pending_buffer_->timestamp().InMilliseconds()
@@ -329,7 +338,10 @@ void AvPipelineImpl::OnCdmStateChanged() {
void AvPipelineImpl::OnCdmDestroyed() {
DCHECK(thread_checker_.CalledOnValidThread());
lcwu1 2015/03/03 18:52:35 Now that this function can be called from the main
gunsch 2015/03/03 23:04:19 Done.
- media_keys_ = NULL;
+ {
+ base::AutoLock lock(media_keys_lock_);
+ media_keys_ = NULL;
+ }
}
void AvPipelineImpl::OnFrameBuffered(
« no previous file with comments | « chromecast/media/cma/pipeline/av_pipeline_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698