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 " |
Pawel Osciak
2015/09/30 08:15:15
We could probably fit these messages in 2 lines no
msu.koo
2015/09/30 08:18:46
Done.
| |
118 "encode frame with invalid shared " | 115 "encode frame with invalid shared " |
119 "memory handle"; | 116 "memory handle"; |
117 PostNotifyError(kPlatformFailureError); | |
120 return; | 118 return; |
121 } | 119 } |
122 | 120 |
123 AcceleratedVideoEncoderMsg_Encode_Params params; | 121 AcceleratedVideoEncoderMsg_Encode_Params params; |
124 params.frame_id = next_frame_id_; | 122 params.frame_id = next_frame_id_; |
125 params.buffer_handle = | 123 params.buffer_handle = |
126 channel_->ShareToGpuProcess(frame->shared_memory_handle()); | 124 channel_->ShareToGpuProcess(frame->shared_memory_handle()); |
127 if (!base::SharedMemory::IsHandleValid(params.buffer_handle)) { | 125 if (!base::SharedMemory::IsHandleValid(params.buffer_handle)) { |
128 NOTIFY_ERROR(kPlatformFailureError) << "EncodeSharedMemory(): failed to " | 126 DLOG(ERROR) << "EncodeSharedMemory(): failed to " |
129 "duplicate buffer handle for GPU " | 127 "duplicate buffer handle for GPU " |
130 "process"; | 128 "process"; |
129 PostNotifyError(kPlatformFailureError); | |
131 return; | 130 return; |
132 } | 131 } |
133 params.buffer_offset = | 132 params.buffer_offset = |
134 base::checked_cast<uint32_t>(frame->shared_memory_offset()); | 133 base::checked_cast<uint32_t>(frame->shared_memory_offset()); |
135 // We assume that planar frame data passed here is packed and contiguous. | 134 // We assume that planar frame data passed here is packed and contiguous. |
136 base::CheckedNumeric<uint32_t> buffer_size = 0u; | 135 base::CheckedNumeric<uint32_t> buffer_size = 0u; |
137 for (size_t i = 0; i < media::VideoFrame::NumPlanes(frame->format()); ++i) { | 136 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. | 137 // Cast DCHECK parameters to void* to avoid printing uint8* as a string. |
139 DCHECK_EQ( | 138 DCHECK_EQ( |
140 reinterpret_cast<void*>(frame->data(i)), | 139 reinterpret_cast<void*>(frame->data(i)), |
(...skipping 14 matching lines...) Expand all Loading... | |
155 | 154 |
156 void GpuVideoEncodeAcceleratorHost::UseOutputBitstreamBuffer( | 155 void GpuVideoEncodeAcceleratorHost::UseOutputBitstreamBuffer( |
157 const media::BitstreamBuffer& buffer) { | 156 const media::BitstreamBuffer& buffer) { |
158 DCHECK(CalledOnValidThread()); | 157 DCHECK(CalledOnValidThread()); |
159 if (!channel_) | 158 if (!channel_) |
160 return; | 159 return; |
161 | 160 |
162 base::SharedMemoryHandle handle = | 161 base::SharedMemoryHandle handle = |
163 channel_->ShareToGpuProcess(buffer.handle()); | 162 channel_->ShareToGpuProcess(buffer.handle()); |
164 if (!base::SharedMemory::IsHandleValid(handle)) { | 163 if (!base::SharedMemory::IsHandleValid(handle)) { |
165 NOTIFY_ERROR(kPlatformFailureError) | 164 |
Pawel Osciak
2015/09/30 08:15:15
Please remove this empty line.
msu.koo
2015/09/30 08:18:46
Done.
| |
165 DLOG(ERROR) | |
166 << "UseOutputBitstreamBuffer(): failed to duplicate buffer handle " | 166 << "UseOutputBitstreamBuffer(): failed to duplicate buffer handle " |
167 "for GPU process: buffer.id()=" << buffer.id(); | 167 "for GPU process: buffer.id()=" << buffer.id(); |
168 PostNotifyError(kPlatformFailureError); | |
168 return; | 169 return; |
169 } | 170 } |
170 Send(new AcceleratedVideoEncoderMsg_UseOutputBitstreamBuffer( | 171 Send(new AcceleratedVideoEncoderMsg_UseOutputBitstreamBuffer( |
171 encoder_route_id_, buffer.id(), handle, buffer.size())); | 172 encoder_route_id_, buffer.id(), handle, buffer.size())); |
172 } | 173 } |
173 | 174 |
174 void GpuVideoEncodeAcceleratorHost::RequestEncodingParametersChange( | 175 void GpuVideoEncodeAcceleratorHost::RequestEncodingParametersChange( |
175 uint32 bitrate, | 176 uint32 bitrate, |
176 uint32 framerate) { | 177 uint32 framerate) { |
177 DCHECK(CalledOnValidThread()); | 178 DCHECK(CalledOnValidThread()); |
(...skipping 26 matching lines...) Expand all Loading... | |
204 // Post the error notification back to this thread, to avoid re-entrancy. | 205 // Post the error notification back to this thread, to avoid re-entrancy. |
205 base::ThreadTaskRunnerHandle::Get()->PostTask( | 206 base::ThreadTaskRunnerHandle::Get()->PostTask( |
206 FROM_HERE, base::Bind(&GpuVideoEncodeAcceleratorHost::OnNotifyError, | 207 FROM_HERE, base::Bind(&GpuVideoEncodeAcceleratorHost::OnNotifyError, |
207 weak_this_factory_.GetWeakPtr(), error)); | 208 weak_this_factory_.GetWeakPtr(), error)); |
208 } | 209 } |
209 | 210 |
210 void GpuVideoEncodeAcceleratorHost::Send(IPC::Message* message) { | 211 void GpuVideoEncodeAcceleratorHost::Send(IPC::Message* message) { |
211 DCHECK(CalledOnValidThread()); | 212 DCHECK(CalledOnValidThread()); |
212 uint32 message_type = message->type(); | 213 uint32 message_type = message->type(); |
213 if (!channel_->Send(message)) { | 214 if (!channel_->Send(message)) { |
214 NOTIFY_ERROR(kPlatformFailureError) << "Send(" << message_type | 215 DLOG(ERROR) << "Send(" << message_type << ") failed"; |
215 << ") failed"; | 216 PostNotifyError(kPlatformFailureError); |
216 } | 217 } |
217 } | 218 } |
218 | 219 |
219 void GpuVideoEncodeAcceleratorHost::OnRequireBitstreamBuffers( | 220 void GpuVideoEncodeAcceleratorHost::OnRequireBitstreamBuffers( |
220 uint32 input_count, | 221 uint32 input_count, |
221 const gfx::Size& input_coded_size, | 222 const gfx::Size& input_coded_size, |
222 uint32 output_buffer_size) { | 223 uint32 output_buffer_size) { |
223 DCHECK(CalledOnValidThread()); | 224 DCHECK(CalledOnValidThread()); |
224 DVLOG(2) << "OnRequireBitstreamBuffers(): input_count=" << input_count | 225 DVLOG(2) << "OnRequireBitstreamBuffers(): input_count=" << input_count |
225 << ", input_coded_size=" << input_coded_size.ToString() | 226 << ", 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(); | 272 weak_this_factory_.InvalidateWeakPtrs(); |
272 | 273 |
273 // Client::NotifyError() may Destroy() |this|, so calling it needs to be the | 274 // Client::NotifyError() may Destroy() |this|, so calling it needs to be the |
274 // last thing done on this stack! | 275 // last thing done on this stack! |
275 media::VideoEncodeAccelerator::Client* client = NULL; | 276 media::VideoEncodeAccelerator::Client* client = NULL; |
276 std::swap(client_, client); | 277 std::swap(client_, client); |
277 client->NotifyError(error); | 278 client->NotifyError(error); |
278 } | 279 } |
279 | 280 |
280 } // namespace content | 281 } // namespace content |
OLD | NEW |