Chromium Code Reviews| Index: webkit/media/webmediaplayer_impl.cc |
| diff --git a/webkit/media/webmediaplayer_impl.cc b/webkit/media/webmediaplayer_impl.cc |
| index e5afb5d04cf465be009f49053a6fa792c62447df..31c32817105225a2117732a86d2d4dbee3df54d7 100644 |
| --- a/webkit/media/webmediaplayer_impl.cc |
| +++ b/webkit/media/webmediaplayer_impl.cc |
| @@ -12,6 +12,7 @@ |
| #include "base/command_line.h" |
| #include "base/message_loop_proxy.h" |
| #include "base/metrics/histogram.h" |
| +#include "base/string_number_conversions.h" |
| #include "base/synchronization/waitable_event.h" |
| #include "media/audio/null_audio_sink.h" |
| #include "media/base/filter_collection.h" |
| @@ -26,10 +27,12 @@ |
| #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
| #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebRect.h" |
| #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSize.h" |
| +#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" |
| #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h" |
| #include "v8/include/v8.h" |
| #include "webkit/media/buffered_data_source.h" |
| #include "webkit/media/filter_helpers.h" |
| +#include "webkit/media/supported_key_systems.h" |
| #include "webkit/media/webmediaplayer_delegate.h" |
| #include "webkit/media/webmediaplayer_proxy.h" |
| #include "webkit/media/webvideoframe_impl.h" |
| @@ -668,6 +671,70 @@ void WebMediaPlayerImpl::sourceEndOfStream( |
| proxy_->DemuxerEndOfStream(pipeline_status); |
| } |
| +WebKit::WebMediaPlayer::MediaKeyException |
| +WebMediaPlayerImpl::generateKeyRequest(const WebKit::WebString& keySystem, |
|
scherkus (not reviewing)
2012/04/12 20:18:41
chromium style unix_hacker here + below
ddorwin
2012/04/12 23:41:23
Done.
|
| + const unsigned char* initData, |
| + unsigned initDataLength) { |
| + if (!SupportedKeySystems::isKeySystemSupported(keySystem)) |
| + return WebKit::WebMediaPlayer::KeySystemNotSupported; |
| + |
| + // Every request call creates a unique ID. |
|
scherkus (not reviewing)
2012/04/12 20:18:41
how unique is unique supposed to be?
unique per p
ddorwin
2012/04/12 23:41:23
Whatever is necessary for the CDM to "associate ca
|
| + // Increment the ID here to avoid race conditions in task threads. |
|
scherkus (not reviewing)
2012/04/12 20:18:41
which race conditions are you referring to?
if it
ddorwin
2012/04/12 23:41:23
For now (see above), per-page uniqueness is fine.
|
| + static uint32_t nextAvailableSessionId = 1; |
|
scherkus (not reviewing)
2012/04/12 20:18:41
unix_hacker style
ddorwin
2012/04/12 23:41:23
Done.
|
| + uint32_t sessionId = nextAvailableSessionId++; |
| + |
| + MessageLoop::current()->PostTask( |
|
scherkus (not reviewing)
2012/04/12 20:18:41
nit: our preferred style for PostTask is:
PostTas
ddorwin
2012/04/12 23:41:23
Done.
|
| + FROM_HERE, |
| + base::Bind(&WebMediaPlayerImpl::generateKeyRequestTask, |
| + AsWeakPtr(), |
| + keySystem, |
| + initData, |
| + initDataLength, |
| + sessionId)); |
| + |
| + return WebKit::WebMediaPlayer::NoError; |
| +} |
| + |
| +WebKit::WebMediaPlayer::MediaKeyException WebMediaPlayerImpl::addKey( |
| + const WebKit::WebString& keySystem, |
| + const unsigned char* key, |
| + unsigned keyLength, |
| + const unsigned char* initData, |
| + unsigned initDataLength, |
| + const WebKit::WebString& sessionId) { |
| + if (!SupportedKeySystems::isKeySystemSupported(keySystem)) |
| + return WebKit::WebMediaPlayer::KeySystemNotSupported; |
| + |
| + MessageLoop::current()->PostTask( |
| + FROM_HERE, |
| + base::Bind(&WebMediaPlayerImpl::addKeyTask, |
| + AsWeakPtr(), |
| + keySystem, |
| + key, |
| + keyLength, |
| + initData, |
| + initDataLength, |
| + sessionId)); |
| + |
| + return WebKit::WebMediaPlayer::NoError; |
| +} |
| + |
| +WebKit::WebMediaPlayer::MediaKeyException WebMediaPlayerImpl::cancelKeyRequest( |
| + const WebKit::WebString& keySystem, |
| + const WebKit::WebString& sessionId) { |
| + if (!SupportedKeySystems::isKeySystemSupported(keySystem)) |
| + return WebKit::WebMediaPlayer::KeySystemNotSupported; |
| + |
| + MessageLoop::current()->PostTask( |
| + FROM_HERE, |
| + base::Bind(&WebMediaPlayerImpl::cancelKeyRequestTask, |
| + AsWeakPtr(), |
| + keySystem, |
| + sessionId)); |
| + |
| + return WebKit::WebMediaPlayer::NoError; |
| +} |
| + |
| void WebMediaPlayerImpl::WillDestroyCurrentMessageLoop() { |
| Destroy(); |
| main_loop_ = NULL; |
| @@ -920,4 +987,65 @@ void WebMediaPlayerImpl::IncrementExternallyAllocatedMemory() { |
| v8::V8::AdjustAmountOfExternalAllocatedMemory(kPlayerExtraMemory); |
| } |
| +void WebMediaPlayerImpl::generateKeyRequestTask( |
|
scherkus (not reviewing)
2012/04/12 20:18:41
you don't need any of these methods
considering t
ddorwin
2012/04/12 23:41:23
I kept the first two functions but removed the thi
|
| + const WebKit::WebString& keySystem, |
| + const unsigned char* initData, |
| + unsigned initDataLength, |
| + uint32_t sessionId) { |
| + WebKit::WebString sessionIdSring(base::UintToString16(sessionId)); |
|
scherkus (not reviewing)
2012/04/12 20:18:41
Sring -> String?
ddorwin
2012/04/12 23:41:23
Done.
|
| + |
| + DVLOG(1) << "generateKeyRequest: " << keySystem.utf8().data() << ": " |
| + << std::string(reinterpret_cast<const char*>(initData), |
| + static_cast<size_t>(initDataLength)).c_str() << ": " |
| + << sessionIdSring.utf8().data(); |
| + |
| + // TODO(ddorwin): Generate a key request in the decrypter and fire |
| + // keyMessage when it completes. |
| + // For now, just fire the event with the initData as the request. |
| + const unsigned char* message = initData; |
| + unsigned messageLength = initDataLength; |
| + |
| + GetClient()->keyMessage(keySystem, sessionIdSring, message, messageLength); |
| +} |
| + |
| +void WebMediaPlayerImpl::addKeyTask( |
| + const WebKit::WebString& keySystem, |
| + const unsigned char* key, |
| + unsigned keyLength, |
| + const unsigned char* initData, |
| + unsigned initDataLength, |
| + const WebKit::WebString& sessionId) { |
| + DVLOG(1) << "addKey: " << keySystem.utf8().data() << ": " |
| + << std::string(reinterpret_cast<const char*>(key), |
| + static_cast<size_t>(keyLength)).c_str() << ": " |
|
scherkus (not reviewing)
2012/04/12 20:18:41
why c_str()?
ddorwin
2012/04/12 23:41:23
Done.
|
| + << std::string(reinterpret_cast<const char*>(initData), |
| + static_cast<size_t>(initDataLength)).c_str() |
| + << "[" << sessionId.utf8().data() << "]"; |
| + |
| + // TODO(ddorwin): Add the key to the decrypter and fire keyAdded when it |
| + // completes. Check the key length there. |
| + // Temporarily, fire an error for invalid key length so we can test the error |
| + // event and fire the keyAdded event in all other cases. |
| + const int kSupportedKeyLengthBits = 128; |
| + const int kBitsPerByte = 8; |
| + const unsigned int kSupportedKeyLengthBytes = |
| + kSupportedKeyLengthBits / kBitsPerByte; |
| + if (keyLength != kSupportedKeyLengthBytes) { |
|
scherkus (not reviewing)
2012/04/12 20:18:41
these constants seemed overly verbose for temporar
ddorwin
2012/04/12 23:41:23
Done.
|
| + DLOG(ERROR) << "invalid key length: " << keyLength; |
| + GetClient()->keyError(keySystem, sessionId, |
| + WebKit::WebMediaPlayerClient::UnknownError, 0); |
| + return; |
| + } |
| + |
| + GetClient()->keyAdded(keySystem, sessionId); |
| +} |
| + |
| +void WebMediaPlayerImpl::cancelKeyRequestTask( |
|
scherkus (not reviewing)
2012/04/12 20:18:41
remove -- add this method when we have an impl
ddorwin
2012/04/12 23:41:23
Done.
|
| + const WebKit::WebString& keySystem, |
| + const WebKit::WebString& sessionId) { |
| + DVLOG(1) << "cancelKeyRequest: " << keySystem.utf8().data() << ": " |
| + << "[" << sessionId.utf8().data() << "]"; |
| + // TODO(ddorwin): Cancel the key request in the decrypter. |
| +} |
| + |
| } // namespace webkit_media |