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

Side by Side Diff: content/renderer/pepper/video_encoder_shim.cc

Issue 1769593002: Add 4 VP9 profiles to the media::VideoCodecProfile enum. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@hevc-codec-7
Patch Set: Use VP9 profile0 by default instead of profile3 Created 4 years, 9 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 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
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:
78 case media::VP9PROFILE_PROFILE1:
79 case media::VP9PROFILE_PROFILE2:
80 case media::VP9PROFILE_PROFILE3:
81 // TODO(servolk): These numbers should be adjusted for different profiles.
ddorwin 2016/03/25 22:51:21 Bug?
servolk 2016/03/25 23:52:01 Done.
78 *vpx_codec = vpx_codec_vp9_cx(); 82 *vpx_codec = vpx_codec_vp9_cx();
79 *min_quantizer = kVp9DefaultMinQuantizer; 83 *min_quantizer = kVp9DefaultMinQuantizer;
80 *max_quantizer = kVp9DefaultMaxQuantizer; 84 *max_quantizer = kVp9DefaultMaxQuantizer;
81 *cpu_used = kVp9DefaultCpuUsed; 85 *cpu_used = kVp9DefaultCpuUsed;
82 break; 86 break;
83 default: 87 default:
84 *vpx_codec = nullptr; 88 *vpx_codec = nullptr;
85 *min_quantizer = 0; 89 *min_quantizer = 0;
86 *max_quantizer = 0; 90 *max_quantizer = 0;
87 *cpu_used = 0; 91 *cpu_used = 0;
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 config_.rc_max_quantizer = max_quantizer; 193 config_.rc_max_quantizer = max_quantizer;
190 // Do not saturate CPU utilization just for encoding. On a lower-end system 194 // 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 195 // 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. 196 // more cores, allow half of the cores to be used for encoding.
193 config_.g_threads = 197 config_.g_threads =
194 std::min(kMaxNumThreads, (base::SysInfo::NumberOfProcessors() + 1) / 2); 198 std::min(kMaxNumThreads, (base::SysInfo::NumberOfProcessors() + 1) / 2);
195 199
196 // Use Q/CQ mode if no target bitrate is given. Note that in the VP8/CQ case 200 // 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. 201 // the meaning of rc_target_bitrate changes to target maximum rate.
198 if (initial_bitrate == 0) { 202 if (initial_bitrate == 0) {
199 if (output_profile == media::VP9PROFILE_ANY) { 203 if (output_profile == media::VP9PROFILE_PROFILE0 ||
204 output_profile == media::VP9PROFILE_PROFILE1 ||
205 output_profile == media::VP9PROFILE_PROFILE2 ||
206 output_profile == media::VP9PROFILE_PROFILE3) {
200 config_.rc_end_usage = VPX_Q; 207 config_.rc_end_usage = VPX_Q;
201 } else if (output_profile == media::VP8PROFILE_ANY) { 208 } else if (output_profile == media::VP8PROFILE_ANY) {
202 config_.rc_end_usage = VPX_CQ; 209 config_.rc_end_usage = VPX_CQ;
203 config_.rc_target_bitrate = kVp8MaxCQBitrate; 210 config_.rc_target_bitrate = kVp8MaxCQBitrate;
204 } 211 }
205 } 212 }
206 213
207 vpx_codec_flags_t flags = 0; 214 vpx_codec_flags_t flags = 0;
208 if (vpx_codec_enc_init(&encoder_, vpx_codec, &config_, flags) != 215 if (vpx_codec_enc_init(&encoder_, vpx_codec, &config_, flags) !=
209 VPX_CODEC_OK) { 216 VPX_CODEC_OK) {
210 NotifyError(media::VideoEncodeAccelerator::kPlatformFailureError); 217 NotifyError(media::VideoEncodeAccelerator::kPlatformFailureError);
211 return; 218 return;
212 } 219 }
213 initialized_ = true; 220 initialized_ = true;
214 221
215 if (vpx_codec_enc_config_set(&encoder_, &config_) != VPX_CODEC_OK) { 222 if (vpx_codec_enc_config_set(&encoder_, &config_) != VPX_CODEC_OK) {
216 NotifyError(media::VideoEncodeAccelerator::kPlatformFailureError); 223 NotifyError(media::VideoEncodeAccelerator::kPlatformFailureError);
217 return; 224 return;
218 } 225 }
219 226
220 if (vpx_codec_control(&encoder_, VP8E_SET_CPUUSED, cpu_used) != 227 if (vpx_codec_control(&encoder_, VP8E_SET_CPUUSED, cpu_used) !=
221 VPX_CODEC_OK) { 228 VPX_CODEC_OK) {
222 NotifyError(media::VideoEncodeAccelerator::kPlatformFailureError); 229 NotifyError(media::VideoEncodeAccelerator::kPlatformFailureError);
223 return; 230 return;
224 } 231 }
225 232
226 if (output_profile == media::VP9PROFILE_ANY) { 233 if (output_profile == media::VP9PROFILE_PROFILE0 ||
234 output_profile == media::VP9PROFILE_PROFILE1 ||
235 output_profile == media::VP9PROFILE_PROFILE2 ||
236 output_profile == media::VP9PROFILE_PROFILE3) {
227 if (vpx_codec_control(&encoder_, VP9E_SET_AQ_MODE, 237 if (vpx_codec_control(&encoder_, VP9E_SET_AQ_MODE,
228 kVp9AqModeCyclicRefresh) != VPX_CODEC_OK) { 238 kVp9AqModeCyclicRefresh) != VPX_CODEC_OK) {
229 NotifyError(media::VideoEncodeAccelerator::kPlatformFailureError); 239 NotifyError(media::VideoEncodeAccelerator::kPlatformFailureError);
230 return; 240 return;
231 } 241 }
232 } 242 }
233 243
234 renderer_task_runner_->PostTask( 244 renderer_task_runner_->PostTask(
235 FROM_HERE, 245 FROM_HERE,
236 base::Bind(&VideoEncoderShim::OnRequireBitstreamBuffers, shim_, 246 base::Bind(&VideoEncoderShim::OnRequireBitstreamBuffers, shim_,
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 // Libvpx and media::VideoEncodeAccelerator are using opposite 392 // Libvpx and media::VideoEncodeAccelerator are using opposite
383 // notions of denominator/numerator. 393 // notions of denominator/numerator.
384 profile.max_framerate_numerator = config.g_timebase.den; 394 profile.max_framerate_numerator = config.g_timebase.den;
385 profile.max_framerate_denominator = config.g_timebase.num; 395 profile.max_framerate_denominator = config.g_timebase.num;
386 profiles.push_back(profile); 396 profiles.push_back(profile);
387 } 397 }
388 398
389 ret = vpx_codec_enc_config_default(vpx_codec_vp9_cx(), &config, 0); 399 ret = vpx_codec_enc_config_default(vpx_codec_vp9_cx(), &config, 0);
390 if (ret == VPX_CODEC_OK) { 400 if (ret == VPX_CODEC_OK) {
391 media::VideoEncodeAccelerator::SupportedProfile profile; 401 media::VideoEncodeAccelerator::SupportedProfile profile;
392 profile.profile = media::VP9PROFILE_ANY;
393 profile.max_resolution = gfx::Size(kMaxWidth, kMaxHeight); 402 profile.max_resolution = gfx::Size(kMaxWidth, kMaxHeight);
394 profile.max_framerate_numerator = config.g_timebase.den; 403 profile.max_framerate_numerator = config.g_timebase.den;
395 profile.max_framerate_denominator = config.g_timebase.num; 404 profile.max_framerate_denominator = config.g_timebase.num;
405 profile.profile = media::VP9PROFILE_PROFILE0;
406 profiles.push_back(profile);
407 profile.profile = media::VP9PROFILE_PROFILE1;
408 profiles.push_back(profile);
409 profile.profile = media::VP9PROFILE_PROFILE2;
410 profiles.push_back(profile);
411 profile.profile = media::VP9PROFILE_PROFILE3;
396 profiles.push_back(profile); 412 profiles.push_back(profile);
397 } 413 }
398 414
399 return profiles; 415 return profiles;
400 } 416 }
401 417
402 bool VideoEncoderShim::Initialize( 418 bool VideoEncoderShim::Initialize(
403 media::VideoPixelFormat input_format, 419 media::VideoPixelFormat input_format,
404 const gfx::Size& input_visible_size, 420 const gfx::Size& input_visible_size,
405 media::VideoCodecProfile output_profile, 421 media::VideoCodecProfile output_profile,
406 uint32_t initial_bitrate, 422 uint32_t initial_bitrate,
407 media::VideoEncodeAccelerator::Client* client) { 423 media::VideoEncodeAccelerator::Client* client) {
408 DCHECK(RenderThreadImpl::current()); 424 DCHECK(RenderThreadImpl::current());
409 DCHECK_EQ(client, host_); 425 DCHECK_EQ(client, host_);
410 426
411 if (input_format != media::PIXEL_FORMAT_I420) 427 if (input_format != media::PIXEL_FORMAT_I420)
412 return false; 428 return false;
413 429
414 if (output_profile != media::VP8PROFILE_ANY && 430 if (output_profile != media::VP8PROFILE_ANY &&
415 output_profile != media::VP9PROFILE_ANY) 431 output_profile != media::VP9PROFILE_PROFILE0 &&
432 output_profile != media::VP9PROFILE_PROFILE1 &&
433 output_profile != media::VP9PROFILE_PROFILE2 &&
434 output_profile != media::VP9PROFILE_PROFILE3)
416 return false; 435 return false;
417 436
418 media_task_runner_->PostTask( 437 media_task_runner_->PostTask(
419 FROM_HERE, 438 FROM_HERE,
420 base::Bind(&VideoEncoderShim::EncoderImpl::Initialize, 439 base::Bind(&VideoEncoderShim::EncoderImpl::Initialize,
421 base::Unretained(encoder_impl_.get()), input_format, 440 base::Unretained(encoder_impl_.get()), input_format,
422 input_visible_size, output_profile, initial_bitrate)); 441 input_visible_size, output_profile, initial_bitrate));
423 442
424 return true; 443 return true;
425 } 444 }
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 } 502 }
484 503
485 void VideoEncoderShim::OnNotifyError( 504 void VideoEncoderShim::OnNotifyError(
486 media::VideoEncodeAccelerator::Error error) { 505 media::VideoEncodeAccelerator::Error error) {
487 DCHECK(RenderThreadImpl::current()); 506 DCHECK(RenderThreadImpl::current());
488 507
489 host_->NotifyError(error); 508 host_->NotifyError(error);
490 } 509 }
491 510
492 } // namespace content 511 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698