Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(109)

Side by Side Diff: media/gpu/ipc/client/gpu_video_encode_accelerator_host.cc

Issue 2395913003: Cleanup of passing GpuMemoryBuffer backed video frames (Closed)
Patch Set: Rebase Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "media/gpu/ipc/client/gpu_video_encode_accelerator_host.h" 5 #include "media/gpu/ipc/client/gpu_video_encode_accelerator_host.h"
6 6
7 #include "base/location.h" 7 #include "base/location.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/threading/thread_task_runner_handle.h" 9 #include "base/threading/thread_task_runner_handle.h"
10 #include "gpu/ipc/client/gpu_channel_host.h" 10 #include "gpu/ipc/client/gpu_channel_host.h"
11 #include "media/base/video_frame.h" 11 #include "media/base/video_frame.h"
12 #include "media/gpu/gpu_video_accelerator_util.h" 12 #include "media/gpu/gpu_video_accelerator_util.h"
13 #include "media/gpu/ipc/common/media_messages.h" 13 #include "media/gpu/ipc/common/media_messages.h"
14 #include "media/video/video_encode_accelerator.h" 14 #include "media/video/video_encode_accelerator.h"
15 #include "ui/gfx/gpu_memory_buffer.h"
16 15
17 namespace media { 16 namespace media {
18 17
19 GpuVideoEncodeAcceleratorHost::GpuVideoEncodeAcceleratorHost( 18 GpuVideoEncodeAcceleratorHost::GpuVideoEncodeAcceleratorHost(
20 gpu::CommandBufferProxyImpl* impl) 19 gpu::CommandBufferProxyImpl* impl)
21 : channel_(impl->channel()), 20 : channel_(impl->channel()),
22 encoder_route_id_(MSG_ROUTING_NONE), 21 encoder_route_id_(MSG_ROUTING_NONE),
23 client_(nullptr), 22 client_(nullptr),
24 impl_(impl), 23 impl_(impl),
25 next_frame_id_(0), 24 next_frame_id_(0),
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 } 107 }
109 encoder_route_id_ = route_id; 108 encoder_route_id_ = route_id;
110 return true; 109 return true;
111 } 110 }
112 111
113 void GpuVideoEncodeAcceleratorHost::Encode( 112 void GpuVideoEncodeAcceleratorHost::Encode(
114 const scoped_refptr<VideoFrame>& frame, 113 const scoped_refptr<VideoFrame>& frame,
115 bool force_keyframe) { 114 bool force_keyframe) {
116 DCHECK(CalledOnValidThread()); 115 DCHECK(CalledOnValidThread());
117 DCHECK_EQ(PIXEL_FORMAT_I420, frame->format()); 116 DCHECK_EQ(PIXEL_FORMAT_I420, frame->format());
117 DCHECK_EQ(VideoFrame::STORAGE_SHMEM, frame->storage_type());
118 if (!channel_) 118 if (!channel_)
119 return; 119 return;
120 120
121 switch (frame->storage_type()) { 121 switch (frame->storage_type()) {
122 case VideoFrame::STORAGE_SHMEM: 122 case VideoFrame::STORAGE_SHMEM:
123 EncodeSharedMemoryFrame(frame, force_keyframe); 123 EncodeSharedMemoryFrame(frame, force_keyframe);
124 break; 124 break;
125 case VideoFrame::STORAGE_GPU_MEMORY_BUFFERS:
126 EncodeGpuMemoryBufferFrame(frame, force_keyframe);
127 break;
128 default: 125 default:
129 PostNotifyError(FROM_HERE, kPlatformFailureError, 126 PostNotifyError(FROM_HERE, kPlatformFailureError,
130 "Encode(): cannot encode frame with invalid handles"); 127 "Encode(): cannot encode frame with invalid handles");
131 return; 128 return;
132 } 129 }
133 130
134 frame_map_[next_frame_id_] = frame; 131 frame_map_[next_frame_id_] = frame;
135 132
136 // Mask against 30 bits, to avoid (undefined) wraparound on signed integer. 133 // Mask against 30 bits, to avoid (undefined) wraparound on signed integer.
137 next_frame_id_ = (next_frame_id_ + 1) & 0x3FFFFFFF; 134 next_frame_id_ = (next_frame_id_ + 1) & 0x3FFFFFFF;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 } 174 }
178 175
179 void GpuVideoEncodeAcceleratorHost::OnWillDeleteImpl() { 176 void GpuVideoEncodeAcceleratorHost::OnWillDeleteImpl() {
180 DCHECK(CalledOnValidThread()); 177 DCHECK(CalledOnValidThread());
181 impl_ = nullptr; 178 impl_ = nullptr;
182 179
183 // The gpu::CommandBufferProxyImpl is going away; error out this VEA. 180 // The gpu::CommandBufferProxyImpl is going away; error out this VEA.
184 OnChannelError(); 181 OnChannelError();
185 } 182 }
186 183
187 void GpuVideoEncodeAcceleratorHost::EncodeGpuMemoryBufferFrame(
188 const scoped_refptr<VideoFrame>& frame,
189 bool force_keyframe) {
190 DCHECK_EQ(VideoFrame::NumPlanes(PIXEL_FORMAT_I420),
191 frame->gpu_memory_buffer_handles().size());
192 AcceleratedVideoEncoderMsg_Encode_Params2 params;
193 params.frame_id = next_frame_id_;
194 params.timestamp = frame->timestamp();
195 bool requires_sync_point = false;
196 for (const auto& handle : frame->gpu_memory_buffer_handles()) {
197 gfx::GpuMemoryBufferHandle new_handle =
198 channel_->ShareGpuMemoryBufferToGpuProcess(handle,
199 &requires_sync_point);
200 if (new_handle.is_null()) {
201 PostNotifyError(FROM_HERE, kPlatformFailureError,
202 "EncodeGpuMemoryBufferFrame(): failed to share gpu "
203 "memory buffer handle for gpu process");
204 return;
205 }
206 params.gpu_memory_buffer_handles.push_back(new_handle);
207 }
208 params.size = frame->coded_size();
209 params.force_keyframe = force_keyframe;
210
211 Send(new AcceleratedVideoEncoderMsg_Encode2(encoder_route_id_, params));
212 }
213
214 void GpuVideoEncodeAcceleratorHost::EncodeSharedMemoryFrame( 184 void GpuVideoEncodeAcceleratorHost::EncodeSharedMemoryFrame(
215 const scoped_refptr<VideoFrame>& frame, 185 const scoped_refptr<VideoFrame>& frame,
216 bool force_keyframe) { 186 bool force_keyframe) {
217 if (!base::SharedMemory::IsHandleValid(frame->shared_memory_handle())) { 187 if (!base::SharedMemory::IsHandleValid(frame->shared_memory_handle())) {
218 PostNotifyError(FROM_HERE, kPlatformFailureError, 188 PostNotifyError(FROM_HERE, kPlatformFailureError,
219 "EncodeSharedMemory(): cannot encode frame with invalid " 189 "EncodeSharedMemory(): cannot encode frame with invalid "
220 "shared memory handle"); 190 "shared memory handle");
221 return; 191 return;
222 } 192 }
223 193
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 weak_this_factory_.InvalidateWeakPtrs(); 289 weak_this_factory_.InvalidateWeakPtrs();
320 290
321 // Client::NotifyError() may Destroy() |this|, so calling it needs to be the 291 // Client::NotifyError() may Destroy() |this|, so calling it needs to be the
322 // last thing done on this stack! 292 // last thing done on this stack!
323 VideoEncodeAccelerator::Client* client = nullptr; 293 VideoEncodeAccelerator::Client* client = nullptr;
324 std::swap(client_, client); 294 std::swap(client_, client);
325 client->NotifyError(error); 295 client->NotifyError(error);
326 } 296 }
327 297
328 } // namespace media 298 } // namespace media
OLDNEW
« no previous file with comments | « media/gpu/ipc/client/gpu_video_encode_accelerator_host.h ('k') | media/gpu/ipc/common/media_messages.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698