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

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

Issue 1993113003: Refactor how padding is calculated. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Self review Created 4 years, 7 months 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
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 uint32_t LastObservedBitrateBps() const; 110 uint32_t LastObservedBitrateBps() const;
88 // Loss protection. Must be called before SetEncoder() to have max packet size 111 // Loss protection. Must be called before SetEncoder() to have max packet size
89 // updated according to protection. 112 // updated according to protection.
90 // TODO(pbos): Set protection method on construction. 113 // TODO(pbos): Set protection method on construction.
91 void SetProtectionMethod(bool nack, bool fec); 114 void SetProtectionMethod(bool nack, bool fec);
92 115
93 // Implements VideoEncoderRateObserver. 116 // Implements VideoEncoderRateObserver.
94 void OnSetRates(uint32_t bitrate_bps, int framerate) override; 117 void OnSetRates(uint32_t bitrate_bps, int framerate) override;
95 118
96 // Implements EncodedImageCallback. 119 // Implements EncodedImageCallback.
97 int32_t Encoded(const EncodedImage& encoded_image, 120 int32_t Encoded(const EncodedImage& encoded_image,
98 const CodecSpecificInfo* codec_specific_info, 121 const CodecSpecificInfo* codec_specific_info,
99 const RTPFragmentationHeader* fragmentation) override; 122 const RTPFragmentationHeader* fragmentation) override;
100 123
101 // Implements VideoSendStatisticsCallback. 124 // Implements VideoSendStatisticsCallback.
102 void SendStatistics(uint32_t bit_rate, 125 void SendStatistics(uint32_t bit_rate,
103 uint32_t frame_rate, 126 uint32_t frame_rate,
104 const std::string& encoder_name) override; 127 const std::string& encoder_name) override;
105 128
106 // virtual to test EncoderStateFeedback with mocks. 129 // virtual to test EncoderStateFeedback with mocks.
107 virtual void OnReceivedIntraFrameRequest(size_t stream_index); 130 virtual void OnReceivedIntraFrameRequest(size_t stream_index);
108 virtual void OnReceivedSLI(uint8_t picture_id); 131 virtual void OnReceivedSLI(uint8_t picture_id);
109 virtual void OnReceivedRPSI(uint64_t picture_id); 132 virtual void OnReceivedRPSI(uint64_t picture_id);
110 133
111 int GetPaddingNeededBps() const;
112
113 void OnBitrateUpdated(uint32_t bitrate_bps, 134 void OnBitrateUpdated(uint32_t bitrate_bps,
114 uint8_t fraction_lost, 135 uint8_t fraction_lost,
115 int64_t round_trip_time_ms); 136 int64_t round_trip_time_ms);
116 137
117 private: 138 private:
118 bool EncoderPaused() const EXCLUSIVE_LOCKS_REQUIRED(data_cs_); 139 bool EncoderPaused() const EXCLUSIVE_LOCKS_REQUIRED(data_cs_);
119 void TraceFrameDropStart() EXCLUSIVE_LOCKS_REQUIRED(data_cs_); 140 void TraceFrameDropStart() EXCLUSIVE_LOCKS_REQUIRED(data_cs_);
120 void TraceFrameDropEnd() EXCLUSIVE_LOCKS_REQUIRED(data_cs_); 141 void TraceFrameDropEnd() EXCLUSIVE_LOCKS_REQUIRED(data_cs_);
121 142
122 const uint32_t number_of_cores_; 143 const uint32_t number_of_cores_;
123 EncodedImageCallback* const sink_; 144 VideoEncoderSink* const sink_;
124 145
125 const std::unique_ptr<VideoProcessing> vp_; 146 const std::unique_ptr<VideoProcessing> vp_;
126 vcm::VideoSender video_sender_; 147 vcm::VideoSender video_sender_;
127 148
128 rtc::CriticalSection data_cs_; 149 rtc::CriticalSection data_cs_;
129 150
130 SendStatisticsProxy* const stats_proxy_; 151 SendStatisticsProxy* const stats_proxy_;
131 OveruseFrameDetector* const overuse_detector_; 152 OveruseFrameDetector* const overuse_detector_;
132 153
133 // The time we last received an input frame or encoded frame. This is used to 154 // The time we last received an input frame or encoded frame. This is used to
134 // track when video is stopped long enough that we also want to stop sending 155 // track when video is stopped long enough that we also want to stop sending
135 // padding. 156 // padding.
136 int64_t time_of_last_frame_activity_ms_ GUARDED_BY(data_cs_); 157 int64_t time_of_last_frame_activity_ms_ GUARDED_BY(data_cs_);
137 VideoCodec encoder_config_ GUARDED_BY(data_cs_); 158 VideoCodec encoder_config_ GUARDED_BY(data_cs_);
138 int min_transmit_bitrate_bps_ GUARDED_BY(data_cs_);
139 uint32_t last_observed_bitrate_bps_ GUARDED_BY(data_cs_); 159 uint32_t last_observed_bitrate_bps_ GUARDED_BY(data_cs_);
140 bool encoder_paused_ GUARDED_BY(data_cs_); 160 bool encoder_paused_ GUARDED_BY(data_cs_);
141 bool encoder_paused_and_dropped_frame_ GUARDED_BY(data_cs_); 161 bool encoder_paused_and_dropped_frame_ GUARDED_BY(data_cs_);
162 bool reported_timeout_ GUARDED_BY(data_cs_);
142 163
143 ProcessThread* module_process_thread_; 164 ProcessThread* module_process_thread_;
144 165
145 bool has_received_sli_ GUARDED_BY(data_cs_); 166 bool has_received_sli_ GUARDED_BY(data_cs_);
146 uint8_t picture_id_sli_ GUARDED_BY(data_cs_); 167 uint8_t picture_id_sli_ GUARDED_BY(data_cs_);
147 bool has_received_rpsi_ GUARDED_BY(data_cs_); 168 bool has_received_rpsi_ GUARDED_BY(data_cs_);
148 uint64_t picture_id_rpsi_ GUARDED_BY(data_cs_); 169 uint64_t picture_id_rpsi_ GUARDED_BY(data_cs_);
149 170
150 bool video_suspended_ GUARDED_BY(data_cs_); 171 bool video_suspended_ GUARDED_BY(data_cs_);
151 }; 172 };
152 173
153 } // namespace webrtc 174 } // namespace webrtc
154 175
155 #endif // WEBRTC_VIDEO_VIE_ENCODER_H_ 176 #endif // WEBRTC_VIDEO_VIE_ENCODER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698