niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
stefan@webrtc.org | 2979461 | 2012-02-08 08:58:55 +0000 | [diff] [blame] | 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 3 | * |
| 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 |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #ifndef MODULES_VIDEO_CODING_JITTER_BUFFER_H_ |
| 12 | #define MODULES_VIDEO_CODING_JITTER_BUFFER_H_ |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 13 | |
stefan@webrtc.org | 4cf1a8a | 2013-06-27 15:20:14 +0000 | [diff] [blame] | 14 | #include <list> |
stefan@webrtc.org | 50fb4af | 2013-06-17 07:33:58 +0000 | [diff] [blame] | 15 | #include <map> |
kwiberg | 3f55dea | 2016-02-29 05:51:59 -0800 | [diff] [blame] | 16 | #include <memory> |
stefan@webrtc.org | a64300a | 2013-03-04 15:24:40 +0000 | [diff] [blame] | 17 | #include <set> |
stefan@webrtc.org | becf9c8 | 2013-02-01 15:09:57 +0000 | [diff] [blame] | 18 | #include <vector> |
stefan@webrtc.org | 2979461 | 2012-02-08 08:58:55 +0000 | [diff] [blame] | 19 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 20 | #include "modules/include/module_common_types.h" |
Danil Chapovalov | 7c06777 | 2019-10-07 12:56:24 +0200 | [diff] [blame] | 21 | #include "modules/include/module_common_types_public.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 22 | #include "modules/video_coding/decoding_state.h" |
Niels Möller | d3da6b0 | 2020-03-05 15:31:10 +0100 | [diff] [blame] | 23 | #include "modules/video_coding/event_wrapper.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 24 | #include "modules/video_coding/include/video_coding.h" |
| 25 | #include "modules/video_coding/include/video_coding_defines.h" |
| 26 | #include "modules/video_coding/inter_frame_delay.h" |
| 27 | #include "modules/video_coding/jitter_buffer_common.h" |
| 28 | #include "modules/video_coding/jitter_estimator.h" |
Markus Handell | 6deec38 | 2020-07-07 12:17:12 +0200 | [diff] [blame] | 29 | #include "rtc_base/synchronization/mutex.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 30 | #include "rtc_base/thread_annotations.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 31 | |
stefan@webrtc.org | 912981f | 2012-10-12 07:04:52 +0000 | [diff] [blame] | 32 | namespace webrtc { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 33 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 34 | // forward declarations |
stefan@webrtc.org | a678a3b | 2013-01-21 07:42:11 +0000 | [diff] [blame] | 35 | class Clock; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 36 | class VCMFrameBuffer; |
| 37 | class VCMPacket; |
| 38 | class VCMEncodedFrame; |
| 39 | |
stefan@webrtc.org | 4cf1a8a | 2013-06-27 15:20:14 +0000 | [diff] [blame] | 40 | typedef std::list<VCMFrameBuffer*> UnorderedFrameList; |
| 41 | |
stefan@webrtc.org | 912981f | 2012-10-12 07:04:52 +0000 | [diff] [blame] | 42 | struct VCMJitterSample { |
| 43 | VCMJitterSample() : timestamp(0), frame_size(0), latest_packet_time(-1) {} |
| 44 | uint32_t timestamp; |
| 45 | uint32_t frame_size; |
| 46 | int64_t latest_packet_time; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 47 | }; |
| 48 | |
stefan@webrtc.org | 50fb4af | 2013-06-17 07:33:58 +0000 | [diff] [blame] | 49 | class TimestampLessThan { |
| 50 | public: |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 51 | bool operator()(uint32_t timestamp1, uint32_t timestamp2) const { |
stefan@webrtc.org | 50fb4af | 2013-06-17 07:33:58 +0000 | [diff] [blame] | 52 | return IsNewerTimestamp(timestamp2, timestamp1); |
| 53 | } |
| 54 | }; |
| 55 | |
agalusza@google.com | d818dcb | 2013-07-29 21:48:11 +0000 | [diff] [blame] | 56 | class FrameList |
| 57 | : public std::map<uint32_t, VCMFrameBuffer*, TimestampLessThan> { |
stefan@webrtc.org | c8b29a2 | 2013-06-17 07:13:16 +0000 | [diff] [blame] | 58 | public: |
| 59 | void InsertFrame(VCMFrameBuffer* frame); |
stefan@webrtc.org | c8b29a2 | 2013-06-17 07:13:16 +0000 | [diff] [blame] | 60 | VCMFrameBuffer* PopFrame(uint32_t timestamp); |
stefan@webrtc.org | 50fb4af | 2013-06-17 07:33:58 +0000 | [diff] [blame] | 61 | VCMFrameBuffer* Front() const; |
| 62 | VCMFrameBuffer* Back() const; |
stefan@webrtc.org | 4cf1a8a | 2013-06-27 15:20:14 +0000 | [diff] [blame] | 63 | int RecycleFramesUntilKeyFrame(FrameList::iterator* key_frame_it, |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 64 | UnorderedFrameList* free_frames); |
pbos@webrtc.org | 4f16c87 | 2014-11-24 09:06:48 +0000 | [diff] [blame] | 65 | void CleanUpOldOrEmptyFrames(VCMDecodingState* decoding_state, |
| 66 | UnorderedFrameList* free_frames); |
stefan@webrtc.org | 4cf1a8a | 2013-06-27 15:20:14 +0000 | [diff] [blame] | 67 | void Reset(UnorderedFrameList* free_frames); |
stefan@webrtc.org | c8b29a2 | 2013-06-17 07:13:16 +0000 | [diff] [blame] | 68 | }; |
| 69 | |
stefan@webrtc.org | 912981f | 2012-10-12 07:04:52 +0000 | [diff] [blame] | 70 | class VCMJitterBuffer { |
| 71 | public: |
Niels Möller | db64d99 | 2019-03-29 14:30:53 +0100 | [diff] [blame] | 72 | VCMJitterBuffer(Clock* clock, std::unique_ptr<EventWrapper> event); |
Qiang Chen | d4cec15 | 2015-06-19 09:17:00 -0700 | [diff] [blame] | 73 | |
Wan-Teh Chang | 6a1ba8c | 2015-05-26 14:11:41 -0700 | [diff] [blame] | 74 | ~VCMJitterBuffer(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 75 | |
Byoungchan Lee | 604fd2f | 2022-01-21 09:49:39 +0900 | [diff] [blame] | 76 | VCMJitterBuffer(const VCMJitterBuffer&) = delete; |
| 77 | VCMJitterBuffer& operator=(const VCMJitterBuffer&) = delete; |
| 78 | |
stefan@webrtc.org | 912981f | 2012-10-12 07:04:52 +0000 | [diff] [blame] | 79 | // Initializes and starts jitter buffer. |
| 80 | void Start(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 81 | |
stefan@webrtc.org | 912981f | 2012-10-12 07:04:52 +0000 | [diff] [blame] | 82 | // Signals all internal events and stops the jitter buffer. |
| 83 | void Stop(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 84 | |
stefan@webrtc.org | 912981f | 2012-10-12 07:04:52 +0000 | [diff] [blame] | 85 | // Returns true if the jitter buffer is running. |
| 86 | bool Running() const; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 87 | |
stefan@webrtc.org | 912981f | 2012-10-12 07:04:52 +0000 | [diff] [blame] | 88 | // Empty the jitter buffer of all its data. |
| 89 | void Flush(); |
stefan@webrtc.org | 791eec7 | 2011-10-11 07:53:43 +0000 | [diff] [blame] | 90 | |
asapersson@webrtc.org | 96dc685 | 2014-11-03 14:40:38 +0000 | [diff] [blame] | 91 | // Gets number of packets received. |
| 92 | int num_packets() const; |
| 93 | |
| 94 | // Gets number of duplicated packets received. |
| 95 | int num_duplicated_packets() const; |
| 96 | |
Artem Titov | dcd7fc7 | 2021-08-09 13:02:57 +0200 | [diff] [blame] | 97 | // Wait `max_wait_time_ms` for a complete frame to arrive. |
isheriff | 6b4b5f3 | 2016-06-08 00:24:21 -0700 | [diff] [blame] | 98 | // If found, a pointer to the frame is returned. Returns nullptr otherwise. |
| 99 | VCMEncodedFrame* NextCompleteFrame(uint32_t max_wait_time_ms); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 100 | |
mikhal@webrtc.org | 759b041 | 2013-05-07 16:36:00 +0000 | [diff] [blame] | 101 | // Extract frame corresponding to input timestamp. |
| 102 | // Frame will be set to a decoding state. |
| 103 | VCMEncodedFrame* ExtractAndSetDecode(uint32_t timestamp); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 104 | |
stefan@webrtc.org | 912981f | 2012-10-12 07:04:52 +0000 | [diff] [blame] | 105 | // Releases a frame returned from the jitter buffer, should be called when |
| 106 | // done with decoding. |
| 107 | void ReleaseFrame(VCMEncodedFrame* frame); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 108 | |
stefan@webrtc.org | 912981f | 2012-10-12 07:04:52 +0000 | [diff] [blame] | 109 | // Returns the time in ms when the latest packet was inserted into the frame. |
| 110 | // Retransmitted is set to true if any of the packets belonging to the frame |
| 111 | // has been retransmitted. |
stefan@webrtc.org | 3417eb4 | 2013-05-21 15:25:53 +0000 | [diff] [blame] | 112 | int64_t LastPacketTime(const VCMEncodedFrame* frame, |
| 113 | bool* retransmitted) const; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 114 | |
stefan@webrtc.org | 912981f | 2012-10-12 07:04:52 +0000 | [diff] [blame] | 115 | // Inserts a packet into a frame returned from GetFrame(). |
Artem Titov | dcd7fc7 | 2021-08-09 13:02:57 +0200 | [diff] [blame] | 116 | // If the return value is <= 0, `frame` is invalidated and the pointer must |
stefan@webrtc.org | c8b29a2 | 2013-06-17 07:13:16 +0000 | [diff] [blame] | 117 | // be dropped after this function returns. |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 118 | VCMFrameBufferEnum InsertPacket(const VCMPacket& packet, bool* retransmitted); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 119 | |
stefan@webrtc.org | 912981f | 2012-10-12 07:04:52 +0000 | [diff] [blame] | 120 | // Returns the estimated jitter in milliseconds. |
| 121 | uint32_t EstimatedJitterMs(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 122 | |
stefan@webrtc.org | becf9c8 | 2013-02-01 15:09:57 +0000 | [diff] [blame] | 123 | void SetNackSettings(size_t max_nack_list_size, |
stefan@webrtc.org | ef14488 | 2013-05-07 19:16:33 +0000 | [diff] [blame] | 124 | int max_packet_age_to_nack, |
| 125 | int max_incomplete_time_ms); |
stefan@webrtc.org | becf9c8 | 2013-02-01 15:09:57 +0000 | [diff] [blame] | 126 | |
stefan@webrtc.org | a64300a | 2013-03-04 15:24:40 +0000 | [diff] [blame] | 127 | // Returns a list of the sequence numbers currently missing. |
Wan-Teh Chang | b1825a4 | 2015-06-03 15:03:35 -0700 | [diff] [blame] | 128 | std::vector<uint16_t> GetNackList(bool* request_key_frame); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 129 | |
stefan@webrtc.org | 912981f | 2012-10-12 07:04:52 +0000 | [diff] [blame] | 130 | private: |
stefan@webrtc.org | a64300a | 2013-03-04 15:24:40 +0000 | [diff] [blame] | 131 | class SequenceNumberLessThan { |
| 132 | public: |
philipel | 9d3ab61 | 2015-12-21 04:12:39 -0800 | [diff] [blame] | 133 | bool operator()(const uint16_t& sequence_number1, |
| 134 | const uint16_t& sequence_number2) const { |
stefan@webrtc.org | 7bc465b | 2013-04-11 17:48:02 +0000 | [diff] [blame] | 135 | return IsNewerSequenceNumber(sequence_number2, sequence_number1); |
stefan@webrtc.org | a64300a | 2013-03-04 15:24:40 +0000 | [diff] [blame] | 136 | } |
| 137 | }; |
| 138 | typedef std::set<uint16_t, SequenceNumberLessThan> SequenceNumberSet; |
| 139 | |
stefan@webrtc.org | 3417eb4 | 2013-05-21 15:25:53 +0000 | [diff] [blame] | 140 | // Gets the frame assigned to the timestamp of the packet. May recycle |
| 141 | // existing frames if no free frames are available. Returns an error code if |
Artem Titov | dcd7fc7 | 2021-08-09 13:02:57 +0200 | [diff] [blame] | 142 | // failing, or kNoError on success. `frame_list` contains which list the |
pbos@webrtc.org | 4f16c87 | 2014-11-24 09:06:48 +0000 | [diff] [blame] | 143 | // packet was in, or NULL if it was not in a FrameList (a new frame). |
| 144 | VCMFrameBufferEnum GetFrame(const VCMPacket& packet, |
| 145 | VCMFrameBuffer** frame, |
| 146 | FrameList** frame_list) |
Markus Handell | 6deec38 | 2020-07-07 12:17:12 +0200 | [diff] [blame] | 147 | RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_); |
asapersson@webrtc.org | 83b5200 | 2014-11-28 10:17:13 +0000 | [diff] [blame] | 148 | |
Artem Titov | dcd7fc7 | 2021-08-09 13:02:57 +0200 | [diff] [blame] | 149 | // Returns true if `frame` is continuous in `decoding_state`, not taking |
stefan@webrtc.org | c8b29a2 | 2013-06-17 07:13:16 +0000 | [diff] [blame] | 150 | // decodable frames into account. |
| 151 | bool IsContinuousInState(const VCMFrameBuffer& frame, |
pbos@webrtc.org | 4f16c87 | 2014-11-24 09:06:48 +0000 | [diff] [blame] | 152 | const VCMDecodingState& decoding_state) const |
Markus Handell | 6deec38 | 2020-07-07 12:17:12 +0200 | [diff] [blame] | 153 | RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_); |
Artem Titov | dcd7fc7 | 2021-08-09 13:02:57 +0200 | [diff] [blame] | 154 | // Returns true if `frame` is continuous in the `last_decoded_state_`, taking |
stefan@webrtc.org | c8b29a2 | 2013-06-17 07:13:16 +0000 | [diff] [blame] | 155 | // all decodable frames into account. |
pbos@webrtc.org | 4f16c87 | 2014-11-24 09:06:48 +0000 | [diff] [blame] | 156 | bool IsContinuous(const VCMFrameBuffer& frame) const |
Markus Handell | 6deec38 | 2020-07-07 12:17:12 +0200 | [diff] [blame] | 157 | RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_); |
Artem Titov | dcd7fc7 | 2021-08-09 13:02:57 +0200 | [diff] [blame] | 158 | // Looks for frames in `incomplete_frames_` which are continuous in the |
| 159 | // provided `decoded_state`. Starts the search from the timestamp of |
| 160 | // `decoded_state`. |
Noah Richards | e4cb4e9 | 2015-05-22 14:03:00 -0700 | [diff] [blame] | 161 | void FindAndInsertContinuousFramesWithState( |
| 162 | const VCMDecodingState& decoded_state) |
Markus Handell | 6deec38 | 2020-07-07 12:17:12 +0200 | [diff] [blame] | 163 | RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_); |
Artem Titov | dcd7fc7 | 2021-08-09 13:02:57 +0200 | [diff] [blame] | 164 | // Looks for frames in `incomplete_frames_` which are continuous in |
| 165 | // `last_decoded_state_` taking all decodable frames into account. Starts |
| 166 | // the search from `new_frame`. |
pbos@webrtc.org | 4f16c87 | 2014-11-24 09:06:48 +0000 | [diff] [blame] | 167 | void FindAndInsertContinuousFrames(const VCMFrameBuffer& new_frame) |
Markus Handell | 6deec38 | 2020-07-07 12:17:12 +0200 | [diff] [blame] | 168 | RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_); |
| 169 | VCMFrameBuffer* NextFrame() const RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_); |
stefan@webrtc.org | a64300a | 2013-03-04 15:24:40 +0000 | [diff] [blame] | 170 | // Returns true if the NACK list was updated to cover sequence numbers up to |
Artem Titov | dcd7fc7 | 2021-08-09 13:02:57 +0200 | [diff] [blame] | 171 | // `sequence_number`. If false a key frame is needed to get into a state where |
stefan@webrtc.org | a64300a | 2013-03-04 15:24:40 +0000 | [diff] [blame] | 172 | // we can continue decoding. |
pbos@webrtc.org | 4f16c87 | 2014-11-24 09:06:48 +0000 | [diff] [blame] | 173 | bool UpdateNackList(uint16_t sequence_number) |
Markus Handell | 6deec38 | 2020-07-07 12:17:12 +0200 | [diff] [blame] | 174 | RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_); |
stefan@webrtc.org | a64300a | 2013-03-04 15:24:40 +0000 | [diff] [blame] | 175 | bool TooLargeNackList() const; |
| 176 | // Returns true if the NACK list was reduced without problem. If false a key |
| 177 | // frame is needed to get into a state where we can continue decoding. |
Markus Handell | 6deec38 | 2020-07-07 12:17:12 +0200 | [diff] [blame] | 178 | bool HandleTooLargeNackList() RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_); |
pbos@webrtc.org | 4f16c87 | 2014-11-24 09:06:48 +0000 | [diff] [blame] | 179 | bool MissingTooOldPacket(uint16_t latest_sequence_number) const |
Markus Handell | 6deec38 | 2020-07-07 12:17:12 +0200 | [diff] [blame] | 180 | RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_); |
stefan@webrtc.org | a64300a | 2013-03-04 15:24:40 +0000 | [diff] [blame] | 181 | // Returns true if the too old packets was successfully removed from the NACK |
| 182 | // list. If false, a key frame is needed to get into a state where we can |
| 183 | // continue decoding. |
pbos@webrtc.org | 4f16c87 | 2014-11-24 09:06:48 +0000 | [diff] [blame] | 184 | bool HandleTooOldPackets(uint16_t latest_sequence_number) |
Markus Handell | 6deec38 | 2020-07-07 12:17:12 +0200 | [diff] [blame] | 185 | RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_); |
Artem Titov | dcd7fc7 | 2021-08-09 13:02:57 +0200 | [diff] [blame] | 186 | // Drops all packets in the NACK list up until `last_decoded_sequence_number`. |
stefan@webrtc.org | a64300a | 2013-03-04 15:24:40 +0000 | [diff] [blame] | 187 | void DropPacketsFromNackList(uint16_t last_decoded_sequence_number); |
| 188 | |
stefan@webrtc.org | 912981f | 2012-10-12 07:04:52 +0000 | [diff] [blame] | 189 | // Gets an empty frame, creating a new frame if necessary (i.e. increases |
| 190 | // jitter buffer size). |
Markus Handell | 6deec38 | 2020-07-07 12:17:12 +0200 | [diff] [blame] | 191 | VCMFrameBuffer* GetEmptyFrame() RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 192 | |
stefan@webrtc.org | 4cf1a8a | 2013-06-27 15:20:14 +0000 | [diff] [blame] | 193 | // Attempts to increase the size of the jitter buffer. Returns true on |
| 194 | // success, false otherwise. |
Markus Handell | 6deec38 | 2020-07-07 12:17:12 +0200 | [diff] [blame] | 195 | bool TryToIncreaseJitterBufferSize() RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_); |
stefan@webrtc.org | 4cf1a8a | 2013-06-27 15:20:14 +0000 | [diff] [blame] | 196 | |
stefan@webrtc.org | 912981f | 2012-10-12 07:04:52 +0000 | [diff] [blame] | 197 | // Recycles oldest frames until a key frame is found. Used if jitter buffer is |
| 198 | // completely full. Returns true if a key frame was found. |
Markus Handell | 6deec38 | 2020-07-07 12:17:12 +0200 | [diff] [blame] | 199 | bool RecycleFramesUntilKeyFrame() RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 200 | |
agalusza@google.com | d818dcb | 2013-07-29 21:48:11 +0000 | [diff] [blame] | 201 | // Update rolling average of packets per frame. |
| 202 | void UpdateAveragePacketsPerFrame(int current_number_packets_); |
| 203 | |
mikhal@webrtc.org | 381da4b | 2013-04-25 21:45:29 +0000 | [diff] [blame] | 204 | // Cleans the frame list in the JB from old/empty frames. |
| 205 | // Should only be called prior to actual use. |
Markus Handell | 6deec38 | 2020-07-07 12:17:12 +0200 | [diff] [blame] | 206 | void CleanUpOldOrEmptyFrames() RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 207 | |
Artem Titov | dcd7fc7 | 2021-08-09 13:02:57 +0200 | [diff] [blame] | 208 | // Returns true if `packet` is likely to have been retransmitted. |
stefan@webrtc.org | 912981f | 2012-10-12 07:04:52 +0000 | [diff] [blame] | 209 | bool IsPacketRetransmitted(const VCMPacket& packet) const; |
henrik.lundin@webrtc.org | baf6db5 | 2011-11-02 18:58:39 +0000 | [diff] [blame] | 210 | |
stefan@webrtc.org | 912981f | 2012-10-12 07:04:52 +0000 | [diff] [blame] | 211 | // The following three functions update the jitter estimate with the |
| 212 | // payload size, receive time and RTP timestamp of a frame. |
| 213 | void UpdateJitterEstimate(const VCMJitterSample& sample, |
| 214 | bool incomplete_frame); |
| 215 | void UpdateJitterEstimate(const VCMFrameBuffer& frame, bool incomplete_frame); |
| 216 | void UpdateJitterEstimate(int64_t latest_packet_time_ms, |
| 217 | uint32_t timestamp, |
| 218 | unsigned int frame_size, |
| 219 | bool incomplete_frame); |
| 220 | |
Markus Handell | 6deec38 | 2020-07-07 12:17:12 +0200 | [diff] [blame] | 221 | int NonContinuousOrIncompleteDuration() RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_); |
stefan@webrtc.org | ef14488 | 2013-05-07 19:16:33 +0000 | [diff] [blame] | 222 | |
| 223 | uint16_t EstimatedLowSequenceNumber(const VCMFrameBuffer& frame) const; |
| 224 | |
sprang | 22691e0 | 2016-07-13 10:57:07 -0700 | [diff] [blame] | 225 | // Reset frame buffer and return it to free_frames_. |
| 226 | void RecycleFrameBuffer(VCMFrameBuffer* frame) |
Markus Handell | 6deec38 | 2020-07-07 12:17:12 +0200 | [diff] [blame] | 227 | RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_); |
sprang | 22691e0 | 2016-07-13 10:57:07 -0700 | [diff] [blame] | 228 | |
stefan@webrtc.org | a678a3b | 2013-01-21 07:42:11 +0000 | [diff] [blame] | 229 | Clock* clock_; |
stefan@webrtc.org | 912981f | 2012-10-12 07:04:52 +0000 | [diff] [blame] | 230 | // If we are running (have started) or not. |
| 231 | bool running_; |
Markus Handell | 6deec38 | 2020-07-07 12:17:12 +0200 | [diff] [blame] | 232 | mutable Mutex mutex_; |
stefan@webrtc.org | 912981f | 2012-10-12 07:04:52 +0000 | [diff] [blame] | 233 | // Event to signal when we have a frame ready for decoder. |
kwiberg | 3f55dea | 2016-02-29 05:51:59 -0800 | [diff] [blame] | 234 | std::unique_ptr<EventWrapper> frame_event_; |
stefan@webrtc.org | 912981f | 2012-10-12 07:04:52 +0000 | [diff] [blame] | 235 | // Number of allocated frames. |
| 236 | int max_number_of_frames_; |
Markus Handell | 6deec38 | 2020-07-07 12:17:12 +0200 | [diff] [blame] | 237 | UnorderedFrameList free_frames_ RTC_GUARDED_BY(mutex_); |
| 238 | FrameList decodable_frames_ RTC_GUARDED_BY(mutex_); |
| 239 | FrameList incomplete_frames_ RTC_GUARDED_BY(mutex_); |
| 240 | VCMDecodingState last_decoded_state_ RTC_GUARDED_BY(mutex_); |
stefan@webrtc.org | 3417eb4 | 2013-05-21 15:25:53 +0000 | [diff] [blame] | 241 | bool first_packet_since_reset_; |
stefan@webrtc.org | 912981f | 2012-10-12 07:04:52 +0000 | [diff] [blame] | 242 | |
stefan@webrtc.org | 912981f | 2012-10-12 07:04:52 +0000 | [diff] [blame] | 243 | // Number of packets in a row that have been too old. |
| 244 | int num_consecutive_old_packets_; |
asapersson@webrtc.org | 96dc685 | 2014-11-03 14:40:38 +0000 | [diff] [blame] | 245 | // Number of packets received. |
Markus Handell | 6deec38 | 2020-07-07 12:17:12 +0200 | [diff] [blame] | 246 | int num_packets_ RTC_GUARDED_BY(mutex_); |
asapersson@webrtc.org | 96dc685 | 2014-11-03 14:40:38 +0000 | [diff] [blame] | 247 | // Number of duplicated packets received. |
Markus Handell | 6deec38 | 2020-07-07 12:17:12 +0200 | [diff] [blame] | 248 | int num_duplicated_packets_ RTC_GUARDED_BY(mutex_); |
stefan@webrtc.org | 912981f | 2012-10-12 07:04:52 +0000 | [diff] [blame] | 249 | |
| 250 | // Jitter estimation. |
| 251 | // Filter for estimating jitter. |
| 252 | VCMJitterEstimator jitter_estimate_; |
| 253 | // Calculates network delays used for jitter calculations. |
| 254 | VCMInterFrameDelay inter_frame_delay_; |
| 255 | VCMJitterSample waiting_for_completion_; |
stefan@webrtc.org | 912981f | 2012-10-12 07:04:52 +0000 | [diff] [blame] | 256 | |
stefan@webrtc.org | 912981f | 2012-10-12 07:04:52 +0000 | [diff] [blame] | 257 | // Holds the internal NACK list (the missing sequence numbers). |
stefan@webrtc.org | a64300a | 2013-03-04 15:24:40 +0000 | [diff] [blame] | 258 | SequenceNumberSet missing_sequence_numbers_; |
| 259 | uint16_t latest_received_sequence_number_; |
stefan@webrtc.org | becf9c8 | 2013-02-01 15:09:57 +0000 | [diff] [blame] | 260 | size_t max_nack_list_size_; |
| 261 | int max_packet_age_to_nack_; // Measured in sequence numbers. |
stefan@webrtc.org | ef14488 | 2013-05-07 19:16:33 +0000 | [diff] [blame] | 262 | int max_incomplete_time_ms_; |
stefan@webrtc.org | 912981f | 2012-10-12 07:04:52 +0000 | [diff] [blame] | 263 | |
agalusza@google.com | d818dcb | 2013-07-29 21:48:11 +0000 | [diff] [blame] | 264 | // Estimated rolling average of packets per frame |
| 265 | float average_packets_per_frame_; |
| 266 | // average_packets_per_frame converges fast if we have fewer than this many |
| 267 | // frames. |
| 268 | int frame_counter_; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 269 | }; |
stefan@webrtc.org | 912981f | 2012-10-12 07:04:52 +0000 | [diff] [blame] | 270 | } // namespace webrtc |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 271 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 272 | #endif // MODULES_VIDEO_CODING_JITTER_BUFFER_H_ |