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

Unified Diff: media/base/android/media_source_player.cc

Issue 1407933010: media: Make MediaKeys ref-counted. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase only Created 5 years, 1 month 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/base/android/media_source_player.h ('k') | media/base/browser_cdm.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/base/android/media_source_player.cc
diff --git a/media/base/android/media_source_player.cc b/media/base/android/media_source_player.cc
index d4408b31396a02d90d20e912e1b75951d6950af6..fd52bba4662fc47d321d82835ee0cffb8d295f65 100644
--- a/media/base/android/media_source_player.cc
+++ b/media/base/android/media_source_player.cc
@@ -11,6 +11,7 @@
#include "base/barrier_closure.h"
#include "base/basictypes.h"
#include "base/bind.h"
+#include "base/bind_helpers.h"
#include "base/callback_helpers.h"
#include "base/logging.h"
#include "base/strings/string_number_conversions.h"
@@ -39,7 +40,6 @@ MediaSourcePlayer::MediaSourcePlayer(
interpolator_(&default_tick_clock_),
doing_browser_seek_(false),
pending_seek_(false),
- drm_bridge_(NULL),
cdm_registration_id_(0),
is_waiting_for_key_(false),
key_added_while_decode_pending_(false),
@@ -69,9 +69,10 @@ MediaSourcePlayer::MediaSourcePlayer(
MediaSourcePlayer::~MediaSourcePlayer() {
Release();
- DCHECK_EQ(!drm_bridge_, !cdm_registration_id_);
- if (drm_bridge_) {
- drm_bridge_->UnregisterPlayer(cdm_registration_id_);
+ DCHECK_EQ(!cdm_, !cdm_registration_id_);
+ if (cdm_) {
+ static_cast<MediaDrmBridge*>(cdm_.get())
+ ->UnregisterPlayer(cdm_registration_id_);
cdm_registration_id_ = 0;
}
}
@@ -267,13 +268,15 @@ void MediaSourcePlayer::OnMediaCryptoReady(
bool /* needs_protected_surface */) {
// Callback parameters are ignored in this player. They are intended for
// MediaCodecPlayer which uses a different threading scheme.
- DCHECK(!drm_bridge_->GetMediaCrypto().is_null());
+ DCHECK(!static_cast<MediaDrmBridge*>(cdm_.get())->GetMediaCrypto().is_null());
// Retry decoder creation if the decoders are waiting for MediaCrypto.
RetryDecoderCreation(true, true);
}
-void MediaSourcePlayer::SetCdm(BrowserCdm* cdm) {
+void MediaSourcePlayer::SetCdm(const scoped_refptr<MediaKeys>& cdm) {
+ DCHECK(cdm);
+
// Currently we don't support DRM change during the middle of playback, even
// if the player is paused.
// TODO(qinmin): support DRM change after playback has started.
@@ -283,25 +286,29 @@ void MediaSourcePlayer::SetCdm(BrowserCdm* cdm) {
<< "This is not well supported!";
}
- if (drm_bridge_) {
+ if (cdm_) {
NOTREACHED() << "Currently we do not support resetting CDM.";
return;
}
+ cdm_ = cdm;
+
// Only MediaDrmBridge will be set on MediaSourcePlayer.
- drm_bridge_ = static_cast<MediaDrmBridge*>(cdm);
+ MediaDrmBridge* drm_bridge = static_cast<MediaDrmBridge*>(cdm_.get());
- cdm_registration_id_ = drm_bridge_->RegisterPlayer(
+ // No need to set |cdm_unset_cb| since |this| holds a reference to the |cdm_|.
+ cdm_registration_id_ = drm_bridge->RegisterPlayer(
base::Bind(&MediaSourcePlayer::OnKeyAdded, weak_this_),
- base::Bind(&MediaSourcePlayer::OnCdmUnset, weak_this_));
+ base::Bind(&base::DoNothing));
- audio_decoder_job_->SetDrmBridge(drm_bridge_);
- video_decoder_job_->SetDrmBridge(drm_bridge_);
+ audio_decoder_job_->SetDrmBridge(drm_bridge);
+ video_decoder_job_->SetDrmBridge(drm_bridge);
- if (drm_bridge_->GetMediaCrypto().is_null()) {
+ if (drm_bridge->GetMediaCrypto().is_null()) {
+ // Use BindToCurrentLoop to avoid reentrancy.
MediaDrmBridge::MediaCryptoReadyCB cb = BindToCurrentLoop(
base::Bind(&MediaSourcePlayer::OnMediaCryptoReady, weak_this_));
- drm_bridge_->SetMediaCryptoReadyCB(cb);
+ drm_bridge->SetMediaCryptoReadyCB(cb);
return;
}
@@ -835,18 +842,4 @@ void MediaSourcePlayer::ResumePlaybackAfterKeyAdded() {
StartInternal();
}
-void MediaSourcePlayer::OnCdmUnset() {
- DVLOG(1) << __FUNCTION__;
- DCHECK(drm_bridge_);
- // TODO(xhwang): Currently this is only called during teardown. Support full
- // detachment of CDM during playback. This will be needed when we start to
- // support setMediaKeys(0) (see http://crbug.com/330324), or when we release
- // MediaDrm when the video is paused, or when the device goes to sleep (see
- // http://crbug.com/272421).
- audio_decoder_job_->SetDrmBridge(NULL);
- video_decoder_job_->SetDrmBridge(NULL);
- cdm_registration_id_ = 0;
- drm_bridge_ = NULL;
-}
-
} // namespace media
« no previous file with comments | « media/base/android/media_source_player.h ('k') | media/base/browser_cdm.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698