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 <memory> | 14 #include <memory> |
15 #include <string> | 15 #include <string> |
16 #include <vector> | 16 #include <vector> |
17 | 17 |
18 #include "webrtc/base/criticalsection.h" | 18 #include "webrtc/base/criticalsection.h" |
19 #include "webrtc/base/event.h" | 19 #include "webrtc/base/event.h" |
20 #include "webrtc/base/sequenced_task_checker.h" | 20 #include "webrtc/base/sequenced_task_checker.h" |
21 #include "webrtc/base/task_queue.h" | 21 #include "webrtc/base/task_queue.h" |
22 #include "webrtc/call.h" | 22 #include "webrtc/call.h" |
23 #include "webrtc/common_types.h" | 23 #include "webrtc/common_types.h" |
24 #include "webrtc/common_video/include/video_bitrate_allocator.h" | 24 #include "webrtc/common_video/include/video_bitrate_allocator.h" |
25 #include "webrtc/common_video/rotation.h" | 25 #include "webrtc/common_video/rotation.h" |
26 #include "webrtc/media/base/videosinkinterface.h" | 26 #include "webrtc/media/base/videosinkinterface.h" |
27 #include "webrtc/modules/video_coding/include/video_coding_defines.h" | 27 #include "webrtc/modules/video_coding/include/video_coding_defines.h" |
28 #include "webrtc/modules/video_coding/utility/simulcast_rate_allocator.h" | |
perkj_webrtc
2016/11/17 21:23:38
?
kthelgason
2016/11/21 13:06:53
Rebase artifact... Removed.
| |
29 #include "webrtc/modules/video_coding/utility/quality_scaler.h" | |
28 #include "webrtc/modules/video_coding/video_coding_impl.h" | 30 #include "webrtc/modules/video_coding/video_coding_impl.h" |
29 #include "webrtc/modules/video_processing/include/video_processing.h" | 31 #include "webrtc/modules/video_processing/include/video_processing.h" |
30 #include "webrtc/system_wrappers/include/atomic32.h" | 32 #include "webrtc/system_wrappers/include/atomic32.h" |
31 #include "webrtc/video/overuse_frame_detector.h" | 33 #include "webrtc/video/overuse_frame_detector.h" |
32 #include "webrtc/video_encoder.h" | 34 #include "webrtc/video_encoder.h" |
33 #include "webrtc/video_send_stream.h" | 35 #include "webrtc/video_send_stream.h" |
34 #include "webrtc/typedefs.h" | 36 #include "webrtc/typedefs.h" |
35 | 37 |
36 namespace webrtc { | 38 namespace webrtc { |
37 | 39 |
38 class ProcessThread; | 40 class ProcessThread; |
39 class SendStatisticsProxy; | 41 class SendStatisticsProxy; |
40 | 42 |
41 // VieEncoder represent a video encoder that accepts raw video frames as input | 43 // VieEncoder represent a video encoder that accepts raw video frames as input |
42 // and produces an encoded bit stream. | 44 // and produces an encoded bit stream. |
43 // Usage: | 45 // Usage: |
44 // Instantiate. | 46 // Instantiate. |
45 // Call SetSink. | 47 // Call SetSink. |
46 // Call SetSource. | 48 // Call SetSource. |
47 // Call ConfigureEncoder with the codec settings. | 49 // Call ConfigureEncoder with the codec settings. |
48 // Call Stop() when done. | 50 // Call Stop() when done. |
49 class ViEEncoder : public rtc::VideoSinkInterface<VideoFrame>, | 51 class ViEEncoder : public rtc::VideoSinkInterface<VideoFrame>, |
50 public EncodedImageCallback, | 52 public EncodedImageCallback, |
51 public VCMSendStatisticsCallback, | 53 public VCMSendStatisticsCallback, |
52 public CpuOveruseObserver { | 54 public ScalingObserverInterface { |
53 public: | 55 public: |
54 // Interface for receiving encoded video frames and notifications about | 56 // Interface for receiving encoded video frames and notifications about |
55 // configuration changes. | 57 // configuration changes. |
56 class EncoderSink : public EncodedImageCallback { | 58 class EncoderSink : public EncodedImageCallback { |
57 public: | 59 public: |
58 virtual void OnEncoderConfigurationChanged( | 60 virtual void OnEncoderConfigurationChanged( |
59 std::vector<VideoStream> streams, | 61 std::vector<VideoStream> streams, |
60 int min_transmit_bitrate_bps) = 0; | 62 int min_transmit_bitrate_bps) = 0; |
61 }; | 63 }; |
62 | 64 |
63 // Down grade resolution at most 2 times for CPU reasons. | |
64 static const int kMaxCpuDowngrades = 2; | |
65 | |
66 ViEEncoder(uint32_t number_of_cores, | 65 ViEEncoder(uint32_t number_of_cores, |
67 SendStatisticsProxy* stats_proxy, | 66 SendStatisticsProxy* stats_proxy, |
68 const VideoSendStream::Config::EncoderSettings& settings, | 67 const VideoSendStream::Config::EncoderSettings& settings, |
69 rtc::VideoSinkInterface<VideoFrame>* pre_encode_callback, | 68 rtc::VideoSinkInterface<VideoFrame>* pre_encode_callback, |
70 EncodedFrameObserver* encoder_timing); | 69 EncodedFrameObserver* encoder_timing); |
71 ~ViEEncoder(); | 70 ~ViEEncoder(); |
72 // RegisterProcessThread register |module_process_thread| with those objects | 71 // RegisterProcessThread register |module_process_thread| with those objects |
73 // that use it. Registration has to happen on the thread where | 72 // that use it. Registration has to happen on the thread where |
74 // |module_process_thread| was created (libjingle's worker thread). | 73 // |module_process_thread| was created (libjingle's worker thread). |
75 // TODO(perkj): Replace the use of |module_process_thread| with a TaskQueue. | 74 // TODO(perkj): Replace the use of |module_process_thread| with a TaskQueue. |
(...skipping 26 matching lines...) Expand all Loading... | |
102 | 101 |
103 // virtual to test EncoderStateFeedback with mocks. | 102 // virtual to test EncoderStateFeedback with mocks. |
104 virtual void OnReceivedIntraFrameRequest(size_t stream_index); | 103 virtual void OnReceivedIntraFrameRequest(size_t stream_index); |
105 virtual void OnReceivedSLI(uint8_t picture_id); | 104 virtual void OnReceivedSLI(uint8_t picture_id); |
106 virtual void OnReceivedRPSI(uint64_t picture_id); | 105 virtual void OnReceivedRPSI(uint64_t picture_id); |
107 | 106 |
108 void OnBitrateUpdated(uint32_t bitrate_bps, | 107 void OnBitrateUpdated(uint32_t bitrate_bps, |
109 uint8_t fraction_lost, | 108 uint8_t fraction_lost, |
110 int64_t round_trip_time_ms); | 109 int64_t round_trip_time_ms); |
111 | 110 |
111 // Downscale resolution at most 2 times for CPU reasons. | |
112 static const int kMaxCpuDowngrades = 2; | |
perkj_webrtc
2016/11/17 21:23:38
Order was correct from the beginning.
https://goo
kthelgason
2016/11/21 13:06:53
Done.
| |
113 // Downscale resolution at most 2 times for low-quality reasons. | |
114 static const int kMaxQualityDowngrades = 2; | |
115 | |
112 protected: | 116 protected: |
113 // Used for testing. For example the |CpuOveruseObserver| methods must be | 117 // Used for testing. For example the |ScalingObserverInterface| methods must |
114 // called on |encoder_queue_|. | 118 // be called on |encoder_queue_|. |
115 rtc::TaskQueue* encoder_queue() { return &encoder_queue_; } | 119 rtc::TaskQueue* encoder_queue() { return &encoder_queue_; } |
116 | 120 |
117 // webrtc::CpuOveruseObserver implementation. | 121 // webrtc::ScalingObserverInterface implementation. |
118 // These methods are protected for easier testing. | 122 // These methods are protected for easier testing. |
119 void OveruseDetected() override; | 123 void ScaleUp(ScaleReason reason) override; |
120 void NormalUsage() override; | 124 void ScaleDown(ScaleReason reason) override; |
121 | 125 |
122 private: | 126 private: |
123 class ConfigureEncoderTask; | 127 class ConfigureEncoderTask; |
124 class EncodeTask; | 128 class EncodeTask; |
125 class VideoSourceProxy; | 129 class VideoSourceProxy; |
126 | 130 |
127 struct VideoFrameInfo { | 131 struct VideoFrameInfo { |
128 VideoFrameInfo(int width, | 132 VideoFrameInfo(int width, |
129 int height, | 133 int height, |
130 VideoRotation rotation, | 134 VideoRotation rotation, |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
167 | 171 |
168 const uint32_t number_of_cores_; | 172 const uint32_t number_of_cores_; |
169 | 173 |
170 const std::unique_ptr<VideoSourceProxy> source_proxy_; | 174 const std::unique_ptr<VideoSourceProxy> source_proxy_; |
171 EncoderSink* sink_; | 175 EncoderSink* sink_; |
172 const VideoSendStream::Config::EncoderSettings settings_; | 176 const VideoSendStream::Config::EncoderSettings settings_; |
173 const VideoCodecType codec_type_; | 177 const VideoCodecType codec_type_; |
174 | 178 |
175 vcm::VideoSender video_sender_ ACCESS_ON(&encoder_queue_); | 179 vcm::VideoSender video_sender_ ACCESS_ON(&encoder_queue_); |
176 OveruseFrameDetector overuse_detector_ ACCESS_ON(&encoder_queue_); | 180 OveruseFrameDetector overuse_detector_ ACCESS_ON(&encoder_queue_); |
181 std::unique_ptr<QualityScaler> quality_scaler_ ACCESS_ON(&encoder_queue_); | |
177 | 182 |
178 SendStatisticsProxy* const stats_proxy_; | 183 SendStatisticsProxy* const stats_proxy_; |
179 rtc::VideoSinkInterface<VideoFrame>* const pre_encode_callback_; | 184 rtc::VideoSinkInterface<VideoFrame>* const pre_encode_callback_; |
180 ProcessThread* module_process_thread_; | 185 ProcessThread* module_process_thread_; |
181 rtc::ThreadChecker module_process_thread_checker_; | 186 rtc::ThreadChecker module_process_thread_checker_; |
182 // |thread_checker_| checks that public methods that are related to lifetime | 187 // |thread_checker_| checks that public methods that are related to lifetime |
183 // of ViEEncoder are called on the same thread. | 188 // of ViEEncoder are called on the same thread. |
184 rtc::ThreadChecker thread_checker_; | 189 rtc::ThreadChecker thread_checker_; |
185 | 190 |
186 VideoEncoderConfig encoder_config_ ACCESS_ON(&encoder_queue_); | 191 VideoEncoderConfig encoder_config_ ACCESS_ON(&encoder_queue_); |
187 std::unique_ptr<VideoBitrateAllocator> rate_allocator_ | 192 std::unique_ptr<VideoBitrateAllocator> rate_allocator_ |
188 ACCESS_ON(&encoder_queue_); | 193 ACCESS_ON(&encoder_queue_); |
189 | 194 |
190 // Set when ConfigureEncoder has been called in order to lazy reconfigure the | 195 // Set when ConfigureEncoder has been called in order to lazy reconfigure the |
191 // encoder on the next frame. | 196 // encoder on the next frame. |
192 bool pending_encoder_reconfiguration_ ACCESS_ON(&encoder_queue_); | 197 bool pending_encoder_reconfiguration_ ACCESS_ON(&encoder_queue_); |
193 rtc::Optional<VideoFrameInfo> last_frame_info_ ACCESS_ON(&encoder_queue_); | 198 rtc::Optional<VideoFrameInfo> last_frame_info_ ACCESS_ON(&encoder_queue_); |
194 uint32_t encoder_start_bitrate_bps_ ACCESS_ON(&encoder_queue_); | 199 uint32_t encoder_start_bitrate_bps_ ACCESS_ON(&encoder_queue_); |
195 size_t max_data_payload_length_ ACCESS_ON(&encoder_queue_); | 200 size_t max_data_payload_length_ ACCESS_ON(&encoder_queue_); |
196 uint32_t last_observed_bitrate_bps_ ACCESS_ON(&encoder_queue_); | 201 uint32_t last_observed_bitrate_bps_ ACCESS_ON(&encoder_queue_); |
197 bool encoder_paused_and_dropped_frame_ ACCESS_ON(&encoder_queue_); | 202 bool encoder_paused_and_dropped_frame_ ACCESS_ON(&encoder_queue_); |
198 bool has_received_sli_ ACCESS_ON(&encoder_queue_); | 203 bool has_received_sli_ ACCESS_ON(&encoder_queue_); |
199 uint8_t picture_id_sli_ ACCESS_ON(&encoder_queue_); | 204 uint8_t picture_id_sli_ ACCESS_ON(&encoder_queue_); |
200 bool has_received_rpsi_ ACCESS_ON(&encoder_queue_); | 205 bool has_received_rpsi_ ACCESS_ON(&encoder_queue_); |
201 uint64_t picture_id_rpsi_ ACCESS_ON(&encoder_queue_); | 206 uint64_t picture_id_rpsi_ ACCESS_ON(&encoder_queue_); |
202 Clock* const clock_; | 207 Clock* const clock_; |
203 | 208 // Counters used for deciding if the video resolution is currently |
204 VideoSendStream::DegradationPreference degradation_preference_ | 209 // restricted, and if so, why. |
205 ACCESS_ON(&encoder_queue_); | 210 int scale_counter_[kScaleReasonSize] ACCESS_ON(&encoder_queue_) = {0}; |
206 // Counter used for deciding if the video resolution is currently | 211 // Set depending on degradation preferences |
207 // restricted by CPU usage. | 212 bool scaling_enabled_ ACCESS_ON(&encoder_queue_) = false; |
208 int cpu_restricted_counter_ ACCESS_ON(&encoder_queue_); | |
209 | 213 |
210 int last_frame_width_ ACCESS_ON(&encoder_queue_); | 214 int last_frame_width_ ACCESS_ON(&encoder_queue_); |
211 int last_frame_height_ ACCESS_ON(&encoder_queue_); | 215 int last_frame_height_ ACCESS_ON(&encoder_queue_); |
212 // Pixel count last time the resolution was requested to be changed down. | 216 // Pixel count last time the resolution was requested to be changed down. |
213 rtc::Optional<int> max_pixel_count_ ACCESS_ON(&encoder_queue_); | 217 rtc::Optional<int> max_pixel_count_ ACCESS_ON(&encoder_queue_); |
214 // Pixel count last time the resolution was requested to be changed up. | 218 // Pixel count last time the resolution was requested to be changed up. |
215 rtc::Optional<int> max_pixel_count_step_up_ ACCESS_ON(&encoder_queue_); | 219 rtc::Optional<int> max_pixel_count_step_up_ ACCESS_ON(&encoder_queue_); |
216 | 220 |
217 rtc::RaceChecker incoming_frame_race_checker_ | 221 rtc::RaceChecker incoming_frame_race_checker_ |
218 GUARDED_BY(incoming_frame_race_checker_); | 222 GUARDED_BY(incoming_frame_race_checker_); |
(...skipping 10 matching lines...) Expand all Loading... | |
229 // All public methods are proxied to |encoder_queue_|. It must must be | 233 // All public methods are proxied to |encoder_queue_|. It must must be |
230 // destroyed first to make sure no tasks are run that use other members. | 234 // destroyed first to make sure no tasks are run that use other members. |
231 rtc::TaskQueue encoder_queue_; | 235 rtc::TaskQueue encoder_queue_; |
232 | 236 |
233 RTC_DISALLOW_COPY_AND_ASSIGN(ViEEncoder); | 237 RTC_DISALLOW_COPY_AND_ASSIGN(ViEEncoder); |
234 }; | 238 }; |
235 | 239 |
236 } // namespace webrtc | 240 } // namespace webrtc |
237 | 241 |
238 #endif // WEBRTC_VIDEO_VIE_ENCODER_H_ | 242 #endif // WEBRTC_VIDEO_VIE_ENCODER_H_ |
OLD | NEW |