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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
167 const EncodedImage& encoded_image, | 170 const EncodedImage& encoded_image, |
168 const CodecSpecificInfo* codec_specific_info, | 171 const CodecSpecificInfo* codec_specific_info, |
169 const RTPFragmentationHeader* fragmentation) override; | 172 const RTPFragmentationHeader* fragmentation) override; |
170 | 173 |
171 void OnDroppedFrame() override; | 174 void OnDroppedFrame() override; |
172 | 175 |
173 bool EncoderPaused() const; | 176 bool EncoderPaused() const; |
174 void TraceFrameDropStart(); | 177 void TraceFrameDropStart(); |
175 void TraceFrameDropEnd(); | 178 void TraceFrameDropEnd(); |
176 | 179 |
180 std::vector<int>* GetScaleCounters() | |
181 EXCLUSIVE_LOCKS_REQUIRED(&encoder_queue_); | |
182 | |
177 rtc::Event shutdown_event_; | 183 rtc::Event shutdown_event_; |
178 | 184 |
179 const uint32_t number_of_cores_; | 185 const uint32_t number_of_cores_; |
180 // 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. |
181 int initial_rampup_; | 187 int initial_rampup_; |
182 | 188 |
183 const std::unique_ptr<VideoSourceProxy> source_proxy_; | 189 const std::unique_ptr<VideoSourceProxy> source_proxy_; |
184 EncoderSink* sink_; | 190 EncoderSink* sink_; |
185 const VideoSendStream::Config::EncoderSettings settings_; | 191 const VideoSendStream::Config::EncoderSettings settings_; |
186 const VideoCodecType codec_type_; | 192 const VideoCodecType codec_type_; |
(...skipping 22 matching lines...) Expand all Loading... | |
209 size_t max_data_payload_length_ ACCESS_ON(&encoder_queue_); | 215 size_t max_data_payload_length_ ACCESS_ON(&encoder_queue_); |
210 bool nack_enabled_ ACCESS_ON(&encoder_queue_); | 216 bool nack_enabled_ ACCESS_ON(&encoder_queue_); |
211 uint32_t last_observed_bitrate_bps_ ACCESS_ON(&encoder_queue_); | 217 uint32_t last_observed_bitrate_bps_ ACCESS_ON(&encoder_queue_); |
212 bool encoder_paused_and_dropped_frame_ ACCESS_ON(&encoder_queue_); | 218 bool encoder_paused_and_dropped_frame_ ACCESS_ON(&encoder_queue_); |
213 bool has_received_sli_ ACCESS_ON(&encoder_queue_); | 219 bool has_received_sli_ ACCESS_ON(&encoder_queue_); |
214 uint8_t picture_id_sli_ ACCESS_ON(&encoder_queue_); | 220 uint8_t picture_id_sli_ ACCESS_ON(&encoder_queue_); |
215 bool has_received_rpsi_ ACCESS_ON(&encoder_queue_); | 221 bool has_received_rpsi_ ACCESS_ON(&encoder_queue_); |
216 uint64_t picture_id_rpsi_ ACCESS_ON(&encoder_queue_); | 222 uint64_t picture_id_rpsi_ ACCESS_ON(&encoder_queue_); |
217 Clock* const clock_; | 223 Clock* const clock_; |
218 // Counters used for deciding if the video resolution is currently | 224 // Counters used for deciding if the video resolution is currently |
219 // restricted, and if so, why. | 225 // restricted, and if so, why, on a per degradation preference basis. |
220 std::vector<int> scale_counter_ ACCESS_ON(&encoder_queue_); | 226 // TODO(sprang): Replace this with a state holding a relative overuse measure |
227 // instead, that can be translated into suitable down-scale or fps limit. | |
228 std::map<const VideoSendStream::DegradationPreference, std::vector<int>> | |
229 scale_counters_ ACCESS_ON(&encoder_queue_); | |
221 // Set depending on degradation preferences | 230 // Set depending on degradation preferences |
222 VideoSendStream::DegradationPreference degradation_preference_ | 231 VideoSendStream::DegradationPreference degradation_preference_ |
223 ACCESS_ON(&encoder_queue_); | 232 ACCESS_ON(&encoder_queue_); |
224 | 233 |
225 struct AdaptationRequest { | 234 struct AdaptationRequest { |
226 // The pixel count produced by the source at the time of the adaptation. | 235 // The pixel count produced by the source at the time of the adaptation. |
227 int input_pixel_count_; | 236 int input_pixel_count_; |
237 // Framerate received from the source at the time of the adaptation. | |
238 int framerate_fps_; | |
nisse-webrtc
2017/03/14 09:00:29
How is that measured? Or is it requested/configure
sprang_webrtc
2017/03/14 14:15:03
This is the measured input fps to the encoder, the
| |
228 // Indicates if request was to adapt up or down. | 239 // Indicates if request was to adapt up or down. |
229 enum class Mode { kAdaptUp, kAdaptDown } mode_; | 240 enum class Mode { kAdaptUp, kAdaptDown } mode_; |
230 }; | 241 }; |
231 // Stores a snapshot of the last adaptation request triggered by an AdaptUp | 242 // Stores a snapshot of the last adaptation request triggered by an AdaptUp |
232 // or AdaptDown signal. | 243 // or AdaptDown signal. |
233 rtc::Optional<AdaptationRequest> last_adaptation_request_ | 244 rtc::Optional<AdaptationRequest> last_adaptation_request_ |
234 ACCESS_ON(&encoder_queue_); | 245 ACCESS_ON(&encoder_queue_); |
235 | 246 |
236 rtc::RaceChecker incoming_frame_race_checker_ | 247 rtc::RaceChecker incoming_frame_race_checker_ |
237 GUARDED_BY(incoming_frame_race_checker_); | 248 GUARDED_BY(incoming_frame_race_checker_); |
(...skipping 13 matching lines...) Expand all Loading... | |
251 // All public methods are proxied to |encoder_queue_|. It must must be | 262 // All public methods are proxied to |encoder_queue_|. It must must be |
252 // destroyed first to make sure no tasks are run that use other members. | 263 // destroyed first to make sure no tasks are run that use other members. |
253 rtc::TaskQueue encoder_queue_; | 264 rtc::TaskQueue encoder_queue_; |
254 | 265 |
255 RTC_DISALLOW_COPY_AND_ASSIGN(ViEEncoder); | 266 RTC_DISALLOW_COPY_AND_ASSIGN(ViEEncoder); |
256 }; | 267 }; |
257 | 268 |
258 } // namespace webrtc | 269 } // namespace webrtc |
259 | 270 |
260 #endif // WEBRTC_VIDEO_VIE_ENCODER_H_ | 271 #endif // WEBRTC_VIDEO_VIE_ENCODER_H_ |
OLD | NEW |