From dc95389fc803581de77c7fb617b1ef4870c9cbd5 Mon Sep 17 00:00:00 2001 From: "mlloyd@chromium.org" Date: Fri, 17 Sep 2010 14:19:15 +0000 Subject: Revert 59784 - GpuVideoDecoder to use GpuVideoDevice and IPC messages to complete VideoFrame allocation GpuVideoDecedoer now sends IPC messages to allocation GL textures. It also uses GpuVideoDevice to create VideoFrames from the GL textures. These GL textures are passed into VideoDecodeEngine. BUG=53714 TEST=Tree is green Review URL: http://codereview.chromium.org/3335019 TBR=hclam@chromium.org Review URL: http://codereview.chromium.org/3451007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@59790 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/renderer/gpu_video_decoder_host.cc | 37 +++++++++++++++++++--- chrome/renderer/gpu_video_decoder_host.h | 1 + .../renderer/media/gles2_video_decode_context.cc | 8 ++--- chrome/renderer/media/gles2_video_decode_context.h | 9 +++--- chrome/renderer/media/ipc_video_decoder.cc | 7 ++-- 5 files changed, 45 insertions(+), 17 deletions(-) (limited to 'chrome/renderer') diff --git a/chrome/renderer/gpu_video_decoder_host.cc b/chrome/renderer/gpu_video_decoder_host.cc index 771c38a..a585ede 100644 --- a/chrome/renderer/gpu_video_decoder_host.cc +++ b/chrome/renderer/gpu_video_decoder_host.cc @@ -109,9 +109,12 @@ void GpuVideoDecoderHost::FillThisBuffer(scoped_refptr frame) { // TODO(hclam): We should keep an IDMap to convert between a frame a buffer // ID so that we can signal GpuVideoDecoder in GPU process to use the buffer. // This eliminates one conversion step. - // TODO(hclam): Fill the param. GpuVideoDecoderOutputBufferParam param; + // TODO(hclam): This is a hack to pass the texture id to the hardware video + // decoder. We should have created a mapping between VideoFrame and buffer id + // and we pass the buffer id to the GPU process. + param.texture = frame->gl_texture(VideoFrame::kRGBPlane); if (!channel_host_ || !channel_host_->Send( new GpuVideoDecoderMsg_FillThisBuffer(route_id(), param))) { LOG(ERROR) << "GpuVideoDecoderMsg_FillThisBuffer failed"; @@ -149,6 +152,13 @@ void GpuVideoDecoderHost::OnInitializeDone( if (!input_transfer_buffer_->Map(param.input_buffer_size)) break; + if (!base::SharedMemory::IsHandleValid(param.output_buffer_handle)) + break; + output_transfer_buffer_.reset( + new base::SharedMemory(param.output_buffer_handle, false)); + if (!output_transfer_buffer_->Map(param.output_buffer_size)) + break; + success = true; } while (0); @@ -158,6 +168,7 @@ void GpuVideoDecoderHost::OnInitializeDone( void GpuVideoDecoderHost::OnUninitializeDone() { input_transfer_buffer_.reset(); + output_transfer_buffer_.reset(); event_handler_->OnUninitializeDone(); } @@ -178,11 +189,27 @@ void GpuVideoDecoderHost::OnFillThisBufferDone( if (param.flags & GpuVideoDecoderOutputBufferParam::kFlagsEndOfStream) { VideoFrame::CreateEmptyFrame(&frame); - } else { + } else if (done_param_.surface_type == + media::VideoFrame::TYPE_SYSTEM_MEMORY) { + VideoFrame::CreateFrame(VideoFrame::YV12, + init_param_.width, + init_param_.height, + base::TimeDelta::FromMicroseconds(param.timestamp), + base::TimeDelta::FromMicroseconds(param.duration), + &frame); + uint8* src = static_cast(output_transfer_buffer_->memory()); + uint8* data0 = frame->data(0); + uint8* data1 = frame->data(1); + uint8* data2 = frame->data(2); + int32 size = init_param_.width * init_param_.height; + memcpy(data0, src, size); + memcpy(data1, src + size, size / 4); + memcpy(data2, src + size + size / 4, size / 4); + } else if (done_param_.surface_type == media::VideoFrame::TYPE_GL_TEXTURE) { // TODO(hclam): The logic in buffer allocation is pretty much around - // using shared memory for output buffer which needs to be adjusted. - // Fake the texture ID until we implement it properly. - VideoFrame::GlTexture textures[3] = { 0, 0, 0 }; + // using shared memory for output buffer which needs to be adjusted. For + // now we have to add this hack to get the texture id. + VideoFrame::GlTexture textures[3] = { param.texture, 0, 0 }; media::VideoFrame::CreateFrameGlTexture( media::VideoFrame::RGBA, init_param_.width, init_param_.height, textures, diff --git a/chrome/renderer/gpu_video_decoder_host.h b/chrome/renderer/gpu_video_decoder_host.h index 1255bf5..02f8fc8 100644 --- a/chrome/renderer/gpu_video_decoder_host.h +++ b/chrome/renderer/gpu_video_decoder_host.h @@ -112,6 +112,7 @@ class GpuVideoDecoderHost // Transfer buffers for both input and output. // TODO(jiesun): remove output buffer when hardware composition is ready. scoped_ptr input_transfer_buffer_; + scoped_ptr output_transfer_buffer_; DISALLOW_COPY_AND_ASSIGN(GpuVideoDecoderHost); }; diff --git a/chrome/renderer/media/gles2_video_decode_context.cc b/chrome/renderer/media/gles2_video_decode_context.cc index 2c04282..075f80a 100644 --- a/chrome/renderer/media/gles2_video_decode_context.cc +++ b/chrome/renderer/media/gles2_video_decode_context.cc @@ -20,15 +20,15 @@ void* Gles2VideoDecodeContext::GetDevice() { } void Gles2VideoDecodeContext::AllocateVideoFrames( - int n, size_t width, size_t height, media::VideoFrame::Format format, - std::vector >* frames, Task* task) { + int n, size_t width, size_t height, AllocationCompleteCallback* callback) { // TODO(hclam): Implement. } -void Gles2VideoDecodeContext::ReleaseAllVideoFrames() { +void Gles2VideoDecodeContext::ReleaseVideoFrames(int n, + media::VideoFrame* frames) { // TODO(hclam): Implement. } -void Gles2VideoDecodeContext::Destroy(Task* task) { +void Gles2VideoDecodeContext::Destroy(DestructionCompleteCallback* callback) { // TODO(hclam): Implement. } diff --git a/chrome/renderer/media/gles2_video_decode_context.h b/chrome/renderer/media/gles2_video_decode_context.h index 35958b6..e087bb3 100644 --- a/chrome/renderer/media/gles2_video_decode_context.h +++ b/chrome/renderer/media/gles2_video_decode_context.h @@ -95,11 +95,10 @@ class Gles2VideoDecodeContext : public media::VideoDecodeContext { // media::VideoDecodeContext implementation. virtual void* GetDevice(); - virtual void AllocateVideoFrames( - int n, size_t width, size_t height, media::VideoFrame::Format format, - std::vector >* frames, Task* task); - virtual void ReleaseAllVideoFrames(); - virtual void Destroy(Task* task) = 0; + virtual void AllocateVideoFrames(int n, size_t width, size_t height, + AllocationCompleteCallback* callback); + virtual void ReleaseVideoFrames(int n, media::VideoFrame* frames); + virtual void Destroy(DestructionCompleteCallback* callback); //-------------------------------------------------------------------------- // Any thread diff --git a/chrome/renderer/media/ipc_video_decoder.cc b/chrome/renderer/media/ipc_video_decoder.cc index eda8696..0b6896b 100644 --- a/chrome/renderer/media/ipc_video_decoder.cc +++ b/chrome/renderer/media/ipc_video_decoder.cc @@ -111,9 +111,10 @@ void IpcVideoDecoder::OnInitializeDone( media::mime_type::kUncompressedVideo); media_format_.SetAsInteger(media::MediaFormat::kWidth, width_); media_format_.SetAsInteger(media::MediaFormat::kHeight, height_); - media_format_.SetAsInteger( - media::MediaFormat::kSurfaceType, - static_cast(media::VideoFrame::TYPE_GL_TEXTURE)); + media_format_.SetAsInteger(media::MediaFormat::kSurfaceType, + static_cast(param.surface_type)); + media_format_.SetAsInteger(media::MediaFormat::kSurfaceFormat, + static_cast(param.format)); state_ = kPlaying; } else { LOG(ERROR) << "IpcVideoDecoder initialization failed!"; -- cgit v1.1