Formatted dtmf_queue.

BUG=
R=stefan@webrtc.org

Review URL: https://webrtc-codereview.appspot.com/1398004

git-svn-id: http://webrtc.googlecode.com/svn/trunk@3982 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
phoglund@webrtc.org 2013-05-08 10:04:06 +00:00
parent 73a4d5ab12
commit 315d39866e
2 changed files with 62 additions and 79 deletions

View File

@ -8,72 +8,57 @@
* be found in the AUTHORS file in the root of the source tree.
*/
#include "dtmf_queue.h"
#include "webrtc/modules/rtp_rtcp/source/dtmf_queue.h"
#include <string.h> //memset
#include <string.h> //memset
namespace webrtc {
DTMFqueue::DTMFqueue():
_DTMFCritsect(CriticalSectionWrapper::CreateCriticalSection()),
_nextEmptyIndex(0)
{
memset(_DTMFKey,0, sizeof(_DTMFKey));
memset(_DTMFLen,0, sizeof(_DTMFLen));
memset(_DTMFLevel,0, sizeof(_DTMFLevel));
DTMFqueue::DTMFqueue()
: dtmf_critsect_(CriticalSectionWrapper::CreateCriticalSection()),
next_empty_index_(0) {
memset(dtmf_key_, 0, sizeof(dtmf_key_));
memset(dtmf_length, 0, sizeof(dtmf_length));
memset(dtmf_level_, 0, sizeof(dtmf_level_));
}
DTMFqueue::~DTMFqueue()
{
delete _DTMFCritsect;
DTMFqueue::~DTMFqueue() { delete dtmf_critsect_; }
int32_t DTMFqueue::AddDTMF(uint8_t key, uint16_t len, uint8_t level) {
CriticalSectionScoped lock(dtmf_critsect_);
if (next_empty_index_ >= DTMF_OUTBAND_MAX) {
return -1;
}
int32_t index = next_empty_index_;
dtmf_key_[index] = key;
dtmf_length[index] = len;
dtmf_level_[index] = level;
next_empty_index_++;
return 0;
}
int32_t
DTMFqueue::AddDTMF(uint8_t key, uint16_t len, uint8_t level)
{
CriticalSectionScoped lock(_DTMFCritsect);
int8_t DTMFqueue::NextDTMF(uint8_t* dtmf_key, uint16_t* len, uint8_t* level) {
CriticalSectionScoped lock(dtmf_critsect_);
if(_nextEmptyIndex >= DTMF_OUTBAND_MAX)
{
return -1;
}
int32_t index = _nextEmptyIndex;
_DTMFKey[index] = key;
_DTMFLen[index] = len;
_DTMFLevel[index] = level;
_nextEmptyIndex++;
return 0;
if (!PendingDTMF()) {
return -1;
}
*dtmf_key = dtmf_key_[0];
*len = dtmf_length[0];
*level = dtmf_level_[0];
memmove(&(dtmf_key_[0]), &(dtmf_key_[1]),
next_empty_index_ * sizeof(uint8_t));
memmove(&(dtmf_length[0]), &(dtmf_length[1]),
next_empty_index_ * sizeof(uint16_t));
memmove(&(dtmf_level_[0]), &(dtmf_level_[1]),
next_empty_index_ * sizeof(uint8_t));
next_empty_index_--;
return 0;
}
int8_t
DTMFqueue::NextDTMF(uint8_t* DTMFKey, uint16_t* len, uint8_t* level)
{
CriticalSectionScoped lock(_DTMFCritsect);
bool DTMFqueue::PendingDTMF() { return (next_empty_index_ > 0); }
if(!PendingDTMF())
{
return -1;
}
*DTMFKey=_DTMFKey[0];
*len=_DTMFLen[0];
*level=_DTMFLevel[0];
memmove(&(_DTMFKey[0]), &(_DTMFKey[1]), _nextEmptyIndex*sizeof(uint8_t));
memmove(&(_DTMFLen[0]), &(_DTMFLen[1]), _nextEmptyIndex*sizeof(uint16_t));
memmove(&(_DTMFLevel[0]), &(_DTMFLevel[1]), _nextEmptyIndex*sizeof(uint8_t));
_nextEmptyIndex--;
return 0;
}
bool
DTMFqueue::PendingDTMF()
{
return(_nextEmptyIndex>0);
}
void
DTMFqueue::ResetDTMF()
{
_nextEmptyIndex = 0;
}
} // namespace webrtc
void DTMFqueue::ResetDTMF() { next_empty_index_ = 0; }
} // namespace webrtc

View File

@ -11,30 +11,28 @@
#ifndef WEBRTC_MODULES_RTP_RTCP_SOURCE_DTMF_QUEUE_H_
#define WEBRTC_MODULES_RTP_RTCP_SOURCE_DTMF_QUEUE_H_
#include "typedefs.h"
#include "rtp_rtcp_config.h"
#include "critical_section_wrapper.h"
#include "webrtc/modules/rtp_rtcp/source/rtp_rtcp_config.h"
#include "webrtc/system_wrappers/interface/critical_section_wrapper.h"
#include "webrtc/typedefs.h"
namespace webrtc {
class DTMFqueue
{
public:
DTMFqueue();
virtual ~DTMFqueue();
class DTMFqueue {
public:
DTMFqueue();
virtual ~DTMFqueue();
int32_t AddDTMF(uint8_t DTMFKey, uint16_t len, uint8_t level);
int8_t NextDTMF(uint8_t* DTMFKey, uint16_t * len, uint8_t * level);
bool PendingDTMF();
void ResetDTMF();
int32_t AddDTMF(uint8_t dtmf_key, uint16_t len, uint8_t level);
int8_t NextDTMF(uint8_t* dtmf_key, uint16_t* len, uint8_t* level);
bool PendingDTMF();
void ResetDTMF();
private:
CriticalSectionWrapper* _DTMFCritsect;
uint8_t _nextEmptyIndex;
uint8_t _DTMFKey[DTMF_OUTBAND_MAX];
uint16_t _DTMFLen[DTMF_OUTBAND_MAX];
uint8_t _DTMFLevel[DTMF_OUTBAND_MAX];
private:
CriticalSectionWrapper* dtmf_critsect_;
uint8_t next_empty_index_;
uint8_t dtmf_key_[DTMF_OUTBAND_MAX];
uint16_t dtmf_length[DTMF_OUTBAND_MAX];
uint8_t dtmf_level_[DTMF_OUTBAND_MAX];
};
} // namespace webrtc
} // namespace webrtc
#endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_DTMF_QUEUE_H_
#endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_DTMF_QUEUE_H_