summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--webkit/media/crypto/ppapi/cdm_wrapper.cc45
-rw-r--r--webkit/media/crypto/ppapi/clear_key_cdm.cc12
-rw-r--r--webkit/media/crypto/ppapi/clear_key_cdm.h3
-rw-r--r--webkit/media/crypto/ppapi/content_decryption_module.h21
4 files changed, 74 insertions, 7 deletions
diff --git a/webkit/media/crypto/ppapi/cdm_wrapper.cc b/webkit/media/crypto/ppapi/cdm_wrapper.cc
index 679abaf..637216a 100644
--- a/webkit/media/crypto/ppapi/cdm_wrapper.cc
+++ b/webkit/media/crypto/ppapi/cdm_wrapper.cc
@@ -358,7 +358,8 @@ int64_t VideoFrameImpl::timestamp() const {
// A wrapper class for abstracting away PPAPI interaction and threading for a
// Content Decryption Module (CDM).
class CdmWrapper : public pp::Instance,
- public pp::ContentDecryptor_Private {
+ public pp::ContentDecryptor_Private,
+ public cdm::CdmHost {
public:
CdmWrapper(PP_Instance instance, pp::Module* module);
virtual ~CdmWrapper();
@@ -382,6 +383,10 @@ class CdmWrapper : public pp::Instance,
pp::Buffer_Dev encrypted_frame,
const PP_EncryptedVideoFrameInfo& encrypted_video_frame_info) OVERRIDE;
+ // CdmHost methods.
+ virtual void SetTimer(int64 delay_ms) OVERRIDE;
+ virtual double GetCurrentWallTimeMs() OVERRIDE;
+
private:
typedef linked_ptr<DecryptedBlockImpl> LinkedDecryptedBlock;
typedef linked_ptr<KeyMessageImpl> LinkedKeyMessage;
@@ -402,6 +407,9 @@ class CdmWrapper : public pp::Instance,
const LinkedVideoFrame& video_frame,
const PP_DecryptTrackingInfo& tracking_info);
+ // Helper for SetTimer().
+ void TimerExpired(int32 result);
+
PpbBufferAllocator allocator_;
pp::CompletionCallbackFactory<CdmWrapper> callback_factory_;
cdm::ContentDecryptionModule* cdm_;
@@ -443,7 +451,7 @@ void CdmWrapper::GenerateKeyRequest(const std::string& key_system,
PP_DCHECK(!key_system.empty());
if (!cdm_) {
- cdm_ = CreateCdmInstance(&allocator_);
+ cdm_ = CreateCdmInstance(&allocator_, this);
if (!cdm_)
return;
}
@@ -553,12 +561,42 @@ void CdmWrapper::DecryptAndDecodeFrame(
encrypted_video_frame_info.encryption_info.tracking_info));
}
+void CdmWrapper::SetTimer(int64 delay_ms) {
+ // NOTE: doesn't really need to run on the main thread; could just as well run
+ // on a helper thread if |cdm_| were thread-friendly and care was taken. We
+ // only use CallOnMainThread() here to get delayed-execution behavior.
+ pp::Module::Get()->core()->CallOnMainThread(
+ delay_ms,
+ callback_factory_.NewCallback(&CdmWrapper::TimerExpired),
+ PP_OK);
+}
+
+void CdmWrapper::TimerExpired(int32 result) {
+ PP_DCHECK(result == PP_OK);
+ bool populated;
+ KeyMessageImpl key_message;
+ cdm_->TimerExpired(&key_message, &populated);
+ if (!populated)
+ return;
+ // TODO(xhwang): do something with this?
+}
+
+double CdmWrapper::GetCurrentWallTimeMs() {
+ // TODO(fischman): figure out whether this requires an IPC round-trip per
+ // call, and if that's a problem for the frequency of calls. If it is,
+ // optimize by proactively sending wall-time across the IPC boundary on some
+ // existing calls, or add a periodic task to update a plugin-side clock.
+ return pp::Module::Get()->core()->GetTime();
+}
+
void CdmWrapper::KeyAdded(int32_t result, const std::string& session_id) {
+ PP_DCHECK(result == PP_OK);
pp::ContentDecryptor_Private::KeyAdded(key_system_, session_id);
}
void CdmWrapper::KeyMessage(int32_t result,
const LinkedKeyMessage& key_message) {
+ PP_DCHECK(result == PP_OK);
pp::Buffer_Dev message_buffer =
static_cast<const PpbBuffer*>(key_message->message())->buffer_dev();
pp::ContentDecryptor_Private::KeyMessage(
@@ -571,6 +609,7 @@ void CdmWrapper::KeyMessage(int32_t result,
// TODO(xhwang): Support MediaKeyError (see spec: http://goo.gl/rbdnR) in CDM
// interface and in this function.
void CdmWrapper::KeyError(int32_t result, const std::string& session_id) {
+ PP_DCHECK(result == PP_OK);
pp::ContentDecryptor_Private::KeyError(key_system_,
session_id,
kUnknownError,
@@ -581,6 +620,7 @@ void CdmWrapper::DeliverBlock(int32_t result,
const cdm::Status& status,
const LinkedDecryptedBlock& decrypted_block,
const PP_DecryptTrackingInfo& tracking_info) {
+ PP_DCHECK(result == PP_OK);
PP_DecryptedBlockInfo decrypted_block_info;
decrypted_block_info.tracking_info = tracking_info;
decrypted_block_info.tracking_info.timestamp = decrypted_block->timestamp();
@@ -612,6 +652,7 @@ void CdmWrapper::DeliverFrame(
const cdm::Status& status,
const LinkedVideoFrame& video_frame,
const PP_DecryptTrackingInfo& tracking_info) {
+ PP_DCHECK(result == PP_OK);
PP_DecryptedFrameInfo decrypted_frame_info;
decrypted_frame_info.tracking_info = tracking_info;
diff --git a/webkit/media/crypto/ppapi/clear_key_cdm.cc b/webkit/media/crypto/ppapi/clear_key_cdm.cc
index 307c886..49df915 100644
--- a/webkit/media/crypto/ppapi/clear_key_cdm.cc
+++ b/webkit/media/crypto/ppapi/clear_key_cdm.cc
@@ -62,8 +62,9 @@ static Type* AllocateAndCopy(const Type* data, int size) {
return copy;
}
-cdm::ContentDecryptionModule* CreateCdmInstance(cdm::Allocator* allocator) {
- return new webkit_media::ClearKeyCdm(allocator);
+cdm::ContentDecryptionModule* CreateCdmInstance(
+ cdm::Allocator* allocator, cdm::CdmHost* host) {
+ return new webkit_media::ClearKeyCdm(allocator, host);
}
void DestroyCdmInstance(cdm::ContentDecryptionModule* instance) {
@@ -123,7 +124,7 @@ void ClearKeyCdm::Client::NeedKey(const std::string& key_system,
NOTREACHED();
}
-ClearKeyCdm::ClearKeyCdm(cdm::Allocator* allocator)
+ClearKeyCdm::ClearKeyCdm(cdm::Allocator* allocator, cdm::CdmHost*)
: decryptor_(&client_), allocator_(allocator) {
DCHECK(allocator_);
}
@@ -186,6 +187,11 @@ cdm::Status ClearKeyCdm::CancelKeyRequest(const char* session_id,
return cdm::kSuccess;
}
+void ClearKeyCdm::TimerExpired(cdm::KeyMessage* msg, bool* populated) {
+ // TODO(xhwang): do something with this?
+ NOTREACHED() << "Wouldn't it be nice if CdmHost::SetTimer() was used?";
+}
+
static void CopyDecryptResults(
media::Decryptor::Status* status_copy,
scoped_refptr<media::DecoderBuffer>* buffer_copy,
diff --git a/webkit/media/crypto/ppapi/clear_key_cdm.h b/webkit/media/crypto/ppapi/clear_key_cdm.h
index 2d3e102..2363b4d 100644
--- a/webkit/media/crypto/ppapi/clear_key_cdm.h
+++ b/webkit/media/crypto/ppapi/clear_key_cdm.h
@@ -24,7 +24,7 @@ namespace webkit_media {
// Clear key implementation of the cdm::ContentDecryptionModule interface.
class ClearKeyCdm : public cdm::ContentDecryptionModule {
public:
- explicit ClearKeyCdm(cdm::Allocator* allocator);
+ explicit ClearKeyCdm(cdm::Allocator* allocator, cdm::CdmHost*);
virtual ~ClearKeyCdm();
// ContentDecryptionModule implementation.
@@ -40,6 +40,7 @@ class ClearKeyCdm : public cdm::ContentDecryptionModule {
int key_id_size) OVERRIDE;
virtual cdm::Status CancelKeyRequest(const char* session_id,
int session_id_size) OVERRIDE;
+ virtual void TimerExpired(cdm::KeyMessage* msg, bool* populated) OVERRIDE;
virtual cdm::Status Decrypt(const cdm::InputBuffer& encrypted_buffer,
cdm::DecryptedBlock* decrypted_block) OVERRIDE;
virtual cdm::Status InitializeVideoDecoder(
diff --git a/webkit/media/crypto/ppapi/content_decryption_module.h b/webkit/media/crypto/ppapi/content_decryption_module.h
index 09a9a0b..47295b9 100644
--- a/webkit/media/crypto/ppapi/content_decryption_module.h
+++ b/webkit/media/crypto/ppapi/content_decryption_module.h
@@ -19,6 +19,7 @@ typedef __int64 int64_t;
namespace cdm {
class Allocator;
class Buffer;
+class CdmHost;
class ContentDecryptionModule;
class DecryptedBlock;
class KeyMessage;
@@ -26,8 +27,10 @@ class VideoFrame;
}
extern "C" {
+// Caller retains ownership of arguments, which must outlive the call to
+// DestroyCdmInstance below.
CDM_EXPORT cdm::ContentDecryptionModule* CreateCdmInstance(
- cdm::Allocator* allocator);
+ cdm::Allocator* allocator, cdm::CdmHost* host);
CDM_EXPORT void DestroyCdmInstance(cdm::ContentDecryptionModule* instance);
CDM_EXPORT const char* GetCdmVersion();
}
@@ -190,6 +193,9 @@ class ContentDecryptionModule {
virtual Status CancelKeyRequest(const char* session_id,
int session_id_size) = 0;
+ // Optionally populates |*msg| and indicates so in |*populated|.
+ virtual void TimerExpired(KeyMessage* msg, bool* populated) = 0;
+
// Decrypts the |encrypted_buffer|.
//
// Returns kSuccess if decryption succeeded, in which case the callee
@@ -286,6 +292,19 @@ class Allocator {
virtual ~Allocator() {}
};
+class CdmHost {
+ public:
+ CdmHost() {}
+ virtual ~CdmHost() {}
+
+ // Requests the host to call ContentDecryptionModule::TimerFired() |delay_ms|
+ // from now.
+ virtual void SetTimer(int64 delay_ms) = 0;
+
+ // Returns the current epoch wall time in milliseconds.
+ virtual double GetCurrentWallTimeMs() = 0;
+};
+
// Represents a decrypted block that has not been decoded.
class DecryptedBlock {
public: