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

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

Issue 1732083002: VideoTrackRecorder: limit VP9 cpu usage and quality (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Simplified video_track_unittests in the same way as media_recorder_handler_unittest 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 | content/renderer/media/video_track_recorder_unittest.cc » ('j') | 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 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 // than-or-equal than the old size, in terms of area, the existing encoder 253 // than-or-equal than the old size, in terms of area, the existing encoder
254 // instance could be reused after changing |codec_config_.{g_w,g_h}|. 254 // instance could be reused after changing |codec_config_.{g_w,g_h}|.
255 DVLOG(1) << "Destroying/Re-Creating encoder for new frame size: " 255 DVLOG(1) << "Destroying/Re-Creating encoder for new frame size: "
256 << gfx::Size(codec_config_.g_w, codec_config_.g_h).ToString() 256 << gfx::Size(codec_config_.g_w, codec_config_.g_h).ToString()
257 << " --> " << size.ToString() << (use_vp9_ ? " vp9" : " vp8"); 257 << " --> " << size.ToString() << (use_vp9_ ? " vp9" : " vp8");
258 encoder_.reset(); 258 encoder_.reset();
259 } 259 }
260 260
261 const vpx_codec_iface_t* interface = 261 const vpx_codec_iface_t* interface =
262 use_vp9_ ? vpx_codec_vp9_cx() : vpx_codec_vp8_cx(); 262 use_vp9_ ? vpx_codec_vp9_cx() : vpx_codec_vp8_cx();
263 const vpx_codec_err_t result = vpx_codec_enc_config_default(interface, 263 vpx_codec_err_t result =
264 &codec_config_, 264 vpx_codec_enc_config_default(interface, &codec_config_, 0 /* reserved */);
265 0 /* reserved */);
266 DCHECK_EQ(VPX_CODEC_OK, result); 265 DCHECK_EQ(VPX_CODEC_OK, result);
267 266
268 DCHECK_EQ(320u, codec_config_.g_w); 267 DCHECK_EQ(320u, codec_config_.g_w);
269 DCHECK_EQ(240u, codec_config_.g_h); 268 DCHECK_EQ(240u, codec_config_.g_h);
270 DCHECK_EQ(256u, codec_config_.rc_target_bitrate); 269 DCHECK_EQ(256u, codec_config_.rc_target_bitrate);
271 // Use the selected bitrate or adjust default bit rate to account for the 270 // Use the selected bitrate or adjust default bit rate to account for the
272 // actual size. 271 // actual size.
273 if (bits_per_second_ > 0) { 272 if (bits_per_second_ > 0) {
274 codec_config_.rc_target_bitrate = bits_per_second_; 273 codec_config_.rc_target_bitrate = bits_per_second_;
275 } else { 274 } else {
276 codec_config_.rc_target_bitrate = size.GetArea() * 275 codec_config_.rc_target_bitrate = size.GetArea() *
277 codec_config_.rc_target_bitrate / 276 codec_config_.rc_target_bitrate /
278 codec_config_.g_w / codec_config_.g_h; 277 codec_config_.g_w / codec_config_.g_h;
279 } 278 }
280 // Both VP8/VP9 configuration should be Variable BitRate by default. 279 // Both VP8/VP9 configuration should be Variable BitRate by default.
281 DCHECK_EQ(VPX_VBR, codec_config_.rc_end_usage); 280 DCHECK_EQ(VPX_VBR, codec_config_.rc_end_usage);
282 if (use_vp9_) { 281 if (use_vp9_) {
283 // Number of frames to consume before producing output. 282 // Number of frames to consume before producing output.
284 codec_config_.g_lag_in_frames = 0; 283 codec_config_.g_lag_in_frames = 0;
285 284
286 // DCHECK that the profile selected by default is I420 (magic number 0). 285 // DCHECK that the profile selected by default is I420 (magic number 0).
287 DCHECK_EQ(0u, codec_config_.g_profile); 286 DCHECK_EQ(0u, codec_config_.g_profile);
287
288 // Request the lowest-CPU usage that VP9 supports. Values greater than 0
289 // will increase encoder speed at the expense of quality. Note that this is
290 // configured via the same parameter as for VP8.
291 const int kCpuUsage = 6;
292 result = vpx_codec_control(encoder_.get(), VP8E_SET_CPUUSED, kCpuUsage);
miu 2016/02/25 20:22:09 6 is actually a high-end setting (4 being the high
mcasas 2016/02/26 01:34:32 Let's go for a compromise of 10. Users can still u
293 DLOG_IF(WARNING, VPX_CODEC_OK != result) << "Failed to set CPUUSED";
294
295 // Clamping the quantizer constrains the worst-case quality and CPU usage.
296 codec_config_.rc_min_quantizer = 20;
miu 2016/02/25 20:22:09 When you clamp the quantizer values this way, the
mcasas 2016/02/26 01:34:32 Done.
297 codec_config_.rc_max_quantizer = 30;
288 } else { 298 } else {
289 // VP8 always produces frames instantaneously. 299 // VP8 always produces frames instantaneously.
290 DCHECK_EQ(0u, codec_config_.g_lag_in_frames); 300 DCHECK_EQ(0u, codec_config_.g_lag_in_frames);
291 } 301 }
292 302
293 DCHECK(size.width()); 303 DCHECK(size.width());
294 DCHECK(size.height()); 304 DCHECK(size.height());
295 codec_config_.g_w = size.width(); 305 codec_config_.g_w = size.width();
296 codec_config_.g_h = size.height(); 306 codec_config_.g_h = size.height();
297 codec_config_.g_pass = VPX_RC_ONE_PASS; 307 codec_config_.g_pass = VPX_RC_ONE_PASS;
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 encoder_->set_paused(false); 404 encoder_->set_paused(false);
395 } 405 }
396 406
397 void VideoTrackRecorder::OnVideoFrameForTesting( 407 void VideoTrackRecorder::OnVideoFrameForTesting(
398 const scoped_refptr<media::VideoFrame>& frame, 408 const scoped_refptr<media::VideoFrame>& frame,
399 base::TimeTicks timestamp) { 409 base::TimeTicks timestamp) {
400 encoder_->StartFrameEncode(frame, timestamp); 410 encoder_->StartFrameEncode(frame, timestamp);
401 } 411 }
402 412
403 } // namespace content 413 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/renderer/media/video_track_recorder_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698