blob: e1414aa4ee35badef3d2ba6f640e057801bb346e [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
stefan@webrtc.org29794612012-02-08 08:58:55 +00002 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
niklase@google.com470e71d2011-07-07 08:21:25 +00003 *
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 Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef MODULES_VIDEO_CODING_JITTER_BUFFER_H_
12#define MODULES_VIDEO_CODING_JITTER_BUFFER_H_
niklase@google.com470e71d2011-07-07 08:21:25 +000013
stefan@webrtc.org4cf1a8a2013-06-27 15:20:14 +000014#include <list>
stefan@webrtc.org50fb4af2013-06-17 07:33:58 +000015#include <map>
kwiberg3f55dea2016-02-29 05:51:59 -080016#include <memory>
stefan@webrtc.orga64300a2013-03-04 15:24:40 +000017#include <set>
stefan@webrtc.orgbecf9c82013-02-01 15:09:57 +000018#include <vector>
stefan@webrtc.org29794612012-02-08 08:58:55 +000019
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020020#include "modules/include/module_common_types.h"
21#include "modules/utility/include/process_thread.h"
22#include "modules/video_coding/decoding_state.h"
23#include "modules/video_coding/include/video_coding.h"
24#include "modules/video_coding/include/video_coding_defines.h"
25#include "modules/video_coding/inter_frame_delay.h"
26#include "modules/video_coding/jitter_buffer_common.h"
27#include "modules/video_coding/jitter_estimator.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020028#include "rtc_base/constructormagic.h"
29#include "rtc_base/criticalsection.h"
30#include "rtc_base/thread_annotations.h"
Mirko Bonadei71207422017-09-15 13:58:09 +020031#include "typedefs.h" // NOLINT(build/include)
niklase@google.com470e71d2011-07-07 08:21:25 +000032
stefan@webrtc.org912981f2012-10-12 07:04:52 +000033namespace webrtc {
niklase@google.com470e71d2011-07-07 08:21:25 +000034
philipel9d3ab612015-12-21 04:12:39 -080035enum VCMNackMode { kNack, kNoNack };
niklase@google.com470e71d2011-07-07 08:21:25 +000036
37// forward declarations
stefan@webrtc.orga678a3b2013-01-21 07:42:11 +000038class Clock;
stefan@webrtc.org2baf5f52013-03-13 08:46:25 +000039class EventFactory;
40class EventWrapper;
niklase@google.com470e71d2011-07-07 08:21:25 +000041class VCMFrameBuffer;
42class VCMPacket;
43class VCMEncodedFrame;
44
stefan@webrtc.org4cf1a8a2013-06-27 15:20:14 +000045typedef std::list<VCMFrameBuffer*> UnorderedFrameList;
46
stefan@webrtc.org912981f2012-10-12 07:04:52 +000047struct VCMJitterSample {
48 VCMJitterSample() : timestamp(0), frame_size(0), latest_packet_time(-1) {}
49 uint32_t timestamp;
50 uint32_t frame_size;
51 int64_t latest_packet_time;
niklase@google.com470e71d2011-07-07 08:21:25 +000052};
53
stefan@webrtc.org50fb4af2013-06-17 07:33:58 +000054class TimestampLessThan {
55 public:
philipel9d3ab612015-12-21 04:12:39 -080056 bool operator()(uint32_t timestamp1, uint32_t timestamp2) const {
stefan@webrtc.org50fb4af2013-06-17 07:33:58 +000057 return IsNewerTimestamp(timestamp2, timestamp1);
58 }
59};
60
agalusza@google.comd818dcb2013-07-29 21:48:11 +000061class FrameList
62 : public std::map<uint32_t, VCMFrameBuffer*, TimestampLessThan> {
stefan@webrtc.orgc8b29a22013-06-17 07:13:16 +000063 public:
64 void InsertFrame(VCMFrameBuffer* frame);
stefan@webrtc.orgc8b29a22013-06-17 07:13:16 +000065 VCMFrameBuffer* PopFrame(uint32_t timestamp);
stefan@webrtc.org50fb4af2013-06-17 07:33:58 +000066 VCMFrameBuffer* Front() const;
67 VCMFrameBuffer* Back() const;
stefan@webrtc.org4cf1a8a2013-06-27 15:20:14 +000068 int RecycleFramesUntilKeyFrame(FrameList::iterator* key_frame_it,
philipel9d3ab612015-12-21 04:12:39 -080069 UnorderedFrameList* free_frames);
pbos@webrtc.org4f16c872014-11-24 09:06:48 +000070 void CleanUpOldOrEmptyFrames(VCMDecodingState* decoding_state,
71 UnorderedFrameList* free_frames);
stefan@webrtc.org4cf1a8a2013-06-27 15:20:14 +000072 void Reset(UnorderedFrameList* free_frames);
stefan@webrtc.orgc8b29a22013-06-17 07:13:16 +000073};
74
asapersson9a4cd872015-10-23 00:27:14 -070075class Vp9SsMap {
76 public:
77 typedef std::map<uint32_t, GofInfoVP9, TimestampLessThan> SsMap;
Stefan Holmerdbdb3a02018-07-17 16:03:46 +020078 Vp9SsMap();
79 ~Vp9SsMap();
80
asapersson9a4cd872015-10-23 00:27:14 -070081 bool Insert(const VCMPacket& packet);
82 void Reset();
83
84 // Removes SS data that are older than |timestamp|.
85 // The |timestamp| should be an old timestamp, i.e. packets with older
86 // timestamps should no longer be inserted.
87 void RemoveOld(uint32_t timestamp);
88
89 bool UpdatePacket(VCMPacket* packet);
90 void UpdateFrames(FrameList* frames);
91
92 // Public for testing.
93 // Returns an iterator to the corresponding SS data for the input |timestamp|.
94 bool Find(uint32_t timestamp, SsMap::iterator* it);
95
96 private:
97 // These two functions are called by RemoveOld.
98 // Checks if it is time to do a clean up (done each kSsCleanupIntervalSec).
99 bool TimeForCleanup(uint32_t timestamp) const;
100
101 // Advances the oldest SS data to handle timestamp wrap in cases where SS data
102 // are received very seldom (e.g. only once in beginning, second when
103 // IsNewerTimestamp is not true).
104 void AdvanceFront(uint32_t timestamp);
105
106 SsMap ss_map_;
107};
108
stefan@webrtc.org912981f2012-10-12 07:04:52 +0000109class VCMJitterBuffer {
110 public:
philipel83f831a2016-03-12 03:30:23 -0800111 VCMJitterBuffer(Clock* clock,
112 std::unique_ptr<EventWrapper> event,
113 NackSender* nack_sender = nullptr,
114 KeyFrameRequestSender* keyframe_request_sender = nullptr);
Qiang Chend4cec152015-06-19 09:17:00 -0700115
Wan-Teh Chang6a1ba8c2015-05-26 14:11:41 -0700116 ~VCMJitterBuffer();
niklase@google.com470e71d2011-07-07 08:21:25 +0000117
stefan@webrtc.org912981f2012-10-12 07:04:52 +0000118 // Initializes and starts jitter buffer.
119 void Start();
niklase@google.com470e71d2011-07-07 08:21:25 +0000120
stefan@webrtc.org912981f2012-10-12 07:04:52 +0000121 // Signals all internal events and stops the jitter buffer.
122 void Stop();
niklase@google.com470e71d2011-07-07 08:21:25 +0000123
stefan@webrtc.org912981f2012-10-12 07:04:52 +0000124 // Returns true if the jitter buffer is running.
125 bool Running() const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000126
stefan@webrtc.org912981f2012-10-12 07:04:52 +0000127 // Empty the jitter buffer of all its data.
128 void Flush();
stefan@webrtc.org791eec72011-10-11 07:53:43 +0000129
sprang@webrtc.org71f055f2013-12-04 15:09:27 +0000130 // Get the number of received frames, by type, since the jitter buffer
stefan@webrtc.org912981f2012-10-12 07:04:52 +0000131 // was started.
pbos@webrtc.orgce4e9a32014-12-18 13:50:16 +0000132 FrameCounts FrameStatistics() const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000133
asapersson@webrtc.org96dc6852014-11-03 14:40:38 +0000134 // Gets number of packets received.
135 int num_packets() const;
136
137 // Gets number of duplicated packets received.
138 int num_duplicated_packets() const;
139
stefan@webrtc.org912981f2012-10-12 07:04:52 +0000140 // Gets number of packets discarded by the jitter buffer.
141 int num_discarded_packets() const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000142
stefan@webrtc.org912981f2012-10-12 07:04:52 +0000143 // Statistics, Calculate frame and bit rates.
philipel9d3ab612015-12-21 04:12:39 -0800144 void IncomingRateStatistics(unsigned int* framerate, unsigned int* bitrate);
niklase@google.com470e71d2011-07-07 08:21:25 +0000145
mikhal@webrtc.org759b0412013-05-07 16:36:00 +0000146 // Wait |max_wait_time_ms| for a complete frame to arrive.
isheriff6b4b5f32016-06-08 00:24:21 -0700147 // If found, a pointer to the frame is returned. Returns nullptr otherwise.
148 VCMEncodedFrame* NextCompleteFrame(uint32_t max_wait_time_ms);
niklase@google.com470e71d2011-07-07 08:21:25 +0000149
mikhal@webrtc.org759b0412013-05-07 16:36:00 +0000150 // Locates a frame for decoding (even an incomplete) without delay.
151 // The function returns true once such a frame is found, its corresponding
152 // timestamp is returned. Otherwise, returns false.
153 bool NextMaybeIncompleteTimestamp(uint32_t* timestamp);
154
155 // Extract frame corresponding to input timestamp.
156 // Frame will be set to a decoding state.
157 VCMEncodedFrame* ExtractAndSetDecode(uint32_t timestamp);
niklase@google.com470e71d2011-07-07 08:21:25 +0000158
stefan@webrtc.org912981f2012-10-12 07:04:52 +0000159 // Releases a frame returned from the jitter buffer, should be called when
160 // done with decoding.
161 void ReleaseFrame(VCMEncodedFrame* frame);
niklase@google.com470e71d2011-07-07 08:21:25 +0000162
stefan@webrtc.org912981f2012-10-12 07:04:52 +0000163 // Returns the time in ms when the latest packet was inserted into the frame.
164 // Retransmitted is set to true if any of the packets belonging to the frame
165 // has been retransmitted.
stefan@webrtc.org3417eb42013-05-21 15:25:53 +0000166 int64_t LastPacketTime(const VCMEncodedFrame* frame,
167 bool* retransmitted) const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000168
stefan@webrtc.org912981f2012-10-12 07:04:52 +0000169 // Inserts a packet into a frame returned from GetFrame().
stefan@webrtc.orgc8b29a22013-06-17 07:13:16 +0000170 // If the return value is <= 0, |frame| is invalidated and the pointer must
171 // be dropped after this function returns.
philipel9d3ab612015-12-21 04:12:39 -0800172 VCMFrameBufferEnum InsertPacket(const VCMPacket& packet, bool* retransmitted);
niklase@google.com470e71d2011-07-07 08:21:25 +0000173
stefan@webrtc.org912981f2012-10-12 07:04:52 +0000174 // Returns the estimated jitter in milliseconds.
175 uint32_t EstimatedJitterMs();
niklase@google.com470e71d2011-07-07 08:21:25 +0000176
stefan@webrtc.org912981f2012-10-12 07:04:52 +0000177 // Updates the round-trip time estimate.
pkasting@chromium.org16825b12015-01-12 21:51:21 +0000178 void UpdateRtt(int64_t rtt_ms);
niklase@google.com470e71d2011-07-07 08:21:25 +0000179
Wan-Teh Chang603175a2015-05-28 14:10:14 -0700180 // Set the NACK mode. |high_rtt_nack_threshold_ms| is an RTT threshold in ms
Wan-Teh Changf2912872015-06-05 13:16:45 -0700181 // above which NACK will be disabled if the NACK mode is |kNack|, -1 meaning
182 // that NACK is always enabled in the |kNack| mode.
Wan-Teh Chang603175a2015-05-28 14:10:14 -0700183 // |low_rtt_nack_threshold_ms| is an RTT threshold in ms below which we expect
184 // to rely on NACK only, and therefore are using larger buffers to have time
185 // to wait for retransmissions.
philipel9d3ab612015-12-21 04:12:39 -0800186 void SetNackMode(VCMNackMode mode,
187 int64_t low_rtt_nack_threshold_ms,
pkasting@chromium.org16825b12015-01-12 21:51:21 +0000188 int64_t high_rtt_nack_threshold_ms);
niklase@google.com470e71d2011-07-07 08:21:25 +0000189
stefan@webrtc.orgbecf9c82013-02-01 15:09:57 +0000190 void SetNackSettings(size_t max_nack_list_size,
stefan@webrtc.orgef144882013-05-07 19:16:33 +0000191 int max_packet_age_to_nack,
192 int max_incomplete_time_ms);
stefan@webrtc.orgbecf9c82013-02-01 15:09:57 +0000193
stefan@webrtc.org912981f2012-10-12 07:04:52 +0000194 // Returns the current NACK mode.
195 VCMNackMode nack_mode() const;
niklase@google.com470e71d2011-07-07 08:21:25 +0000196
stefan@webrtc.orga64300a2013-03-04 15:24:40 +0000197 // Returns a list of the sequence numbers currently missing.
Wan-Teh Changb1825a42015-06-03 15:03:35 -0700198 std::vector<uint16_t> GetNackList(bool* request_key_frame);
niklase@google.com470e71d2011-07-07 08:21:25 +0000199
mikhal@webrtc.org3c5a9242013-09-03 20:45:36 +0000200 // Set decode error mode - Should not be changed in the middle of the
201 // session. Changes will not influence frames already in the buffer.
mikhal@webrtc.orgdbf6a812013-08-21 20:40:47 +0000202 void SetDecodeErrorMode(VCMDecodeErrorMode error_mode);
philipel9d3ab612015-12-21 04:12:39 -0800203 VCMDecodeErrorMode decode_error_mode() const { return decode_error_mode_; }
stefan@webrtc.org4c059d82011-10-13 07:35:37 +0000204
pbos@webrtc.org55707692014-12-19 15:45:03 +0000205 void RegisterStatsCallback(VCMReceiveStatisticsCallback* callback);
pbos@webrtc.orgce4e9a32014-12-18 13:50:16 +0000206
stefan@webrtc.org912981f2012-10-12 07:04:52 +0000207 private:
stefan@webrtc.orga64300a2013-03-04 15:24:40 +0000208 class SequenceNumberLessThan {
209 public:
philipel9d3ab612015-12-21 04:12:39 -0800210 bool operator()(const uint16_t& sequence_number1,
211 const uint16_t& sequence_number2) const {
stefan@webrtc.org7bc465b2013-04-11 17:48:02 +0000212 return IsNewerSequenceNumber(sequence_number2, sequence_number1);
stefan@webrtc.orga64300a2013-03-04 15:24:40 +0000213 }
214 };
215 typedef std::set<uint16_t, SequenceNumberLessThan> SequenceNumberSet;
216
stefan@webrtc.org3417eb42013-05-21 15:25:53 +0000217 // Gets the frame assigned to the timestamp of the packet. May recycle
218 // existing frames if no free frames are available. Returns an error code if
pbos@webrtc.org4f16c872014-11-24 09:06:48 +0000219 // failing, or kNoError on success. |frame_list| contains which list the
220 // packet was in, or NULL if it was not in a FrameList (a new frame).
221 VCMFrameBufferEnum GetFrame(const VCMPacket& packet,
222 VCMFrameBuffer** frame,
223 FrameList** frame_list)
danilchap56359be2017-09-07 07:53:45 -0700224 RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
asapersson@webrtc.org83b52002014-11-28 10:17:13 +0000225
stefan@webrtc.orgc8b29a22013-06-17 07:13:16 +0000226 // Returns true if |frame| is continuous in |decoding_state|, not taking
227 // decodable frames into account.
228 bool IsContinuousInState(const VCMFrameBuffer& frame,
pbos@webrtc.org4f16c872014-11-24 09:06:48 +0000229 const VCMDecodingState& decoding_state) const
danilchap56359be2017-09-07 07:53:45 -0700230 RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
stefan@webrtc.orgc8b29a22013-06-17 07:13:16 +0000231 // Returns true if |frame| is continuous in the |last_decoded_state_|, taking
232 // all decodable frames into account.
pbos@webrtc.org4f16c872014-11-24 09:06:48 +0000233 bool IsContinuous(const VCMFrameBuffer& frame) const
danilchap56359be2017-09-07 07:53:45 -0700234 RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
Noah Richardse4cb4e92015-05-22 14:03:00 -0700235 // Looks for frames in |incomplete_frames_| which are continuous in the
236 // provided |decoded_state|. Starts the search from the timestamp of
237 // |decoded_state|.
238 void FindAndInsertContinuousFramesWithState(
239 const VCMDecodingState& decoded_state)
danilchap56359be2017-09-07 07:53:45 -0700240 RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
stefan@webrtc.orgc8b29a22013-06-17 07:13:16 +0000241 // Looks for frames in |incomplete_frames_| which are continuous in
242 // |last_decoded_state_| taking all decodable frames into account. Starts
243 // the search from |new_frame|.
pbos@webrtc.org4f16c872014-11-24 09:06:48 +0000244 void FindAndInsertContinuousFrames(const VCMFrameBuffer& new_frame)
danilchap56359be2017-09-07 07:53:45 -0700245 RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
246 VCMFrameBuffer* NextFrame() const RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
stefan@webrtc.orga64300a2013-03-04 15:24:40 +0000247 // Returns true if the NACK list was updated to cover sequence numbers up to
248 // |sequence_number|. If false a key frame is needed to get into a state where
249 // we can continue decoding.
pbos@webrtc.org4f16c872014-11-24 09:06:48 +0000250 bool UpdateNackList(uint16_t sequence_number)
danilchap56359be2017-09-07 07:53:45 -0700251 RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
stefan@webrtc.orga64300a2013-03-04 15:24:40 +0000252 bool TooLargeNackList() const;
253 // Returns true if the NACK list was reduced without problem. If false a key
254 // frame is needed to get into a state where we can continue decoding.
danilchap56359be2017-09-07 07:53:45 -0700255 bool HandleTooLargeNackList() RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
pbos@webrtc.org4f16c872014-11-24 09:06:48 +0000256 bool MissingTooOldPacket(uint16_t latest_sequence_number) const
danilchap56359be2017-09-07 07:53:45 -0700257 RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
stefan@webrtc.orga64300a2013-03-04 15:24:40 +0000258 // Returns true if the too old packets was successfully removed from the NACK
259 // list. If false, a key frame is needed to get into a state where we can
260 // continue decoding.
pbos@webrtc.org4f16c872014-11-24 09:06:48 +0000261 bool HandleTooOldPackets(uint16_t latest_sequence_number)
danilchap56359be2017-09-07 07:53:45 -0700262 RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
stefan@webrtc.orga64300a2013-03-04 15:24:40 +0000263 // Drops all packets in the NACK list up until |last_decoded_sequence_number|.
264 void DropPacketsFromNackList(uint16_t last_decoded_sequence_number);
265
stefan@webrtc.org912981f2012-10-12 07:04:52 +0000266 // Gets an empty frame, creating a new frame if necessary (i.e. increases
267 // jitter buffer size).
danilchap56359be2017-09-07 07:53:45 -0700268 VCMFrameBuffer* GetEmptyFrame() RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
niklase@google.com470e71d2011-07-07 08:21:25 +0000269
stefan@webrtc.org4cf1a8a2013-06-27 15:20:14 +0000270 // Attempts to increase the size of the jitter buffer. Returns true on
271 // success, false otherwise.
danilchap56359be2017-09-07 07:53:45 -0700272 bool TryToIncreaseJitterBufferSize() RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
stefan@webrtc.org4cf1a8a2013-06-27 15:20:14 +0000273
stefan@webrtc.org912981f2012-10-12 07:04:52 +0000274 // Recycles oldest frames until a key frame is found. Used if jitter buffer is
275 // completely full. Returns true if a key frame was found.
danilchap56359be2017-09-07 07:53:45 -0700276 bool RecycleFramesUntilKeyFrame() RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
niklase@google.com470e71d2011-07-07 08:21:25 +0000277
stefan@webrtc.org4cf1a8a2013-06-27 15:20:14 +0000278 // Updates the frame statistics.
agalusza@google.comd177c102013-08-08 01:12:33 +0000279 // Counts only complete frames, so decodable incomplete frames will not be
280 // counted.
pbos@webrtc.orgce4e9a32014-12-18 13:50:16 +0000281 void CountFrame(const VCMFrameBuffer& frame)
danilchap56359be2017-09-07 07:53:45 -0700282 RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
stefan@webrtc.org791eec72011-10-11 07:53:43 +0000283
agalusza@google.comd818dcb2013-07-29 21:48:11 +0000284 // Update rolling average of packets per frame.
285 void UpdateAveragePacketsPerFrame(int current_number_packets_);
286
mikhal@webrtc.org381da4b2013-04-25 21:45:29 +0000287 // Cleans the frame list in the JB from old/empty frames.
288 // Should only be called prior to actual use.
danilchap56359be2017-09-07 07:53:45 -0700289 void CleanUpOldOrEmptyFrames() RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
niklase@google.com470e71d2011-07-07 08:21:25 +0000290
stefan@webrtc.org912981f2012-10-12 07:04:52 +0000291 // Returns true if |packet| is likely to have been retransmitted.
292 bool IsPacketRetransmitted(const VCMPacket& packet) const;
henrik.lundin@webrtc.orgbaf6db52011-11-02 18:58:39 +0000293
stefan@webrtc.org912981f2012-10-12 07:04:52 +0000294 // The following three functions update the jitter estimate with the
295 // payload size, receive time and RTP timestamp of a frame.
296 void UpdateJitterEstimate(const VCMJitterSample& sample,
297 bool incomplete_frame);
298 void UpdateJitterEstimate(const VCMFrameBuffer& frame, bool incomplete_frame);
299 void UpdateJitterEstimate(int64_t latest_packet_time_ms,
300 uint32_t timestamp,
301 unsigned int frame_size,
302 bool incomplete_frame);
303
stefan@webrtc.org912981f2012-10-12 07:04:52 +0000304 // Returns true if we should wait for retransmissions, false otherwise.
305 bool WaitForRetransmissions();
306
danilchap56359be2017-09-07 07:53:45 -0700307 int NonContinuousOrIncompleteDuration()
308 RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
stefan@webrtc.orgef144882013-05-07 19:16:33 +0000309
310 uint16_t EstimatedLowSequenceNumber(const VCMFrameBuffer& frame) const;
311
danilchap56359be2017-09-07 07:53:45 -0700312 void UpdateHistograms() RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
asapersson@webrtc.org96dc6852014-11-03 14:40:38 +0000313
sprang22691e02016-07-13 10:57:07 -0700314 // Reset frame buffer and return it to free_frames_.
315 void RecycleFrameBuffer(VCMFrameBuffer* frame)
danilchap56359be2017-09-07 07:53:45 -0700316 RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
sprang22691e02016-07-13 10:57:07 -0700317
stefan@webrtc.orga678a3b2013-01-21 07:42:11 +0000318 Clock* clock_;
stefan@webrtc.org912981f2012-10-12 07:04:52 +0000319 // If we are running (have started) or not.
320 bool running_;
kthelgasonff046c72017-03-31 02:03:55 -0700321 rtc::CriticalSection crit_sect_;
stefan@webrtc.org912981f2012-10-12 07:04:52 +0000322 // Event to signal when we have a frame ready for decoder.
kwiberg3f55dea2016-02-29 05:51:59 -0800323 std::unique_ptr<EventWrapper> frame_event_;
stefan@webrtc.org912981f2012-10-12 07:04:52 +0000324 // Number of allocated frames.
325 int max_number_of_frames_;
danilchap56359be2017-09-07 07:53:45 -0700326 UnorderedFrameList free_frames_ RTC_GUARDED_BY(crit_sect_);
327 FrameList decodable_frames_ RTC_GUARDED_BY(crit_sect_);
328 FrameList incomplete_frames_ RTC_GUARDED_BY(crit_sect_);
329 VCMDecodingState last_decoded_state_ RTC_GUARDED_BY(crit_sect_);
stefan@webrtc.org3417eb42013-05-21 15:25:53 +0000330 bool first_packet_since_reset_;
stefan@webrtc.org912981f2012-10-12 07:04:52 +0000331
332 // Statistics.
danilchap56359be2017-09-07 07:53:45 -0700333 VCMReceiveStatisticsCallback* stats_callback_ RTC_GUARDED_BY(crit_sect_);
sprang@webrtc.org71f055f2013-12-04 15:09:27 +0000334 // Frame counts for each type (key, delta, ...)
pbos@webrtc.orgce4e9a32014-12-18 13:50:16 +0000335 FrameCounts receive_statistics_;
stefan@webrtc.org912981f2012-10-12 07:04:52 +0000336 // Latest calculated frame rates of incoming stream.
337 unsigned int incoming_frame_rate_;
338 unsigned int incoming_frame_count_;
339 int64_t time_last_incoming_frame_count_;
340 unsigned int incoming_bit_count_;
341 unsigned int incoming_bit_rate_;
stefan@webrtc.org912981f2012-10-12 07:04:52 +0000342 // Number of packets in a row that have been too old.
343 int num_consecutive_old_packets_;
asapersson@webrtc.org96dc6852014-11-03 14:40:38 +0000344 // Number of packets received.
danilchap56359be2017-09-07 07:53:45 -0700345 int num_packets_ RTC_GUARDED_BY(crit_sect_);
asapersson@webrtc.org96dc6852014-11-03 14:40:38 +0000346 // Number of duplicated packets received.
danilchap56359be2017-09-07 07:53:45 -0700347 int num_duplicated_packets_ RTC_GUARDED_BY(crit_sect_);
stefan@webrtc.org912981f2012-10-12 07:04:52 +0000348 // Number of packets discarded by the jitter buffer.
danilchap56359be2017-09-07 07:53:45 -0700349 int num_discarded_packets_ RTC_GUARDED_BY(crit_sect_);
asapersson@webrtc.org83b52002014-11-28 10:17:13 +0000350 // Time when first packet is received.
danilchap56359be2017-09-07 07:53:45 -0700351 int64_t time_first_packet_ms_ RTC_GUARDED_BY(crit_sect_);
stefan@webrtc.org912981f2012-10-12 07:04:52 +0000352
353 // Jitter estimation.
354 // Filter for estimating jitter.
355 VCMJitterEstimator jitter_estimate_;
356 // Calculates network delays used for jitter calculations.
357 VCMInterFrameDelay inter_frame_delay_;
358 VCMJitterSample waiting_for_completion_;
pkasting@chromium.org16825b12015-01-12 21:51:21 +0000359 int64_t rtt_ms_;
stefan@webrtc.org912981f2012-10-12 07:04:52 +0000360
361 // NACK and retransmissions.
362 VCMNackMode nack_mode_;
pkasting@chromium.org16825b12015-01-12 21:51:21 +0000363 int64_t low_rtt_nack_threshold_ms_;
364 int64_t high_rtt_nack_threshold_ms_;
stefan@webrtc.org912981f2012-10-12 07:04:52 +0000365 // Holds the internal NACK list (the missing sequence numbers).
stefan@webrtc.orga64300a2013-03-04 15:24:40 +0000366 SequenceNumberSet missing_sequence_numbers_;
367 uint16_t latest_received_sequence_number_;
stefan@webrtc.orgbecf9c82013-02-01 15:09:57 +0000368 size_t max_nack_list_size_;
369 int max_packet_age_to_nack_; // Measured in sequence numbers.
stefan@webrtc.orgef144882013-05-07 19:16:33 +0000370 int max_incomplete_time_ms_;
stefan@webrtc.org912981f2012-10-12 07:04:52 +0000371
agalusza@google.coma7e360e2013-08-01 03:15:08 +0000372 VCMDecodeErrorMode decode_error_mode_;
agalusza@google.comd818dcb2013-07-29 21:48:11 +0000373 // Estimated rolling average of packets per frame
374 float average_packets_per_frame_;
375 // average_packets_per_frame converges fast if we have fewer than this many
376 // frames.
377 int frame_counter_;
philipel83f831a2016-03-12 03:30:23 -0800378
henrikg3c089d72015-09-16 05:37:44 -0700379 RTC_DISALLOW_COPY_AND_ASSIGN(VCMJitterBuffer);
niklase@google.com470e71d2011-07-07 08:21:25 +0000380};
stefan@webrtc.org912981f2012-10-12 07:04:52 +0000381} // namespace webrtc
niklase@google.com470e71d2011-07-07 08:21:25 +0000382
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200383#endif // MODULES_VIDEO_CODING_JITTER_BUFFER_H_