Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "content/common/gpu/client/gpu_jpeg_decode_accelerator_host.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "base/logging.h" | |
| 9 #include "content/common/gpu/client/gpu_channel_host.h" | |
| 10 #include "content/common/gpu/gpu_messages.h" | |
| 11 #include "ipc/ipc_message_macros.h" | |
| 12 #include "ipc/ipc_message_utils.h" | |
| 13 | |
| 14 using media::JpegDecodeAccelerator; | |
| 15 namespace content { | |
| 16 | |
| 17 GpuJpegDecodeAcceleratorHost::GpuJpegDecodeAcceleratorHost( | |
| 18 GpuChannelHost* channel, | |
| 19 int32 route_id) | |
| 20 : channel_(channel), client_(nullptr), decoder_route_id_(route_id) { | |
| 21 DCHECK(channel_); | |
| 22 } | |
| 23 | |
| 24 GpuJpegDecodeAcceleratorHost::~GpuJpegDecodeAcceleratorHost() { | |
| 25 DCHECK(CalledOnValidThread()); | |
| 26 Send(new AcceleratedJpegDecoderMsg_Destroy(decoder_route_id_)); | |
| 27 | |
| 28 if (channel_) { | |
| 29 if (decoder_route_id_ != MSG_ROUTING_NONE) | |
| 30 channel_->RemoveRoute(decoder_route_id_); | |
| 31 channel_ = nullptr; | |
| 32 } | |
| 33 } | |
| 34 | |
| 35 bool GpuJpegDecodeAcceleratorHost::OnMessageReceived(const IPC::Message& msg) { | |
| 36 DCHECK(CalledOnValidThread()); | |
| 37 bool handled = true; | |
| 38 IPC_BEGIN_MESSAGE_MAP(GpuJpegDecodeAcceleratorHost, msg) | |
| 39 IPC_MESSAGE_HANDLER(AcceleratedJpegDecoderHostMsg_DecodeAck, OnDecodeAck) | |
| 40 IPC_MESSAGE_UNHANDLED(handled = false) | |
| 41 IPC_END_MESSAGE_MAP() | |
| 42 DCHECK(handled); | |
| 43 return handled; | |
| 44 } | |
| 45 | |
| 46 void GpuJpegDecodeAcceleratorHost::OnChannelError() { | |
| 47 DVLOG(3) << __func__; | |
| 48 DCHECK(CalledOnValidThread()); | |
| 49 | |
| 50 channel_ = nullptr; | |
| 51 OnDecodeAck(kInvalidBitstreamBufferId, PLATFORM_FAILURE); | |
| 52 } | |
| 53 | |
| 54 bool GpuJpegDecodeAcceleratorHost::Initialize( | |
| 55 media::JpegDecodeAccelerator::Client* client) { | |
| 56 DCHECK(CalledOnValidThread()); | |
| 57 | |
| 58 bool succeeded = false; | |
| 59 // This cannot be on IO thread because the msg is synchronous. | |
| 60 Send(new GpuMsg_CreateJpegDecoder(decoder_route_id_, &succeeded)); | |
| 61 | |
| 62 if (!succeeded) { | |
| 63 DLOG(ERROR) << "Send(GpuMsg_CreateJpegDecoder()) failed"; | |
| 64 return false; | |
| 65 } | |
| 66 client_ = client; | |
| 67 | |
| 68 return true; | |
| 69 } | |
| 70 | |
| 71 void GpuJpegDecodeAcceleratorHost::Decode( | |
| 72 const media::BitstreamBuffer& bitstream_buffer, | |
| 73 const scoped_refptr<media::VideoFrame>& video_frame) { | |
| 74 DCHECK(CalledOnValidThread()); | |
| 75 if (!channel_) | |
| 76 return; | |
| 77 | |
| 78 DCHECK( | |
| 79 base::SharedMemory::IsHandleValid(video_frame->shared_memory_handle())); | |
| 80 | |
| 81 base::SharedMemoryHandle input_handle = | |
| 82 channel_->ShareToGpuProcess(bitstream_buffer.handle()); | |
| 83 if (!base::SharedMemory::IsHandleValid(input_handle)) { | |
| 84 DLOG(ERROR) << "Failed to duplicate handle of BitstreamBuffer"; | |
| 85 return; | |
| 86 } | |
| 87 base::SharedMemoryHandle output_handle = | |
| 88 channel_->ShareToGpuProcess(video_frame->shared_memory_handle()); | |
| 89 if (!base::SharedMemory::IsHandleValid(output_handle)) { | |
| 90 DLOG(ERROR) << "Failed to duplicate handle of VideoFrame"; | |
| 91 if (input_handle.auto_close) { | |
| 92 // Defer closing task to the ScopedFD. | |
| 93 base::ScopedFD(input_handle.fd); | |
| 94 } | |
| 95 return; | |
| 96 } | |
| 97 | |
| 98 size_t output_buffer_size = media::VideoFrame::AllocationSize( | |
| 99 video_frame->format(), video_frame->coded_size()); | |
| 100 | |
| 101 AcceleratedJpegDecoderMsg_Decode_Params decode_params; | |
| 102 decode_params.coded_size = video_frame->coded_size(); | |
| 103 decode_params.input_buffer_id = bitstream_buffer.id(); | |
| 104 decode_params.input_buffer_handle = input_handle; | |
| 105 decode_params.input_buffer_size = bitstream_buffer.size(); | |
| 106 decode_params.output_video_frame_handle = output_handle; | |
| 107 decode_params.output_buffer_size = output_buffer_size; | |
| 108 Send(new AcceleratedJpegDecoderMsg_Decode(decoder_route_id_, decode_params)); | |
| 109 } | |
| 110 | |
| 111 void GpuJpegDecodeAcceleratorHost::Send(IPC::Message* message) { | |
| 112 DVLOG(3) << __func__; | |
|
Pawel Osciak
2015/05/28 09:13:17
Nit: I'd remove this.
kcwu
2015/05/28 12:10:27
Done.
| |
| 113 DCHECK(CalledOnValidThread()); | |
| 114 | |
| 115 if (!channel_) | |
| 116 return; | |
| 117 if (!channel_->Send(message)) { | |
| 118 DLOG(ERROR) << "Send(" << message->type() << ") failed"; | |
| 119 } | |
|
Pawel Osciak
2015/05/28 09:13:17
If it's possible for channel to be null at 115, it
kcwu
2015/05/28 12:10:27
I'm revisiting the life cycle relation between |ch
| |
| 120 } | |
| 121 | |
| 122 void GpuJpegDecodeAcceleratorHost::OnDecodeAck(int32_t bitstream_buffer_id, | |
| 123 Error error) { | |
| 124 DCHECK(CalledOnValidThread()); | |
| 125 | |
| 126 if (!client_) | |
| 127 return; | |
| 128 | |
| 129 if (error == media::JpegDecodeAccelerator::NO_ERROR) { | |
| 130 client_->VideoFrameReady(bitstream_buffer_id); | |
| 131 } else { | |
|
Pawel Osciak
2015/05/28 09:13:17
What if the error is not critical, e.g. UNSUPPORTE
kcwu
2015/05/28 12:10:27
On earlier review, wuchengli suggest to error out
| |
| 132 // Only NotifyError once. | |
| 133 client_->NotifyError(bitstream_buffer_id, error); | |
| 134 client_ = nullptr; | |
| 135 } | |
| 136 } | |
| 137 | |
| 138 } // namespace content | |
| OLD | NEW |