Chromium Code Reviews| 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 // Request the lowest-CPU usage that VP9 supports while keeping a certain | |
| 289 // quality. Values greater than 0 will increase encoder speed at the expense | |
| 290 // of quality. Note: this is configured via the same parameter as for VP8. | |
| 291 const int kCpuUsage = 10; | |
|
miu
2016/02/26 19:27:49
It's important you understand what this does: Inte
mcasas
2016/02/26 22:18:22
Hmmm talking about implementation details
leaking.
| |
| 292 result = vpx_codec_control(encoder_.get(), VP8E_SET_CPUUSED, kCpuUsage); | |
| 293 DLOG_IF(WARNING, VPX_CODEC_OK != result) << "Failed to set CPUUSED"; | |
| 288 } else { | 294 } else { |
| 289 // VP8 always produces frames instantaneously. | 295 // VP8 always produces frames instantaneously. |
| 290 DCHECK_EQ(0u, codec_config_.g_lag_in_frames); | 296 DCHECK_EQ(0u, codec_config_.g_lag_in_frames); |
| 291 } | 297 } |
| 292 | 298 |
| 293 DCHECK(size.width()); | 299 DCHECK(size.width()); |
| 294 DCHECK(size.height()); | 300 DCHECK(size.height()); |
| 295 codec_config_.g_w = size.width(); | 301 codec_config_.g_w = size.width(); |
| 296 codec_config_.g_h = size.height(); | 302 codec_config_.g_h = size.height(); |
| 297 codec_config_.g_pass = VPX_RC_ONE_PASS; | 303 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); | 400 encoder_->set_paused(false); |
| 395 } | 401 } |
| 396 | 402 |
| 397 void VideoTrackRecorder::OnVideoFrameForTesting( | 403 void VideoTrackRecorder::OnVideoFrameForTesting( |
| 398 const scoped_refptr<media::VideoFrame>& frame, | 404 const scoped_refptr<media::VideoFrame>& frame, |
| 399 base::TimeTicks timestamp) { | 405 base::TimeTicks timestamp) { |
| 400 encoder_->StartFrameEncode(frame, timestamp); | 406 encoder_->StartFrameEncode(frame, timestamp); |
| 401 } | 407 } |
| 402 | 408 |
| 403 } // namespace content | 409 } // namespace content |
| OLD | NEW |