summaryrefslogtreecommitdiff
path: root/service/src/com/android/telephony/imsmedia/lib/libimsmedia/core/nodes/RtpDecoderNode.cpp
blob: 66e06141cf652818b3d37da4ad88a5013db05900 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
/**
 * Copyright (C) 2022 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <RtpDecoderNode.h>
#include <ImsMediaTrace.h>
#include <ImsMediaCondition.h>
#include <AudioConfig.h>
#include <VideoConfig.h>
#include <TextConfig.h>

#if defined(DEBUG_JITTER_GEN_SIMULATION_DELAY) || defined(DEBUG_JITTER_GEN_SIMULATION_REORDER) || \
        defined(DEBUG_JITTER_GEN_SIMULATION_LOSS)
#include <ImsMediaTimer.h>
#endif
#ifdef DEBUG_JITTER_GEN_SIMULATION_DELAY
#define DEBUG_JITTER_MAX_PACKET_INTERVAL 15  // milliseconds
#endif
#ifdef DEBUG_JITTER_GEN_SIMULATION_REORDER
#include <ImsMediaDataQueue.h>
#define DEBUG_JITTER_REORDER_MAX 4
#define DEBUG_JITTER_REORDER_MIN 4
#define DEBUG_JITTER_NORMAL      2
#endif
#ifdef DEBUG_JITTER_GEN_SIMULATION_LOSS
#define DEBUG_JITTER_LOSS_PACKET_INTERVAL 20
#endif
#ifdef DEBUG_JITTER_GEN_SIMULATION_DUPLICATE
#define DEBUG_JITTER_DUPLICATE_PACKET_INTERVAL 30
#endif

RtpDecoderNode::RtpDecoderNode(BaseSessionCallback* callback) :
        BaseNode(callback)
{
    mRtpSession = nullptr;
    mReceivingSSRC = 0;
    mInactivityTime = 0;
    mNoRtpTime = 0;
    mRtpPayloadTx = 0;
    mRtpPayloadRx = 0;
    mRtpTxDtmfPayload = 0;
    mRtpRxDtmfPayload = 0;
    mDtmfSamplingRate = 0;
    mCvoValue = CVO_DEFINE_NONE;
    mRedundantPayload = 0;
    mArrivalTime = 0;
    mSubtype = MEDIASUBTYPE_UNDEFINED;
    mDtmfEndBit = false;
#if defined(DEBUG_JITTER_GEN_SIMULATION_LOSS) || defined(DEBUG_JITTER_GEN_SIMULATION_DUPLICATE)
    mPacketCounter = 1;
#endif
#ifdef DEBUG_JITTER_GEN_SIMULATION_DELAY
    mNextTime = 0;
#endif
#ifdef DEBUG_JITTER_GEN_SIMULATION_REORDER
    mReorderDataCount = 0;
#endif
}

RtpDecoderNode::~RtpDecoderNode()
{
    // remove IRtpSession here to avoid shared instance in other node from unable to use
    if (mRtpSession)
    {
        mRtpSession->StopRtp();
        mRtpSession->SetRtpDecoderListener(nullptr);
        IRtpSession::ReleaseInstance(mRtpSession);
        mRtpSession = nullptr;
    }
}

kBaseNodeId RtpDecoderNode::GetNodeId()
{
    return kNodeIdRtpDecoder;
}

ImsMediaResult RtpDecoderNode::Start()
{
    IMLOGD1("[Start] type[%d]", mMediaType);

    if (mRtpPayloadTx == 0 || mRtpPayloadRx == 0)
    {
        IMLOGE0("[Start] invalid payload number");
        return RESULT_INVALID_PARAM;
    }

    if (mRtpSession == nullptr)
    {
        mRtpSession = IRtpSession::GetInstance(mMediaType, mLocalAddress, mPeerAddress);

        if (mRtpSession == nullptr)
        {
            IMLOGE0("[Start] - Can't create rtp session");
            return RESULT_NOT_READY;
        }
    }

    if (mMediaType == IMS_MEDIA_AUDIO)
    {
        mRtpSession->SetRtpPayloadParam(mRtpPayloadTx, mRtpPayloadRx, mSamplingRate * 1000,
                mRtpTxDtmfPayload, mRtpRxDtmfPayload, mDtmfSamplingRate * 1000);
    }
    else if (mMediaType == IMS_MEDIA_VIDEO)
    {
        mRtpSession->SetRtpPayloadParam(mRtpPayloadTx, mRtpPayloadRx, mSamplingRate * 1000);
    }
    else if (mMediaType == IMS_MEDIA_TEXT)
    {
        if (mRedundantPayload > 0)
        {
            mRtpSession->SetRtpPayloadParam(mRtpPayloadTx, mRtpPayloadRx, mSamplingRate * 1000,
                    mRedundantPayload, mSamplingRate * 1000);
        }
        else
        {
            mRtpSession->SetRtpPayloadParam(mRtpPayloadTx, mRtpPayloadRx, mSamplingRate * 1000);
        }
    }

    mRtpSession->SetRtpDecoderListener(this);
    mRtpSession->StartRtp();
    mReceivingSSRC = 0;
    mNoRtpTime = 0;
    mSubtype = MEDIASUBTYPE_UNDEFINED;
    mNodeState = kNodeStateRunning;
#if defined(DEBUG_JITTER_GEN_SIMULATION_LOSS) || defined(DEBUG_JITTER_GEN_SIMULATION_DUPLICATE)
    mPacketCounter = 1;
#endif
    return RESULT_SUCCESS;
}

void RtpDecoderNode::Stop()
{
    IMLOGD1("[Stop] type[%d]", mMediaType);

    mReceivingSSRC = 0;

    if (mRtpSession)
    {
        mRtpSession->StopRtp();
    }

    mNodeState = kNodeStateStopped;
}

void RtpDecoderNode::OnDataFromFrontNode(ImsMediaSubType subtype, uint8_t* data, uint32_t datasize,
        uint32_t timestamp, bool mark, uint32_t seq, ImsMediaSubType nDataType,
        uint32_t arrivalTime)
{
    IMLOGD_PACKET8(IM_PACKET_LOG_RTP,
            "[OnDataFromFrontNode] media[%d], subtype[%d] Size[%d], TS[%d], Mark[%d], Seq[%d], "
            "datatype[%d], arrivalTime[%u]",
            mMediaType, subtype, datasize, timestamp, mark, seq, nDataType, arrivalTime);

    mArrivalTime = arrivalTime;
#ifdef DEBUG_JITTER_GEN_SIMULATION_DELAY
    {
        ImsMediaCondition condition;
        uint32_t delay = ImsMediaTimer::GenerateRandom(DEBUG_JITTER_MAX_PACKET_INTERVAL);
        mArrivalTime += delay;
        condition.wait_timeout(delay);
    }
#endif

#if defined(DEBUG_JITTER_GEN_SIMULATION_LOSS) || defined(DEBUG_JITTER_GEN_SIMULATION_DUPLICATE)
    bool flag = false;
#ifdef DEBUG_JITTER_GEN_SIMULATION_LOSS
    uint32_t seed = ImsMediaTimer::GenerateRandom(5);
    if (mPacketCounter % DEBUG_JITTER_LOSS_PACKET_INTERVAL == 0 || seed % 5 == 0)
    {
        flag = true;
    }
#endif
#ifdef DEBUG_JITTER_GEN_SIMULATION_DUPLICATE
    if ((mPacketCounter % DEBUG_JITTER_DUPLICATE_PACKET_INTERVAL) == 0)
    {
        flag = true;
    }
#endif
    mPacketCounter++;
#endif
#ifdef DEBUG_JITTER_GEN_SIMULATION_REORDER
    {
        // add data to jitter gen buffer
        DataEntry entry;
        entry.subtype = MEDIASUBTYPE_RTPPACKET;
        entry.pbBuffer = data;
        entry.nBufferSize = datasize;
        entry.nTimestamp = 0;
        entry.bMark = 0;
        entry.nSeqNum = 0;
        entry.arrivalTime = arrivalTime;

        if (mReorderDataCount < DEBUG_JITTER_NORMAL)
        {
            jitterData.Add(&entry);
        }
        else if (mReorderDataCount < DEBUG_JITTER_NORMAL + DEBUG_JITTER_REORDER_MAX)
        {
            int32_t nCurrReorderSize;
            int32_t nInsertPos;
            uint32_t nCurrJitterBufferSize;
            nCurrJitterBufferSize = jitterData.GetCount();

            if (DEBUG_JITTER_REORDER_MAX > DEBUG_JITTER_REORDER_MIN)
            {
                nCurrReorderSize = mReorderDataCount - DEBUG_JITTER_NORMAL + 1 -
                        ImsMediaTimer::GenerateRandom(
                                DEBUG_JITTER_REORDER_MAX - DEBUG_JITTER_REORDER_MIN + 1);
            }
            else
            {
                nCurrReorderSize = mReorderDataCount - DEBUG_JITTER_NORMAL + 1;
            }

            if (nCurrReorderSize > 0)
            {
                nCurrReorderSize = ImsMediaTimer::GenerateRandom(nCurrReorderSize + 1);
            }

            nInsertPos = nCurrJitterBufferSize - nCurrReorderSize;

            if (nInsertPos < 0)
            {
                nInsertPos = 0;
            }

            jitterData.InsertAt(nInsertPos, &entry);
        }

        mReorderDataCount++;

        if (mReorderDataCount >= DEBUG_JITTER_NORMAL + DEBUG_JITTER_REORDER_MAX)
        {
            mReorderDataCount = 0;
        }

        // send
        while (jitterData.GetCount() >= DEBUG_JITTER_REORDER_MAX)
        {
            DataEntry* pEntry;

            if (jitterData.Get(&pEntry))
            {
#ifdef DEBUG_JITTER_GEN_SIMULATION_LOSS
                if (flag == false)
                {
                    mRtpSession->ProcRtpPacket(pEntry->pbBuffer, pEntry->nBufferSize);
                }
#else
#ifdef DEBUG_JITTER_GEN_SIMULATION_DUPLICATE
                if (flag == true)
                {
                    mRtpSession->ProcRtpPacket(pEntry->pbBuffer, pEntry->nBufferSize);
                }
#endif
                mRtpSession->ProcRtpPacket(pEntry->pbBuffer, pEntry->nBufferSize);
#endif
                jitterData.Delete();
            }
        }
    }
#else
#ifdef DEBUG_JITTER_GEN_SIMULATION_LOSS
    if (flag == false)
    {
        mRtpSession->ProcRtpPacket(data, datasize);
    }
#else
#ifdef DEBUG_JITTER_GEN_SIMULATION_DUPLICATE
    if (flag == true)
    {
        mRtpSession->ProcRtpPacket(data, datasize);
    }
#endif
    mRtpSession->ProcRtpPacket(data, datasize);
#endif
#endif
}

bool RtpDecoderNode::IsRunTime()
{
    return true;
}

bool RtpDecoderNode::IsSourceNode()
{
    return false;
}

void RtpDecoderNode::SetConfig(void* config)
{
    IMLOGD1("[SetConfig] type[%d]", mMediaType);

    if (config == nullptr)
    {
        return;
    }

    if (mMediaType == IMS_MEDIA_AUDIO)
    {
        AudioConfig* pConfig = reinterpret_cast<AudioConfig*>(config);
        mPeerAddress = RtpAddress(pConfig->getRemoteAddress().c_str(), pConfig->getRemotePort());
        mSamplingRate = pConfig->getSamplingRateKHz();
        mRtpPayloadTx = pConfig->getTxPayloadTypeNumber();
        mRtpPayloadRx = pConfig->getRxPayloadTypeNumber();
        mRtpTxDtmfPayload = pConfig->getTxDtmfPayloadTypeNumber();
        mRtpRxDtmfPayload = pConfig->getRxDtmfPayloadTypeNumber();
        mDtmfSamplingRate = pConfig->getDtmfsamplingRateKHz();
    }
    else if (mMediaType == IMS_MEDIA_VIDEO)
    {
        VideoConfig* pConfig = reinterpret_cast<VideoConfig*>(config);
        mPeerAddress = RtpAddress(pConfig->getRemoteAddress().c_str(), pConfig->getRemotePort());
        mSamplingRate = pConfig->getSamplingRateKHz();
        mRtpPayloadTx = pConfig->getTxPayloadTypeNumber();
        mRtpPayloadRx = pConfig->getRxPayloadTypeNumber();
        mCvoValue = pConfig->getCvoValue();
    }
    else if (mMediaType == IMS_MEDIA_TEXT)
    {
        TextConfig* pConfig = reinterpret_cast<TextConfig*>(config);
        mPeerAddress = RtpAddress(pConfig->getRemoteAddress().c_str(), pConfig->getRemotePort());
        mSamplingRate = pConfig->getSamplingRateKHz();
        mRtpPayloadTx = pConfig->getTxPayloadTypeNumber();
        mRtpPayloadRx = pConfig->getRxPayloadTypeNumber();
        mRedundantPayload = pConfig->getRedundantPayload();
    }

    IMLOGD2("[SetConfig] peer Ip[%s], port[%d]", mPeerAddress.ipAddress, mPeerAddress.port);
}

bool RtpDecoderNode::IsSameConfig(void* config)
{
    if (config == nullptr)
    {
        return true;
    }

    if (mMediaType == IMS_MEDIA_AUDIO)
    {
        AudioConfig* pConfig = reinterpret_cast<AudioConfig*>(config);
        return (mPeerAddress ==
                        RtpAddress(pConfig->getRemoteAddress().c_str(), pConfig->getRemotePort()) &&
                mSamplingRate == pConfig->getSamplingRateKHz() &&
                mRtpPayloadTx == pConfig->getTxPayloadTypeNumber() &&
                mRtpPayloadRx == pConfig->getRxPayloadTypeNumber() &&
                mRtpTxDtmfPayload == pConfig->getTxDtmfPayloadTypeNumber() &&
                mRtpRxDtmfPayload == pConfig->getRxDtmfPayloadTypeNumber() &&
                mDtmfSamplingRate == pConfig->getDtmfsamplingRateKHz());
    }
    else if (mMediaType == IMS_MEDIA_VIDEO)
    {
        VideoConfig* pConfig = reinterpret_cast<VideoConfig*>(config);
        return (mPeerAddress ==
                        RtpAddress(pConfig->getRemoteAddress().c_str(), pConfig->getRemotePort()) &&
                mSamplingRate == pConfig->getSamplingRateKHz() &&
                mRtpPayloadTx == pConfig->getTxPayloadTypeNumber() &&
                mRtpPayloadRx == pConfig->getRxPayloadTypeNumber() &&
                mCvoValue == pConfig->getCvoValue());
    }
    else if (mMediaType == IMS_MEDIA_TEXT)
    {
        TextConfig* pConfig = reinterpret_cast<TextConfig*>(config);
        return (mPeerAddress ==
                        RtpAddress(pConfig->getRemoteAddress().c_str(), pConfig->getRemotePort()) &&
                mSamplingRate == pConfig->getSamplingRateKHz() &&
                mRtpPayloadTx == pConfig->getTxPayloadTypeNumber() &&
                mRtpPayloadRx == pConfig->getRxPayloadTypeNumber() &&
                mRedundantPayload == pConfig->getRedundantPayload());
    }

    return false;
}

void RtpDecoderNode::OnMediaDataInd(unsigned char* data, uint32_t datasize, uint32_t timestamp,
        bool mark, uint16_t seq, uint32_t payloadType, uint32_t ssrc, bool extension,
        uint16_t nExtensionData)
{
    IMLOGD_PACKET8(IM_PACKET_LOG_RTP,
            "[OnMediaDataInd] media[%d] size[%d], TS[%d], mark[%d], seq[%d], payloadType[%d] "
            "sampling[%d], ext[%d]",
            mMediaType, datasize, timestamp, mark, seq, payloadType, mSamplingRate, extension);

    if (mMediaType == IMS_MEDIA_AUDIO && mRtpPayloadRx != payloadType &&
            mRtpPayloadTx != payloadType && payloadType != mRtpRxDtmfPayload &&
            payloadType != mRtpTxDtmfPayload)
    {
        IMLOGE1("[OnMediaDataInd] media[%d] invalid frame", mMediaType);
        return;
    }

    // no need to change to timestamp to milliseconds unit in audio or text packet
    if (mMediaType != IMS_MEDIA_VIDEO && mSamplingRate != 0)
    {
        timestamp = timestamp / (mSamplingRate);
    }

    if (mReceivingSSRC != ssrc)
    {
        IMLOGD3("[OnMediaDataInd] media[%d] SSRC changed, [%x] -> [%x]", mMediaType, mReceivingSSRC,
                ssrc);
        mReceivingSSRC = ssrc;
        SendDataToRearNode(MEDIASUBTYPE_REFRESHED, nullptr, mReceivingSSRC, 0, 0, 0);
    }

    if (mMediaType == IMS_MEDIA_AUDIO &&
            (payloadType == mRtpRxDtmfPayload || payloadType == mRtpTxDtmfPayload) && datasize >= 4)
    {
        processDtmf(data);
        return;
    }

    if (extension && mMediaType == IMS_MEDIA_VIDEO && mCvoValue != CVO_DEFINE_NONE)
    {
        uint16_t nExtensionID;
        uint16_t nCamID;
        uint16_t nRotation;
        nExtensionID = nExtensionData;
        nExtensionID = nExtensionID >> 12;

        nCamID = nExtensionData;  // 0: Front-facing camera, 1: Back-facing camera
        nCamID = nCamID << 12;
        nCamID = nCamID >> 15;

        nRotation = nExtensionData;
        nRotation = nRotation << 13;
        nRotation = nRotation >> 13;

        switch (nRotation)
        {
            case 0:  // No rotation (Rotated 0CW/CCW = To rotate 0CW/CCW)
            case 4:  // + Horizontal Flip, but it's treated as same as above
                mSubtype = MEDIASUBTYPE_ROT0;
                break;
            case 1:  // Rotated 270CW(90CCW) = To rotate 90CW(270CCW)
            case 5:  // + Horizontal Flip, but it's treated as same as above
                mSubtype = MEDIASUBTYPE_ROT90;
                break;
            case 2:  // Rotated 180CW = To rotate 180CW
            case 6:  // + Horizontal Flip, but it's treated as same as above
                mSubtype = MEDIASUBTYPE_ROT180;
                break;
            case 3:  // Rotated 90CW(270CCW) = To rotate 270CW(90CCW)
            case 7:  // + Horizontal Flip, but it's treated as same as above
                mSubtype = MEDIASUBTYPE_ROT270;
                break;
            default:
                break;
        }

        IMLOGD4("[OnMediaDataInd] extensionId[%d], camId[%d], rot[%d], subtype[%d]", nExtensionID,
                nCamID, nRotation, mSubtype);
    }

    if (mMediaType == IMS_MEDIA_TEXT)
    {
        if (payloadType == mRtpPayloadTx)
        {
            if (mRedundantPayload == 0)
            {
                mSubtype = MEDIASUBTYPE_BITSTREAM_T140;
            }
            else
            {
                mSubtype = MEDIASUBTYPE_BITSTREAM_T140_RED;
            }
        }
        else if (payloadType == mRedundantPayload)
        {
            mSubtype = MEDIASUBTYPE_BITSTREAM_T140;
        }
        else
        {
            IMLOGI2("[OnMediaDataInd] media[%d] INVALID payload[%d] is received", mMediaType,
                    payloadType);
        }
    }

    SendDataToRearNode(
            mSubtype, data, datasize, timestamp, mark, seq, MEDIASUBTYPE_UNDEFINED, mArrivalTime);
}

void RtpDecoderNode::OnNumReceivedPacket(uint32_t nNumRtpPacket)
{
    IMLOGD_PACKET2(IM_PACKET_LOG_RTP, "[OnNumReceivedPacket] InactivityTime[%d], numRtp[%d]",
            mInactivityTime, nNumRtpPacket);

    if (nNumRtpPacket == 0)
    {
        mNoRtpTime++;
    }
    else
    {
        mNoRtpTime = 0;
    }

    if (mInactivityTime != 0 && mNoRtpTime == mInactivityTime)
    {
        if (mCallback != nullptr)
        {
            mCallback->SendEvent(kImsMediaEventMediaInactivity, kProtocolRtp, mInactivityTime);
        }
    }
}

void RtpDecoderNode::SetLocalAddress(const RtpAddress& address)
{
    mLocalAddress = address;
}

void RtpDecoderNode::SetPeerAddress(const RtpAddress& address)
{
    mPeerAddress = address;
}

void RtpDecoderNode::SetInactivityTimerSec(const uint32_t time)
{
    IMLOGD2("[SetInactivityTimerSec] media[%d], time[%d] reset", mMediaType, time);
    mInactivityTime = time;
    mNoRtpTime = 0;
}

void RtpDecoderNode::processDtmf(uint8_t* data)
{
    /** dtmf event payload format
     *  0                   1                   2                   3
     *  0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
     * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
     * |     event     |E|R| volume    |          duration             |
     * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
     */

    // check end bit and send event once per event
    if (data[1] & 0x80)
    {
        if (mDtmfEndBit)
        {
            uint8_t digit = data[0];
            int32_t duration = data[2];
            mSamplingRate != 0 ? duration = ((duration << 8) | data[3]) / mSamplingRate
                               : 0;  // convert milliseconds

            IMLOGD2("[processDtmf] dtmf received, digit[%d], duration[%d]", digit, duration);

            mCallback->SendEvent(kAudioDtmfReceivedInd, digit, duration);
            mDtmfEndBit = false;
        }
    }
    else
    {
        // mark true when the new event started
        mDtmfEndBit = true;
    }
}