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 #ifndef WEBRTC_VIDEO_VIE_ENCODER_H_ | 11 #ifndef WEBRTC_VIDEO_VIE_ENCODER_H_ |
12 #define WEBRTC_VIDEO_VIE_ENCODER_H_ | 12 #define WEBRTC_VIDEO_VIE_ENCODER_H_ |
13 | 13 |
| 14 #include <map> |
14 #include <memory> | 15 #include <memory> |
15 #include <string> | 16 #include <string> |
16 #include <vector> | 17 #include <vector> |
17 | 18 |
18 #include "webrtc/api/video/video_rotation.h" | 19 #include "webrtc/api/video/video_rotation.h" |
19 #include "webrtc/base/criticalsection.h" | 20 #include "webrtc/base/criticalsection.h" |
20 #include "webrtc/base/event.h" | 21 #include "webrtc/base/event.h" |
21 #include "webrtc/base/sequenced_task_checker.h" | 22 #include "webrtc/base/sequenced_task_checker.h" |
22 #include "webrtc/base/task_queue.h" | 23 #include "webrtc/base/task_queue.h" |
23 #include "webrtc/call/call.h" | 24 #include "webrtc/call/call.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 // Interface for receiving encoded video frames and notifications about | 56 // Interface for receiving encoded video frames and notifications about |
56 // configuration changes. | 57 // configuration changes. |
57 class EncoderSink : public EncodedImageCallback { | 58 class EncoderSink : public EncodedImageCallback { |
58 public: | 59 public: |
59 virtual void OnEncoderConfigurationChanged( | 60 virtual void OnEncoderConfigurationChanged( |
60 std::vector<VideoStream> streams, | 61 std::vector<VideoStream> streams, |
61 int min_transmit_bitrate_bps) = 0; | 62 int min_transmit_bitrate_bps) = 0; |
62 }; | 63 }; |
63 | 64 |
64 // Downscale resolution at most 2 times for CPU reasons. | 65 // Downscale resolution at most 2 times for CPU reasons. |
65 static const int kMaxCpuDowngrades = 2; | 66 static const int kMaxCpuResolutionDowngrades = 2; |
| 67 // Downscale framerate at most 4 times. |
| 68 static const int kMaxCpuFramerateDowngrades = 4; |
66 | 69 |
67 ViEEncoder(uint32_t number_of_cores, | 70 ViEEncoder(uint32_t number_of_cores, |
68 SendStatisticsProxy* stats_proxy, | 71 SendStatisticsProxy* stats_proxy, |
69 const VideoSendStream::Config::EncoderSettings& settings, | 72 const VideoSendStream::Config::EncoderSettings& settings, |
70 rtc::VideoSinkInterface<VideoFrame>* pre_encode_callback, | 73 rtc::VideoSinkInterface<VideoFrame>* pre_encode_callback, |
71 EncodedFrameObserver* encoder_timing); | 74 EncodedFrameObserver* encoder_timing); |
72 ~ViEEncoder(); | 75 ~ViEEncoder(); |
73 // RegisterProcessThread register |module_process_thread| with those objects | 76 // RegisterProcessThread register |module_process_thread| with those objects |
74 // that use it. Registration has to happen on the thread where | 77 // that use it. Registration has to happen on the thread where |
75 // |module_process_thread| was created (libjingle's worker thread). | 78 // |module_process_thread| was created (libjingle's worker thread). |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 const EncodedImage& encoded_image, | 168 const EncodedImage& encoded_image, |
166 const CodecSpecificInfo* codec_specific_info, | 169 const CodecSpecificInfo* codec_specific_info, |
167 const RTPFragmentationHeader* fragmentation) override; | 170 const RTPFragmentationHeader* fragmentation) override; |
168 | 171 |
169 void OnDroppedFrame() override; | 172 void OnDroppedFrame() override; |
170 | 173 |
171 bool EncoderPaused() const; | 174 bool EncoderPaused() const; |
172 void TraceFrameDropStart(); | 175 void TraceFrameDropStart(); |
173 void TraceFrameDropEnd(); | 176 void TraceFrameDropEnd(); |
174 | 177 |
| 178 const std::vector<int>& GetScaleCounters() |
| 179 EXCLUSIVE_LOCKS_REQUIRED(&encoder_queue_); |
| 180 void IncrementScaleCounter(int reason, int delta) |
| 181 EXCLUSIVE_LOCKS_REQUIRED(&encoder_queue_); |
| 182 |
175 rtc::Event shutdown_event_; | 183 rtc::Event shutdown_event_; |
176 | 184 |
177 const uint32_t number_of_cores_; | 185 const uint32_t number_of_cores_; |
178 // Counts how many frames we've dropped in the initial rampup phase. | 186 // Counts how many frames we've dropped in the initial rampup phase. |
179 int initial_rampup_; | 187 int initial_rampup_; |
180 | 188 |
181 const std::unique_ptr<VideoSourceProxy> source_proxy_; | 189 const std::unique_ptr<VideoSourceProxy> source_proxy_; |
182 EncoderSink* sink_; | 190 EncoderSink* sink_; |
183 const VideoSendStream::Config::EncoderSettings settings_; | 191 const VideoSendStream::Config::EncoderSettings settings_; |
184 const VideoCodecType codec_type_; | 192 const VideoCodecType codec_type_; |
(...skipping 18 matching lines...) Expand all Loading... |
203 // encoder on the next frame. | 211 // encoder on the next frame. |
204 bool pending_encoder_reconfiguration_ ACCESS_ON(&encoder_queue_); | 212 bool pending_encoder_reconfiguration_ ACCESS_ON(&encoder_queue_); |
205 rtc::Optional<VideoFrameInfo> last_frame_info_ ACCESS_ON(&encoder_queue_); | 213 rtc::Optional<VideoFrameInfo> last_frame_info_ ACCESS_ON(&encoder_queue_); |
206 uint32_t encoder_start_bitrate_bps_ ACCESS_ON(&encoder_queue_); | 214 uint32_t encoder_start_bitrate_bps_ ACCESS_ON(&encoder_queue_); |
207 size_t max_data_payload_length_ ACCESS_ON(&encoder_queue_); | 215 size_t max_data_payload_length_ ACCESS_ON(&encoder_queue_); |
208 bool nack_enabled_ ACCESS_ON(&encoder_queue_); | 216 bool nack_enabled_ ACCESS_ON(&encoder_queue_); |
209 uint32_t last_observed_bitrate_bps_ ACCESS_ON(&encoder_queue_); | 217 uint32_t last_observed_bitrate_bps_ ACCESS_ON(&encoder_queue_); |
210 bool encoder_paused_and_dropped_frame_ ACCESS_ON(&encoder_queue_); | 218 bool encoder_paused_and_dropped_frame_ ACCESS_ON(&encoder_queue_); |
211 Clock* const clock_; | 219 Clock* const clock_; |
212 // Counters used for deciding if the video resolution is currently | 220 // Counters used for deciding if the video resolution is currently |
213 // restricted, and if so, why. | 221 // restricted, and if so, why, on a per degradation preference basis. |
214 std::vector<int> scale_counter_ ACCESS_ON(&encoder_queue_); | 222 // 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. |
| 224 std::map<const VideoSendStream::DegradationPreference, std::vector<int>> |
| 225 scale_counters_ ACCESS_ON(&encoder_queue_); |
215 // Set depending on degradation preferences | 226 // Set depending on degradation preferences |
216 VideoSendStream::DegradationPreference degradation_preference_ | 227 VideoSendStream::DegradationPreference degradation_preference_ |
217 ACCESS_ON(&encoder_queue_); | 228 ACCESS_ON(&encoder_queue_); |
218 | 229 |
219 struct AdaptationRequest { | 230 struct AdaptationRequest { |
220 // The pixel count produced by the source at the time of the adaptation. | 231 // The pixel count produced by the source at the time of the adaptation. |
221 int input_pixel_count_; | 232 int input_pixel_count_; |
| 233 // Framerate received from the source at the time of the adaptation. |
| 234 int framerate_fps_; |
222 // Indicates if request was to adapt up or down. | 235 // Indicates if request was to adapt up or down. |
223 enum class Mode { kAdaptUp, kAdaptDown } mode_; | 236 enum class Mode { kAdaptUp, kAdaptDown } mode_; |
224 }; | 237 }; |
225 // Stores a snapshot of the last adaptation request triggered by an AdaptUp | 238 // Stores a snapshot of the last adaptation request triggered by an AdaptUp |
226 // or AdaptDown signal. | 239 // or AdaptDown signal. |
227 rtc::Optional<AdaptationRequest> last_adaptation_request_ | 240 rtc::Optional<AdaptationRequest> last_adaptation_request_ |
228 ACCESS_ON(&encoder_queue_); | 241 ACCESS_ON(&encoder_queue_); |
229 | 242 |
230 rtc::RaceChecker incoming_frame_race_checker_ | 243 rtc::RaceChecker incoming_frame_race_checker_ |
231 GUARDED_BY(incoming_frame_race_checker_); | 244 GUARDED_BY(incoming_frame_race_checker_); |
(...skipping 13 matching lines...) Expand all Loading... |
245 // All public methods are proxied to |encoder_queue_|. It must must be | 258 // All public methods are proxied to |encoder_queue_|. It must must be |
246 // destroyed first to make sure no tasks are run that use other members. | 259 // destroyed first to make sure no tasks are run that use other members. |
247 rtc::TaskQueue encoder_queue_; | 260 rtc::TaskQueue encoder_queue_; |
248 | 261 |
249 RTC_DISALLOW_COPY_AND_ASSIGN(ViEEncoder); | 262 RTC_DISALLOW_COPY_AND_ASSIGN(ViEEncoder); |
250 }; | 263 }; |
251 | 264 |
252 } // namespace webrtc | 265 } // namespace webrtc |
253 | 266 |
254 #endif // WEBRTC_VIDEO_VIE_ENCODER_H_ | 267 #endif // WEBRTC_VIDEO_VIE_ENCODER_H_ |
OLD | NEW |