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

Side by Side Diff: media/gpu/ipc/service/gpu_video_encode_accelerator.cc

Issue 2251993004: media/.../{android_,gpu_}video_encode_accelerator{,_host} cleanup (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 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/service/gpu_video_encode_accelerator.h" 5 #include "media/gpu/ipc/service/gpu_video_encode_accelerator.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 25 matching lines...) Expand all
36 #elif defined(OS_MACOSX) 36 #elif defined(OS_MACOSX)
37 #include "media/gpu/vt_video_encode_accelerator_mac.h" 37 #include "media/gpu/vt_video_encode_accelerator_mac.h"
38 #elif defined(OS_WIN) 38 #elif defined(OS_WIN)
39 #include "base/feature_list.h" 39 #include "base/feature_list.h"
40 #include "media/base/media_switches.h" 40 #include "media/base/media_switches.h"
41 #include "media/gpu/media_foundation_video_encode_accelerator_win.h" 41 #include "media/gpu/media_foundation_video_encode_accelerator_win.h"
42 #endif 42 #endif
43 43
44 namespace media { 44 namespace media {
45 45
46 namespace {
watk 2016/08/18 18:12:15 I don't think it's in the style guide but we usual
mcasas 2016/08/18 19:24:40 oops, done
46 static bool MakeDecoderContextCurrent( 47 static bool MakeDecoderContextCurrent(
watk 2016/08/18 18:12:15 Remove static on this one and all below.
mcasas 2016/08/18 19:24:40 Done.
47 const base::WeakPtr<gpu::GpuCommandBufferStub> stub) { 48 const base::WeakPtr<gpu::GpuCommandBufferStub> stub) {
48 if (!stub) { 49 if (!stub) {
49 DLOG(ERROR) << "Stub is gone; won't MakeCurrent()."; 50 DLOG(ERROR) << "Stub is gone; won't MakeCurrent().";
50 return false; 51 return false;
51 } 52 }
52 53
53 if (!stub->decoder()->MakeCurrent()) { 54 if (!stub->decoder()->MakeCurrent()) {
54 DLOG(ERROR) << "Failed to MakeCurrent()"; 55 DLOG(ERROR) << "Failed to MakeCurrent()";
55 return false; 56 return false;
56 } 57 }
57 58
58 return true; 59 return true;
59 } 60 }
60 61
62 #if defined(OS_CHROMEOS) && defined(USE_V4L2_CODEC)
63 static std::unique_ptr<VideoEncodeAccelerator> CreateV4L2VEA() {
64 std::unique_ptr<VideoEncodeAccelerator> encoder;
65 scoped_refptr<V4L2Device> device = V4L2Device::Create(V4L2Device::kEncoder);
66 if (device)
67 encoder.reset(new V4L2VideoEncodeAccelerator(device));
watk 2016/08/18 18:12:15 If you feel like doing some extra cleanup :) You c
mcasas 2016/08/18 19:24:40 Tried but it wouldn't work: ../../media/gpu/ipc/se
watk 2016/08/18 20:13:15 Ah my bad
68 return encoder;
69 }
70 #endif
71
72 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY)
73 static std::unique_ptr<VideoEncodeAccelerator> CreateVaapiVEA() {
74 return base::WrapUnique<VideoEncodeAccelerator>(
75 new VaapiVideoEncodeAccelerator());
76 }
77 #endif
78
79 #if defined(OS_ANDROID) && defined(ENABLE_WEBRTC)
80 static std::unique_ptr<VideoEncodeAccelerator> CreateAndroidVEA() {
81 return base::WrapUnique<VideoEncodeAccelerator>(
82 new AndroidVideoEncodeAccelerator());
83 }
84 #endif
85
86 #if defined(OS_MACOSX)
87 static std::unique_ptr<VideoEncodeAccelerator> CreateVTVEA() {
88 return base::WrapUnique<VideoEncodeAccelerator>(
89 new VTVideoEncodeAccelerator());
90 }
91 #endif
92
93 #if defined(OS_WIN)
94 static std::unique_ptr<VideoEncodeAccelerator> CreateMediaFoundationVEA() {
95 return base::WrapUnique<media::VideoEncodeAccelerator>(
96 new MediaFoundationVideoEncodeAccelerator());
97 }
98 #endif
99
100 } // anonymous namespace
101
61 GpuVideoEncodeAccelerator::GpuVideoEncodeAccelerator( 102 GpuVideoEncodeAccelerator::GpuVideoEncodeAccelerator(
62 int32_t host_route_id, 103 int32_t host_route_id,
63 gpu::GpuCommandBufferStub* stub) 104 gpu::GpuCommandBufferStub* stub)
64 : host_route_id_(host_route_id), 105 : host_route_id_(host_route_id),
65 stub_(stub), 106 stub_(stub),
66 input_format_(PIXEL_FORMAT_UNKNOWN), 107 input_format_(PIXEL_FORMAT_UNKNOWN),
67 output_buffer_size_(0), 108 output_buffer_size_(0),
68 weak_this_factory_(this) { 109 weak_this_factory_(this) {
69 stub_->AddDestructionObserver(this); 110 stub_->AddDestructionObserver(this);
70 make_context_current_ = 111 make_context_current_ =
71 base::Bind(&MakeDecoderContextCurrent, stub_->AsWeakPtr()); 112 base::Bind(&MakeDecoderContextCurrent, stub_->AsWeakPtr());
72 } 113 }
73 114
74 GpuVideoEncodeAccelerator::~GpuVideoEncodeAccelerator() { 115 GpuVideoEncodeAccelerator::~GpuVideoEncodeAccelerator() {
75 // This class can only be self-deleted from OnWillDestroyStub(), which means 116 // This class can only be self-deleted from OnWillDestroyStub(), which means
76 // the VEA has already been destroyed in there. 117 // the VEA has already been destroyed in there.
77 DCHECK(!encoder_); 118 DCHECK(!encoder_);
78 } 119 }
79 120
80 bool GpuVideoEncodeAccelerator::Initialize(VideoPixelFormat input_format, 121 bool GpuVideoEncodeAccelerator::Initialize(VideoPixelFormat input_format,
81 const gfx::Size& input_visible_size, 122 const gfx::Size& input_visible_size,
82 VideoCodecProfile output_profile, 123 VideoCodecProfile output_profile,
83 uint32_t initial_bitrate) { 124 uint32_t initial_bitrate) {
84 DVLOG(2) << "GpuVideoEncodeAccelerator::Initialize(): " 125 DVLOG(1) << __FUNCTION__
85 << "input_format=" << input_format 126 << " input_format=" << VideoPixelFormatToString(input_format)
86 << ", input_visible_size=" << input_visible_size.ToString() 127 << ", input_visible_size=" << input_visible_size.ToString()
87 << ", output_profile=" << output_profile 128 << ", output_profile=" << GetProfileName(output_profile)
88 << ", initial_bitrate=" << initial_bitrate; 129 << ", initial_bitrate=" << initial_bitrate;
89 DCHECK(!encoder_); 130 DCHECK(!encoder_);
90 131
91 if (!stub_->channel()->AddRoute(host_route_id_, stub_->stream_id(), this)) { 132 if (!stub_->channel()->AddRoute(host_route_id_, stub_->stream_id(), this)) {
92 DLOG(ERROR) << "GpuVideoEncodeAccelerator::Initialize(): " 133 DLOG(ERROR) << __FUNCTION__ << " failed to add route";
93 "failed to add route";
94 return false; 134 return false;
95 } 135 }
96 136
97 if (input_visible_size.width() > limits::kMaxDimension || 137 if (input_visible_size.width() > limits::kMaxDimension ||
98 input_visible_size.height() > limits::kMaxDimension || 138 input_visible_size.height() > limits::kMaxDimension ||
99 input_visible_size.GetArea() > limits::kMaxCanvas) { 139 input_visible_size.GetArea() > limits::kMaxCanvas) {
100 DLOG(ERROR) << "GpuVideoEncodeAccelerator::Initialize(): " 140 DLOG(ERROR) << __FUNCTION__ << "too large input_visible_size "
101 << "input_visible_size " << input_visible_size.ToString() 141 << input_visible_size.ToString();
102 << " too large";
103 return false; 142 return false;
104 } 143 }
105 144
106 const gpu::GpuPreferences& gpu_preferences = 145 const gpu::GpuPreferences& gpu_preferences =
107 stub_->channel()->gpu_channel_manager()->gpu_preferences(); 146 stub_->channel()->gpu_channel_manager()->gpu_preferences();
108 147
109 std::vector<GpuVideoEncodeAccelerator::CreateVEAFp> create_vea_fps =
110 CreateVEAFps(gpu_preferences);
111 // Try all possible encoders and use the first successful encoder. 148 // Try all possible encoders and use the first successful encoder.
112 for (size_t i = 0; i < create_vea_fps.size(); ++i) { 149 for (const auto& vea_factory_method : GetVEAFactoryMethods(gpu_preferences)) {
113 encoder_ = (*create_vea_fps[i])(); 150 encoder_ = vea_factory_method.Run();
114 if (encoder_ && 151 if (encoder_ &&
115 encoder_->Initialize(input_format, input_visible_size, output_profile, 152 encoder_->Initialize(input_format, input_visible_size, output_profile,
116 initial_bitrate, this)) { 153 initial_bitrate, this)) {
117 input_format_ = input_format; 154 input_format_ = input_format;
118 input_visible_size_ = input_visible_size; 155 input_visible_size_ = input_visible_size;
119 return true; 156 return true;
120 } 157 }
121 } 158 }
122 encoder_.reset(); 159 encoder_.reset();
123 DLOG(ERROR) 160 DLOG(ERROR) << __FUNCTION__ << " VEA initialization failed";
124 << "GpuVideoEncodeAccelerator::Initialize(): VEA initialization failed";
125 return false; 161 return false;
126 } 162 }
127 163
128 bool GpuVideoEncodeAccelerator::OnMessageReceived(const IPC::Message& message) { 164 bool GpuVideoEncodeAccelerator::OnMessageReceived(const IPC::Message& message) {
129 bool handled = true; 165 bool handled = true;
130 IPC_BEGIN_MESSAGE_MAP(GpuVideoEncodeAccelerator, message) 166 IPC_BEGIN_MESSAGE_MAP(GpuVideoEncodeAccelerator, message)
131 IPC_MESSAGE_HANDLER(AcceleratedVideoEncoderMsg_Encode, OnEncode) 167 IPC_MESSAGE_HANDLER(AcceleratedVideoEncoderMsg_Encode, OnEncode)
132 IPC_MESSAGE_HANDLER(AcceleratedVideoEncoderMsg_Encode2, OnEncode2) 168 IPC_MESSAGE_HANDLER(AcceleratedVideoEncoderMsg_Encode2, OnEncode2)
133 IPC_MESSAGE_HANDLER(AcceleratedVideoEncoderMsg_UseOutputBitstreamBuffer, 169 IPC_MESSAGE_HANDLER(AcceleratedVideoEncoderMsg_UseOutputBitstreamBuffer,
134 OnUseOutputBitstreamBuffer) 170 OnUseOutputBitstreamBuffer)
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 stub_->RemoveDestructionObserver(this); 207 stub_->RemoveDestructionObserver(this);
172 encoder_.reset(); 208 encoder_.reset();
173 delete this; 209 delete this;
174 } 210 }
175 211
176 // static 212 // static
177 gpu::VideoEncodeAcceleratorSupportedProfiles 213 gpu::VideoEncodeAcceleratorSupportedProfiles
178 GpuVideoEncodeAccelerator::GetSupportedProfiles( 214 GpuVideoEncodeAccelerator::GetSupportedProfiles(
179 const gpu::GpuPreferences& gpu_preferences) { 215 const gpu::GpuPreferences& gpu_preferences) {
180 VideoEncodeAccelerator::SupportedProfiles profiles; 216 VideoEncodeAccelerator::SupportedProfiles profiles;
181 std::vector<GpuVideoEncodeAccelerator::CreateVEAFp> create_vea_fps =
182 CreateVEAFps(gpu_preferences);
183 217
184 for (size_t i = 0; i < create_vea_fps.size(); ++i) { 218 for (const auto& vea_factory_method : GetVEAFactoryMethods(gpu_preferences)) {
185 std::unique_ptr<VideoEncodeAccelerator> encoder = (*create_vea_fps[i])(); 219 std::unique_ptr<VideoEncodeAccelerator> encoder = vea_factory_method.Run();
186 if (!encoder) 220 if (!encoder)
187 continue; 221 continue;
188 VideoEncodeAccelerator::SupportedProfiles vea_profiles = 222 VideoEncodeAccelerator::SupportedProfiles vea_profiles =
189 encoder->GetSupportedProfiles(); 223 encoder->GetSupportedProfiles();
190 GpuVideoAcceleratorUtil::InsertUniqueEncodeProfiles(vea_profiles, 224 GpuVideoAcceleratorUtil::InsertUniqueEncodeProfiles(vea_profiles,
191 &profiles); 225 &profiles);
192 } 226 }
193 return GpuVideoAcceleratorUtil::ConvertMediaToGpuEncodeProfiles(profiles); 227 return GpuVideoAcceleratorUtil::ConvertMediaToGpuEncodeProfiles(profiles);
194 } 228 }
195 229
196 // static 230 // static
197 std::vector<GpuVideoEncodeAccelerator::CreateVEAFp> 231 std::vector<GpuVideoEncodeAccelerator::VEAFactoryMethod>
198 GpuVideoEncodeAccelerator::CreateVEAFps( 232 GpuVideoEncodeAccelerator::GetVEAFactoryMethods(
199 const gpu::GpuPreferences& gpu_preferences) { 233 const gpu::GpuPreferences& gpu_preferences) {
200 std::vector<GpuVideoEncodeAccelerator::CreateVEAFp> create_vea_fps; 234 std::vector<VEAFactoryMethod> vea_factory_methods;
201 #if defined(OS_CHROMEOS) && defined(USE_V4L2_CODEC) 235 #if defined(OS_CHROMEOS) && defined(USE_V4L2_CODEC)
202 create_vea_fps.push_back(&GpuVideoEncodeAccelerator::CreateV4L2VEA); 236 vea_factory_methods.push_back(base::Bind(&CreateV4L2VEA));
203 #endif 237 #endif
204 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) 238 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY)
205 if (!gpu_preferences.disable_vaapi_accelerated_video_encode) 239 if (!gpu_preferences.disable_vaapi_accelerated_video_encode)
206 create_vea_fps.push_back(&GpuVideoEncodeAccelerator::CreateVaapiVEA); 240 vea_factory_methods.push_back(base::Bind(&CreateVaapiVEA));
207 #endif 241 #endif
208 #if defined(OS_ANDROID) && defined(ENABLE_WEBRTC) 242 #if defined(OS_ANDROID) && defined(ENABLE_WEBRTC)
209 if (!gpu_preferences.disable_web_rtc_hw_encoding) 243 if (!gpu_preferences.disable_web_rtc_hw_encoding)
210 create_vea_fps.push_back(&GpuVideoEncodeAccelerator::CreateAndroidVEA); 244 vea_factory_methods.push_back(base::Bind(&CreateAndroidVEA));
211 #endif 245 #endif
212 #if defined(OS_MACOSX) 246 #if defined(OS_MACOSX)
213 create_vea_fps.push_back(&GpuVideoEncodeAccelerator::CreateVTVEA); 247 vea_factory_methods.push_back(base::Bind(&CreateVTVEA));
214 #endif 248 #endif
215 #if defined(OS_WIN) 249 #if defined(OS_WIN)
216 if (base::FeatureList::IsEnabled(kMediaFoundationH264Encoding)) { 250 if (base::FeatureList::IsEnabled(kMediaFoundationH264Encoding))
217 create_vea_fps.push_back( 251 vea_factory_methods.push_back(base::Bind(&CreateMediaFoundationVEA));
218 &GpuVideoEncodeAccelerator::CreateMediaFoundationVEA);
219 }
220 #endif 252 #endif
221 return create_vea_fps; 253 return vea_factory_methods;
222 } 254 }
223 255
224 #if defined(OS_CHROMEOS) && defined(USE_V4L2_CODEC)
225 // static
226 std::unique_ptr<VideoEncodeAccelerator>
227 GpuVideoEncodeAccelerator::CreateV4L2VEA() {
228 std::unique_ptr<VideoEncodeAccelerator> encoder;
229 scoped_refptr<V4L2Device> device = V4L2Device::Create(V4L2Device::kEncoder);
230 if (device)
231 encoder.reset(new V4L2VideoEncodeAccelerator(device));
232 return encoder;
233 }
234 #endif
235
236 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY)
237 // static
238 std::unique_ptr<VideoEncodeAccelerator>
239 GpuVideoEncodeAccelerator::CreateVaapiVEA() {
240 return base::WrapUnique<VideoEncodeAccelerator>(
241 new VaapiVideoEncodeAccelerator());
242 }
243 #endif
244
245 #if defined(OS_ANDROID) && defined(ENABLE_WEBRTC)
246 // static
247 std::unique_ptr<VideoEncodeAccelerator>
248 GpuVideoEncodeAccelerator::CreateAndroidVEA() {
249 return base::WrapUnique<VideoEncodeAccelerator>(
250 new AndroidVideoEncodeAccelerator());
251 }
252 #endif
253
254 #if defined(OS_MACOSX)
255 // static
256 std::unique_ptr<VideoEncodeAccelerator>
257 GpuVideoEncodeAccelerator::CreateVTVEA() {
258 return base::WrapUnique<VideoEncodeAccelerator>(
259 new VTVideoEncodeAccelerator());
260 }
261 #endif
262
263 #if defined(OS_WIN)
264 // static
265 std::unique_ptr<media::VideoEncodeAccelerator>
266 GpuVideoEncodeAccelerator::CreateMediaFoundationVEA() {
267 return base::WrapUnique<media::VideoEncodeAccelerator>(
268 new MediaFoundationVideoEncodeAccelerator());
269 }
270 #endif
271
272 void GpuVideoEncodeAccelerator::OnEncode( 256 void GpuVideoEncodeAccelerator::OnEncode(
273 const AcceleratedVideoEncoderMsg_Encode_Params& params) { 257 const AcceleratedVideoEncoderMsg_Encode_Params& params) {
274 DVLOG(3) << "GpuVideoEncodeAccelerator::OnEncode: frame_id = " 258 DVLOG(3) << __FUNCTION__ << " frame_id = " << params.frame_id
275 << params.frame_id << ", buffer_size=" << params.buffer_size 259 << ", buffer_size=" << params.buffer_size
276 << ", force_keyframe=" << params.force_keyframe; 260 << ", force_keyframe=" << params.force_keyframe;
277 DCHECK_EQ(PIXEL_FORMAT_I420, input_format_); 261 DCHECK_EQ(PIXEL_FORMAT_I420, input_format_);
278 262
279 // Wrap into a SharedMemory in the beginning, so that |params.buffer_handle| 263 // Wrap into a SharedMemory in the beginning, so that |params.buffer_handle|
280 // is cleaned properly in case of an early return. 264 // is cleaned properly in case of an early return.
281 std::unique_ptr<base::SharedMemory> shm( 265 std::unique_ptr<base::SharedMemory> shm(
282 new base::SharedMemory(params.buffer_handle, true)); 266 new base::SharedMemory(params.buffer_handle, true));
283 267
284 if (!encoder_) 268 if (!encoder_)
285 return; 269 return;
286 270
287 if (params.frame_id < 0) { 271 if (params.frame_id < 0) {
288 DLOG(ERROR) << "GpuVideoEncodeAccelerator::OnEncode(): invalid " 272 DLOG(ERROR) << __FUNCTION__ << " invalidc "
watk 2016/08/18 18:12:15 s/invalidc/invalid
mcasas 2016/08/18 19:24:40 Done.
289 << "frame_id=" << params.frame_id; 273 << "frame_id=" << params.frame_id;
290 NotifyError(VideoEncodeAccelerator::kPlatformFailureError); 274 NotifyError(VideoEncodeAccelerator::kPlatformFailureError);
291 return; 275 return;
292 } 276 }
293 277
294 const uint32_t aligned_offset = 278 const uint32_t aligned_offset =
295 params.buffer_offset % base::SysInfo::VMAllocationGranularity(); 279 params.buffer_offset % base::SysInfo::VMAllocationGranularity();
296 base::CheckedNumeric<off_t> map_offset = params.buffer_offset; 280 base::CheckedNumeric<off_t> map_offset = params.buffer_offset;
297 map_offset -= aligned_offset; 281 map_offset -= aligned_offset;
298 base::CheckedNumeric<size_t> map_size = params.buffer_size; 282 base::CheckedNumeric<size_t> map_size = params.buffer_size;
299 map_size += aligned_offset; 283 map_size += aligned_offset;
300 284
301 if (!map_offset.IsValid() || !map_size.IsValid()) { 285 if (!map_offset.IsValid() || !map_size.IsValid()) {
302 DLOG(ERROR) << "GpuVideoEncodeAccelerator::OnEncode():" 286 DLOG(ERROR) << __FUNCTION__ << " invalid (buffer_offset, buffer_size)";
303 << " invalid (buffer_offset,buffer_size)";
304 NotifyError(VideoEncodeAccelerator::kPlatformFailureError); 287 NotifyError(VideoEncodeAccelerator::kPlatformFailureError);
305 return; 288 return;
306 } 289 }
307 290
308 if (!shm->MapAt(map_offset.ValueOrDie(), map_size.ValueOrDie())) { 291 if (!shm->MapAt(map_offset.ValueOrDie(), map_size.ValueOrDie())) {
309 DLOG(ERROR) << "GpuVideoEncodeAccelerator::OnEncode(): " 292 DLOG(ERROR) << __FUNCTION__
310 << "could not map frame_id=" << params.frame_id; 293 << " could not map frame_id=" << params.frame_id;
311 NotifyError(VideoEncodeAccelerator::kPlatformFailureError); 294 NotifyError(VideoEncodeAccelerator::kPlatformFailureError);
312 return; 295 return;
313 } 296 }
314 297
315 uint8_t* shm_memory = 298 uint8_t* shm_memory =
316 reinterpret_cast<uint8_t*>(shm->memory()) + aligned_offset; 299 reinterpret_cast<uint8_t*>(shm->memory()) + aligned_offset;
317 scoped_refptr<VideoFrame> frame = VideoFrame::WrapExternalSharedMemory( 300 scoped_refptr<VideoFrame> frame = VideoFrame::WrapExternalSharedMemory(
318 input_format_, input_coded_size_, gfx::Rect(input_visible_size_), 301 input_format_, input_coded_size_, gfx::Rect(input_visible_size_),
319 input_visible_size_, shm_memory, params.buffer_size, params.buffer_handle, 302 input_visible_size_, shm_memory, params.buffer_size, params.buffer_handle,
320 params.buffer_offset, params.timestamp); 303 params.buffer_offset, params.timestamp);
321 if (!frame) { 304 if (!frame) {
322 DLOG(ERROR) << "GpuVideoEncodeAccelerator::OnEncode(): " 305 DLOG(ERROR) << __FUNCTION__ << " could not create a frame";
323 << "could not create a frame";
324 NotifyError(VideoEncodeAccelerator::kPlatformFailureError); 306 NotifyError(VideoEncodeAccelerator::kPlatformFailureError);
325 return; 307 return;
326 } 308 }
327 frame->AddDestructionObserver(BindToCurrentLoop(base::Bind( 309 frame->AddDestructionObserver(BindToCurrentLoop(base::Bind(
328 &GpuVideoEncodeAccelerator::EncodeFrameFinished, 310 &GpuVideoEncodeAccelerator::EncodeFrameFinished,
329 weak_this_factory_.GetWeakPtr(), params.frame_id, base::Passed(&shm)))); 311 weak_this_factory_.GetWeakPtr(), params.frame_id, base::Passed(&shm))));
330 encoder_->Encode(frame, params.force_keyframe); 312 encoder_->Encode(frame, params.force_keyframe);
331 } 313 }
332 314
333 void GpuVideoEncodeAccelerator::OnEncode2( 315 void GpuVideoEncodeAccelerator::OnEncode2(
334 const AcceleratedVideoEncoderMsg_Encode_Params2& params) { 316 const AcceleratedVideoEncoderMsg_Encode_Params2& params) {
335 DVLOG(3) << "GpuVideoEncodeAccelerator::OnEncode2: " 317 DVLOG(3) << __FUNCTION__ << " frame_id = " << params.frame_id
336 << "frame_id = " << params.frame_id
337 << ", size=" << params.size.ToString() 318 << ", size=" << params.size.ToString()
338 << ", force_keyframe=" << params.force_keyframe 319 << ", force_keyframe=" << params.force_keyframe
339 << ", handle type=" << params.gpu_memory_buffer_handles[0].type; 320 << ", handle type=" << params.gpu_memory_buffer_handles[0].type;
340 // Encoding GpuMemoryBuffer backed frames is not supported. 321 // Encoding GpuMemoryBuffer backed frames is not supported.
341 NOTREACHED(); 322 NOTREACHED();
342 } 323 }
343 324
344 void GpuVideoEncodeAccelerator::OnUseOutputBitstreamBuffer( 325 void GpuVideoEncodeAccelerator::OnUseOutputBitstreamBuffer(
345 int32_t buffer_id, 326 int32_t buffer_id,
346 base::SharedMemoryHandle buffer_handle, 327 base::SharedMemoryHandle buffer_handle,
347 uint32_t buffer_size) { 328 uint32_t buffer_size) {
348 DVLOG(3) << "GpuVideoEncodeAccelerator::OnUseOutputBitstreamBuffer(): " 329 DVLOG(3) << __FUNCTION__ << " buffer_id=" << buffer_id
349 << "buffer_id=" << buffer_id << ", buffer_size=" << buffer_size; 330 << ", buffer_size=" << buffer_size;
350 if (!encoder_) 331 if (!encoder_)
351 return; 332 return;
352 if (buffer_id < 0) { 333 if (buffer_id < 0) {
353 DLOG(ERROR) << "GpuVideoEncodeAccelerator::OnUseOutputBitstreamBuffer(): " 334 DLOG(ERROR) << __FUNCTION__ << " invalid buffer_id=" << buffer_id;
354 << "invalid buffer_id=" << buffer_id;
355 NotifyError(VideoEncodeAccelerator::kPlatformFailureError); 335 NotifyError(VideoEncodeAccelerator::kPlatformFailureError);
356 return; 336 return;
357 } 337 }
358 if (buffer_size < output_buffer_size_) { 338 if (buffer_size < output_buffer_size_) {
359 DLOG(ERROR) << "GpuVideoEncodeAccelerator::OnUseOutputBitstreamBuffer(): " 339 DLOG(ERROR) << __FUNCTION__
360 << "buffer too small for buffer_id=" << buffer_id; 340 << " buffer too small for buffer_id=" << buffer_id;
361 NotifyError(VideoEncodeAccelerator::kPlatformFailureError); 341 NotifyError(VideoEncodeAccelerator::kPlatformFailureError);
362 return; 342 return;
363 } 343 }
364 encoder_->UseOutputBitstreamBuffer( 344 encoder_->UseOutputBitstreamBuffer(
365 BitstreamBuffer(buffer_id, buffer_handle, buffer_size)); 345 BitstreamBuffer(buffer_id, buffer_handle, buffer_size));
366 } 346 }
367 347
368 void GpuVideoEncodeAccelerator::OnDestroy() { 348 void GpuVideoEncodeAccelerator::OnDestroy() {
369 DVLOG(2) << "GpuVideoEncodeAccelerator::OnDestroy()"; 349 DVLOG(2) << __FUNCTION__;
370 OnWillDestroyStub(); 350 OnWillDestroyStub();
371 } 351 }
372 352
373 void GpuVideoEncodeAccelerator::OnRequestEncodingParametersChange( 353 void GpuVideoEncodeAccelerator::OnRequestEncodingParametersChange(
374 uint32_t bitrate, 354 uint32_t bitrate,
375 uint32_t framerate) { 355 uint32_t framerate) {
376 DVLOG(2) << "GpuVideoEncodeAccelerator::OnRequestEncodingParametersChange(): " 356 DVLOG(2) << __FUNCTION__ << " bitrate=" << bitrate
377 << "bitrate=" << bitrate << ", framerate=" << framerate; 357 << ", framerate=" << framerate;
378 if (!encoder_) 358 if (!encoder_)
379 return; 359 return;
380 encoder_->RequestEncodingParametersChange(bitrate, framerate); 360 encoder_->RequestEncodingParametersChange(bitrate, framerate);
381 } 361 }
382 362
383 void GpuVideoEncodeAccelerator::EncodeFrameFinished( 363 void GpuVideoEncodeAccelerator::EncodeFrameFinished(
384 int32_t frame_id, 364 int32_t frame_id,
385 std::unique_ptr<base::SharedMemory> shm) { 365 std::unique_ptr<base::SharedMemory> shm) {
386 Send(new AcceleratedVideoEncoderHostMsg_NotifyInputDone(host_route_id_, 366 Send(new AcceleratedVideoEncoderHostMsg_NotifyInputDone(host_route_id_,
387 frame_id)); 367 frame_id));
388 // Just let |shm| fall out of scope. 368 // Just let |shm| fall out of scope.
389 } 369 }
390 370
391 void GpuVideoEncodeAccelerator::Send(IPC::Message* message) { 371 void GpuVideoEncodeAccelerator::Send(IPC::Message* message) {
392 stub_->channel()->Send(message); 372 stub_->channel()->Send(message);
393 } 373 }
394 374
395 } // namespace media 375 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698