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