OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/renderer/pepper/video_encoder_shim.h" | 5 #include "content/renderer/pepper/video_encoder_shim.h" |
6 | 6 |
7 #include <inttypes.h> | 7 #include <inttypes.h> |
8 | 8 |
9 #include <deque> | 9 #include <deque> |
10 | 10 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
67 int32_t* min_quantizer, | 67 int32_t* min_quantizer, |
68 int32_t* max_quantizer, | 68 int32_t* max_quantizer, |
69 int32_t* cpu_used) { | 69 int32_t* cpu_used) { |
70 switch (codec) { | 70 switch (codec) { |
71 case media::VP8PROFILE_ANY: | 71 case media::VP8PROFILE_ANY: |
72 *vpx_codec = vpx_codec_vp8_cx(); | 72 *vpx_codec = vpx_codec_vp8_cx(); |
73 *min_quantizer = kVp8DefaultMinQuantizer; | 73 *min_quantizer = kVp8DefaultMinQuantizer; |
74 *max_quantizer = kVp8DefaultMaxQuantizer; | 74 *max_quantizer = kVp8DefaultMaxQuantizer; |
75 *cpu_used = kVp8DefaultCpuUsed; | 75 *cpu_used = kVp8DefaultCpuUsed; |
76 break; | 76 break; |
77 case media::VP9PROFILE_ANY: | 77 case media::VP9PROFILE_PROFILE0: |
ddorwin
2016/03/31 21:09:50
I wonder if we should have a comment here about wh
servolk
2016/03/31 21:26:38
Probably not worth adding the profiles 1-3 here ex
| |
78 *vpx_codec = vpx_codec_vp9_cx(); | 78 *vpx_codec = vpx_codec_vp9_cx(); |
79 *min_quantizer = kVp9DefaultMinQuantizer; | 79 *min_quantizer = kVp9DefaultMinQuantizer; |
80 *max_quantizer = kVp9DefaultMaxQuantizer; | 80 *max_quantizer = kVp9DefaultMaxQuantizer; |
81 *cpu_used = kVp9DefaultCpuUsed; | 81 *cpu_used = kVp9DefaultCpuUsed; |
82 break; | 82 break; |
83 default: | 83 default: |
84 *vpx_codec = nullptr; | 84 *vpx_codec = nullptr; |
85 *min_quantizer = 0; | 85 *min_quantizer = 0; |
86 *max_quantizer = 0; | 86 *max_quantizer = 0; |
87 *cpu_used = 0; | 87 *cpu_used = 0; |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
189 config_.rc_max_quantizer = max_quantizer; | 189 config_.rc_max_quantizer = max_quantizer; |
190 // Do not saturate CPU utilization just for encoding. On a lower-end system | 190 // Do not saturate CPU utilization just for encoding. On a lower-end system |
191 // with only 1 or 2 cores, use only one thread for encoding. On systems with | 191 // with only 1 or 2 cores, use only one thread for encoding. On systems with |
192 // more cores, allow half of the cores to be used for encoding. | 192 // more cores, allow half of the cores to be used for encoding. |
193 config_.g_threads = | 193 config_.g_threads = |
194 std::min(kMaxNumThreads, (base::SysInfo::NumberOfProcessors() + 1) / 2); | 194 std::min(kMaxNumThreads, (base::SysInfo::NumberOfProcessors() + 1) / 2); |
195 | 195 |
196 // Use Q/CQ mode if no target bitrate is given. Note that in the VP8/CQ case | 196 // Use Q/CQ mode if no target bitrate is given. Note that in the VP8/CQ case |
197 // the meaning of rc_target_bitrate changes to target maximum rate. | 197 // the meaning of rc_target_bitrate changes to target maximum rate. |
198 if (initial_bitrate == 0) { | 198 if (initial_bitrate == 0) { |
199 if (output_profile == media::VP9PROFILE_ANY) { | 199 if (output_profile == media::VP9PROFILE_PROFILE0) { |
200 config_.rc_end_usage = VPX_Q; | 200 config_.rc_end_usage = VPX_Q; |
201 } else if (output_profile == media::VP8PROFILE_ANY) { | 201 } else if (output_profile == media::VP8PROFILE_ANY) { |
202 config_.rc_end_usage = VPX_CQ; | 202 config_.rc_end_usage = VPX_CQ; |
ddorwin
2016/03/31 21:09:50
DCHECK(not the other three profiles)?
Similar bel
servolk
2016/03/31 21:26:38
I've added some DCHECKs at the top of this method.
| |
203 config_.rc_target_bitrate = kVp8MaxCQBitrate; | 203 config_.rc_target_bitrate = kVp8MaxCQBitrate; |
204 } | 204 } |
205 } | 205 } |
206 | 206 |
207 vpx_codec_flags_t flags = 0; | 207 vpx_codec_flags_t flags = 0; |
208 if (vpx_codec_enc_init(&encoder_, vpx_codec, &config_, flags) != | 208 if (vpx_codec_enc_init(&encoder_, vpx_codec, &config_, flags) != |
209 VPX_CODEC_OK) { | 209 VPX_CODEC_OK) { |
210 NotifyError(media::VideoEncodeAccelerator::kPlatformFailureError); | 210 NotifyError(media::VideoEncodeAccelerator::kPlatformFailureError); |
211 return; | 211 return; |
212 } | 212 } |
213 initialized_ = true; | 213 initialized_ = true; |
214 | 214 |
215 if (vpx_codec_enc_config_set(&encoder_, &config_) != VPX_CODEC_OK) { | 215 if (vpx_codec_enc_config_set(&encoder_, &config_) != VPX_CODEC_OK) { |
216 NotifyError(media::VideoEncodeAccelerator::kPlatformFailureError); | 216 NotifyError(media::VideoEncodeAccelerator::kPlatformFailureError); |
217 return; | 217 return; |
218 } | 218 } |
219 | 219 |
220 if (vpx_codec_control(&encoder_, VP8E_SET_CPUUSED, cpu_used) != | 220 if (vpx_codec_control(&encoder_, VP8E_SET_CPUUSED, cpu_used) != |
221 VPX_CODEC_OK) { | 221 VPX_CODEC_OK) { |
222 NotifyError(media::VideoEncodeAccelerator::kPlatformFailureError); | 222 NotifyError(media::VideoEncodeAccelerator::kPlatformFailureError); |
223 return; | 223 return; |
224 } | 224 } |
225 | 225 |
226 if (output_profile == media::VP9PROFILE_ANY) { | 226 if (output_profile == media::VP9PROFILE_PROFILE0) { |
227 if (vpx_codec_control(&encoder_, VP9E_SET_AQ_MODE, | 227 if (vpx_codec_control(&encoder_, VP9E_SET_AQ_MODE, |
228 kVp9AqModeCyclicRefresh) != VPX_CODEC_OK) { | 228 kVp9AqModeCyclicRefresh) != VPX_CODEC_OK) { |
229 NotifyError(media::VideoEncodeAccelerator::kPlatformFailureError); | 229 NotifyError(media::VideoEncodeAccelerator::kPlatformFailureError); |
230 return; | 230 return; |
231 } | 231 } |
232 } | 232 } |
233 | 233 |
234 renderer_task_runner_->PostTask( | 234 renderer_task_runner_->PostTask( |
235 FROM_HERE, | 235 FROM_HERE, |
236 base::Bind(&VideoEncoderShim::OnRequireBitstreamBuffers, shim_, | 236 base::Bind(&VideoEncoderShim::OnRequireBitstreamBuffers, shim_, |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
382 // Libvpx and media::VideoEncodeAccelerator are using opposite | 382 // Libvpx and media::VideoEncodeAccelerator are using opposite |
383 // notions of denominator/numerator. | 383 // notions of denominator/numerator. |
384 profile.max_framerate_numerator = config.g_timebase.den; | 384 profile.max_framerate_numerator = config.g_timebase.den; |
385 profile.max_framerate_denominator = config.g_timebase.num; | 385 profile.max_framerate_denominator = config.g_timebase.num; |
386 profiles.push_back(profile); | 386 profiles.push_back(profile); |
387 } | 387 } |
388 | 388 |
389 ret = vpx_codec_enc_config_default(vpx_codec_vp9_cx(), &config, 0); | 389 ret = vpx_codec_enc_config_default(vpx_codec_vp9_cx(), &config, 0); |
390 if (ret == VPX_CODEC_OK) { | 390 if (ret == VPX_CODEC_OK) { |
391 media::VideoEncodeAccelerator::SupportedProfile profile; | 391 media::VideoEncodeAccelerator::SupportedProfile profile; |
392 profile.profile = media::VP9PROFILE_ANY; | |
393 profile.max_resolution = gfx::Size(kMaxWidth, kMaxHeight); | 392 profile.max_resolution = gfx::Size(kMaxWidth, kMaxHeight); |
394 profile.max_framerate_numerator = config.g_timebase.den; | 393 profile.max_framerate_numerator = config.g_timebase.den; |
395 profile.max_framerate_denominator = config.g_timebase.num; | 394 profile.max_framerate_denominator = config.g_timebase.num; |
395 profile.profile = media::VP9PROFILE_PROFILE0; | |
396 profiles.push_back(profile); | 396 profiles.push_back(profile); |
397 } | 397 } |
398 | 398 |
399 return profiles; | 399 return profiles; |
400 } | 400 } |
401 | 401 |
402 bool VideoEncoderShim::Initialize( | 402 bool VideoEncoderShim::Initialize( |
403 media::VideoPixelFormat input_format, | 403 media::VideoPixelFormat input_format, |
404 const gfx::Size& input_visible_size, | 404 const gfx::Size& input_visible_size, |
405 media::VideoCodecProfile output_profile, | 405 media::VideoCodecProfile output_profile, |
406 uint32_t initial_bitrate, | 406 uint32_t initial_bitrate, |
407 media::VideoEncodeAccelerator::Client* client) { | 407 media::VideoEncodeAccelerator::Client* client) { |
408 DCHECK(RenderThreadImpl::current()); | 408 DCHECK(RenderThreadImpl::current()); |
409 DCHECK_EQ(client, host_); | 409 DCHECK_EQ(client, host_); |
410 | 410 |
411 if (input_format != media::PIXEL_FORMAT_I420) | 411 if (input_format != media::PIXEL_FORMAT_I420) |
412 return false; | 412 return false; |
413 | 413 |
414 if (output_profile != media::VP8PROFILE_ANY && | 414 if (output_profile != media::VP8PROFILE_ANY && |
415 output_profile != media::VP9PROFILE_ANY) | 415 output_profile != media::VP9PROFILE_PROFILE0) |
416 return false; | 416 return false; |
417 | 417 |
418 media_task_runner_->PostTask( | 418 media_task_runner_->PostTask( |
419 FROM_HERE, | 419 FROM_HERE, |
420 base::Bind(&VideoEncoderShim::EncoderImpl::Initialize, | 420 base::Bind(&VideoEncoderShim::EncoderImpl::Initialize, |
421 base::Unretained(encoder_impl_.get()), input_format, | 421 base::Unretained(encoder_impl_.get()), input_format, |
422 input_visible_size, output_profile, initial_bitrate)); | 422 input_visible_size, output_profile, initial_bitrate)); |
423 | 423 |
424 return true; | 424 return true; |
425 } | 425 } |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
483 } | 483 } |
484 | 484 |
485 void VideoEncoderShim::OnNotifyError( | 485 void VideoEncoderShim::OnNotifyError( |
486 media::VideoEncodeAccelerator::Error error) { | 486 media::VideoEncodeAccelerator::Error error) { |
487 DCHECK(RenderThreadImpl::current()); | 487 DCHECK(RenderThreadImpl::current()); |
488 | 488 |
489 host_->NotifyError(error); | 489 host_->NotifyError(error); |
490 } | 490 } |
491 | 491 |
492 } // namespace content | 492 } // namespace content |
OLD | NEW |