blob: ddbb798af8787898ee785cd102350e0d38df79ef [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 * Reset MCU side data.
13 */
14
15#include "mcu.h"
16
henrik.lundin@webrtc.orgdbba1f92011-12-20 15:45:05 +000017#include <assert.h>
niklase@google.com470e71d2011-07-07 08:21:25 +000018#include <string.h>
19
20#include "automode.h"
21
22int WebRtcNetEQ_McuReset(MCUInst_t *inst)
23{
24
25#ifdef NETEQ_ATEVENT_DECODE
26 int ok;
27#endif
28
29 /* MCU/DSP Communication layer */
30 inst->pw16_readAddress = NULL;
31 inst->pw16_writeAddress = NULL;
32 inst->main_inst = NULL;
33 inst->one_desc = 0;
34 inst->BufferStat_inst.Automode_inst.extraDelayMs = 0;
turaj@webrtc.orge46c8d32013-05-22 20:39:43 +000035 inst->BufferStat_inst.Automode_inst.minimum_delay_ms = 0;
pwestin@webrtc.org401ef362013-08-06 21:01:36 +000036 inst->BufferStat_inst.Automode_inst.maximum_delay_ms = 10000;
niklase@google.com470e71d2011-07-07 08:21:25 +000037 inst->NetEqPlayoutMode = kPlayoutOn;
turaj@webrtc.orge46c8d32013-05-22 20:39:43 +000038 inst->av_sync = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000039
40 WebRtcNetEQ_DbReset(&inst->codec_DB_inst);
41 memset(&inst->PayloadSplit_inst, 0, sizeof(SplitInfo_t));
42
43 /* Clear the Packet buffer and the pointer to memory storage */
44 WebRtcNetEQ_PacketBufferFlush(&inst->PacketBuffer_inst);
45 inst->PacketBuffer_inst.memorySizeW16 = 0;
46 inst->PacketBuffer_inst.maxInsertPositions = 0;
47
48 /* Clear the decision and delay history */
49 memset(&inst->BufferStat_inst, 0, sizeof(BufstatsInst_t));
50#ifdef NETEQ_ATEVENT_DECODE
51 ok = WebRtcNetEQ_DtmfDecoderInit(&inst->DTMF_inst, 8000, 560);
52 if (ok != 0)
53 {
54 return ok;
55 }
56#endif
57 inst->NoOfExpandCalls = 0;
58 inst->current_Codec = -1;
59 inst->current_Payload = -1;
60
61 inst->millisecondsPerCall = 10;
62 inst->timestampsPerCall = inst->millisecondsPerCall * 8;
63 inst->fs = 8000;
64 inst->first_packet = 1;
65
66 WebRtcNetEQ_ResetMcuInCallStats(inst);
67
henrik.lundin@webrtc.orgdbba1f92011-12-20 15:45:05 +000068 WebRtcNetEQ_ResetWaitingTimeStats(inst);
69
niklase@google.com470e71d2011-07-07 08:21:25 +000070 WebRtcNetEQ_ResetMcuJitterStat(inst);
71
72 WebRtcNetEQ_ResetAutomode(&(inst->BufferStat_inst.Automode_inst),
73 inst->PacketBuffer_inst.maxInsertPositions);
74
75 return 0;
76}
77
78/*
79 * Reset MCU-side statistics variables for the in-call statistics.
80 */
81
82int WebRtcNetEQ_ResetMcuInCallStats(MCUInst_t *inst)
83{
84 inst->lostTS = 0;
85 inst->lastReportTS = 0;
86 inst->PacketBuffer_inst.discardedPackets = 0;
87
88 return 0;
89}
90
91/*
henrik.lundin@webrtc.orgdbba1f92011-12-20 15:45:05 +000092 * Reset waiting-time statistics.
93 */
94
95void WebRtcNetEQ_ResetWaitingTimeStats(MCUInst_t *inst) {
96 memset(inst->waiting_times, 0,
97 kLenWaitingTimes * sizeof(inst->waiting_times[0]));
98 inst->len_waiting_times = 0;
99 inst->next_waiting_time_index = 0;
100}
101
102/*
103 * Store waiting-time in the statistics.
104 */
105
106void WebRtcNetEQ_StoreWaitingTime(MCUInst_t *inst, int waiting_time) {
107 assert(inst->next_waiting_time_index < kLenWaitingTimes);
108 inst->waiting_times[inst->next_waiting_time_index] = waiting_time;
109 inst->next_waiting_time_index++;
110 if (inst->next_waiting_time_index >= kLenWaitingTimes) {
111 inst->next_waiting_time_index = 0;
112 }
113 if (inst->len_waiting_times < kLenWaitingTimes) {
114 inst->len_waiting_times++;
115 }
116}
117
118/*
niklase@google.com470e71d2011-07-07 08:21:25 +0000119 * Reset all MCU-side statistics variables for the post-call statistics.
120 */
121
122int WebRtcNetEQ_ResetMcuJitterStat(MCUInst_t *inst)
123{
niklase@google.com470e71d2011-07-07 08:21:25 +0000124 inst->BufferStat_inst.Automode_inst.countIAT500ms = 0;
125 inst->BufferStat_inst.Automode_inst.countIAT1000ms = 0;
126 inst->BufferStat_inst.Automode_inst.countIAT2000ms = 0;
127 inst->BufferStat_inst.Automode_inst.longestIATms = 0;
128
129 return 0;
130}
131