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 "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 Loading... |
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 static bool MakeDecoderContextCurrent( | 46 namespace { |
| 47 |
| 48 bool MakeDecoderContextCurrent( |
47 const base::WeakPtr<gpu::GpuCommandBufferStub> stub) { | 49 const base::WeakPtr<gpu::GpuCommandBufferStub> stub) { |
48 if (!stub) { | 50 if (!stub) { |
49 DLOG(ERROR) << "Stub is gone; won't MakeCurrent()."; | 51 DLOG(ERROR) << "Stub is gone; won't MakeCurrent()."; |
50 return false; | 52 return false; |
51 } | 53 } |
52 | 54 |
53 if (!stub->decoder()->MakeCurrent()) { | 55 if (!stub->decoder()->MakeCurrent()) { |
54 DLOG(ERROR) << "Failed to MakeCurrent()"; | 56 DLOG(ERROR) << "Failed to MakeCurrent()"; |
55 return false; | 57 return false; |
56 } | 58 } |
57 | 59 |
58 return true; | 60 return true; |
59 } | 61 } |
60 | 62 |
| 63 #if defined(OS_CHROMEOS) && defined(USE_V4L2_CODEC) |
| 64 std::unique_ptr<VideoEncodeAccelerator> CreateV4L2VEA() { |
| 65 scoped_refptr<V4L2Device> device = V4L2Device::Create(V4L2Device::kEncoder); |
| 66 if (!device) |
| 67 return nullptr; |
| 68 return base::WrapUnique<VideoEncodeAccelerator>( |
| 69 new V4L2VideoEncodeAccelerator(device)); |
| 70 } |
| 71 #endif |
| 72 |
| 73 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) |
| 74 std::unique_ptr<VideoEncodeAccelerator> CreateVaapiVEA() { |
| 75 return base::WrapUnique<VideoEncodeAccelerator>( |
| 76 new VaapiVideoEncodeAccelerator()); |
| 77 } |
| 78 #endif |
| 79 |
| 80 #if defined(OS_ANDROID) && defined(ENABLE_WEBRTC) |
| 81 std::unique_ptr<VideoEncodeAccelerator> CreateAndroidVEA() { |
| 82 return base::WrapUnique<VideoEncodeAccelerator>( |
| 83 new AndroidVideoEncodeAccelerator()); |
| 84 } |
| 85 #endif |
| 86 |
| 87 #if defined(OS_MACOSX) |
| 88 std::unique_ptr<VideoEncodeAccelerator> CreateVTVEA() { |
| 89 return base::WrapUnique<VideoEncodeAccelerator>( |
| 90 new VTVideoEncodeAccelerator()); |
| 91 } |
| 92 #endif |
| 93 |
| 94 #if defined(OS_WIN) |
| 95 std::unique_ptr<VideoEncodeAccelerator> CreateMediaFoundationVEA() { |
| 96 return base::WrapUnique<media::VideoEncodeAccelerator>( |
| 97 new MediaFoundationVideoEncodeAccelerator()); |
| 98 } |
| 99 #endif |
| 100 |
| 101 } // anonymous namespace |
| 102 |
61 GpuVideoEncodeAccelerator::GpuVideoEncodeAccelerator( | 103 GpuVideoEncodeAccelerator::GpuVideoEncodeAccelerator( |
62 int32_t host_route_id, | 104 int32_t host_route_id, |
63 gpu::GpuCommandBufferStub* stub) | 105 gpu::GpuCommandBufferStub* stub) |
64 : host_route_id_(host_route_id), | 106 : host_route_id_(host_route_id), |
65 stub_(stub), | 107 stub_(stub), |
66 input_format_(PIXEL_FORMAT_UNKNOWN), | 108 input_format_(PIXEL_FORMAT_UNKNOWN), |
67 output_buffer_size_(0), | 109 output_buffer_size_(0), |
68 weak_this_factory_(this) { | 110 weak_this_factory_(this) { |
69 stub_->AddDestructionObserver(this); | 111 stub_->AddDestructionObserver(this); |
70 make_context_current_ = | 112 make_context_current_ = |
71 base::Bind(&MakeDecoderContextCurrent, stub_->AsWeakPtr()); | 113 base::Bind(&MakeDecoderContextCurrent, stub_->AsWeakPtr()); |
72 } | 114 } |
73 | 115 |
74 GpuVideoEncodeAccelerator::~GpuVideoEncodeAccelerator() { | 116 GpuVideoEncodeAccelerator::~GpuVideoEncodeAccelerator() { |
75 // This class can only be self-deleted from OnWillDestroyStub(), which means | 117 // This class can only be self-deleted from OnWillDestroyStub(), which means |
76 // the VEA has already been destroyed in there. | 118 // the VEA has already been destroyed in there. |
77 DCHECK(!encoder_); | 119 DCHECK(!encoder_); |
78 } | 120 } |
79 | 121 |
80 bool GpuVideoEncodeAccelerator::Initialize(VideoPixelFormat input_format, | 122 bool GpuVideoEncodeAccelerator::Initialize(VideoPixelFormat input_format, |
81 const gfx::Size& input_visible_size, | 123 const gfx::Size& input_visible_size, |
82 VideoCodecProfile output_profile, | 124 VideoCodecProfile output_profile, |
83 uint32_t initial_bitrate) { | 125 uint32_t initial_bitrate) { |
84 DVLOG(2) << "GpuVideoEncodeAccelerator::Initialize(): " | 126 DVLOG(1) << __FUNCTION__ |
85 << "input_format=" << input_format | 127 << " input_format=" << VideoPixelFormatToString(input_format) |
86 << ", input_visible_size=" << input_visible_size.ToString() | 128 << ", input_visible_size=" << input_visible_size.ToString() |
87 << ", output_profile=" << output_profile | 129 << ", output_profile=" << GetProfileName(output_profile) |
88 << ", initial_bitrate=" << initial_bitrate; | 130 << ", initial_bitrate=" << initial_bitrate; |
89 DCHECK(!encoder_); | 131 DCHECK(!encoder_); |
90 | 132 |
91 if (!stub_->channel()->AddRoute(host_route_id_, stub_->stream_id(), this)) { | 133 if (!stub_->channel()->AddRoute(host_route_id_, stub_->stream_id(), this)) { |
92 DLOG(ERROR) << "GpuVideoEncodeAccelerator::Initialize(): " | 134 DLOG(ERROR) << __FUNCTION__ << " failed to add route"; |
93 "failed to add route"; | |
94 return false; | 135 return false; |
95 } | 136 } |
96 | 137 |
97 if (input_visible_size.width() > limits::kMaxDimension || | 138 if (input_visible_size.width() > limits::kMaxDimension || |
98 input_visible_size.height() > limits::kMaxDimension || | 139 input_visible_size.height() > limits::kMaxDimension || |
99 input_visible_size.GetArea() > limits::kMaxCanvas) { | 140 input_visible_size.GetArea() > limits::kMaxCanvas) { |
100 DLOG(ERROR) << "GpuVideoEncodeAccelerator::Initialize(): " | 141 DLOG(ERROR) << __FUNCTION__ << "too large input_visible_size " |
101 << "input_visible_size " << input_visible_size.ToString() | 142 << input_visible_size.ToString(); |
102 << " too large"; | |
103 return false; | 143 return false; |
104 } | 144 } |
105 | 145 |
106 const gpu::GpuPreferences& gpu_preferences = | 146 const gpu::GpuPreferences& gpu_preferences = |
107 stub_->channel()->gpu_channel_manager()->gpu_preferences(); | 147 stub_->channel()->gpu_channel_manager()->gpu_preferences(); |
108 | 148 |
109 std::vector<GpuVideoEncodeAccelerator::CreateVEAFp> create_vea_fps = | |
110 CreateVEAFps(gpu_preferences); | |
111 // Try all possible encoders and use the first successful encoder. | 149 // Try all possible encoders and use the first successful encoder. |
112 for (size_t i = 0; i < create_vea_fps.size(); ++i) { | 150 for (const auto& factory_function : GetVEAFactoryFunctions(gpu_preferences)) { |
113 encoder_ = (*create_vea_fps[i])(); | 151 encoder_ = factory_function.Run(); |
114 if (encoder_ && | 152 if (encoder_ && |
115 encoder_->Initialize(input_format, input_visible_size, output_profile, | 153 encoder_->Initialize(input_format, input_visible_size, output_profile, |
116 initial_bitrate, this)) { | 154 initial_bitrate, this)) { |
117 input_format_ = input_format; | 155 input_format_ = input_format; |
118 input_visible_size_ = input_visible_size; | 156 input_visible_size_ = input_visible_size; |
119 return true; | 157 return true; |
120 } | 158 } |
121 } | 159 } |
122 encoder_.reset(); | 160 encoder_.reset(); |
123 DLOG(ERROR) | 161 DLOG(ERROR) << __FUNCTION__ << " VEA initialization failed"; |
124 << "GpuVideoEncodeAccelerator::Initialize(): VEA initialization failed"; | |
125 return false; | 162 return false; |
126 } | 163 } |
127 | 164 |
128 bool GpuVideoEncodeAccelerator::OnMessageReceived(const IPC::Message& message) { | 165 bool GpuVideoEncodeAccelerator::OnMessageReceived(const IPC::Message& message) { |
129 bool handled = true; | 166 bool handled = true; |
130 IPC_BEGIN_MESSAGE_MAP(GpuVideoEncodeAccelerator, message) | 167 IPC_BEGIN_MESSAGE_MAP(GpuVideoEncodeAccelerator, message) |
131 IPC_MESSAGE_HANDLER(AcceleratedVideoEncoderMsg_Encode, OnEncode) | 168 IPC_MESSAGE_HANDLER(AcceleratedVideoEncoderMsg_Encode, OnEncode) |
132 IPC_MESSAGE_HANDLER(AcceleratedVideoEncoderMsg_Encode2, OnEncode2) | 169 IPC_MESSAGE_HANDLER(AcceleratedVideoEncoderMsg_Encode2, OnEncode2) |
133 IPC_MESSAGE_HANDLER(AcceleratedVideoEncoderMsg_UseOutputBitstreamBuffer, | 170 IPC_MESSAGE_HANDLER(AcceleratedVideoEncoderMsg_UseOutputBitstreamBuffer, |
134 OnUseOutputBitstreamBuffer) | 171 OnUseOutputBitstreamBuffer) |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 stub_->RemoveDestructionObserver(this); | 208 stub_->RemoveDestructionObserver(this); |
172 encoder_.reset(); | 209 encoder_.reset(); |
173 delete this; | 210 delete this; |
174 } | 211 } |
175 | 212 |
176 // static | 213 // static |
177 gpu::VideoEncodeAcceleratorSupportedProfiles | 214 gpu::VideoEncodeAcceleratorSupportedProfiles |
178 GpuVideoEncodeAccelerator::GetSupportedProfiles( | 215 GpuVideoEncodeAccelerator::GetSupportedProfiles( |
179 const gpu::GpuPreferences& gpu_preferences) { | 216 const gpu::GpuPreferences& gpu_preferences) { |
180 VideoEncodeAccelerator::SupportedProfiles profiles; | 217 VideoEncodeAccelerator::SupportedProfiles profiles; |
181 std::vector<GpuVideoEncodeAccelerator::CreateVEAFp> create_vea_fps = | |
182 CreateVEAFps(gpu_preferences); | |
183 | 218 |
184 for (size_t i = 0; i < create_vea_fps.size(); ++i) { | 219 for (const auto& factory_function : GetVEAFactoryFunctions(gpu_preferences)) { |
185 std::unique_ptr<VideoEncodeAccelerator> encoder = (*create_vea_fps[i])(); | 220 std::unique_ptr<VideoEncodeAccelerator> encoder = factory_function.Run(); |
186 if (!encoder) | 221 if (!encoder) |
187 continue; | 222 continue; |
188 VideoEncodeAccelerator::SupportedProfiles vea_profiles = | 223 VideoEncodeAccelerator::SupportedProfiles vea_profiles = |
189 encoder->GetSupportedProfiles(); | 224 encoder->GetSupportedProfiles(); |
190 GpuVideoAcceleratorUtil::InsertUniqueEncodeProfiles(vea_profiles, | 225 GpuVideoAcceleratorUtil::InsertUniqueEncodeProfiles(vea_profiles, |
191 &profiles); | 226 &profiles); |
192 } | 227 } |
193 return GpuVideoAcceleratorUtil::ConvertMediaToGpuEncodeProfiles(profiles); | 228 return GpuVideoAcceleratorUtil::ConvertMediaToGpuEncodeProfiles(profiles); |
194 } | 229 } |
195 | 230 |
196 // static | 231 // static |
197 std::vector<GpuVideoEncodeAccelerator::CreateVEAFp> | 232 std::vector<GpuVideoEncodeAccelerator::VEAFactoryFunction> |
198 GpuVideoEncodeAccelerator::CreateVEAFps( | 233 GpuVideoEncodeAccelerator::GetVEAFactoryFunctions( |
199 const gpu::GpuPreferences& gpu_preferences) { | 234 const gpu::GpuPreferences& gpu_preferences) { |
200 std::vector<GpuVideoEncodeAccelerator::CreateVEAFp> create_vea_fps; | 235 std::vector<VEAFactoryFunction> vea_factory_functions; |
201 #if defined(OS_CHROMEOS) && defined(USE_V4L2_CODEC) | 236 #if defined(OS_CHROMEOS) && defined(USE_V4L2_CODEC) |
202 create_vea_fps.push_back(&GpuVideoEncodeAccelerator::CreateV4L2VEA); | 237 vea_factory_functions.push_back(base::Bind(&CreateV4L2VEA)); |
203 #endif | 238 #endif |
204 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) | 239 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) |
205 if (!gpu_preferences.disable_vaapi_accelerated_video_encode) | 240 if (!gpu_preferences.disable_vaapi_accelerated_video_encode) |
206 create_vea_fps.push_back(&GpuVideoEncodeAccelerator::CreateVaapiVEA); | 241 vea_factory_functions.push_back(base::Bind(&CreateVaapiVEA)); |
207 #endif | 242 #endif |
208 #if defined(OS_ANDROID) && defined(ENABLE_WEBRTC) | 243 #if defined(OS_ANDROID) && defined(ENABLE_WEBRTC) |
209 if (!gpu_preferences.disable_web_rtc_hw_encoding) | 244 if (!gpu_preferences.disable_web_rtc_hw_encoding) |
210 create_vea_fps.push_back(&GpuVideoEncodeAccelerator::CreateAndroidVEA); | 245 vea_factory_functions.push_back(base::Bind(&CreateAndroidVEA)); |
211 #endif | 246 #endif |
212 #if defined(OS_MACOSX) | 247 #if defined(OS_MACOSX) |
213 create_vea_fps.push_back(&GpuVideoEncodeAccelerator::CreateVTVEA); | 248 vea_factory_functions.push_back(base::Bind(&CreateVTVEA)); |
214 #endif | 249 #endif |
215 #if defined(OS_WIN) | 250 #if defined(OS_WIN) |
216 if (base::FeatureList::IsEnabled(kMediaFoundationH264Encoding)) { | 251 if (base::FeatureList::IsEnabled(kMediaFoundationH264Encoding)) |
217 create_vea_fps.push_back( | 252 vea_factory_functions.push_back(base::Bind(&CreateMediaFoundationVEA)); |
218 &GpuVideoEncodeAccelerator::CreateMediaFoundationVEA); | |
219 } | |
220 #endif | 253 #endif |
221 return create_vea_fps; | 254 return vea_factory_functions; |
222 } | 255 } |
223 | 256 |
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( | 257 void GpuVideoEncodeAccelerator::OnEncode( |
273 const AcceleratedVideoEncoderMsg_Encode_Params& params) { | 258 const AcceleratedVideoEncoderMsg_Encode_Params& params) { |
274 DVLOG(3) << "GpuVideoEncodeAccelerator::OnEncode: frame_id = " | 259 DVLOG(3) << __FUNCTION__ << " frame_id = " << params.frame_id |
275 << params.frame_id << ", buffer_size=" << params.buffer_size | 260 << ", buffer_size=" << params.buffer_size |
276 << ", force_keyframe=" << params.force_keyframe; | 261 << ", force_keyframe=" << params.force_keyframe; |
277 DCHECK_EQ(PIXEL_FORMAT_I420, input_format_); | 262 DCHECK_EQ(PIXEL_FORMAT_I420, input_format_); |
278 | 263 |
279 // Wrap into a SharedMemory in the beginning, so that |params.buffer_handle| | 264 // Wrap into a SharedMemory in the beginning, so that |params.buffer_handle| |
280 // is cleaned properly in case of an early return. | 265 // is cleaned properly in case of an early return. |
281 std::unique_ptr<base::SharedMemory> shm( | 266 std::unique_ptr<base::SharedMemory> shm( |
282 new base::SharedMemory(params.buffer_handle, true)); | 267 new base::SharedMemory(params.buffer_handle, true)); |
283 | 268 |
284 if (!encoder_) | 269 if (!encoder_) |
285 return; | 270 return; |
286 | 271 |
287 if (params.frame_id < 0) { | 272 if (params.frame_id < 0) { |
288 DLOG(ERROR) << "GpuVideoEncodeAccelerator::OnEncode(): invalid " | 273 DLOG(ERROR) << __FUNCTION__ << " invalid frame_id=" << params.frame_id; |
289 << "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 map_offset or map_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 |
OLD | NEW |