diff options
Diffstat (limited to 'media/blink/encrypted_media_player_support.h')
-rw-r--r-- | media/blink/encrypted_media_player_support.h | 121 |
1 files changed, 87 insertions, 34 deletions
diff --git a/media/blink/encrypted_media_player_support.h b/media/blink/encrypted_media_player_support.h index 737720d..4f4c937 100644 --- a/media/blink/encrypted_media_player_support.h +++ b/media/blink/encrypted_media_player_support.h @@ -5,14 +5,19 @@ #ifndef MEDIA_BLINK_ENCRYPTED_MEDIA_PLAYER_SUPPORT_H_ #define MEDIA_BLINK_ENCRYPTED_MEDIA_PLAYER_SUPPORT_H_ -#include "media/base/decryptor.h" +#include <string> +#include <vector> + +#include "base/memory/scoped_ptr.h" +#include "base/memory/weak_ptr.h" +#include "media/base/cdm_factory.h" #include "media/base/demuxer.h" -#include "media/base/media_export.h" +#include "media/cdm/proxy_decryptor.h" +#include "third_party/WebKit/public/platform/WebContentDecryptionModuleResult.h" #include "third_party/WebKit/public/platform/WebMediaPlayer.h" namespace blink { class WebContentDecryptionModule; -class WebContentDecryptionModuleResult; class WebLocalFrame; class WebMediaPlayerClient; class WebString; @@ -20,58 +25,106 @@ class WebString; namespace media { -class MEDIA_EXPORT EncryptedMediaPlayerSupport { +class WebContentDecryptionModuleImpl; + +class EncryptedMediaPlayerSupport + : public base::SupportsWeakPtr<EncryptedMediaPlayerSupport> { public: - EncryptedMediaPlayerSupport(); - virtual ~EncryptedMediaPlayerSupport(); + EncryptedMediaPlayerSupport(scoped_ptr<CdmFactory> cdm_factory, + blink::WebMediaPlayerClient* client, + blink::WebContentDecryptionModule* initial_cdm); + ~EncryptedMediaPlayerSupport(); - // Prefixed API methods. - virtual blink::WebMediaPlayer::MediaKeyException GenerateKeyRequest( + blink::WebMediaPlayer::MediaKeyException GenerateKeyRequest( blink::WebLocalFrame* frame, const blink::WebString& key_system, const unsigned char* init_data, - unsigned init_data_length) = 0; + unsigned init_data_length); - virtual blink::WebMediaPlayer::MediaKeyException AddKey( + blink::WebMediaPlayer::MediaKeyException AddKey( const blink::WebString& key_system, const unsigned char* key, unsigned key_length, const unsigned char* init_data, unsigned init_data_length, - const blink::WebString& session_id) = 0; + const blink::WebString& session_id); - virtual blink::WebMediaPlayer::MediaKeyException CancelKeyRequest( + blink::WebMediaPlayer::MediaKeyException CancelKeyRequest( const blink::WebString& key_system, - const blink::WebString& session_id) = 0; - + const blink::WebString& session_id); - // Unprefixed API methods. - virtual void SetInitialContentDecryptionModule( - blink::WebContentDecryptionModule* initial_cdm) = 0; - virtual void SetContentDecryptionModule( - blink::WebContentDecryptionModule* cdm) = 0; - virtual void SetContentDecryptionModule( + void SetContentDecryptionModule( + blink::WebContentDecryptionModule* cdm); + void SetContentDecryptionModule( blink::WebContentDecryptionModule* cdm, - blink::WebContentDecryptionModuleResult result) = 0; + blink::WebContentDecryptionModuleResult result); + SetDecryptorReadyCB CreateSetDecryptorReadyCB(); + Demuxer::NeedKeyCB CreateNeedKeyCB(); - // Callback factory and notification methods used by WebMediaPlayerImpl. + void OnPipelineDecryptError(); - // Creates a callback that Demuxers can use to signal that the content - // requires a key. This method make sure the callback returned can be safely - // invoked from any thread. - virtual Demuxer::NeedKeyCB CreateNeedKeyCB() = 0; + 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); - // Creates a callback that renderers can use to set decryptor - // ready callback. This method make sure the callback returned can be safely - // invoked from any thread. - virtual SetDecryptorReadyCB CreateSetDecryptorReadyCB() = 0; + blink::WebMediaPlayer::MediaKeyException GenerateKeyRequestInternal( + blink::WebLocalFrame* frame, + const std::string& key_system, + const unsigned char* init_data, + unsigned init_data_length); - // Called to inform this object that the media pipeline encountered - // and handled a decryption error. - virtual void OnPipelineDecryptError() = 0; + blink::WebMediaPlayer::MediaKeyException AddKeyInternal( + const std::string& key_system, + const unsigned char* key, + unsigned key_length, + const unsigned char* init_data, + unsigned init_data_length, + const std::string& session_id); + + blink::WebMediaPlayer::MediaKeyException CancelKeyRequestInternal( + 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, + uint32 system_code); + void OnKeyMessage(const std::string& session_id, + const std::vector<uint8>& message, + const GURL& destination_url); + + void ContentDecryptionModuleAttached( + blink::WebContentDecryptionModuleResult result, + bool success); + + scoped_ptr<CdmFactory> cdm_factory_; + + blink::WebMediaPlayerClient* client_; + + // The currently selected key system. Empty string means that no key system + // 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. + std::string init_data_type_; + + // 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_; - private: DISALLOW_COPY_AND_ASSIGN(EncryptedMediaPlayerSupport); }; |