| 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/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 Loading... |
| 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 // Values of VP8E_SET_CPUUSED greater than 0 will increase encoder speed at |
| 289 // the expense of quality up to a maximum value of 16 for VP9, by tuning the |
| 290 // target time spent encoding the frame. Go from 12 to 6 depending on the |
| 291 // amount of cores available in the system. |
| 292 const int kCpuUsed = std::max(6, 13 - base::SysInfo::NumberOfProcessors()); |
| 293 result = vpx_codec_control(encoder_.get(), VP8E_SET_CPUUSED, kCpuUsed); |
| 294 DLOG_IF(WARNING, VPX_CODEC_OK != result) << "VP8E_SET_CPUUSED failed"; |
| 288 } else { | 295 } else { |
| 289 // VP8 always produces frames instantaneously. | 296 // VP8 always produces frames instantaneously. |
| 290 DCHECK_EQ(0u, codec_config_.g_lag_in_frames); | 297 DCHECK_EQ(0u, codec_config_.g_lag_in_frames); |
| 291 } | 298 } |
| 292 | 299 |
| 293 DCHECK(size.width()); | 300 DCHECK(size.width()); |
| 294 DCHECK(size.height()); | 301 DCHECK(size.height()); |
| 295 codec_config_.g_w = size.width(); | 302 codec_config_.g_w = size.width(); |
| 296 codec_config_.g_h = size.height(); | 303 codec_config_.g_h = size.height(); |
| 297 codec_config_.g_pass = VPX_RC_ONE_PASS; | 304 codec_config_.g_pass = VPX_RC_ONE_PASS; |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 394 encoder_->set_paused(false); | 401 encoder_->set_paused(false); |
| 395 } | 402 } |
| 396 | 403 |
| 397 void VideoTrackRecorder::OnVideoFrameForTesting( | 404 void VideoTrackRecorder::OnVideoFrameForTesting( |
| 398 const scoped_refptr<media::VideoFrame>& frame, | 405 const scoped_refptr<media::VideoFrame>& frame, |
| 399 base::TimeTicks timestamp) { | 406 base::TimeTicks timestamp) { |
| 400 encoder_->StartFrameEncode(frame, timestamp); | 407 encoder_->StartFrameEncode(frame, timestamp); |
| 401 } | 408 } |
| 402 | 409 |
| 403 } // namespace content | 410 } // namespace content |
| OLD | NEW |