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

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

Issue 2398963003: Move usage of QualityScaler to ViEEncoder. (Closed)
Patch Set: Stats now properly reflect scaling status Created 4 years, 1 month 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
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/rotation.h" 24 #include "webrtc/common_video/rotation.h"
25 #include "webrtc/media/base/videosinkinterface.h" 25 #include "webrtc/media/base/videosinkinterface.h"
26 #include "webrtc/modules/video_coding/include/video_coding_defines.h" 26 #include "webrtc/modules/video_coding/include/video_coding_defines.h"
27 #include "webrtc/modules/video_coding/utility/simulcast_rate_allocator.h" 27 #include "webrtc/modules/video_coding/utility/simulcast_rate_allocator.h"
28 #include "webrtc/modules/video_coding/utility/quality_scaler.h"
28 #include "webrtc/modules/video_coding/video_coding_impl.h" 29 #include "webrtc/modules/video_coding/video_coding_impl.h"
29 #include "webrtc/modules/video_processing/include/video_processing.h" 30 #include "webrtc/modules/video_processing/include/video_processing.h"
30 #include "webrtc/system_wrappers/include/atomic32.h" 31 #include "webrtc/system_wrappers/include/atomic32.h"
31 #include "webrtc/video/overuse_frame_detector.h" 32 #include "webrtc/video/overuse_frame_detector.h"
32 #include "webrtc/video_encoder.h" 33 #include "webrtc/video_encoder.h"
33 #include "webrtc/video_send_stream.h" 34 #include "webrtc/video_send_stream.h"
34 #include "webrtc/typedefs.h" 35 #include "webrtc/typedefs.h"
35 36
36 namespace webrtc { 37 namespace webrtc {
37 38
38 class ProcessThread; 39 class ProcessThread;
39 class SendStatisticsProxy; 40 class SendStatisticsProxy;
40 41
41 // VieEncoder represent a video encoder that accepts raw video frames as input 42 // VieEncoder represent a video encoder that accepts raw video frames as input
42 // and produces an encoded bit stream. 43 // and produces an encoded bit stream.
43 // Usage: 44 // Usage:
44 // Instantiate. 45 // Instantiate.
45 // Call SetSink. 46 // Call SetSink.
46 // Call SetSource. 47 // Call SetSource.
47 // Call ConfigureEncoder with the codec settings. 48 // Call ConfigureEncoder with the codec settings.
48 // Call Stop() when done. 49 // Call Stop() when done.
49 class ViEEncoder : public rtc::VideoSinkInterface<VideoFrame>, 50 class ViEEncoder : public rtc::VideoSinkInterface<VideoFrame>,
50 public EncodedImageCallback, 51 public EncodedImageCallback,
51 public VCMSendStatisticsCallback, 52 public VCMSendStatisticsCallback,
52 public CpuOveruseObserver { 53 public ScalingObserverInterface {
53 public: 54 public:
54 // Interface for receiving encoded video frames and notifications about 55 // Interface for receiving encoded video frames and notifications about
55 // configuration changes. 56 // configuration changes.
56 class EncoderSink : public EncodedImageCallback { 57 class EncoderSink : public EncodedImageCallback {
57 public: 58 public:
58 virtual void OnEncoderConfigurationChanged( 59 virtual void OnEncoderConfigurationChanged(
59 std::vector<VideoStream> streams, 60 std::vector<VideoStream> streams,
60 int min_transmit_bitrate_bps) = 0; 61 int min_transmit_bitrate_bps) = 0;
61 }; 62 };
62 63
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 // virtual to test EncoderStateFeedback with mocks. 103 // virtual to test EncoderStateFeedback with mocks.
103 virtual void OnReceivedIntraFrameRequest(size_t stream_index); 104 virtual void OnReceivedIntraFrameRequest(size_t stream_index);
104 virtual void OnReceivedSLI(uint8_t picture_id); 105 virtual void OnReceivedSLI(uint8_t picture_id);
105 virtual void OnReceivedRPSI(uint64_t picture_id); 106 virtual void OnReceivedRPSI(uint64_t picture_id);
106 107
107 void OnBitrateUpdated(uint32_t bitrate_bps, 108 void OnBitrateUpdated(uint32_t bitrate_bps,
108 uint8_t fraction_lost, 109 uint8_t fraction_lost,
109 int64_t round_trip_time_ms); 110 int64_t round_trip_time_ms);
110 111
111 protected: 112 protected:
112 // Used for testing. For example the |CpuOveruseObserver| methods must be 113 // Used for testing. For example the |ScalingObserverInterface| methods must
113 // called on |encoder_queue_|. 114 // be called on |encoder_queue_|.
114 rtc::TaskQueue* encoder_queue() { return &encoder_queue_; } 115 rtc::TaskQueue* encoder_queue() { return &encoder_queue_; }
115 116
116 // webrtc::CpuOveruseObserver implementation. 117 // webrtc::ScalingObserverInterface implementation.
117 // These methods are protected for easier testing. 118 // These methods are protected for easier testing.
118 void OveruseDetected() override; 119 void ScaleUp(ScaleReason reason) override;
perkj_webrtc 2016/10/26 15:53:50 This seems racy to me. I think we want something l
119 void NormalUsage() override; 120 void ScaleDown(ScaleReason reason) override;
120 121
121 private: 122 private:
122 class ConfigureEncoderTask; 123 class ConfigureEncoderTask;
123 class EncodeTask; 124 class EncodeTask;
124 class VideoSourceProxy; 125 class VideoSourceProxy;
125 126
126 struct VideoFrameInfo { 127 struct VideoFrameInfo {
127 VideoFrameInfo(int width, 128 VideoFrameInfo(int width,
128 int height, 129 int height,
129 VideoRotation rotation, 130 VideoRotation rotation,
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 rtc::Event shutdown_event_; 166 rtc::Event shutdown_event_;
166 167
167 const uint32_t number_of_cores_; 168 const uint32_t number_of_cores_;
168 169
169 const std::unique_ptr<VideoSourceProxy> source_proxy_; 170 const std::unique_ptr<VideoSourceProxy> source_proxy_;
170 EncoderSink* sink_; 171 EncoderSink* sink_;
171 const VideoSendStream::Config::EncoderSettings settings_; 172 const VideoSendStream::Config::EncoderSettings settings_;
172 const VideoCodecType codec_type_; 173 const VideoCodecType codec_type_;
173 174
174 vcm::VideoSender video_sender_ ACCESS_ON(&encoder_queue_); 175 vcm::VideoSender video_sender_ ACCESS_ON(&encoder_queue_);
175 bool disable_resolution_scaling_ ACCESS_ON(&encoder_queue_); 176 bool enable_quality_scaling_ ACCESS_ON(&encoder_queue_);
magjed_webrtc 2016/10/26 14:28:37 I think you misunderstood me about the RAII change
kthelgason 2016/10/26 19:02:50 So the issue with doing what you describe comes do
magjed_webrtc 2016/10/27 11:45:57 I don't follow, for me it looks perfectly fine to
176 OveruseFrameDetector overuse_detector_ ACCESS_ON(&encoder_queue_); 177 OveruseFrameDetector overuse_detector_ ACCESS_ON(&encoder_queue_);
178 std::unique_ptr<QualityScaler> quality_scaler_ ACCESS_ON(&encoder_queue_);
177 179
178 SendStatisticsProxy* const stats_proxy_; 180 SendStatisticsProxy* const stats_proxy_;
179 rtc::VideoSinkInterface<VideoFrame>* const pre_encode_callback_; 181 rtc::VideoSinkInterface<VideoFrame>* const pre_encode_callback_;
180 ProcessThread* module_process_thread_; 182 ProcessThread* module_process_thread_;
181 rtc::ThreadChecker module_process_thread_checker_; 183 rtc::ThreadChecker module_process_thread_checker_;
182 // |thread_checker_| checks that public methods that are related to lifetime 184 // |thread_checker_| checks that public methods that are related to lifetime
183 // of ViEEncoder are called on the same thread. 185 // of ViEEncoder are called on the same thread.
184 rtc::ThreadChecker thread_checker_; 186 rtc::ThreadChecker thread_checker_;
185 187
186 VideoEncoderConfig encoder_config_ ACCESS_ON(&encoder_queue_); 188 VideoEncoderConfig encoder_config_ ACCESS_ON(&encoder_queue_);
(...skipping 11 matching lines...) Expand all
198 size_t max_data_payload_length_ ACCESS_ON(&encoder_queue_); 200 size_t max_data_payload_length_ ACCESS_ON(&encoder_queue_);
199 uint32_t last_observed_bitrate_bps_ ACCESS_ON(&encoder_queue_); 201 uint32_t last_observed_bitrate_bps_ ACCESS_ON(&encoder_queue_);
200 bool encoder_paused_and_dropped_frame_ ACCESS_ON(&encoder_queue_); 202 bool encoder_paused_and_dropped_frame_ ACCESS_ON(&encoder_queue_);
201 bool has_received_sli_ ACCESS_ON(&encoder_queue_); 203 bool has_received_sli_ ACCESS_ON(&encoder_queue_);
202 uint8_t picture_id_sli_ ACCESS_ON(&encoder_queue_); 204 uint8_t picture_id_sli_ ACCESS_ON(&encoder_queue_);
203 bool has_received_rpsi_ ACCESS_ON(&encoder_queue_); 205 bool has_received_rpsi_ ACCESS_ON(&encoder_queue_);
204 uint64_t picture_id_rpsi_ ACCESS_ON(&encoder_queue_); 206 uint64_t picture_id_rpsi_ ACCESS_ON(&encoder_queue_);
205 Clock* const clock_; 207 Clock* const clock_;
206 // Counter used for deciding if the video resolution is currently 208 // Counter used for deciding if the video resolution is currently
207 // restricted by CPU usage. It is reset if |source_| is changed. 209 // restricted by CPU usage. It is reset if |source_| is changed.
208 int cpu_restricted_counter_; // ACCESS_ON(&encoder_queue_); 210 int scale_counter_[ScaleReasonSize] = {0}; // ACCESS_ON(&encoder_queue_);
209 211
210 int last_frame_width_; // ACCESS_ON(&encoder_queue_); 212 int last_frame_width_; // ACCESS_ON(&encoder_queue_);
211 int last_frame_height_; // ACCESS_ON(&encoder_queue_); 213 int last_frame_height_; // ACCESS_ON(&encoder_queue_);
212 // Resolution has been requested to be less than |max_pixel_count_|. 214 // Resolution has been requested to be less than |max_pixel_count_|.
213 rtc::Optional<int> max_pixel_count_; // ACCESS_ON(&encoder_queue_); 215 rtc::Optional<int> max_pixel_count_; // ACCESS_ON(&encoder_queue_);
214 // Resolution has been requested to higher than |max_pixel_count_step_up_|. 216 // Resolution has been requested to higher than |max_pixel_count_step_up_|.
215 rtc::Optional<int> max_pixel_count_step_up_; // ACCESS_ON(&encoder_queue_); 217 rtc::Optional<int> max_pixel_count_step_up_; // ACCESS_ON(&encoder_queue_);
216 218
217 rtc::RaceChecker incoming_frame_race_checker_; 219 rtc::RaceChecker incoming_frame_race_checker_;
218 Atomic32 posted_frames_waiting_for_encode_; 220 Atomic32 posted_frames_waiting_for_encode_;
219 // Used to make sure incoming time stamp is increasing for every frame. 221 // Used to make sure incoming time stamp is increasing for every frame.
220 int64_t last_captured_timestamp_ GUARDED_BY(incoming_frame_race_checker_); 222 int64_t last_captured_timestamp_ GUARDED_BY(incoming_frame_race_checker_);
221 // Delta used for translating between NTP and internal timestamps. 223 // Delta used for translating between NTP and internal timestamps.
222 const int64_t delta_ntp_internal_ms_; 224 const int64_t delta_ntp_internal_ms_;
223 225
224 int64_t last_frame_log_ms_ GUARDED_BY(incoming_frame_race_checker_); 226 int64_t last_frame_log_ms_ GUARDED_BY(incoming_frame_race_checker_);
225 int captured_frame_count_ ACCESS_ON(&encoder_queue_); 227 int captured_frame_count_ ACCESS_ON(&encoder_queue_);
226 int dropped_frame_count_ ACCESS_ON(&encoder_queue_); 228 int dropped_frame_count_ ACCESS_ON(&encoder_queue_);
227 229
228 // All public methods are proxied to |encoder_queue_|. It must must be 230 // All public methods are proxied to |encoder_queue_|. It must must be
229 // destroyed first to make sure no tasks are run that use other members. 231 // destroyed first to make sure no tasks are run that use other members.
230 rtc::TaskQueue encoder_queue_; 232 rtc::TaskQueue encoder_queue_;
231 233
232 RTC_DISALLOW_COPY_AND_ASSIGN(ViEEncoder); 234 RTC_DISALLOW_COPY_AND_ASSIGN(ViEEncoder);
233 }; 235 };
234 236
235 } // namespace webrtc 237 } // namespace webrtc
236 238
237 #endif // WEBRTC_VIDEO_VIE_ENCODER_H_ 239 #endif // WEBRTC_VIDEO_VIE_ENCODER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698