| 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 775 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 786 if (IsInitialized()) { | 786 if (IsInitialized()) { |
| 787 // TODO(mcasas) VP8 quirk/optimisation: If the new |size| is strictly less- | 787 // TODO(mcasas) VP8 quirk/optimisation: If the new |size| is strictly less- |
| 788 // than-or-equal than the old size, in terms of area, the existing encoder | 788 // than-or-equal than the old size, in terms of area, the existing encoder |
| 789 // instance could be reused after changing |codec_config_.{g_w,g_h}|. | 789 // instance could be reused after changing |codec_config_.{g_w,g_h}|. |
| 790 DVLOG(1) << "Destroying/Re-Creating encoder for new frame size: " | 790 DVLOG(1) << "Destroying/Re-Creating encoder for new frame size: " |
| 791 << gfx::Size(codec_config_.g_w, codec_config_.g_h).ToString() | 791 << gfx::Size(codec_config_.g_w, codec_config_.g_h).ToString() |
| 792 << " --> " << size.ToString() << (use_vp9_ ? " vp9" : " vp8"); | 792 << " --> " << size.ToString() << (use_vp9_ ? " vp9" : " vp8"); |
| 793 encoder_.reset(); | 793 encoder_.reset(); |
| 794 } | 794 } |
| 795 | 795 |
| 796 const vpx_codec_iface_t* interface = | 796 const vpx_codec_iface_t* codec_interface = |
| 797 use_vp9_ ? vpx_codec_vp9_cx() : vpx_codec_vp8_cx(); | 797 use_vp9_ ? vpx_codec_vp9_cx() : vpx_codec_vp8_cx(); |
| 798 vpx_codec_err_t result = | 798 vpx_codec_err_t result = vpx_codec_enc_config_default( |
| 799 vpx_codec_enc_config_default(interface, &codec_config_, 0 /* reserved */); | 799 codec_interface, &codec_config_, 0 /* reserved */); |
| 800 DCHECK_EQ(VPX_CODEC_OK, result); | 800 DCHECK_EQ(VPX_CODEC_OK, result); |
| 801 | 801 |
| 802 DCHECK_EQ(320u, codec_config_.g_w); | 802 DCHECK_EQ(320u, codec_config_.g_w); |
| 803 DCHECK_EQ(240u, codec_config_.g_h); | 803 DCHECK_EQ(240u, codec_config_.g_h); |
| 804 DCHECK_EQ(256u, codec_config_.rc_target_bitrate); | 804 DCHECK_EQ(256u, codec_config_.rc_target_bitrate); |
| 805 // Use the selected bitrate or adjust default bit rate to account for the | 805 // Use the selected bitrate or adjust default bit rate to account for the |
| 806 // actual size. Note: |rc_target_bitrate| units are kbit per second. | 806 // actual size. Note: |rc_target_bitrate| units are kbit per second. |
| 807 if (bits_per_second_ > 0) { | 807 if (bits_per_second_ > 0) { |
| 808 codec_config_.rc_target_bitrate = bits_per_second_ / 1000; | 808 codec_config_.rc_target_bitrate = bits_per_second_ / 1000; |
| 809 } else { | 809 } else { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 847 codec_config_.kf_min_dist = 0; | 847 codec_config_.kf_min_dist = 0; |
| 848 codec_config_.kf_max_dist = 100; | 848 codec_config_.kf_max_dist = 100; |
| 849 | 849 |
| 850 codec_config_.g_threads = GetNumberOfThreadsForEncoding(); | 850 codec_config_.g_threads = GetNumberOfThreadsForEncoding(); |
| 851 | 851 |
| 852 // Number of frames to consume before producing output. | 852 // Number of frames to consume before producing output. |
| 853 codec_config_.g_lag_in_frames = 0; | 853 codec_config_.g_lag_in_frames = 0; |
| 854 | 854 |
| 855 DCHECK(!encoder_); | 855 DCHECK(!encoder_); |
| 856 encoder_.reset(new vpx_codec_ctx_t); | 856 encoder_.reset(new vpx_codec_ctx_t); |
| 857 const vpx_codec_err_t ret = vpx_codec_enc_init(encoder_.get(), interface, | 857 const vpx_codec_err_t ret = vpx_codec_enc_init( |
| 858 &codec_config_, 0 /* flags */); | 858 encoder_.get(), codec_interface, &codec_config_, 0 /* flags */); |
| 859 DCHECK_EQ(VPX_CODEC_OK, ret); | 859 DCHECK_EQ(VPX_CODEC_OK, ret); |
| 860 | 860 |
| 861 if (use_vp9_) { | 861 if (use_vp9_) { |
| 862 // Values of VP8E_SET_CPUUSED greater than 0 will increase encoder speed at | 862 // Values of VP8E_SET_CPUUSED greater than 0 will increase encoder speed at |
| 863 // the expense of quality up to a maximum value of 8 for VP9, by tuning the | 863 // the expense of quality up to a maximum value of 8 for VP9, by tuning the |
| 864 // target time spent encoding the frame. Go from 8 to 5 (values for real | 864 // target time spent encoding the frame. Go from 8 to 5 (values for real |
| 865 // time encoding) depending on the amount of cores available in the system. | 865 // time encoding) depending on the amount of cores available in the system. |
| 866 const int kCpuUsed = | 866 const int kCpuUsed = |
| 867 std::max(5, 8 - base::SysInfo::NumberOfProcessors() / 2); | 867 std::max(5, 8 - base::SysInfo::NumberOfProcessors() / 2); |
| 868 result = vpx_codec_control(encoder_.get(), VP8E_SET_CPUUSED, kCpuUsed); | 868 result = vpx_codec_control(encoder_.get(), VP8E_SET_CPUUSED, kCpuUsed); |
| (...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1149 encoder_->SetPaused(paused_before_init_); | 1149 encoder_->SetPaused(paused_before_init_); |
| 1150 | 1150 |
| 1151 // StartFrameEncode() will be called on Render IO thread. | 1151 // StartFrameEncode() will be called on Render IO thread. |
| 1152 MediaStreamVideoSink::ConnectToTrack( | 1152 MediaStreamVideoSink::ConnectToTrack( |
| 1153 track_, | 1153 track_, |
| 1154 base::Bind(&VideoTrackRecorder::Encoder::StartFrameEncode, encoder_), | 1154 base::Bind(&VideoTrackRecorder::Encoder::StartFrameEncode, encoder_), |
| 1155 false); | 1155 false); |
| 1156 } | 1156 } |
| 1157 | 1157 |
| 1158 } // namespace content | 1158 } // namespace content |
| OLD | NEW |