| 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 { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 std::min(8, (base::SysInfo::NumberOfProcessors() + 1) / 2); | 317 std::min(8, (base::SysInfo::NumberOfProcessors() + 1) / 2); |
| 319 | 318 |
| 320 // Number of frames to consume before producing output. | 319 // Number of frames to consume before producing output. |
| 321 codec_config_.g_lag_in_frames = 0; | 320 codec_config_.g_lag_in_frames = 0; |
| 322 | 321 |
| 323 DCHECK(!encoder_); | 322 DCHECK(!encoder_); |
| 324 encoder_.reset(new vpx_codec_ctx_t); | 323 encoder_.reset(new vpx_codec_ctx_t); |
| 325 const vpx_codec_err_t ret = vpx_codec_enc_init(encoder_.get(), interface, | 324 const vpx_codec_err_t ret = vpx_codec_enc_init(encoder_.get(), interface, |
| 326 &codec_config_, kNoFlags); | 325 &codec_config_, kNoFlags); |
| 327 DCHECK_EQ(VPX_CODEC_OK, ret); | 326 DCHECK_EQ(VPX_CODEC_OK, ret); |
| 327 |
| 328 if (use_vp9_) { |
| 329 // Values of VP8E_SET_CPUUSED greater than 0 will increase encoder speed at |
| 330 // the expense of quality up to a maximum value of 8 for VP9, by tuning the |
| 331 // target time spent encoding the frame. Go from 8 to 5 (values for real |
| 332 // time encoding) depending on the amount of cores available in the system. |
| 333 const int kCpuUsed = |
| 334 std::max(5, 8 - base::SysInfo::NumberOfProcessors() / 2); |
| 335 result = vpx_codec_control(encoder_.get(), VP8E_SET_CPUUSED, kCpuUsed); |
| 336 DLOG_IF(WARNING, VPX_CODEC_OK != result) << "VP8E_SET_CPUUSED failed"; |
| 337 } |
| 328 } | 338 } |
| 329 | 339 |
| 330 bool VideoTrackRecorder::VpxEncoder::IsInitialized() const { | 340 bool VideoTrackRecorder::VpxEncoder::IsInitialized() const { |
| 331 DCHECK(encoding_thread_->task_runner()->BelongsToCurrentThread()); | 341 DCHECK(encoding_thread_->task_runner()->BelongsToCurrentThread()); |
| 332 return codec_config_.g_timebase.den != 0; | 342 return codec_config_.g_timebase.den != 0; |
| 333 } | 343 } |
| 334 | 344 |
| 335 base::TimeDelta VideoTrackRecorder::VpxEncoder::CalculateFrameDuration( | 345 base::TimeDelta VideoTrackRecorder::VpxEncoder::CalculateFrameDuration( |
| 336 const scoped_refptr<VideoFrame>& frame) { | 346 const scoped_refptr<VideoFrame>& frame) { |
| 337 DCHECK(encoding_thread_->task_runner()->BelongsToCurrentThread()); | 347 DCHECK(encoding_thread_->task_runner()->BelongsToCurrentThread()); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 |
| OLD | NEW |