OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include "webrtc/modules/video_coding/generic_encoder.h" | 11 #include "webrtc/modules/video_coding/generic_encoder.h" |
12 | 12 |
13 #include <vector> | 13 #include <vector> |
14 | 14 |
15 #include "webrtc/base/checks.h" | 15 #include "webrtc/base/checks.h" |
16 #include "webrtc/base/logging.h" | 16 #include "webrtc/base/logging.h" |
17 #include "webrtc/base/trace_event.h" | 17 #include "webrtc/base/trace_event.h" |
18 #include "webrtc/engine_configurations.h" | 18 #include "webrtc/engine_configurations.h" |
19 #include "webrtc/modules/video_coding/encoded_frame.h" | 19 #include "webrtc/modules/video_coding/encoded_frame.h" |
20 #include "webrtc/modules/video_coding/media_optimization.h" | 20 #include "webrtc/modules/video_coding/media_optimization.h" |
21 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" | 21 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" |
22 | 22 |
23 namespace webrtc { | 23 namespace webrtc { |
24 VCMGenericEncoder::VCMGenericEncoder( | 24 VCMGenericEncoder::VCMGenericEncoder( |
25 VideoEncoder* encoder, | 25 VideoEncoder* encoder, |
26 VideoEncoderRateObserver* rate_observer, | |
27 VCMEncodedFrameCallback* encoded_frame_callback, | 26 VCMEncodedFrameCallback* encoded_frame_callback, |
28 bool internal_source) | 27 bool internal_source) |
29 : encoder_(encoder), | 28 : encoder_(encoder), |
30 rate_observer_(rate_observer), | |
31 vcm_encoded_frame_callback_(encoded_frame_callback), | 29 vcm_encoded_frame_callback_(encoded_frame_callback), |
32 internal_source_(internal_source), | 30 internal_source_(internal_source), |
33 encoder_params_({0, 0, 0, 0}), | 31 encoder_params_({0, 0, 0, 0}), |
34 is_screenshare_(false) {} | 32 is_screenshare_(false) {} |
35 | 33 |
36 VCMGenericEncoder::~VCMGenericEncoder() {} | 34 VCMGenericEncoder::~VCMGenericEncoder() {} |
37 | 35 |
38 int32_t VCMGenericEncoder::Release() { | 36 int32_t VCMGenericEncoder::Release() { |
39 RTC_DCHECK_RUNS_SERIALIZED(&race_checker_); | 37 RTC_DCHECK_RUNS_SERIALIZED(&race_checker_); |
40 TRACE_EVENT0("webrtc", "VCMGenericEncoder::Release"); | 38 TRACE_EVENT0("webrtc", "VCMGenericEncoder::Release"); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 rates_have_changed = | 93 rates_have_changed = |
96 params.target_bitrate != encoder_params_.target_bitrate || | 94 params.target_bitrate != encoder_params_.target_bitrate || |
97 params.input_frame_rate != encoder_params_.input_frame_rate; | 95 params.input_frame_rate != encoder_params_.input_frame_rate; |
98 encoder_params_ = params; | 96 encoder_params_ = params; |
99 } | 97 } |
100 if (channel_parameters_have_changed) | 98 if (channel_parameters_have_changed) |
101 encoder_->SetChannelParameters(params.loss_rate, params.rtt); | 99 encoder_->SetChannelParameters(params.loss_rate, params.rtt); |
102 if (rates_have_changed) { | 100 if (rates_have_changed) { |
103 uint32_t target_bitrate_kbps = (params.target_bitrate + 500) / 1000; | 101 uint32_t target_bitrate_kbps = (params.target_bitrate + 500) / 1000; |
104 encoder_->SetRates(target_bitrate_kbps, params.input_frame_rate); | 102 encoder_->SetRates(target_bitrate_kbps, params.input_frame_rate); |
105 if (rate_observer_) { | |
106 rate_observer_->OnSetRates(params.target_bitrate, | |
107 params.input_frame_rate); | |
108 } | |
109 } | 103 } |
110 } | 104 } |
111 | 105 |
112 EncoderParameters VCMGenericEncoder::GetEncoderParameters() const { | 106 EncoderParameters VCMGenericEncoder::GetEncoderParameters() const { |
113 rtc::CritScope lock(¶ms_lock_); | 107 rtc::CritScope lock(¶ms_lock_); |
114 return encoder_params_; | 108 return encoder_params_; |
115 } | 109 } |
116 | 110 |
117 int32_t VCMGenericEncoder::SetPeriodicKeyFrames(bool enable) { | 111 int32_t VCMGenericEncoder::SetPeriodicKeyFrames(bool enable) { |
118 RTC_DCHECK_RUNS_SERIALIZED(&race_checker_); | 112 RTC_DCHECK_RUNS_SERIALIZED(&race_checker_); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 | 156 |
163 if (media_opt_) { | 157 if (media_opt_) { |
164 media_opt_->UpdateWithEncodedData(encoded_image); | 158 media_opt_->UpdateWithEncodedData(encoded_image); |
165 if (internal_source_) | 159 if (internal_source_) |
166 return media_opt_->DropFrame(); // Signal to encoder to drop next frame. | 160 return media_opt_->DropFrame(); // Signal to encoder to drop next frame. |
167 } | 161 } |
168 return VCM_OK; | 162 return VCM_OK; |
169 } | 163 } |
170 | 164 |
171 } // namespace webrtc | 165 } // namespace webrtc |
OLD | NEW |