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 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
55 public: | 55 public: |
56 // Interface for receiving encoded video frames and notifications about | 56 // Interface for receiving encoded video frames and notifications about |
57 // configuration changes. | 57 // configuration changes. |
58 class EncoderSink : public EncodedImageCallback { | 58 class EncoderSink : public EncodedImageCallback { |
59 public: | 59 public: |
60 virtual void OnEncoderConfigurationChanged( | 60 virtual void OnEncoderConfigurationChanged( |
61 std::vector<VideoStream> streams, | 61 std::vector<VideoStream> streams, |
62 int min_transmit_bitrate_bps) = 0; | 62 int min_transmit_bitrate_bps) = 0; |
63 }; | 63 }; |
64 | 64 |
65 struct AdaptCounts { | |
66 int resolution = 0; | |
67 int fps = 0; | |
68 }; | |
sprang_webrtc
2017/05/10 09:34:24
Maybe add a comment what the numbers mean, especia
åsapersson
2017/05/10 09:54:53
Done.
| |
69 | |
65 // Downscale resolution at most 2 times for CPU reasons. | 70 // Downscale resolution at most 2 times for CPU reasons. |
66 static const int kMaxCpuResolutionDowngrades = 2; | 71 static const int kMaxCpuResolutionDowngrades = 2; |
67 // Downscale framerate at most 4 times. | 72 // Downscale framerate at most 4 times. |
68 static const int kMaxCpuFramerateDowngrades = 4; | 73 static const int kMaxCpuFramerateDowngrades = 4; |
69 | 74 |
70 ViEEncoder(uint32_t number_of_cores, | 75 ViEEncoder(uint32_t number_of_cores, |
71 SendStatisticsProxy* stats_proxy, | 76 SendStatisticsProxy* stats_proxy, |
72 const VideoSendStream::Config::EncoderSettings& settings, | 77 const VideoSendStream::Config::EncoderSettings& settings, |
73 rtc::VideoSinkInterface<VideoFrame>* pre_encode_callback, | 78 rtc::VideoSinkInterface<VideoFrame>* pre_encode_callback, |
74 EncodedFrameObserver* encoder_timing); | 79 EncodedFrameObserver* encoder_timing); |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
168 const EncodedImage& encoded_image, | 173 const EncodedImage& encoded_image, |
169 const CodecSpecificInfo* codec_specific_info, | 174 const CodecSpecificInfo* codec_specific_info, |
170 const RTPFragmentationHeader* fragmentation) override; | 175 const RTPFragmentationHeader* fragmentation) override; |
171 | 176 |
172 void OnDroppedFrame() override; | 177 void OnDroppedFrame() override; |
173 | 178 |
174 bool EncoderPaused() const; | 179 bool EncoderPaused() const; |
175 void TraceFrameDropStart(); | 180 void TraceFrameDropStart(); |
176 void TraceFrameDropEnd(); | 181 void TraceFrameDropEnd(); |
177 | 182 |
178 const std::vector<int>& GetScaleCounters() | 183 // Class holding adaptation information. |
179 EXCLUSIVE_LOCKS_REQUIRED(&encoder_queue_); | 184 class AdaptCounter { |
180 void IncrementScaleCounter(int reason, int delta) | 185 public: |
181 EXCLUSIVE_LOCKS_REQUIRED(&encoder_queue_); | 186 AdaptCounter(); |
187 ~AdaptCounter(); | |
188 | |
189 // Get number of adaptation downscales for |reason|. | |
190 AdaptCounts Counts(int reason) const; | |
191 | |
192 std::string ToString() const; | |
193 | |
194 void IncrementFramerate(int reason, int delta); | |
195 void IncrementResolution(int reason, int delta); | |
196 | |
197 // Gets the total number of downgrades (for all adapt reasons). | |
198 int FramerateCount() const; | |
199 int ResolutionCount() const; | |
200 int TotalCount() const; | |
201 | |
202 // Gets the total number of downgrades for |reason|. | |
203 int FramerateCount(int reason) const; | |
204 int ResolutionCount(int reason) const; | |
205 int TotalCount(int reason) const; | |
206 | |
207 private: | |
208 std::string ToString(const std::vector<int>& counters) const; | |
209 int Count(const std::vector<int>& counters) const; | |
210 | |
211 // Degradation counters holding number of framerate/resolution reductions | |
212 // per adapt reason. | |
213 std::vector<int> fps_counters_; | |
214 std::vector<int> resolution_counters_; | |
215 }; | |
216 | |
217 AdaptCounter& GetAdaptCounter() RUN_ON(&encoder_queue_); | |
218 const AdaptCounter& GetConstAdaptCounter() RUN_ON(&encoder_queue_); | |
219 void UpdateAdaptationStats(AdaptReason reason) RUN_ON(&encoder_queue_); | |
220 AdaptCounts GetActiveCounts(AdaptReason reason) RUN_ON(&encoder_queue_); | |
182 | 221 |
183 rtc::Event shutdown_event_; | 222 rtc::Event shutdown_event_; |
184 | 223 |
185 const uint32_t number_of_cores_; | 224 const uint32_t number_of_cores_; |
186 // Counts how many frames we've dropped in the initial rampup phase. | 225 // Counts how many frames we've dropped in the initial rampup phase. |
187 int initial_rampup_; | 226 int initial_rampup_; |
188 | 227 |
189 const std::unique_ptr<VideoSourceProxy> source_proxy_; | 228 const std::unique_ptr<VideoSourceProxy> source_proxy_; |
190 EncoderSink* sink_; | 229 EncoderSink* sink_; |
191 const VideoSendStream::Config::EncoderSettings settings_; | 230 const VideoSendStream::Config::EncoderSettings settings_; |
(...skipping 18 matching lines...) Expand all Loading... | |
210 // Set when ConfigureEncoder has been called in order to lazy reconfigure the | 249 // Set when ConfigureEncoder has been called in order to lazy reconfigure the |
211 // encoder on the next frame. | 250 // encoder on the next frame. |
212 bool pending_encoder_reconfiguration_ ACCESS_ON(&encoder_queue_); | 251 bool pending_encoder_reconfiguration_ ACCESS_ON(&encoder_queue_); |
213 rtc::Optional<VideoFrameInfo> last_frame_info_ ACCESS_ON(&encoder_queue_); | 252 rtc::Optional<VideoFrameInfo> last_frame_info_ ACCESS_ON(&encoder_queue_); |
214 uint32_t encoder_start_bitrate_bps_ ACCESS_ON(&encoder_queue_); | 253 uint32_t encoder_start_bitrate_bps_ ACCESS_ON(&encoder_queue_); |
215 size_t max_data_payload_length_ ACCESS_ON(&encoder_queue_); | 254 size_t max_data_payload_length_ ACCESS_ON(&encoder_queue_); |
216 bool nack_enabled_ ACCESS_ON(&encoder_queue_); | 255 bool nack_enabled_ ACCESS_ON(&encoder_queue_); |
217 uint32_t last_observed_bitrate_bps_ ACCESS_ON(&encoder_queue_); | 256 uint32_t last_observed_bitrate_bps_ ACCESS_ON(&encoder_queue_); |
218 bool encoder_paused_and_dropped_frame_ ACCESS_ON(&encoder_queue_); | 257 bool encoder_paused_and_dropped_frame_ ACCESS_ON(&encoder_queue_); |
219 Clock* const clock_; | 258 Clock* const clock_; |
220 // Counters used for deciding if the video resolution is currently | 259 // Counters used for deciding if the video resolution or framerate is |
221 // restricted, and if so, why, on a per degradation preference basis. | 260 // currently restricted, and if so, why, on a per degradation preference |
261 // basis. | |
222 // TODO(sprang): Replace this with a state holding a relative overuse measure | 262 // TODO(sprang): Replace this with a state holding a relative overuse measure |
223 // instead, that can be translated into suitable down-scale or fps limit. | 263 // instead, that can be translated into suitable down-scale or fps limit. |
224 std::map<const VideoSendStream::DegradationPreference, std::vector<int>> | 264 std::map<const VideoSendStream::DegradationPreference, AdaptCounter> |
225 scale_counters_ ACCESS_ON(&encoder_queue_); | 265 adapt_counters_ ACCESS_ON(&encoder_queue_); |
226 // Set depending on degradation preferences | 266 // Set depending on degradation preferences. |
227 VideoSendStream::DegradationPreference degradation_preference_ | 267 VideoSendStream::DegradationPreference degradation_preference_ |
228 ACCESS_ON(&encoder_queue_); | 268 ACCESS_ON(&encoder_queue_); |
229 | 269 |
230 struct AdaptationRequest { | 270 struct AdaptationRequest { |
231 // The pixel count produced by the source at the time of the adaptation. | 271 // The pixel count produced by the source at the time of the adaptation. |
232 int input_pixel_count_; | 272 int input_pixel_count_; |
233 // Framerate received from the source at the time of the adaptation. | 273 // Framerate received from the source at the time of the adaptation. |
234 int framerate_fps_; | 274 int framerate_fps_; |
235 // Indicates if request was to adapt up or down. | 275 // Indicates if request was to adapt up or down. |
236 enum class Mode { kAdaptUp, kAdaptDown } mode_; | 276 enum class Mode { kAdaptUp, kAdaptDown } mode_; |
(...skipping 21 matching lines...) Expand all Loading... | |
258 // All public methods are proxied to |encoder_queue_|. It must must be | 298 // All public methods are proxied to |encoder_queue_|. It must must be |
259 // destroyed first to make sure no tasks are run that use other members. | 299 // destroyed first to make sure no tasks are run that use other members. |
260 rtc::TaskQueue encoder_queue_; | 300 rtc::TaskQueue encoder_queue_; |
261 | 301 |
262 RTC_DISALLOW_COPY_AND_ASSIGN(ViEEncoder); | 302 RTC_DISALLOW_COPY_AND_ASSIGN(ViEEncoder); |
263 }; | 303 }; |
264 | 304 |
265 } // namespace webrtc | 305 } // namespace webrtc |
266 | 306 |
267 #endif // WEBRTC_VIDEO_VIE_ENCODER_H_ | 307 #endif // WEBRTC_VIDEO_VIE_ENCODER_H_ |
OLD | NEW |