diff options
Diffstat (limited to 'media')
-rw-r--r-- | media/base/android/media_drm_bridge.cc | 34 | ||||
-rw-r--r-- | media/base/android/media_drm_bridge.h | 9 | ||||
-rw-r--r-- | media/base/media_keys.h | 13 | ||||
-rw-r--r-- | media/blink/cdm_session_adapter.cc | 20 | ||||
-rw-r--r-- | media/blink/cdm_session_adapter.h | 14 | ||||
-rw-r--r-- | media/blink/webcontentdecryptionmodule_impl.cc | 4 | ||||
-rw-r--r-- | media/blink/webcontentdecryptionmodulesession_impl.cc | 13 | ||||
-rw-r--r-- | media/cdm/aes_decryptor.cc | 47 | ||||
-rw-r--r-- | media/cdm/aes_decryptor.h | 12 | ||||
-rw-r--r-- | media/cdm/aes_decryptor_unittest.cc | 40 | ||||
-rw-r--r-- | media/cdm/cenc_utils.cc | 49 | ||||
-rw-r--r-- | media/cdm/cenc_utils.h | 9 | ||||
-rw-r--r-- | media/cdm/cenc_utils_unittest.cc | 178 | ||||
-rw-r--r-- | media/cdm/ppapi/external_clear_key/clear_key_cdm.cc | 15 | ||||
-rw-r--r-- | media/cdm/proxy_decryptor.cc | 14 | ||||
-rw-r--r-- | media/mojo/services/mojo_cdm.cc | 24 | ||||
-rw-r--r-- | media/mojo/services/mojo_cdm.h | 11 | ||||
-rw-r--r-- | media/mojo/services/mojo_cdm_service.cc | 15 | ||||
-rw-r--r-- | media/test/pipeline_integration_test.cc | 21 |
19 files changed, 253 insertions, 289 deletions
diff --git a/media/base/android/media_drm_bridge.cc b/media/base/android/media_drm_bridge.cc index 0e31818..0aaeef4 100644 --- a/media/base/android/media_drm_bridge.cc +++ b/media/base/android/media_drm_bridge.cc @@ -15,6 +15,8 @@ #include "base/location.h" #include "base/logging.h" #include "base/message_loop/message_loop_proxy.h" +#include "base/numerics/safe_conversions.h" +#include "base/stl_util.h" #include "base/strings/string_util.h" #include "base/sys_byteorder.h" #include "base/sys_info.h" @@ -92,13 +94,12 @@ typedef std::vector<uint8> UUID; // 1, If multiple PSSH boxes are found,the "Data" of the first matching PSSH box // will be set in |pssh_data|. // 2, Only PSSH and TENC boxes are allowed in |data|. TENC boxes are skipped. -bool GetPsshData(const uint8* data, - int data_size, +bool GetPsshData(const std::vector<uint8_t>& data, const UUID& uuid, std::vector<uint8>* pssh_data) { - const uint8* cur = data; - const uint8* data_end = data + data_size; - int bytes_left = data_size; + int bytes_left = base::checked_cast<int>(data.size()); + const uint8_t* cur = &data[0]; + const uint8_t* data_end = cur + bytes_left; while (bytes_left > 0) { const uint8* box_head = cur; @@ -427,8 +428,7 @@ bool MediaDrmBridge::SetSecurityLevel(SecurityLevel security_level) { } void MediaDrmBridge::SetServerCertificate( - const uint8* certificate_data, - int certificate_data_length, + const std::vector<uint8_t>& certificate, scoped_ptr<media::SimpleCdmPromise> promise) { promise->reject(NOT_SUPPORTED_ERROR, 0, "SetServerCertificate() is not supported."); @@ -437,8 +437,7 @@ void MediaDrmBridge::SetServerCertificate( void MediaDrmBridge::CreateSessionAndGenerateRequest( SessionType session_type, media::EmeInitDataType init_data_type, - const uint8* init_data, - int init_data_length, + const std::vector<uint8_t>& init_data, scoped_ptr<media::NewSessionCdmPromise> promise) { DVLOG(1) << __FUNCTION__; @@ -456,15 +455,15 @@ void MediaDrmBridge::CreateSessionAndGenerateRequest( if (std::equal(scheme_uuid_.begin(), scheme_uuid_.end(), kWidevineUuid) && init_data_type == media::EmeInitDataType::CENC) { std::vector<uint8> pssh_data; - if (!GetPsshData(init_data, init_data_length, scheme_uuid_, &pssh_data)) { + if (!GetPsshData(init_data, scheme_uuid_, &pssh_data)) { promise->reject(INVALID_ACCESS_ERROR, 0, "Invalid PSSH data."); return; } - j_init_data = - base::android::ToJavaByteArray(env, &pssh_data[0], pssh_data.size()); + j_init_data = base::android::ToJavaByteArray( + env, vector_as_array(&pssh_data), pssh_data.size()); } else { - j_init_data = - base::android::ToJavaByteArray(env, init_data, init_data_length); + j_init_data = base::android::ToJavaByteArray( + env, vector_as_array(&init_data), init_data.size()); } ScopedJavaLocalRef<jstring> j_mime = @@ -483,14 +482,13 @@ void MediaDrmBridge::LoadSession( void MediaDrmBridge::UpdateSession( const std::string& session_id, - const uint8* response, - int response_length, + const std::vector<uint8_t>& response, scoped_ptr<media::SimpleCdmPromise> promise) { DVLOG(1) << __FUNCTION__; JNIEnv* env = AttachCurrentThread(); - ScopedJavaLocalRef<jbyteArray> j_response = - base::android::ToJavaByteArray(env, response, response_length); + ScopedJavaLocalRef<jbyteArray> j_response = base::android::ToJavaByteArray( + env, vector_as_array(&response), response.size()); ScopedJavaLocalRef<jbyteArray> j_session_id = base::android::ToJavaByteArray( env, reinterpret_cast<const uint8_t*>(session_id.data()), session_id.size()); diff --git a/media/base/android/media_drm_bridge.h b/media/base/android/media_drm_bridge.h index b767aa6..30842b9 100644 --- a/media/base/android/media_drm_bridge.h +++ b/media/base/android/media_drm_bridge.h @@ -86,21 +86,18 @@ class MEDIA_EXPORT MediaDrmBridge : public BrowserCdm { // MediaKeys (via BrowserCdm) implementation. void SetServerCertificate( - const uint8* certificate_data, - int certificate_data_length, + const std::vector<uint8_t>& certificate, scoped_ptr<media::SimpleCdmPromise> promise) override; void CreateSessionAndGenerateRequest( SessionType session_type, media::EmeInitDataType init_data_type, - const uint8* init_data, - int init_data_length, + const std::vector<uint8_t>& init_data, scoped_ptr<media::NewSessionCdmPromise> promise) override; void LoadSession(SessionType session_type, const std::string& session_id, scoped_ptr<media::NewSessionCdmPromise> promise) override; void UpdateSession(const std::string& session_id, - const uint8* response, - int response_length, + const std::vector<uint8_t>& response, scoped_ptr<media::SimpleCdmPromise> promise) override; void CloseSession(const std::string& session_id, scoped_ptr<media::SimpleCdmPromise> promise) override; diff --git a/media/base/media_keys.h b/media/base/media_keys.h index 796d78d..ba2a680 100644 --- a/media/base/media_keys.h +++ b/media/base/media_keys.h @@ -89,8 +89,7 @@ class MEDIA_EXPORT MediaKeys{ // Provides a server certificate to be used to encrypt messages to the // license server. - virtual void SetServerCertificate(const uint8* certificate_data, - int certificate_data_length, + virtual void SetServerCertificate(const std::vector<uint8_t>& certificate, scoped_ptr<SimpleCdmPromise> promise) = 0; // Creates a session with |session_type|. Then generates a request with the @@ -105,8 +104,7 @@ class MEDIA_EXPORT MediaKeys{ virtual void CreateSessionAndGenerateRequest( SessionType session_type, EmeInitDataType init_data_type, - const uint8* init_data, - int init_data_length, + const std::vector<uint8_t>& init_data, scoped_ptr<NewSessionCdmPromise> promise) = 0; // Loads a session with the |session_id| provided. @@ -118,8 +116,7 @@ class MEDIA_EXPORT MediaKeys{ // Updates a session specified by |session_id| with |response|. virtual void UpdateSession(const std::string& session_id, - const uint8* response, - int response_length, + const std::vector<uint8_t>& response, scoped_ptr<SimpleCdmPromise> promise) = 0; // Closes the session specified by |session_id|. The CDM should resolve or @@ -151,7 +148,7 @@ class MEDIA_EXPORT MediaKeys{ typedef base::Callback<void(const std::string& session_id, MediaKeys::MessageType message_type, - const std::vector<uint8>& message, + const std::vector<uint8_t>& message, const GURL& legacy_destination_url)> SessionMessageCB; @@ -163,7 +160,7 @@ typedef base::Callback<void(const std::string& session_id)> SessionClosedCB; typedef base::Callback<void(const std::string& session_id, MediaKeys::Exception exception, - uint32 system_code, + uint32_t system_code, const std::string& error_message)> LegacySessionErrorCB; diff --git a/media/blink/cdm_session_adapter.cc b/media/blink/cdm_session_adapter.cc index 8e62bce..692eecc 100644 --- a/media/blink/cdm_session_adapter.cc +++ b/media/blink/cdm_session_adapter.cc @@ -50,11 +50,9 @@ void CdmSessionAdapter::CreateCdm( } void CdmSessionAdapter::SetServerCertificate( - const uint8* server_certificate, - int server_certificate_length, + const std::vector<uint8_t>& certificate, scoped_ptr<SimpleCdmPromise> promise) { - cdm_->SetServerCertificate(server_certificate, server_certificate_length, - promise.Pass()); + cdm_->SetServerCertificate(certificate, promise.Pass()); } WebContentDecryptionModuleSessionImpl* CdmSessionAdapter::CreateSession() { @@ -79,12 +77,11 @@ void CdmSessionAdapter::UnregisterSession(const std::string& session_id) { void CdmSessionAdapter::InitializeNewSession( EmeInitDataType init_data_type, - const uint8* init_data, - int init_data_length, + const std::vector<uint8_t>& init_data, MediaKeys::SessionType session_type, scoped_ptr<NewSessionCdmPromise> promise) { cdm_->CreateSessionAndGenerateRequest(session_type, init_data_type, init_data, - init_data_length, promise.Pass()); + promise.Pass()); } void CdmSessionAdapter::LoadSession(MediaKeys::SessionType session_type, @@ -94,10 +91,9 @@ void CdmSessionAdapter::LoadSession(MediaKeys::SessionType session_type, } void CdmSessionAdapter::UpdateSession(const std::string& session_id, - const uint8* response, - int response_length, + const std::vector<uint8_t>& response, scoped_ptr<SimpleCdmPromise> promise) { - cdm_->UpdateSession(session_id, response, response_length, promise.Pass()); + cdm_->UpdateSession(session_id, response, promise.Pass()); } void CdmSessionAdapter::CloseSession(const std::string& session_id, @@ -146,7 +142,7 @@ void CdmSessionAdapter::OnCdmCreated( void CdmSessionAdapter::OnSessionMessage( const std::string& session_id, MediaKeys::MessageType message_type, - const std::vector<uint8>& message, + const std::vector<uint8_t>& message, const GURL& /* legacy_destination_url */) { WebContentDecryptionModuleSessionImpl* session = GetSession(session_id); DLOG_IF(WARNING, !session) << __FUNCTION__ << " for unknown session " @@ -187,7 +183,7 @@ void CdmSessionAdapter::OnSessionClosed(const std::string& session_id) { void CdmSessionAdapter::OnLegacySessionError( const std::string& session_id, MediaKeys::Exception exception_code, - uint32 system_code, + uint32_t system_code, const std::string& error_message) { // Error events not used by unprefixed EME. // TODO(jrummell): Remove when prefixed EME removed. diff --git a/media/blink/cdm_session_adapter.h b/media/blink/cdm_session_adapter.h index 5ed7550e..cc60143 100644 --- a/media/blink/cdm_session_adapter.h +++ b/media/blink/cdm_session_adapter.h @@ -7,6 +7,7 @@ #include <map> #include <string> +#include <vector> #include "base/basictypes.h" #include "base/containers/hash_tables.h" @@ -42,8 +43,7 @@ class CdmSessionAdapter : public base::RefCounted<CdmSessionAdapter> { // Provides a server certificate to be used to encrypt messages to the // license server. - void SetServerCertificate(const uint8* server_certificate, - int server_certificate_length, + void SetServerCertificate(const std::vector<uint8_t>& certificate, scoped_ptr<SimpleCdmPromise> promise); // Creates a new session and adds it to the internal map. The caller owns the @@ -64,8 +64,7 @@ class CdmSessionAdapter : public base::RefCounted<CdmSessionAdapter> { // Initializes a session with the |init_data_type|, |init_data| and // |session_type| provided. void InitializeNewSession(EmeInitDataType init_data_type, - const uint8* init_data, - int init_data_length, + const std::vector<uint8_t>& init_data, MediaKeys::SessionType session_type, scoped_ptr<NewSessionCdmPromise> promise); @@ -76,8 +75,7 @@ class CdmSessionAdapter : public base::RefCounted<CdmSessionAdapter> { // Updates the session specified by |session_id| with |response|. void UpdateSession(const std::string& session_id, - const uint8* response, - int response_length, + const std::vector<uint8_t>& response, scoped_ptr<SimpleCdmPromise> promise); // Closes the session specified by |session_id|. @@ -118,7 +116,7 @@ class CdmSessionAdapter : public base::RefCounted<CdmSessionAdapter> { // Callbacks for firing session events. void OnSessionMessage(const std::string& session_id, MediaKeys::MessageType message_type, - const std::vector<uint8>& message, + const std::vector<uint8_t>& message, const GURL& legacy_destination_url); void OnSessionKeysChange(const std::string& session_id, bool has_additional_usable_key, @@ -128,7 +126,7 @@ class CdmSessionAdapter : public base::RefCounted<CdmSessionAdapter> { void OnSessionClosed(const std::string& session_id); void OnLegacySessionError(const std::string& session_id, MediaKeys::Exception exception_code, - uint32 system_code, + uint32_t system_code, const std::string& error_message); // Helper function of the callbacks. diff --git a/media/blink/webcontentdecryptionmodule_impl.cc b/media/blink/webcontentdecryptionmodule_impl.cc index 7bdd9c9..6284602 100644 --- a/media/blink/webcontentdecryptionmodule_impl.cc +++ b/media/blink/webcontentdecryptionmodule_impl.cc @@ -93,8 +93,8 @@ void WebContentDecryptionModuleImpl::setServerCertificate( blink::WebContentDecryptionModuleResult result) { DCHECK(server_certificate); adapter_->SetServerCertificate( - server_certificate, - base::saturated_cast<int>(server_certificate_length), + std::vector<uint8>(server_certificate, + server_certificate + server_certificate_length), scoped_ptr<SimpleCdmPromise>( new CdmResultPromise<>(result, std::string()))); } diff --git a/media/blink/webcontentdecryptionmodulesession_impl.cc b/media/blink/webcontentdecryptionmodulesession_impl.cc index 94afa0e..5ecba27 100644 --- a/media/blink/webcontentdecryptionmodulesession_impl.cc +++ b/media/blink/webcontentdecryptionmodulesession_impl.cc @@ -8,6 +8,7 @@ #include "base/callback_helpers.h" #include "base/logging.h" #include "base/numerics/safe_conversions.h" +#include "base/stl_util.h" #include "base/strings/string_util.h" #include "base/strings/utf_string_conversions.h" #include "media/base/cdm_key_information.h" @@ -110,12 +111,11 @@ static bool SanitizeInitData(EmeInitDataType init_data_type, return true; case EmeInitDataType::CENC: - if (!ValidatePsshInput(init_data, init_data_length)) { + sanitized_init_data->assign(init_data, init_data + init_data_length); + if (!ValidatePsshInput(*sanitized_init_data)) { error_message->assign("Initialization data for CENC is incorrect."); return false; } - - sanitized_init_data->assign(init_data, init_data + init_data_length); return true; case EmeInitDataType::KEYIDS: { @@ -173,6 +173,7 @@ void WebContentDecryptionModuleSessionImpl::initializeNewSession( size_t init_data_length, blink::WebEncryptedMediaSessionType session_type, blink::WebContentDecryptionModuleResult result) { + DCHECK(init_data); DCHECK(session_id_.empty()); // From https://w3c.github.io/encrypted-media/#generateRequest. @@ -225,9 +226,7 @@ void WebContentDecryptionModuleSessionImpl::initializeNewSession( // instance value. // 9.7 Use the cdm to execute the following steps: adapter_->InitializeNewSession( - eme_init_data_type, vector_as_array(&sanitized_init_data), - base::saturated_cast<int>(sanitized_init_data.size()), - convertSessionType(session_type), + eme_init_data_type, sanitized_init_data, convertSessionType(session_type), scoped_ptr<NewSessionCdmPromise>(new NewSessionCdmResultPromise( result, adapter_->GetKeySystemUMAPrefix() + kGenerateRequestUMAName, base::Bind( @@ -260,7 +259,7 @@ void WebContentDecryptionModuleSessionImpl::update( DCHECK(response); DCHECK(!session_id_.empty()); adapter_->UpdateSession( - session_id_, response, base::saturated_cast<int>(response_length), + session_id_, std::vector<uint8>(response, response + response_length), scoped_ptr<SimpleCdmPromise>(new CdmResultPromise<>( result, adapter_->GetKeySystemUMAPrefix() + kUpdateSessionUMAName))); } diff --git a/media/cdm/aes_decryptor.cc b/media/cdm/aes_decryptor.cc index ec0de28..77783e3 100644 --- a/media/cdm/aes_decryptor.cc +++ b/media/cdm/aes_decryptor.cc @@ -105,7 +105,7 @@ void AesDecryptor::SessionIdDecryptionKeyMap::Erase( key_list_.erase(position); } -uint32 AesDecryptor::next_session_id_ = 1; +uint32_t AesDecryptor::next_session_id_ = 1; enum ClearBytesBufferSel { kSrcContainsClearBytes, @@ -114,8 +114,8 @@ enum ClearBytesBufferSel { static void CopySubsamples(const std::vector<SubsampleEntry>& subsamples, const ClearBytesBufferSel sel, - const uint8* src, - uint8* dst) { + const uint8_t* src, + uint8_t* dst) { for (size_t i = 0; i < subsamples.size(); i++) { const SubsampleEntry& subsample = subsamples[i]; if (sel == kSrcContainsClearBytes) { @@ -167,7 +167,7 @@ static scoped_refptr<DecoderBuffer> DecryptData(const DecoderBuffer& input, // TODO(xhwang): Find a way to avoid this data copy. return DecoderBuffer::CopyFrom( - reinterpret_cast<const uint8*>(decrypted_text.data()), + reinterpret_cast<const uint8_t*>(decrypted_text.data()), decrypted_text.size()); } @@ -192,7 +192,7 @@ static scoped_refptr<DecoderBuffer> DecryptData(const DecoderBuffer& input, // No need to decrypt if there is no encrypted data. if (total_encrypted_size <= 0) { - return DecoderBuffer::CopyFrom(reinterpret_cast<const uint8*>(sample), + return DecoderBuffer::CopyFrom(reinterpret_cast<const uint8_t*>(sample), sample_size); } @@ -202,9 +202,10 @@ static scoped_refptr<DecoderBuffer> DecryptData(const DecoderBuffer& input, // copy all encrypted subsamples to a contiguous buffer, decrypt them, then // copy the decrypted bytes over the encrypted bytes in the output. // TODO(strobe): attempt to reduce number of memory copies - scoped_ptr<uint8[]> encrypted_bytes(new uint8[total_encrypted_size]); + scoped_ptr<uint8_t[]> encrypted_bytes(new uint8_t[total_encrypted_size]); CopySubsamples(subsamples, kSrcContainsClearBytes, - reinterpret_cast<const uint8*>(sample), encrypted_bytes.get()); + reinterpret_cast<const uint8_t*>(sample), + encrypted_bytes.get()); base::StringPiece encrypted_text( reinterpret_cast<const char*>(encrypted_bytes.get()), @@ -217,9 +218,9 @@ static scoped_refptr<DecoderBuffer> DecryptData(const DecoderBuffer& input, DCHECK_EQ(decrypted_text.size(), encrypted_text.size()); scoped_refptr<DecoderBuffer> output = DecoderBuffer::CopyFrom( - reinterpret_cast<const uint8*>(sample), sample_size); + reinterpret_cast<const uint8_t*>(sample), sample_size); CopySubsamples(subsamples, kDstContainsClearBytes, - reinterpret_cast<const uint8*>(decrypted_text.data()), + reinterpret_cast<const uint8_t*>(decrypted_text.data()), output->writable_data()); return output; } @@ -242,8 +243,7 @@ AesDecryptor::~AesDecryptor() { key_map_.clear(); } -void AesDecryptor::SetServerCertificate(const uint8* certificate_data, - int certificate_data_length, +void AesDecryptor::SetServerCertificate(const std::vector<uint8_t>& certificate, scoped_ptr<SimpleCdmPromise> promise) { promise->reject( NOT_SUPPORTED_ERROR, 0, "SetServerCertificate() is not supported."); @@ -252,8 +252,7 @@ void AesDecryptor::SetServerCertificate(const uint8* certificate_data, void AesDecryptor::CreateSessionAndGenerateRequest( SessionType session_type, EmeInitDataType init_data_type, - const uint8* init_data, - int init_data_length, + const std::vector<uint8_t>& init_data, scoped_ptr<NewSessionCdmPromise> promise) { std::string session_id(base::UintToString(next_session_id_++)); valid_sessions_.insert(session_id); @@ -261,27 +260,26 @@ void AesDecryptor::CreateSessionAndGenerateRequest( // For now, the AesDecryptor does not care about |session_type|. // TODO(jrummell): Validate |session_type|. - std::vector<uint8> message; + std::vector<uint8_t> message; // TODO(jrummell): Since unprefixed will never send NULL, remove this check // when prefixed EME is removed (http://crbug.com/249976). - if (init_data && init_data_length) { - std::vector<std::vector<uint8>> keys; + if (!init_data.empty()) { + std::vector<std::vector<uint8_t>> keys; switch (init_data_type) { case EmeInitDataType::WEBM: // |init_data| is simply the key needed. - keys.push_back( - std::vector<uint8>(init_data, init_data + init_data_length)); + keys.push_back(init_data); break; case EmeInitDataType::CENC: // |init_data| is a set of 0 or more concatenated 'pssh' boxes. - if (!GetKeyIdsForCommonSystemId(init_data, init_data_length, &keys)) { + if (!GetKeyIdsForCommonSystemId(init_data, &keys)) { promise->reject(NOT_SUPPORTED_ERROR, 0, "No supported PSSH box found."); return; } break; case EmeInitDataType::KEYIDS: { - std::string init_data_string(init_data, init_data + init_data_length); + std::string init_data_string(init_data.begin(), init_data.end()); std::string error_message; if (!ExtractKeyIdsFromKeyIdsInitData(init_data_string, &keys, &error_message)) { @@ -315,11 +313,9 @@ void AesDecryptor::LoadSession(SessionType session_type, } void AesDecryptor::UpdateSession(const std::string& session_id, - const uint8* response, - int response_length, + const std::vector<uint8_t>& response, scoped_ptr<SimpleCdmPromise> promise) { - CHECK(response); - CHECK_GT(response_length, 0); + CHECK(!response.empty()); // TODO(jrummell): Convert back to a DCHECK once prefixed EME is removed. if (valid_sessions_.find(session_id) == valid_sessions_.end()) { @@ -327,8 +323,7 @@ void AesDecryptor::UpdateSession(const std::string& session_id, return; } - std::string key_string(reinterpret_cast<const char*>(response), - response_length); + std::string key_string(response.begin(), response.end()); KeyIdAndKeyPairs keys; SessionType session_type = MediaKeys::TEMPORARY_SESSION; diff --git a/media/cdm/aes_decryptor.h b/media/cdm/aes_decryptor.h index 5c7a06c..110abfb1 100644 --- a/media/cdm/aes_decryptor.h +++ b/media/cdm/aes_decryptor.h @@ -7,6 +7,7 @@ #include <set> #include <string> +#include <vector> #include "base/basictypes.h" #include "base/containers/scoped_ptr_hash_map.h" @@ -39,21 +40,18 @@ class MEDIA_EXPORT AesDecryptor : public MediaKeys, ~AesDecryptor() override; // MediaKeys implementation. - void SetServerCertificate(const uint8* certificate_data, - int certificate_data_length, + void SetServerCertificate(const std::vector<uint8_t>& certificate, scoped_ptr<SimpleCdmPromise> promise) override; void CreateSessionAndGenerateRequest( SessionType session_type, EmeInitDataType init_data_type, - const uint8* init_data, - int init_data_length, + const std::vector<uint8_t>& init_data, scoped_ptr<NewSessionCdmPromise> promise) override; void LoadSession(SessionType session_type, const std::string& session_id, scoped_ptr<NewSessionCdmPromise> promise) override; void UpdateSession(const std::string& session_id, - const uint8* response, - int response_length, + const std::vector<uint8_t>& response, scoped_ptr<SimpleCdmPromise> promise) override; void CloseSession(const std::string& session_id, scoped_ptr<SimpleCdmPromise> promise) override; @@ -149,7 +147,7 @@ class MEDIA_EXPORT AesDecryptor : public MediaKeys, // Make session ID unique per renderer by making it static. Session // IDs seen by the app will be "1", "2", etc. - static uint32 next_session_id_; + static uint32_t next_session_id_; NewKeyCB new_audio_key_cb_; NewKeyCB new_video_key_cb_; diff --git a/media/cdm/aes_decryptor_unittest.cc b/media/cdm/aes_decryptor_unittest.cc index 3f26239..6fd8cec 100644 --- a/media/cdm/aes_decryptor_unittest.cc +++ b/media/cdm/aes_decryptor_unittest.cc @@ -285,9 +285,9 @@ class AesDecryptorTest : public testing::Test { DCHECK(!key_id.empty()); EXPECT_CALL(*this, OnSessionMessage(IsNotEmpty(), _, IsJSONDictionary(), GURL::EmptyGURL())); - decryptor_.CreateSessionAndGenerateRequest( - MediaKeys::TEMPORARY_SESSION, EmeInitDataType::WEBM, &key_id[0], - key_id.size(), CreateSessionPromise(RESOLVED)); + decryptor_.CreateSessionAndGenerateRequest(MediaKeys::TEMPORARY_SESSION, + EmeInitDataType::WEBM, key_id, + CreateSessionPromise(RESOLVED)); // This expects the promise to be called synchronously, which is the case // for AesDecryptor. return session_id_; @@ -335,8 +335,7 @@ class AesDecryptorTest : public testing::Test { } decryptor_.UpdateSession(session_id, - reinterpret_cast<const uint8*>(key.c_str()), - key.length(), + std::vector<uint8>(key.begin(), key.end()), CreatePromise(expected_result)); } @@ -432,29 +431,29 @@ class AesDecryptorTest : public testing::Test { TEST_F(AesDecryptorTest, CreateSessionWithNullInitData) { EXPECT_CALL(*this, OnSessionMessage(IsNotEmpty(), _, IsEmpty(), GURL::EmptyGURL())); - decryptor_.CreateSessionAndGenerateRequest(MediaKeys::TEMPORARY_SESSION, - EmeInitDataType::WEBM, NULL, 0, - CreateSessionPromise(RESOLVED)); + decryptor_.CreateSessionAndGenerateRequest( + MediaKeys::TEMPORARY_SESSION, EmeInitDataType::WEBM, std::vector<uint8>(), + CreateSessionPromise(RESOLVED)); } TEST_F(AesDecryptorTest, MultipleCreateSession) { EXPECT_CALL(*this, OnSessionMessage(IsNotEmpty(), _, IsEmpty(), GURL::EmptyGURL())); - decryptor_.CreateSessionAndGenerateRequest(MediaKeys::TEMPORARY_SESSION, - EmeInitDataType::WEBM, NULL, 0, - CreateSessionPromise(RESOLVED)); + decryptor_.CreateSessionAndGenerateRequest( + MediaKeys::TEMPORARY_SESSION, EmeInitDataType::WEBM, std::vector<uint8>(), + CreateSessionPromise(RESOLVED)); EXPECT_CALL(*this, OnSessionMessage(IsNotEmpty(), _, IsEmpty(), GURL::EmptyGURL())); - decryptor_.CreateSessionAndGenerateRequest(MediaKeys::TEMPORARY_SESSION, - EmeInitDataType::WEBM, NULL, 0, - CreateSessionPromise(RESOLVED)); + decryptor_.CreateSessionAndGenerateRequest( + MediaKeys::TEMPORARY_SESSION, EmeInitDataType::WEBM, std::vector<uint8>(), + CreateSessionPromise(RESOLVED)); EXPECT_CALL(*this, OnSessionMessage(IsNotEmpty(), _, IsEmpty(), GURL::EmptyGURL())); - decryptor_.CreateSessionAndGenerateRequest(MediaKeys::TEMPORARY_SESSION, - EmeInitDataType::WEBM, NULL, 0, - CreateSessionPromise(RESOLVED)); + decryptor_.CreateSessionAndGenerateRequest( + MediaKeys::TEMPORARY_SESSION, EmeInitDataType::WEBM, std::vector<uint8>(), + CreateSessionPromise(RESOLVED)); } TEST_F(AesDecryptorTest, CreateSessionWithCencInitData) { @@ -475,8 +474,9 @@ TEST_F(AesDecryptorTest, CreateSessionWithCencInitData) { EXPECT_CALL(*this, OnSessionMessage(IsNotEmpty(), _, IsJSONDictionary(), GURL::EmptyGURL())); decryptor_.CreateSessionAndGenerateRequest( - MediaKeys::TEMPORARY_SESSION, EmeInitDataType::CENC, init_data, - arraysize(init_data), CreateSessionPromise(RESOLVED)); + MediaKeys::TEMPORARY_SESSION, EmeInitDataType::CENC, + std::vector<uint8>(init_data, init_data + arraysize(init_data)), + CreateSessionPromise(RESOLVED)); } TEST_F(AesDecryptorTest, CreateSessionWithKeyIdsInitData) { @@ -487,7 +487,7 @@ TEST_F(AesDecryptorTest, CreateSessionWithKeyIdsInitData) { GURL::EmptyGURL())); decryptor_.CreateSessionAndGenerateRequest( MediaKeys::TEMPORARY_SESSION, EmeInitDataType::KEYIDS, - reinterpret_cast<const uint8*>(init_data), arraysize(init_data) - 1, + std::vector<uint8>(init_data, init_data + arraysize(init_data) - 1), CreateSessionPromise(RESOLVED)); } diff --git a/media/cdm/cenc_utils.cc b/media/cdm/cenc_utils.cc index a59c19c..86779b2 100644 --- a/media/cdm/cenc_utils.cc +++ b/media/cdm/cenc_utils.cc @@ -40,10 +40,10 @@ const int kMinimumBoxSizeInBytes = 32; // SystemID for the Common System. // https://w3c.github.io/encrypted-media/cenc-format.html#common-system -const uint8 kCommonSystemId[] = { 0x10, 0x77, 0xef, 0xec, - 0xc0, 0xb2, 0x4d, 0x02, - 0xac, 0xe3, 0x3c, 0x1e, - 0x52, 0xe2, 0xfb, 0x4b }; +const uint8_t kCommonSystemId[] = { 0x10, 0x77, 0xef, 0xec, + 0xc0, 0xb2, 0x4d, 0x02, + 0xac, 0xe3, 0x3c, 0x1e, + 0x52, 0xe2, 0xfb, 0x4b }; #define RCHECK(x) \ do { \ @@ -52,10 +52,10 @@ const uint8 kCommonSystemId[] = { 0x10, 0x77, 0xef, 0xec, } while (0) // Helper function to read up to 32 bits from a bit stream. -static uint32 ReadBits(BitReader* reader, int num_bits) { +static uint32_t ReadBits(BitReader* reader, int num_bits) { DCHECK_GE(reader->bits_available(), num_bits); DCHECK((num_bits > 0) && (num_bits <= 32)); - uint32 value; + uint32_t value; reader->ReadBits(num_bits, &value); return value; } @@ -63,7 +63,7 @@ static uint32 ReadBits(BitReader* reader, int num_bits) { // Checks whether the next 16 bytes matches the Common SystemID. // Assumes |reader| has enough data. static bool IsCommonSystemID(BitReader* reader) { - for (uint32 i = 0; i < arraysize(kCommonSystemId); ++i) { + for (uint32_t i = 0; i < arraysize(kCommonSystemId); ++i) { if (ReadBits(reader, 8) != kCommonSystemId[i]) return false; } @@ -100,11 +100,11 @@ static bool ValidBoxHeader(BitReader* reader, uint32* size) { return available_bytes >= *size; } -bool ValidatePsshInput(const uint8* input, size_t input_length) { +bool ValidatePsshInput(const std::vector<uint8_t>& input) { size_t offset = 0; - while (offset < input_length) { + while (offset < input.size()) { // Create a BitReader over the remaining part of the buffer. - BitReader reader(input + offset, input_length - offset); + BitReader reader(&input[offset], input.size() - offset); uint32 size; RCHECK(ValidBoxHeader(&reader, &size)); @@ -113,18 +113,16 @@ bool ValidatePsshInput(const uint8* input, size_t input_length) { } // Only valid if this contains 0 or more 'pssh' boxes. - return offset == input_length; + return offset == input.size(); } -bool GetKeyIdsForCommonSystemId(const uint8* input, - int input_length, - std::vector<std::vector<uint8>>* key_ids) { - int offset = 0; - std::vector<std::vector<uint8>> result; +bool GetKeyIdsForCommonSystemId(const std::vector<uint8_t>& input, + KeyIdList* key_ids) { + size_t offset = 0; + KeyIdList result; - while (offset < input_length) { - // Create a BitReader over the remaining part of the buffer. - BitReader reader(input + offset, input_length - offset); + while (offset < input.size()) { + BitReader reader(&input[offset], input.size() - offset); uint32 size; RCHECK(ValidBoxHeader(&reader, &size)); @@ -132,7 +130,7 @@ bool GetKeyIdsForCommonSystemId(const uint8* input, offset += size; // Check the version, as KIDs only available if version > 0. - uint8 version = ReadBits(&reader, 8); + uint8_t version = ReadBits(&reader, 8); if (version == 0) continue; @@ -142,23 +140,24 @@ bool GetKeyIdsForCommonSystemId(const uint8* input, continue; // Validate SystemID - RCHECK(static_cast<uint32>(reader.bits_available()) >= + RCHECK(static_cast<uint32_t>(reader.bits_available()) >= arraysize(kCommonSystemId) * 8); if (!IsCommonSystemID(&reader)) continue; // Not Common System, so try the next pssh box. // Since version > 0, next field is the KID_count. - RCHECK(static_cast<uint32>(reader.bits_available()) >= sizeof(uint32) * 8); - uint32 count = ReadBits(&reader, 32); + RCHECK(static_cast<uint32_t>(reader.bits_available()) >= + sizeof(uint32_t) * 8); + uint32_t count = ReadBits(&reader, 32); if (count == 0) continue; // Make sure there is enough data for all the KIDs specified, and then // extract them. - RCHECK(static_cast<uint32>(reader.bits_available()) > count * 16 * 8); + RCHECK(static_cast<uint32_t>(reader.bits_available()) > count * 16 * 8); while (count > 0) { - std::vector<uint8> key; + std::vector<uint8_t> key; key.reserve(16); for (int i = 0; i < 16; ++i) { key.push_back(ReadBits(&reader, 8)); diff --git a/media/cdm/cenc_utils.h b/media/cdm/cenc_utils.h index 6fd9952..ec85fb3 100644 --- a/media/cdm/cenc_utils.h +++ b/media/cdm/cenc_utils.h @@ -9,12 +9,13 @@ #include "base/basictypes.h" #include "media/base/media_export.h" +#include "media/cdm/json_web_key.h" namespace media { // Validate that |input| is a set of concatenated 'pssh' boxes and the sizes // match. Returns true if |input| looks valid, false otherwise. -MEDIA_EXPORT bool ValidatePsshInput(const uint8* input, size_t input_length); +MEDIA_EXPORT bool ValidatePsshInput(const std::vector<uint8_t>& input); // Gets the Key Ids from a 'pssh' box for the Common SystemID among one or // more concatenated 'pssh' boxes. If |input| looks valid, then true is @@ -24,10 +25,8 @@ MEDIA_EXPORT bool ValidatePsshInput(const uint8* input, size_t input_length); // found, or are included but don't contain any key IDs. This should be // fixed once the test files are updated to include correct 'pssh' boxes. // http://crbug.com/460308 -MEDIA_EXPORT bool GetKeyIdsForCommonSystemId( - const uint8* input, - int input_length, - std::vector<std::vector<uint8>>* key_ids); +MEDIA_EXPORT bool GetKeyIdsForCommonSystemId(const std::vector<uint8_t>& input, + KeyIdList* key_ids); } // namespace media diff --git a/media/cdm/cenc_utils_unittest.cc b/media/cdm/cenc_utils_unittest.cc index fd481da..9923619 100644 --- a/media/cdm/cenc_utils_unittest.cc +++ b/media/cdm/cenc_utils_unittest.cc @@ -9,19 +9,19 @@ namespace media { -const uint8 kKey1Data[] = { +const uint8_t kKey1Data[] = { 0x7E, 0x57, 0x1D, 0x03, 0x7E, 0x57, 0x1D, 0x03, 0x7E, 0x57, 0x1D, 0x03, 0x7E, 0x57, 0x1D, 0x03 }; -const uint8 kKey2Data[] = { +const uint8_t kKey2Data[] = { 0x7E, 0x57, 0x1D, 0x04, 0x7E, 0x57, 0x1D, 0x04, 0x7E, 0x57, 0x1D, 0x04, 0x7E, 0x57, 0x1D, 0x04, }; -const uint8 kKey3Data[] = { +const uint8_t kKey3Data[] = { 0x7E, 0x57, 0x1D, 0x04, 0x7E, 0x57, 0x1D, 0x05, 0x7E, 0x57, 0x1D, 0x04, 0x7E, 0x57, 0x1D, 0x05, }; -const uint8 kKey4Data[] = { +const uint8_t kKey4Data[] = { 0x7E, 0x57, 0x1D, 0x04, 0x7E, 0x57, 0x1D, 0x06, 0x7E, 0x57, 0x1D, 0x04, 0x7E, 0x57, 0x1D, 0x06, }; @@ -36,7 +36,9 @@ class CencUtilsTest : public testing::Test { protected: // Initialize the start of the 'pssh' box (up to key_count) - void InitializePSSHBox(std::vector<uint8>* box, uint8 size, uint8 version) { + void InitializePSSHBox(std::vector<uint8_t>* box, + uint8_t size, + uint8_t version) { DCHECK(box->size() == 0); box->reserve(size); @@ -75,9 +77,9 @@ class CencUtilsTest : public testing::Test { box->push_back(0x4B); } - std::vector<uint8> MakePSSHBox(uint8 version) { - std::vector<uint8> box; - uint8 size = (version == 0) ? 32 : 36; + std::vector<uint8_t> MakePSSHBox(uint8_t version) { + std::vector<uint8_t> box; + uint8_t size = (version == 0) ? 32 : 36; InitializePSSHBox(&box, size, version); if (version > 0) { // Add key_count (= 0). @@ -94,13 +96,13 @@ class CencUtilsTest : public testing::Test { return box; } - std::vector<uint8> MakePSSHBox(uint8 version, - const std::vector<uint8>& key1) { + std::vector<uint8_t> MakePSSHBox(uint8_t version, + const std::vector<uint8_t>& key1) { DCHECK(version > 0); DCHECK(key1.size() == 16); - std::vector<uint8> box; - uint8 size = 52; + std::vector<uint8_t> box; + uint8_t size = 52; InitializePSSHBox(&box, size, version); // Add key_count (= 1). @@ -121,15 +123,15 @@ class CencUtilsTest : public testing::Test { return box; } - std::vector<uint8> MakePSSHBox(uint8 version, - const std::vector<uint8>& key1, - const std::vector<uint8>& key2) { + std::vector<uint8_t> MakePSSHBox(uint8_t version, + const std::vector<uint8_t>& key1, + const std::vector<uint8_t>& key2) { DCHECK(version > 0); DCHECK(key1.size() == 16); DCHECK(key2.size() == 16); - std::vector<uint8> box; - uint8 size = 68; + std::vector<uint8_t> box; + uint8_t size = 68; InitializePSSHBox(&box, size, version); // Add key_count (= 2). @@ -154,94 +156,94 @@ class CencUtilsTest : public testing::Test { return box; } - const std::vector<uint8>& Key1() { return key1_; } - const std::vector<uint8>& Key2() { return key2_; } - const std::vector<uint8>& Key3() { return key3_; } - const std::vector<uint8>& Key4() { return key4_; } + const std::vector<uint8_t>& Key1() { return key1_; } + const std::vector<uint8_t>& Key2() { return key2_; } + const std::vector<uint8_t>& Key3() { return key3_; } + const std::vector<uint8_t>& Key4() { return key4_; } private: - std::vector<uint8> key1_; - std::vector<uint8> key2_; - std::vector<uint8> key3_; - std::vector<uint8> key4_; + std::vector<uint8_t> key1_; + std::vector<uint8_t> key2_; + std::vector<uint8_t> key3_; + std::vector<uint8_t> key4_; }; TEST_F(CencUtilsTest, EmptyPSSH) { - std::vector<std::vector<uint8>> key_ids; - EXPECT_TRUE(ValidatePsshInput(nullptr, 0)); - EXPECT_TRUE(GetKeyIdsForCommonSystemId(nullptr, 0, &key_ids)); + KeyIdList key_ids; + EXPECT_TRUE(ValidatePsshInput(std::vector<uint8_t>())); + EXPECT_TRUE(GetKeyIdsForCommonSystemId(std::vector<uint8_t>(), &key_ids)); EXPECT_EQ(0u, key_ids.size()); } TEST_F(CencUtilsTest, PSSHVersion0) { - std::vector<uint8> box = MakePSSHBox(0); - std::vector<std::vector<uint8>> key_ids; - EXPECT_TRUE(ValidatePsshInput(&box[0], box.size())); - EXPECT_TRUE(GetKeyIdsForCommonSystemId(&box[0], box.size(), &key_ids)); + std::vector<uint8_t> box = MakePSSHBox(0); + KeyIdList key_ids; + EXPECT_TRUE(ValidatePsshInput(box)); + EXPECT_TRUE(GetKeyIdsForCommonSystemId(box, &key_ids)); EXPECT_EQ(0u, key_ids.size()); } TEST_F(CencUtilsTest, PSSHVersion1WithNoKeys) { - std::vector<uint8> box = MakePSSHBox(1); - std::vector<std::vector<uint8>> key_ids; - EXPECT_TRUE(ValidatePsshInput(&box[0], box.size())); - EXPECT_TRUE(GetKeyIdsForCommonSystemId(&box[0], box.size(), &key_ids)); + std::vector<uint8_t> box = MakePSSHBox(1); + KeyIdList key_ids; + EXPECT_TRUE(ValidatePsshInput(box)); + EXPECT_TRUE(GetKeyIdsForCommonSystemId(box, &key_ids)); EXPECT_EQ(0u, key_ids.size()); } TEST_F(CencUtilsTest, PSSHVersion1WithOneKey) { - std::vector<uint8> box = MakePSSHBox(1, Key1()); - std::vector<std::vector<uint8>> key_ids; - EXPECT_TRUE(ValidatePsshInput(&box[0], box.size())); - EXPECT_TRUE(GetKeyIdsForCommonSystemId(&box[0], box.size(), &key_ids)); + std::vector<uint8_t> box = MakePSSHBox(1, Key1()); + KeyIdList key_ids; + EXPECT_TRUE(ValidatePsshInput(box)); + EXPECT_TRUE(GetKeyIdsForCommonSystemId(box, &key_ids)); EXPECT_EQ(1u, key_ids.size()); EXPECT_EQ(key_ids[0], Key1()); } TEST_F(CencUtilsTest, PSSHVersion1WithTwoKeys) { - std::vector<uint8> box = MakePSSHBox(1, Key1(), Key2()); - std::vector<std::vector<uint8>> key_ids; - EXPECT_TRUE(ValidatePsshInput(&box[0], box.size())); - EXPECT_TRUE(GetKeyIdsForCommonSystemId(&box[0], box.size(), &key_ids)); + std::vector<uint8_t> box = MakePSSHBox(1, Key1(), Key2()); + KeyIdList key_ids; + EXPECT_TRUE(ValidatePsshInput(box)); + EXPECT_TRUE(GetKeyIdsForCommonSystemId(box, &key_ids)); EXPECT_EQ(2u, key_ids.size()); EXPECT_EQ(key_ids[0], Key1()); EXPECT_EQ(key_ids[1], Key2()); } TEST_F(CencUtilsTest, PSSHVersion0Plus1) { - std::vector<uint8> box0 = MakePSSHBox(0); - std::vector<uint8> box1 = MakePSSHBox(1, Key1()); + std::vector<uint8_t> box0 = MakePSSHBox(0); + std::vector<uint8_t> box1 = MakePSSHBox(1, Key1()); // Concatentate box1 into box0. for (const auto& value : box1) box0.push_back(value); - std::vector<std::vector<uint8>> key_ids; - EXPECT_TRUE(ValidatePsshInput(&box0[0], box0.size())); - EXPECT_TRUE(GetKeyIdsForCommonSystemId(&box0[0], box0.size(), &key_ids)); + KeyIdList key_ids; + EXPECT_TRUE(ValidatePsshInput(box0)); + EXPECT_TRUE(GetKeyIdsForCommonSystemId(box0, &key_ids)); EXPECT_EQ(1u, key_ids.size()); EXPECT_EQ(key_ids[0], Key1()); } TEST_F(CencUtilsTest, PSSHVersion1Plus0) { - std::vector<uint8> box0 = MakePSSHBox(0); - std::vector<uint8> box1 = MakePSSHBox(1, Key1()); + std::vector<uint8_t> box0 = MakePSSHBox(0); + std::vector<uint8_t> box1 = MakePSSHBox(1, Key1()); // Concatentate box0 into box1. for (const auto& value : box0) box1.push_back(value); - std::vector<std::vector<uint8>> key_ids; - EXPECT_TRUE(ValidatePsshInput(&box1[0], box1.size())); - EXPECT_TRUE(GetKeyIdsForCommonSystemId(&box1[0], box1.size(), &key_ids)); + KeyIdList key_ids; + EXPECT_TRUE(ValidatePsshInput(box1)); + EXPECT_TRUE(GetKeyIdsForCommonSystemId(box1, &key_ids)); EXPECT_EQ(1u, key_ids.size()); EXPECT_EQ(key_ids[0], Key1()); } TEST_F(CencUtilsTest, MultiplePSSHVersion1) { - std::vector<uint8> box = MakePSSHBox(1, Key1(), Key2()); - std::vector<uint8> box1 = MakePSSHBox(1, Key3()); - std::vector<uint8> box2 = MakePSSHBox(1, Key4()); + std::vector<uint8_t> box = MakePSSHBox(1, Key1(), Key2()); + std::vector<uint8_t> box1 = MakePSSHBox(1, Key3()); + std::vector<uint8_t> box2 = MakePSSHBox(1, Key4()); // Concatentate box1 into box. for (const auto& value : box1) @@ -250,9 +252,9 @@ TEST_F(CencUtilsTest, MultiplePSSHVersion1) { for (const auto& value : box2) box.push_back(value); - std::vector<std::vector<uint8>> key_ids; - EXPECT_TRUE(ValidatePsshInput(&box[0], box.size())); - EXPECT_TRUE(GetKeyIdsForCommonSystemId(&box[0], box.size(), &key_ids)); + KeyIdList key_ids; + EXPECT_TRUE(ValidatePsshInput(box)); + EXPECT_TRUE(GetKeyIdsForCommonSystemId(box, &key_ids)); EXPECT_EQ(4u, key_ids.size()); EXPECT_EQ(key_ids[0], Key1()); EXPECT_EQ(key_ids[1], Key2()); @@ -261,43 +263,45 @@ TEST_F(CencUtilsTest, MultiplePSSHVersion1) { } TEST_F(CencUtilsTest, InvalidPSSH) { - std::vector<uint8> box = MakePSSHBox(1, Key1(), Key2()); - std::vector<std::vector<uint8>> key_ids; + std::vector<uint8_t> box = MakePSSHBox(1, Key1(), Key2()); + KeyIdList key_ids; for (uint32 i = 1; i < box.size(); ++i) { // Modify size of data passed to be less than real size. - EXPECT_FALSE(ValidatePsshInput(&box[0], i)); - EXPECT_FALSE(GetKeyIdsForCommonSystemId(&box[0], i, &key_ids)); + std::vector<uint8_t> truncated(&box[0], &box[0] + i); + EXPECT_FALSE(ValidatePsshInput(truncated)); + EXPECT_FALSE(GetKeyIdsForCommonSystemId(truncated, &key_ids)); // Modify starting point. - EXPECT_FALSE(ValidatePsshInput(&box[i], box.size() - i)); - EXPECT_FALSE(GetKeyIdsForCommonSystemId(&box[i], box.size() - i, &key_ids)); + std::vector<uint8_t> changed_offset(&box[i], &box[i] + box.size() - i); + EXPECT_FALSE(ValidatePsshInput(changed_offset)); + EXPECT_FALSE(GetKeyIdsForCommonSystemId(changed_offset, &key_ids)); } } TEST_F(CencUtilsTest, InvalidSystemID) { - std::vector<uint8> box = MakePSSHBox(1, Key1(), Key2()); + std::vector<uint8_t> box = MakePSSHBox(1, Key1(), Key2()); // Modify the System ID. ++box[20]; - std::vector<std::vector<uint8>> key_ids; - EXPECT_TRUE(GetKeyIdsForCommonSystemId(&box[0], box.size(), &key_ids)); + KeyIdList key_ids; + EXPECT_TRUE(GetKeyIdsForCommonSystemId(box, &key_ids)); EXPECT_EQ(0u, key_ids.size()); } TEST_F(CencUtilsTest, InvalidFlags) { - std::vector<uint8> box = MakePSSHBox(1, Key1(), Key2()); + std::vector<uint8_t> box = MakePSSHBox(1, Key1(), Key2()); // Modify flags. box[10] = 3; - std::vector<std::vector<uint8>> key_ids; + KeyIdList key_ids; // TODO(jrummell): This should fail as the 'pssh' box is skipped. - EXPECT_TRUE(GetKeyIdsForCommonSystemId(&box[0], box.size(), &key_ids)); + EXPECT_TRUE(GetKeyIdsForCommonSystemId(box, &key_ids)); EXPECT_EQ(0u, key_ids.size()); } TEST_F(CencUtilsTest, LongSize) { - const uint8 data[] = { + const uint8_t data[] = { 0x00, 0x00, 0x00, 0x01, // size = 1 0x70, 0x73, 0x73, 0x68, // 'pssh' 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4c, // longsize @@ -313,14 +317,16 @@ TEST_F(CencUtilsTest, LongSize) { 0x00, 0x00, 0x00, 0x00 // datasize }; - std::vector<std::vector<uint8>> key_ids; - EXPECT_TRUE(ValidatePsshInput(data, arraysize(data))); - EXPECT_TRUE(GetKeyIdsForCommonSystemId(data, arraysize(data), &key_ids)); + KeyIdList key_ids; + EXPECT_TRUE( + ValidatePsshInput(std::vector<uint8_t>(data, data + arraysize(data)))); + EXPECT_TRUE(GetKeyIdsForCommonSystemId( + std::vector<uint8_t>(data, data + arraysize(data)), &key_ids)); EXPECT_EQ(2u, key_ids.size()); } TEST_F(CencUtilsTest, NoSize) { - const uint8 data[] = { + const uint8_t data[] = { 0x00, 0x00, 0x00, 0x00, // size = 0 0x70, 0x73, 0x73, 0x68, // 'pssh' 0x01, // version @@ -335,14 +341,16 @@ TEST_F(CencUtilsTest, NoSize) { 0x00, 0x00, 0x00, 0x00 // datasize }; - std::vector<std::vector<uint8>> key_ids; - EXPECT_TRUE(ValidatePsshInput(data, arraysize(data))); - EXPECT_TRUE(GetKeyIdsForCommonSystemId(data, arraysize(data), &key_ids)); + KeyIdList key_ids; + EXPECT_TRUE( + ValidatePsshInput(std::vector<uint8_t>(data, data + arraysize(data)))); + EXPECT_TRUE(GetKeyIdsForCommonSystemId( + std::vector<uint8_t>(data, data + arraysize(data)), &key_ids)); EXPECT_EQ(2u, key_ids.size()); } TEST_F(CencUtilsTest, HugeSize) { - const uint8 data[] = { + const uint8_t data[] = { 0x00, 0x00, 0x00, 0x01, // size = 1 0x70, 0x73, 0x73, 0x68, // 'pssh' 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, // longsize = big @@ -358,9 +366,11 @@ TEST_F(CencUtilsTest, HugeSize) { 0x00, 0x00, 0x00, 0x00 // datasize }; - std::vector<std::vector<uint8>> key_ids; - EXPECT_FALSE(ValidatePsshInput(data, arraysize(data))); - EXPECT_FALSE(GetKeyIdsForCommonSystemId(data, arraysize(data), &key_ids)); + KeyIdList key_ids; + EXPECT_FALSE( + ValidatePsshInput(std::vector<uint8_t>(data, data + arraysize(data)))); + EXPECT_FALSE(GetKeyIdsForCommonSystemId( + std::vector<uint8_t>(data, data + arraysize(data)), &key_ids)); } } // namespace media diff --git a/media/cdm/ppapi/external_clear_key/clear_key_cdm.cc b/media/cdm/ppapi/external_clear_key/clear_key_cdm.cc index 725ee88..39199de 100644 --- a/media/cdm/ppapi/external_clear_key/clear_key_cdm.cc +++ b/media/cdm/ppapi/external_clear_key/clear_key_cdm.cc @@ -322,7 +322,8 @@ void ClearKeyCdm::CreateSessionAndGenerateRequest( promise_id))); decryptor_.CreateSessionAndGenerateRequest( ConvertSessionType(session_type), ConvertInitDataType(init_data_type), - init_data, init_data_size, promise.Pass()); + std::vector<uint8_t>(init_data, init_data + init_data_size), + promise.Pass()); if (key_system_ == kExternalClearKeyFileIOTestKeySystem) StartFileIOTest(); @@ -361,9 +362,9 @@ void ClearKeyCdm::LoadSession(uint32 promise_id, base::Bind(&ClearKeyCdm::OnPromiseFailed, base::Unretained(this), promise_id))); - decryptor_.CreateSessionAndGenerateRequest(MediaKeys::TEMPORARY_SESSION, - EmeInitDataType::WEBM, NULL, 0, - promise.Pass()); + decryptor_.CreateSessionAndGenerateRequest( + MediaKeys::TEMPORARY_SESSION, EmeInitDataType::WEBM, + std::vector<uint8_t>(), promise.Pass()); } void ClearKeyCdm::UpdateSession(uint32 promise_id, @@ -384,7 +385,8 @@ void ClearKeyCdm::UpdateSession(uint32 promise_id, base::Bind(&ClearKeyCdm::OnPromiseFailed, base::Unretained(this), promise_id))); decryptor_.UpdateSession( - web_session_str, response, response_size, promise.Pass()); + web_session_str, std::vector<uint8_t>(response, response + response_size), + promise.Pass()); if (!renewal_timer_set_) { ScheduleNextRenewal(); @@ -721,8 +723,7 @@ void ClearKeyCdm::LoadLoadableSession() { base::Bind(&ClearKeyCdm::OnPromiseFailed, base::Unretained(this), promise_id_for_emulated_loadsession_))); decryptor_.UpdateSession(session_id_for_emulated_loadsession_, - reinterpret_cast<const uint8*>(jwk_set.data()), - jwk_set.size(), + std::vector<uint8_t>(jwk_set.begin(), jwk_set.end()), promise.Pass()); } diff --git a/media/cdm/proxy_decryptor.cc b/media/cdm/proxy_decryptor.cc index 9260e14..c30cb83 100644 --- a/media/cdm/proxy_decryptor.cc +++ b/media/cdm/proxy_decryptor.cc @@ -9,6 +9,7 @@ #include "base/bind.h" #include "base/callback_helpers.h" #include "base/logging.h" +#include "base/stl_util.h" #include "base/strings/string_util.h" #include "media/base/cdm_callback_promise.h" #include "media/base/cdm_factory.h" @@ -216,9 +217,8 @@ void ProxyDecryptor::OnPermissionStatus( // on Android) and the permission status will be evaluated then. DVLOG_IF(1, !granted) << "Permission request rejected."; - media_keys_->CreateSessionAndGenerateRequest( - session_type, init_data_type, vector_as_array(&init_data), - init_data.size(), promise.Pass()); + media_keys_->CreateSessionAndGenerateRequest(session_type, init_data_type, + init_data, promise.Pass()); } void ProxyDecryptor::AddKey(const uint8* key, @@ -271,12 +271,14 @@ void ProxyDecryptor::AddKey(const uint8* key, GenerateJWKSet(key, key_length, init_data, init_data_length); DCHECK(!jwk.empty()); media_keys_->UpdateSession(new_session_id, - reinterpret_cast<const uint8*>(jwk.data()), - jwk.size(), promise.Pass()); + std::vector<uint8_t>(jwk.begin(), jwk.end()), + promise.Pass()); return; } - media_keys_->UpdateSession(new_session_id, key, key_length, promise.Pass()); + media_keys_->UpdateSession(new_session_id, + std::vector<uint8_t>(key, key + key_length), + promise.Pass()); } void ProxyDecryptor::CancelKeyRequest(const std::string& session_id) { diff --git a/media/mojo/services/mojo_cdm.cc b/media/mojo/services/mojo_cdm.cc index df82ec9..17a1a48 100644 --- a/media/mojo/services/mojo_cdm.cc +++ b/media/mojo/services/mojo_cdm.cc @@ -16,15 +16,6 @@ namespace media { -static mojo::Array<uint8_t> CreateMojoArray(const uint8_t* data, int length) { - DCHECK(data); - DCHECK_GT(length, 0); - std::vector<uint8_t> vector(data, data + length); - mojo::Array<uint8_t> array; - array.Swap(&vector); - return array.Pass(); -} - template <typename PromiseType> static void RejectPromise(scoped_ptr<PromiseType> promise, mojo::CdmPromiseResultPtr result) { @@ -62,11 +53,10 @@ MojoCdm::~MojoCdm() { DVLOG(1) << __FUNCTION__; } -void MojoCdm::SetServerCertificate(const uint8_t* certificate_data, - int certificate_data_length, +void MojoCdm::SetServerCertificate(const std::vector<uint8_t>& certificate, scoped_ptr<SimpleCdmPromise> promise) { remote_cdm_->SetServerCertificate( - CreateMojoArray(certificate_data, certificate_data_length), + mojo::Array<uint8_t>::From(certificate), base::Bind(&MojoCdm::OnPromiseResult<>, weak_factory_.GetWeakPtr(), base::Passed(&promise))); } @@ -74,13 +64,12 @@ void MojoCdm::SetServerCertificate(const uint8_t* certificate_data, void MojoCdm::CreateSessionAndGenerateRequest( SessionType session_type, EmeInitDataType init_data_type, - const uint8_t* init_data, - int init_data_length, + const std::vector<uint8_t>& init_data, scoped_ptr<NewSessionCdmPromise> promise) { remote_cdm_->CreateSessionAndGenerateRequest( static_cast<mojo::ContentDecryptionModule::SessionType>(session_type), static_cast<mojo::ContentDecryptionModule::InitDataType>(init_data_type), - CreateMojoArray(init_data, init_data_length), + mojo::Array<uint8_t>::From(init_data), base::Bind(&MojoCdm::OnPromiseResult<std::string>, weak_factory_.GetWeakPtr(), base::Passed(&promise))); } @@ -96,11 +85,10 @@ void MojoCdm::LoadSession(SessionType session_type, } void MojoCdm::UpdateSession(const std::string& session_id, - const uint8_t* response, - int response_length, + const std::vector<uint8_t>& response, scoped_ptr<SimpleCdmPromise> promise) { remote_cdm_->UpdateSession( - session_id, CreateMojoArray(response, response_length), + session_id, mojo::Array<uint8_t>::From(response), base::Bind(&MojoCdm::OnPromiseResult<>, weak_factory_.GetWeakPtr(), base::Passed(&promise))); } diff --git a/media/mojo/services/mojo_cdm.h b/media/mojo/services/mojo_cdm.h index 4c29577..68667da 100644 --- a/media/mojo/services/mojo_cdm.h +++ b/media/mojo/services/mojo_cdm.h @@ -5,6 +5,8 @@ #ifndef MEDIA_MOJO_SERVICES_MOJO_CDM_H_ #define MEDIA_MOJO_SERVICES_MOJO_CDM_H_ +#include <vector> + #include "base/macros.h" #include "base/memory/weak_ptr.h" #include "media/base/media_keys.h" @@ -33,21 +35,18 @@ class MojoCdm : public MediaKeys, public mojo::ContentDecryptionModuleClient { ~MojoCdm() final; // MediaKeys implementation. - void SetServerCertificate(const uint8_t* certificate_data, - int certificate_data_length, + void SetServerCertificate(const std::vector<uint8_t>& certificate, scoped_ptr<SimpleCdmPromise> promise) final; void CreateSessionAndGenerateRequest( SessionType session_type, EmeInitDataType init_data_type, - const uint8_t* init_data, - int init_data_length, + const std::vector<uint8_t>& init_data, scoped_ptr<NewSessionCdmPromise> promise) final; void LoadSession(SessionType session_type, const std::string& session_id, scoped_ptr<NewSessionCdmPromise> promise) final; void UpdateSession(const std::string& session_id, - const uint8_t* response, - int response_length, + const std::vector<uint8_t>& response, scoped_ptr<SimpleCdmPromise> promise) final; void CloseSession(const std::string& session_id, scoped_ptr<SimpleCdmPromise> promise) final; diff --git a/media/mojo/services/mojo_cdm_service.cc b/media/mojo/services/mojo_cdm_service.cc index 58c335d..b92d9f8 100644 --- a/media/mojo/services/mojo_cdm_service.cc +++ b/media/mojo/services/mojo_cdm_service.cc @@ -47,11 +47,8 @@ void MojoCdmService::SetClient(mojo::ContentDecryptionModuleClientPtr client) { void MojoCdmService::SetServerCertificate( mojo::Array<uint8_t> certificate_data, const mojo::Callback<void(mojo::CdmPromiseResultPtr)>& callback) { - const std::vector<uint8_t>& certificate_data_vector = - certificate_data.storage(); cdm_->SetServerCertificate( - certificate_data_vector.empty() ? nullptr : &certificate_data_vector[0], - certificate_data_vector.size(), + certificate_data.storage(), scoped_ptr<SimpleCdmPromise>(new SimpleMojoCdmPromise(callback))); } @@ -61,12 +58,9 @@ void MojoCdmService::CreateSessionAndGenerateRequest( mojo::Array<uint8_t> init_data, const mojo::Callback<void(mojo::CdmPromiseResultPtr, mojo::String)>& callback) { - const std::vector<uint8_t>& init_data_vector = init_data.storage(); cdm_->CreateSessionAndGenerateRequest( static_cast<MediaKeys::SessionType>(session_type), - static_cast<EmeInitDataType>(init_data_type), - init_data_vector.empty() ? nullptr : &init_data_vector[0], - init_data_vector.size(), + static_cast<EmeInitDataType>(init_data_type), init_data.storage(), scoped_ptr<NewSessionCdmPromise>(new NewSessionMojoCdmPromise(callback))); } @@ -85,11 +79,8 @@ void MojoCdmService::UpdateSession( const mojo::String& session_id, mojo::Array<uint8_t> response, const mojo::Callback<void(mojo::CdmPromiseResultPtr)>& callback) { - const std::vector<uint8_t>& response_vector = response.storage(); cdm_->UpdateSession( - session_id.To<std::string>(), - response_vector.empty() ? nullptr : &response_vector[0], - response_vector.size(), + session_id.To<std::string>(), response.storage(), scoped_ptr<SimpleCdmPromise>(new SimpleMojoCdmPromise(callback))); } diff --git a/media/test/pipeline_integration_test.cc b/media/test/pipeline_integration_test.cc index 54d355c..dd214eb 100644 --- a/media/test/pipeline_integration_test.cc +++ b/media/test/pipeline_integration_test.cc @@ -5,6 +5,7 @@ #include "base/bind.h" #include "base/command_line.h" #include "base/memory/scoped_ptr.h" +#include "base/stl_util.h" #include "base/strings/string_util.h" #include "build/build_config.h" #include "media/base/cdm_callback_promise.h" @@ -317,12 +318,12 @@ class KeyProvidingApp : public FakeEncryptedMedia::AppBase { // key ID as the init_data. // http://crbug.com/460308 decryptor->CreateSessionAndGenerateRequest( - MediaKeys::TEMPORARY_SESSION, EmeInitDataType::WEBM, kKeyId, - arraysize(kKeyId), CreateSessionPromise(RESOLVED)); + MediaKeys::TEMPORARY_SESSION, EmeInitDataType::WEBM, + std::vector<uint8>(kKeyId, kKeyId + arraysize(kKeyId)), + CreateSessionPromise(RESOLVED)); } else { decryptor->CreateSessionAndGenerateRequest( - MediaKeys::TEMPORARY_SESSION, init_data_type, - vector_as_array(&init_data), init_data.size(), + MediaKeys::TEMPORARY_SESSION, init_data_type, init_data, CreateSessionPromise(RESOLVED)); } EXPECT_FALSE(current_session_id_.empty()); @@ -342,8 +343,7 @@ class KeyProvidingApp : public FakeEncryptedMedia::AppBase { std::string jwk = GenerateJWKSet( kSecretKey, arraysize(kSecretKey), key_id, key_id_length); decryptor->UpdateSession(current_session_id_, - reinterpret_cast<const uint8*>(jwk.data()), - jwk.size(), + std::vector<uint8>(jwk.begin(), jwk.end()), CreatePromise(RESOLVED)); } @@ -379,13 +379,11 @@ class RotatingKeyProvidingApp : public KeyProvidingApp { // key ID as the init_data. // http://crbug.com/460308 decryptor->CreateSessionAndGenerateRequest( - MediaKeys::TEMPORARY_SESSION, EmeInitDataType::WEBM, - vector_as_array(&key_id), key_id.size(), + MediaKeys::TEMPORARY_SESSION, EmeInitDataType::WEBM, key_id, CreateSessionPromise(RESOLVED)); } else { decryptor->CreateSessionAndGenerateRequest( - MediaKeys::TEMPORARY_SESSION, init_data_type, - vector_as_array(&init_data), init_data.size(), + MediaKeys::TEMPORARY_SESSION, init_data_type, init_data, CreateSessionPromise(RESOLVED)); } @@ -395,8 +393,7 @@ class RotatingKeyProvidingApp : public KeyProvidingApp { vector_as_array(&key_id), key_id.size()); decryptor->UpdateSession(current_session_id_, - reinterpret_cast<const uint8*>(jwk.data()), - jwk.size(), + std::vector<uint8>(jwk.begin(), jwk.end()), CreatePromise(RESOLVED)); } |