summaryrefslogtreecommitdiffstats
path: root/chromium/content/renderer/pepper/content_decryptor_delegate.h
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/content/renderer/pepper/content_decryptor_delegate.h')
-rw-r--r--chromium/content/renderer/pepper/content_decryptor_delegate.h135
1 files changed, 97 insertions, 38 deletions
diff --git a/chromium/content/renderer/pepper/content_decryptor_delegate.h b/chromium/content/renderer/pepper/content_decryptor_delegate.h
index 352817dd011..182d6a66257 100644
--- a/chromium/content/renderer/pepper/content_decryptor_delegate.h
+++ b/chromium/content/renderer/pepper/content_decryptor_delegate.h
@@ -5,13 +5,18 @@
#ifndef CONTENT_RENDERER_PEPPER_CONTENT_DECRYPTOR_DELEGATE_H_
#define CONTENT_RENDERER_PEPPER_CONTENT_DECRYPTOR_DELEGATE_H_
+#include <map>
#include <queue>
#include <string>
#include "base/basictypes.h"
+#include "base/callback_helpers.h"
#include "base/compiler_specific.h"
+#include "base/containers/scoped_ptr_hash_map.h"
#include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h"
+#include "media/base/cdm_promise.h"
+#include "media/base/channel_layout.h"
#include "media/base/decryptor.h"
#include "media/base/media_keys.h"
#include "media/base/sample_format.h"
@@ -39,24 +44,30 @@ class ContentDecryptorDelegate {
const PPP_ContentDecryptor_Private* plugin_decryption_interface);
~ContentDecryptorDelegate();
- void Initialize(const std::string& key_system);
+ // This object should not be accessed after |fatal_plugin_error_cb| is called.
+ void Initialize(const std::string& key_system,
+ const media::SessionMessageCB& session_message_cb,
+ const media::SessionReadyCB& session_ready_cb,
+ const media::SessionClosedCB& session_closed_cb,
+ const media::SessionErrorCB& session_error_cb,
+ const base::Closure& fatal_plugin_error_cb);
- void SetSessionEventCallbacks(
- const media::SessionCreatedCB& session_created_cb,
- const media::SessionMessageCB& session_message_cb,
- const media::SessionReadyCB& session_ready_cb,
- const media::SessionClosedCB& session_closed_cb,
- const media::SessionErrorCB& session_error_cb);
+ void InstanceCrashed();
// Provides access to PPP_ContentDecryptor_Private.
- bool CreateSession(uint32 session_id,
- const std::string& type,
+ void CreateSession(const std::string& init_data_type,
const uint8* init_data,
- int init_data_length);
- bool UpdateSession(uint32 session_id,
+ int init_data_length,
+ media::MediaKeys::SessionType session_type,
+ scoped_ptr<media::NewSessionCdmPromise> promise);
+ void LoadSession(const std::string& web_session_id,
+ scoped_ptr<media::NewSessionCdmPromise> promise);
+ void UpdateSession(const std::string& web_session_id,
const uint8* response,
- int response_length);
- bool ReleaseSession(uint32 session_id);
+ int response_length,
+ scoped_ptr<media::SimpleCdmPromise> promise);
+ void ReleaseSession(const std::string& web_session_id,
+ scoped_ptr<media::SimpleCdmPromise> promise);
bool Decrypt(media::Decryptor::StreamType stream_type,
const scoped_refptr<media::DecoderBuffer>& encrypted_buffer,
const media::Decryptor::DecryptCB& decrypt_cb);
@@ -80,15 +91,21 @@ class ContentDecryptorDelegate {
const media::Decryptor::VideoDecodeCB& video_decode_cb);
// PPB_ContentDecryptor_Private dispatching methods.
- void OnSessionCreated(uint32 session_id, PP_Var web_session_id_var);
- void OnSessionMessage(uint32 session_id,
+ void OnPromiseResolved(uint32 promise_id);
+ void OnPromiseResolvedWithSession(uint32 promise_id, PP_Var web_session_id);
+ void OnPromiseRejected(uint32 promise_id,
+ PP_CdmExceptionCode exception_code,
+ uint32 system_code,
+ PP_Var error_description);
+ void OnSessionMessage(PP_Var web_session_id,
PP_Var message,
PP_Var destination_url);
- void OnSessionReady(uint32 session_id);
- void OnSessionClosed(uint32 session_id);
- void OnSessionError(uint32 session_id,
- int32_t media_error,
- int32_t system_code);
+ void OnSessionReady(PP_Var web_session_id);
+ void OnSessionClosed(PP_Var web_session_id);
+ void OnSessionError(PP_Var web_session_id,
+ PP_CdmExceptionCode exception_code,
+ uint32 system_code,
+ PP_Var error_description);
void DeliverBlock(PP_Resource decrypted_block,
const PP_DecryptedBlockInfo* block_info);
void DecoderInitializeDone(PP_DecryptorStreamType decoder_type,
@@ -104,6 +121,41 @@ class ContentDecryptorDelegate {
const PP_DecryptedSampleInfo* sample_info);
private:
+ // The following types keep track of Promises. The index is the promise_id,
+ // so that returning results can be matched to the corresponding promise.
+ typedef base::ScopedPtrHashMap<uint32_t, media::CdmPromise> PromiseMap;
+
+ template <typename Callback>
+ class TrackableCallback {
+ public:
+ TrackableCallback() : id_(0u) {}
+ ~TrackableCallback() {
+ // Callbacks must be satisfied.
+ DCHECK_EQ(id_, 0u);
+ DCHECK(is_null());
+ };
+
+ bool Matches(uint32_t id) const { return id == id_; }
+
+ bool is_null() const { return cb_.is_null(); }
+
+ void Set(uint32_t id, const Callback& cb) {
+ DCHECK_EQ(id_, 0u);
+ DCHECK(cb_.is_null());
+ id_ = id;
+ cb_ = cb;
+ }
+
+ Callback ResetAndReturn() {
+ id_ = 0;
+ return base::ResetAndReturn(&cb_);
+ }
+
+ private:
+ uint32_t id_;
+ Callback cb_;
+ };
+
// Cancels the pending decrypt-and-decode callback for |stream_type|.
void CancelDecode(media::Decryptor::StreamType stream_type);
@@ -133,6 +185,16 @@ class ContentDecryptorDelegate {
media::SampleFormat sample_format,
media::Decryptor::AudioBuffers* frames);
+ void SatisfyAllPendingCallbacksOnError();
+
+ // Takes ownership of |promise| and returns an identifier to be passed via
+ // Pepper.
+ uint32_t SavePromise(scoped_ptr<media::CdmPromise> promise);
+
+ // Find the promise for a specified |promise_id|. Caller is responsible to
+ // delete the CdmPromise<> once done with it.
+ scoped_ptr<media::CdmPromise> TakePromise(uint32_t promise_id);
+
const PP_Instance pp_instance_;
const PPP_ContentDecryptor_Private* const plugin_decryption_interface_;
@@ -140,12 +202,15 @@ class ContentDecryptorDelegate {
std::string key_system_;
// Callbacks for firing session events.
- media::SessionCreatedCB session_created_cb_;
media::SessionMessageCB session_message_cb_;
media::SessionReadyCB session_ready_cb_;
media::SessionClosedCB session_closed_cb_;
media::SessionErrorCB session_error_cb_;
+ // Callback to notify that unexpected error happened and |this| should not
+ // be used anymore.
+ base::Closure fatal_plugin_error_cb_;
+
gfx::Size natural_size_;
// Request ID for tracking pending content decryption callbacks.
@@ -154,23 +219,12 @@ class ContentDecryptorDelegate {
// of request IDs.
uint32_t next_decryption_request_id_;
- uint32_t pending_audio_decrypt_request_id_;
- media::Decryptor::DecryptCB pending_audio_decrypt_cb_;
-
- uint32_t pending_video_decrypt_request_id_;
- media::Decryptor::DecryptCB pending_video_decrypt_cb_;
-
- uint32_t pending_audio_decoder_init_request_id_;
- media::Decryptor::DecoderInitCB pending_audio_decoder_init_cb_;
-
- uint32_t pending_video_decoder_init_request_id_;
- media::Decryptor::DecoderInitCB pending_video_decoder_init_cb_;
-
- uint32_t pending_audio_decode_request_id_;
- media::Decryptor::AudioDecodeCB pending_audio_decode_cb_;
-
- uint32_t pending_video_decode_request_id_;
- media::Decryptor::VideoDecodeCB pending_video_decode_cb_;
+ TrackableCallback<media::Decryptor::DecryptCB> audio_decrypt_cb_;
+ TrackableCallback<media::Decryptor::DecryptCB> video_decrypt_cb_;
+ TrackableCallback<media::Decryptor::DecoderInitCB> audio_decoder_init_cb_;
+ TrackableCallback<media::Decryptor::DecoderInitCB> video_decoder_init_cb_;
+ TrackableCallback<media::Decryptor::AudioDecodeCB> audio_decode_cb_;
+ TrackableCallback<media::Decryptor::VideoDecodeCB> video_decode_cb_;
// Cached audio and video input buffers. See MakeMediaBufferResource.
scoped_refptr<PPB_Buffer_Impl> audio_input_resource_;
@@ -181,6 +235,11 @@ class ContentDecryptorDelegate {
// Keep track of audio parameters.
int audio_samples_per_second_;
int audio_channel_count_;
+ media::ChannelLayout audio_channel_layout_;
+
+ // Keep track of outstanding promises. Maps have ownership of the promises.
+ uint32_t next_promise_id_;
+ PromiseMap promises_;
base::WeakPtr<ContentDecryptorDelegate> weak_this_;
base::WeakPtrFactory<ContentDecryptorDelegate> weak_ptr_factory_;