// PCM2G711Transformer.cpp: implementation of the PCM2G711Transformer class.
|
//
|
//////////////////////////////////////////////////////////////////////
|
|
#include "PCM2G711Transformer.h"
|
#include "AudioSampleManager.h"
|
#include "AudioSample.h"
|
|
//////////////////////////////////////////////////////////////////////
|
// Construction/Destruction
|
//////////////////////////////////////////////////////////////////////
|
|
PCM2G711Transformer::PCM2G711Transformer()
|
{
|
char subFacilityName[100];
|
sprintf(subFacilityName, "PCM2G711Transformer:%x", this);
|
tracer.SetSubFacilityName(subFacilityName);
|
SetTraceLevel();
|
}
|
|
PCM2G711Transformer::~PCM2G711Transformer()
|
{
|
}
|
|
int
|
PCM2G711Transformer::SetTraceLevel()
|
{
|
long SystemMask = 0;
|
if ((SystemMask = GetRegKeyLong(HKEY_CURRENT_USER, "Software\\Cisco Systems\\MTC\\Tracing", "AllComponents", 0x0)) == 0)
|
{
|
SystemMask = GetRegKeyLong(HKEY_CURRENT_USER, "Software\\Cisco Systems\\MTC\\Tracing", "PCM2G711Transformer", 0x100000);
|
}
|
tracer.SetSystemMask(SystemMask);
|
return 0;
|
}
|
|
int
|
PCM2G711Transformer::SetALaw()
|
{
|
g711Codec.SetALaw();
|
return 0;
|
}
|
|
int
|
PCM2G711Transformer::SetULaw()
|
{
|
g711Codec.SetULaw();
|
return 0;
|
}
|
|
int
|
PCM2G711Transformer::TransformAudioSamples(std::vector<std::pair<AudioSample *, AudioSource *> > &data, AudioSample **ppAudioSample)
|
{
|
int result = 0;
|
AudioSample *outSample = NULL;
|
AudioSample *inSample = NULL;
|
if (data.size() > 0)
|
{
|
inSample = data[0].first;
|
}
|
|
if (inSample)
|
{
|
result = AudioSampleManager::GetInstance()->GetAudioSample(&outSample, this);
|
|
if (outSample)
|
{
|
if (g711Codec.GetCodecType() == CODECTYPE_ULAW)
|
{
|
outSample->SetFormat(WaveFormat::GetWaveFormat(WaveFormat_ULaw));
|
}
|
else
|
{
|
outSample->SetFormat(WaveFormat::GetWaveFormat(WaveFormat_ALaw));
|
}
|
|
if (inSample->DataSize() <= 0)
|
{
|
outSample->SetSilenceDuration(inSample->GetSilenceDuration());
|
}
|
else
|
{
|
int outputSize = outSample->BufferSize();
|
result = g711Codec.Encode(inSample->Data(), inSample->DataSize(), outSample->Data(), &outputSize);
|
outSample->SetDataSize(outputSize);
|
}
|
}
|
else
|
{
|
result = -10;
|
}
|
}
|
*ppAudioSample = outSample;
|
return result;
|
}
|