ghy
Alejandro Acuña
2025-03-12 26319e4c5bfbee722c15b8e7ccca9b6127bb1cb8
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
// 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;
}