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 | |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 91 | #ifdef NETEQ_STEREO |
| 92 | int usingStereo; |
| 93 | #endif |
| 94 | |
| 95 | } MCUInst_t; |
| 96 | |
| 97 | /**************************************************************************** |
| 98 | * WebRtcNetEQ_McuReset(...) |
| 99 | * |
| 100 | * Reset the MCU instance. |
| 101 | * |
| 102 | * Input: |
| 103 | * - inst : MCU instance |
| 104 | * |
| 105 | * Return value : 0 - Ok |
| 106 | * <0 - Error |
| 107 | */ |
| 108 | int WebRtcNetEQ_McuReset(MCUInst_t *inst); |
| 109 | |
| 110 | /**************************************************************************** |
| 111 | * WebRtcNetEQ_ResetMcuInCallStats(...) |
| 112 | * |
| 113 | * Reset MCU-side statistics variables for the in-call statistics. |
| 114 | * |
| 115 | * Input: |
| 116 | * - inst : MCU instance |
| 117 | * |
| 118 | * Return value : 0 - Ok |
| 119 | * <0 - Error |
| 120 | */ |
| 121 | int WebRtcNetEQ_ResetMcuInCallStats(MCUInst_t *inst); |
| 122 | |
| 123 | /**************************************************************************** |
henrik.lundin@webrtc.org | dbba1f9 | 2011-12-20 15:45:05 +0000 | [diff] [blame] | 124 | * WebRtcNetEQ_ResetWaitingTimeStats(...) |
| 125 | * |
| 126 | * Reset waiting-time statistics. |
| 127 | * |
| 128 | * Input: |
| 129 | * - inst : MCU instance. |
| 130 | * |
| 131 | * Return value : n/a |
| 132 | */ |
| 133 | void WebRtcNetEQ_ResetWaitingTimeStats(MCUInst_t *inst); |
| 134 | |
| 135 | /**************************************************************************** |
| 136 | * WebRtcNetEQ_LogWaitingTime(...) |
| 137 | * |
| 138 | * Log waiting-time to the statistics. |
| 139 | * |
| 140 | * Input: |
| 141 | * - inst : MCU instance. |
| 142 | * - waiting_time : Waiting time in "RecOut calls" (i.e., 1 call = 10 ms). |
| 143 | * |
| 144 | * Return value : n/a |
| 145 | */ |
| 146 | void WebRtcNetEQ_StoreWaitingTime(MCUInst_t *inst, int waiting_time); |
| 147 | |
| 148 | /**************************************************************************** |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 149 | * WebRtcNetEQ_ResetMcuJitterStat(...) |
| 150 | * |
| 151 | * Reset MCU-side statistics variables for the post-call statistics. |
| 152 | * |
| 153 | * Input: |
| 154 | * - inst : MCU instance |
| 155 | * |
| 156 | * Return value : 0 - Ok |
| 157 | * <0 - Error |
| 158 | */ |
| 159 | int WebRtcNetEQ_ResetMcuJitterStat(MCUInst_t *inst); |
| 160 | |
| 161 | /**************************************************************************** |
| 162 | * WebRtcNetEQ_McuAddressInit(...) |
| 163 | * |
| 164 | * Initializes MCU with read address and write address. |
| 165 | * |
| 166 | * Input: |
| 167 | * - inst : MCU instance |
| 168 | * - Data2McuAddress : Pointer to MCU address |
| 169 | * - Data2DspAddress : Pointer to DSP address |
| 170 | * - main_inst : Pointer to NetEQ main instance |
| 171 | * |
| 172 | * Return value : 0 - Ok |
| 173 | * <0 - Error |
| 174 | */ |
| 175 | int WebRtcNetEQ_McuAddressInit(MCUInst_t *inst, void * Data2McuAddress, |
| 176 | void * Data2DspAddress, void *main_inst); |
| 177 | |
| 178 | /**************************************************************************** |
| 179 | * WebRtcNetEQ_McuSetFs(...) |
| 180 | * |
| 181 | * Initializes MCU with read address and write address. |
| 182 | * |
| 183 | * Input: |
| 184 | * - inst : MCU instance |
| 185 | * - fs_hz : Sample rate in Hz -- 8000, 16000, 32000, (48000) |
| 186 | * |
| 187 | * Return value : 0 - Ok |
| 188 | * <0 - Error |
| 189 | */ |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame^] | 190 | int WebRtcNetEQ_McuSetFs(MCUInst_t *inst, uint16_t fs_hz); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 191 | |
| 192 | /**************************************************************************** |
| 193 | * WebRtcNetEQ_SignalMcu(...) |
| 194 | * |
| 195 | * Signal the MCU that data is available and ask for a RecOut decision. |
| 196 | * |
| 197 | * Input: |
| 198 | * - inst : MCU instance |
| 199 | * |
| 200 | * Return value : 0 - Ok |
| 201 | * <0 - Error |
| 202 | */ |
| 203 | int WebRtcNetEQ_SignalMcu(MCUInst_t *inst); |
| 204 | |
| 205 | /**************************************************************************** |
| 206 | * WebRtcNetEQ_RecInInternal(...) |
| 207 | * |
| 208 | * This function inserts a packet into the jitter buffer. |
| 209 | * |
| 210 | * Input: |
| 211 | * - MCU_inst : MCU instance |
| 212 | * - RTPpacket : The RTP packet, parsed into NetEQ's internal RTP struct |
| 213 | * - uw32_timeRec : Time stamp for the arrival of the packet (not RTP timestamp) |
| 214 | * |
| 215 | * Return value : 0 - Ok |
| 216 | * -1 - Error |
| 217 | */ |
| 218 | |
| 219 | int WebRtcNetEQ_RecInInternal(MCUInst_t *MCU_inst, RTPPacket_t *RTPpacket, |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame^] | 220 | uint32_t uw32_timeRec); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 221 | |
| 222 | /**************************************************************************** |
| 223 | * WebRtcNetEQ_RecInInternal(...) |
| 224 | * |
| 225 | * Split the packet according to split_inst and inserts the parts into |
| 226 | * Buffer_inst. |
| 227 | * |
| 228 | * Input: |
| 229 | * - MCU_inst : MCU instance |
| 230 | * - RTPpacket : The RTP packet, parsed into NetEQ's internal RTP struct |
| 231 | * - uw32_timeRec : Time stamp for the arrival of the packet (not RTP timestamp) |
| 232 | * |
| 233 | * Return value : 0 - Ok |
| 234 | * -1 - Error |
| 235 | */ |
| 236 | int WebRtcNetEQ_SplitAndInsertPayload(RTPPacket_t *packet, PacketBuf_t *Buffer_inst, |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame^] | 237 | SplitInfo_t *split_inst, int16_t *flushed); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 238 | |
| 239 | /**************************************************************************** |
| 240 | * WebRtcNetEQ_GetTimestampScaling(...) |
| 241 | * |
| 242 | * Update information about timestamp scaling for a payload type |
| 243 | * in MCU_inst->scalingFactor. |
| 244 | * |
| 245 | * Input: |
| 246 | * - MCU_inst : MCU instance |
| 247 | * - rtpPayloadType : RTP payload number |
| 248 | * |
| 249 | * Return value : 0 - Ok |
| 250 | * -1 - Error |
| 251 | */ |
| 252 | |
| 253 | int WebRtcNetEQ_GetTimestampScaling(MCUInst_t *MCU_inst, int rtpPayloadType); |
| 254 | |
| 255 | /**************************************************************************** |
| 256 | * WebRtcNetEQ_ScaleTimestampExternalToInternal(...) |
| 257 | * |
| 258 | * Convert from external to internal timestamp using current scaling info. |
| 259 | * |
| 260 | * Input: |
| 261 | * - MCU_inst : MCU instance |
| 262 | * - externalTS : External timestamp |
| 263 | * |
| 264 | * Return value : Internal timestamp |
| 265 | */ |
| 266 | |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame^] | 267 | uint32_t WebRtcNetEQ_ScaleTimestampExternalToInternal(const MCUInst_t *MCU_inst, |
| 268 | uint32_t externalTS); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 269 | |
| 270 | /**************************************************************************** |
| 271 | * WebRtcNetEQ_ScaleTimestampInternalToExternal(...) |
| 272 | * |
| 273 | * Convert from external to internal timestamp using current scaling info. |
| 274 | * |
| 275 | * Input: |
| 276 | * - MCU_inst : MCU instance |
| 277 | * - externalTS : Internal timestamp |
| 278 | * |
| 279 | * Return value : External timestamp |
| 280 | */ |
| 281 | |
pbos@webrtc.org | 0946a56 | 2013-04-09 00:28:06 +0000 | [diff] [blame^] | 282 | uint32_t WebRtcNetEQ_ScaleTimestampInternalToExternal(const MCUInst_t *MCU_inst, |
| 283 | uint32_t internalTS); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 284 | #endif |