blob: c8a4cd73a2fc98da89022a524f6e4a5a975f910c [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;
niklase@google.com470e71d2011-07-07 08:21:25 +000036 inst->NetEqPlayoutMode = kPlayoutOn;
turaj@webrtc.orge46c8d32013-05-22 20:39:43 +000037 inst->av_sync = 0;
niklase@google.com470e71d2011-07-07 08:21:25 +000038
39 WebRtcNetEQ_DbReset(&inst->codec_DB_inst);
40 memset(&inst->PayloadSplit_inst, 0, sizeof(SplitInfo_t));
41
42 /* Clear the Packet buffer and the pointer to memory storage */
43 WebRtcNetEQ_PacketBufferFlush(&inst->PacketBuffer_inst);
44 inst->PacketBuffer_inst.memorySizeW16 = 0;
45 inst->PacketBuffer_inst.maxInsertPositions = 0;
46
47 /* Clear the decision and delay history */
48 memset(&inst->BufferStat_inst, 0, sizeof(BufstatsInst_t));
49#ifdef NETEQ_ATEVENT_DECODE
50 ok = WebRtcNetEQ_DtmfDecoderInit(&inst->DTMF_inst, 8000, 560);
51 if (ok != 0)
52 {
53 return ok;
54 }
55#endif
56 inst->NoOfExpandCalls = 0;
57 inst->current_Codec = -1;
58 inst->current_Payload = -1;
59
60 inst->millisecondsPerCall = 10;
61 inst->timestampsPerCall = inst->millisecondsPerCall * 8;
62 inst->fs = 8000;
63 inst->first_packet = 1;
64
65 WebRtcNetEQ_ResetMcuInCallStats(inst);
66
henrik.lundin@webrtc.orgdbba1f92011-12-20 15:45:05 +000067 WebRtcNetEQ_ResetWaitingTimeStats(inst);
68
niklase@google.com470e71d2011-07-07 08:21:25 +000069 WebRtcNetEQ_ResetMcuJitterStat(inst);
70
71 WebRtcNetEQ_ResetAutomode(&(inst->BufferStat_inst.Automode_inst),
72 inst->PacketBuffer_inst.maxInsertPositions);
73
74 return 0;
75}
76
77/*
78 * Reset MCU-side statistics variables for the in-call statistics.
79 */
80
81int WebRtcNetEQ_ResetMcuInCallStats(MCUInst_t *inst)
82{
83 inst->lostTS = 0;
84 inst->lastReportTS = 0;
85 inst->PacketBuffer_inst.discardedPackets = 0;
86
87 return 0;
88}
89
90/*
henrik.lundin@webrtc.orgdbba1f92011-12-20 15:45:05 +000091 * Reset waiting-time statistics.
92 */
93
94void WebRtcNetEQ_ResetWaitingTimeStats(MCUInst_t *inst) {
95 memset(inst->waiting_times, 0,
96 kLenWaitingTimes * sizeof(inst->waiting_times[0]));
97 inst->len_waiting_times = 0;
98 inst->next_waiting_time_index = 0;
99}
100
101/*
102 * Store waiting-time in the statistics.
103 */
104
105void WebRtcNetEQ_StoreWaitingTime(MCUInst_t *inst, int waiting_time) {
106 assert(inst->next_waiting_time_index < kLenWaitingTimes);
107 inst->waiting_times[inst->next_waiting_time_index] = waiting_time;
108 inst->next_waiting_time_index++;
109 if (inst->next_waiting_time_index >= kLenWaitingTimes) {
110 inst->next_waiting_time_index = 0;
111 }
112 if (inst->len_waiting_times < kLenWaitingTimes) {
113 inst->len_waiting_times++;
114 }
115}
116
117/*
niklase@google.com470e71d2011-07-07 08:21:25 +0000118 * Reset all MCU-side statistics variables for the post-call statistics.
119 */
120
121int WebRtcNetEQ_ResetMcuJitterStat(MCUInst_t *inst)
122{
niklase@google.com470e71d2011-07-07 08:21:25 +0000123 inst->BufferStat_inst.Automode_inst.countIAT500ms = 0;
124 inst->BufferStat_inst.Automode_inst.countIAT1000ms = 0;
125 inst->BufferStat_inst.Automode_inst.countIAT2000ms = 0;
126 inst->BufferStat_inst.Automode_inst.longestIATms = 0;
127
128 return 0;
129}
130