| 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 // 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 |
| 43 // and produces an encoded bit stream. | 43 // and produces an encoded bit stream. |
| 44 // Usage: | 44 // Usage: |
| 45 // 1. Instantiate | 45 // 1. Instantiate |
| 46 // 2. Call Init | 46 // 2. Call Init |
| 47 // 3. Call RegisterExternalEncoder if available. | 47 // 3. Call RegisterExternalEncoder if available. |
| 48 // 4. Call SetEncoder with the codec settings and the object that shall receive | 48 // 4. Call SetEncoder with the codec settings and the object that shall receive |
| 49 // the encoded bit stream. | 49 // the encoded bit stream. |
| 50 // 5. Call Start. | 50 // 5. Call Start. |
| 51 // 6. For each available raw video frame call EncodeVideoFrame. | 51 // 6. For each available raw video frame call EncodeVideoFrame. |
| 52 |
| 53 class VideoEncoderSink : public EncodedImageCallback { |
| 54 public: |
| 55 static const int TimeOutMs = 2000; |
| 56 |
| 57 // Triggered if the encoder has not produced a frame for |TimeOutMs|. |
| 58 // The effect of this call is that no padding will be sent for this stream and |
| 59 // thus, this method should thus not be called if padding is needed. |
| 60 // Note that this method should not be called if the encoder is |
| 61 // not supposed to produce data. Ie, the current allowed bitrate is zero. |
| 62 // May be called on an arbitrary thread. |
| 63 virtual void OnEncoderActivityChanged(bool running) = 0; |
| 64 |
| 65 protected: |
| 66 virtual ~VideoEncoderSink() {} |
| 67 }; |
| 68 |
| 52 class ViEEncoder : public VideoEncoderRateObserver, | 69 class ViEEncoder : public VideoEncoderRateObserver, |
| 53 public EncodedImageCallback, | 70 public EncodedImageCallback, |
| 54 public VCMSendStatisticsCallback { | 71 public VCMSendStatisticsCallback { |
| 55 public: | 72 public: |
| 56 friend class ViEBitrateObserver; | 73 friend class ViEBitrateObserver; |
| 57 | 74 |
| 58 ViEEncoder(uint32_t number_of_cores, | 75 ViEEncoder(uint32_t number_of_cores, |
| 59 ProcessThread* module_process_thread, | 76 ProcessThread* module_process_thread, |
| 60 SendStatisticsProxy* stats_proxy, | 77 SendStatisticsProxy* stats_proxy, |
| 61 OveruseFrameDetector* overuse_detector, | 78 OveruseFrameDetector* overuse_detector, |
| 62 EncodedImageCallback* sink); | 79 VideoEncoderSink* sink); |
| 63 | |
| 64 ~ViEEncoder(); | 80 ~ViEEncoder(); |
| 65 | 81 |
| 66 vcm::VideoSender* video_sender(); | 82 vcm::VideoSender* video_sender(); |
| 67 | 83 |
| 68 // Returns the id of the owning channel. | 84 // Returns the id of the owning channel. |
| 69 int Owner() const; | 85 int Owner() const; |
| 70 | 86 |
| 71 void Start(); | 87 void Start(); |
| 72 // Drops incoming packets before they get to the encoder. | 88 // Drops incoming packets before they get to the encoder. |
| 73 void Pause(); | 89 void Pause(); |
| 74 | 90 |
| 75 // Codec settings. | 91 // Codec settings. |
| 76 int32_t RegisterExternalEncoder(VideoEncoder* encoder, | 92 int32_t RegisterExternalEncoder(VideoEncoder* encoder, |
| 77 uint8_t pl_type, | 93 uint8_t pl_type, |
| 78 bool internal_source); | 94 bool internal_source); |
| 79 int32_t DeRegisterExternalEncoder(uint8_t pl_type); | 95 int32_t DeRegisterExternalEncoder(uint8_t pl_type); |
| 80 void SetEncoder(const VideoCodec& video_codec, | 96 void SetEncoder(const VideoCodec& video_codec, |
| 81 int min_transmit_bitrate_bps, | |
| 82 size_t max_data_payload_length); | 97 size_t max_data_payload_length); |
| 83 | 98 |
| 84 void EncodeVideoFrame(const VideoFrame& video_frame); | 99 void EncodeVideoFrame(const VideoFrame& video_frame); |
| 85 void SendKeyFrame(); | 100 void SendKeyFrame(); |
| 86 | 101 |
| 102 // Checks to see if the encoder has produced anything during the last |
| 103 // VideoEncoderSink::TimeOutMs period and if the state has changed, calls |
| 104 // VideoEncoderSink::OnEncoderActivityChanged. |
| 105 // Must be called periodically. |
| 106 // TODO(perkj): CheckForActivity should be replaced with an internal timer |
| 107 // once ViEncoder owns the encoder thread. |
| 108 void CheckForActivity(); |
| 109 |
| 87 // Implements VideoEncoderRateObserver. | 110 // Implements VideoEncoderRateObserver. |
| 88 // TODO(perkj): Refactor VideoEncoderRateObserver. This is only used for | 111 // TODO(perkj): Refactor VideoEncoderRateObserver. This is only used for |
| 89 // stats. The stats should be set in VideoSendStream instead. | 112 // stats. The stats should be set in VideoSendStream instead. |
| 90 // |bitrate_bps| is the target bitrate and |framerate| is the input frame | 113 // |bitrate_bps| is the target bitrate and |framerate| is the input frame |
| 91 // rate so it has nothing to do with the actual encoder. | 114 // rate so it has nothing to do with the actual encoder. |
| 92 void OnSetRates(uint32_t bitrate_bps, int framerate) override; | 115 void OnSetRates(uint32_t bitrate_bps, int framerate) override; |
| 93 | 116 |
| 94 // Implements EncodedImageCallback. | 117 // Implements EncodedImageCallback. |
| 95 int32_t Encoded(const EncodedImage& encoded_image, | 118 int32_t Encoded(const EncodedImage& encoded_image, |
| 96 const CodecSpecificInfo* codec_specific_info, | 119 const CodecSpecificInfo* codec_specific_info, |
| 97 const RTPFragmentationHeader* fragmentation) override; | 120 const RTPFragmentationHeader* fragmentation) override; |
| 98 | 121 |
| 99 // Implements VideoSendStatisticsCallback. | 122 // Implements VideoSendStatisticsCallback. |
| 100 void SendStatistics(uint32_t bit_rate, | 123 void SendStatistics(uint32_t bit_rate, |
| 101 uint32_t frame_rate, | 124 uint32_t frame_rate, |
| 102 const std::string& encoder_name) override; | 125 const std::string& encoder_name) override; |
| 103 | 126 |
| 104 // virtual to test EncoderStateFeedback with mocks. | 127 // virtual to test EncoderStateFeedback with mocks. |
| 105 virtual void OnReceivedIntraFrameRequest(size_t stream_index); | 128 virtual void OnReceivedIntraFrameRequest(size_t stream_index); |
| 106 virtual void OnReceivedSLI(uint8_t picture_id); | 129 virtual void OnReceivedSLI(uint8_t picture_id); |
| 107 virtual void OnReceivedRPSI(uint64_t picture_id); | 130 virtual void OnReceivedRPSI(uint64_t picture_id); |
| 108 | 131 |
| 109 int GetPaddingNeededBps() const; | |
| 110 | |
| 111 void OnBitrateUpdated(uint32_t bitrate_bps, | 132 void OnBitrateUpdated(uint32_t bitrate_bps, |
| 112 uint8_t fraction_lost, | 133 uint8_t fraction_lost, |
| 113 int64_t round_trip_time_ms); | 134 int64_t round_trip_time_ms); |
| 114 | 135 |
| 115 private: | 136 private: |
| 116 bool EncoderPaused() const EXCLUSIVE_LOCKS_REQUIRED(data_cs_); | 137 bool EncoderPaused() const EXCLUSIVE_LOCKS_REQUIRED(data_cs_); |
| 117 void TraceFrameDropStart() EXCLUSIVE_LOCKS_REQUIRED(data_cs_); | 138 void TraceFrameDropStart() EXCLUSIVE_LOCKS_REQUIRED(data_cs_); |
| 118 void TraceFrameDropEnd() EXCLUSIVE_LOCKS_REQUIRED(data_cs_); | 139 void TraceFrameDropEnd() EXCLUSIVE_LOCKS_REQUIRED(data_cs_); |
| 119 | 140 |
| 120 const uint32_t number_of_cores_; | 141 const uint32_t number_of_cores_; |
| 121 EncodedImageCallback* const sink_; | 142 VideoEncoderSink* const sink_; |
| 122 | 143 |
| 123 const std::unique_ptr<VideoProcessing> vp_; | 144 const std::unique_ptr<VideoProcessing> vp_; |
| 124 vcm::VideoSender video_sender_; | 145 vcm::VideoSender video_sender_; |
| 125 | 146 |
| 126 rtc::CriticalSection data_cs_; | 147 rtc::CriticalSection data_cs_; |
| 127 | 148 |
| 128 SendStatisticsProxy* const stats_proxy_; | 149 SendStatisticsProxy* const stats_proxy_; |
| 129 OveruseFrameDetector* const overuse_detector_; | 150 OveruseFrameDetector* const overuse_detector_; |
| 130 | 151 |
| 131 // The time we last received an input frame or encoded frame. This is used to | 152 // The time we last received an input frame or encoded frame. This is used to |
| 132 // track when video is stopped long enough that we also want to stop sending | 153 // track when video is stopped long enough that we also want to stop sending |
| 133 // padding. | 154 // padding. |
| 134 int64_t time_of_last_frame_activity_ms_ GUARDED_BY(data_cs_); | 155 int64_t time_of_last_frame_activity_ms_ GUARDED_BY(data_cs_); |
| 135 VideoCodec encoder_config_ GUARDED_BY(data_cs_); | 156 VideoCodec encoder_config_ GUARDED_BY(data_cs_); |
| 136 int min_transmit_bitrate_bps_ GUARDED_BY(data_cs_); | |
| 137 uint32_t last_observed_bitrate_bps_ GUARDED_BY(data_cs_); | 157 uint32_t last_observed_bitrate_bps_ GUARDED_BY(data_cs_); |
| 138 bool encoder_paused_ GUARDED_BY(data_cs_); | 158 bool encoder_paused_ GUARDED_BY(data_cs_); |
| 139 bool encoder_paused_and_dropped_frame_ GUARDED_BY(data_cs_); | 159 bool encoder_paused_and_dropped_frame_ GUARDED_BY(data_cs_); |
| 160 bool reported_timeout_ GUARDED_BY(data_cs_); |
| 140 | 161 |
| 141 ProcessThread* module_process_thread_; | 162 ProcessThread* module_process_thread_; |
| 142 | 163 |
| 143 bool has_received_sli_ GUARDED_BY(data_cs_); | 164 bool has_received_sli_ GUARDED_BY(data_cs_); |
| 144 uint8_t picture_id_sli_ GUARDED_BY(data_cs_); | 165 uint8_t picture_id_sli_ GUARDED_BY(data_cs_); |
| 145 bool has_received_rpsi_ GUARDED_BY(data_cs_); | 166 bool has_received_rpsi_ GUARDED_BY(data_cs_); |
| 146 uint64_t picture_id_rpsi_ GUARDED_BY(data_cs_); | 167 uint64_t picture_id_rpsi_ GUARDED_BY(data_cs_); |
| 147 | 168 |
| 148 bool video_suspended_ GUARDED_BY(data_cs_); | 169 bool video_suspended_ GUARDED_BY(data_cs_); |
| 149 }; | 170 }; |
| 150 | 171 |
| 151 } // namespace webrtc | 172 } // namespace webrtc |
| 152 | 173 |
| 153 #endif // WEBRTC_VIDEO_VIE_ENCODER_H_ | 174 #endif // WEBRTC_VIDEO_VIE_ENCODER_H_ |
| OLD | NEW |