diff options
-rw-r--r-- | chrome/common/DEPS | 1 | ||||
-rw-r--r-- | chrome/common/gpu_messages_internal.h | 17 | ||||
-rw-r--r-- | chrome/common/gpu_video_common.cc | 180 | ||||
-rw-r--r-- | chrome/common/gpu_video_common.h | 24 | ||||
-rw-r--r-- | chrome/gpu/gpu_video_decoder.cc | 16 | ||||
-rw-r--r-- | chrome/renderer/gpu_video_decoder_host.cc | 5 |
6 files changed, 153 insertions, 90 deletions
diff --git a/chrome/common/DEPS b/chrome/common/DEPS index ce48477..93d6fc0 100644 --- a/chrome/common/DEPS +++ b/chrome/common/DEPS @@ -4,6 +4,7 @@ include_rules = [ "+grit", # For generated headers "+libxml", "+media/audio", + "+media/base", "+remoting/client/plugin", "+sandbox/src", "+skia/include", diff --git a/chrome/common/gpu_messages_internal.h b/chrome/common/gpu_messages_internal.h index e281f371..5a4d505 100644 --- a/chrome/common/gpu_messages_internal.h +++ b/chrome/common/gpu_messages_internal.h @@ -303,6 +303,12 @@ IPC_BEGIN_MESSAGES(GpuVideoDecoder) // where output transfer buffer had to be guarded. IPC_MESSAGE_ROUTED0(GpuVideoDecoderMsg_FillThisBufferDoneACK) + // Sent from Renderer process to the GPU process to notify that textures are + // generated for a video frame. + IPC_MESSAGE_ROUTED2(GpuVideoDecoderMsg_VideoFrameAllocated, + int32, /* Video Frame ID */ + std::vector<uint32>) /* Textures for video frame */ + IPC_END_MESSAGES(GpuVideoDecoder) //------------------------------------------------------------------------------ @@ -329,6 +335,16 @@ IPC_BEGIN_MESSAGES(GpuVideoDecoderHost) IPC_MESSAGE_ROUTED1(GpuVideoDecoderHostMsg_FillThisBufferDone, GpuVideoDecoderOutputBufferParam) + // Allocate video frames for output of the hardware video decoder. + IPC_MESSAGE_ROUTED4(GpuVideoDecoderHostMsg_AllocateVideoFrame, + int32, /* Numer of video frames to generate */ + int32, /* Width of the video frame */ + int32, /* Height of the video frame */ + media::VideoFrame::Format /* Format of the video frame */) + + // Release all video frames allocated for a hardware video decoder. + IPC_MESSAGE_ROUTED0(GpuVideoDecoderHostMsg_ReleaseAllVideoFrames) + // GpuVideoDecoder report output format change. IPC_MESSAGE_ROUTED1(GpuVideoDecoderHostMsg_MediaFormatChange, GpuVideoDecoderFormatChangeParam) @@ -338,4 +354,3 @@ IPC_BEGIN_MESSAGES(GpuVideoDecoderHost) GpuVideoDecoderErrorInfoParam) IPC_END_MESSAGES(GpuVideoDecoderHost) - diff --git a/chrome/common/gpu_video_common.cc b/chrome/common/gpu_video_common.cc index 928bb44..65810fc 100644 --- a/chrome/common/gpu_video_common.cc +++ b/chrome/common/gpu_video_common.cc @@ -8,16 +8,16 @@ namespace IPC { void ParamTraits<GpuVideoServiceInfoParam>::Write( Message* m, const GpuVideoServiceInfoParam& p) { - m->WriteInt(p.video_service_route_id); - m->WriteInt(p.video_service_host_route_id); - m->WriteInt(p.service_available); + WriteParam(m, p.video_service_route_id); + WriteParam(m, p.video_service_host_route_id); + WriteParam(m, p.service_available); } bool ParamTraits<GpuVideoServiceInfoParam>::Read( const Message* m, void** iter, GpuVideoServiceInfoParam* r) { - if (!m->ReadInt(iter, &r->video_service_route_id) || - !m->ReadInt(iter, &r->video_service_host_route_id) || - !m->ReadInt(iter, &r->service_available)) + if (!ReadParam(m, iter, &r->video_service_route_id) || + !ReadParam(m, iter, &r->video_service_host_route_id) || + !ReadParam(m, iter, &r->service_available)) return false; return true; } @@ -34,18 +34,18 @@ void ParamTraits<GpuVideoServiceInfoParam>::Log( void ParamTraits<GpuVideoDecoderInfoParam>::Write( Message* m, const GpuVideoDecoderInfoParam& p) { - m->WriteInt(p.context_id); - m->WriteInt(p.decoder_id); - m->WriteInt(p.decoder_route_id); - m->WriteInt(p.decoder_host_route_id); + WriteParam(m, p.context_id); + WriteParam(m, p.decoder_id); + WriteParam(m, p.decoder_route_id); + WriteParam(m, p.decoder_host_route_id); } bool ParamTraits<GpuVideoDecoderInfoParam>::Read( const Message* m, void** iter, GpuVideoDecoderInfoParam* r) { - if (!m->ReadInt(iter, &r->context_id) || - !m->ReadInt(iter, &r->decoder_id) || - !m->ReadInt(iter, &r->decoder_route_id) || - !m->ReadInt(iter, &r->decoder_host_route_id)) + if (!ReadParam(m, iter, &r->context_id) || + !ReadParam(m, iter, &r->decoder_id) || + !ReadParam(m, iter, &r->decoder_route_id) || + !ReadParam(m, iter, &r->decoder_host_route_id)) return false; return true; } @@ -62,16 +62,16 @@ void ParamTraits<GpuVideoDecoderInfoParam>::Log( void ParamTraits<GpuVideoDecoderInitParam>::Write( Message* m, const GpuVideoDecoderInitParam& p) { - m->WriteInt(p.codec_id); - m->WriteInt(p.width); - m->WriteInt(p.height); + WriteParam(m, p.codec_id); + WriteParam(m, p.width); + WriteParam(m, p.height); } bool ParamTraits<GpuVideoDecoderInitParam>::Read( const Message* m, void** iter, GpuVideoDecoderInitParam* r) { - if (!m->ReadInt(iter, &r->codec_id) || - !m->ReadInt(iter, &r->width) || - !m->ReadInt(iter, &r->height)) + if (!ReadParam(m, iter, &r->codec_id) || + !ReadParam(m, iter, &r->width) || + !ReadParam(m, iter, &r->height)) return false; return true; } @@ -85,30 +85,26 @@ void ParamTraits<GpuVideoDecoderInitParam>::Log( void ParamTraits<GpuVideoDecoderInitDoneParam>::Write( Message* m, const GpuVideoDecoderInitDoneParam& p) { - m->WriteInt(p.success); - m->WriteInt(p.stride); - m->WriteInt(p.format); - m->WriteInt(p.surface_type); - m->WriteInt(p.input_buffer_size); - m->WriteInt(p.output_buffer_size); - IPC::ParamTraits<base::SharedMemoryHandle>::Write( - m, p.input_buffer_handle); - IPC::ParamTraits<base::SharedMemoryHandle>::Write( - m, p.output_buffer_handle); + WriteParam(m, p.success); + WriteParam(m, p.stride); + WriteParam(m, p.format); + WriteParam(m, p.surface_type); + WriteParam(m, p.input_buffer_size); + WriteParam(m, p.output_buffer_size); + WriteParam(m, p.input_buffer_handle); + WriteParam(m, p.output_buffer_handle); } bool ParamTraits<GpuVideoDecoderInitDoneParam>::Read( const Message* m, void** iter, GpuVideoDecoderInitDoneParam* r) { - if (!m->ReadInt(iter, &r->success) || - !m->ReadInt(iter, &r->stride) || - !m->ReadInt(iter, &r->format) || - !m->ReadInt(iter, &r->surface_type) || - !m->ReadInt(iter, &r->input_buffer_size) || - !m->ReadInt(iter, &r->output_buffer_size) || - !IPC::ParamTraits<base::SharedMemoryHandle>::Read( - m, iter, &r->input_buffer_handle) || - !IPC::ParamTraits<base::SharedMemoryHandle>::Read( - m, iter, &r->output_buffer_handle)) + if (!ReadParam(m, iter, &r->success) || + !ReadParam(m, iter, &r->stride) || + !ReadParam(m, iter, &r->format) || + !ReadParam(m, iter, &r->surface_type) || + !ReadParam(m, iter, &r->input_buffer_size) || + !ReadParam(m, iter, &r->output_buffer_size) || + !ReadParam(m, iter, &r->input_buffer_handle) || + !ReadParam(m, iter, &r->output_buffer_handle)) return false; return true; } @@ -122,16 +118,16 @@ void ParamTraits<GpuVideoDecoderInitDoneParam>::Log( void ParamTraits<GpuVideoDecoderInputBufferParam>::Write( Message* m, const GpuVideoDecoderInputBufferParam& p) { - m->WriteInt64(p.timestamp); - m->WriteInt(p.offset); - m->WriteInt(p.size); + WriteParam(m, p.timestamp); + WriteParam(m, p.offset); + WriteParam(m, p.size); } bool ParamTraits<GpuVideoDecoderInputBufferParam>::Read( const Message* m, void** iter, GpuVideoDecoderInputBufferParam* r) { - if (!m->ReadInt64(iter, &r->timestamp) || - !m->ReadInt(iter, &r->offset) || - !m->ReadInt(iter, &r->size)) + if (!ReadParam(m, iter, &r->timestamp) || + !ReadParam(m, iter, &r->offset) || + !ReadParam(m, iter, &r->size)) return false; return true; } @@ -147,18 +143,18 @@ void ParamTraits<GpuVideoDecoderInputBufferParam>::Log( void ParamTraits<GpuVideoDecoderOutputBufferParam>::Write( Message* m, const GpuVideoDecoderOutputBufferParam& p) { - m->WriteInt64(p.timestamp); - m->WriteInt64(p.duration); - m->WriteInt(p.flags); - m->WriteInt(p.texture); + WriteParam(m, p.timestamp); + WriteParam(m, p.duration); + WriteParam(m, p.flags); + WriteParam(m, p.texture); } bool ParamTraits<GpuVideoDecoderOutputBufferParam>::Read( const Message* m, void** iter, GpuVideoDecoderOutputBufferParam* r) { - if (!m->ReadInt64(iter, &r->timestamp) || - !m->ReadInt64(iter, &r->duration) || - !m->ReadInt(iter, &r->flags) || - !m->ReadInt(iter, &r->texture)) + if (!ReadParam(m, iter, &r->timestamp) || + !ReadParam(m, iter, &r->duration) || + !ReadParam(m, iter, &r->flags) || + !ReadParam(m, iter, &r->texture)) return false; return true; } @@ -176,12 +172,12 @@ void ParamTraits<GpuVideoDecoderOutputBufferParam>::Log( void ParamTraits<GpuVideoDecoderErrorInfoParam>::Write( Message* m, const GpuVideoDecoderErrorInfoParam& p) { - m->WriteInt(p.error_id); + WriteParam(m, p.error_id); } bool ParamTraits<GpuVideoDecoderErrorInfoParam>::Read( const Message* m, void** iter, GpuVideoDecoderErrorInfoParam* r) { - if (!m->ReadInt(iter, &r->error_id)) + if (!ReadParam(m, iter, &r->error_id)) return false; return true; } @@ -195,14 +191,14 @@ void ParamTraits<GpuVideoDecoderErrorInfoParam>::Log( void ParamTraits<GpuVideoDecoderFormatChangeParam>::Write( Message* m, const GpuVideoDecoderFormatChangeParam& p) { - m->WriteInt(p.input_buffer_size); - m->WriteInt(p.output_buffer_size); + WriteParam(m, p.input_buffer_size); + WriteParam(m, p.output_buffer_size); } bool ParamTraits<GpuVideoDecoderFormatChangeParam>::Read( const Message* m, void** iter, GpuVideoDecoderFormatChangeParam* r) { - if (!m->ReadInt(iter, &r->input_buffer_size) || - !m->ReadInt(iter, &r->output_buffer_size)) + if (!ReadParam(m, iter, &r->input_buffer_size) || + !ReadParam(m, iter, &r->output_buffer_size)) return false; return true; } @@ -212,4 +208,66 @@ void ParamTraits<GpuVideoDecoderFormatChangeParam>::Log( l->append(StringPrintf("(%d %d)", p.input_buffer_size, p.output_buffer_size)); } -}; + +/////////////////////////////////////////////////////////////////////////////// +// Traits for media::VideoFrame::Format +void ParamTraits<media::VideoFrame::Format>::Write( + Message* m, const param_type& p) { + WriteParam(m, p); +} + +bool ParamTraits<media::VideoFrame::Format>::Read( + const Message* m, void** iter, param_type* p) { + int type; + if (!ReadParam(m, iter, &type)) + return false; + *p = static_cast<param_type>(type); + return true; +} + +void ParamTraits<media::VideoFrame::Format>::Log( + const param_type& p, std::string* l) { + std::string s; + switch (p) { + case media::VideoFrame::RGB555: + s = "RGB555"; + break; + case media::VideoFrame::RGB565: + s = "RGB565"; + break; + case media::VideoFrame::RGB24: + s = "RGB24"; + break; + case media::VideoFrame::RGB32: + s = "RGB32"; + break; + case media::VideoFrame::RGBA: + s = "RGBA"; + break; + case media::VideoFrame::YV12: + s = "YV12"; + break; + case media::VideoFrame::YV16: + s = "YV16"; + break; + case media::VideoFrame::NV12: + s = "NV12"; + break; + case media::VideoFrame::EMPTY: + s = "EMPTY"; + break; + case media::VideoFrame::ASCII: + s = "ASCII"; + break; + case media::VideoFrame::INVALID: + s = "INVALID"; + break; + default: + NOTIMPLEMENTED(); + s = "UNKNOWN"; + break; + } + LogParam(s, l); +} + +} // namespace IPC diff --git a/chrome/common/gpu_video_common.h b/chrome/common/gpu_video_common.h index b49fe6d..ee3f1e3 100644 --- a/chrome/common/gpu_video_common.h +++ b/chrome/common/gpu_video_common.h @@ -8,6 +8,7 @@ #include "base/basictypes.h" #include "base/shared_memory.h" #include "chrome/common/common_param_traits.h" +#include "media/base/video_frame.h" struct GpuVideoServiceInfoParam { // route id for GpuVideoService on GPU process side for this channel. @@ -46,20 +47,10 @@ struct GpuVideoDecoderInitParam { }; struct GpuVideoDecoderInitDoneParam { - enum SurfaceType { - SurfaceTypeSystemMemory, - SurfaceTypeGlTexture, - SurfaceTypeD3dTexture, - }; - enum SurfaceFormat { - SurfaceFormat_YV12, - SurfaceFormat_NV12, - SurfaceFormat_RGBA, - }; int32 success; // other parameter is only meaningful when this is true. int32 provides_buffer; - int32 format; - int32 surface_type; + media::VideoFrame::Format format; + int32 surface_type; // TODO(hclam): Remove this. We only pass GL textures. int32 stride; int32 input_buffer_size; int32 output_buffer_size; @@ -169,6 +160,15 @@ struct ParamTraits<GpuVideoDecoderFormatChangeParam> { static bool Read(const Message* m, void** iter, param_type* r); static void Log(const param_type& p, std::string* l); }; + +template <> +struct ParamTraits<media::VideoFrame::Format> { + typedef media::VideoFrame::Format param_type; + static void Write(Message* m, const param_type& p); + static bool Read(const Message* m, void** iter, param_type* p); + static void Log(const param_type& p, std::string* l); }; +} // namespace IPC + #endif // CHROME_COMMON_GPU_VIDEO_COMMON_H_ diff --git a/chrome/gpu/gpu_video_decoder.cc b/chrome/gpu/gpu_video_decoder.cc index 1abe7dd..bcdce82 100644 --- a/chrome/gpu/gpu_video_decoder.cc +++ b/chrome/gpu/gpu_video_decoder.cc @@ -106,19 +106,9 @@ void GpuVideoDecoder::OnInitializeComplete(const VideoCodecInfo& info) { } // Translate surface type. - param.surface_type = static_cast<GpuVideoDecoderInitDoneParam::SurfaceType>( - info.stream_info.surface_type); - - // Translate surface format. - switch (info.stream_info.surface_format) { - case VideoFrame::YV12: - param.format = GpuVideoDecoderInitDoneParam::SurfaceFormat_YV12; - break; - case VideoFrame::RGBA: - param.format = GpuVideoDecoderInitDoneParam::SurfaceFormat_RGBA; - default: - NOTREACHED(); - } + // TODO(hclam): Remove |surface_type| since we are always passing textures. + param.surface_type = static_cast<int>(info.stream_info.surface_type); + param.format = info.stream_info.surface_format; // TODO(jiesun): Check the assumption of input size < original size. param.input_buffer_size = config_.width * config_.height * 3 / 2; diff --git a/chrome/renderer/gpu_video_decoder_host.cc b/chrome/renderer/gpu_video_decoder_host.cc index 4d010c2..a585ede 100644 --- a/chrome/renderer/gpu_video_decoder_host.cc +++ b/chrome/renderer/gpu_video_decoder_host.cc @@ -190,7 +190,7 @@ void GpuVideoDecoderHost::OnFillThisBufferDone( if (param.flags & GpuVideoDecoderOutputBufferParam::kFlagsEndOfStream) { VideoFrame::CreateEmptyFrame(&frame); } else if (done_param_.surface_type == - GpuVideoDecoderInitDoneParam::SurfaceTypeSystemMemory) { + media::VideoFrame::TYPE_SYSTEM_MEMORY) { VideoFrame::CreateFrame(VideoFrame::YV12, init_param_.width, init_param_.height, @@ -205,8 +205,7 @@ void GpuVideoDecoderHost::OnFillThisBufferDone( memcpy(data0, src, size); memcpy(data1, src + size, size / 4); memcpy(data2, src + size + size / 4, size / 4); - } else if (done_param_.surface_type == - GpuVideoDecoderInitDoneParam::SurfaceTypeGlTexture) { + } 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. For // now we have to add this hack to get the texture id. |