OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/common/gpu/client/gpu_video_encode_accelerator_host.h" | 5 #include "content/common/gpu/client/gpu_video_encode_accelerator_host.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "content/common/gpu/client/gpu_channel_host.h" | 8 #include "content/common/gpu/client/gpu_channel_host.h" |
9 #include "content/common/gpu/gpu_messages.h" | 9 #include "content/common/gpu/gpu_messages.h" |
10 #include "content/common/gpu/media/gpu_video_accelerator_util.h" | 10 #include "content/common/gpu/media/gpu_video_accelerator_util.h" |
11 #include "media/base/video_frame.h" | 11 #include "media/base/video_frame.h" |
12 | 12 |
13 namespace content { | 13 namespace content { |
14 | 14 |
15 #define NOTIFY_ERROR(error) \ | |
16 PostNotifyError(error); \ | |
17 DLOG(ERROR) | |
18 | |
19 GpuVideoEncodeAcceleratorHost::GpuVideoEncodeAcceleratorHost( | 15 GpuVideoEncodeAcceleratorHost::GpuVideoEncodeAcceleratorHost( |
20 GpuChannelHost* channel, | 16 GpuChannelHost* channel, |
21 CommandBufferProxyImpl* impl) | 17 CommandBufferProxyImpl* impl) |
22 : channel_(channel), | 18 : channel_(channel), |
23 encoder_route_id_(MSG_ROUTING_NONE), | 19 encoder_route_id_(MSG_ROUTING_NONE), |
24 client_(NULL), | 20 client_(NULL), |
25 impl_(impl), | 21 impl_(impl), |
26 next_frame_id_(0), | 22 next_frame_id_(0), |
27 weak_this_factory_(this) { | 23 weak_this_factory_(this) { |
28 DCHECK(channel_); | 24 DCHECK(channel_); |
(...skipping 29 matching lines...) Expand all Loading... | |
58 return handled; | 54 return handled; |
59 } | 55 } |
60 | 56 |
61 void GpuVideoEncodeAcceleratorHost::OnChannelError() { | 57 void GpuVideoEncodeAcceleratorHost::OnChannelError() { |
62 DCHECK(CalledOnValidThread()); | 58 DCHECK(CalledOnValidThread()); |
63 if (channel_) { | 59 if (channel_) { |
64 if (encoder_route_id_ != MSG_ROUTING_NONE) | 60 if (encoder_route_id_ != MSG_ROUTING_NONE) |
65 channel_->RemoveRoute(encoder_route_id_); | 61 channel_->RemoveRoute(encoder_route_id_); |
66 channel_ = NULL; | 62 channel_ = NULL; |
67 } | 63 } |
68 NOTIFY_ERROR(kPlatformFailureError) << "OnChannelError()"; | 64 DLOG(ERROR) << "OnChannelError()"; |
65 PostNotifyError(kPlatformFailureError); | |
69 } | 66 } |
70 | 67 |
71 media::VideoEncodeAccelerator::SupportedProfiles | 68 media::VideoEncodeAccelerator::SupportedProfiles |
72 GpuVideoEncodeAcceleratorHost::GetSupportedProfiles() { | 69 GpuVideoEncodeAcceleratorHost::GetSupportedProfiles() { |
73 DCHECK(CalledOnValidThread()); | 70 DCHECK(CalledOnValidThread()); |
74 if (!channel_) | 71 if (!channel_) |
75 return media::VideoEncodeAccelerator::SupportedProfiles(); | 72 return media::VideoEncodeAccelerator::SupportedProfiles(); |
76 return GpuVideoAcceleratorUtil::ConvertGpuToMediaEncodeProfiles( | 73 return GpuVideoAcceleratorUtil::ConvertGpuToMediaEncodeProfiles( |
77 channel_->gpu_info().video_encode_accelerator_supported_profiles); | 74 channel_->gpu_info().video_encode_accelerator_supported_profiles); |
78 } | 75 } |
(...skipping 28 matching lines...) Expand all Loading... | |
107 } | 104 } |
108 | 105 |
109 void GpuVideoEncodeAcceleratorHost::Encode( | 106 void GpuVideoEncodeAcceleratorHost::Encode( |
110 const scoped_refptr<media::VideoFrame>& frame, | 107 const scoped_refptr<media::VideoFrame>& frame, |
111 bool force_keyframe) { | 108 bool force_keyframe) { |
112 DCHECK(CalledOnValidThread()); | 109 DCHECK(CalledOnValidThread()); |
113 if (!channel_) | 110 if (!channel_) |
114 return; | 111 return; |
115 | 112 |
116 if (!base::SharedMemory::IsHandleValid(frame->shared_memory_handle())) { | 113 if (!base::SharedMemory::IsHandleValid(frame->shared_memory_handle())) { |
117 NOTIFY_ERROR(kPlatformFailureError) << "EncodeSharedMemory(): cannot " | 114 DLOG(ERROR) << "EncodeSharedMemory(): cannot encode frame with " |
118 "encode frame with invalid shared " | 115 "invalid shared memory handle"; |
119 "memory handle"; | 116 PostNotifyError(kPlatformFailureError); |
120 return; | 117 return; |
121 } | 118 } |
122 | 119 |
123 AcceleratedVideoEncoderMsg_Encode_Params params; | 120 AcceleratedVideoEncoderMsg_Encode_Params params; |
124 params.frame_id = next_frame_id_; | 121 params.frame_id = next_frame_id_; |
125 params.buffer_handle = | 122 params.buffer_handle = |
126 channel_->ShareToGpuProcess(frame->shared_memory_handle()); | 123 channel_->ShareToGpuProcess(frame->shared_memory_handle()); |
127 if (!base::SharedMemory::IsHandleValid(params.buffer_handle)) { | 124 if (!base::SharedMemory::IsHandleValid(params.buffer_handle)) { |
128 NOTIFY_ERROR(kPlatformFailureError) << "EncodeSharedMemory(): failed to " | 125 DLOG(ERROR) << "EncodeSharedMemory(): failed to duplicate buffer handle " |
129 "duplicate buffer handle for GPU " | 126 "for GPU process"; |
130 "process"; | 127 PostNotifyError(kPlatformFailureError); |
131 return; | 128 return; |
132 } | 129 } |
133 params.buffer_offset = | 130 params.buffer_offset = |
134 base::checked_cast<uint32_t>(frame->shared_memory_offset()); | 131 base::checked_cast<uint32_t>(frame->shared_memory_offset()); |
135 // We assume that planar frame data passed here is packed and contiguous. | 132 // We assume that planar frame data passed here is packed and contiguous. |
136 base::CheckedNumeric<uint32_t> buffer_size = 0u; | 133 base::CheckedNumeric<uint32_t> buffer_size = 0u; |
137 for (size_t i = 0; i < media::VideoFrame::NumPlanes(frame->format()); ++i) { | 134 for (size_t i = 0; i < media::VideoFrame::NumPlanes(frame->format()); ++i) { |
138 // Cast DCHECK parameters to void* to avoid printing uint8* as a string. | 135 // Cast DCHECK parameters to void* to avoid printing uint8* as a string. |
139 DCHECK_EQ( | 136 DCHECK_EQ( |
140 reinterpret_cast<void*>(frame->data(i)), | 137 reinterpret_cast<void*>(frame->data(i)), |
(...skipping 14 matching lines...) Expand all Loading... | |
155 | 152 |
156 void GpuVideoEncodeAcceleratorHost::UseOutputBitstreamBuffer( | 153 void GpuVideoEncodeAcceleratorHost::UseOutputBitstreamBuffer( |
157 const media::BitstreamBuffer& buffer) { | 154 const media::BitstreamBuffer& buffer) { |
158 DCHECK(CalledOnValidThread()); | 155 DCHECK(CalledOnValidThread()); |
159 if (!channel_) | 156 if (!channel_) |
160 return; | 157 return; |
161 | 158 |
162 base::SharedMemoryHandle handle = | 159 base::SharedMemoryHandle handle = |
163 channel_->ShareToGpuProcess(buffer.handle()); | 160 channel_->ShareToGpuProcess(buffer.handle()); |
164 if (!base::SharedMemory::IsHandleValid(handle)) { | 161 if (!base::SharedMemory::IsHandleValid(handle)) { |
165 NOTIFY_ERROR(kPlatformFailureError) | 162 DLOG(ERROR) << "UseOutputBitstreamBuffer(): failed to duplicate " |
166 << "UseOutputBitstreamBuffer(): failed to duplicate buffer handle " | 163 "buffer handle for GPU process: buffer.id()=" << buffer.id(); |
167 "for GPU process: buffer.id()=" << buffer.id(); | 164 PostNotifyError(kPlatformFailureError); |
168 return; | 165 return; |
169 } | 166 } |
170 Send(new AcceleratedVideoEncoderMsg_UseOutputBitstreamBuffer( | 167 Send(new AcceleratedVideoEncoderMsg_UseOutputBitstreamBuffer( |
171 encoder_route_id_, buffer.id(), handle, buffer.size())); | 168 encoder_route_id_, buffer.id(), handle, buffer.size())); |
172 } | 169 } |
173 | 170 |
174 void GpuVideoEncodeAcceleratorHost::RequestEncodingParametersChange( | 171 void GpuVideoEncodeAcceleratorHost::RequestEncodingParametersChange( |
175 uint32 bitrate, | 172 uint32 bitrate, |
176 uint32 framerate) { | 173 uint32 framerate) { |
177 DCHECK(CalledOnValidThread()); | 174 DCHECK(CalledOnValidThread()); |
(...skipping 26 matching lines...) Expand all Loading... | |
204 // Post the error notification back to this thread, to avoid re-entrancy. | 201 // Post the error notification back to this thread, to avoid re-entrancy. |
205 base::ThreadTaskRunnerHandle::Get()->PostTask( | 202 base::ThreadTaskRunnerHandle::Get()->PostTask( |
206 FROM_HERE, base::Bind(&GpuVideoEncodeAcceleratorHost::OnNotifyError, | 203 FROM_HERE, base::Bind(&GpuVideoEncodeAcceleratorHost::OnNotifyError, |
207 weak_this_factory_.GetWeakPtr(), error)); | 204 weak_this_factory_.GetWeakPtr(), error)); |
208 } | 205 } |
209 | 206 |
210 void GpuVideoEncodeAcceleratorHost::Send(IPC::Message* message) { | 207 void GpuVideoEncodeAcceleratorHost::Send(IPC::Message* message) { |
211 DCHECK(CalledOnValidThread()); | 208 DCHECK(CalledOnValidThread()); |
212 uint32 message_type = message->type(); | 209 uint32 message_type = message->type(); |
213 if (!channel_->Send(message)) { | 210 if (!channel_->Send(message)) { |
214 NOTIFY_ERROR(kPlatformFailureError) << "Send(" << message_type | 211 DLOG(ERROR) << "Send(" << message_type << ") failed"; |
215 << ") failed"; | 212 PostNotifyError(kPlatformFailureError); |
mcasas
2015/09/30 15:32:07
It's unfortunate that PostNotifyError(bla) is also
msu.koo
2015/10/01 04:22:13
DLOG comes with line number and file name. If we c
mcasas
2015/10/05 16:18:48
Yeah leaving the DLOG(ERROR) sounds logical,
but
| |
216 } | 213 } |
217 } | 214 } |
218 | 215 |
219 void GpuVideoEncodeAcceleratorHost::OnRequireBitstreamBuffers( | 216 void GpuVideoEncodeAcceleratorHost::OnRequireBitstreamBuffers( |
220 uint32 input_count, | 217 uint32 input_count, |
221 const gfx::Size& input_coded_size, | 218 const gfx::Size& input_coded_size, |
222 uint32 output_buffer_size) { | 219 uint32 output_buffer_size) { |
223 DCHECK(CalledOnValidThread()); | 220 DCHECK(CalledOnValidThread()); |
224 DVLOG(2) << "OnRequireBitstreamBuffers(): input_count=" << input_count | 221 DVLOG(2) << "OnRequireBitstreamBuffers(): input_count=" << input_count |
225 << ", input_coded_size=" << input_coded_size.ToString() | 222 << ", input_coded_size=" << input_coded_size.ToString() |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
271 weak_this_factory_.InvalidateWeakPtrs(); | 268 weak_this_factory_.InvalidateWeakPtrs(); |
272 | 269 |
273 // Client::NotifyError() may Destroy() |this|, so calling it needs to be the | 270 // Client::NotifyError() may Destroy() |this|, so calling it needs to be the |
274 // last thing done on this stack! | 271 // last thing done on this stack! |
275 media::VideoEncodeAccelerator::Client* client = NULL; | 272 media::VideoEncodeAccelerator::Client* client = NULL; |
276 std::swap(client_, client); | 273 std::swap(client_, client); |
277 client->NotifyError(error); | 274 client->NotifyError(error); |
278 } | 275 } |
279 | 276 |
280 } // namespace content | 277 } // namespace content |
OLD | NEW |