blob: ea9cfd60db764684e7dea645a922efdfe53f08a6 [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
stefan@webrtc.org07b45a52012-02-02 08:37:48 +00002 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
niklase@google.com470e71d2011-07-07 08:21:25 +00003 *
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
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef VIDEO_VIDEO_STREAM_ENCODER_H_
12#define VIDEO_VIDEO_STREAM_ENCODER_H_
niklase@google.com470e71d2011-07-07 08:21:25 +000013
Yuwei Huangd9f99c12017-10-24 15:40:52 -070014#include <atomic>
sprangc5d62e22017-04-02 23:53:04 -070015#include <map>
kwiberg27f982b2016-03-01 11:52:33 -080016#include <memory>
perkj376b1922016-05-02 11:35:24 -070017#include <string>
mflodman@webrtc.org02270cd2015-02-06 13:10:19 +000018#include <vector>
mflodman@webrtc.orgd6ec3862012-10-25 11:30:29 +000019
Jiawei Ou4206a0a2018-07-20 15:49:43 -070020#include "api/video/video_bitrate_allocator.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020021#include "api/video/video_rotation.h"
Niels Möllerc6ce9c52018-05-11 11:15:30 +020022#include "api/video/video_sink_interface.h"
Niels Möller0327c2d2018-05-21 14:09:31 +020023#include "api/video/video_stream_encoder_interface.h"
Niels Möller213618e2018-07-24 09:29:58 +020024#include "api/video/video_stream_encoder_observer.h"
25#include "api/video/video_stream_encoder_settings.h"
Erik Språng6a7baa72019-02-26 18:31:00 +010026#include "api/video_codecs/video_codec.h"
Niels Möller0327c2d2018-05-21 14:09:31 +020027#include "api/video_codecs/video_encoder.h"
Niels Möller6bb5ab92019-01-11 11:11:10 +010028#include "modules/video_coding/utility/frame_dropper.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020029#include "modules/video_coding/utility/quality_scaler.h"
30#include "modules/video_coding/video_coding_impl.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020031#include "rtc_base/event.h"
Erik Språng7ca375c2019-02-06 16:20:17 +010032#include "rtc_base/experiments/rate_control_settings.h"
Erik Språng6a7baa72019-02-26 18:31:00 +010033#include "rtc_base/race_checker.h"
Niels Möller6bb5ab92019-01-11 11:11:10 +010034#include "rtc_base/rate_statistics.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020035#include "rtc_base/sequenced_task_checker.h"
36#include "rtc_base/task_queue.h"
Erik Språng7ca375c2019-02-06 16:20:17 +010037#include "video/encoder_bitrate_adjuster.h"
Erik Språng6a7baa72019-02-26 18:31:00 +010038#include "video/frame_encode_timer.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020039#include "video/overuse_frame_detector.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000040
41namespace webrtc {
mflodman@webrtc.org84d17832011-12-01 17:02:23 +000042
Sebastian Jansson652dc912018-04-19 17:09:15 +020043// VideoStreamEncoder represent a video encoder that accepts raw video frames as
44// input and produces an encoded bit stream.
45// Usage:
46// Instantiate.
47// Call SetSink.
48// Call SetSource.
49// Call ConfigureEncoder with the codec settings.
50// Call Stop() when done.
51class VideoStreamEncoder : public VideoStreamEncoderInterface,
52 private EncodedImageCallback,
53 // Protected only to provide access to tests.
54 protected AdaptationObserverInterface {
55 public:
mflodmancc3d4422017-08-03 08:27:51 -070056 VideoStreamEncoder(uint32_t number_of_cores,
Niels Möller213618e2018-07-24 09:29:58 +020057 VideoStreamEncoderObserver* encoder_stats_observer,
58 const VideoStreamEncoderSettings& settings,
mflodmancc3d4422017-08-03 08:27:51 -070059 std::unique_ptr<OveruseFrameDetector> overuse_detector);
Stefan Holmerdbdb3a02018-07-17 16:03:46 +020060 ~VideoStreamEncoder() override;
niklase@google.com470e71d2011-07-07 08:21:25 +000061
Sebastian Jansson652dc912018-04-19 17:09:15 +020062 void SetSource(rtc::VideoSourceInterface<VideoFrame>* source,
Taylor Brandstetter49fcc102018-05-16 14:20:41 -070063 const DegradationPreference& degradation_preference) override;
perkj803d97f2016-11-01 11:45:46 -070064
Sebastian Jansson652dc912018-04-19 17:09:15 +020065 void SetSink(EncoderSink* sink, bool rotation_applied) override;
mflodman@webrtc.org02270cd2015-02-06 13:10:19 +000066
perkj26091b12016-09-01 01:17:40 -070067 // TODO(perkj): Can we remove VideoCodec.startBitrate ?
Sebastian Jansson652dc912018-04-19 17:09:15 +020068 void SetStartBitrate(int start_bitrate_bps) override;
mflodman@webrtc.org9ec883e2012-03-05 17:12:41 +000069
Niels Möller0327c2d2018-05-21 14:09:31 +020070 void SetBitrateAllocationObserver(
Sebastian Jansson652dc912018-04-19 17:09:15 +020071 VideoBitrateAllocationObserver* bitrate_observer) override;
sprang1a646ee2016-12-01 06:34:11 -080072
Per512ecb32016-09-23 15:52:06 +020073 void ConfigureEncoder(VideoEncoderConfig config,
Niels Möllerf1338562018-04-26 09:51:47 +020074 size_t max_data_payload_length) override;
niklase@google.com470e71d2011-07-07 08:21:25 +000075
perkj26091b12016-09-01 01:17:40 -070076 // Permanently stop encoding. After this method has returned, it is
77 // guaranteed that no encoded frames will be delivered to the sink.
Sebastian Jansson652dc912018-04-19 17:09:15 +020078 void Stop() override;
perkj26091b12016-09-01 01:17:40 -070079
Sebastian Jansson652dc912018-04-19 17:09:15 +020080 void SendKeyFrame() override;
mflodman@webrtc.orgd6ec3862012-10-25 11:30:29 +000081
mflodman86aabb22016-03-11 15:44:32 +010082 void OnBitrateUpdated(uint32_t bitrate_bps,
stefan@webrtc.orgedeea912014-12-08 19:46:23 +000083 uint8_t fraction_lost,
Sebastian Jansson652dc912018-04-19 17:09:15 +020084 int64_t round_trip_time_ms) override;
pwestin@webrtc.org49888ce2012-04-27 05:25:53 +000085
perkj803d97f2016-11-01 11:45:46 -070086 protected:
kthelgason876222f2016-11-29 01:44:11 -080087 // Used for testing. For example the |ScalingObserverInterface| methods must
88 // be called on |encoder_queue_|.
perkj803d97f2016-11-01 11:45:46 -070089 rtc::TaskQueue* encoder_queue() { return &encoder_queue_; }
90
Niels Möllerd692ef92017-10-04 15:28:55 +020091 // AdaptationObserverInterface implementation.
perkj803d97f2016-11-01 11:45:46 -070092 // These methods are protected for easier testing.
sprangb1ca0732017-02-01 08:38:12 -080093 void AdaptUp(AdaptReason reason) override;
94 void AdaptDown(AdaptReason reason) override;
perkj803d97f2016-11-01 11:45:46 -070095
mflodman@webrtc.org84d17832011-12-01 17:02:23 +000096 private:
perkja49cbd32016-09-16 07:53:41 -070097 class VideoSourceProxy;
perkj26091b12016-09-01 01:17:40 -070098
kthelgason93f16d72017-01-16 06:15:23 -080099 class VideoFrameInfo {
100 public:
Yves Gerey665174f2018-06-19 15:03:05 +0200101 VideoFrameInfo(int width, int height, bool is_texture)
102 : width(width), height(height), is_texture(is_texture) {}
perkjfa10b552016-10-02 23:45:26 -0700103 int width;
104 int height;
perkjfa10b552016-10-02 23:45:26 -0700105 bool is_texture;
kthelgason93f16d72017-01-16 06:15:23 -0800106 int pixel_count() const { return width * height; }
perkjfa10b552016-10-02 23:45:26 -0700107 };
108
Pera48ddb72016-09-29 11:48:50 +0200109 void ConfigureEncoderOnTaskQueue(VideoEncoderConfig config,
Niels Möllerf1338562018-04-26 09:51:47 +0200110 size_t max_data_payload_length);
Niels Möllera8b15082018-02-07 13:42:09 +0100111 void ReconfigureEncoder() RTC_RUN_ON(&encoder_queue_);
perkj26091b12016-09-01 01:17:40 -0700112
Erik Språng7ca375c2019-02-06 16:20:17 +0100113 void ConfigureQualityScaler(const VideoEncoder::EncoderInfo& encoder_info);
kthelgason2bc68642017-02-07 07:02:22 -0800114
perkja49cbd32016-09-16 07:53:41 -0700115 // Implements VideoSinkInterface.
116 void OnFrame(const VideoFrame& video_frame) override;
Ilya Nikolaevskiyd79314f2017-10-23 10:45:37 +0200117 void OnDiscardedFrame() override;
perkja49cbd32016-09-16 07:53:41 -0700118
Sebastian Janssona3177052018-04-10 13:05:49 +0200119 void MaybeEncodeVideoFrame(const VideoFrame& frame,
120 int64_t time_when_posted_in_ms);
121
perkjd52063f2016-09-07 06:32:18 -0700122 void EncodeVideoFrame(const VideoFrame& frame,
123 int64_t time_when_posted_in_ms);
Sebastian Janssona3177052018-04-10 13:05:49 +0200124 // Indicates wether frame should be dropped because the pixel count is too
125 // large for the current bitrate configuration.
126 bool DropDueToSize(uint32_t pixel_count) const RTC_RUN_ON(&encoder_queue_);
perkj26091b12016-09-01 01:17:40 -0700127
128 // Implements EncodedImageCallback.
129 EncodedImageCallback::Result OnEncodedImage(
130 const EncodedImage& encoded_image,
131 const CodecSpecificInfo* codec_specific_info,
132 const RTPFragmentationHeader* fragmentation) override;
133
Ilya Nikolaevskiyd79314f2017-10-23 10:45:37 +0200134 void OnDroppedFrame(EncodedImageCallback::DropReason reason) override;
kthelgason876222f2016-11-29 01:44:11 -0800135
perkj26091b12016-09-01 01:17:40 -0700136 bool EncoderPaused() const;
137 void TraceFrameDropStart();
138 void TraceFrameDropEnd();
139
Niels Möller6bb5ab92019-01-11 11:11:10 +0100140 VideoBitrateAllocation GetBitrateAllocationAndNotifyObserver(
141 const uint32_t target_bitrate_bps,
142 uint32_t framerate_fps) RTC_RUN_ON(&encoder_queue_);
143 uint32_t GetInputFramerateFps() RTC_RUN_ON(&encoder_queue_);
Erik Språngd7329ca2019-02-21 21:19:53 +0100144 void SetEncoderRates(const VideoBitrateAllocation& bitrate_allocation,
145 uint32_t framerate_fps) RTC_RUN_ON(&encoder_queue_);
Niels Möller6bb5ab92019-01-11 11:11:10 +0100146
asapersson09f05612017-05-15 23:40:18 -0700147 // Class holding adaptation information.
148 class AdaptCounter final {
149 public:
150 AdaptCounter();
151 ~AdaptCounter();
152
153 // Get number of adaptation downscales for |reason|.
Niels Möller213618e2018-07-24 09:29:58 +0200154 VideoStreamEncoderObserver::AdaptationSteps Counts(int reason) const;
asapersson09f05612017-05-15 23:40:18 -0700155
156 std::string ToString() const;
157
asaperssonf7e294d2017-06-13 23:25:22 -0700158 void IncrementFramerate(int reason);
159 void IncrementResolution(int reason);
160 void DecrementFramerate(int reason);
161 void DecrementResolution(int reason);
162 void DecrementFramerate(int reason, int cur_fps);
asapersson09f05612017-05-15 23:40:18 -0700163
164 // Gets the total number of downgrades (for all adapt reasons).
165 int FramerateCount() const;
166 int ResolutionCount() const;
asapersson09f05612017-05-15 23:40:18 -0700167
168 // Gets the total number of downgrades for |reason|.
169 int FramerateCount(int reason) const;
170 int ResolutionCount(int reason) const;
171 int TotalCount(int reason) const;
172
173 private:
174 std::string ToString(const std::vector<int>& counters) const;
175 int Count(const std::vector<int>& counters) const;
asaperssonf7e294d2017-06-13 23:25:22 -0700176 void MoveCount(std::vector<int>* counters, int from_reason);
asapersson09f05612017-05-15 23:40:18 -0700177
178 // Degradation counters holding number of framerate/resolution reductions
179 // per adapt reason.
180 std::vector<int> fps_counters_;
181 std::vector<int> resolution_counters_;
182 };
183
danilchapa37de392017-09-09 04:17:22 -0700184 AdaptCounter& GetAdaptCounter() RTC_RUN_ON(&encoder_queue_);
185 const AdaptCounter& GetConstAdaptCounter() RTC_RUN_ON(&encoder_queue_);
186 void UpdateAdaptationStats(AdaptReason reason) RTC_RUN_ON(&encoder_queue_);
Niels Möller213618e2018-07-24 09:29:58 +0200187 VideoStreamEncoderObserver::AdaptationSteps GetActiveCounts(
188 AdaptReason reason) RTC_RUN_ON(&encoder_queue_);
Erik Språng7ca375c2019-02-06 16:20:17 +0100189 void RunPostEncode(EncodedImage encoded_image,
Niels Möller6bb5ab92019-01-11 11:11:10 +0100190 int64_t time_sent_us,
Erik Språng7ca375c2019-02-06 16:20:17 +0100191 int temporal_index);
Erik Språngd7329ca2019-02-21 21:19:53 +0100192 bool HasInternalSource() const RTC_RUN_ON(&encoder_queue_);
Erik Språng6a7baa72019-02-26 18:31:00 +0100193 void ReleaseEncoder() RTC_RUN_ON(&encoder_queue_);
sprangc5d62e22017-04-02 23:53:04 -0700194
perkj26091b12016-09-01 01:17:40 -0700195 rtc::Event shutdown_event_;
stefan@webrtc.orgbfacda62013-03-27 16:36:01 +0000196
pbos@webrtc.orgb238d122013-04-09 13:41:51 +0000197 const uint32_t number_of_cores_;
Kári Tristan Helgason639602a2018-08-02 10:51:40 +0200198 // Counts how many frames we've dropped in the initial framedrop phase.
199 int initial_framedrop_;
200 const bool initial_framedrop_on_bwe_enabled_;
201 bool has_seen_first_significant_bwe_change_ = false;
perkja49cbd32016-09-16 07:53:41 -0700202
Åsa Perssona945aee2018-04-24 16:53:25 +0200203 const bool quality_scaling_experiment_enabled_;
204
perkja49cbd32016-09-16 07:53:41 -0700205 const std::unique_ptr<VideoSourceProxy> source_proxy_;
Per512ecb32016-09-23 15:52:06 +0200206 EncoderSink* sink_;
Niels Möller213618e2018-07-24 09:29:58 +0200207 const VideoStreamEncoderSettings settings_;
Erik Språng7ca375c2019-02-06 16:20:17 +0100208 const RateControlSettings rate_control_settings_;
niklase@google.com470e71d2011-07-07 08:21:25 +0000209
Niels Möllera8b15082018-02-07 13:42:09 +0100210 const std::unique_ptr<OveruseFrameDetector> overuse_detector_
211 RTC_PT_GUARDED_BY(&encoder_queue_);
Yves Gerey665174f2018-06-19 15:03:05 +0200212 std::unique_ptr<QualityScaler> quality_scaler_ RTC_GUARDED_BY(&encoder_queue_)
Niels Möllera8b15082018-02-07 13:42:09 +0100213 RTC_PT_GUARDED_BY(&encoder_queue_);
pwestin@webrtc.org49888ce2012-04-27 05:25:53 +0000214
Niels Möller213618e2018-07-24 09:29:58 +0200215 VideoStreamEncoderObserver* const encoder_stats_observer_;
perkja49cbd32016-09-16 07:53:41 -0700216 // |thread_checker_| checks that public methods that are related to lifetime
mflodmancc3d4422017-08-03 08:27:51 -0700217 // of VideoStreamEncoder are called on the same thread.
perkja49cbd32016-09-16 07:53:41 -0700218 rtc::ThreadChecker thread_checker_;
mflodman@webrtc.org84d17832011-12-01 17:02:23 +0000219
Niels Möller1e062892018-02-07 10:18:32 +0100220 VideoEncoderConfig encoder_config_ RTC_GUARDED_BY(&encoder_queue_);
Niels Möller4db138e2018-04-19 09:04:13 +0200221 std::unique_ptr<VideoEncoder> encoder_ RTC_GUARDED_BY(&encoder_queue_)
222 RTC_PT_GUARDED_BY(&encoder_queue_);
Erik Språng6a7baa72019-02-26 18:31:00 +0100223 bool encoder_initialized_;
Erik Språng08127a92016-11-16 16:41:30 +0100224 std::unique_ptr<VideoBitrateAllocator> rate_allocator_
Yves Gerey665174f2018-06-19 15:03:05 +0200225 RTC_GUARDED_BY(&encoder_queue_) RTC_PT_GUARDED_BY(&encoder_queue_);
sprangfda496a2017-06-15 04:21:07 -0700226 // The maximum frame rate of the current codec configuration, as determined
227 // at the last ReconfigureEncoder() call.
Niels Möller1e062892018-02-07 10:18:32 +0100228 int max_framerate_ RTC_GUARDED_BY(&encoder_queue_);
mflodman@webrtc.org84d17832011-12-01 17:02:23 +0000229
perkjfa10b552016-10-02 23:45:26 -0700230 // Set when ConfigureEncoder has been called in order to lazy reconfigure the
231 // encoder on the next frame.
Niels Möller1e062892018-02-07 10:18:32 +0100232 bool pending_encoder_reconfiguration_ RTC_GUARDED_BY(&encoder_queue_);
Mirta Dvornicic1ec2a162018-12-10 09:47:34 +0000233 // Set when configuration must create a new encoder object, e.g.,
234 // because of a codec change.
235 bool pending_encoder_creation_ RTC_GUARDED_BY(&encoder_queue_);
Danil Chapovalovb9b146c2018-06-15 12:28:07 +0200236 absl::optional<VideoFrameInfo> last_frame_info_
Niels Möller1e062892018-02-07 10:18:32 +0100237 RTC_GUARDED_BY(&encoder_queue_);
238 int crop_width_ RTC_GUARDED_BY(&encoder_queue_);
239 int crop_height_ RTC_GUARDED_BY(&encoder_queue_);
240 uint32_t encoder_start_bitrate_bps_ RTC_GUARDED_BY(&encoder_queue_);
241 size_t max_data_payload_length_ RTC_GUARDED_BY(&encoder_queue_);
Niels Möller1e062892018-02-07 10:18:32 +0100242 uint32_t last_observed_bitrate_bps_ RTC_GUARDED_BY(&encoder_queue_);
243 bool encoder_paused_and_dropped_frame_ RTC_GUARDED_BY(&encoder_queue_);
perkj26091b12016-09-01 01:17:40 -0700244 Clock* const clock_;
asapersson09f05612017-05-15 23:40:18 -0700245 // Counters used for deciding if the video resolution or framerate is
246 // currently restricted, and if so, why, on a per degradation preference
247 // basis.
sprangc5d62e22017-04-02 23:53:04 -0700248 // TODO(sprang): Replace this with a state holding a relative overuse measure
249 // instead, that can be translated into suitable down-scale or fps limit.
Taylor Brandstetter49fcc102018-05-16 14:20:41 -0700250 std::map<const DegradationPreference, AdaptCounter> adapt_counters_
Niels Möller1e062892018-02-07 10:18:32 +0100251 RTC_GUARDED_BY(&encoder_queue_);
Taylor Brandstetter49fcc102018-05-16 14:20:41 -0700252 // Set depending on degradation preferences.
253 DegradationPreference degradation_preference_ RTC_GUARDED_BY(&encoder_queue_);
perkj803d97f2016-11-01 11:45:46 -0700254
sprang84a37592017-02-10 07:04:27 -0800255 struct AdaptationRequest {
256 // The pixel count produced by the source at the time of the adaptation.
257 int input_pixel_count_;
sprangc5d62e22017-04-02 23:53:04 -0700258 // Framerate received from the source at the time of the adaptation.
259 int framerate_fps_;
sprang84a37592017-02-10 07:04:27 -0800260 // Indicates if request was to adapt up or down.
261 enum class Mode { kAdaptUp, kAdaptDown } mode_;
262 };
263 // Stores a snapshot of the last adaptation request triggered by an AdaptUp
264 // or AdaptDown signal.
Danil Chapovalovb9b146c2018-06-15 12:28:07 +0200265 absl::optional<AdaptationRequest> last_adaptation_request_
Niels Möller1e062892018-02-07 10:18:32 +0100266 RTC_GUARDED_BY(&encoder_queue_);
perkj803d97f2016-11-01 11:45:46 -0700267
268 rtc::RaceChecker incoming_frame_race_checker_
danilchapa37de392017-09-09 04:17:22 -0700269 RTC_GUARDED_BY(incoming_frame_race_checker_);
Yuwei Huangd9f99c12017-10-24 15:40:52 -0700270 std::atomic<int> posted_frames_waiting_for_encode_;
perkj26091b12016-09-01 01:17:40 -0700271 // Used to make sure incoming time stamp is increasing for every frame.
danilchapa37de392017-09-09 04:17:22 -0700272 int64_t last_captured_timestamp_ RTC_GUARDED_BY(incoming_frame_race_checker_);
perkj26091b12016-09-01 01:17:40 -0700273 // Delta used for translating between NTP and internal timestamps.
danilchapa37de392017-09-09 04:17:22 -0700274 const int64_t delta_ntp_internal_ms_
275 RTC_GUARDED_BY(incoming_frame_race_checker_);
perkj26091b12016-09-01 01:17:40 -0700276
danilchapa37de392017-09-09 04:17:22 -0700277 int64_t last_frame_log_ms_ RTC_GUARDED_BY(incoming_frame_race_checker_);
Niels Möller1e062892018-02-07 10:18:32 +0100278 int captured_frame_count_ RTC_GUARDED_BY(&encoder_queue_);
279 int dropped_frame_count_ RTC_GUARDED_BY(&encoder_queue_);
Danil Chapovalovb9b146c2018-06-15 12:28:07 +0200280 absl::optional<VideoFrame> pending_frame_ RTC_GUARDED_BY(&encoder_queue_);
Sebastian Janssona3177052018-04-10 13:05:49 +0200281 int64_t pending_frame_post_time_us_ RTC_GUARDED_BY(&encoder_queue_);
asapersson6ffb67d2016-09-12 00:10:45 -0700282
Ilya Nikolaevskiy71aee3a2019-02-18 13:01:26 +0100283 VideoFrame::UpdateRect accumulated_update_rect_
284 RTC_GUARDED_BY(&encoder_queue_);
285
danilchapa37de392017-09-09 04:17:22 -0700286 VideoBitrateAllocationObserver* bitrate_observer_
Niels Möller1e062892018-02-07 10:18:32 +0100287 RTC_GUARDED_BY(&encoder_queue_);
Danil Chapovalovb9b146c2018-06-15 12:28:07 +0200288 absl::optional<int64_t> last_parameters_update_ms_
Niels Möller1e062892018-02-07 10:18:32 +0100289 RTC_GUARDED_BY(&encoder_queue_);
sprang1a646ee2016-12-01 06:34:11 -0800290
Erik Språnge2fd86a2018-10-24 11:32:39 +0200291 VideoEncoder::EncoderInfo encoder_info_ RTC_GUARDED_BY(&encoder_queue_);
Erik Språngd7329ca2019-02-21 21:19:53 +0100292 VideoEncoderFactory::CodecInfo codec_info_ RTC_GUARDED_BY(&encoder_queue_);
Erik Språng6a7baa72019-02-26 18:31:00 +0100293 VideoBitrateAllocation last_bitrate_allocation_
294 RTC_GUARDED_BY(&encoder_queue_);
295 uint32_t last_framerate_fps_ RTC_GUARDED_BY(&encoder_queue_);
296 VideoCodec send_codec_ RTC_GUARDED_BY(&encoder_queue_);
Niels Möller6bb5ab92019-01-11 11:11:10 +0100297
Erik Språng6a7baa72019-02-26 18:31:00 +0100298 FrameDropper frame_dropper_ RTC_GUARDED_BY(&encoder_queue_);
Niels Möller6bb5ab92019-01-11 11:11:10 +0100299 // If frame dropper is not force disabled, frame dropping might still be
300 // disabled if VideoEncoder::GetEncoderInfo() indicates that the encoder has a
301 // trusted rate controller. This is determined on a per-frame basis, as the
302 // encoder behavior might dynamically change.
303 bool force_disable_frame_dropper_ RTC_GUARDED_BY(&encoder_queue_);
304 RateStatistics input_framerate_ RTC_GUARDED_BY(&encoder_queue_);
305 // Incremented on worker thread whenever |frame_dropper_| determines that a
306 // frame should be dropped. Decremented on whichever thread runs
307 // OnEncodedImage(), which is only called by one thread but not necessarily
308 // the worker thread.
309 std::atomic<int> pending_frame_drops_;
Erik Språnge2fd86a2018-10-24 11:32:39 +0200310
Erik Språng7ca375c2019-02-06 16:20:17 +0100311 std::unique_ptr<EncoderBitrateAdjuster> bitrate_adjuster_
312 RTC_GUARDED_BY(&encoder_queue_);
313
Erik Språngd7329ca2019-02-21 21:19:53 +0100314 // TODO(sprang): Change actually support keyframe per simulcast stream, or
315 // turn this into a simple bool |pending_keyframe_request_|.
316 std::vector<FrameType> next_frame_types_ RTC_GUARDED_BY(&encoder_queue_);
317
Erik Språng6a7baa72019-02-26 18:31:00 +0100318 FrameEncodeTimer frame_encoder_timer_;
319
320 // Experiment groups parsed from field trials for realtime video ([0]) and
321 // screenshare ([1]). 0 means no group specified. Positive values are
322 // experiment group numbers incremented by 1.
323 const std::array<uint8_t, 2> experiment_groups_;
324
perkj26091b12016-09-01 01:17:40 -0700325 // All public methods are proxied to |encoder_queue_|. It must must be
326 // destroyed first to make sure no tasks are run that use other members.
327 rtc::TaskQueue encoder_queue_;
perkja49cbd32016-09-16 07:53:41 -0700328
mflodmancc3d4422017-08-03 08:27:51 -0700329 RTC_DISALLOW_COPY_AND_ASSIGN(VideoStreamEncoder);
niklase@google.com470e71d2011-07-07 08:21:25 +0000330};
mflodman@webrtc.org84d17832011-12-01 17:02:23 +0000331
332} // namespace webrtc
333
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200334#endif // VIDEO_VIDEO_STREAM_ENCODER_H_