blob: 1be81c201cba17535ad4bd1d0b0f0fc7d77e5de9 [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
102} MCUInst_t;
103
104/****************************************************************************
105 * WebRtcNetEQ_McuReset(...)
106 *
107 * Reset the MCU instance.
108 *
109 * Input:
110 * - inst : MCU instance
111 *
112 * Return value : 0 - Ok
113 * <0 - Error
114 */
115int WebRtcNetEQ_McuReset(MCUInst_t *inst);
116
117/****************************************************************************
118 * WebRtcNetEQ_ResetMcuInCallStats(...)
119 *
120 * Reset MCU-side statistics variables for the in-call statistics.
121 *
122 * Input:
123 * - inst : MCU instance
124 *
125 * Return value : 0 - Ok
126 * <0 - Error
127 */
128int WebRtcNetEQ_ResetMcuInCallStats(MCUInst_t *inst);
129
130/****************************************************************************
henrik.lundin@webrtc.orgdbba1f92011-12-20 15:45:05 +0000131 * WebRtcNetEQ_ResetWaitingTimeStats(...)
132 *
133 * Reset waiting-time statistics.
134 *
135 * Input:
136 * - inst : MCU instance.
137 *
138 * Return value : n/a
139 */
140void WebRtcNetEQ_ResetWaitingTimeStats(MCUInst_t *inst);
141
142/****************************************************************************
143 * WebRtcNetEQ_LogWaitingTime(...)
144 *
145 * Log waiting-time to the statistics.
146 *
147 * Input:
148 * - inst : MCU instance.
149 * - waiting_time : Waiting time in "RecOut calls" (i.e., 1 call = 10 ms).
150 *
151 * Return value : n/a
152 */
153void WebRtcNetEQ_StoreWaitingTime(MCUInst_t *inst, int waiting_time);
154
155/****************************************************************************
niklase@google.com470e71d2011-07-07 08:21:25 +0000156 * WebRtcNetEQ_ResetMcuJitterStat(...)
157 *
158 * Reset MCU-side statistics variables for the post-call statistics.
159 *
160 * Input:
161 * - inst : MCU instance
162 *
163 * Return value : 0 - Ok
164 * <0 - Error
165 */
166int WebRtcNetEQ_ResetMcuJitterStat(MCUInst_t *inst);
167
168/****************************************************************************
169 * WebRtcNetEQ_McuAddressInit(...)
170 *
171 * Initializes MCU with read address and write address.
172 *
173 * Input:
174 * - inst : MCU instance
175 * - Data2McuAddress : Pointer to MCU address
176 * - Data2DspAddress : Pointer to DSP address
177 * - main_inst : Pointer to NetEQ main instance
178 *
179 * Return value : 0 - Ok
180 * <0 - Error
181 */
182int WebRtcNetEQ_McuAddressInit(MCUInst_t *inst, void * Data2McuAddress,
183 void * Data2DspAddress, void *main_inst);
184
185/****************************************************************************
186 * WebRtcNetEQ_McuSetFs(...)
187 *
188 * Initializes MCU with read address and write address.
189 *
190 * Input:
191 * - inst : MCU instance
192 * - fs_hz : Sample rate in Hz -- 8000, 16000, 32000, (48000)
193 *
194 * Return value : 0 - Ok
195 * <0 - Error
196 */
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000197int WebRtcNetEQ_McuSetFs(MCUInst_t *inst, uint16_t fs_hz);
niklase@google.com470e71d2011-07-07 08:21:25 +0000198
199/****************************************************************************
200 * WebRtcNetEQ_SignalMcu(...)
201 *
202 * Signal the MCU that data is available and ask for a RecOut decision.
203 *
204 * Input:
205 * - inst : MCU instance
turaj@webrtc.org28d54ab2013-04-22 18:53:35 +0000206 * - av_sync : 1 if NetEQ is in AV-sync mode, otherwise 0.
niklase@google.com470e71d2011-07-07 08:21:25 +0000207 *
208 * Return value : 0 - Ok
209 * <0 - Error
210 */
211int WebRtcNetEQ_SignalMcu(MCUInst_t *inst);
212
213/****************************************************************************
214 * WebRtcNetEQ_RecInInternal(...)
215 *
216 * This function inserts a packet into the jitter buffer.
217 *
218 * Input:
219 * - MCU_inst : MCU instance
220 * - RTPpacket : The RTP packet, parsed into NetEQ's internal RTP struct
221 * - uw32_timeRec : Time stamp for the arrival of the packet (not RTP timestamp)
222 *
223 * Return value : 0 - Ok
224 * -1 - Error
225 */
226
227int WebRtcNetEQ_RecInInternal(MCUInst_t *MCU_inst, RTPPacket_t *RTPpacket,
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000228 uint32_t uw32_timeRec);
niklase@google.com470e71d2011-07-07 08:21:25 +0000229
230/****************************************************************************
231 * WebRtcNetEQ_RecInInternal(...)
232 *
233 * Split the packet according to split_inst and inserts the parts into
234 * Buffer_inst.
235 *
236 * Input:
237 * - MCU_inst : MCU instance
238 * - RTPpacket : The RTP packet, parsed into NetEQ's internal RTP struct
239 * - uw32_timeRec : Time stamp for the arrival of the packet (not RTP timestamp)
turaj@webrtc.org28d54ab2013-04-22 18:53:35 +0000240 * - av_sync : indicates if AV-sync is enabled, 1 enabled,
241 * 0 disabled.
niklase@google.com470e71d2011-07-07 08:21:25 +0000242 *
243 * Return value : 0 - Ok
244 * -1 - Error
245 */
turaj@webrtc.org28d54ab2013-04-22 18:53:35 +0000246int WebRtcNetEQ_SplitAndInsertPayload(RTPPacket_t* packet,
247 PacketBuf_t* Buffer_inst,
248 SplitInfo_t* split_inst,
249 int16_t* flushed,
250 int av_sync);
niklase@google.com470e71d2011-07-07 08:21:25 +0000251
252/****************************************************************************
253 * WebRtcNetEQ_GetTimestampScaling(...)
254 *
255 * Update information about timestamp scaling for a payload type
256 * in MCU_inst->scalingFactor.
257 *
258 * Input:
259 * - MCU_inst : MCU instance
260 * - rtpPayloadType : RTP payload number
261 *
262 * Return value : 0 - Ok
263 * -1 - Error
264 */
265
266int WebRtcNetEQ_GetTimestampScaling(MCUInst_t *MCU_inst, int rtpPayloadType);
267
268/****************************************************************************
269 * WebRtcNetEQ_ScaleTimestampExternalToInternal(...)
270 *
271 * Convert from external to internal timestamp using current scaling info.
272 *
273 * Input:
274 * - MCU_inst : MCU instance
275 * - externalTS : External timestamp
276 *
277 * Return value : Internal timestamp
278 */
279
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000280uint32_t WebRtcNetEQ_ScaleTimestampExternalToInternal(const MCUInst_t *MCU_inst,
281 uint32_t externalTS);
niklase@google.com470e71d2011-07-07 08:21:25 +0000282
283/****************************************************************************
284 * WebRtcNetEQ_ScaleTimestampInternalToExternal(...)
285 *
286 * Convert from external to internal timestamp using current scaling info.
287 *
288 * Input:
289 * - MCU_inst : MCU instance
290 * - externalTS : Internal timestamp
291 *
292 * Return value : External timestamp
293 */
294
pbos@webrtc.org0946a562013-04-09 00:28:06 +0000295uint32_t WebRtcNetEQ_ScaleTimestampInternalToExternal(const MCUInst_t *MCU_inst,
296 uint32_t internalTS);
niklase@google.com470e71d2011-07-07 08:21:25 +0000297#endif