Chromium Code Reviews| Index: webkit/plugins/ppapi/content_decryptor_delegate.cc |
| diff --git a/webkit/plugins/ppapi/content_decryptor_delegate.cc b/webkit/plugins/ppapi/content_decryptor_delegate.cc |
| index f682c444d9c63c68368ae3d935cf2087b0967b44..02372b903e82132c67a90937b1914f987ac74a84 100644 |
| --- a/webkit/plugins/ppapi/content_decryptor_delegate.cc |
| +++ b/webkit/plugins/ppapi/content_decryptor_delegate.cc |
| @@ -40,8 +40,7 @@ namespace { |
| // resource. The |*resource|, if valid, will be in the ResourceTracker with a |
| // 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, uint32_t size, |
| +bool MakeBufferResource(PP_Instance instance, const uint8* data, uint32_t size, |
| scoped_refptr<PPB_Buffer_Impl>* resource) { |
| TRACE_EVENT0("eme", "ContentDecryptorDelegate - MakeBufferResource"); |
| DCHECK(resource); |
| @@ -84,8 +83,7 @@ bool CopyStringToArray(const std::string& str, uint8 (&array)[array_size]) { |
| // otherwise. |
| static bool MakeEncryptedBlockInfo( |
| const scoped_refptr<media::DecoderBuffer>& encrypted_buffer, |
| - uint32_t request_id, |
| - PP_EncryptedBlockInfo* block_info) { |
| + uint32_t request_id, PP_EncryptedBlockInfo* block_info) { |
| // TODO(xhwang): Fix initialization of PP_EncryptedBlockInfo here and |
| // anywhere else. |
| memset(block_info, 0, sizeof(*block_info)); |
| @@ -129,8 +127,7 @@ static bool MakeEncryptedBlockInfo( |
| // Deserializes audio data stored in |audio_frames| into individual audio |
| // buffers in |frames|. Returns true upon success. |
| -bool DeserializeAudioFrames(PP_Resource audio_frames, |
| - int data_size, |
| +bool DeserializeAudioFrames(PP_Resource audio_frames, int data_size, |
| media::Decryptor::AudioBuffers* frames) { |
| DCHECK(frames); |
| EnterResourceNoLock<PPB_Buffer_API> enter(audio_frames, true); |
| @@ -167,7 +164,7 @@ bool DeserializeAudioFrames(PP_Resource audio_frames, |
| scoped_refptr<media::DataBuffer> frame = |
| media::DataBuffer::CopyFrom(cur, frame_size); |
| - frame->SetTimestamp(base::TimeDelta::FromMicroseconds(timestamp)); |
| + frame->set_timestamp(base::TimeDelta::FromMicroseconds(timestamp)); |
| frames->push_back(frame); |
| cur += frame_size; |
| @@ -282,8 +279,7 @@ ContentDecryptorDelegate::ContentDecryptorDelegate( |
| pending_audio_decode_request_id_(0), |
| pending_video_decode_request_id_(0), |
| weak_ptr_factory_(this), |
| - weak_this_(weak_ptr_factory_.GetWeakPtr()) { |
| -} |
| + weak_this_(weak_ptr_factory_.GetWeakPtr()) {} |
|
brettw
2013/06/24 20:25:42
This was better before.
|
| void ContentDecryptorDelegate::Initialize(const std::string& key_system) { |
| // TODO(ddorwin): Add an Initialize method to PPP_ContentDecryptor_Private. |
| @@ -305,42 +301,34 @@ void ContentDecryptorDelegate::SetKeyEventCallbacks( |
| bool ContentDecryptorDelegate::GenerateKeyRequest(const std::string& type, |
| const uint8* init_data, |
| int init_data_length) { |
| - PP_Var init_data_array = |
| - PpapiGlobals::Get()->GetVarTracker()->MakeArrayBufferPPVar( |
| - init_data_length, init_data); |
| + PP_Var init_data_array = PpapiGlobals::Get()->GetVarTracker() |
| + ->MakeArrayBufferPPVar(init_data_length, init_data); |
|
brettw
2013/06/24 20:25:42
You did a lot of random reformatting in this file.
|
| plugin_decryption_interface_->GenerateKeyRequest( |
| pp_instance_, |
| StringVar::StringToPPVar(key_system_), // TODO(ddorwin): Remove. |
| - StringVar::StringToPPVar(type), |
| - init_data_array); |
| + StringVar::StringToPPVar(type), init_data_array); |
| return true; |
| } |
| bool ContentDecryptorDelegate::AddKey(const std::string& session_id, |
| - const uint8* key, |
| - int key_length, |
| + const uint8* key, int key_length, |
| const uint8* init_data, |
| int init_data_length) { |
| - PP_Var key_array = |
| - PpapiGlobals::Get()->GetVarTracker()->MakeArrayBufferPPVar(key_length, |
| - key); |
| - PP_Var init_data_array = |
| - PpapiGlobals::Get()->GetVarTracker()->MakeArrayBufferPPVar( |
| - init_data_length, init_data); |
| + PP_Var key_array = PpapiGlobals::Get()->GetVarTracker() |
| + ->MakeArrayBufferPPVar(key_length, key); |
| + PP_Var init_data_array = PpapiGlobals::Get()->GetVarTracker() |
| + ->MakeArrayBufferPPVar(init_data_length, init_data); |
| plugin_decryption_interface_->AddKey( |
| - pp_instance_, |
| - StringVar::StringToPPVar(session_id), |
| - key_array, |
| + pp_instance_, StringVar::StringToPPVar(session_id), key_array, |
| init_data_array); |
| return true; |
| } |
| bool ContentDecryptorDelegate::CancelKeyRequest(const std::string& session_id) { |
| plugin_decryption_interface_->CancelKeyRequest( |
| - pp_instance_, |
| - StringVar::StringToPPVar(session_id)); |
| + pp_instance_, StringVar::StringToPPVar(session_id)); |
| return true; |
| } |
| @@ -355,8 +343,8 @@ bool ContentDecryptorDelegate::Decrypt( |
| // now because there is only one pending audio/video decrypt request at any |
| // time. This is enforced by the media pipeline. |
| scoped_refptr<PPB_Buffer_Impl> encrypted_resource; |
| - if (!MakeMediaBufferResource( |
| - stream_type, encrypted_buffer, &encrypted_resource) || |
| + if (!MakeMediaBufferResource(stream_type, encrypted_buffer, |
|
brettw
2013/06/24 20:25:42
I preferred the previous formatting,
|
| + &encrypted_resource) || |
| !encrypted_resource.get()) { |
| return false; |
| } |
| @@ -393,9 +381,7 @@ bool ContentDecryptorDelegate::Decrypt( |
| SetBufferToFreeInTrackingInfo(&block_info.tracking_info); |
| - plugin_decryption_interface_->Decrypt(pp_instance_, |
| - pp_resource, |
| - &block_info); |
| + plugin_decryption_interface_->Decrypt(pp_instance_, pp_resource, &block_info); |
| return true; |
| } |
| @@ -445,8 +431,7 @@ bool ContentDecryptorDelegate::InitializeAudioDecoder( |
| pp_decoder_config.request_id = next_decryption_request_id_++; |
| scoped_refptr<PPB_Buffer_Impl> extra_data_resource; |
| - if (!MakeBufferResource(pp_instance_, |
| - decoder_config.extra_data(), |
| + if (!MakeBufferResource(pp_instance_, decoder_config.extra_data(), |
| decoder_config.extra_data_size(), |
| &extra_data_resource)) { |
| return false; |
| @@ -458,9 +443,8 @@ bool ContentDecryptorDelegate::InitializeAudioDecoder( |
| pending_audio_decoder_init_request_id_ = pp_decoder_config.request_id; |
| pending_audio_decoder_init_cb_ = init_cb; |
| - plugin_decryption_interface_->InitializeAudioDecoder(pp_instance_, |
| - &pp_decoder_config, |
| - pp_resource); |
| + plugin_decryption_interface_->InitializeAudioDecoder( |
| + pp_instance_, &pp_decoder_config, pp_resource); |
| return true; |
| } |
| @@ -479,8 +463,7 @@ bool ContentDecryptorDelegate::InitializeVideoDecoder( |
| pp_decoder_config.request_id = next_decryption_request_id_++; |
| scoped_refptr<PPB_Buffer_Impl> extra_data_resource; |
| - if (!MakeBufferResource(pp_instance_, |
| - decoder_config.extra_data(), |
| + if (!MakeBufferResource(pp_instance_, decoder_config.extra_data(), |
| decoder_config.extra_data_size(), |
| &extra_data_resource)) { |
| return false; |
| @@ -494,9 +477,8 @@ bool ContentDecryptorDelegate::InitializeVideoDecoder( |
| natural_size_ = decoder_config.natural_size(); |
| - plugin_decryption_interface_->InitializeVideoDecoder(pp_instance_, |
| - &pp_decoder_config, |
| - pp_resource); |
| + plugin_decryption_interface_->InitializeVideoDecoder( |
| + pp_instance_, &pp_decoder_config, pp_resource); |
| return true; |
| } |
| @@ -530,8 +512,7 @@ bool ContentDecryptorDelegate::DecryptAndDecodeAudio( |
| // because there is only one pending audio decode request at any time. |
| // This is enforced by the media pipeline. |
| scoped_refptr<PPB_Buffer_Impl> encrypted_resource; |
| - if (!MakeMediaBufferResource(media::Decryptor::kAudio, |
| - encrypted_buffer, |
| + if (!MakeMediaBufferResource(media::Decryptor::kAudio, encrypted_buffer, |
| &encrypted_resource)) { |
| return false; |
| } |
| @@ -560,10 +541,8 @@ bool ContentDecryptorDelegate::DecryptAndDecodeAudio( |
| pending_audio_decode_cb_ = audio_decode_cb; |
| ScopedPPResource pp_resource(encrypted_resource.get()); |
| - plugin_decryption_interface_->DecryptAndDecode(pp_instance_, |
| - PP_DECRYPTORSTREAMTYPE_AUDIO, |
| - pp_resource, |
| - &block_info); |
| + plugin_decryption_interface_->DecryptAndDecode( |
|
brettw
2013/06/24 20:25:42
IMO this type of thing is equal either way and I d
|
| + pp_instance_, PP_DECRYPTORSTREAMTYPE_AUDIO, pp_resource, &block_info); |
| return true; |
| } |
| @@ -574,8 +553,7 @@ bool ContentDecryptorDelegate::DecryptAndDecodeVideo( |
| // because there is only one pending video decode request at any time. |
| // This is enforced by the media pipeline. |
| scoped_refptr<PPB_Buffer_Impl> encrypted_resource; |
| - if (!MakeMediaBufferResource(media::Decryptor::kVideo, |
| - encrypted_buffer, |
| + if (!MakeMediaBufferResource(media::Decryptor::kVideo, encrypted_buffer, |
| &encrypted_resource)) { |
| return false; |
| } |
| @@ -607,10 +585,8 @@ bool ContentDecryptorDelegate::DecryptAndDecodeVideo( |
| // TODO(tomfinegan): Need to get stream type from media stack. |
| ScopedPPResource pp_resource(encrypted_resource.get()); |
| - plugin_decryption_interface_->DecryptAndDecode(pp_instance_, |
| - PP_DECRYPTORSTREAMTYPE_VIDEO, |
| - pp_resource, |
| - &block_info); |
| + plugin_decryption_interface_->DecryptAndDecode( |
| + pp_instance_, PP_DECRYPTORSTREAMTYPE_VIDEO, pp_resource, &block_info); |
| return true; |
| } |
| @@ -644,8 +620,7 @@ void ContentDecryptorDelegate::KeyMessage(PP_Var key_system_var, |
| StringVar* session_id_string = StringVar::FromPPVar(session_id_var); |
| - ArrayBufferVar* message_array_buffer = |
| - ArrayBufferVar::FromPPVar(message_var); |
| + ArrayBufferVar* message_array_buffer = ArrayBufferVar::FromPPVar(message_var); |
| std::string message; |
| if (message_array_buffer) { |
| @@ -660,8 +635,7 @@ void ContentDecryptorDelegate::KeyMessage(PP_Var key_system_var, |
| return; |
| } |
| - key_message_cb_.Run(session_id_string->value(), |
| - message, |
| + key_message_cb_.Run(session_id_string->value(), message, |
| default_url_string->value()); |
| } |
| @@ -684,50 +658,42 @@ void ContentDecryptorDelegate::KeyError(PP_Var key_system_var, |
| } |
| void ContentDecryptorDelegate::DecoderInitializeDone( |
| - PP_DecryptorStreamType decoder_type, |
| - uint32_t request_id, |
| - PP_Bool success) { |
| + PP_DecryptorStreamType decoder_type, uint32_t request_id, PP_Bool success) { |
|
brettw
2013/06/24 20:25:42
The previous formatting was correct. Arg decl and
|
| if (decoder_type == PP_DECRYPTORSTREAMTYPE_AUDIO) { |
| // If the request ID is not valid or does not match what's saved, do |
| // nothing. |
| - if (request_id == 0 || |
| - request_id != pending_audio_decoder_init_request_id_) |
| + if (request_id == 0 || request_id != pending_audio_decoder_init_request_id_) |
| return; |
| - DCHECK(!pending_audio_decoder_init_cb_.is_null()); |
| - pending_audio_decoder_init_request_id_ = 0; |
| - base::ResetAndReturn( |
| - &pending_audio_decoder_init_cb_).Run(PP_ToBool(success)); |
| + DCHECK(!pending_audio_decoder_init_cb_.is_null()); |
| + pending_audio_decoder_init_request_id_ = 0; |
| + base::ResetAndReturn(&pending_audio_decoder_init_cb_) |
| + .Run(PP_ToBool(success)); |
| } else { |
| - if (request_id == 0 || |
| - request_id != pending_video_decoder_init_request_id_) |
| + if (request_id == 0 || request_id != pending_video_decoder_init_request_id_) |
| return; |
| - if (!success) |
| - natural_size_ = gfx::Size(); |
| + if (!success) natural_size_ = gfx::Size(); |
| - DCHECK(!pending_video_decoder_init_cb_.is_null()); |
| - pending_video_decoder_init_request_id_ = 0; |
| - base::ResetAndReturn( |
| - &pending_video_decoder_init_cb_).Run(PP_ToBool(success)); |
| + DCHECK(!pending_video_decoder_init_cb_.is_null()); |
| + pending_video_decoder_init_request_id_ = 0; |
| + base::ResetAndReturn(&pending_video_decoder_init_cb_) |
|
brettw
2013/06/24 20:25:42
Old formatting was better (avoid . at beginning of
|
| + .Run(PP_ToBool(success)); |
| } |
| } |
| void ContentDecryptorDelegate::DecoderDeinitializeDone( |
| - PP_DecryptorStreamType decoder_type, |
| - uint32_t request_id) { |
| + PP_DecryptorStreamType decoder_type, uint32_t request_id) { |
| // TODO(tomfinegan): Add decoder stop completion handling. |
| } |
| void ContentDecryptorDelegate::DecoderResetDone( |
| - PP_DecryptorStreamType decoder_type, |
| - uint32_t request_id) { |
| + PP_DecryptorStreamType decoder_type, uint32_t request_id) { |
| // TODO(tomfinegan): Add decoder reset completion handling. |
| } |
| void ContentDecryptorDelegate::DeliverBlock( |
| - PP_Resource decrypted_block, |
| - const PP_DecryptedBlockInfo* block_info) { |
| + PP_Resource decrypted_block, const PP_DecryptedBlockInfo* block_info) { |
| DCHECK(block_info); |
| FreeBuffer(block_info->tracking_info.buffer_id); |
| @@ -777,10 +743,10 @@ 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()), block_info->data_size)); |
| - decrypted_buffer->SetTimestamp(base::TimeDelta::FromMicroseconds( |
| - block_info->tracking_info.timestamp)); |
| + media::DecoderBuffer::CopyFrom(static_cast<uint8*>(mapper.data()), |
| + block_info->data_size)); |
| + decrypted_buffer->SetTimestamp( |
| + base::TimeDelta::FromMicroseconds(block_info->tracking_info.timestamp)); |
| decrypt_cb.Run(media::Decryptor::kSuccess, decrypted_buffer); |
| } |
| @@ -818,8 +784,7 @@ static uint8* GetMappedBuffer(PP_Resource resource, |
| } |
| void ContentDecryptorDelegate::DeliverFrame( |
| - PP_Resource decrypted_frame, |
| - const PP_DecryptedFrameInfo* frame_info) { |
| + PP_Resource decrypted_frame, const PP_DecryptedFrameInfo* frame_info) { |
| DCHECK(frame_info); |
| const uint32_t request_id = frame_info->tracking_info.request_id; |
| @@ -861,9 +826,8 @@ void ContentDecryptorDelegate::DeliverFrame( |
| scoped_refptr<media::VideoFrame> decoded_frame = |
| media::VideoFrame::WrapExternalYuvData( |
| - media::VideoFrame::YV12, |
| - frame_size, gfx::Rect(frame_size), natural_size_, |
| - frame_info->strides[PP_DECRYPTEDFRAMEPLANES_Y], |
| + media::VideoFrame::YV12, frame_size, gfx::Rect(frame_size), |
| + natural_size_, frame_info->strides[PP_DECRYPTEDFRAMEPLANES_Y], |
| frame_info->strides[PP_DECRYPTEDFRAMEPLANES_U], |
| frame_info->strides[PP_DECRYPTEDFRAMEPLANES_V], |
| frame_data + frame_info->plane_offsets[PP_DECRYPTEDFRAMEPLANES_Y], |
| @@ -873,17 +837,16 @@ void ContentDecryptorDelegate::DeliverFrame( |
| frame_info->tracking_info.timestamp), |
| media::BindToLoop( |
| base::MessageLoopProxy::current(), |
| - base::Bind(&BufferNoLongerNeeded, ppb_buffer, |
| - base::Bind(&ContentDecryptorDelegate::FreeBuffer, |
| - weak_this_, |
| - frame_info->tracking_info.buffer_id)))); |
| + base::Bind( |
| + &BufferNoLongerNeeded, ppb_buffer, |
| + base::Bind(&ContentDecryptorDelegate::FreeBuffer, weak_this_, |
| + frame_info->tracking_info.buffer_id)))); |
| video_decode_cb.Run(media::Decryptor::kSuccess, decoded_frame); |
| } |
| void ContentDecryptorDelegate::DeliverSamples( |
| - PP_Resource audio_frames, |
| - const PP_DecryptedBlockInfo* block_info) { |
| + PP_Resource audio_frames, const PP_DecryptedBlockInfo* block_info) { |
| DCHECK(block_info); |
| FreeBuffer(block_info->tracking_info.buffer_id); |
| @@ -912,8 +875,7 @@ void ContentDecryptorDelegate::DeliverSamples( |
| } |
| media::Decryptor::AudioBuffers audio_frame_list; |
| - if (!DeserializeAudioFrames(audio_frames, |
| - block_info->data_size, |
| + if (!DeserializeAudioFrames(audio_frames, block_info->data_size, |
| &audio_frame_list)) { |
| NOTREACHED() << "CDM did not serialize the buffer correctly."; |
| audio_decode_cb.Run(media::Decryptor::kError, empty_frames); |
| @@ -934,8 +896,8 @@ void ContentDecryptorDelegate::CancelDecode( |
| audio_input_resource_ = NULL; |
| pending_audio_decode_request_id_ = 0; |
| if (!pending_audio_decode_cb_.is_null()) |
| - base::ResetAndReturn(&pending_audio_decode_cb_).Run( |
| - media::Decryptor::kSuccess, media::Decryptor::AudioBuffers()); |
| + base::ResetAndReturn(&pending_audio_decode_cb_) |
| + .Run(media::Decryptor::kSuccess, media::Decryptor::AudioBuffers()); |
| break; |
| case media::Decryptor::kVideo: |
| // Release the shared memory as it can still be in use by the plugin. |
| @@ -944,8 +906,8 @@ void ContentDecryptorDelegate::CancelDecode( |
| video_input_resource_ = NULL; |
| pending_video_decode_request_id_ = 0; |
| if (!pending_video_decode_cb_.is_null()) |
| - base::ResetAndReturn(&pending_video_decode_cb_).Run( |
| - media::Decryptor::kSuccess, NULL); |
| + base::ResetAndReturn(&pending_video_decode_cb_) |
| + .Run(media::Decryptor::kSuccess, NULL); |
| break; |
| default: |
| NOTREACHED(); |
| @@ -967,8 +929,8 @@ bool ContentDecryptorDelegate::MakeMediaBufferResource( |
| DCHECK(stream_type == media::Decryptor::kAudio || |
| stream_type == media::Decryptor::kVideo); |
| scoped_refptr<PPB_Buffer_Impl>& media_resource = |
| - (stream_type == media::Decryptor::kAudio) ? audio_input_resource_ : |
| - video_input_resource_; |
| + (stream_type == media::Decryptor::kAudio) ? audio_input_resource_ |
| + : video_input_resource_; |
| const size_t data_size = static_cast<size_t>(encrypted_buffer->GetDataSize()); |
| if (!media_resource.get() || media_resource->size() < data_size) { |
| @@ -990,8 +952,8 @@ bool ContentDecryptorDelegate::MakeMediaBufferResource( |
| << ((stream_type == media::Decryptor::kAudio) ? "audio" : "video") |
| << " stream bumped to " << media_resource_size |
| << " bytes to fit input."; |
| - media_resource = PPB_Buffer_Impl::CreateResource(pp_instance_, |
| - media_resource_size); |
| + media_resource = |
| + PPB_Buffer_Impl::CreateResource(pp_instance_, media_resource_size); |
| if (!media_resource.get()) |
| return false; |
| } |