| 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 <vector> | 14 #include <vector> |
| 16 | 15 |
| 17 #include "webrtc/base/criticalsection.h" | 16 #include "webrtc/base/criticalsection.h" |
| 18 #include "webrtc/base/scoped_ptr.h" | 17 #include "webrtc/base/scoped_ptr.h" |
| 19 #include "webrtc/base/scoped_ref_ptr.h" | 18 #include "webrtc/base/scoped_ref_ptr.h" |
| 20 #include "webrtc/base/thread_annotations.h" | 19 #include "webrtc/base/thread_annotations.h" |
| 21 #include "webrtc/call/bitrate_allocator.h" | 20 #include "webrtc/call/bitrate_allocator.h" |
| 22 #include "webrtc/common_types.h" | 21 #include "webrtc/common_types.h" |
| 23 #include "webrtc/frame_callback.h" | 22 #include "webrtc/frame_callback.h" |
| 24 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" | 23 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 36 class OveruseFrameDetector; | 35 class OveruseFrameDetector; |
| 37 class PacedSender; | 36 class PacedSender; |
| 38 class PayloadRouter; | 37 class PayloadRouter; |
| 39 class ProcessThread; | 38 class ProcessThread; |
| 40 class QMVideoSettingsCallback; | 39 class QMVideoSettingsCallback; |
| 41 class SendStatisticsProxy; | 40 class SendStatisticsProxy; |
| 42 class ViEBitrateObserver; | 41 class ViEBitrateObserver; |
| 43 class ViEEffectFilter; | 42 class ViEEffectFilter; |
| 44 class VideoCodingModule; | 43 class VideoCodingModule; |
| 45 | 44 |
| 46 class ViEEncoder : public RtcpIntraFrameObserver, | 45 class ViEEncoder : public VideoEncoderRateObserver, |
| 47 public VideoEncoderRateObserver, | |
| 48 public VCMPacketizationCallback, | 46 public VCMPacketizationCallback, |
| 49 public VCMSendStatisticsCallback, | 47 public VCMSendStatisticsCallback, |
| 50 public VideoCaptureCallback { | 48 public VideoCaptureCallback { |
| 51 public: | 49 public: |
| 52 friend class ViEBitrateObserver; | 50 friend class ViEBitrateObserver; |
| 53 | 51 |
| 54 ViEEncoder(uint32_t number_of_cores, | 52 ViEEncoder(uint32_t number_of_cores, |
| 53 const std::vector<uint32_t>& ssrcs, |
| 55 ProcessThread* module_process_thread, | 54 ProcessThread* module_process_thread, |
| 56 SendStatisticsProxy* stats_proxy, | 55 SendStatisticsProxy* stats_proxy, |
| 57 I420FrameCallback* pre_encode_callback, | 56 I420FrameCallback* pre_encode_callback, |
| 58 OveruseFrameDetector* overuse_detector, | 57 OveruseFrameDetector* overuse_detector, |
| 59 PacedSender* pacer, | 58 PacedSender* pacer, |
| 60 PayloadRouter* payload_router, | 59 PayloadRouter* payload_router, |
| 61 BitrateAllocator* bitrate_allocator); | 60 BitrateAllocator* bitrate_allocator); |
| 62 ~ViEEncoder(); | 61 ~ViEEncoder(); |
| 63 | 62 |
| 64 bool Init(); | 63 bool Init(); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 int32_t SendData(uint8_t payload_type, | 103 int32_t SendData(uint8_t payload_type, |
| 105 const EncodedImage& encoded_image, | 104 const EncodedImage& encoded_image, |
| 106 const RTPFragmentationHeader* fragmentation_header, | 105 const RTPFragmentationHeader* fragmentation_header, |
| 107 const RTPVideoHeader* rtp_video_hdr) override; | 106 const RTPVideoHeader* rtp_video_hdr) override; |
| 108 void OnEncoderImplementationName(const char* implementation_name) override; | 107 void OnEncoderImplementationName(const char* implementation_name) override; |
| 109 | 108 |
| 110 // Implements VideoSendStatisticsCallback. | 109 // Implements VideoSendStatisticsCallback. |
| 111 int32_t SendStatistics(const uint32_t bit_rate, | 110 int32_t SendStatistics(const uint32_t bit_rate, |
| 112 const uint32_t frame_rate) override; | 111 const uint32_t frame_rate) override; |
| 113 | 112 |
| 114 // Implements RtcpIntraFrameObserver. | 113 // virtual to test EncoderStateFeedback with mocks. |
| 115 void OnReceivedIntraFrameRequest(uint32_t ssrc) override; | 114 virtual void OnReceivedIntraFrameRequest(uint32_t ssrc); |
| 116 void OnReceivedSLI(uint32_t ssrc, uint8_t picture_id) override; | 115 virtual void OnReceivedSLI(uint32_t ssrc, uint8_t picture_id); |
| 117 void OnReceivedRPSI(uint32_t ssrc, uint64_t picture_id) override; | 116 virtual void OnReceivedRPSI(uint32_t ssrc, uint64_t picture_id); |
| 118 void OnLocalSsrcChanged(uint32_t old_ssrc, uint32_t new_ssrc) override; | |
| 119 | |
| 120 // Sets SSRCs for all streams. | |
| 121 void SetSsrcs(const std::vector<uint32_t>& ssrcs); | |
| 122 | 117 |
| 123 void SetMinTransmitBitrate(int min_transmit_bitrate_kbps); | 118 void SetMinTransmitBitrate(int min_transmit_bitrate_kbps); |
| 124 | 119 |
| 125 // Lets the sender suspend video when the rate drops below | 120 // Lets the sender suspend video when the rate drops below |
| 126 // |threshold_bps|, and turns back on when the rate goes back up above | 121 // |threshold_bps|, and turns back on when the rate goes back up above |
| 127 // |threshold_bps| + |window_bps|. | 122 // |threshold_bps| + |window_bps|. |
| 128 void SuspendBelowMinBitrate(); | 123 void SuspendBelowMinBitrate(); |
| 129 | 124 |
| 130 // New-style callbacks, used by VideoSendStream. | 125 // New-style callbacks, used by VideoSendStream. |
| 131 void RegisterPostEncodeImageCallback( | 126 void RegisterPostEncodeImageCallback( |
| 132 EncodedImageCallback* post_encode_callback); | 127 EncodedImageCallback* post_encode_callback); |
| 133 | 128 |
| 134 int GetPaddingNeededBps() const; | 129 int GetPaddingNeededBps() const; |
| 135 | 130 |
| 136 protected: | 131 protected: |
| 137 // Called by BitrateObserver. | 132 // Called by BitrateObserver. |
| 138 void OnNetworkChanged(uint32_t bitrate_bps, | 133 void OnNetworkChanged(uint32_t bitrate_bps, |
| 139 uint8_t fraction_lost, | 134 uint8_t fraction_lost, |
| 140 int64_t round_trip_time_ms); | 135 int64_t round_trip_time_ms); |
| 141 | 136 |
| 142 private: | 137 private: |
| 143 bool EncoderPaused() const EXCLUSIVE_LOCKS_REQUIRED(data_cs_); | 138 bool EncoderPaused() const EXCLUSIVE_LOCKS_REQUIRED(data_cs_); |
| 144 void TraceFrameDropStart() EXCLUSIVE_LOCKS_REQUIRED(data_cs_); | 139 void TraceFrameDropStart() EXCLUSIVE_LOCKS_REQUIRED(data_cs_); |
| 145 void TraceFrameDropEnd() EXCLUSIVE_LOCKS_REQUIRED(data_cs_); | 140 void TraceFrameDropEnd() EXCLUSIVE_LOCKS_REQUIRED(data_cs_); |
| 146 | 141 |
| 147 const uint32_t number_of_cores_; | 142 const uint32_t number_of_cores_; |
| 143 const std::vector<uint32_t> ssrcs_; |
| 148 | 144 |
| 149 const rtc::scoped_ptr<VideoProcessing> vp_; | 145 const rtc::scoped_ptr<VideoProcessing> vp_; |
| 150 const rtc::scoped_ptr<QMVideoSettingsCallback> qm_callback_; | 146 const rtc::scoped_ptr<QMVideoSettingsCallback> qm_callback_; |
| 151 const rtc::scoped_ptr<VideoCodingModule> vcm_; | 147 const rtc::scoped_ptr<VideoCodingModule> vcm_; |
| 152 | 148 |
| 153 rtc::CriticalSection data_cs_; | 149 rtc::CriticalSection data_cs_; |
| 154 rtc::scoped_ptr<BitrateObserver> bitrate_observer_; | 150 rtc::scoped_ptr<BitrateObserver> bitrate_observer_; |
| 155 | 151 |
| 156 SendStatisticsProxy* const stats_proxy_; | 152 SendStatisticsProxy* const stats_proxy_; |
| 157 I420FrameCallback* const pre_encode_callback_; | 153 I420FrameCallback* const pre_encode_callback_; |
| 158 OveruseFrameDetector* const overuse_detector_; | 154 OveruseFrameDetector* const overuse_detector_; |
| 159 PacedSender* const pacer_; | 155 PacedSender* const pacer_; |
| 160 PayloadRouter* const send_payload_router_; | 156 PayloadRouter* const send_payload_router_; |
| 161 BitrateAllocator* const bitrate_allocator_; | 157 BitrateAllocator* const bitrate_allocator_; |
| 162 | 158 |
| 163 // The time we last received an input frame or encoded frame. This is used to | 159 // The time we last received an input frame or encoded frame. This is used to |
| 164 // track when video is stopped long enough that we also want to stop sending | 160 // track when video is stopped long enough that we also want to stop sending |
| 165 // padding. | 161 // padding. |
| 166 int64_t time_of_last_frame_activity_ms_ GUARDED_BY(data_cs_); | 162 int64_t time_of_last_frame_activity_ms_ GUARDED_BY(data_cs_); |
| 167 VideoCodec encoder_config_ GUARDED_BY(data_cs_); | 163 VideoCodec encoder_config_ GUARDED_BY(data_cs_); |
| 168 int min_transmit_bitrate_kbps_ GUARDED_BY(data_cs_); | 164 int min_transmit_bitrate_kbps_ GUARDED_BY(data_cs_); |
| 169 uint32_t last_observed_bitrate_bps_ GUARDED_BY(data_cs_); | 165 uint32_t last_observed_bitrate_bps_ GUARDED_BY(data_cs_); |
| 170 int target_delay_ms_ GUARDED_BY(data_cs_); | 166 int target_delay_ms_ GUARDED_BY(data_cs_); |
| 171 bool network_is_transmitting_ GUARDED_BY(data_cs_); | 167 bool network_is_transmitting_ GUARDED_BY(data_cs_); |
| 172 bool encoder_paused_ GUARDED_BY(data_cs_); | 168 bool encoder_paused_ GUARDED_BY(data_cs_); |
| 173 bool encoder_paused_and_dropped_frame_ GUARDED_BY(data_cs_); | 169 bool encoder_paused_and_dropped_frame_ GUARDED_BY(data_cs_); |
| 174 std::map<unsigned int, int64_t> time_last_intra_request_ms_ | 170 std::vector<int64_t> time_last_intra_request_ms_ GUARDED_BY(data_cs_); |
| 175 GUARDED_BY(data_cs_); | |
| 176 | 171 |
| 177 ProcessThread* module_process_thread_; | 172 ProcessThread* module_process_thread_; |
| 178 | 173 |
| 179 bool has_received_sli_ GUARDED_BY(data_cs_); | 174 bool has_received_sli_ GUARDED_BY(data_cs_); |
| 180 uint8_t picture_id_sli_ GUARDED_BY(data_cs_); | 175 uint8_t picture_id_sli_ GUARDED_BY(data_cs_); |
| 181 bool has_received_rpsi_ GUARDED_BY(data_cs_); | 176 bool has_received_rpsi_ GUARDED_BY(data_cs_); |
| 182 uint64_t picture_id_rpsi_ GUARDED_BY(data_cs_); | 177 uint64_t picture_id_rpsi_ GUARDED_BY(data_cs_); |
| 183 std::map<uint32_t, int> ssrc_streams_ GUARDED_BY(data_cs_); | |
| 184 | 178 |
| 185 bool video_suspended_ GUARDED_BY(data_cs_); | 179 bool video_suspended_ GUARDED_BY(data_cs_); |
| 186 }; | 180 }; |
| 187 | 181 |
| 188 } // namespace webrtc | 182 } // namespace webrtc |
| 189 | 183 |
| 190 #endif // WEBRTC_VIDEO_VIE_ENCODER_H_ | 184 #endif // WEBRTC_VIDEO_VIE_ENCODER_H_ |
| OLD | NEW |