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

Side by Side Diff: content/renderer/media/video_track_recorder.cc

Issue 1809853002: MediaRecorder: Tune complexity settings for VP9 encoding (second go) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/media/video_track_recorder.h" 5 #include "content/renderer/media/video_track_recorder.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 codec_config_.g_w / codec_config_.g_h; 289 codec_config_.g_w / codec_config_.g_h;
290 } 290 }
291 // Both VP8/VP9 configuration should be Variable BitRate by default. 291 // Both VP8/VP9 configuration should be Variable BitRate by default.
292 DCHECK_EQ(VPX_VBR, codec_config_.rc_end_usage); 292 DCHECK_EQ(VPX_VBR, codec_config_.rc_end_usage);
293 if (use_vp9_) { 293 if (use_vp9_) {
294 // Number of frames to consume before producing output. 294 // Number of frames to consume before producing output.
295 codec_config_.g_lag_in_frames = 0; 295 codec_config_.g_lag_in_frames = 0;
296 296
297 // DCHECK that the profile selected by default is I420 (magic number 0). 297 // DCHECK that the profile selected by default is I420 (magic number 0).
298 DCHECK_EQ(0u, codec_config_.g_profile); 298 DCHECK_EQ(0u, codec_config_.g_profile);
299
300 // Values of VP8E_SET_CPUUSED greater than 0 will increase encoder speed at
301 // the expense of quality up to a maximum value of 16 for VP9, by tuning the
302 // target time spent encoding the frame. Go from 12 to 6 depending on the
303 // amount of cores available in the system.
304 const int kCpuUsed = std::max(6, 13 - base::SysInfo::NumberOfProcessors());
305 result = vpx_codec_control(encoder_.get(), VP8E_SET_CPUUSED, kCpuUsed);
306 DLOG_IF(WARNING, VPX_CODEC_OK != result) << "VP8E_SET_CPUUSED failed";
307 } else { 299 } else {
308 // VP8 always produces frames instantaneously. 300 // VP8 always produces frames instantaneously.
309 DCHECK_EQ(0u, codec_config_.g_lag_in_frames); 301 DCHECK_EQ(0u, codec_config_.g_lag_in_frames);
310 } 302 }
311 303
312 DCHECK(size.width()); 304 DCHECK(size.width());
313 DCHECK(size.height()); 305 DCHECK(size.height());
314 codec_config_.g_w = size.width(); 306 codec_config_.g_w = size.width();
315 codec_config_.g_h = size.height(); 307 codec_config_.g_h = size.height();
316 codec_config_.g_pass = VPX_RC_ONE_PASS; 308 codec_config_.g_pass = VPX_RC_ONE_PASS;
(...skipping 22 matching lines...) Expand all
339 std::min(8, (base::SysInfo::NumberOfProcessors() + 1) / 2); 331 std::min(8, (base::SysInfo::NumberOfProcessors() + 1) / 2);
340 332
341 // Number of frames to consume before producing output. 333 // Number of frames to consume before producing output.
342 codec_config_.g_lag_in_frames = 0; 334 codec_config_.g_lag_in_frames = 0;
343 335
344 DCHECK(!encoder_); 336 DCHECK(!encoder_);
345 encoder_.reset(new vpx_codec_ctx_t); 337 encoder_.reset(new vpx_codec_ctx_t);
346 const vpx_codec_err_t ret = vpx_codec_enc_init(encoder_.get(), interface, 338 const vpx_codec_err_t ret = vpx_codec_enc_init(encoder_.get(), interface,
347 &codec_config_, kNoFlags); 339 &codec_config_, kNoFlags);
348 DCHECK_EQ(VPX_CODEC_OK, ret); 340 DCHECK_EQ(VPX_CODEC_OK, ret);
341
342 if (use_vp9_) {
343 // Values of VP8E_SET_CPUUSED greater than 0 will increase encoder speed at
344 // the expense of quality up to a maximum value of 8 for VP9, by tuning the
345 // target time spent encoding the frame. Go from 8 to 5 (values for real
346 // time encoding) depending on the amount of cores available in the system.
347 const int kCpuUsed =
348 std::max(5, 8 - base::SysInfo::NumberOfProcessors() / 2);
349 result = vpx_codec_control(encoder_.get(), VP8E_SET_CPUUSED, kCpuUsed);
350 DLOG_IF(WARNING, VPX_CODEC_OK != result) << "VP8E_SET_CPUUSED failed";
351 }
349 } 352 }
350 353
351 bool VideoTrackRecorder::VpxEncoder::IsInitialized() const { 354 bool VideoTrackRecorder::VpxEncoder::IsInitialized() const {
352 DCHECK(encoding_thread_->task_runner()->BelongsToCurrentThread()); 355 DCHECK(encoding_thread_->task_runner()->BelongsToCurrentThread());
353 return codec_config_.g_timebase.den != 0; 356 return codec_config_.g_timebase.den != 0;
354 } 357 }
355 358
356 base::TimeDelta VideoTrackRecorder::VpxEncoder::CalculateFrameDuration( 359 base::TimeDelta VideoTrackRecorder::VpxEncoder::CalculateFrameDuration(
357 const scoped_refptr<VideoFrame>& frame) { 360 const scoped_refptr<VideoFrame>& frame) {
358 DCHECK(encoding_thread_->task_runner()->BelongsToCurrentThread()); 361 DCHECK(encoding_thread_->task_runner()->BelongsToCurrentThread());
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 encoder_->set_paused(false); 418 encoder_->set_paused(false);
416 } 419 }
417 420
418 void VideoTrackRecorder::OnVideoFrameForTesting( 421 void VideoTrackRecorder::OnVideoFrameForTesting(
419 const scoped_refptr<media::VideoFrame>& frame, 422 const scoped_refptr<media::VideoFrame>& frame,
420 base::TimeTicks timestamp) { 423 base::TimeTicks timestamp) {
421 encoder_->StartFrameEncode(frame, timestamp); 424 encoder_->StartFrameEncode(frame, timestamp);
422 } 425 }
423 426
424 } // namespace content 427 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698