summaryrefslogtreecommitdiffstats
path: root/media/blink
diff options
context:
space:
mode:
authorxhwang <xhwang@chromium.org>2014-11-25 00:44:01 -0800
committerCommit bot <commit-bot@chromium.org>2014-11-25 08:44:53 +0000
commit97de420c168b0650f90c4a05a6e1614cf6684a51 (patch)
treea9faaf885db1f2da9a1aae1bb8f6247db31610d0 /media/blink
parent0951457a3ccedffa92ce1030d7edc13a4c3c47df (diff)
downloadchromium_src-97de420c168b0650f90c4a05a6e1614cf6684a51.zip
chromium_src-97de420c168b0650f90c4a05a6e1614cf6684a51.tar.gz
chromium_src-97de420c168b0650f90c4a05a6e1614cf6684a51.tar.bz2
Handle SetCdm() in media::Renderer.
Changes include: - Pass CdmContext in SetCdm(). - Move SetCdm() handling code from EncryptedMediaPlayerSupport to RendererImpl. - Pass in SetDecryptorReadyCB at initialization time instead of construction time for several classes: VRI/ARI/DecoderStream/DecoderSelector. - Prefixed EME uses the same path to SetCdm(). BUG=401264 TEST=All existing tests pass. Review URL: https://codereview.chromium.org/748863002 Cr-Commit-Position: refs/heads/master@{#305605}
Diffstat (limited to 'media/blink')
-rw-r--r--media/blink/cdm_session_adapter.cc10
-rw-r--r--media/blink/cdm_session_adapter.h12
-rw-r--r--media/blink/encrypted_media_player_support.cc108
-rw-r--r--media/blink/encrypted_media_player_support.h37
-rw-r--r--media/blink/webcontentdecryptionmodule_impl.cc10
-rw-r--r--media/blink/webcontentdecryptionmodule_impl.h20
-rw-r--r--media/blink/webmediaplayer_impl.cc61
-rw-r--r--media/blink/webmediaplayer_impl.h10
8 files changed, 73 insertions, 195 deletions
diff --git a/media/blink/cdm_session_adapter.cc b/media/blink/cdm_session_adapter.cc
index 3804306..43ce395 100644
--- a/media/blink/cdm_session_adapter.cc
+++ b/media/blink/cdm_session_adapter.cc
@@ -127,20 +127,14 @@ void CdmSessionAdapter::GetUsableKeyIds(
media_keys_->GetUsableKeyIds(web_session_id, promise.Pass());
}
-Decryptor* CdmSessionAdapter::GetDecryptor() {
- return media_keys_->GetCdmContext()->GetDecryptor();
+CdmContext* CdmSessionAdapter::GetCdmContext() {
+ return media_keys_->GetCdmContext();
}
const std::string& CdmSessionAdapter::GetKeySystemUMAPrefix() const {
return key_system_uma_prefix_;
}
-#if defined(ENABLE_BROWSER_CDMS)
-int CdmSessionAdapter::GetCdmId() const {
- return media_keys_->GetCdmContext()->GetCdmId();
-}
-#endif // defined(ENABLE_BROWSER_CDMS)
-
void CdmSessionAdapter::OnSessionMessage(const std::string& web_session_id,
const std::vector<uint8>& message,
const GURL& destination_url) {
diff --git a/media/blink/cdm_session_adapter.h b/media/blink/cdm_session_adapter.h
index 8721fc3..bfb5690 100644
--- a/media/blink/cdm_session_adapter.h
+++ b/media/blink/cdm_session_adapter.h
@@ -20,7 +20,6 @@ class GURL;
namespace media {
class CdmFactory;
-class Decryptor;
class WebContentDecryptionModuleSessionImpl;
// Owns the CDM instance and makes calls from session objects to the CDM.
@@ -89,21 +88,14 @@ class CdmSessionAdapter : public base::RefCounted<CdmSessionAdapter> {
void GetUsableKeyIds(const std::string& web_session_id,
scoped_ptr<KeyIdsPromise> promise);
- // Returns the Decryptor associated with this CDM. May be NULL if no
- // Decryptor is associated with the MediaKeys object.
+ // Returns the CdmContext associated with |media_keys_|.
// TODO(jrummell): Figure out lifetimes, as WMPI may still use the decryptor
// after WebContentDecryptionModule is freed. http://crbug.com/330324
- Decryptor* GetDecryptor();
+ CdmContext* GetCdmContext();
// Returns a prefix to use for UMAs.
const std::string& GetKeySystemUMAPrefix() const;
-#if defined(ENABLE_BROWSER_CDMS)
- // Returns the CDM ID associated with the |media_keys_|. May be kInvalidCdmId
- // if no CDM ID is associated.
- int GetCdmId() const;
-#endif
-
private:
friend class base::RefCounted<CdmSessionAdapter>;
typedef base::hash_map<std::string,
diff --git a/media/blink/encrypted_media_player_support.cc b/media/blink/encrypted_media_player_support.cc
index ab4bcb5..bfb6ed5 100644
--- a/media/blink/encrypted_media_player_support.cc
+++ b/media/blink/encrypted_media_player_support.cc
@@ -37,10 +37,6 @@ namespace media {
// Prefix for histograms related to Encrypted Media Extensions.
static const char* kMediaEme = "Media.EME.";
-// Used for calls to decryptor_ready_cb where the result can be ignored.
-static void DoNothing(bool success) {
-}
-
// Convert a WebString to ASCII, falling back on an empty string in the case
// of a non-ASCII string.
static std::string ToASCIIOrEmpty(const WebString& string) {
@@ -120,10 +116,10 @@ static std::string GuessInitDataType(const unsigned char* init_data,
EncryptedMediaPlayerSupport::EncryptedMediaPlayerSupport(
scoped_ptr<CdmFactory> cdm_factory,
blink::WebMediaPlayerClient* client,
- blink::WebContentDecryptionModule* initial_cdm)
+ const SetCdmContextCB& set_cdm_context_cb)
: cdm_factory_(cdm_factory.Pass()),
client_(client),
- web_cdm_(ToWebContentDecryptionModuleImpl(initial_cdm)) {
+ set_cdm_context_cb_(set_cdm_context_cb) {
}
EncryptedMediaPlayerSupport::~EncryptedMediaPlayerSupport() {
@@ -174,9 +170,10 @@ EncryptedMediaPlayerSupport::GenerateKeyRequestInternal(
return WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported;
}
- if (proxy_decryptor_ && !decryptor_ready_cb_.is_null()) {
- base::ResetAndReturn(&decryptor_ready_cb_)
- .Run(proxy_decryptor_->GetDecryptor(), base::Bind(DoNothing));
+ if (proxy_decryptor_ && !set_cdm_context_cb_.is_null()) {
+ base::ResetAndReturn(&set_cdm_context_cb_)
+ .Run(proxy_decryptor_->GetCdmContext(),
+ base::Bind(&IgnoreCdmAttached));
}
current_key_system_ = key_system;
@@ -281,64 +278,6 @@ EncryptedMediaPlayerSupport::CancelKeyRequestInternal(
return WebMediaPlayer::MediaKeyExceptionNoError;
}
-void EncryptedMediaPlayerSupport::SetContentDecryptionModule(
- blink::WebContentDecryptionModule* cdm) {
- // TODO(xhwang): Support setMediaKeys(0) if necessary: http://crbug.com/330324
- if (!cdm)
- return;
-
- web_cdm_ = ToWebContentDecryptionModuleImpl(cdm);
-
- if (web_cdm_ && !decryptor_ready_cb_.is_null())
- base::ResetAndReturn(&decryptor_ready_cb_)
- .Run(web_cdm_->GetDecryptor(), base::Bind(DoNothing));
-}
-
-void EncryptedMediaPlayerSupport::SetContentDecryptionModule(
- blink::WebContentDecryptionModule* cdm,
- blink::WebContentDecryptionModuleResult result) {
- // TODO(xhwang): Support setMediaKeys(0) if necessary: http://crbug.com/330324
- if (!cdm) {
- result.completeWithError(
- blink::WebContentDecryptionModuleExceptionNotSupportedError,
- 0,
- "Null MediaKeys object is not supported.");
- return;
- }
-
- web_cdm_ = ToWebContentDecryptionModuleImpl(cdm);
-
- if (web_cdm_ && !decryptor_ready_cb_.is_null()) {
- base::ResetAndReturn(&decryptor_ready_cb_)
- .Run(web_cdm_->GetDecryptor(), BIND_TO_RENDER_LOOP1(
- &EncryptedMediaPlayerSupport::ContentDecryptionModuleAttached,
- result));
- } else {
- // No pipeline/decoder connected, so resolve the promise. When something
- // is connected, setting the CDM will happen in SetDecryptorReadyCallback().
- ContentDecryptionModuleAttached(result, true);
- }
-}
-
-void EncryptedMediaPlayerSupport::ContentDecryptionModuleAttached(
- blink::WebContentDecryptionModuleResult result,
- bool success) {
- if (success) {
- result.complete();
- return;
- }
-
- result.completeWithError(
- blink::WebContentDecryptionModuleExceptionNotSupportedError,
- 0,
- "Unable to set MediaKeys object");
-}
-
-SetDecryptorReadyCB EncryptedMediaPlayerSupport::CreateSetDecryptorReadyCB() {
- return BIND_TO_RENDER_LOOP(
- &EncryptedMediaPlayerSupport::SetDecryptorReadyCallback);
-}
-
Demuxer::NeedKeyCB EncryptedMediaPlayerSupport::CreateNeedKeyCB() {
return BIND_TO_RENDER_LOOP(&EncryptedMediaPlayerSupport::OnNeedKey);
}
@@ -409,39 +348,4 @@ void EncryptedMediaPlayerSupport::OnKeyMessage(
destination_url);
}
-void EncryptedMediaPlayerSupport::SetDecryptorReadyCallback(
- const DecryptorReadyCB& decryptor_ready_cb) {
- // Cancels the previous decryptor request.
- if (decryptor_ready_cb.is_null()) {
- if (!decryptor_ready_cb_.is_null()) {
- base::ResetAndReturn(&decryptor_ready_cb_)
- .Run(NULL, base::Bind(DoNothing));
- }
- return;
- }
-
- // TODO(xhwang): Support multiple decryptor notification request (e.g. from
- // video and audio). The current implementation is okay for the current
- // media pipeline since we initialize audio and video decoders in sequence.
- // But WebMediaPlayerImpl should not depend on media pipeline's implementation
- // detail.
- DCHECK(decryptor_ready_cb_.is_null());
-
- // Mixed use of prefixed and unprefixed EME APIs is disallowed by Blink.
- DCHECK(!proxy_decryptor_ || !web_cdm_);
-
- if (proxy_decryptor_) {
- decryptor_ready_cb.Run(proxy_decryptor_->GetDecryptor(),
- base::Bind(DoNothing));
- return;
- }
-
- if (web_cdm_) {
- decryptor_ready_cb.Run(web_cdm_->GetDecryptor(), base::Bind(DoNothing));
- return;
- }
-
- decryptor_ready_cb_ = decryptor_ready_cb;
-}
-
} // namespace media
diff --git a/media/blink/encrypted_media_player_support.h b/media/blink/encrypted_media_player_support.h
index 4f4c937..a80ff58 100644
--- a/media/blink/encrypted_media_player_support.h
+++ b/media/blink/encrypted_media_player_support.h
@@ -8,8 +8,10 @@
#include <string>
#include <vector>
+#include "base/callback.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
+#include "media/base/cdm_context.h"
#include "media/base/cdm_factory.h"
#include "media/base/demuxer.h"
#include "media/cdm/proxy_decryptor.h"
@@ -27,12 +29,20 @@ namespace media {
class WebContentDecryptionModuleImpl;
+// Provides support to prefixed EME implementation.
+// Do NOT add unprefixed EME functionality to this class!
+// TODO(xhwang): Move CreateNeedKeyCB() outside this class. Then when we
+// deprecate prefixed EME support, drop this whole file.
+
class EncryptedMediaPlayerSupport
: public base::SupportsWeakPtr<EncryptedMediaPlayerSupport> {
public:
+ typedef base::Callback<void(CdmContext*, const CdmAttachedCB&)>
+ SetCdmContextCB;
+
EncryptedMediaPlayerSupport(scoped_ptr<CdmFactory> cdm_factory,
blink::WebMediaPlayerClient* client,
- blink::WebContentDecryptionModule* initial_cdm);
+ const SetCdmContextCB& set_cdm_context_cb);
~EncryptedMediaPlayerSupport();
blink::WebMediaPlayer::MediaKeyException GenerateKeyRequest(
@@ -53,24 +63,11 @@ class EncryptedMediaPlayerSupport
const blink::WebString& key_system,
const blink::WebString& session_id);
- void SetContentDecryptionModule(
- blink::WebContentDecryptionModule* cdm);
- void SetContentDecryptionModule(
- blink::WebContentDecryptionModule* cdm,
- blink::WebContentDecryptionModuleResult result);
-
- SetDecryptorReadyCB CreateSetDecryptorReadyCB();
Demuxer::NeedKeyCB CreateNeedKeyCB();
void OnPipelineDecryptError();
private:
- // Requests that this object notifies when a decryptor is ready through the
- // |decryptor_ready_cb| provided.
- // If |decryptor_ready_cb| is null, the existing callback will be fired with
- // NULL immediately and reset.
- void SetDecryptorReadyCallback(const DecryptorReadyCB& decryptor_ready_cb);
-
blink::WebMediaPlayer::MediaKeyException GenerateKeyRequestInternal(
blink::WebLocalFrame* frame,
const std::string& key_system,
@@ -100,10 +97,6 @@ class EncryptedMediaPlayerSupport
const std::vector<uint8>& message,
const GURL& destination_url);
- void ContentDecryptionModuleAttached(
- blink::WebContentDecryptionModuleResult result,
- bool success);
-
scoped_ptr<CdmFactory> cdm_factory_;
blink::WebMediaPlayerClient* client_;
@@ -116,15 +109,11 @@ class EncryptedMediaPlayerSupport
// through GenerateKeyRequest() directly from WebKit.
std::string init_data_type_;
+ SetCdmContextCB set_cdm_context_cb_;
+
// Manages decryption keys and decrypts encrypted frames.
scoped_ptr<ProxyDecryptor> proxy_decryptor_;
- // Non-owned pointer to the CDM. Updated via calls to
- // setContentDecryptionModule().
- WebContentDecryptionModuleImpl* web_cdm_;
-
- DecryptorReadyCB decryptor_ready_cb_;
-
DISALLOW_COPY_AND_ASSIGN(EncryptedMediaPlayerSupport);
};
diff --git a/media/blink/webcontentdecryptionmodule_impl.cc b/media/blink/webcontentdecryptionmodule_impl.cc
index 70002d4..e2fa8aa 100644
--- a/media/blink/webcontentdecryptionmodule_impl.cc
+++ b/media/blink/webcontentdecryptionmodule_impl.cc
@@ -91,14 +91,8 @@ void WebContentDecryptionModuleImpl::setServerCertificate(
new CdmResultPromise<>(result, std::string())));
}
-Decryptor* WebContentDecryptionModuleImpl::GetDecryptor() {
- return adapter_->GetDecryptor();
+CdmContext* WebContentDecryptionModuleImpl::GetCdmContext() {
+ return adapter_->GetCdmContext();
}
-#if defined(ENABLE_BROWSER_CDMS)
-int WebContentDecryptionModuleImpl::GetCdmId() const {
- return adapter_->GetCdmId();
-}
-#endif // defined(ENABLE_BROWSER_CDMS)
-
} // namespace media
diff --git a/media/blink/webcontentdecryptionmodule_impl.h b/media/blink/webcontentdecryptionmodule_impl.h
index 38388c4..bf1915e 100644
--- a/media/blink/webcontentdecryptionmodule_impl.h
+++ b/media/blink/webcontentdecryptionmodule_impl.h
@@ -21,10 +21,9 @@ class WebSecurityOrigin;
namespace media {
+class CdmContext;
class CdmFactory;
class CdmSessionAdapter;
-class Decryptor;
-class MediaKeys;
class WebContentDecryptionModuleSessionImpl;
class MEDIA_EXPORT WebContentDecryptionModuleImpl
@@ -37,18 +36,6 @@ class MEDIA_EXPORT WebContentDecryptionModuleImpl
virtual ~WebContentDecryptionModuleImpl();
- // Returns the Decryptor associated with this CDM. May be NULL if no
- // Decryptor associated with the MediaKeys object.
- // TODO(jrummell): Figure out lifetimes, as WMPI may still use the decryptor
- // after WebContentDecryptionModule is freed. http://crbug.com/330324
- Decryptor* GetDecryptor();
-
-#if defined(ENABLE_BROWSER_CDMS)
- // Returns the CDM ID associated with this object. May be kInvalidCdmId if no
- // CDM ID is associated, such as when Clear Key is used.
- int GetCdmId() const;
-#endif // defined(ENABLE_BROWSER_CDMS)
-
// blink::WebContentDecryptionModule implementation.
virtual blink::WebContentDecryptionModuleSession* createSession();
// TODO(jrummell): Remove this method once blink updated.
@@ -60,6 +47,11 @@ class MEDIA_EXPORT WebContentDecryptionModuleImpl
size_t server_certificate_length,
blink::WebContentDecryptionModuleResult result);
+ // Returns the CdmContext associated with this CDM, which must not be nullptr.
+ // TODO(jrummell): Figure out lifetimes, as WMPI may still use the decryptor
+ // after WebContentDecryptionModule is freed. http://crbug.com/330324
+ CdmContext* GetCdmContext();
+
private:
// Takes reference to |adapter|.
WebContentDecryptionModuleImpl(scoped_refptr<CdmSessionAdapter> adapter);
diff --git a/media/blink/webmediaplayer_impl.cc b/media/blink/webmediaplayer_impl.cc
index 0d9a6a3..56c467d 100644
--- a/media/blink/webmediaplayer_impl.cc
+++ b/media/blink/webmediaplayer_impl.cc
@@ -36,6 +36,7 @@
#include "media/blink/encrypted_media_player_support.h"
#include "media/blink/texttrack_impl.h"
#include "media/blink/webaudiosourceprovider_impl.h"
+#include "media/blink/webcontentdecryptionmodule_impl.h"
#include "media/blink/webinbandtexttrack_impl.h"
#include "media/blink/webmediaplayer_delegate.h"
#include "media/blink/webmediaplayer_params.h"
@@ -168,9 +169,10 @@ WebMediaPlayerImpl::WebMediaPlayerImpl(
BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnNaturalSizeChanged),
BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnOpacityChanged))),
text_track_index_(0),
- encrypted_media_support_(cdm_factory.Pass(),
- client,
- params.initial_cdm()),
+ encrypted_media_support_(
+ cdm_factory.Pass(),
+ client,
+ base::Bind(&WebMediaPlayerImpl::SetCdm, AsWeakPtr())),
audio_hardware_config_(params.audio_hardware_config()),
renderer_(renderer.Pass()) {
// Threaded compositing isn't enabled universally yet.
@@ -674,18 +676,38 @@ WebMediaPlayer::MediaKeyException WebMediaPlayerImpl::cancelKeyRequest(
}
void WebMediaPlayerImpl::setContentDecryptionModule(
- blink::WebContentDecryptionModule* cdm) {
+ blink::WebContentDecryptionModule* cdm,
+ blink::WebContentDecryptionModuleResult result) {
DCHECK(main_task_runner_->BelongsToCurrentThread());
- encrypted_media_support_.SetContentDecryptionModule(cdm);
+ // TODO(xhwang): Support setMediaKeys(0) if necessary: http://crbug.com/330324
+ if (!cdm) {
+ result.completeWithError(
+ blink::WebContentDecryptionModuleExceptionNotSupportedError, 0,
+ "Null MediaKeys object is not supported.");
+ return;
+ }
+
+ SetCdm(ToWebContentDecryptionModuleImpl(cdm)->GetCdmContext(),
+ BIND_TO_RENDER_LOOP1(&WebMediaPlayerImpl::OnCdmAttached, result));
}
-void WebMediaPlayerImpl::setContentDecryptionModule(
- blink::WebContentDecryptionModule* cdm,
- blink::WebContentDecryptionModuleResult result) {
- DCHECK(main_task_runner_->BelongsToCurrentThread());
+void WebMediaPlayerImpl::SetCdm(CdmContext* cdm_context,
+ const CdmAttachedCB& cdm_attached_cb) {
+ pipeline_.SetCdm(cdm_context, cdm_attached_cb);
+}
- encrypted_media_support_.SetContentDecryptionModule(cdm, result);
+void WebMediaPlayerImpl::OnCdmAttached(
+ blink::WebContentDecryptionModuleResult result,
+ bool success) {
+ if (success) {
+ result.complete();
+ return;
+ }
+
+ result.completeWithError(
+ blink::WebContentDecryptionModuleExceptionNotSupportedError, 0,
+ "Unable to set MediaKeys object");
}
void WebMediaPlayerImpl::OnPipelineSeeked(bool time_changed,
@@ -841,9 +863,6 @@ void WebMediaPlayerImpl::NotifyDownloading(bool is_downloading) {
// TODO(xhwang): Move this to a factory class so that we can create different
// renderers.
scoped_ptr<Renderer> WebMediaPlayerImpl::CreateRenderer() {
- SetDecryptorReadyCB set_decryptor_ready_cb =
- encrypted_media_support_.CreateSetDecryptorReadyCB();
-
// Create our audio decoders and renderer.
ScopedVector<AudioDecoder> audio_decoders;
@@ -851,13 +870,9 @@ scoped_ptr<Renderer> WebMediaPlayerImpl::CreateRenderer() {
media_task_runner_, base::Bind(&LogMediaSourceError, media_log_)));
audio_decoders.push_back(new OpusAudioDecoder(media_task_runner_));
- scoped_ptr<AudioRenderer> audio_renderer(
- new AudioRendererImpl(media_task_runner_,
- audio_source_provider_.get(),
- audio_decoders.Pass(),
- set_decryptor_ready_cb,
- audio_hardware_config_,
- media_log_));
+ scoped_ptr<AudioRenderer> audio_renderer(new AudioRendererImpl(
+ media_task_runner_, audio_source_provider_.get(), audio_decoders.Pass(),
+ audio_hardware_config_, media_log_));
// Create our video decoders and renderer.
ScopedVector<VideoDecoder> video_decoders;
@@ -872,11 +887,7 @@ scoped_ptr<Renderer> WebMediaPlayerImpl::CreateRenderer() {
video_decoders.push_back(new FFmpegVideoDecoder(media_task_runner_));
scoped_ptr<VideoRenderer> video_renderer(new VideoRendererImpl(
- media_task_runner_,
- video_decoders.Pass(),
- set_decryptor_ready_cb,
- true,
- media_log_));
+ media_task_runner_, video_decoders.Pass(), true, media_log_));
// Create renderer.
return scoped_ptr<Renderer>(new RendererImpl(
diff --git a/media/blink/webmediaplayer_impl.h b/media/blink/webmediaplayer_impl.h
index 674a378..596df9e 100644
--- a/media/blink/webmediaplayer_impl.h
+++ b/media/blink/webmediaplayer_impl.h
@@ -156,10 +156,6 @@ class MEDIA_EXPORT WebMediaPlayerImpl
const blink::WebString& key_system,
const blink::WebString& session_id);
- // TODO(jrummell): Remove this method once Blink updated to use the other
- // method.
- virtual void setContentDecryptionModule(
- blink::WebContentDecryptionModule* cdm);
virtual void setContentDecryptionModule(
blink::WebContentDecryptionModule* cdm,
blink::WebContentDecryptionModuleResult result);
@@ -213,6 +209,12 @@ class MEDIA_EXPORT WebMediaPlayerImpl
// compositor can return the frame.
scoped_refptr<VideoFrame> GetCurrentFrameFromCompositor();
+ void SetCdm(CdmContext* cdm_context, const CdmAttachedCB& cdm_attached_cb);
+
+ // Called when a CDM has been attached to the |pipeline_|.
+ void OnCdmAttached(blink::WebContentDecryptionModuleResult result,
+ bool success);
+
blink::WebLocalFrame* frame_;
// TODO(hclam): get rid of these members and read from the pipeline directly.