Chromium Code Reviews| 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 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 53 public: | 53 public: |
| 54 // Interface for receiving encoded video frames and notifications about | 54 // Interface for receiving encoded video frames and notifications about |
| 55 // configuration changes. | 55 // configuration changes. |
| 56 class EncoderSink : public EncodedImageCallback { | 56 class EncoderSink : public EncodedImageCallback { |
| 57 public: | 57 public: |
| 58 virtual void OnEncoderConfigurationChanged( | 58 virtual void OnEncoderConfigurationChanged( |
| 59 std::vector<VideoStream> streams, | 59 std::vector<VideoStream> streams, |
| 60 int min_transmit_bitrate_bps) = 0; | 60 int min_transmit_bitrate_bps) = 0; |
| 61 }; | 61 }; |
| 62 | 62 |
| 63 // Down grade resolution at most 2 times for CPU reasons. | |
| 64 static const int kMaxCpuDowngrades = 2; | |
| 65 | |
| 63 ViEEncoder(uint32_t number_of_cores, | 66 ViEEncoder(uint32_t number_of_cores, |
| 64 SendStatisticsProxy* stats_proxy, | 67 SendStatisticsProxy* stats_proxy, |
| 65 const webrtc::VideoSendStream::Config::EncoderSettings& settings, | 68 const VideoSendStream::Config::EncoderSettings& settings, |
| 66 rtc::VideoSinkInterface<VideoFrame>* pre_encode_callback, | 69 rtc::VideoSinkInterface<VideoFrame>* pre_encode_callback, |
| 67 LoadObserver* overuse_callback, | |
| 68 EncodedFrameObserver* encoder_timing); | 70 EncodedFrameObserver* encoder_timing); |
| 69 ~ViEEncoder(); | 71 ~ViEEncoder(); |
| 70 // RegisterProcessThread register |module_process_thread| with those objects | 72 // RegisterProcessThread register |module_process_thread| with those objects |
| 71 // that use it. Registration has to happen on the thread where | 73 // that use it. Registration has to happen on the thread where |
| 72 // |module_process_thread| was created (libjingle's worker thread). | 74 // |module_process_thread| was created (libjingle's worker thread). |
| 73 // TODO(perkj): Replace the use of |module_process_thread| with a TaskQueue. | 75 // TODO(perkj): Replace the use of |module_process_thread| with a TaskQueue. |
| 74 void RegisterProcessThread(ProcessThread* module_process_thread); | 76 void RegisterProcessThread(ProcessThread* module_process_thread); |
| 75 void DeRegisterProcessThread(); | 77 void DeRegisterProcessThread(); |
| 76 | 78 |
| 77 void SetSource(rtc::VideoSourceInterface<VideoFrame>* source); | 79 // Sets the source that will provide I420 video frames. |
| 78 void SetSink(EncoderSink* sink); | 80 // |degradation_preference| control weather or not resolution may reduced. |
|
åsapersson
2016/10/31 08:43:02
whether
perkj_webrtc
2016/10/31 19:45:18
nice spelling ! thanks
| |
| 81 void SetSource( | |
| 82 rtc::VideoSourceInterface<VideoFrame>* source, | |
| 83 const VideoSendStream::DegradationPreference& degradation_preference); | |
| 84 | |
| 85 // Sets the |sink| that gets the encoded frames. |rotation_applied| means | |
| 86 // that the source must support rotation. Only set |rotation_applied| if the | |
| 87 // remote side does not support the rotation extension. | |
| 88 void SetSink(EncoderSink* sink, bool rotation_applied); | |
| 79 | 89 |
| 80 // TODO(perkj): Can we remove VideoCodec.startBitrate ? | 90 // TODO(perkj): Can we remove VideoCodec.startBitrate ? |
| 81 void SetStartBitrate(int start_bitrate_bps); | 91 void SetStartBitrate(int start_bitrate_bps); |
| 82 | 92 |
| 83 void ConfigureEncoder(VideoEncoderConfig config, | 93 void ConfigureEncoder(VideoEncoderConfig config, |
| 84 size_t max_data_payload_length); | 94 size_t max_data_payload_length); |
| 85 | 95 |
| 86 // Permanently stop encoding. After this method has returned, it is | 96 // Permanently stop encoding. After this method has returned, it is |
| 87 // guaranteed that no encoded frames will be delivered to the sink. | 97 // guaranteed that no encoded frames will be delivered to the sink. |
| 88 void Stop(); | 98 void Stop(); |
| 89 | 99 |
| 90 void SendKeyFrame(); | 100 void SendKeyFrame(); |
| 91 | 101 |
| 92 // virtual to test EncoderStateFeedback with mocks. | 102 // virtual to test EncoderStateFeedback with mocks. |
| 93 virtual void OnReceivedIntraFrameRequest(size_t stream_index); | 103 virtual void OnReceivedIntraFrameRequest(size_t stream_index); |
| 94 virtual void OnReceivedSLI(uint8_t picture_id); | 104 virtual void OnReceivedSLI(uint8_t picture_id); |
| 95 virtual void OnReceivedRPSI(uint64_t picture_id); | 105 virtual void OnReceivedRPSI(uint64_t picture_id); |
| 96 | 106 |
| 97 void OnBitrateUpdated(uint32_t bitrate_bps, | 107 void OnBitrateUpdated(uint32_t bitrate_bps, |
| 98 uint8_t fraction_lost, | 108 uint8_t fraction_lost, |
| 99 int64_t round_trip_time_ms); | 109 int64_t round_trip_time_ms); |
| 100 | 110 |
| 111 protected: | |
| 112 // Used for testing. For example the |CpuOveruseObserver| methods must be | |
| 113 // called on |encoder_queue_|. | |
| 114 rtc::TaskQueue* encoder_queue() { return &encoder_queue_; } | |
| 115 | |
| 116 // webrtc::CpuOveruseObserver implementation. | |
| 117 // These methods are protected for easier testing. | |
| 118 void OveruseDetected() override; | |
| 119 void NormalUsage() override; | |
| 120 | |
| 101 private: | 121 private: |
| 102 class ConfigureEncoderTask; | 122 class ConfigureEncoderTask; |
| 103 class EncodeTask; | 123 class EncodeTask; |
| 104 class VideoSourceProxy; | 124 class VideoSourceProxy; |
| 105 | 125 |
| 106 struct VideoFrameInfo { | 126 struct VideoFrameInfo { |
| 107 VideoFrameInfo(int width, | 127 VideoFrameInfo(int width, |
| 108 int height, | 128 int height, |
| 109 VideoRotation rotation, | 129 VideoRotation rotation, |
| 110 bool is_texture) | 130 bool is_texture) |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 131 | 151 |
| 132 void EncodeVideoFrame(const VideoFrame& frame, | 152 void EncodeVideoFrame(const VideoFrame& frame, |
| 133 int64_t time_when_posted_in_ms); | 153 int64_t time_when_posted_in_ms); |
| 134 | 154 |
| 135 // Implements EncodedImageCallback. | 155 // Implements EncodedImageCallback. |
| 136 EncodedImageCallback::Result OnEncodedImage( | 156 EncodedImageCallback::Result OnEncodedImage( |
| 137 const EncodedImage& encoded_image, | 157 const EncodedImage& encoded_image, |
| 138 const CodecSpecificInfo* codec_specific_info, | 158 const CodecSpecificInfo* codec_specific_info, |
| 139 const RTPFragmentationHeader* fragmentation) override; | 159 const RTPFragmentationHeader* fragmentation) override; |
| 140 | 160 |
| 141 // webrtc::CpuOveruseObserver implementation. | |
| 142 void OveruseDetected() override; | |
| 143 void NormalUsage() override; | |
| 144 | |
| 145 bool EncoderPaused() const; | 161 bool EncoderPaused() const; |
| 146 void TraceFrameDropStart(); | 162 void TraceFrameDropStart(); |
| 147 void TraceFrameDropEnd(); | 163 void TraceFrameDropEnd(); |
| 148 | 164 |
| 149 rtc::Event shutdown_event_; | 165 rtc::Event shutdown_event_; |
| 150 | 166 |
| 151 const uint32_t number_of_cores_; | 167 const uint32_t number_of_cores_; |
| 152 | 168 |
| 153 const std::unique_ptr<VideoSourceProxy> source_proxy_; | 169 const std::unique_ptr<VideoSourceProxy> source_proxy_; |
| 154 EncoderSink* sink_; | 170 EncoderSink* sink_; |
| 155 const VideoSendStream::Config::EncoderSettings settings_; | 171 const VideoSendStream::Config::EncoderSettings settings_; |
| 156 const VideoCodecType codec_type_; | 172 const VideoCodecType codec_type_; |
| 157 | 173 |
| 158 vcm::VideoSender video_sender_ ACCESS_ON(&encoder_queue_); | 174 vcm::VideoSender video_sender_ ACCESS_ON(&encoder_queue_); |
| 159 | |
| 160 OveruseFrameDetector overuse_detector_ ACCESS_ON(&encoder_queue_); | 175 OveruseFrameDetector overuse_detector_ ACCESS_ON(&encoder_queue_); |
| 161 LoadObserver* const load_observer_ ACCESS_ON(&encoder_queue_); | |
| 162 | 176 |
| 163 SendStatisticsProxy* const stats_proxy_; | 177 SendStatisticsProxy* const stats_proxy_; |
| 164 rtc::VideoSinkInterface<VideoFrame>* const pre_encode_callback_; | 178 rtc::VideoSinkInterface<VideoFrame>* const pre_encode_callback_; |
| 165 ProcessThread* module_process_thread_; | 179 ProcessThread* module_process_thread_; |
| 166 rtc::ThreadChecker module_process_thread_checker_; | 180 rtc::ThreadChecker module_process_thread_checker_; |
| 167 // |thread_checker_| checks that public methods that are related to lifetime | 181 // |thread_checker_| checks that public methods that are related to lifetime |
| 168 // of ViEEncoder are called on the same thread. | 182 // of ViEEncoder are called on the same thread. |
| 169 rtc::ThreadChecker thread_checker_; | 183 rtc::ThreadChecker thread_checker_; |
| 170 | 184 |
| 171 VideoEncoderConfig encoder_config_ ACCESS_ON(&encoder_queue_); | 185 VideoEncoderConfig encoder_config_ ACCESS_ON(&encoder_queue_); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 182 uint32_t encoder_start_bitrate_bps_ ACCESS_ON(&encoder_queue_); | 196 uint32_t encoder_start_bitrate_bps_ ACCESS_ON(&encoder_queue_); |
| 183 size_t max_data_payload_length_ ACCESS_ON(&encoder_queue_); | 197 size_t max_data_payload_length_ ACCESS_ON(&encoder_queue_); |
| 184 uint32_t last_observed_bitrate_bps_ ACCESS_ON(&encoder_queue_); | 198 uint32_t last_observed_bitrate_bps_ ACCESS_ON(&encoder_queue_); |
| 185 bool encoder_paused_and_dropped_frame_ ACCESS_ON(&encoder_queue_); | 199 bool encoder_paused_and_dropped_frame_ ACCESS_ON(&encoder_queue_); |
| 186 bool has_received_sli_ ACCESS_ON(&encoder_queue_); | 200 bool has_received_sli_ ACCESS_ON(&encoder_queue_); |
| 187 uint8_t picture_id_sli_ ACCESS_ON(&encoder_queue_); | 201 uint8_t picture_id_sli_ ACCESS_ON(&encoder_queue_); |
| 188 bool has_received_rpsi_ ACCESS_ON(&encoder_queue_); | 202 bool has_received_rpsi_ ACCESS_ON(&encoder_queue_); |
| 189 uint64_t picture_id_rpsi_ ACCESS_ON(&encoder_queue_); | 203 uint64_t picture_id_rpsi_ ACCESS_ON(&encoder_queue_); |
| 190 Clock* const clock_; | 204 Clock* const clock_; |
| 191 | 205 |
| 192 rtc::RaceChecker incoming_frame_race_checker_; | 206 VideoSendStream::DegradationPreference degradation_preference_ |
| 207 ACCESS_ON(&encoder_queue_); | |
| 208 // Counter used for deciding if the video resolution is currently | |
| 209 // restricted by CPU usage. | |
| 210 int cpu_restricted_counter_ ACCESS_ON(&encoder_queue_); | |
| 211 | |
| 212 int last_frame_width_ ACCESS_ON(&encoder_queue_); | |
| 213 int last_frame_height_ ACCESS_ON(&encoder_queue_); | |
| 214 // Pixel count last time the resolution was requested to be changed down. | |
| 215 rtc::Optional<int> max_pixel_count_ ACCESS_ON(&encoder_queue_); | |
| 216 // Pixel count last time the resolution was requested to be changed up. | |
| 217 rtc::Optional<int> max_pixel_count_step_up_ ACCESS_ON(&encoder_queue_); | |
| 218 | |
| 219 rtc::RaceChecker incoming_frame_race_checker_ | |
| 220 GUARDED_BY(incoming_frame_race_checker_); | |
| 193 Atomic32 posted_frames_waiting_for_encode_; | 221 Atomic32 posted_frames_waiting_for_encode_; |
| 194 // Used to make sure incoming time stamp is increasing for every frame. | 222 // Used to make sure incoming time stamp is increasing for every frame. |
| 195 int64_t last_captured_timestamp_ GUARDED_BY(incoming_frame_race_checker_); | 223 int64_t last_captured_timestamp_ GUARDED_BY(incoming_frame_race_checker_); |
| 196 // Delta used for translating between NTP and internal timestamps. | 224 // Delta used for translating between NTP and internal timestamps. |
| 197 const int64_t delta_ntp_internal_ms_; | 225 const int64_t delta_ntp_internal_ms_ GUARDED_BY(incoming_frame_race_checker_); |
| 198 | 226 |
| 199 int64_t last_frame_log_ms_ GUARDED_BY(incoming_frame_race_checker_); | 227 int64_t last_frame_log_ms_ GUARDED_BY(incoming_frame_race_checker_); |
| 200 int captured_frame_count_ ACCESS_ON(&encoder_queue_); | 228 int captured_frame_count_ ACCESS_ON(&encoder_queue_); |
| 201 int dropped_frame_count_ ACCESS_ON(&encoder_queue_); | 229 int dropped_frame_count_ ACCESS_ON(&encoder_queue_); |
| 202 | 230 |
| 203 // All public methods are proxied to |encoder_queue_|. It must must be | 231 // All public methods are proxied to |encoder_queue_|. It must must be |
| 204 // destroyed first to make sure no tasks are run that use other members. | 232 // destroyed first to make sure no tasks are run that use other members. |
| 205 rtc::TaskQueue encoder_queue_; | 233 rtc::TaskQueue encoder_queue_; |
| 206 | 234 |
| 207 RTC_DISALLOW_COPY_AND_ASSIGN(ViEEncoder); | 235 RTC_DISALLOW_COPY_AND_ASSIGN(ViEEncoder); |
| 208 }; | 236 }; |
| 209 | 237 |
| 210 } // namespace webrtc | 238 } // namespace webrtc |
| 211 | 239 |
| 212 #endif // WEBRTC_VIDEO_VIE_ENCODER_H_ | 240 #endif // WEBRTC_VIDEO_VIE_ENCODER_H_ |
| OLD | NEW |