diff options
author | xhwang <xhwang@chromium.org> | 2014-12-02 15:49:50 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-12-02 23:50:04 +0000 |
commit | bab66f5a4aac5b611ea0008f322391e0bb25eaff (patch) | |
tree | aa8d09836ab1bf0e08bc5c04e6a18bd4df2e442c /media/blink | |
parent | ef7b79065bed0e271e997fe2c002c5d16159f836 (diff) | |
download | chromium_src-bab66f5a4aac5b611ea0008f322391e0bb25eaff.zip chromium_src-bab66f5a4aac5b611ea0008f322391e0bb25eaff.tar.gz chromium_src-bab66f5a4aac5b611ea0008f322391e0bb25eaff.tar.bz2 |
Move OnNeedKey() to WebMediaPlayerImpl.
OnNeedKey() is needed for both prefixed and unprefixed EME. Move it out of EncryptedMediaPlayerSupport so that EncryptedMediaPlayerSupport is for prefixed EME only.
BUG=249976
Review URL: https://codereview.chromium.org/759933003
Cr-Commit-Position: refs/heads/master@{#306493}
Diffstat (limited to 'media/blink')
-rw-r--r-- | media/blink/encrypted_media_player_support.cc | 43 | ||||
-rw-r--r-- | media/blink/encrypted_media_player_support.h | 13 | ||||
-rw-r--r-- | media/blink/webmediaplayer_impl.cc | 23 | ||||
-rw-r--r-- | media/blink/webmediaplayer_impl.h | 4 |
4 files changed, 42 insertions, 41 deletions
diff --git a/media/blink/encrypted_media_player_support.cc b/media/blink/encrypted_media_player_support.cc index bfb6ed5..01422e5 100644 --- a/media/blink/encrypted_media_player_support.cc +++ b/media/blink/encrypted_media_player_support.cc @@ -20,7 +20,6 @@ #include "third_party/WebKit/public/platform/WebMediaPlayerClient.h" #include "third_party/WebKit/public/web/WebDocument.h" #include "third_party/WebKit/public/web/WebLocalFrame.h" -#include "third_party/WebKit/public/web/WebRuntimeFeatures.h" using blink::WebMediaPlayer; using blink::WebMediaPlayerClient; @@ -138,9 +137,8 @@ EncryptedMediaPlayerSupport::GenerateKeyRequest( std::string ascii_key_system = GetUnprefixedKeySystemName(ToASCIIOrEmpty(key_system)); - WebMediaPlayer::MediaKeyException e = - GenerateKeyRequestInternal(frame, ascii_key_system, init_data, - init_data_length); + WebMediaPlayer::MediaKeyException e = GenerateKeyRequestInternal( + frame, ascii_key_system, init_data, init_data_length); ReportMediaKeyExceptionToUMA("generateKeyRequest", ascii_key_system, e); return e; } @@ -185,11 +183,8 @@ EncryptedMediaPlayerSupport::GenerateKeyRequestInternal( if (init_data_type.empty()) init_data_type = GuessInitDataType(init_data, init_data_length); - // TODO(xhwang): We assume all streams are from the same container (thus have - // the same "type") for now. In the future, the "type" should be passed down - // from the application. - if (!proxy_decryptor_->GenerateKeyRequest( - init_data_type, init_data, init_data_length)) { + if (!proxy_decryptor_->GenerateKeyRequest(init_data_type, init_data, + init_data_length)) { current_key_system_.clear(); return WebMediaPlayer::MediaKeyExceptionKeySystemNotSupported; } @@ -278,34 +273,20 @@ EncryptedMediaPlayerSupport::CancelKeyRequestInternal( return WebMediaPlayer::MediaKeyExceptionNoError; } -Demuxer::NeedKeyCB EncryptedMediaPlayerSupport::CreateNeedKeyCB() { - return BIND_TO_RENDER_LOOP(&EncryptedMediaPlayerSupport::OnNeedKey); +void EncryptedMediaPlayerSupport::SetInitDataType( + const std::string& init_data_type) { + DCHECK(!init_data_type.empty()); + DLOG_IF(WARNING, + !init_data_type_.empty() && init_data_type != init_data_type_) + << "Mixed init data type not supported. The new type is ignored."; + if (init_data_type_.empty()) + init_data_type_ = init_data_type; } void EncryptedMediaPlayerSupport::OnPipelineDecryptError() { EmeUMAHistogramCounts(current_key_system_, "DecryptError", 1); } -void EncryptedMediaPlayerSupport::OnNeedKey( - const std::string& type, - const std::vector<uint8>& init_data) { - // Do not fire NeedKey event if encrypted media is not enabled. - if (!blink::WebRuntimeFeatures::isPrefixedEncryptedMediaEnabled() && - !blink::WebRuntimeFeatures::isEncryptedMediaEnabled()) { - return; - } - - UMA_HISTOGRAM_COUNTS(kMediaEme + std::string("NeedKey"), 1); - - DCHECK(init_data_type_.empty() || type.empty() || type == init_data_type_); - if (init_data_type_.empty()) - init_data_type_ = type; - - const uint8* init_data_ptr = init_data.empty() ? NULL : &init_data[0]; - client_->encrypted(WebString::fromUTF8(type), init_data_ptr, - base::saturated_cast<unsigned int>(init_data.size())); -} - void EncryptedMediaPlayerSupport::OnKeyAdded(const std::string& session_id) { EmeUMAHistogramCounts(current_key_system_, "KeyAdded", 1); client_->keyAdded( diff --git a/media/blink/encrypted_media_player_support.h b/media/blink/encrypted_media_player_support.h index a80ff58..c261ec3 100644 --- a/media/blink/encrypted_media_player_support.h +++ b/media/blink/encrypted_media_player_support.h @@ -31,9 +31,7 @@ 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. - +// TODO(xhwang): When deprecating prefixed EME support, drop this whole file. class EncryptedMediaPlayerSupport : public base::SupportsWeakPtr<EncryptedMediaPlayerSupport> { public: @@ -63,7 +61,7 @@ class EncryptedMediaPlayerSupport const blink::WebString& key_system, const blink::WebString& session_id); - Demuxer::NeedKeyCB CreateNeedKeyCB(); + void SetInitDataType(const std::string& init_data_type); void OnPipelineDecryptError(); @@ -86,9 +84,6 @@ class EncryptedMediaPlayerSupport const std::string& key_system, const std::string& session_id); - void OnNeedKey(const std::string& type, - const std::vector<uint8>& init_data); - void OnKeyAdded(const std::string& session_id); void OnKeyError(const std::string& session_id, MediaKeys::KeyError error_code, @@ -105,8 +100,8 @@ class EncryptedMediaPlayerSupport // has been selected. std::string current_key_system_; - // Temporary for EME v0.1. In the future the init data type should be passed - // through GenerateKeyRequest() directly from WebKit. + // We assume all streams are from the same container, thus have the same + // init data type. std::string init_data_type_; SetCdmContextCB set_cdm_context_cb_; diff --git a/media/blink/webmediaplayer_impl.cc b/media/blink/webmediaplayer_impl.cc index 74db5fe..b862928 100644 --- a/media/blink/webmediaplayer_impl.cc +++ b/media/blink/webmediaplayer_impl.cc @@ -60,6 +60,7 @@ #include "third_party/WebKit/public/platform/WebString.h" #include "third_party/WebKit/public/platform/WebURL.h" #include "third_party/WebKit/public/web/WebLocalFrame.h" +#include "third_party/WebKit/public/web/WebRuntimeFeatures.h" #include "third_party/WebKit/public/web/WebSecurityOrigin.h" #include "third_party/WebKit/public/web/WebView.h" @@ -699,6 +700,26 @@ void WebMediaPlayerImpl::setContentDecryptionModule( BIND_TO_RENDER_LOOP1(&WebMediaPlayerImpl::OnCdmAttached, result)); } +void WebMediaPlayerImpl::OnNeedKey(const std::string& init_data_type, + const std::vector<uint8>& init_data) { + DCHECK(!init_data_type.empty()); + + // Do not fire NeedKey event if encrypted media is not enabled. + // TODO(xhwang): Handle this in |client_|. + if (!blink::WebRuntimeFeatures::isPrefixedEncryptedMediaEnabled() && + !blink::WebRuntimeFeatures::isEncryptedMediaEnabled()) { + return; + } + + UMA_HISTOGRAM_COUNTS("Media.EME.NeedKey", 1); + + encrypted_media_support_.SetInitDataType(init_data_type); + + const uint8* init_data_ptr = init_data.empty() ? nullptr : &init_data[0]; + client_->encrypted(WebString::fromUTF8(init_data_type), init_data_ptr, + base::saturated_cast<unsigned int>(init_data.size())); +} + void WebMediaPlayerImpl::SetCdm(CdmContext* cdm_context, const CdmAttachedCB& cdm_attached_cb) { pipeline_.SetCdm(cdm_context, cdm_attached_cb); @@ -910,7 +931,7 @@ void WebMediaPlayerImpl::StartPipeline() { LogCB mse_log_cb; Demuxer::NeedKeyCB need_key_cb = - encrypted_media_support_.CreateNeedKeyCB(); + BIND_TO_RENDER_LOOP(&WebMediaPlayerImpl::OnNeedKey); // Figure out which demuxer to use. if (load_type_ != LoadTypeMediaSource) { diff --git a/media/blink/webmediaplayer_impl.h b/media/blink/webmediaplayer_impl.h index 596df9e..466b566 100644 --- a/media/blink/webmediaplayer_impl.h +++ b/media/blink/webmediaplayer_impl.h @@ -209,6 +209,10 @@ class MEDIA_EXPORT WebMediaPlayerImpl // compositor can return the frame. scoped_refptr<VideoFrame> GetCurrentFrameFromCompositor(); + // Called when the demuxer encounters encrypted streams. + void OnNeedKey(const std::string& init_data_type, + const std::vector<uint8>& init_data); + void SetCdm(CdmContext* cdm_context, const CdmAttachedCB& cdm_attached_cb); // Called when a CDM has been attached to the |pipeline_|. |