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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 | 70 |
71 // Downscale resolution at most 2 times for CPU reasons. | 71 // Downscale resolution at most 2 times for CPU reasons. |
72 static const int kMaxCpuResolutionDowngrades = 2; | 72 static const int kMaxCpuResolutionDowngrades = 2; |
73 // Downscale framerate at most 4 times. | 73 // Downscale framerate at most 4 times. |
74 static const int kMaxCpuFramerateDowngrades = 4; | 74 static const int kMaxCpuFramerateDowngrades = 4; |
75 | 75 |
76 ViEEncoder(uint32_t number_of_cores, | 76 ViEEncoder(uint32_t number_of_cores, |
77 SendStatisticsProxy* stats_proxy, | 77 SendStatisticsProxy* stats_proxy, |
78 const VideoSendStream::Config::EncoderSettings& settings, | 78 const VideoSendStream::Config::EncoderSettings& settings, |
79 rtc::VideoSinkInterface<VideoFrame>* pre_encode_callback, | 79 rtc::VideoSinkInterface<VideoFrame>* pre_encode_callback, |
80 EncodedFrameObserver* encoder_timing); | 80 EncodedFrameObserver* encoder_timing, |
| 81 std::unique_ptr<OveruseFrameDetector> overuse_detector); |
81 ~ViEEncoder(); | 82 ~ViEEncoder(); |
82 // RegisterProcessThread register |module_process_thread| with those objects | 83 // RegisterProcessThread register |module_process_thread| with those objects |
83 // that use it. Registration has to happen on the thread where | 84 // that use it. Registration has to happen on the thread where |
84 // |module_process_thread| was created (libjingle's worker thread). | 85 // |module_process_thread| was created (libjingle's worker thread). |
85 // TODO(perkj): Replace the use of |module_process_thread| with a TaskQueue. | 86 // TODO(perkj): Replace the use of |module_process_thread| with a TaskQueue. |
86 void RegisterProcessThread(ProcessThread* module_process_thread); | 87 void RegisterProcessThread(ProcessThread* module_process_thread); |
87 void DeRegisterProcessThread(); | 88 void DeRegisterProcessThread(); |
88 | 89 |
89 // Sets the source that will provide I420 video frames. | 90 // Sets the source that will provide I420 video frames. |
90 // |degradation_preference| control whether or not resolution or frame rate | 91 // |degradation_preference| control whether or not resolution or frame rate |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 | 123 |
123 protected: | 124 protected: |
124 // Used for testing. For example the |ScalingObserverInterface| methods must | 125 // Used for testing. For example the |ScalingObserverInterface| methods must |
125 // be called on |encoder_queue_|. | 126 // be called on |encoder_queue_|. |
126 rtc::TaskQueue* encoder_queue() { return &encoder_queue_; } | 127 rtc::TaskQueue* encoder_queue() { return &encoder_queue_; } |
127 | 128 |
128 // webrtc::ScalingObserverInterface implementation. | 129 // webrtc::ScalingObserverInterface implementation. |
129 // These methods are protected for easier testing. | 130 // These methods are protected for easier testing. |
130 void AdaptUp(AdaptReason reason) override; | 131 void AdaptUp(AdaptReason reason) override; |
131 void AdaptDown(AdaptReason reason) override; | 132 void AdaptDown(AdaptReason reason) override; |
| 133 static CpuOveruseOptions GetCpuOveruseOptions(bool full_overuse_time); |
132 | 134 |
133 private: | 135 private: |
134 class ConfigureEncoderTask; | 136 class ConfigureEncoderTask; |
135 class EncodeTask; | 137 class EncodeTask; |
136 class VideoSourceProxy; | 138 class VideoSourceProxy; |
137 | 139 |
138 class VideoFrameInfo { | 140 class VideoFrameInfo { |
139 public: | 141 public: |
140 VideoFrameInfo(int width, | 142 VideoFrameInfo(int width, |
141 int height, | 143 int height, |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 const uint32_t number_of_cores_; | 224 const uint32_t number_of_cores_; |
223 // 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. |
224 int initial_rampup_; | 226 int initial_rampup_; |
225 | 227 |
226 const std::unique_ptr<VideoSourceProxy> source_proxy_; | 228 const std::unique_ptr<VideoSourceProxy> source_proxy_; |
227 EncoderSink* sink_; | 229 EncoderSink* sink_; |
228 const VideoSendStream::Config::EncoderSettings settings_; | 230 const VideoSendStream::Config::EncoderSettings settings_; |
229 const VideoCodecType codec_type_; | 231 const VideoCodecType codec_type_; |
230 | 232 |
231 vcm::VideoSender video_sender_ ACCESS_ON(&encoder_queue_); | 233 vcm::VideoSender video_sender_ ACCESS_ON(&encoder_queue_); |
232 OveruseFrameDetector overuse_detector_ ACCESS_ON(&encoder_queue_); | 234 std::unique_ptr<OveruseFrameDetector> overuse_detector_ |
| 235 ACCESS_ON(&encoder_queue_); |
233 std::unique_ptr<QualityScaler> quality_scaler_ ACCESS_ON(&encoder_queue_); | 236 std::unique_ptr<QualityScaler> quality_scaler_ ACCESS_ON(&encoder_queue_); |
234 | 237 |
235 SendStatisticsProxy* const stats_proxy_; | 238 SendStatisticsProxy* const stats_proxy_; |
236 rtc::VideoSinkInterface<VideoFrame>* const pre_encode_callback_; | 239 rtc::VideoSinkInterface<VideoFrame>* const pre_encode_callback_; |
237 ProcessThread* module_process_thread_; | 240 ProcessThread* module_process_thread_; |
238 rtc::ThreadChecker module_process_thread_checker_; | 241 rtc::ThreadChecker module_process_thread_checker_; |
239 // |thread_checker_| checks that public methods that are related to lifetime | 242 // |thread_checker_| checks that public methods that are related to lifetime |
240 // of ViEEncoder are called on the same thread. | 243 // of ViEEncoder are called on the same thread. |
241 rtc::ThreadChecker thread_checker_; | 244 rtc::ThreadChecker thread_checker_; |
242 | 245 |
243 VideoEncoderConfig encoder_config_ ACCESS_ON(&encoder_queue_); | 246 VideoEncoderConfig encoder_config_ ACCESS_ON(&encoder_queue_); |
244 std::unique_ptr<VideoBitrateAllocator> rate_allocator_ | 247 std::unique_ptr<VideoBitrateAllocator> rate_allocator_ |
245 ACCESS_ON(&encoder_queue_); | 248 ACCESS_ON(&encoder_queue_); |
| 249 // The maximum frame rate of the current codec configuration, as determined |
| 250 // at the last ReconfigureEncoder() call. |
| 251 int max_framerate_ ACCESS_ON(&encoder_queue_); |
246 | 252 |
247 // Set when ConfigureEncoder has been called in order to lazy reconfigure the | 253 // Set when ConfigureEncoder has been called in order to lazy reconfigure the |
248 // encoder on the next frame. | 254 // encoder on the next frame. |
249 bool pending_encoder_reconfiguration_ ACCESS_ON(&encoder_queue_); | 255 bool pending_encoder_reconfiguration_ ACCESS_ON(&encoder_queue_); |
250 rtc::Optional<VideoFrameInfo> last_frame_info_ ACCESS_ON(&encoder_queue_); | 256 rtc::Optional<VideoFrameInfo> last_frame_info_ ACCESS_ON(&encoder_queue_); |
251 uint32_t encoder_start_bitrate_bps_ ACCESS_ON(&encoder_queue_); | 257 uint32_t encoder_start_bitrate_bps_ ACCESS_ON(&encoder_queue_); |
252 size_t max_data_payload_length_ ACCESS_ON(&encoder_queue_); | 258 size_t max_data_payload_length_ ACCESS_ON(&encoder_queue_); |
253 bool nack_enabled_ ACCESS_ON(&encoder_queue_); | 259 bool nack_enabled_ ACCESS_ON(&encoder_queue_); |
254 uint32_t last_observed_bitrate_bps_ ACCESS_ON(&encoder_queue_); | 260 uint32_t last_observed_bitrate_bps_ ACCESS_ON(&encoder_queue_); |
255 bool encoder_paused_and_dropped_frame_ ACCESS_ON(&encoder_queue_); | 261 bool encoder_paused_and_dropped_frame_ ACCESS_ON(&encoder_queue_); |
256 Clock* const clock_; | 262 Clock* const clock_; |
257 // Counters used for deciding if the video resolution or framerate is | 263 // Counters used for deciding if the video resolution or framerate is |
258 // currently restricted, and if so, why, on a per degradation preference | 264 // currently restricted, and if so, why, on a per degradation preference |
259 // basis. | 265 // basis. |
260 // TODO(sprang): Replace this with a state holding a relative overuse measure | 266 // TODO(sprang): Replace this with a state holding a relative overuse measure |
261 // instead, that can be translated into suitable down-scale or fps limit. | 267 // instead, that can be translated into suitable down-scale or fps limit. |
262 std::map<const VideoSendStream::DegradationPreference, AdaptCounter> | 268 std::map<const VideoSendStream::DegradationPreference, AdaptCounter> |
263 adapt_counters_ ACCESS_ON(&encoder_queue_); | 269 adapt_counters_ ACCESS_ON(&encoder_queue_); |
264 // Set depending on degradation preferences. | 270 // Set depending on degradation preferences. |
265 VideoSendStream::DegradationPreference degradation_preference_ | 271 VideoSendStream::DegradationPreference degradation_preference_ |
266 ACCESS_ON(&encoder_queue_); | 272 ACCESS_ON(&encoder_queue_); |
267 | 273 |
268 struct AdaptationRequest { | 274 struct AdaptationRequest { |
269 // The pixel count produced by the source at the time of the adaptation. | 275 // The pixel count produced by the source at the time of the adaptation. |
270 int input_pixel_count_; | 276 int input_pixel_count_; |
271 // Framerate received from the source at the time of the adaptation. | 277 // Framerate received from the source at the time of the adaptation. |
272 int framerate_fps_; | 278 int framerate_fps_; |
| 279 // The selected framerate, as result of downscaling request (if any). |
| 280 rtc::Optional<int> selected_framerate_fps_; |
273 // Indicates if request was to adapt up or down. | 281 // Indicates if request was to adapt up or down. |
274 enum class Mode { kAdaptUp, kAdaptDown } mode_; | 282 enum class Mode { kAdaptUp, kAdaptDown } mode_; |
275 }; | 283 }; |
276 // Stores a snapshot of the last adaptation request triggered by an AdaptUp | 284 // Stores a snapshot of the last adaptation request triggered by an AdaptUp |
277 // or AdaptDown signal. | 285 // or AdaptDown signal. |
278 rtc::Optional<AdaptationRequest> last_adaptation_request_ | 286 rtc::Optional<AdaptationRequest> last_adaptation_request_ |
279 ACCESS_ON(&encoder_queue_); | 287 ACCESS_ON(&encoder_queue_); |
280 | 288 |
281 rtc::RaceChecker incoming_frame_race_checker_ | 289 rtc::RaceChecker incoming_frame_race_checker_ |
282 GUARDED_BY(incoming_frame_race_checker_); | 290 GUARDED_BY(incoming_frame_race_checker_); |
(...skipping 13 matching lines...) Expand all Loading... |
296 // All public methods are proxied to |encoder_queue_|. It must must be | 304 // All public methods are proxied to |encoder_queue_|. It must must be |
297 // destroyed first to make sure no tasks are run that use other members. | 305 // destroyed first to make sure no tasks are run that use other members. |
298 rtc::TaskQueue encoder_queue_; | 306 rtc::TaskQueue encoder_queue_; |
299 | 307 |
300 RTC_DISALLOW_COPY_AND_ASSIGN(ViEEncoder); | 308 RTC_DISALLOW_COPY_AND_ASSIGN(ViEEncoder); |
301 }; | 309 }; |
302 | 310 |
303 } // namespace webrtc | 311 } // namespace webrtc |
304 | 312 |
305 #endif // WEBRTC_VIDEO_VIE_ENCODER_H_ | 313 #endif // WEBRTC_VIDEO_VIE_ENCODER_H_ |
OLD | NEW |