Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(780)

Side by Side Diff: webrtc/video/vie_encoder.h

Issue 2871623002: Update video adaptation stats to support degradations in both resolution and framerate. (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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:23 Maybe this can be declared together with the count
åsapersson 2017/05/10 09:54:53 The struct is public.
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
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.
184 class AdaptCounter {
185 public:
186 AdaptCounter();
187 ~AdaptCounter();
sprang_webrtc 2017/05/10 09:34:24 nit: virtual destructor or final class
åsapersson 2017/05/10 09:54:53 Done.
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 const AdaptCounter& GetAdaptCounter()
179 EXCLUSIVE_LOCKS_REQUIRED(&encoder_queue_); 218 EXCLUSIVE_LOCKS_REQUIRED(&encoder_queue_);
180 void IncrementScaleCounter(int reason, int delta) 219 void IncrementFramerateCounter(AdaptReason reason, int delta)
220 EXCLUSIVE_LOCKS_REQUIRED(&encoder_queue_);
kthelgason 2017/05/09 11:50:15 I've been using the RUN_ON macro for asserting tha
åsapersson 2017/05/10 08:24:45 Done.
221 void IncrementResolutionCounter(AdaptReason reason, int delta)
222 EXCLUSIVE_LOCKS_REQUIRED(&encoder_queue_);
223 void UpdateAdaptationStats(AdaptReason reason)
224 EXCLUSIVE_LOCKS_REQUIRED(&encoder_queue_);
225 ViEEncoder::AdaptCounts GetActiveCounts(AdaptReason reason)
181 EXCLUSIVE_LOCKS_REQUIRED(&encoder_queue_); 226 EXCLUSIVE_LOCKS_REQUIRED(&encoder_queue_);
182 227
183 rtc::Event shutdown_event_; 228 rtc::Event shutdown_event_;
184 229
185 const uint32_t number_of_cores_; 230 const uint32_t number_of_cores_;
186 // Counts how many frames we've dropped in the initial rampup phase. 231 // Counts how many frames we've dropped in the initial rampup phase.
187 int initial_rampup_; 232 int initial_rampup_;
188 233
189 const std::unique_ptr<VideoSourceProxy> source_proxy_; 234 const std::unique_ptr<VideoSourceProxy> source_proxy_;
190 EncoderSink* sink_; 235 EncoderSink* sink_;
(...skipping 19 matching lines...) Expand all
210 // Set when ConfigureEncoder has been called in order to lazy reconfigure the 255 // Set when ConfigureEncoder has been called in order to lazy reconfigure the
211 // encoder on the next frame. 256 // encoder on the next frame.
212 bool pending_encoder_reconfiguration_ ACCESS_ON(&encoder_queue_); 257 bool pending_encoder_reconfiguration_ ACCESS_ON(&encoder_queue_);
213 rtc::Optional<VideoFrameInfo> last_frame_info_ ACCESS_ON(&encoder_queue_); 258 rtc::Optional<VideoFrameInfo> last_frame_info_ ACCESS_ON(&encoder_queue_);
214 uint32_t encoder_start_bitrate_bps_ ACCESS_ON(&encoder_queue_); 259 uint32_t encoder_start_bitrate_bps_ ACCESS_ON(&encoder_queue_);
215 size_t max_data_payload_length_ ACCESS_ON(&encoder_queue_); 260 size_t max_data_payload_length_ ACCESS_ON(&encoder_queue_);
216 bool nack_enabled_ ACCESS_ON(&encoder_queue_); 261 bool nack_enabled_ ACCESS_ON(&encoder_queue_);
217 uint32_t last_observed_bitrate_bps_ ACCESS_ON(&encoder_queue_); 262 uint32_t last_observed_bitrate_bps_ ACCESS_ON(&encoder_queue_);
218 bool encoder_paused_and_dropped_frame_ ACCESS_ON(&encoder_queue_); 263 bool encoder_paused_and_dropped_frame_ ACCESS_ON(&encoder_queue_);
219 Clock* const clock_; 264 Clock* const clock_;
220 // Counters used for deciding if the video resolution is currently 265 // Counters used for deciding if the video resolution or framerate is
221 // restricted, and if so, why, on a per degradation preference basis. 266 // currently restricted, and if so, why, on a per degradation preference
267 // basis.
222 // TODO(sprang): Replace this with a state holding a relative overuse measure 268 // 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. 269 // instead, that can be translated into suitable down-scale or fps limit.
224 std::map<const VideoSendStream::DegradationPreference, std::vector<int>> 270 std::map<const VideoSendStream::DegradationPreference, AdaptCounter>
225 scale_counters_ ACCESS_ON(&encoder_queue_); 271 adapt_counters_ ACCESS_ON(&encoder_queue_);
226 // Set depending on degradation preferences 272 // Set depending on degradation preferences.
227 VideoSendStream::DegradationPreference degradation_preference_ 273 VideoSendStream::DegradationPreference degradation_preference_
228 ACCESS_ON(&encoder_queue_); 274 ACCESS_ON(&encoder_queue_);
229 275
230 struct AdaptationRequest { 276 struct AdaptationRequest {
231 // The pixel count produced by the source at the time of the adaptation. 277 // The pixel count produced by the source at the time of the adaptation.
232 int input_pixel_count_; 278 int input_pixel_count_;
233 // Framerate received from the source at the time of the adaptation. 279 // Framerate received from the source at the time of the adaptation.
234 int framerate_fps_; 280 int framerate_fps_;
235 // Indicates if request was to adapt up or down. 281 // Indicates if request was to adapt up or down.
236 enum class Mode { kAdaptUp, kAdaptDown } mode_; 282 enum class Mode { kAdaptUp, kAdaptDown } mode_;
(...skipping 21 matching lines...) Expand all
258 // 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
259 // 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.
260 rtc::TaskQueue encoder_queue_; 306 rtc::TaskQueue encoder_queue_;
261 307
262 RTC_DISALLOW_COPY_AND_ASSIGN(ViEEncoder); 308 RTC_DISALLOW_COPY_AND_ASSIGN(ViEEncoder);
263 }; 309 };
264 310
265 } // namespace webrtc 311 } // namespace webrtc
266 312
267 #endif // WEBRTC_VIDEO_VIE_ENCODER_H_ 313 #endif // WEBRTC_VIDEO_VIE_ENCODER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698