| 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 <map> | |
| 15 #include <memory> | 14 #include <memory> |
| 16 #include <string> | 15 #include <string> |
| 17 #include <vector> | 16 #include <vector> |
| 18 | 17 |
| 19 #include "webrtc/api/video/video_rotation.h" | 18 #include "webrtc/api/video/video_rotation.h" |
| 20 #include "webrtc/base/criticalsection.h" | 19 #include "webrtc/base/criticalsection.h" |
| 21 #include "webrtc/base/event.h" | 20 #include "webrtc/base/event.h" |
| 22 #include "webrtc/base/sequenced_task_checker.h" | 21 #include "webrtc/base/sequenced_task_checker.h" |
| 23 #include "webrtc/base/task_queue.h" | 22 #include "webrtc/base/task_queue.h" |
| 24 #include "webrtc/call/call.h" | 23 #include "webrtc/call/call.h" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 // Interface for receiving encoded video frames and notifications about | 55 // Interface for receiving encoded video frames and notifications about |
| 57 // configuration changes. | 56 // configuration changes. |
| 58 class EncoderSink : public EncodedImageCallback { | 57 class EncoderSink : public EncodedImageCallback { |
| 59 public: | 58 public: |
| 60 virtual void OnEncoderConfigurationChanged( | 59 virtual void OnEncoderConfigurationChanged( |
| 61 std::vector<VideoStream> streams, | 60 std::vector<VideoStream> streams, |
| 62 int min_transmit_bitrate_bps) = 0; | 61 int min_transmit_bitrate_bps) = 0; |
| 63 }; | 62 }; |
| 64 | 63 |
| 65 // Downscale resolution at most 2 times for CPU reasons. | 64 // Downscale resolution at most 2 times for CPU reasons. |
| 66 static const int kMaxCpuResolutionDowngrades = 2; | 65 static const int kMaxCpuDowngrades = 2; |
| 67 // Downscale framerate at most 4 times. | |
| 68 static const int kMaxCpuFramerateDowngrades = 4; | |
| 69 | 66 |
| 70 ViEEncoder(uint32_t number_of_cores, | 67 ViEEncoder(uint32_t number_of_cores, |
| 71 SendStatisticsProxy* stats_proxy, | 68 SendStatisticsProxy* stats_proxy, |
| 72 const VideoSendStream::Config::EncoderSettings& settings, | 69 const VideoSendStream::Config::EncoderSettings& settings, |
| 73 rtc::VideoSinkInterface<VideoFrame>* pre_encode_callback, | 70 rtc::VideoSinkInterface<VideoFrame>* pre_encode_callback, |
| 74 EncodedFrameObserver* encoder_timing); | 71 EncodedFrameObserver* encoder_timing); |
| 75 ~ViEEncoder(); | 72 ~ViEEncoder(); |
| 76 // RegisterProcessThread register |module_process_thread| with those objects | 73 // RegisterProcessThread register |module_process_thread| with those objects |
| 77 // that use it. Registration has to happen on the thread where | 74 // that use it. Registration has to happen on the thread where |
| 78 // |module_process_thread| was created (libjingle's worker thread). | 75 // |module_process_thread| was created (libjingle's worker thread). |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 const EncodedImage& encoded_image, | 167 const EncodedImage& encoded_image, |
| 171 const CodecSpecificInfo* codec_specific_info, | 168 const CodecSpecificInfo* codec_specific_info, |
| 172 const RTPFragmentationHeader* fragmentation) override; | 169 const RTPFragmentationHeader* fragmentation) override; |
| 173 | 170 |
| 174 void OnDroppedFrame() override; | 171 void OnDroppedFrame() override; |
| 175 | 172 |
| 176 bool EncoderPaused() const; | 173 bool EncoderPaused() const; |
| 177 void TraceFrameDropStart(); | 174 void TraceFrameDropStart(); |
| 178 void TraceFrameDropEnd(); | 175 void TraceFrameDropEnd(); |
| 179 | 176 |
| 180 const std::vector<int>& GetScaleCounters() | |
| 181 EXCLUSIVE_LOCKS_REQUIRED(&encoder_queue_); | |
| 182 void IncrementScaleCounter(int reason, int delta) | |
| 183 EXCLUSIVE_LOCKS_REQUIRED(&encoder_queue_); | |
| 184 | |
| 185 rtc::Event shutdown_event_; | 177 rtc::Event shutdown_event_; |
| 186 | 178 |
| 187 const uint32_t number_of_cores_; | 179 const uint32_t number_of_cores_; |
| 188 // Counts how many frames we've dropped in the initial rampup phase. | 180 // Counts how many frames we've dropped in the initial rampup phase. |
| 189 int initial_rampup_; | 181 int initial_rampup_; |
| 190 | 182 |
| 191 const std::unique_ptr<VideoSourceProxy> source_proxy_; | 183 const std::unique_ptr<VideoSourceProxy> source_proxy_; |
| 192 EncoderSink* sink_; | 184 EncoderSink* sink_; |
| 193 const VideoSendStream::Config::EncoderSettings settings_; | 185 const VideoSendStream::Config::EncoderSettings settings_; |
| 194 const VideoCodecType codec_type_; | 186 const VideoCodecType codec_type_; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 217 size_t max_data_payload_length_ ACCESS_ON(&encoder_queue_); | 209 size_t max_data_payload_length_ ACCESS_ON(&encoder_queue_); |
| 218 bool nack_enabled_ ACCESS_ON(&encoder_queue_); | 210 bool nack_enabled_ ACCESS_ON(&encoder_queue_); |
| 219 uint32_t last_observed_bitrate_bps_ ACCESS_ON(&encoder_queue_); | 211 uint32_t last_observed_bitrate_bps_ ACCESS_ON(&encoder_queue_); |
| 220 bool encoder_paused_and_dropped_frame_ ACCESS_ON(&encoder_queue_); | 212 bool encoder_paused_and_dropped_frame_ ACCESS_ON(&encoder_queue_); |
| 221 bool has_received_sli_ ACCESS_ON(&encoder_queue_); | 213 bool has_received_sli_ ACCESS_ON(&encoder_queue_); |
| 222 uint8_t picture_id_sli_ ACCESS_ON(&encoder_queue_); | 214 uint8_t picture_id_sli_ ACCESS_ON(&encoder_queue_); |
| 223 bool has_received_rpsi_ ACCESS_ON(&encoder_queue_); | 215 bool has_received_rpsi_ ACCESS_ON(&encoder_queue_); |
| 224 uint64_t picture_id_rpsi_ ACCESS_ON(&encoder_queue_); | 216 uint64_t picture_id_rpsi_ ACCESS_ON(&encoder_queue_); |
| 225 Clock* const clock_; | 217 Clock* const clock_; |
| 226 // Counters used for deciding if the video resolution is currently | 218 // Counters used for deciding if the video resolution is currently |
| 227 // restricted, and if so, why, on a per degradation preference basis. | 219 // restricted, and if so, why. |
| 228 // TODO(sprang): Replace this with a state holding a relative overuse measure | 220 std::vector<int> scale_counter_ ACCESS_ON(&encoder_queue_); |
| 229 // instead, that can be translated into suitable down-scale or fps limit. | |
| 230 std::map<const VideoSendStream::DegradationPreference, std::vector<int>> | |
| 231 scale_counters_ ACCESS_ON(&encoder_queue_); | |
| 232 // Set depending on degradation preferences | 221 // Set depending on degradation preferences |
| 233 VideoSendStream::DegradationPreference degradation_preference_ | 222 VideoSendStream::DegradationPreference degradation_preference_ |
| 234 ACCESS_ON(&encoder_queue_); | 223 ACCESS_ON(&encoder_queue_); |
| 235 | 224 |
| 236 struct AdaptationRequest { | 225 struct AdaptationRequest { |
| 237 // The pixel count produced by the source at the time of the adaptation. | 226 // The pixel count produced by the source at the time of the adaptation. |
| 238 int input_pixel_count_; | 227 int input_pixel_count_; |
| 239 // Framerate received from the source at the time of the adaptation. | |
| 240 int framerate_fps_; | |
| 241 // Indicates if request was to adapt up or down. | 228 // Indicates if request was to adapt up or down. |
| 242 enum class Mode { kAdaptUp, kAdaptDown } mode_; | 229 enum class Mode { kAdaptUp, kAdaptDown } mode_; |
| 243 }; | 230 }; |
| 244 // Stores a snapshot of the last adaptation request triggered by an AdaptUp | 231 // Stores a snapshot of the last adaptation request triggered by an AdaptUp |
| 245 // or AdaptDown signal. | 232 // or AdaptDown signal. |
| 246 rtc::Optional<AdaptationRequest> last_adaptation_request_ | 233 rtc::Optional<AdaptationRequest> last_adaptation_request_ |
| 247 ACCESS_ON(&encoder_queue_); | 234 ACCESS_ON(&encoder_queue_); |
| 248 | 235 |
| 249 rtc::RaceChecker incoming_frame_race_checker_ | 236 rtc::RaceChecker incoming_frame_race_checker_ |
| 250 GUARDED_BY(incoming_frame_race_checker_); | 237 GUARDED_BY(incoming_frame_race_checker_); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 264 // All public methods are proxied to |encoder_queue_|. It must must be | 251 // All public methods are proxied to |encoder_queue_|. It must must be |
| 265 // destroyed first to make sure no tasks are run that use other members. | 252 // destroyed first to make sure no tasks are run that use other members. |
| 266 rtc::TaskQueue encoder_queue_; | 253 rtc::TaskQueue encoder_queue_; |
| 267 | 254 |
| 268 RTC_DISALLOW_COPY_AND_ASSIGN(ViEEncoder); | 255 RTC_DISALLOW_COPY_AND_ASSIGN(ViEEncoder); |
| 269 }; | 256 }; |
| 270 | 257 |
| 271 } // namespace webrtc | 258 } // namespace webrtc |
| 272 | 259 |
| 273 #endif // WEBRTC_VIDEO_VIE_ENCODER_H_ | 260 #endif // WEBRTC_VIDEO_VIE_ENCODER_H_ |
| OLD | NEW |