diff options
author | jrummell <jrummell@chromium.org> | 2015-04-24 10:15:45 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-04-24 17:15:51 +0000 |
commit | f52b16ac4740888ce847620da41357824286a719 (patch) | |
tree | ee6d9cb1cc6a0d6f4dc0cffbb0e0004bcda1b54e | |
parent | 04ffcf25e708f3835ad4a48af044b2fb10aa6c27 (diff) | |
download | chromium_src-f52b16ac4740888ce847620da41357824286a719.zip chromium_src-f52b16ac4740888ce847620da41357824286a719.tar.gz chromium_src-f52b16ac4740888ce847620da41357824286a719.tar.bz2 |
Use std::vector<uint8_t> instead of uint8*/int for MediaKeys interface
BUG=433446
TEST=media_unittests and EME layout tests pass
Review URL: https://codereview.chromium.org/1072403009
Cr-Commit-Position: refs/heads/master@{#326824}
28 files changed, 338 insertions, 441 deletions
diff --git a/chromecast/media/cdm/browser_cdm_cast.cc b/chromecast/media/cdm/browser_cdm_cast.cc index 33c10c5..07c3c3e 100644 --- a/chromecast/media/cdm/browser_cdm_cast.cc +++ b/chromecast/media/cdm/browser_cdm_cast.cc @@ -68,7 +68,7 @@ void BrowserCdmCast::LoadSession( } void BrowserCdmCast::OnSessionMessage(const std::string& session_id, - const std::vector<uint8>& message, + const std::vector<uint8_t>& message, const GURL& destination_url) { // Note: Message type is not supported in Chromecast. Do our best guess here. ::media::MediaKeys::MessageType message_type = @@ -99,31 +99,6 @@ void BrowserCdmCast::OnSessionKeysChange( player_tracker_impl_->NotifyNewKey(); } -void BrowserCdmCast::SetServerCertificateHelper( - const std::vector<uint8>& certificate_data, - scoped_ptr<::media::SimpleCdmPromise> promise) { - SetServerCertificate(certificate_data.data(), - certificate_data.size(), - promise.Pass()); -} - -void BrowserCdmCast::CreateSessionAndGenerateRequestHelper( - ::media::MediaKeys::SessionType session_type, - ::media::EmeInitDataType init_data_type, - const std::vector<uint8>& init_data, - scoped_ptr<::media::NewSessionCdmPromise> promise) { - CreateSessionAndGenerateRequest( - session_type, init_data_type, init_data.data(), init_data.size(), - promise.Pass()); -} - -void BrowserCdmCast::UpdateSessionHelper( - const std::string& session_id, - const std::vector<uint8>& response, - scoped_ptr<::media::SimpleCdmPromise> promise) { - UpdateSession(session_id, response.data(), response.size(), promise.Pass()); -} - // A macro runs current member function on |cdm_loop_| thread. #define FORWARD_ON_CDM_THREAD(param_fn, ...) \ cdm_loop_->PostTask( \ @@ -160,29 +135,26 @@ BrowserCdmCast* BrowserCdmCastUi::browser_cdm_cast() const { } void BrowserCdmCastUi::SetServerCertificate( - const uint8* certificate_data, - int certificate_data_length, + const std::vector<uint8_t>& certificate, scoped_ptr<::media::SimpleCdmPromise> promise) { DCHECK(thread_checker_.CalledOnValidThread()); FORWARD_ON_CDM_THREAD( - SetServerCertificateHelper, - std::vector<uint8>(certificate_data, - certificate_data + certificate_data_length), + SetServerCertificate, + certificate, base::Passed(&promise)); } void BrowserCdmCastUi::CreateSessionAndGenerateRequest( ::media::MediaKeys::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) { DCHECK(thread_checker_.CalledOnValidThread()); FORWARD_ON_CDM_THREAD( - CreateSessionAndGenerateRequestHelper, + CreateSessionAndGenerateRequest, session_type, init_data_type, - std::vector<uint8>(init_data, init_data + init_data_length), + init_data, base::Passed(&promise)); } @@ -197,14 +169,13 @@ void BrowserCdmCastUi::LoadSession( void BrowserCdmCastUi::UpdateSession( const std::string& session_id, - const uint8* response, - int response_length, + const std::vector<uint8_t>& response, scoped_ptr<::media::SimpleCdmPromise> promise) { DCHECK(thread_checker_.CalledOnValidThread()); FORWARD_ON_CDM_THREAD( - UpdateSessionHelper, + UpdateSession, session_id, - std::vector<uint8>(response, response + response_length), + response, base::Passed(&promise)); } diff --git a/chromecast/media/cdm/browser_cdm_cast.h b/chromecast/media/cdm/browser_cdm_cast.h index 28fb984..1f2d8e7 100644 --- a/chromecast/media/cdm/browser_cdm_cast.h +++ b/chromecast/media/cdm/browser_cdm_cast.h @@ -9,6 +9,7 @@ #include <map> #include <string> +#include <vector> #include "base/callback.h" #include "base/macros.h" @@ -67,7 +68,7 @@ class BrowserCdmCast : public ::media::BrowserCdm { protected: void OnSessionMessage(const std::string& session_id, - const std::vector<uint8>& message, + const std::vector<uint8_t>& message, const GURL& destination_url); void OnSessionClosed(const std::string& session_id); void OnSessionKeysChange(const std::string& session_id, @@ -76,19 +77,6 @@ class BrowserCdmCast : public ::media::BrowserCdm { private: friend class BrowserCdmCastUi; - // Helper methods for forwarding calls to methods that take raw pointers. - void SetServerCertificateHelper( - const std::vector<uint8>& certificate_data, - scoped_ptr<::media::SimpleCdmPromise> promise); - void CreateSessionAndGenerateRequestHelper( - ::media::MediaKeys::SessionType session_type, - ::media::EmeInitDataType init_data_type, - const std::vector<uint8>& init_data, - scoped_ptr<::media::NewSessionCdmPromise> promise); - void UpdateSessionHelper(const std::string& session_id, - const std::vector<uint8>& response, - scoped_ptr<::media::SimpleCdmPromise> promise); - ::media::SessionMessageCB session_message_cb_; ::media::SessionClosedCB session_closed_cb_; ::media::LegacySessionErrorCB legacy_session_error_cb_; @@ -122,21 +110,18 @@ class BrowserCdmCastUi : public ::media::BrowserCdm { private: // ::media::MediaKeys 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( ::media::MediaKeys::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(::media::MediaKeys::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/content/browser/media/cdm/browser_cdm_manager.cc b/content/browser/media/cdm/browser_cdm_manager.cc index 88cf526..8f1e78a 100644 --- a/content/browser/media/cdm/browser_cdm_manager.cc +++ b/content/browser/media/cdm/browser_cdm_manager.cc @@ -324,8 +324,7 @@ void BrowserCdmManager::OnSetServerCertificate( return; } - cdm->SetServerCertificate(&certificate[0], certificate.size(), - promise.Pass()); + cdm->SetServerCertificate(certificate, promise.Pass()); } void BrowserCdmManager::OnCreateSessionAndGenerateRequest( @@ -405,7 +404,7 @@ void BrowserCdmManager::OnUpdateSession(int render_frame_id, return; } - cdm->UpdateSession(session_id, &response[0], response.size(), promise.Pass()); + cdm->UpdateSession(session_id, response, promise.Pass()); } void BrowserCdmManager::OnCloseSession(int render_frame_id, @@ -577,8 +576,8 @@ void BrowserCdmManager::CreateSessionAndGenerateRequestIfPermitted( // Only the temporary session type is supported in browser CDM path. // TODO(xhwang): Add SessionType support if needed. cdm->CreateSessionAndGenerateRequest(media::MediaKeys::TEMPORARY_SESSION, - init_data_type, &init_data[0], - init_data.size(), promise.Pass()); + init_data_type, init_data, + promise.Pass()); } } // namespace content diff --git a/content/renderer/media/crypto/ppapi_decryptor.cc b/content/renderer/media/crypto/ppapi_decryptor.cc index a70249a..d50e911 100644 --- a/content/renderer/media/crypto/ppapi_decryptor.cc +++ b/content/renderer/media/crypto/ppapi_decryptor.cc @@ -90,8 +90,7 @@ PpapiDecryptor::~PpapiDecryptor() { } void PpapiDecryptor::SetServerCertificate( - const uint8* certificate_data, - int certificate_data_length, + const std::vector<uint8_t>& certificate, scoped_ptr<media::SimpleCdmPromise> promise) { DVLOG(2) << __FUNCTION__; DCHECK(render_loop_proxy_->BelongsToCurrentThread()); @@ -101,15 +100,13 @@ void PpapiDecryptor::SetServerCertificate( return; } - CdmDelegate()->SetServerCertificate( - certificate_data, certificate_data_length, promise.Pass()); + CdmDelegate()->SetServerCertificate(certificate, promise.Pass()); } void PpapiDecryptor::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(2) << __FUNCTION__; DCHECK(render_loop_proxy_->BelongsToCurrentThread()); @@ -120,8 +117,7 @@ void PpapiDecryptor::CreateSessionAndGenerateRequest( } CdmDelegate()->CreateSessionAndGenerateRequest(session_type, init_data_type, - init_data, init_data_length, - promise.Pass()); + init_data, promise.Pass()); } void PpapiDecryptor::LoadSession( @@ -140,8 +136,7 @@ void PpapiDecryptor::LoadSession( void PpapiDecryptor::UpdateSession( const std::string& session_id, - const uint8* response, - int response_length, + const std::vector<uint8_t>& response, scoped_ptr<media::SimpleCdmPromise> promise) { DCHECK(render_loop_proxy_->BelongsToCurrentThread()); @@ -149,8 +144,7 @@ void PpapiDecryptor::UpdateSession( promise->reject(INVALID_STATE_ERROR, 0, "CdmDelegate() does not exist."); return; } - CdmDelegate()->UpdateSession(session_id, response, response_length, - promise.Pass()); + CdmDelegate()->UpdateSession(session_id, response, promise.Pass()); } void PpapiDecryptor::CloseSession(const std::string& session_id, @@ -393,7 +387,7 @@ void PpapiDecryptor::OnDecoderInitialized(StreamType stream_type, void PpapiDecryptor::OnSessionMessage(const std::string& session_id, MessageType message_type, - const std::vector<uint8>& message, + const std::vector<uint8_t>& message, const GURL& legacy_destination_url) { DCHECK(render_loop_proxy_->BelongsToCurrentThread()); session_message_cb_.Run(session_id, message_type, message, @@ -429,7 +423,7 @@ void PpapiDecryptor::OnSessionClosed(const std::string& session_id) { void PpapiDecryptor::OnLegacySessionError( const std::string& session_id, MediaKeys::Exception exception_code, - uint32 system_code, + uint32_t system_code, const std::string& error_description) { DCHECK(render_loop_proxy_->BelongsToCurrentThread()); legacy_session_error_cb_.Run(session_id, exception_code, system_code, diff --git a/content/renderer/media/crypto/ppapi_decryptor.h b/content/renderer/media/crypto/ppapi_decryptor.h index ed4523f..374b5c1 100644 --- a/content/renderer/media/crypto/ppapi_decryptor.h +++ b/content/renderer/media/crypto/ppapi_decryptor.h @@ -50,21 +50,18 @@ class PpapiDecryptor : public media::MediaKeys, // media::MediaKeys 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; @@ -113,7 +110,7 @@ class PpapiDecryptor : public media::MediaKeys, // Callbacks for |plugin_cdm_delegate_| to fire 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, @@ -123,7 +120,7 @@ class PpapiDecryptor : public media::MediaKeys, 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_description); void AttemptToResumePlayback(); diff --git a/content/renderer/media/crypto/proxy_media_keys.cc b/content/renderer/media/crypto/proxy_media_keys.cc index 9dd2de67..9f121fe 100644 --- a/content/renderer/media/crypto/proxy_media_keys.cc +++ b/content/renderer/media/crypto/proxy_media_keys.cc @@ -40,21 +40,16 @@ ProxyMediaKeys::~ProxyMediaKeys() { } void ProxyMediaKeys::SetServerCertificate( - const uint8* certificate_data, - int certificate_data_length, + const std::vector<uint8_t>& certificate, scoped_ptr<media::SimpleCdmPromise> promise) { uint32_t promise_id = cdm_promise_adapter_.SavePromise(promise.Pass()); - manager_->SetServerCertificate( - cdm_id_, promise_id, - std::vector<uint8>(certificate_data, - certificate_data + certificate_data_length)); + manager_->SetServerCertificate(cdm_id_, promise_id, certificate); } void ProxyMediaKeys::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) { if (session_type != media::MediaKeys::TEMPORARY_SESSION) { promise->reject(NOT_SUPPORTED_ERROR, 0, @@ -83,8 +78,7 @@ void ProxyMediaKeys::CreateSessionAndGenerateRequest( uint32_t promise_id = cdm_promise_adapter_.SavePromise(promise.Pass()); manager_->CreateSessionAndGenerateRequest( - cdm_id_, promise_id, create_session_init_data_type, - std::vector<uint8>(init_data, init_data + init_data_length)); + cdm_id_, promise_id, create_session_init_data_type, init_data); } void ProxyMediaKeys::LoadSession( @@ -99,13 +93,10 @@ void ProxyMediaKeys::LoadSession( void ProxyMediaKeys::UpdateSession( const std::string& session_id, - const uint8* response, - int response_length, + const std::vector<uint8_t>& response, scoped_ptr<media::SimpleCdmPromise> promise) { uint32_t promise_id = cdm_promise_adapter_.SavePromise(promise.Pass()); - manager_->UpdateSession( - cdm_id_, promise_id, session_id, - std::vector<uint8>(response, response + response_length)); + manager_->UpdateSession(cdm_id_, promise_id, session_id, response); } void ProxyMediaKeys::CloseSession(const std::string& session_id, @@ -137,7 +128,7 @@ int ProxyMediaKeys::GetCdmId() const { void ProxyMediaKeys::OnSessionMessage( const std::string& session_id, media::MediaKeys::MessageType message_type, - const std::vector<uint8>& message, + const std::vector<uint8_t>& message, const GURL& legacy_destination_url) { session_message_cb_.Run(session_id, message_type, message, legacy_destination_url); @@ -149,7 +140,7 @@ void ProxyMediaKeys::OnSessionClosed(const std::string& session_id) { void ProxyMediaKeys::OnLegacySessionError(const std::string& session_id, media::MediaKeys::Exception exception, - uint32 system_code, + uint32_t system_code, const std::string& error_message) { legacy_session_error_cb_.Run(session_id, exception, system_code, error_message); diff --git a/content/renderer/media/crypto/proxy_media_keys.h b/content/renderer/media/crypto/proxy_media_keys.h index e13fc3d..979de0a 100644 --- a/content/renderer/media/crypto/proxy_media_keys.h +++ b/content/renderer/media/crypto/proxy_media_keys.h @@ -7,6 +7,7 @@ #include <map> #include <string> +#include <vector> #include "base/basictypes.h" #include "base/containers/hash_tables.h" @@ -39,21 +40,18 @@ class ProxyMediaKeys : public media::MediaKeys, public media::CdmContext { // MediaKeys 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; @@ -68,12 +66,12 @@ class ProxyMediaKeys : public media::MediaKeys, public media::CdmContext { // Callbacks. void OnSessionMessage(const std::string& session_id, media::MediaKeys::MessageType message_type, - const std::vector<uint8>& message, + const std::vector<uint8_t>& message, const GURL& legacy_destination_url); void OnSessionClosed(const std::string& session_id); void OnLegacySessionError(const std::string& session_id, media::MediaKeys::Exception exception, - uint32 system_code, + uint32_t system_code, const std::string& error_message); void OnSessionKeysChange(const std::string& session_id, bool has_additional_usable_key, diff --git a/content/renderer/pepper/content_decryptor_delegate.cc b/content/renderer/pepper/content_decryptor_delegate.cc index e8dc612..0cf812d 100644 --- a/content/renderer/pepper/content_decryptor_delegate.cc +++ b/content/renderer/pepper/content_decryptor_delegate.cc @@ -8,6 +8,7 @@ #include "base/message_loop/message_loop_proxy.h" #include "base/metrics/sparse_histogram.h" #include "base/numerics/safe_conversions.h" +#include "base/stl_util.h" #include "base/trace_event/trace_event.h" #include "content/renderer/pepper/ppb_buffer_impl.h" #include "media/base/audio_buffer.h" @@ -53,7 +54,7 @@ namespace { // reference-count of 0. If |data| is NULL, sets |*resource| to NULL. Returns // true upon success and false if any error happened. bool MakeBufferResource(PP_Instance instance, - const uint8* data, + const uint8_t* data, uint32_t size, scoped_refptr<PPB_Buffer_Impl>* resource) { TRACE_EVENT0("media", "ContentDecryptorDelegate - MakeBufferResource"); @@ -83,7 +84,7 @@ bool MakeBufferResource(PP_Instance instance, // Returns true if copy succeeded. Returns false if copy failed, e.g. if the // |array_size| is smaller than the |str| length. template <uint32_t array_size> -bool CopyStringToArray(const std::string& str, uint8 (&array)[array_size]) { +bool CopyStringToArray(const std::string& str, uint8_t(&array)[array_size]) { if (array_size < str.size()) return false; @@ -345,7 +346,7 @@ MediaKeys::MessageType PpCdmMessageTypeToMediaMessageType( // TODO(xhwang): Unify EME UMA reporting code when prefixed EME is deprecated. // See http://crbug.com/412987 for details. -void ReportSystemCodeUMA(const std::string& key_system, uint32 system_code) { +void ReportSystemCodeUMA(const std::string& key_system, uint32_t system_code) { // Sparse histogram macro does not cache the histogram, so it's safe to use // macro with non-static histogram name here. UMA_HISTOGRAM_SPARSE_SLOWLY( @@ -405,12 +406,10 @@ void ContentDecryptorDelegate::InstanceCrashed() { } void ContentDecryptorDelegate::SetServerCertificate( - const uint8_t* certificate, - uint32_t certificate_length, + const std::vector<uint8_t>& certificate, scoped_ptr<media::SimpleCdmPromise> promise) { - if (!certificate || - certificate_length < media::limits::kMinCertificateLength || - certificate_length > media::limits::kMaxCertificateLength) { + if (certificate.size() < media::limits::kMinCertificateLength || + certificate.size() > media::limits::kMaxCertificateLength) { promise->reject( media::MediaKeys::INVALID_ACCESS_ERROR, 0, "Incorrect certificate."); return; @@ -419,7 +418,8 @@ void ContentDecryptorDelegate::SetServerCertificate( uint32_t promise_id = cdm_promise_adapter_.SavePromise(promise.Pass()); PP_Var certificate_array = PpapiGlobals::Get()->GetVarTracker()->MakeArrayBufferPPVar( - certificate_length, certificate); + base::checked_cast<uint32>(certificate.size()), + vector_as_array(&certificate)); plugin_decryption_interface_->SetServerCertificate( pp_instance_, promise_id, certificate_array); } @@ -427,13 +427,13 @@ void ContentDecryptorDelegate::SetServerCertificate( void ContentDecryptorDelegate::CreateSessionAndGenerateRequest( MediaKeys::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<NewSessionCdmPromise> promise) { uint32_t promise_id = cdm_promise_adapter_.SavePromise(promise.Pass()); PP_Var init_data_array = PpapiGlobals::Get()->GetVarTracker()->MakeArrayBufferPPVar( - init_data_length, init_data); + base::checked_cast<uint32>(init_data.size()), + vector_as_array(&init_data)); plugin_decryption_interface_->CreateSessionAndGenerateRequest( pp_instance_, promise_id, MediaSessionTypeToPpSessionType(session_type), MediaInitDataTypeToPpInitDataType(init_data_type), init_data_array); @@ -451,13 +451,13 @@ void ContentDecryptorDelegate::LoadSession( void ContentDecryptorDelegate::UpdateSession( const std::string& session_id, - const uint8* response, - int response_length, + const std::vector<uint8_t>& response, scoped_ptr<SimpleCdmPromise> promise) { uint32_t promise_id = cdm_promise_adapter_.SavePromise(promise.Pass()); PP_Var response_array = PpapiGlobals::Get()->GetVarTracker()->MakeArrayBufferPPVar( - response_length, response); + base::checked_cast<uint32>(response.size()), + vector_as_array(&response)); plugin_decryption_interface_->UpdateSession( pp_instance_, promise_id, StringVar::StringToPPVar(session_id), response_array); @@ -734,11 +734,11 @@ bool ContentDecryptorDelegate::DecryptAndDecodeVideo( return true; } -void ContentDecryptorDelegate::OnPromiseResolved(uint32 promise_id) { +void ContentDecryptorDelegate::OnPromiseResolved(uint32_t promise_id) { cdm_promise_adapter_.ResolvePromise(promise_id); } -void ContentDecryptorDelegate::OnPromiseResolvedWithSession(uint32 promise_id, +void ContentDecryptorDelegate::OnPromiseResolvedWithSession(uint32_t promise_id, PP_Var session_id) { StringVar* session_id_string = StringVar::FromPPVar(session_id); DCHECK(session_id_string); @@ -746,9 +746,9 @@ void ContentDecryptorDelegate::OnPromiseResolvedWithSession(uint32 promise_id, } void ContentDecryptorDelegate::OnPromiseRejected( - uint32 promise_id, + uint32_t promise_id, PP_CdmExceptionCode exception_code, - uint32 system_code, + uint32_t system_code, PP_Var error_description) { ReportSystemCodeUMA(key_system_, system_code); @@ -770,9 +770,10 @@ void ContentDecryptorDelegate::OnSessionMessage(PP_Var session_id, DCHECK(session_id_string); ArrayBufferVar* message_array_buffer = ArrayBufferVar::FromPPVar(message); - std::vector<uint8> message_vector; + std::vector<uint8_t> message_vector; if (message_array_buffer) { - const uint8* data = static_cast<const uint8*>(message_array_buffer->Map()); + const uint8_t* data = + static_cast<const uint8_t*>(message_array_buffer->Map()); message_vector.assign(data, data + message_array_buffer->ByteLength()); } @@ -849,7 +850,7 @@ void ContentDecryptorDelegate::OnSessionClosed(PP_Var session_id) { void ContentDecryptorDelegate::OnLegacySessionError( PP_Var session_id, PP_CdmExceptionCode exception_code, - uint32 system_code, + uint32_t system_code, PP_Var error_description) { ReportSystemCodeUMA(key_system_, system_code); @@ -949,7 +950,7 @@ void ContentDecryptorDelegate::DeliverBlock( // TODO(tomfinegan): Find a way to take ownership of the shared memory // managed by the PPB_Buffer_Dev, and avoid the extra copy. scoped_refptr<media::DecoderBuffer> decrypted_buffer( - media::DecoderBuffer::CopyFrom(static_cast<uint8*>(mapper.data()), + media::DecoderBuffer::CopyFrom(static_cast<uint8_t*>(mapper.data()), block_info->data_size)); decrypted_buffer->set_timestamp( base::TimeDelta::FromMicroseconds(block_info->tracking_info.timestamp)); @@ -968,13 +969,13 @@ static void BufferNoLongerNeeded( // Enters |resource|, maps shared memory and returns pointer of mapped data. // Returns NULL if any error occurs. -static uint8* GetMappedBuffer(PP_Resource resource, - scoped_refptr<PPB_Buffer_Impl>* ppb_buffer) { +static uint8_t* GetMappedBuffer(PP_Resource resource, + scoped_refptr<PPB_Buffer_Impl>* ppb_buffer) { EnterResourceNoLock<PPB_Buffer_API> enter(resource, true); if (!enter.succeeded()) return NULL; - uint8* mapped_data = static_cast<uint8*>(enter.object()->Map()); + uint8_t* mapped_data = static_cast<uint8_t*>(enter.object()->Map()); if (!enter.object()->IsMapped() || !mapped_data) return NULL; @@ -1018,7 +1019,7 @@ void ContentDecryptorDelegate::DeliverFrame( } scoped_refptr<PPB_Buffer_Impl> ppb_buffer; - uint8* frame_data = GetMappedBuffer(decrypted_frame, &ppb_buffer); + uint8_t* frame_data = GetMappedBuffer(decrypted_frame, &ppb_buffer); if (!frame_data) { FreeBuffer(frame_info->tracking_info.buffer_id); video_decode_cb.Run(Decryptor::kError, NULL); @@ -1208,7 +1209,7 @@ bool ContentDecryptorDelegate::DeserializeAudioFrames( // TODO(jrummell): Pass ownership of data() directly to AudioBuffer to avoid // the copy. Since it is possible to get multiple buffers, it would need to be // sliced and ref counted appropriately. http://crbug.com/255576. - const uint8* cur = static_cast<uint8*>(mapper.data()); + const uint8_t* cur = static_cast<uint8_t*>(mapper.data()); size_t bytes_left = data_size; const int audio_bytes_per_frame = @@ -1218,8 +1219,7 @@ bool ContentDecryptorDelegate::DeserializeAudioFrames( return false; // Allocate space for the channel pointers given to AudioBuffer. - std::vector<const uint8*> channel_ptrs(audio_channel_count_, - static_cast<const uint8*>(NULL)); + std::vector<const uint8_t*> channel_ptrs(audio_channel_count_, nullptr); do { int64 timestamp = 0; int64 frame_size = -1; diff --git a/content/renderer/pepper/content_decryptor_delegate.h b/content/renderer/pepper/content_decryptor_delegate.h index 1fbeddb..cb3791d 100644 --- a/content/renderer/pepper/content_decryptor_delegate.h +++ b/content/renderer/pepper/content_decryptor_delegate.h @@ -8,6 +8,7 @@ #include <map> #include <queue> #include <string> +#include <vector> #include "base/basictypes.h" #include "base/callback_helpers.h" @@ -60,21 +61,18 @@ class ContentDecryptorDelegate { void InstanceCrashed(); // Provides access to PPP_ContentDecryptor_Private. - void SetServerCertificate(const uint8_t* certificate, - uint32_t certificate_length, + void SetServerCertificate(const std::vector<uint8_t>& certificate, scoped_ptr<media::SimpleCdmPromise> promise); void CreateSessionAndGenerateRequest( media::MediaKeys::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); void LoadSession(media::MediaKeys::SessionType session_type, const std::string& session_id, scoped_ptr<media::NewSessionCdmPromise> promise); void UpdateSession(const std::string& session_id, - const uint8* response, - int response_length, + const std::vector<uint8_t>& response, scoped_ptr<media::SimpleCdmPromise> promise); void CloseSession(const std::string& session_id, scoped_ptr<media::SimpleCdmPromise> promise); @@ -103,11 +101,11 @@ class ContentDecryptorDelegate { const media::Decryptor::VideoDecodeCB& video_decode_cb); // PPB_ContentDecryptor_Private dispatching methods. - void OnPromiseResolved(uint32 promise_id); - void OnPromiseResolvedWithSession(uint32 promise_id, PP_Var session_id); - void OnPromiseRejected(uint32 promise_id, + void OnPromiseResolved(uint32_t promise_id); + void OnPromiseResolvedWithSession(uint32_t promise_id, PP_Var session_id); + void OnPromiseRejected(uint32_t promise_id, PP_CdmExceptionCode exception_code, - uint32 system_code, + uint32_t system_code, PP_Var error_description); void OnSessionMessage(PP_Var session_id, PP_CdmMessageType message_type, @@ -121,7 +119,7 @@ class ContentDecryptorDelegate { void OnSessionClosed(PP_Var session_id); void OnLegacySessionError(PP_Var session_id, PP_CdmExceptionCode exception_code, - uint32 system_code, + uint32_t system_code, PP_Var error_description); void DeliverBlock(PP_Resource decrypted_block, const PP_DecryptedBlockInfo* block_info); 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)); } |