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" |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
110 return true; | 110 return true; |
111 } | 111 } |
112 | 112 |
113 void GpuVideoEncodeAcceleratorHost::Encode( | 113 void GpuVideoEncodeAcceleratorHost::Encode( |
114 const scoped_refptr<media::VideoFrame>& frame, | 114 const scoped_refptr<media::VideoFrame>& frame, |
115 bool force_keyframe) { | 115 bool force_keyframe) { |
116 DCHECK(CalledOnValidThread()); | 116 DCHECK(CalledOnValidThread()); |
117 if (!channel_) | 117 if (!channel_) |
118 return; | 118 return; |
119 | 119 |
120 if (!base::SharedMemory::IsHandleValid(frame->shared_memory_handle())) { | 120 bool rv = false; |
mcasas
2015/06/04 15:20:55
s/rv/return_val/ or similar?
emircan
2015/06/04 22:04:40
Done.
| |
121 NOTIFY_ERROR(kPlatformFailureError) | 121 if (frame->storage_type() == media::VideoFrame::STORAGE_TEXTURE) |
122 << "Encode(): cannot encode frame not backed by shared memory"; | 122 rv = EncodeNativeTexture(frame, force_keyframe); |
123 return; | 123 else |
124 } | 124 rv = EncodeSharedMemory(frame, force_keyframe); |
mcasas
2015/06/04 15:20:55
What about
const bool encoded_ok = (frame->IsMapp
emircan
2015/06/04 22:04:40
IsMappable() covers STORAGE_OWNED_MEMORY and STORA
| |
125 base::SharedMemoryHandle handle = | 125 |
126 channel_->ShareToGpuProcess(frame->shared_memory_handle()); | 126 if (!rv) { |
127 if (!base::SharedMemory::IsHandleValid(handle)) { | 127 NOTIFY_ERROR(kPlatformFailureError) << "Encode(): cannot encode frame"; |
128 NOTIFY_ERROR(kPlatformFailureError) | |
129 << "Encode(): failed to duplicate buffer handle for GPU process"; | |
130 return; | 128 return; |
131 } | 129 } |
132 | 130 |
133 // We assume that planar frame data passed here is packed and contiguous. | |
134 const size_t plane_count = media::VideoFrame::NumPlanes(frame->format()); | |
135 size_t frame_size = 0; | |
136 for (size_t i = 0; i < plane_count; ++i) { | |
137 // Cast DCHECK parameters to void* to avoid printing uint8* as a string. | |
138 DCHECK_EQ(reinterpret_cast<void*>(frame->data(i)), | |
139 reinterpret_cast<void*>((frame->data(0) + frame_size))) | |
140 << "plane=" << i; | |
141 frame_size += frame->stride(i) * frame->rows(i); | |
142 } | |
143 | |
144 Send(new AcceleratedVideoEncoderMsg_Encode( | |
145 encoder_route_id_, next_frame_id_, handle, frame->shared_memory_offset(), | |
146 frame_size, force_keyframe)); | |
147 frame_map_[next_frame_id_] = frame; | 131 frame_map_[next_frame_id_] = frame; |
148 | 132 |
149 // Mask against 30 bits, to avoid (undefined) wraparound on signed integer. | 133 // Mask against 30 bits, to avoid (undefined) wraparound on signed integer. |
150 next_frame_id_ = (next_frame_id_ + 1) & 0x3FFFFFFF; | 134 next_frame_id_ = (next_frame_id_ + 1) & 0x3FFFFFFF; |
151 } | 135 } |
152 | 136 |
153 void GpuVideoEncodeAcceleratorHost::UseOutputBitstreamBuffer( | 137 void GpuVideoEncodeAcceleratorHost::UseOutputBitstreamBuffer( |
154 const media::BitstreamBuffer& buffer) { | 138 const media::BitstreamBuffer& buffer) { |
155 DCHECK(CalledOnValidThread()); | 139 DCHECK(CalledOnValidThread()); |
156 if (!channel_) | 140 if (!channel_) |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
188 } | 172 } |
189 | 173 |
190 void GpuVideoEncodeAcceleratorHost::OnWillDeleteImpl() { | 174 void GpuVideoEncodeAcceleratorHost::OnWillDeleteImpl() { |
191 DCHECK(CalledOnValidThread()); | 175 DCHECK(CalledOnValidThread()); |
192 impl_ = NULL; | 176 impl_ = NULL; |
193 | 177 |
194 // The CommandBufferProxyImpl is going away; error out this VEA. | 178 // The CommandBufferProxyImpl is going away; error out this VEA. |
195 OnChannelError(); | 179 OnChannelError(); |
196 } | 180 } |
197 | 181 |
182 bool GpuVideoEncodeAcceleratorHost::EncodeNativeTexture( | |
183 const scoped_refptr<media::VideoFrame>& frame, | |
184 bool force_keyframe) { | |
185 Send(new AcceleratedVideoEncoderMsg_EncodeNativeTexture( | |
mcasas
2015/06/04 15:20:55
DCHECK_EQ(frame->storage_type(), STORAGE_TEXTURE)
emircan
2015/06/04 22:04:40
Correct. Passing only the mailbox.
| |
186 encoder_route_id_, next_frame_id_, frame->mailbox_holder(0), | |
187 force_keyframe)); | |
188 return true; | |
189 } | |
190 | |
191 bool GpuVideoEncodeAcceleratorHost::EncodeSharedMemory( | |
192 const scoped_refptr<media::VideoFrame>& frame, | |
193 bool force_keyframe) { | |
194 if (!base::SharedMemory::IsHandleValid(frame->shared_memory_handle())) { | |
mcasas
2015/06/04 15:20:55
DCHECK_EQ(frame->storage_type(), STORAGE_SHMEM)?
A
emircan
2015/06/04 22:04:40
Done.
| |
195 NOTIFY_ERROR(kPlatformFailureError) << "EncodeSharedMemory(): cannot " | |
196 "encode frame with invalid shared " | |
197 "memory handle"; | |
198 return false; | |
199 } | |
200 base::SharedMemoryHandle handle = | |
201 channel_->ShareToGpuProcess(frame->shared_memory_handle()); | |
202 if (!base::SharedMemory::IsHandleValid(handle)) { | |
203 NOTIFY_ERROR(kPlatformFailureError) << "EncodeSharedMemory(): failed to " | |
204 "duplicate buffer handle for GPU " | |
205 "process"; | |
206 return false; | |
207 } | |
208 | |
209 // We assume that planar frame data passed here is packed and contiguous. | |
210 const size_t plane_count = media::VideoFrame::NumPlanes(frame->format()); | |
211 size_t frame_size = 0; | |
212 for (size_t i = 0; i < plane_count; ++i) { | |
213 // Cast DCHECK parameters to void* to avoid printing uint8* as a string. | |
214 DCHECK_EQ(reinterpret_cast<void*>(frame->data(i)), | |
215 reinterpret_cast<void*>((frame->data(0) + frame_size))) | |
216 << "plane=" << i; | |
217 frame_size += frame->stride(i) * frame->rows(i); | |
218 } | |
219 | |
220 Send(new AcceleratedVideoEncoderMsg_EncodeSharedMemory( | |
221 encoder_route_id_, next_frame_id_, handle, | |
222 frame->shared_memory_offset(), frame_size, force_keyframe)); | |
223 return true; | |
224 } | |
225 | |
198 void GpuVideoEncodeAcceleratorHost::PostNotifyError(Error error) { | 226 void GpuVideoEncodeAcceleratorHost::PostNotifyError(Error error) { |
199 DCHECK(CalledOnValidThread()); | 227 DCHECK(CalledOnValidThread()); |
200 DVLOG(2) << "PostNotifyError(): error=" << error; | 228 DVLOG(2) << "PostNotifyError(): error=" << error; |
201 // Post the error notification back to this thread, to avoid re-entrancy. | 229 // Post the error notification back to this thread, to avoid re-entrancy. |
202 base::ThreadTaskRunnerHandle::Get()->PostTask( | 230 base::ThreadTaskRunnerHandle::Get()->PostTask( |
203 FROM_HERE, base::Bind(&GpuVideoEncodeAcceleratorHost::OnNotifyError, | 231 FROM_HERE, base::Bind(&GpuVideoEncodeAcceleratorHost::OnNotifyError, |
204 weak_this_factory_.GetWeakPtr(), error)); | 232 weak_this_factory_.GetWeakPtr(), error)); |
205 } | 233 } |
206 | 234 |
207 void GpuVideoEncodeAcceleratorHost::Send(IPC::Message* message) { | 235 void GpuVideoEncodeAcceleratorHost::Send(IPC::Message* message) { |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
268 weak_this_factory_.InvalidateWeakPtrs(); | 296 weak_this_factory_.InvalidateWeakPtrs(); |
269 | 297 |
270 // Client::NotifyError() may Destroy() |this|, so calling it needs to be the | 298 // Client::NotifyError() may Destroy() |this|, so calling it needs to be the |
271 // last thing done on this stack! | 299 // last thing done on this stack! |
272 media::VideoEncodeAccelerator::Client* client = NULL; | 300 media::VideoEncodeAccelerator::Client* client = NULL; |
273 std::swap(client_, client); | 301 std::swap(client_, client); |
274 client->NotifyError(error); | 302 client->NotifyError(error); |
275 } | 303 } |
276 | 304 |
277 } // namespace content | 305 } // namespace content |
OLD | NEW |