niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
| 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 | |
| 33 | enum TsScaling |
| 34 | { |
| 35 | kTSnoScaling = 0, |
| 36 | kTSscalingTwo, |
| 37 | kTSscalingTwoThirds, |
| 38 | kTSscalingFourThirds |
| 39 | }; |
| 40 | |
henrik.lundin@webrtc.org | dbba1f9 | 2011-12-20 15:45:05 +0000 | [diff] [blame] | 41 | enum { kLenWaitingTimes = 100 }; |
| 42 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 43 | typedef struct |
| 44 | { |
| 45 | |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 46 | 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 55 | |
| 56 | /* MCU/DSP Communication layer */ |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 57 | int16_t *pw16_readAddress; |
| 58 | int16_t *pw16_writeAddress; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 59 | 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.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 74 | int16_t AVT_PlayoutOn; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 75 | enum WebRtcNetEQPlayoutMode NetEqPlayoutMode; |
| 76 | |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 77 | int16_t one_desc; /* Number of times running on one desc */ |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 78 | |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 79 | uint32_t lostTS; /* Number of timestamps lost */ |
| 80 | uint32_t lastReportTS; /* Timestamp elapsed since last report was given */ |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 81 | |
henrik.lundin@webrtc.org | dbba1f9 | 2011-12-20 15:45:05 +0000 | [diff] [blame] | 82 | int waiting_times[kLenWaitingTimes]; /* Waiting time statistics storage. */ |
| 83 | int len_waiting_times; |
| 84 | int next_waiting_time_index; |
| 85 | |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 86 | uint32_t externalTS; |
| 87 | uint32_t internalTS; |
| 88 | int16_t TSscalingInitialized; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 89 | enum TsScaling scalingFactor; |
| 90 | |
turaj@webrtc.org | 28d54ab | 2013-04-22 18:53:35 +0000 | [diff] [blame] | 91 | /* 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 98 | #ifdef NETEQ_STEREO |
| 99 | int usingStereo; |
| 100 | #endif |
| 101 | |
turaj@webrtc.org | a305e96 | 2013-06-06 19:00:09 +0000 | [diff] [blame] | 102 | /* The sequence number of the latest decoded RTP payload. */ |
| 103 | int decoded_packet_sequence_number; |
| 104 | uint32_t decoded_packet_timestamp; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 105 | } 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 | */ |
| 118 | int 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 | */ |
| 131 | int WebRtcNetEQ_ResetMcuInCallStats(MCUInst_t *inst); |
| 132 | |
| 133 | /**************************************************************************** |
henrik.lundin@webrtc.org | dbba1f9 | 2011-12-20 15:45:05 +0000 | [diff] [blame] | 134 | * WebRtcNetEQ_ResetWaitingTimeStats(...) |
| 135 | * |
| 136 | * Reset waiting-time statistics. |
| 137 | * |
| 138 | * Input: |
| 139 | * - inst : MCU instance. |
| 140 | * |
| 141 | * Return value : n/a |
| 142 | */ |
| 143 | void 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 | */ |
| 156 | void WebRtcNetEQ_StoreWaitingTime(MCUInst_t *inst, int waiting_time); |
| 157 | |
| 158 | /**************************************************************************** |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 159 | * 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 | */ |
| 169 | int 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 | */ |
| 185 | int 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.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 200 | int WebRtcNetEQ_McuSetFs(MCUInst_t *inst, uint16_t fs_hz); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 201 | |
| 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.org | 28d54ab | 2013-04-22 18:53:35 +0000 | [diff] [blame] | 209 | * - av_sync : 1 if NetEQ is in AV-sync mode, otherwise 0. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 210 | * |
| 211 | * Return value : 0 - Ok |
| 212 | * <0 - Error |
| 213 | */ |
| 214 | int 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 | |
| 230 | int WebRtcNetEQ_RecInInternal(MCUInst_t *MCU_inst, RTPPacket_t *RTPpacket, |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 231 | uint32_t uw32_timeRec); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 232 | |
| 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.org | 28d54ab | 2013-04-22 18:53:35 +0000 | [diff] [blame] | 243 | * - av_sync : indicates if AV-sync is enabled, 1 enabled, |
| 244 | * 0 disabled. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 245 | * |
| 246 | * Return value : 0 - Ok |
| 247 | * -1 - Error |
| 248 | */ |
turaj@webrtc.org | 28d54ab | 2013-04-22 18:53:35 +0000 | [diff] [blame] | 249 | int 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.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 254 | |
| 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 | |
| 269 | int 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.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 283 | uint32_t WebRtcNetEQ_ScaleTimestampExternalToInternal(const MCUInst_t *MCU_inst, |
| 284 | uint32_t externalTS); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 285 | |
| 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.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame] | 298 | uint32_t WebRtcNetEQ_ScaleTimestampInternalToExternal(const MCUInst_t *MCU_inst, |
| 299 | uint32_t internalTS); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 300 | #endif |