Alejandro Acuña
2024-08-12 1876e65234c20209001178705cfa50d8f9ded67a
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
// G7112PCMTransformer.cpp: implementation of the G7112PCMTransformer class.
//
//////////////////////////////////////////////////////////////////////
 
#include "G7112PCMTransformer.h"
#include "AudioSampleManager.h"
#include "RTPPacket.h"
 
using namespace std;
 
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
 
G7112PCMTransformer::G7112PCMTransformer()
{
    char subFacilityName[100];
    sprintf(subFacilityName, "G7112PCMTransformer:%x", this);
    tracer.SetSubFacilityName(subFacilityName);
    SetTraceLevel();
}
 
G7112PCMTransformer::~G7112PCMTransformer()
{
}
 
int
G7112PCMTransformer::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", "G7112PCMTransformer", 0x100000);
    }
    tracer.SetSystemMask(SystemMask);
    return 0;
}
 
int
G7112PCMTransformer::SetALaw()
{
    g711Codec.SetALaw();
    return 0;
}
 
int
G7112PCMTransformer::SetULaw()
{
    g711Codec.SetULaw();
    return 0;
}
 
int
G7112PCMTransformer::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)
        {
            outSample->SetFormat(WaveFormat::GetWaveFormat(WaveFormat_PCM_16_8_1));
            
            if (inSample->RTPHeader())
            {
                outSample->SetRTPHeader((inSample->RTPHeader())->CloneHeader());
            }
 
            if (inSample->DataSize() <= 0)
            {
                outSample->SetSilenceDuration(inSample->GetSilenceDuration());
            }
            else
            {
                int outputSize = outSample->BufferSize();
                result = g711Codec.Decode(inSample->Data(), inSample->DataSize(), outSample->Data(), &outputSize);
                outSample->SetDataSize(outputSize);
            }
        }
        else
        {
            result = -10;
        }
    }
    *ppAudioSample = outSample;
    return result;
}