2011-07-07 08:21:25 +00:00
|
|
|
/*
|
2012-03-07 08:12:21 +00:00
|
|
|
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
|
2011-07-07 08:21:25 +00:00
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
*/
|
|
|
|
|
|
2013-05-21 13:52:32 +00:00
|
|
|
#include "webrtc/system_wrappers/interface/trace.h"
|
|
|
|
|
#include "webrtc/voice_engine/dtmf_inband_queue.h"
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
|
2013-05-14 08:31:39 +00:00
|
|
|
DtmfInbandQueue::DtmfInbandQueue(int32_t id):
|
2011-07-07 08:21:25 +00:00
|
|
|
_id(id),
|
|
|
|
|
_DtmfCritsect(*CriticalSectionWrapper::CreateCriticalSection()),
|
|
|
|
|
_nextEmptyIndex(0)
|
|
|
|
|
{
|
|
|
|
|
memset(_DtmfKey,0, sizeof(_DtmfKey));
|
|
|
|
|
memset(_DtmfLen,0, sizeof(_DtmfLen));
|
|
|
|
|
memset(_DtmfLevel,0, sizeof(_DtmfLevel));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DtmfInbandQueue::~DtmfInbandQueue()
|
|
|
|
|
{
|
|
|
|
|
delete &_DtmfCritsect;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
2013-04-09 10:09:10 +00:00
|
|
|
DtmfInbandQueue::AddDtmf(uint8_t key, uint16_t len, uint8_t level)
|
2011-07-07 08:21:25 +00:00
|
|
|
{
|
2012-03-07 08:12:21 +00:00
|
|
|
CriticalSectionScoped lock(&_DtmfCritsect);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
if (_nextEmptyIndex >= kDtmfInbandMax)
|
|
|
|
|
{
|
|
|
|
|
WEBRTC_TRACE(kTraceWarning, kTraceVoice, VoEId(_id,-1),
|
|
|
|
|
"DtmfInbandQueue::AddDtmf() unable to add Dtmf tone");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
2013-04-09 10:09:10 +00:00
|
|
|
int32_t index = _nextEmptyIndex;
|
2011-07-07 08:21:25 +00:00
|
|
|
_DtmfKey[index] = key;
|
|
|
|
|
_DtmfLen[index] = len;
|
|
|
|
|
_DtmfLevel[index] = level;
|
|
|
|
|
_nextEmptyIndex++;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-09 10:09:10 +00:00
|
|
|
int8_t
|
|
|
|
|
DtmfInbandQueue::NextDtmf(uint16_t* len, uint8_t* level)
|
2011-07-07 08:21:25 +00:00
|
|
|
{
|
2012-03-07 08:12:21 +00:00
|
|
|
CriticalSectionScoped lock(&_DtmfCritsect);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
if(!PendingDtmf())
|
|
|
|
|
{
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
2013-04-09 10:09:10 +00:00
|
|
|
int8_t nextDtmf = _DtmfKey[0];
|
2011-07-07 08:21:25 +00:00
|
|
|
*len=_DtmfLen[0];
|
|
|
|
|
*level=_DtmfLevel[0];
|
|
|
|
|
|
|
|
|
|
memmove(&(_DtmfKey[0]), &(_DtmfKey[1]),
|
2013-04-09 10:09:10 +00:00
|
|
|
_nextEmptyIndex*sizeof(uint8_t));
|
2011-07-07 08:21:25 +00:00
|
|
|
memmove(&(_DtmfLen[0]), &(_DtmfLen[1]),
|
2013-04-09 10:09:10 +00:00
|
|
|
_nextEmptyIndex*sizeof(uint16_t));
|
2011-07-07 08:21:25 +00:00
|
|
|
memmove(&(_DtmfLevel[0]), &(_DtmfLevel[1]),
|
2013-04-09 10:09:10 +00:00
|
|
|
_nextEmptyIndex*sizeof(uint8_t));
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
_nextEmptyIndex--;
|
|
|
|
|
return nextDtmf;
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-18 10:32:33 +00:00
|
|
|
bool
|
2011-07-07 08:21:25 +00:00
|
|
|
DtmfInbandQueue::PendingDtmf()
|
|
|
|
|
{
|
2014-03-18 10:32:33 +00:00
|
|
|
CriticalSectionScoped lock(&_DtmfCritsect);
|
|
|
|
|
return _nextEmptyIndex > 0;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2014-03-18 10:32:33 +00:00
|
|
|
void
|
2011-07-07 08:21:25 +00:00
|
|
|
DtmfInbandQueue::ResetDtmf()
|
|
|
|
|
{
|
2014-03-18 10:32:33 +00:00
|
|
|
CriticalSectionScoped lock(&_DtmfCritsect);
|
2011-07-07 08:21:25 +00:00
|
|
|
_nextEmptyIndex = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace webrtc
|