Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(342)

Unified Diff: webkit/plugins/ppapi/content_decryptor_delegate.cc

Issue 17315021: Refactored DataBuffer to use unix_hacker style methods. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed style that was botched by an incorrect use of clang-format Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « media/filters/opus_audio_decoder.cc ('k') | webkit/renderer/media/crypto/ppapi/ffmpeg_cdm_audio_decoder.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..c8ce64e8961e11b0d52136ab0929870fbd9747f2 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);
@@ -71,8 +70,7 @@ bool MakeBufferResource(PP_Instance instance,
// |array_size| is smaller than the |str| length.
template <uint32_t array_size>
bool CopyStringToArray(const std::string& str, uint8 (&array)[array_size]) {
- if (array_size < str.size())
- return false;
+ if (array_size < str.size()) return false;
scherkus (not reviewing) 2013/06/21 23:39:16 hey!
memcpy(array, str.data(), str.size());
return true;
@@ -84,8 +82,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 +126,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 +163,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 +278,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()) {}
void ContentDecryptorDelegate::Initialize(const std::string& key_system) {
// TODO(ddorwin): Add an Initialize method to PPP_ContentDecryptor_Private.
@@ -305,42 +300,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);
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 +342,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,
+ &encrypted_resource) ||
!encrypted_resource.get()) {
return false;
}
@@ -393,9 +380,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 +430,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 +442,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 +462,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 +476,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 +511,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 +540,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(
+ pp_instance_, PP_DECRYPTORSTREAMTYPE_AUDIO, pp_resource, &block_info);
return true;
}
@@ -574,8 +552,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 +584,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 +619,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 +634,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 +657,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) {
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_)
+ .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 +742,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 +783,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 +825,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 +836,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 +874,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 +895,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 +905,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 +928,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) {
@@ -983,15 +944,14 @@ bool ContentDecryptorDelegate::MakeMediaBufferResource(
const uint32_t kMinimumMediaBufferSize = 1024;
uint32_t media_resource_size =
media_resource.get() ? media_resource->size() : kMinimumMediaBufferSize;
- while (media_resource_size < data_size)
- media_resource_size *= 2;
+ while (media_resource_size < data_size) media_resource_size *= 2;
scherkus (not reviewing) 2013/06/21 23:39:16 hey!
DVLOG(2) << "Size of media buffer for "
<< ((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;
}
« no previous file with comments | « media/filters/opus_audio_decoder.cc ('k') | webkit/renderer/media/crypto/ppapi/ffmpeg_cdm_audio_decoder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698