blob: 931e6dcf5610c4d1cadd389da4d94a02af00dd81 [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 * MCU struct and functions related to the MCU side operations.
13 */
14
15#ifndef MCU_H
16#define MCU_H
17
18#include "typedefs.h"
19
20#include "codec_db.h"
21#include "rtcp.h"
22#include "packet_buffer.h"
23#include "buffer_stats.h"
24#include "neteq_statistics.h"
25
26#ifdef NETEQ_ATEVENT_DECODE
27#include "dtmf_buffer.h"
28#endif
29
30#define MAX_ONE_DESC 5 /* cannot do more than this many consecutive one-descriptor decodings */
31#define MAX_LOSS_REPORT_PERIOD 60 /* number of seconds between auto-reset */
32
33enum TsScaling
34{
35 kTSnoScaling = 0,
36 kTSscalingTwo,
37 kTSscalingTwoThirds,
38 kTSscalingFourThirds
39};
40
henrik.lundin@webrtc.orgdbba1f92011-12-20 15:45:05 +000041enum { kLenWaitingTimes = 100 };
42
niklase@google.com470e71d2011-07-07 08:21:25 +000043typedef struct
44{
45
pbos@webrtc.org0946a562013-04-09 00:28:06 +000046 int16_t current_Codec;
47 int16_t current_Payload;
48 uint32_t timeStamp; /* Next timestamp that should be played */
49 int16_t millisecondsPerCall;
50 uint16_t timestampsPerCall; /* Output chunk size */
51 uint16_t fs;
52 uint32_t ssrc; /* Current ssrc */
53 int16_t new_codec;
54 int16_t first_packet;
niklase@google.com470e71d2011-07-07 08:21:25 +000055
56 /* MCU/DSP Communication layer */
pbos@webrtc.org0946a562013-04-09 00:28:06 +000057 int16_t *pw16_readAddress;
58 int16_t *pw16_writeAddress;
niklase@google.com470e71d2011-07-07 08:21:25 +000059 void *main_inst;
60
61 CodecDbInst_t codec_DB_inst; /* Information about all the codecs, i.e. which
62 functions to use and which codpoints that
63 have been assigned */
64 SplitInfo_t PayloadSplit_inst; /* Information about how the current codec
65 payload should be splitted */
66 WebRtcNetEQ_RTCP_t RTCP_inst; /* RTCP statistics */
67 PacketBuf_t PacketBuffer_inst; /* The packet buffer */
68 BufstatsInst_t BufferStat_inst; /* Statistics that are used to make decision
69 for what the DSP should perform */
70#ifdef NETEQ_ATEVENT_DECODE
71 dtmf_inst_t DTMF_inst;
72#endif
73 int NoOfExpandCalls;
pbos@webrtc.org0946a562013-04-09 00:28:06 +000074 int16_t AVT_PlayoutOn;
niklase@google.com470e71d2011-07-07 08:21:25 +000075 enum WebRtcNetEQPlayoutMode NetEqPlayoutMode;
76
pbos@webrtc.org0946a562013-04-09 00:28:06 +000077 int16_t one_desc; /* Number of times running on one desc */
niklase@google.com470e71d2011-07-07 08:21:25 +000078
pbos@webrtc.org0946a562013-04-09 00:28:06 +000079 uint32_t lostTS; /* Number of timestamps lost */
80 uint32_t lastReportTS; /* Timestamp elapsed since last report was given */
niklase@google.com470e71d2011-07-07 08:21:25 +000081
henrik.lundin@webrtc.orgdbba1f92011-12-20 15:45:05 +000082 int waiting_times[kLenWaitingTimes]; /* Waiting time statistics storage. */
83 int len_waiting_times;
84 int next_waiting_time_index;
85
pbos@webrtc.org0946a562013-04-09 00:28:06 +000086 uint32_t externalTS;
87 uint32_t internalTS;
88 int16_t TSscalingInitialized;
niklase@google.com470e71d2011-07-07 08:21:25 +000089 enum TsScaling scalingFactor;
90
turaj@webrtc.org28d54ab2013-04-22 18:53:35 +000091 /* AV-sync enabled. In AV-sync NetEq screens packets for specific sync
92 * packets. Sync packets are not decoded by a decoder but generate all-zero
93 * signal with the same number of samples as previously decoded payload.
94 * Also in AV-sync mode the sample-size of a sync payload is reported as
95 * previous frame-size. */
96 int av_sync;
97
niklase@google.com470e71d2011-07-07 08:21:25 +000098#ifdef NETEQ_STEREO
99 int usingStereo;
100#endif
101
turaj@webrtc.orga305e962013-06-06 19:00:09 +0000102 /* The sequence number of the latest decoded RTP payload. */
103 int decoded_packet_sequence_number;
104 uint32_t decoded_packet_timestamp;
niklase@google.com470e71d2011-07-07 08:21:25 +0000105} MCUInst_t;
106
107/****************************************************************************
108 * WebRtcNetEQ_McuReset(...)
109 *
110 * Reset the MCU instance.
111 *
112 * Input:
113 * - inst : MCU instance
114 *
115 * Return value : 0 - Ok
116 * <0 - Error
117 */
118int WebRtcNetEQ_McuReset(MCUInst_t *inst);
119
120/****************************************************************************
121 * WebRtcNetEQ_ResetMcuInCallStats(...)
122 *
123 * Reset MCU-side statistics variables for the in-call statistics.
124 *
125 * Input:
126 * - inst : MCU instance
127 *
128 * Return value : 0 - Ok
129 * <0 - Error
130 */
131int WebRtcNetEQ_ResetMcuInCallStats(MCUInst_t *inst);
132
133/****************************************************************************
henrik.lundin@webrtc.orgdbba1f92011-12-20 15:45:05 +0000134 * WebRtcNetEQ_ResetWaitingTimeStats(...)
135 *
136 * Reset waiting-time statistics.
137 *
138 * Input:
139 * - inst : MCU instance.
140 *
141 * Return value : n/a
142 */
143void WebRtcNetEQ_ResetWaitingTimeStats(MCUInst_t *inst);
144
145/****************************************************************************
146 * WebRtcNetEQ_LogWaitingTime(...)
147 *
148 * Log waiting-time to the statistics.
149 *
150 * Input:
151 * - inst : MCU instance.
152 * - waiting_time : Waiting time in "RecOut calls" (i.e., 1 call = 10 ms).
153 *
154 * Return value : n/a
155 */
156void WebRtcNetEQ_StoreWaitingTime(MCUInst_t *inst, int waiting_time);
157
158/****************************************************************************
niklase@google.com470e71d2011-07-07 08:21:25 +0000159 * WebRtcNetEQ_ResetMcuJitterStat(...)
160 *
161 * Reset MCU-side statistics variables for the post-call statistics.
162 *
163 * Input:
164 * - inst : MCU instance
165 *
166 * Return value : 0 - Ok
167 * <0 - Error
168 */
169int WebRtcNetEQ_ResetMcuJitterStat(MCUInst_t *inst);
170
171/****************************************************************************
172 * WebRtcNetEQ_McuAddressInit(...)
173 *
174 * Initializes MCU with read address and write address.
175 *
176 * Input:
177 * - inst : MCU instance
178 * - Data2McuAddress : Pointer to MCU address
179 * - Data2DspAddress : Pointer to DSP address
180 * - main_inst : Pointer to NetEQ main instance
181 *
182 * Return value : 0 - Ok
183 * <0 - Error
184 */
185int WebRtcNetEQ_McuAddressInit(MCUInst_t *inst, void * Data2McuAddress,
186 void * Data2DspAddress, void *main_inst);
187
188/****************************************************************************
189 * WebRtcNetEQ_McuSetFs(...)
190 *
191 * Initializes MCU with read address and write address.
192 *
193 * Input:
194 * - inst : MCU instance
195 * - fs_hz : Sample rate in Hz -- 8000, 16000, 32000, (48000)
196 *
197 * Return value : 0 - Ok
198 * <0 - Error
199 */
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000200int WebRtcNetEQ_McuSetFs(MCUInst_t *inst, uint16_t fs_hz);
niklase@google.com470e71d2011-07-07 08:21:25 +0000201
202/****************************************************************************
203 * WebRtcNetEQ_SignalMcu(...)
204 *
205 * Signal the MCU that data is available and ask for a RecOut decision.
206 *
207 * Input:
208 * - inst : MCU instance
turaj@webrtc.org28d54ab2013-04-22 18:53:35 +0000209 * - av_sync : 1 if NetEQ is in AV-sync mode, otherwise 0.
niklase@google.com470e71d2011-07-07 08:21:25 +0000210 *
211 * Return value : 0 - Ok
212 * <0 - Error
213 */
214int WebRtcNetEQ_SignalMcu(MCUInst_t *inst);
215
216/****************************************************************************
217 * WebRtcNetEQ_RecInInternal(...)
218 *
219 * This function inserts a packet into the jitter buffer.
220 *
221 * Input:
222 * - MCU_inst : MCU instance
223 * - RTPpacket : The RTP packet, parsed into NetEQ's internal RTP struct
224 * - uw32_timeRec : Time stamp for the arrival of the packet (not RTP timestamp)
225 *
226 * Return value : 0 - Ok
227 * -1 - Error
228 */
229
230int WebRtcNetEQ_RecInInternal(MCUInst_t *MCU_inst, RTPPacket_t *RTPpacket,
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000231 uint32_t uw32_timeRec);
niklase@google.com470e71d2011-07-07 08:21:25 +0000232
233/****************************************************************************
234 * WebRtcNetEQ_RecInInternal(...)
235 *
236 * Split the packet according to split_inst and inserts the parts into
237 * Buffer_inst.
238 *
239 * Input:
240 * - MCU_inst : MCU instance
241 * - RTPpacket : The RTP packet, parsed into NetEQ's internal RTP struct
242 * - uw32_timeRec : Time stamp for the arrival of the packet (not RTP timestamp)
turaj@webrtc.org28d54ab2013-04-22 18:53:35 +0000243 * - av_sync : indicates if AV-sync is enabled, 1 enabled,
244 * 0 disabled.
niklase@google.com470e71d2011-07-07 08:21:25 +0000245 *
246 * Return value : 0 - Ok
247 * -1 - Error
248 */
turaj@webrtc.org28d54ab2013-04-22 18:53:35 +0000249int WebRtcNetEQ_SplitAndInsertPayload(RTPPacket_t* packet,
250 PacketBuf_t* Buffer_inst,
251 SplitInfo_t* split_inst,
252 int16_t* flushed,
253 int av_sync);
niklase@google.com470e71d2011-07-07 08:21:25 +0000254
255/****************************************************************************
256 * WebRtcNetEQ_GetTimestampScaling(...)
257 *
258 * Update information about timestamp scaling for a payload type
259 * in MCU_inst->scalingFactor.
260 *
261 * Input:
262 * - MCU_inst : MCU instance
263 * - rtpPayloadType : RTP payload number
264 *
265 * Return value : 0 - Ok
266 * -1 - Error
267 */
268
269int WebRtcNetEQ_GetTimestampScaling(MCUInst_t *MCU_inst, int rtpPayloadType);
270
271/****************************************************************************
272 * WebRtcNetEQ_ScaleTimestampExternalToInternal(...)
273 *
274 * Convert from external to internal timestamp using current scaling info.
275 *
276 * Input:
277 * - MCU_inst : MCU instance
278 * - externalTS : External timestamp
279 *
280 * Return value : Internal timestamp
281 */
282
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000283uint32_t WebRtcNetEQ_ScaleTimestampExternalToInternal(const MCUInst_t *MCU_inst,
284 uint32_t externalTS);
niklase@google.com470e71d2011-07-07 08:21:25 +0000285
286/****************************************************************************
287 * WebRtcNetEQ_ScaleTimestampInternalToExternal(...)
288 *
289 * Convert from external to internal timestamp using current scaling info.
290 *
291 * Input:
292 * - MCU_inst : MCU instance
293 * - externalTS : Internal timestamp
294 *
295 * Return value : External timestamp
296 */
297
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000298uint32_t WebRtcNetEQ_ScaleTimestampInternalToExternal(const MCUInst_t *MCU_inst,
299 uint32_t internalTS);
niklase@google.com470e71d2011-07-07 08:21:25 +0000300#endif