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