blob: 61ff2b970fd77ef22f65d8b3b8ebce55e0ca8352 [file] [log] [blame]
niklase@google.com470e71d2011-07-07 08:21:25 +00001/*
2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
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
11/*
12 * Interface for the actual packet buffer data structure.
13 */
14
15#ifndef PACKET_BUFFER_H
16#define PACKET_BUFFER_H
17
18#include "typedefs.h"
19
20#include "webrtc_neteq.h"
21#include "rtp.h"
22
23/* Define minimum allowed buffer memory, in 16-bit words */
24#define PBUFFER_MIN_MEMORY_SIZE 150
25
26/****************************/
27/* The packet buffer struct */
28/****************************/
29
30typedef struct
31{
32
33 /* Variables common to the entire buffer */
pbos@webrtc.org0946a562013-04-09 00:28:06 +000034 uint16_t packSizeSamples; /* packet size in samples of last decoded packet */
35 int16_t *startPayloadMemory; /* pointer to the payload memory */
36 int memorySizeW16; /* the size (in int16_t) of the payload memory */
37 int16_t *currentMemoryPos; /* The memory position to insert next payload */
niklase@google.com470e71d2011-07-07 08:21:25 +000038 int numPacketsInBuffer; /* The number of packets in the buffer */
39 int insertPosition; /* The position to insert next packet */
40 int maxInsertPositions; /* Maximum number of packets allowed */
41
42 /* Arrays with one entry per packet slot */
43 /* NOTE: If these are changed, the changes must be accounted for at the end of
44 the function WebRtcNetEQ_GetDefaultCodecSettings(). */
pbos@webrtc.org0946a562013-04-09 00:28:06 +000045 uint32_t *timeStamp; /* Timestamp in slot n */
46 int16_t **payloadLocation; /* Memory location of payload in slot n */
47 uint16_t *seqNumber; /* Sequence number in slot n */
48 int16_t *payloadType; /* Payload type of packet in slot n */
49 int16_t *payloadLengthBytes; /* Payload length of packet in slot n */
50 int16_t *rcuPlCntr; /* zero for non-RCU payload, 1 for main payload
niklase@google.com470e71d2011-07-07 08:21:25 +000051 2 for redundant payload */
henrik.lundin@webrtc.orgdbba1f92011-12-20 15:45:05 +000052 int *waitingTime;
53
henrik.lundin@webrtc.org89ab6522011-11-23 11:06:05 +000054 /* Statistics counter */
pbos@webrtc.org0946a562013-04-09 00:28:06 +000055 uint16_t discardedPackets; /* Number of discarded packets */
niklase@google.com470e71d2011-07-07 08:21:25 +000056
57} PacketBuf_t;
58
59/*************************/
60/* Function declarations */
61/*************************/
62
63/****************************************************************************
64 * WebRtcNetEQ_PacketBufferInit(...)
65 *
66 * This function initializes the packet buffer.
67 *
68 * Input:
69 * - bufferInst : Buffer instance to be initialized
70 * - noOfPackets : Maximum number of packets that buffer should hold
71 * - memory : Pointer to the storage memory for the payloads
pbos@webrtc.org0946a562013-04-09 00:28:06 +000072 * - memorySize : The size of the payload memory (in int16_t)
niklase@google.com470e71d2011-07-07 08:21:25 +000073 *
74 * Output:
75 * - bufferInst : Updated buffer instance
76 *
77 * Return value : 0 - Ok
78 * <0 - Error
79 */
80
81int WebRtcNetEQ_PacketBufferInit(PacketBuf_t *bufferInst, int maxNoOfPackets,
pbos@webrtc.org0946a562013-04-09 00:28:06 +000082 int16_t *pw16_memory, int memorySize);
niklase@google.com470e71d2011-07-07 08:21:25 +000083
84/****************************************************************************
85 * WebRtcNetEQ_PacketBufferFlush(...)
86 *
87 * This function flushes all the packets in the buffer.
88 *
89 * Input:
90 * - bufferInst : Buffer instance to be flushed
91 *
92 * Output:
93 * - bufferInst : Flushed buffer instance
94 *
95 * Return value : 0 - Ok
96 */
97
98int WebRtcNetEQ_PacketBufferFlush(PacketBuf_t *bufferInst);
99
100/****************************************************************************
101 * WebRtcNetEQ_PacketBufferInsert(...)
102 *
103 * This function inserts an RTP packet into the packet buffer.
104 *
105 * Input:
turaj@webrtc.org28d54ab2013-04-22 18:53:35 +0000106 * - bufferInst : Buffer instance
107 * - RTPpacket : An RTP packet struct (with payload, sequence
108 * number, etc.)
109 * - av_sync : 1 indicates AV-sync enabled, 0 disabled.
niklase@google.com470e71d2011-07-07 08:21:25 +0000110 *
111 * Output:
turaj@webrtc.org28d54ab2013-04-22 18:53:35 +0000112 * - bufferInst : Updated buffer instance
113 * - flushed : 1 if buffer was flushed, 0 otherwise
niklase@google.com470e71d2011-07-07 08:21:25 +0000114 *
turaj@webrtc.org28d54ab2013-04-22 18:53:35 +0000115 * Return value : 0 - Ok
116 * -1 - Error
niklase@google.com470e71d2011-07-07 08:21:25 +0000117 */
118
119int WebRtcNetEQ_PacketBufferInsert(PacketBuf_t *bufferInst, const RTPPacket_t *RTPpacket,
turaj@webrtc.org28d54ab2013-04-22 18:53:35 +0000120 int16_t *flushed, int av_sync);
niklase@google.com470e71d2011-07-07 08:21:25 +0000121
122/****************************************************************************
123 * WebRtcNetEQ_PacketBufferExtract(...)
124 *
125 * This function extracts a payload from the buffer.
126 *
127 * Input:
128 * - bufferInst : Buffer instance
129 * - bufferPosition: Position of the packet that should be extracted
130 *
131 * Output:
132 * - RTPpacket : An RTP packet struct (with payload, sequence
133 * number, etc)
134 * - bufferInst : Updated buffer instance
135 *
136 * Return value : 0 - Ok
137 * <0 - Error
138 */
139
140int WebRtcNetEQ_PacketBufferExtract(PacketBuf_t *bufferInst, RTPPacket_t *RTPpacket,
henrik.lundin@webrtc.orgdbba1f92011-12-20 15:45:05 +0000141 int bufferPosition, int *waitingTime);
niklase@google.com470e71d2011-07-07 08:21:25 +0000142
143/****************************************************************************
144 * WebRtcNetEQ_PacketBufferFindLowestTimestamp(...)
145 *
146 * This function finds the next packet with the lowest timestamp.
147 *
148 * Input:
kma@webrtc.org89a10002012-01-30 15:37:33 +0000149 * - buffer_inst : Buffer instance.
150 * - current_time_stamp : The timestamp to compare packet timestamps with.
151 * - erase_old_packets : If non-zero, erase packets older than currentTS.
niklase@google.com470e71d2011-07-07 08:21:25 +0000152 *
153 * Output:
kma@webrtc.org89a10002012-01-30 15:37:33 +0000154 * - time_stamp : Lowest timestamp that was found.
155 * - buffer_position : Position of this packet (-1 if there are no
156 * packets in the buffer).
157 * - payload_type : Payload type of the found payload.
niklase@google.com470e71d2011-07-07 08:21:25 +0000158 *
kma@webrtc.org89a10002012-01-30 15:37:33 +0000159 * Return value : 0 - Ok;
160 * < 0 - Error.
niklase@google.com470e71d2011-07-07 08:21:25 +0000161 */
162
kma@webrtc.org89a10002012-01-30 15:37:33 +0000163int WebRtcNetEQ_PacketBufferFindLowestTimestamp(PacketBuf_t* buffer_inst,
164 uint32_t current_time_stamp,
165 uint32_t* time_stamp,
166 int* buffer_position,
167 int erase_old_packets,
168 int16_t* payload_type);
niklase@google.com470e71d2011-07-07 08:21:25 +0000169
170/****************************************************************************
tina.legrand@webrtc.org5ac387c2012-11-19 08:02:55 +0000171 * WebRtcNetEQ_PacketBufferGetPacketSize(...)
172 *
173 * Calculate and return an estimate of the data length (in samples) of the
174 * given packet. If no estimate is available (because we do not know how to
175 * compute packet durations for the associated payload type), last_duration
176 * will be returned instead.
177 *
178 * Input:
179 * - buffer_inst : Buffer instance
180 * - buffer_pos : The index of the buffer of which to estimate the
181 * duration
182 * - codec_database : Codec database instance
183 * - codec_pos : The codec database entry associated with the payload
184 * type of the specified buffer.
185 * - last_duration : The duration of the previous frame.
turaj@webrtc.org28d54ab2013-04-22 18:53:35 +0000186 * - av_sync : 1 indicates AV-sync enabled, 0 disabled.
tina.legrand@webrtc.org5ac387c2012-11-19 08:02:55 +0000187 *
188 * Return value : The buffer size in samples
189 */
190
191int WebRtcNetEQ_PacketBufferGetPacketSize(const PacketBuf_t* buffer_inst,
192 int buffer_pos,
193 const CodecDbInst_t* codec_database,
turaj@webrtc.org28d54ab2013-04-22 18:53:35 +0000194 int codec_pos, int last_duration,
195 int av_sync);
tina.legrand@webrtc.org5ac387c2012-11-19 08:02:55 +0000196
197/****************************************************************************
niklase@google.com470e71d2011-07-07 08:21:25 +0000198 * WebRtcNetEQ_PacketBufferGetSize(...)
199 *
200 * Calculate and return an estimate of the total data length (in samples)
201 * currently in the buffer. The estimate is calculated as the number of
202 * packets currently in the buffer (which does not have any remaining waiting
203 * time), multiplied with the number of samples obtained from the last
204 * decoded packet.
205 *
206 * Input:
tina.legrand@webrtc.org5ac387c2012-11-19 08:02:55 +0000207 * - buffer_inst : Buffer instance
208 * - codec_database : Codec database instance
turaj@webrtc.org28d54ab2013-04-22 18:53:35 +0000209 * - av_sync : 1 indicates AV-sync enabled, 0 disabled.
niklase@google.com470e71d2011-07-07 08:21:25 +0000210 *
tina.legrand@webrtc.org5ac387c2012-11-19 08:02:55 +0000211 * Return value : The buffer size in samples
niklase@google.com470e71d2011-07-07 08:21:25 +0000212 */
213
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000214int32_t WebRtcNetEQ_PacketBufferGetSize(const PacketBuf_t* buffer_inst,
turaj@webrtc.org28d54ab2013-04-22 18:53:35 +0000215 const CodecDbInst_t* codec_database,
216 int av_sync);
niklase@google.com470e71d2011-07-07 08:21:25 +0000217
218/****************************************************************************
henrik.lundin@webrtc.orgdbba1f92011-12-20 15:45:05 +0000219 * WebRtcNetEQ_IncrementWaitingTimes(...)
220 *
221 * Increment the waiting time for all packets in the buffer by one.
222 *
223 * Input:
224 * - bufferInst : Buffer instance
225 *
226 * Return value : n/a
227 */
228
229void WebRtcNetEQ_IncrementWaitingTimes(PacketBuf_t *buffer_inst);
230
231/****************************************************************************
niklase@google.com470e71d2011-07-07 08:21:25 +0000232 * WebRtcNetEQ_GetDefaultCodecSettings(...)
233 *
234 * Calculates a recommended buffer size for a specific set of codecs.
235 *
236 * Input:
237 * - codecID : An array of codec types that will be used
238 * - noOfCodecs : Number of codecs in array codecID
239 *
240 * Output:
241 * - maxBytes : Recommended buffer memory size in bytes
242 * - maxSlots : Recommended number of slots in buffer
turaj@webrtc.org6388c3e2013-02-12 21:42:18 +0000243 * - per_slot_overhead_bytes : overhead in bytes for each slot in buffer.
niklase@google.com470e71d2011-07-07 08:21:25 +0000244 *
245 * Return value : 0 - Ok
246 * <0 - Error
247 */
248
249int WebRtcNetEQ_GetDefaultCodecSettings(const enum WebRtcNetEQDecoder *codecID,
turaj@webrtc.org6388c3e2013-02-12 21:42:18 +0000250 int noOfCodecs, int *maxBytes,
251 int *maxSlots,
252 int* per_slot_overhead_bytes);
niklase@google.com470e71d2011-07-07 08:21:25 +0000253
254#endif /* PACKET_BUFFER_H */