| 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 12 matching lines...) Expand all Loading... |
| 23 #include "webrtc/modules/video_coding/include/video_coding_defines.h" | 23 #include "webrtc/modules/video_coding/include/video_coding_defines.h" |
| 24 #include "webrtc/modules/video_coding/decoding_state.h" | 24 #include "webrtc/modules/video_coding/decoding_state.h" |
| 25 #include "webrtc/modules/video_coding/inter_frame_delay.h" | 25 #include "webrtc/modules/video_coding/inter_frame_delay.h" |
| 26 #include "webrtc/modules/video_coding/jitter_buffer_common.h" | 26 #include "webrtc/modules/video_coding/jitter_buffer_common.h" |
| 27 #include "webrtc/modules/video_coding/jitter_estimator.h" | 27 #include "webrtc/modules/video_coding/jitter_estimator.h" |
| 28 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" | 28 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" |
| 29 #include "webrtc/typedefs.h" | 29 #include "webrtc/typedefs.h" |
| 30 | 30 |
| 31 namespace webrtc { | 31 namespace webrtc { |
| 32 | 32 |
| 33 enum VCMNackMode { | 33 enum VCMNackMode { kNack, kNoNack }; |
| 34 kNack, | |
| 35 kNoNack | |
| 36 }; | |
| 37 | 34 |
| 38 // forward declarations | 35 // forward declarations |
| 39 class Clock; | 36 class Clock; |
| 40 class EventFactory; | 37 class EventFactory; |
| 41 class EventWrapper; | 38 class EventWrapper; |
| 42 class VCMFrameBuffer; | 39 class VCMFrameBuffer; |
| 43 class VCMPacket; | 40 class VCMPacket; |
| 44 class VCMEncodedFrame; | 41 class VCMEncodedFrame; |
| 45 | 42 |
| 46 typedef std::list<VCMFrameBuffer*> UnorderedFrameList; | 43 typedef std::list<VCMFrameBuffer*> UnorderedFrameList; |
| 47 | 44 |
| 48 struct VCMJitterSample { | 45 struct VCMJitterSample { |
| 49 VCMJitterSample() : timestamp(0), frame_size(0), latest_packet_time(-1) {} | 46 VCMJitterSample() : timestamp(0), frame_size(0), latest_packet_time(-1) {} |
| 50 uint32_t timestamp; | 47 uint32_t timestamp; |
| 51 uint32_t frame_size; | 48 uint32_t frame_size; |
| 52 int64_t latest_packet_time; | 49 int64_t latest_packet_time; |
| 53 }; | 50 }; |
| 54 | 51 |
| 55 class TimestampLessThan { | 52 class TimestampLessThan { |
| 56 public: | 53 public: |
| 57 bool operator() (uint32_t timestamp1, | 54 bool operator()(uint32_t timestamp1, uint32_t timestamp2) const { |
| 58 uint32_t timestamp2) const { | |
| 59 return IsNewerTimestamp(timestamp2, timestamp1); | 55 return IsNewerTimestamp(timestamp2, timestamp1); |
| 60 } | 56 } |
| 61 }; | 57 }; |
| 62 | 58 |
| 63 class FrameList | 59 class FrameList |
| 64 : public std::map<uint32_t, VCMFrameBuffer*, TimestampLessThan> { | 60 : public std::map<uint32_t, VCMFrameBuffer*, TimestampLessThan> { |
| 65 public: | 61 public: |
| 66 void InsertFrame(VCMFrameBuffer* frame); | 62 void InsertFrame(VCMFrameBuffer* frame); |
| 67 VCMFrameBuffer* PopFrame(uint32_t timestamp); | 63 VCMFrameBuffer* PopFrame(uint32_t timestamp); |
| 68 VCMFrameBuffer* Front() const; | 64 VCMFrameBuffer* Front() const; |
| 69 VCMFrameBuffer* Back() const; | 65 VCMFrameBuffer* Back() const; |
| 70 int RecycleFramesUntilKeyFrame(FrameList::iterator* key_frame_it, | 66 int RecycleFramesUntilKeyFrame(FrameList::iterator* key_frame_it, |
| 71 UnorderedFrameList* free_frames); | 67 UnorderedFrameList* free_frames); |
| 72 void CleanUpOldOrEmptyFrames(VCMDecodingState* decoding_state, | 68 void CleanUpOldOrEmptyFrames(VCMDecodingState* decoding_state, |
| 73 UnorderedFrameList* free_frames); | 69 UnorderedFrameList* free_frames); |
| 74 void Reset(UnorderedFrameList* free_frames); | 70 void Reset(UnorderedFrameList* free_frames); |
| 75 }; | 71 }; |
| 76 | 72 |
| 77 class Vp9SsMap { | 73 class Vp9SsMap { |
| 78 public: | 74 public: |
| 79 typedef std::map<uint32_t, GofInfoVP9, TimestampLessThan> SsMap; | 75 typedef std::map<uint32_t, GofInfoVP9, TimestampLessThan> SsMap; |
| 80 bool Insert(const VCMPacket& packet); | 76 bool Insert(const VCMPacket& packet); |
| 81 void Reset(); | 77 void Reset(); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 // Gets number of packets received. | 130 // Gets number of packets received. |
| 135 int num_packets() const; | 131 int num_packets() const; |
| 136 | 132 |
| 137 // Gets number of duplicated packets received. | 133 // Gets number of duplicated packets received. |
| 138 int num_duplicated_packets() const; | 134 int num_duplicated_packets() const; |
| 139 | 135 |
| 140 // Gets number of packets discarded by the jitter buffer. | 136 // Gets number of packets discarded by the jitter buffer. |
| 141 int num_discarded_packets() const; | 137 int num_discarded_packets() const; |
| 142 | 138 |
| 143 // Statistics, Calculate frame and bit rates. | 139 // Statistics, Calculate frame and bit rates. |
| 144 void IncomingRateStatistics(unsigned int* framerate, | 140 void IncomingRateStatistics(unsigned int* framerate, unsigned int* bitrate); |
| 145 unsigned int* bitrate); | |
| 146 | 141 |
| 147 // Checks if the packet sequence will be complete if the next frame would be | 142 // Checks if the packet sequence will be complete if the next frame would be |
| 148 // grabbed for decoding. That is, if a frame has been lost between the | 143 // grabbed for decoding. That is, if a frame has been lost between the |
| 149 // last decoded frame and the next, or if the next frame is missing one | 144 // last decoded frame and the next, or if the next frame is missing one |
| 150 // or more packets. | 145 // or more packets. |
| 151 bool CompleteSequenceWithNextFrame(); | 146 bool CompleteSequenceWithNextFrame(); |
| 152 | 147 |
| 153 // Wait |max_wait_time_ms| for a complete frame to arrive. | 148 // Wait |max_wait_time_ms| for a complete frame to arrive. |
| 154 // The function returns true once such a frame is found, its corresponding | 149 // The function returns true once such a frame is found, its corresponding |
| 155 // timestamp is returned. Otherwise, returns false. | 150 // timestamp is returned. Otherwise, returns false. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 170 | 165 |
| 171 // Returns the time in ms when the latest packet was inserted into the frame. | 166 // Returns the time in ms when the latest packet was inserted into the frame. |
| 172 // Retransmitted is set to true if any of the packets belonging to the frame | 167 // Retransmitted is set to true if any of the packets belonging to the frame |
| 173 // has been retransmitted. | 168 // has been retransmitted. |
| 174 int64_t LastPacketTime(const VCMEncodedFrame* frame, | 169 int64_t LastPacketTime(const VCMEncodedFrame* frame, |
| 175 bool* retransmitted) const; | 170 bool* retransmitted) const; |
| 176 | 171 |
| 177 // Inserts a packet into a frame returned from GetFrame(). | 172 // Inserts a packet into a frame returned from GetFrame(). |
| 178 // If the return value is <= 0, |frame| is invalidated and the pointer must | 173 // If the return value is <= 0, |frame| is invalidated and the pointer must |
| 179 // be dropped after this function returns. | 174 // be dropped after this function returns. |
| 180 VCMFrameBufferEnum InsertPacket(const VCMPacket& packet, | 175 VCMFrameBufferEnum InsertPacket(const VCMPacket& packet, bool* retransmitted); |
| 181 bool* retransmitted); | |
| 182 | 176 |
| 183 // Returns the estimated jitter in milliseconds. | 177 // Returns the estimated jitter in milliseconds. |
| 184 uint32_t EstimatedJitterMs(); | 178 uint32_t EstimatedJitterMs(); |
| 185 | 179 |
| 186 // Updates the round-trip time estimate. | 180 // Updates the round-trip time estimate. |
| 187 void UpdateRtt(int64_t rtt_ms); | 181 void UpdateRtt(int64_t rtt_ms); |
| 188 | 182 |
| 189 // Set the NACK mode. |high_rtt_nack_threshold_ms| is an RTT threshold in ms | 183 // Set the NACK mode. |high_rtt_nack_threshold_ms| is an RTT threshold in ms |
| 190 // above which NACK will be disabled if the NACK mode is |kNack|, -1 meaning | 184 // above which NACK will be disabled if the NACK mode is |kNack|, -1 meaning |
| 191 // that NACK is always enabled in the |kNack| mode. | 185 // that NACK is always enabled in the |kNack| mode. |
| 192 // |low_rtt_nack_threshold_ms| is an RTT threshold in ms below which we expect | 186 // |low_rtt_nack_threshold_ms| is an RTT threshold in ms below which we expect |
| 193 // to rely on NACK only, and therefore are using larger buffers to have time | 187 // to rely on NACK only, and therefore are using larger buffers to have time |
| 194 // to wait for retransmissions. | 188 // to wait for retransmissions. |
| 195 void SetNackMode(VCMNackMode mode, int64_t low_rtt_nack_threshold_ms, | 189 void SetNackMode(VCMNackMode mode, |
| 190 int64_t low_rtt_nack_threshold_ms, |
| 196 int64_t high_rtt_nack_threshold_ms); | 191 int64_t high_rtt_nack_threshold_ms); |
| 197 | 192 |
| 198 void SetNackSettings(size_t max_nack_list_size, | 193 void SetNackSettings(size_t max_nack_list_size, |
| 199 int max_packet_age_to_nack, | 194 int max_packet_age_to_nack, |
| 200 int max_incomplete_time_ms); | 195 int max_incomplete_time_ms); |
| 201 | 196 |
| 202 // Returns the current NACK mode. | 197 // Returns the current NACK mode. |
| 203 VCMNackMode nack_mode() const; | 198 VCMNackMode nack_mode() const; |
| 204 | 199 |
| 205 // Returns a list of the sequence numbers currently missing. | 200 // Returns a list of the sequence numbers currently missing. |
| 206 std::vector<uint16_t> GetNackList(bool* request_key_frame); | 201 std::vector<uint16_t> GetNackList(bool* request_key_frame); |
| 207 | 202 |
| 208 // Set decode error mode - Should not be changed in the middle of the | 203 // Set decode error mode - Should not be changed in the middle of the |
| 209 // session. Changes will not influence frames already in the buffer. | 204 // session. Changes will not influence frames already in the buffer. |
| 210 void SetDecodeErrorMode(VCMDecodeErrorMode error_mode); | 205 void SetDecodeErrorMode(VCMDecodeErrorMode error_mode); |
| 211 int64_t LastDecodedTimestamp() const; | 206 int64_t LastDecodedTimestamp() const; |
| 212 VCMDecodeErrorMode decode_error_mode() const {return decode_error_mode_;} | 207 VCMDecodeErrorMode decode_error_mode() const { return decode_error_mode_; } |
| 213 | 208 |
| 214 // Used to compute time of complete continuous frames. Returns the timestamps | 209 // Used to compute time of complete continuous frames. Returns the timestamps |
| 215 // corresponding to the start and end of the continuous complete buffer. | 210 // corresponding to the start and end of the continuous complete buffer. |
| 216 void RenderBufferSize(uint32_t* timestamp_start, uint32_t* timestamp_end); | 211 void RenderBufferSize(uint32_t* timestamp_start, uint32_t* timestamp_end); |
| 217 | 212 |
| 218 void RegisterStatsCallback(VCMReceiveStatisticsCallback* callback); | 213 void RegisterStatsCallback(VCMReceiveStatisticsCallback* callback); |
| 219 | 214 |
| 220 private: | 215 private: |
| 221 class SequenceNumberLessThan { | 216 class SequenceNumberLessThan { |
| 222 public: | 217 public: |
| 223 bool operator() (const uint16_t& sequence_number1, | 218 bool operator()(const uint16_t& sequence_number1, |
| 224 const uint16_t& sequence_number2) const { | 219 const uint16_t& sequence_number2) const { |
| 225 return IsNewerSequenceNumber(sequence_number2, sequence_number1); | 220 return IsNewerSequenceNumber(sequence_number2, sequence_number1); |
| 226 } | 221 } |
| 227 }; | 222 }; |
| 228 typedef std::set<uint16_t, SequenceNumberLessThan> SequenceNumberSet; | 223 typedef std::set<uint16_t, SequenceNumberLessThan> SequenceNumberSet; |
| 229 | 224 |
| 230 // Gets the frame assigned to the timestamp of the packet. May recycle | 225 // Gets the frame assigned to the timestamp of the packet. May recycle |
| 231 // existing frames if no free frames are available. Returns an error code if | 226 // existing frames if no free frames are available. Returns an error code if |
| 232 // failing, or kNoError on success. |frame_list| contains which list the | 227 // failing, or kNoError on success. |frame_list| contains which list the |
| 233 // packet was in, or NULL if it was not in a FrameList (a new frame). | 228 // packet was in, or NULL if it was not in a FrameList (a new frame). |
| 234 VCMFrameBufferEnum GetFrame(const VCMPacket& packet, | 229 VCMFrameBufferEnum GetFrame(const VCMPacket& packet, |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 385 // Estimated rolling average of packets per frame | 380 // Estimated rolling average of packets per frame |
| 386 float average_packets_per_frame_; | 381 float average_packets_per_frame_; |
| 387 // average_packets_per_frame converges fast if we have fewer than this many | 382 // average_packets_per_frame converges fast if we have fewer than this many |
| 388 // frames. | 383 // frames. |
| 389 int frame_counter_; | 384 int frame_counter_; |
| 390 RTC_DISALLOW_COPY_AND_ASSIGN(VCMJitterBuffer); | 385 RTC_DISALLOW_COPY_AND_ASSIGN(VCMJitterBuffer); |
| 391 }; | 386 }; |
| 392 } // namespace webrtc | 387 } // namespace webrtc |
| 393 | 388 |
| 394 #endif // WEBRTC_MODULES_VIDEO_CODING_JITTER_BUFFER_H_ | 389 #endif // WEBRTC_MODULES_VIDEO_CODING_JITTER_BUFFER_H_ |
| OLD | NEW |