summaryrefslogtreecommitdiffstats
path: root/webkit/media
diff options
context:
space:
mode:
authorxhwang@chromium.org <xhwang@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-10-10 23:36:31 +0000
committerxhwang@chromium.org <xhwang@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-10-10 23:36:31 +0000
commit326dff446c95d772d1f80f086ccff86b3ff8bf25 (patch)
tree61c0459fc2f20a842ccab20fd868ec1fb5c84dc3 /webkit/media
parent1fba73c14c6cadc0f04045e04187d734695aec65 (diff)
downloadchromium_src-326dff446c95d772d1f80f086ccff86b3ff8bf25.zip
chromium_src-326dff446c95d772d1f80f086ccff86b3ff8bf25.tar.gz
chromium_src-326dff446c95d772d1f80f086ccff86b3ff8bf25.tar.bz2
Add decryptor requesting and kNoKey handling in DecryptingVideoDecoder (DVD).
- These logic was previously implemented in ProxyDecryptor. Now add them into DVD so that the DVD can talk directly to other Decryptor implementations such as the PpapiDecryptor. - Since we have more states in DVD now, add more state enum to manage state transition. - Add RequestDecryptorNotificationCB for decryptor creation notification. - Add KeyAddedCB for notifying the DVD that new key has been added. BUG=141784 TEST=current unittests pass; added more unittests. Review URL: https://chromiumcodereview.appspot.com/11074010 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@161231 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/media')
-rw-r--r--webkit/media/crypto/ppapi_decryptor.cc3
-rw-r--r--webkit/media/crypto/ppapi_decryptor.h3
-rw-r--r--webkit/media/crypto/proxy_decryptor.cc57
-rw-r--r--webkit/media/crypto/proxy_decryptor.h15
-rw-r--r--webkit/media/filter_helpers.cc16
-rw-r--r--webkit/media/filter_helpers.h6
6 files changed, 72 insertions, 28 deletions
diff --git a/webkit/media/crypto/ppapi_decryptor.cc b/webkit/media/crypto/ppapi_decryptor.cc
index 185a050..640da5b 100644
--- a/webkit/media/crypto/ppapi_decryptor.cc
+++ b/webkit/media/crypto/ppapi_decryptor.cc
@@ -104,7 +104,8 @@ void PpapiDecryptor::CancelDecrypt() {
void PpapiDecryptor::InitializeVideoDecoder(
const media::VideoDecoderConfig& config,
- const DecoderInitCB& init_cb) {
+ const DecoderInitCB& init_cb,
+ const KeyAddedCB& key_added_cb) {
// TODO(xhwang): Implement this!
NOTIMPLEMENTED();
init_cb.Run(false);
diff --git a/webkit/media/crypto/ppapi_decryptor.h b/webkit/media/crypto/ppapi_decryptor.h
index 5cf9d6c..a7effa1 100644
--- a/webkit/media/crypto/ppapi_decryptor.h
+++ b/webkit/media/crypto/ppapi_decryptor.h
@@ -52,7 +52,8 @@ class PpapiDecryptor : public media::Decryptor {
const DecryptCB& decrypt_cb) OVERRIDE;
virtual void CancelDecrypt() OVERRIDE;
virtual void InitializeVideoDecoder(const media::VideoDecoderConfig& config,
- const DecoderInitCB& init_cb) OVERRIDE;
+ const DecoderInitCB& init_cb,
+ const KeyAddedCB& key_added_cb) OVERRIDE;
virtual void DecryptAndDecodeVideo(
const scoped_refptr<media::DecoderBuffer>& encrypted,
const VideoDecodeCB& video_decode_cb) OVERRIDE;
diff --git a/webkit/media/crypto/proxy_decryptor.cc b/webkit/media/crypto/proxy_decryptor.cc
index 9d1d77d..16cfa7e 100644
--- a/webkit/media/crypto/proxy_decryptor.cc
+++ b/webkit/media/crypto/proxy_decryptor.cc
@@ -77,20 +77,43 @@ ProxyDecryptor::ProxyDecryptor(
ProxyDecryptor::~ProxyDecryptor() {
}
+// TODO(xhwang): Support multiple decryptor notification request (e.g. from
+// video and audio decoders).
+void ProxyDecryptor::RequestDecryptorNotification(
+ const DecryptorNotificationCB& decryptor_notification_cb) {
+ base::AutoLock auto_lock(lock_);
+
+ // Cancels the previous decryptor request.
+ if (decryptor_notification_cb.is_null()) {
+ if (!decryptor_notification_cb_.is_null())
+ base::ResetAndReturn(&decryptor_notification_cb_).Run(NULL);
+ return;
+ }
+
+ // Normal decryptor request.
+ DCHECK(decryptor_notification_cb_.is_null());
+ if (decryptor_.get()) {
+ decryptor_notification_cb.Run(decryptor_.get());
+ return;
+ }
+ decryptor_notification_cb_ = decryptor_notification_cb;
+}
+
bool ProxyDecryptor::GenerateKeyRequest(const std::string& key_system,
const uint8* init_data,
int init_data_length) {
// We do not support run-time switching of decryptors. GenerateKeyRequest()
// only creates a new decryptor when |decryptor_| is not initialized.
DVLOG(1) << "GenerateKeyRequest: key_system = " << key_system;
- if (!decryptor_.get()) {
- base::AutoLock auto_lock(lock_);
- decryptor_ = CreateDecryptor(key_system);
- }
+
+ base::AutoLock auto_lock(lock_);
if (!decryptor_.get()) {
- client_->KeyError(key_system, "", media::Decryptor::kUnknownError, 0);
- return false;
+ decryptor_ = CreateDecryptor(key_system);
+ if (!decryptor_.get()) {
+ client_->KeyError(key_system, "", media::Decryptor::kUnknownError, 0);
+ return false;
+ }
}
if (!decryptor_->GenerateKeyRequest(key_system,
@@ -99,6 +122,9 @@ bool ProxyDecryptor::GenerateKeyRequest(const std::string& key_system,
return false;
}
+ if (!decryptor_notification_cb_.is_null())
+ base::ResetAndReturn(&decryptor_notification_cb_).Run(decryptor_.get());
+
return true;
}
@@ -178,28 +204,29 @@ void ProxyDecryptor::CancelDecrypt() {
void ProxyDecryptor::InitializeVideoDecoder(
const media::VideoDecoderConfig& config,
- const DecoderInitCB& init_cb) {
- // TODO(xhwang): Implement this!
- NOTIMPLEMENTED();
+ const DecoderInitCB& init_cb,
+ const KeyAddedCB& key_added_cb) {
+ // TODO(xhwang): Remove this!
+ NOTREACHED();
init_cb.Run(false);
}
void ProxyDecryptor::DecryptAndDecodeVideo(
const scoped_refptr<media::DecoderBuffer>& encrypted,
const VideoDecodeCB& video_decode_cb) {
- // TODO(xhwang): Implement this!
- NOTIMPLEMENTED();
+ // TODO(xhwang): Remove this!
+ NOTREACHED();
video_decode_cb.Run(kError, NULL);
}
void ProxyDecryptor::CancelDecryptAndDecodeVideo() {
- // TODO(xhwang): Implement this!
- NOTIMPLEMENTED();
+ // TODO(xhwang): Remove this!
+ NOTREACHED();
}
void ProxyDecryptor::StopVideoDecoder() {
- // TODO(xhwang): Implement this!
- NOTIMPLEMENTED();
+ // TODO(xhwang): Remove this!
+ NOTREACHED();
}
scoped_ptr<media::Decryptor> ProxyDecryptor::CreatePpapiDecryptor(
diff --git a/webkit/media/crypto/proxy_decryptor.h b/webkit/media/crypto/proxy_decryptor.h
index 175aef6..08356eb 100644
--- a/webkit/media/crypto/proxy_decryptor.h
+++ b/webkit/media/crypto/proxy_decryptor.h
@@ -42,6 +42,16 @@ class ProxyDecryptor : public media::Decryptor {
decryptor_ = decryptor.Pass();
}
+ // Callback to notify that the decryptor has been created.
+ typedef base::Callback<void(Decryptor*)> DecryptorNotificationCB;
+
+ // Requests the ProxyDecryptor to notify the decryptor creation through the
+ // |decryptor_notification_cb| provided.
+ // If |decryptor_notification_cb| is null, the ProxyDecryptor should cancel
+ // the existing request and fire it with NULL immediately.
+ void RequestDecryptorNotification(
+ const DecryptorNotificationCB& decryptor_notification_cb);
+
// media::Decryptor implementation.
virtual bool GenerateKeyRequest(const std::string& key_system,
const uint8* init_data,
@@ -58,7 +68,8 @@ class ProxyDecryptor : public media::Decryptor {
const DecryptCB& decrypt_cb) OVERRIDE;
virtual void CancelDecrypt() OVERRIDE;
virtual void InitializeVideoDecoder(const media::VideoDecoderConfig& config,
- const DecoderInitCB& init_cb) OVERRIDE;
+ const DecoderInitCB& init_cb,
+ const KeyAddedCB& key_added_cb) OVERRIDE;
virtual void DecryptAndDecodeVideo(
const scoped_refptr<media::DecoderBuffer>& encrypted,
const VideoDecodeCB& video_decode_cb) OVERRIDE;
@@ -96,6 +107,8 @@ class ProxyDecryptor : public media::Decryptor {
// safe as per the Decryptor interface.
base::Lock lock_;
+ DecryptorNotificationCB decryptor_notification_cb_;
+
// The real decryptor that does decryption for the ProxyDecryptor.
// This pointer is protected by the |lock_|.
scoped_ptr<media::Decryptor> decryptor_;
diff --git a/webkit/media/filter_helpers.cc b/webkit/media/filter_helpers.cc
index d49f776..da96307 100644
--- a/webkit/media/filter_helpers.cc
+++ b/webkit/media/filter_helpers.cc
@@ -14,6 +14,7 @@
#include "media/filters/ffmpeg_demuxer.h"
#include "media/filters/ffmpeg_video_decoder.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h"
+#include "webkit/media/crypto/proxy_decryptor.h"
#include "webkit/media/media_stream_client.h"
namespace webkit_media {
@@ -28,7 +29,7 @@ namespace webkit_media {
static void AddDefaultDecodersToCollection(
media::MessageLoopFactory* message_loop_factory,
media::FilterCollection* filter_collection,
- media::Decryptor* decryptor) {
+ ProxyDecryptor* proxy_decryptor) {
filter_collection->AddAudioDecoder(new media::FFmpegAudioDecoder(
base::Bind(&media::MessageLoopFactory::GetMessageLoop,
base::Unretained(message_loop_factory),
@@ -39,14 +40,15 @@ static void AddDefaultDecodersToCollection(
base::Bind(&media::MessageLoopFactory::GetMessageLoop,
base::Unretained(message_loop_factory),
media::MessageLoopFactory::kDecoder),
- decryptor);
+ base::Bind(&ProxyDecryptor::RequestDecryptorNotification,
+ base::Unretained(proxy_decryptor)));
scoped_refptr<media::FFmpegVideoDecoder> ffmpeg_video_decoder =
new media::FFmpegVideoDecoder(
base::Bind(&media::MessageLoopFactory::GetMessageLoop,
base::Unretained(message_loop_factory),
media::MessageLoopFactory::kDecoder),
- decryptor);
+ proxy_decryptor);
filter_collection->GetVideoDecoders()->push_back(decrypting_video_decoder);
filter_collection->GetVideoDecoders()->push_back(ffmpeg_video_decoder);
@@ -79,7 +81,7 @@ void BuildMediaSourceCollection(
const scoped_refptr<media::ChunkDemuxer>& demuxer,
media::MessageLoopFactory* message_loop_factory,
media::FilterCollection* filter_collection,
- media::Decryptor* decryptor) {
+ ProxyDecryptor* proxy_decryptor) {
DCHECK(demuxer);
filter_collection->SetDemuxer(demuxer);
@@ -89,21 +91,21 @@ void BuildMediaSourceCollection(
filter_collection->GetVideoDecoders()->clear();
AddDefaultDecodersToCollection(message_loop_factory, filter_collection,
- decryptor);
+ proxy_decryptor);
}
void BuildDefaultCollection(
const scoped_refptr<media::DataSource>& data_source,
media::MessageLoopFactory* message_loop_factory,
media::FilterCollection* filter_collection,
- media::Decryptor* decryptor) {
+ ProxyDecryptor* proxy_decryptor) {
filter_collection->SetDemuxer(new media::FFmpegDemuxer(
message_loop_factory->GetMessageLoop(
media::MessageLoopFactory::kPipeline),
data_source));
AddDefaultDecodersToCollection(message_loop_factory, filter_collection,
- decryptor);
+ proxy_decryptor);
}
} // webkit_media
diff --git a/webkit/media/filter_helpers.h b/webkit/media/filter_helpers.h
index c5fd87d..ef7a8c7 100644
--- a/webkit/media/filter_helpers.h
+++ b/webkit/media/filter_helpers.h
@@ -9,7 +9,6 @@
#include "base/memory/ref_counted.h"
namespace media {
-class Decryptor;
class ChunkDemuxer;
class DataSource;
class FFmpegVideoDecoder;
@@ -24,6 +23,7 @@ class WebURL;
namespace webkit_media {
class MediaStreamClient;
+class ProxyDecryptor;
// Builds the required filters for handling media stream URLs and adds them to
// |filter_collection| returning true if successful.
@@ -40,7 +40,7 @@ void BuildMediaSourceCollection(
const scoped_refptr<media::ChunkDemuxer>& demuxer,
media::MessageLoopFactory* message_loop_factory,
media::FilterCollection* filter_collection,
- media::Decryptor* decryptor);
+ ProxyDecryptor* proxy_decryptor);
// Builds the required filters for handling regular URLs and adds them to
// |filter_collection| and fills |video_decoder| returning true if successful.
@@ -48,7 +48,7 @@ void BuildDefaultCollection(
const scoped_refptr<media::DataSource>& data_source,
media::MessageLoopFactory* message_loop_factory,
media::FilterCollection* filter_collection,
- media::Decryptor* decryptor);
+ ProxyDecryptor* proxy_decryptor);
} // webkit_media