niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 1 | /* |
stefan@webrtc.org | 07b45a5 | 2012-02-02 08:37:48 | [diff] [blame] | 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 3 | * |
| 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 Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 11 | #ifndef VIDEO_VIDEO_STREAM_ENCODER_H_ |
| 12 | #define VIDEO_VIDEO_STREAM_ENCODER_H_ |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 13 | |
Yuwei Huang | d9f99c1 | 2017-10-24 22:40:52 | [diff] [blame] | 14 | #include <atomic> |
sprang | c5d62e2 | 2017-04-03 06:53:04 | [diff] [blame] | 15 | #include <map> |
kwiberg | 27f982b | 2016-03-01 19:52:33 | [diff] [blame] | 16 | #include <memory> |
perkj | 376b192 | 2016-05-02 18:35:24 | [diff] [blame] | 17 | #include <string> |
mflodman@webrtc.org | 02270cd | 2015-02-06 13:10:19 | [diff] [blame] | 18 | #include <vector> |
mflodman@webrtc.org | d6ec386 | 2012-10-25 11:30:29 | [diff] [blame] | 19 | |
Jiawei Ou | 4206a0a | 2018-07-20 22:49:43 | [diff] [blame] | 20 | #include "api/video/video_bitrate_allocator.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 21 | #include "api/video/video_rotation.h" |
Niels Möller | c6ce9c5 | 2018-05-11 09:15:30 | [diff] [blame] | 22 | #include "api/video/video_sink_interface.h" |
Niels Möller | 0327c2d | 2018-05-21 12:09:31 | [diff] [blame] | 23 | #include "api/video/video_stream_encoder_interface.h" |
Niels Möller | 213618e | 2018-07-24 07:29:58 | [diff] [blame] | 24 | #include "api/video/video_stream_encoder_observer.h" |
| 25 | #include "api/video/video_stream_encoder_settings.h" |
Niels Möller | 0327c2d | 2018-05-21 12:09:31 | [diff] [blame] | 26 | #include "api/video_codecs/video_encoder.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 27 | #include "modules/video_coding/utility/quality_scaler.h" |
| 28 | #include "modules/video_coding/video_coding_impl.h" |
| 29 | #include "rtc_base/criticalsection.h" |
| 30 | #include "rtc_base/event.h" |
| 31 | #include "rtc_base/sequenced_task_checker.h" |
| 32 | #include "rtc_base/task_queue.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 33 | #include "video/overuse_frame_detector.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 34 | |
| 35 | namespace webrtc { |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 | [diff] [blame] | 36 | |
Sebastian Jansson | 652dc91 | 2018-04-19 15:09:15 | [diff] [blame] | 37 | // VideoStreamEncoder represent a video encoder that accepts raw video frames as |
| 38 | // input and produces an encoded bit stream. |
| 39 | // Usage: |
| 40 | // Instantiate. |
| 41 | // Call SetSink. |
| 42 | // Call SetSource. |
| 43 | // Call ConfigureEncoder with the codec settings. |
| 44 | // Call Stop() when done. |
| 45 | class VideoStreamEncoder : public VideoStreamEncoderInterface, |
| 46 | private EncodedImageCallback, |
| 47 | // Protected only to provide access to tests. |
| 48 | protected AdaptationObserverInterface { |
| 49 | public: |
mflodman | cc3d442 | 2017-08-03 15:27:51 | [diff] [blame] | 50 | VideoStreamEncoder(uint32_t number_of_cores, |
Niels Möller | 213618e | 2018-07-24 07:29:58 | [diff] [blame] | 51 | VideoStreamEncoderObserver* encoder_stats_observer, |
| 52 | const VideoStreamEncoderSettings& settings, |
mflodman | cc3d442 | 2017-08-03 15:27:51 | [diff] [blame] | 53 | rtc::VideoSinkInterface<VideoFrame>* pre_encode_callback, |
mflodman | cc3d442 | 2017-08-03 15:27:51 | [diff] [blame] | 54 | std::unique_ptr<OveruseFrameDetector> overuse_detector); |
Stefan Holmer | dbdb3a0 | 2018-07-17 14:03:46 | [diff] [blame] | 55 | ~VideoStreamEncoder() override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 56 | |
Sebastian Jansson | 652dc91 | 2018-04-19 15:09:15 | [diff] [blame] | 57 | void SetSource(rtc::VideoSourceInterface<VideoFrame>* source, |
Taylor Brandstetter | 49fcc10 | 2018-05-16 21:20:41 | [diff] [blame] | 58 | const DegradationPreference& degradation_preference) override; |
perkj | 803d97f | 2016-11-01 18:45:46 | [diff] [blame] | 59 | |
Sebastian Jansson | 652dc91 | 2018-04-19 15:09:15 | [diff] [blame] | 60 | void SetSink(EncoderSink* sink, bool rotation_applied) override; |
mflodman@webrtc.org | 02270cd | 2015-02-06 13:10:19 | [diff] [blame] | 61 | |
perkj | 26091b1 | 2016-09-01 08:17:40 | [diff] [blame] | 62 | // TODO(perkj): Can we remove VideoCodec.startBitrate ? |
Sebastian Jansson | 652dc91 | 2018-04-19 15:09:15 | [diff] [blame] | 63 | void SetStartBitrate(int start_bitrate_bps) override; |
mflodman@webrtc.org | 9ec883e | 2012-03-05 17:12:41 | [diff] [blame] | 64 | |
Niels Möller | 0327c2d | 2018-05-21 12:09:31 | [diff] [blame] | 65 | void SetBitrateAllocationObserver( |
Sebastian Jansson | 652dc91 | 2018-04-19 15:09:15 | [diff] [blame] | 66 | VideoBitrateAllocationObserver* bitrate_observer) override; |
sprang | 1a646ee | 2016-12-01 14:34:11 | [diff] [blame] | 67 | |
Per | 512ecb3 | 2016-09-23 13:52:06 | [diff] [blame] | 68 | void ConfigureEncoder(VideoEncoderConfig config, |
Niels Möller | f133856 | 2018-04-26 07:51:47 | [diff] [blame] | 69 | size_t max_data_payload_length) override; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 70 | |
perkj | 26091b1 | 2016-09-01 08:17:40 | [diff] [blame] | 71 | // Permanently stop encoding. After this method has returned, it is |
| 72 | // guaranteed that no encoded frames will be delivered to the sink. |
Sebastian Jansson | 652dc91 | 2018-04-19 15:09:15 | [diff] [blame] | 73 | void Stop() override; |
perkj | 26091b1 | 2016-09-01 08:17:40 | [diff] [blame] | 74 | |
Sebastian Jansson | 652dc91 | 2018-04-19 15:09:15 | [diff] [blame] | 75 | void SendKeyFrame() override; |
mflodman@webrtc.org | d6ec386 | 2012-10-25 11:30:29 | [diff] [blame] | 76 | |
mflodman | 86aabb2 | 2016-03-11 14:44:32 | [diff] [blame] | 77 | void OnBitrateUpdated(uint32_t bitrate_bps, |
stefan@webrtc.org | edeea91 | 2014-12-08 19:46:23 | [diff] [blame] | 78 | uint8_t fraction_lost, |
Sebastian Jansson | 652dc91 | 2018-04-19 15:09:15 | [diff] [blame] | 79 | int64_t round_trip_time_ms) override; |
pwestin@webrtc.org | 49888ce | 2012-04-27 05:25:53 | [diff] [blame] | 80 | |
perkj | 803d97f | 2016-11-01 18:45:46 | [diff] [blame] | 81 | protected: |
kthelgason | 876222f | 2016-11-29 09:44:11 | [diff] [blame] | 82 | // Used for testing. For example the |ScalingObserverInterface| methods must |
| 83 | // be called on |encoder_queue_|. |
perkj | 803d97f | 2016-11-01 18:45:46 | [diff] [blame] | 84 | rtc::TaskQueue* encoder_queue() { return &encoder_queue_; } |
| 85 | |
Niels Möller | d692ef9 | 2017-10-04 13:28:55 | [diff] [blame] | 86 | // AdaptationObserverInterface implementation. |
perkj | 803d97f | 2016-11-01 18:45:46 | [diff] [blame] | 87 | // These methods are protected for easier testing. |
sprang | b1ca073 | 2017-02-01 16:38:12 | [diff] [blame] | 88 | void AdaptUp(AdaptReason reason) override; |
| 89 | void AdaptDown(AdaptReason reason) override; |
perkj | 803d97f | 2016-11-01 18:45:46 | [diff] [blame] | 90 | |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 | [diff] [blame] | 91 | private: |
perkj | a49cbd3 | 2016-09-16 14:53:41 | [diff] [blame] | 92 | class VideoSourceProxy; |
perkj | 26091b1 | 2016-09-01 08:17:40 | [diff] [blame] | 93 | |
kthelgason | 93f16d7 | 2017-01-16 14:15:23 | [diff] [blame] | 94 | class VideoFrameInfo { |
| 95 | public: |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 96 | VideoFrameInfo(int width, int height, bool is_texture) |
| 97 | : width(width), height(height), is_texture(is_texture) {} |
perkj | fa10b55 | 2016-10-03 06:45:26 | [diff] [blame] | 98 | int width; |
| 99 | int height; |
perkj | fa10b55 | 2016-10-03 06:45:26 | [diff] [blame] | 100 | bool is_texture; |
kthelgason | 93f16d7 | 2017-01-16 14:15:23 | [diff] [blame] | 101 | int pixel_count() const { return width * height; } |
perkj | fa10b55 | 2016-10-03 06:45:26 | [diff] [blame] | 102 | }; |
| 103 | |
Per | a48ddb7 | 2016-09-29 09:48:50 | [diff] [blame] | 104 | void ConfigureEncoderOnTaskQueue(VideoEncoderConfig config, |
Niels Möller | f133856 | 2018-04-26 07:51:47 | [diff] [blame] | 105 | size_t max_data_payload_length); |
Niels Möller | a8b1508 | 2018-02-07 12:42:09 | [diff] [blame] | 106 | void ReconfigureEncoder() RTC_RUN_ON(&encoder_queue_); |
perkj | 26091b1 | 2016-09-01 08:17:40 | [diff] [blame] | 107 | |
kthelgason | 2bc6864 | 2017-02-07 15:02:22 | [diff] [blame] | 108 | void ConfigureQualityScaler(); |
| 109 | |
perkj | a49cbd3 | 2016-09-16 14:53:41 | [diff] [blame] | 110 | // Implements VideoSinkInterface. |
| 111 | void OnFrame(const VideoFrame& video_frame) override; |
Ilya Nikolaevskiy | d79314f | 2017-10-23 08:45:37 | [diff] [blame] | 112 | void OnDiscardedFrame() override; |
perkj | a49cbd3 | 2016-09-16 14:53:41 | [diff] [blame] | 113 | |
Sebastian Jansson | a317705 | 2018-04-10 11:05:49 | [diff] [blame] | 114 | void MaybeEncodeVideoFrame(const VideoFrame& frame, |
| 115 | int64_t time_when_posted_in_ms); |
| 116 | |
perkj | d52063f | 2016-09-07 13:32:18 | [diff] [blame] | 117 | void EncodeVideoFrame(const VideoFrame& frame, |
| 118 | int64_t time_when_posted_in_ms); |
Sebastian Jansson | a317705 | 2018-04-10 11:05:49 | [diff] [blame] | 119 | // Indicates wether frame should be dropped because the pixel count is too |
| 120 | // large for the current bitrate configuration. |
| 121 | bool DropDueToSize(uint32_t pixel_count) const RTC_RUN_ON(&encoder_queue_); |
perkj | 26091b1 | 2016-09-01 08:17:40 | [diff] [blame] | 122 | |
| 123 | // Implements EncodedImageCallback. |
| 124 | EncodedImageCallback::Result OnEncodedImage( |
| 125 | const EncodedImage& encoded_image, |
| 126 | const CodecSpecificInfo* codec_specific_info, |
| 127 | const RTPFragmentationHeader* fragmentation) override; |
| 128 | |
Ilya Nikolaevskiy | d79314f | 2017-10-23 08:45:37 | [diff] [blame] | 129 | void OnDroppedFrame(EncodedImageCallback::DropReason reason) override; |
kthelgason | 876222f | 2016-11-29 09:44:11 | [diff] [blame] | 130 | |
perkj | 26091b1 | 2016-09-01 08:17:40 | [diff] [blame] | 131 | bool EncoderPaused() const; |
| 132 | void TraceFrameDropStart(); |
| 133 | void TraceFrameDropEnd(); |
| 134 | |
asapersson | 09f0561 | 2017-05-16 06:40:18 | [diff] [blame] | 135 | // Class holding adaptation information. |
| 136 | class AdaptCounter final { |
| 137 | public: |
| 138 | AdaptCounter(); |
| 139 | ~AdaptCounter(); |
| 140 | |
| 141 | // Get number of adaptation downscales for |reason|. |
Niels Möller | 213618e | 2018-07-24 07:29:58 | [diff] [blame] | 142 | VideoStreamEncoderObserver::AdaptationSteps Counts(int reason) const; |
asapersson | 09f0561 | 2017-05-16 06:40:18 | [diff] [blame] | 143 | |
| 144 | std::string ToString() const; |
| 145 | |
asapersson | f7e294d | 2017-06-14 06:25:22 | [diff] [blame] | 146 | void IncrementFramerate(int reason); |
| 147 | void IncrementResolution(int reason); |
| 148 | void DecrementFramerate(int reason); |
| 149 | void DecrementResolution(int reason); |
| 150 | void DecrementFramerate(int reason, int cur_fps); |
asapersson | 09f0561 | 2017-05-16 06:40:18 | [diff] [blame] | 151 | |
| 152 | // Gets the total number of downgrades (for all adapt reasons). |
| 153 | int FramerateCount() const; |
| 154 | int ResolutionCount() const; |
asapersson | 09f0561 | 2017-05-16 06:40:18 | [diff] [blame] | 155 | |
| 156 | // Gets the total number of downgrades for |reason|. |
| 157 | int FramerateCount(int reason) const; |
| 158 | int ResolutionCount(int reason) const; |
| 159 | int TotalCount(int reason) const; |
| 160 | |
| 161 | private: |
| 162 | std::string ToString(const std::vector<int>& counters) const; |
| 163 | int Count(const std::vector<int>& counters) const; |
asapersson | f7e294d | 2017-06-14 06:25:22 | [diff] [blame] | 164 | void MoveCount(std::vector<int>* counters, int from_reason); |
asapersson | 09f0561 | 2017-05-16 06:40:18 | [diff] [blame] | 165 | |
| 166 | // Degradation counters holding number of framerate/resolution reductions |
| 167 | // per adapt reason. |
| 168 | std::vector<int> fps_counters_; |
| 169 | std::vector<int> resolution_counters_; |
| 170 | }; |
| 171 | |
danilchap | a37de39 | 2017-09-09 11:17:22 | [diff] [blame] | 172 | AdaptCounter& GetAdaptCounter() RTC_RUN_ON(&encoder_queue_); |
| 173 | const AdaptCounter& GetConstAdaptCounter() RTC_RUN_ON(&encoder_queue_); |
| 174 | void UpdateAdaptationStats(AdaptReason reason) RTC_RUN_ON(&encoder_queue_); |
Niels Möller | 213618e | 2018-07-24 07:29:58 | [diff] [blame] | 175 | VideoStreamEncoderObserver::AdaptationSteps GetActiveCounts( |
| 176 | AdaptReason reason) RTC_RUN_ON(&encoder_queue_); |
sprang | c5d62e2 | 2017-04-03 06:53:04 | [diff] [blame] | 177 | |
perkj | 26091b1 | 2016-09-01 08:17:40 | [diff] [blame] | 178 | rtc::Event shutdown_event_; |
stefan@webrtc.org | bfacda6 | 2013-03-27 16:36:01 | [diff] [blame] | 179 | |
pbos@webrtc.org | b238d12 | 2013-04-09 13:41:51 | [diff] [blame] | 180 | const uint32_t number_of_cores_; |
Kári Tristan Helgason | 639602a | 2018-08-02 08:51:40 | [diff] [blame] | 181 | // Counts how many frames we've dropped in the initial framedrop phase. |
| 182 | int initial_framedrop_; |
| 183 | const bool initial_framedrop_on_bwe_enabled_; |
| 184 | bool has_seen_first_significant_bwe_change_ = false; |
perkj | a49cbd3 | 2016-09-16 14:53:41 | [diff] [blame] | 185 | |
Åsa Persson | a945aee | 2018-04-24 14:53:25 | [diff] [blame] | 186 | const bool quality_scaling_experiment_enabled_; |
| 187 | |
perkj | a49cbd3 | 2016-09-16 14:53:41 | [diff] [blame] | 188 | const std::unique_ptr<VideoSourceProxy> source_proxy_; |
Per | 512ecb3 | 2016-09-23 13:52:06 | [diff] [blame] | 189 | EncoderSink* sink_; |
Niels Möller | 213618e | 2018-07-24 07:29:58 | [diff] [blame] | 190 | const VideoStreamEncoderSettings settings_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 191 | |
Niels Möller | 1e06289 | 2018-02-07 09:18:32 | [diff] [blame] | 192 | vcm::VideoSender video_sender_ RTC_GUARDED_BY(&encoder_queue_); |
Niels Möller | a8b1508 | 2018-02-07 12:42:09 | [diff] [blame] | 193 | const std::unique_ptr<OveruseFrameDetector> overuse_detector_ |
| 194 | RTC_PT_GUARDED_BY(&encoder_queue_); |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 195 | std::unique_ptr<QualityScaler> quality_scaler_ RTC_GUARDED_BY(&encoder_queue_) |
Niels Möller | a8b1508 | 2018-02-07 12:42:09 | [diff] [blame] | 196 | RTC_PT_GUARDED_BY(&encoder_queue_); |
pwestin@webrtc.org | 49888ce | 2012-04-27 05:25:53 | [diff] [blame] | 197 | |
Niels Möller | 213618e | 2018-07-24 07:29:58 | [diff] [blame] | 198 | VideoStreamEncoderObserver* const encoder_stats_observer_; |
perkj | 26091b1 | 2016-09-01 08:17:40 | [diff] [blame] | 199 | rtc::VideoSinkInterface<VideoFrame>* const pre_encode_callback_; |
perkj | a49cbd3 | 2016-09-16 14:53:41 | [diff] [blame] | 200 | // |thread_checker_| checks that public methods that are related to lifetime |
mflodman | cc3d442 | 2017-08-03 15:27:51 | [diff] [blame] | 201 | // of VideoStreamEncoder are called on the same thread. |
perkj | a49cbd3 | 2016-09-16 14:53:41 | [diff] [blame] | 202 | rtc::ThreadChecker thread_checker_; |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 | [diff] [blame] | 203 | |
Niels Möller | 1e06289 | 2018-02-07 09:18:32 | [diff] [blame] | 204 | VideoEncoderConfig encoder_config_ RTC_GUARDED_BY(&encoder_queue_); |
Niels Möller | 4db138e | 2018-04-19 07:04:13 | [diff] [blame] | 205 | std::unique_ptr<VideoEncoder> encoder_ RTC_GUARDED_BY(&encoder_queue_) |
| 206 | RTC_PT_GUARDED_BY(&encoder_queue_); |
Erik Språng | 08127a9 | 2016-11-16 15:41:30 | [diff] [blame] | 207 | std::unique_ptr<VideoBitrateAllocator> rate_allocator_ |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 208 | RTC_GUARDED_BY(&encoder_queue_) RTC_PT_GUARDED_BY(&encoder_queue_); |
sprang | fda496a | 2017-06-15 11:21:07 | [diff] [blame] | 209 | // The maximum frame rate of the current codec configuration, as determined |
| 210 | // at the last ReconfigureEncoder() call. |
Niels Möller | 1e06289 | 2018-02-07 09:18:32 | [diff] [blame] | 211 | int max_framerate_ RTC_GUARDED_BY(&encoder_queue_); |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 | [diff] [blame] | 212 | |
perkj | fa10b55 | 2016-10-03 06:45:26 | [diff] [blame] | 213 | // Set when ConfigureEncoder has been called in order to lazy reconfigure the |
| 214 | // encoder on the next frame. |
Niels Möller | 1e06289 | 2018-02-07 09:18:32 | [diff] [blame] | 215 | bool pending_encoder_reconfiguration_ RTC_GUARDED_BY(&encoder_queue_); |
Niels Möller | 4db138e | 2018-04-19 07:04:13 | [diff] [blame] | 216 | // Set when configuration must create a new encoder object, e.g., |
| 217 | // because of a codec change. |
| 218 | bool pending_encoder_creation_ RTC_GUARDED_BY(&encoder_queue_); |
Danil Chapovalov | b9b146c | 2018-06-15 10:28:07 | [diff] [blame] | 219 | absl::optional<VideoFrameInfo> last_frame_info_ |
Niels Möller | 1e06289 | 2018-02-07 09:18:32 | [diff] [blame] | 220 | RTC_GUARDED_BY(&encoder_queue_); |
| 221 | int crop_width_ RTC_GUARDED_BY(&encoder_queue_); |
| 222 | int crop_height_ RTC_GUARDED_BY(&encoder_queue_); |
| 223 | uint32_t encoder_start_bitrate_bps_ RTC_GUARDED_BY(&encoder_queue_); |
| 224 | size_t max_data_payload_length_ RTC_GUARDED_BY(&encoder_queue_); |
Niels Möller | 1e06289 | 2018-02-07 09:18:32 | [diff] [blame] | 225 | uint32_t last_observed_bitrate_bps_ RTC_GUARDED_BY(&encoder_queue_); |
| 226 | bool encoder_paused_and_dropped_frame_ RTC_GUARDED_BY(&encoder_queue_); |
perkj | 26091b1 | 2016-09-01 08:17:40 | [diff] [blame] | 227 | Clock* const clock_; |
asapersson | 09f0561 | 2017-05-16 06:40:18 | [diff] [blame] | 228 | // Counters used for deciding if the video resolution or framerate is |
| 229 | // currently restricted, and if so, why, on a per degradation preference |
| 230 | // basis. |
sprang | c5d62e2 | 2017-04-03 06:53:04 | [diff] [blame] | 231 | // TODO(sprang): Replace this with a state holding a relative overuse measure |
| 232 | // instead, that can be translated into suitable down-scale or fps limit. |
Taylor Brandstetter | 49fcc10 | 2018-05-16 21:20:41 | [diff] [blame] | 233 | std::map<const DegradationPreference, AdaptCounter> adapt_counters_ |
Niels Möller | 1e06289 | 2018-02-07 09:18:32 | [diff] [blame] | 234 | RTC_GUARDED_BY(&encoder_queue_); |
Taylor Brandstetter | 49fcc10 | 2018-05-16 21:20:41 | [diff] [blame] | 235 | // Set depending on degradation preferences. |
| 236 | DegradationPreference degradation_preference_ RTC_GUARDED_BY(&encoder_queue_); |
perkj | 803d97f | 2016-11-01 18:45:46 | [diff] [blame] | 237 | |
sprang | 84a3759 | 2017-02-10 15:04:27 | [diff] [blame] | 238 | struct AdaptationRequest { |
| 239 | // The pixel count produced by the source at the time of the adaptation. |
| 240 | int input_pixel_count_; |
sprang | c5d62e2 | 2017-04-03 06:53:04 | [diff] [blame] | 241 | // Framerate received from the source at the time of the adaptation. |
| 242 | int framerate_fps_; |
sprang | 84a3759 | 2017-02-10 15:04:27 | [diff] [blame] | 243 | // Indicates if request was to adapt up or down. |
| 244 | enum class Mode { kAdaptUp, kAdaptDown } mode_; |
| 245 | }; |
| 246 | // Stores a snapshot of the last adaptation request triggered by an AdaptUp |
| 247 | // or AdaptDown signal. |
Danil Chapovalov | b9b146c | 2018-06-15 10:28:07 | [diff] [blame] | 248 | absl::optional<AdaptationRequest> last_adaptation_request_ |
Niels Möller | 1e06289 | 2018-02-07 09:18:32 | [diff] [blame] | 249 | RTC_GUARDED_BY(&encoder_queue_); |
perkj | 803d97f | 2016-11-01 18:45:46 | [diff] [blame] | 250 | |
| 251 | rtc::RaceChecker incoming_frame_race_checker_ |
danilchap | a37de39 | 2017-09-09 11:17:22 | [diff] [blame] | 252 | RTC_GUARDED_BY(incoming_frame_race_checker_); |
Yuwei Huang | d9f99c1 | 2017-10-24 22:40:52 | [diff] [blame] | 253 | std::atomic<int> posted_frames_waiting_for_encode_; |
perkj | 26091b1 | 2016-09-01 08:17:40 | [diff] [blame] | 254 | // Used to make sure incoming time stamp is increasing for every frame. |
danilchap | a37de39 | 2017-09-09 11:17:22 | [diff] [blame] | 255 | int64_t last_captured_timestamp_ RTC_GUARDED_BY(incoming_frame_race_checker_); |
perkj | 26091b1 | 2016-09-01 08:17:40 | [diff] [blame] | 256 | // Delta used for translating between NTP and internal timestamps. |
danilchap | a37de39 | 2017-09-09 11:17:22 | [diff] [blame] | 257 | const int64_t delta_ntp_internal_ms_ |
| 258 | RTC_GUARDED_BY(incoming_frame_race_checker_); |
perkj | 26091b1 | 2016-09-01 08:17:40 | [diff] [blame] | 259 | |
danilchap | a37de39 | 2017-09-09 11:17:22 | [diff] [blame] | 260 | int64_t last_frame_log_ms_ RTC_GUARDED_BY(incoming_frame_race_checker_); |
Niels Möller | 1e06289 | 2018-02-07 09:18:32 | [diff] [blame] | 261 | int captured_frame_count_ RTC_GUARDED_BY(&encoder_queue_); |
| 262 | int dropped_frame_count_ RTC_GUARDED_BY(&encoder_queue_); |
Danil Chapovalov | b9b146c | 2018-06-15 10:28:07 | [diff] [blame] | 263 | absl::optional<VideoFrame> pending_frame_ RTC_GUARDED_BY(&encoder_queue_); |
Sebastian Jansson | a317705 | 2018-04-10 11:05:49 | [diff] [blame] | 264 | int64_t pending_frame_post_time_us_ RTC_GUARDED_BY(&encoder_queue_); |
asapersson | 6ffb67d | 2016-09-12 07:10:45 | [diff] [blame] | 265 | |
danilchap | a37de39 | 2017-09-09 11:17:22 | [diff] [blame] | 266 | VideoBitrateAllocationObserver* bitrate_observer_ |
Niels Möller | 1e06289 | 2018-02-07 09:18:32 | [diff] [blame] | 267 | RTC_GUARDED_BY(&encoder_queue_); |
Danil Chapovalov | b9b146c | 2018-06-15 10:28:07 | [diff] [blame] | 268 | absl::optional<int64_t> last_parameters_update_ms_ |
Niels Möller | 1e06289 | 2018-02-07 09:18:32 | [diff] [blame] | 269 | RTC_GUARDED_BY(&encoder_queue_); |
sprang | 1a646ee | 2016-12-01 14:34:11 | [diff] [blame] | 270 | |
perkj | 26091b1 | 2016-09-01 08:17:40 | [diff] [blame] | 271 | // All public methods are proxied to |encoder_queue_|. It must must be |
| 272 | // destroyed first to make sure no tasks are run that use other members. |
| 273 | rtc::TaskQueue encoder_queue_; |
perkj | a49cbd3 | 2016-09-16 14:53:41 | [diff] [blame] | 274 | |
mflodman | cc3d442 | 2017-08-03 15:27:51 | [diff] [blame] | 275 | RTC_DISALLOW_COPY_AND_ASSIGN(VideoStreamEncoder); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 | [diff] [blame] | 276 | }; |
mflodman@webrtc.org | 84d1783 | 2011-12-01 17:02:23 | [diff] [blame] | 277 | |
| 278 | } // namespace webrtc |
| 279 | |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 280 | #endif // VIDEO_VIDEO_STREAM_ENCODER_H_ |