Alejandro Acuña
2024-09-16 adba74e107bcda9e1cb510bc14364b02e781baef
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
#import "../CCNMediaTerm/CCNSMT/CCNSMT.tlb" no_namespace, raw_interfaces_only
 
 
#include <stdio.h>
 
 
 
 
int altavoz = 50;
int micro = 50;
int port = 6666;
BSTR direccionSOS;
char * sos;
  
 
DWORD WINAPI controladorIn (LPVOID args)
{
    HRESULT hr = CoInitialize(NULL);
    ICCNMediaTermPtr pICCNMediaTerm(__uuidof(CCNMediaTerm));
    pICCNMediaTerm->Initialize();
 
    // Call this function to inform WINRTP of the audio codec used to encode the incoming RTP stream. 
    // This function may be called before StartRX is called. (so you may need to call StopRX before making this call). 
    // If called before StartRX is called, it sets the codec for the next invocation of StartRX. 
    // If it is called while receiving audio (i.e. after StartRX) it may return an error.
    // [in] long CompressionType: The following values are supported
    //      2 : G.711 Alaw 64kbps
    //      4 : G.711 Ulaw 64kbps
    // [in] long MillisecPacketSize: Specifies the length of audio in each incoming RTP audio packets
    // [in] long EchoCancellationValue: Ignored. Put any value here. Echo cancellation is not supported in the WINRTP
    // [in] long G723BitRate: Ignored
    pICCNMediaTerm->SetAudioCodecRX(2, 20, 0, 0);
 
    // Informs the WINRTP of the UDP port number where it should listen for the incoming RTP audio stream. 
    // Note: StartAudioReceive must be called before any audio from the incoming stream is played to the speaker.
    // [in] long nUDPPortNumber: UDP port number
    pICCNMediaTerm->SetAudioReceivePort(port);
 
 
    // Sets the audio codec for the transmit stream (outgoing stream). Should be called while NOT streaming (i.e. before StartTX/after StopT
    // [in] long CompressionType: See SetAudioCodecRX
    //      2 : G.711 Alaw 64kbps
    //      4 : G.711 Ulaw 64kbps
    // [in] long MillisecPacketSize: See SetAudioCodecRX
    // [in] long PrecedenceValue: Ignored
    // [in] long SilenceSuppression: Specifies whether to do silence suppression in the transmit stream
    //  0 : Silence suppression is turned OFF
    //  1 : Silence suppression is turned ON
    // [in] unsigned short MaxFramesPerPacket: Ignored
    // [in] long G723BitRate: See SetAudioCodecRX
    pICCNMediaTerm->SetAudioCodecTX(2, 20, 0, 0, 0, 0);
    
    // Sets the destination [IP Address, UDP Port] where the send side audio stream should be transmitted. 
    // Must be called while not streaming (i.e. Before StartTX/after StopTX).
    // [in] BSTR strHostName: IP address of the destination. E.g. “171.69.12.34”
    // [in] long nUDPortNumber: UDP port number where to send the stream
    pICCNMediaTerm->SetAudioDestination(direccionSOS, 6666);
    
    // Sets up WINRTP to start the receive side. It also starts playing the received audio to the speaker. 
    // unsigned long waveoutDeviceID: specifies which audio device to use for playback/speaker. 
    // These device ID's are numbered 0 ... (# of playback devices - 1), and -1 means use the default playback device. 
    // Check out waveOutOpen() and waveOutGetDevCaps() functions in the windows API.. If you are confused, -1 actually means (unsigned long) –1.
    pICCNMediaTerm->StartRX(-1);
 
    // Starts streaming on the transmit side. This method must be called before StartPlayingFileTX is called. 
    // Calling this method starts transmitting the user’s voice
    // unsigned long waveinDeviceID: specifies which audio device to use for audio capture/recording. device ID's are numbered 0...(#of recording audio devices-1), 
    // and -1 means use default audio device for windows. Check out waveInOpen() and waveInGetDevCaps() in the windows API. If you are confused, -1 actually means (unsigned long) –1.
    pICCNMediaTerm->StartTX(-1);
 
    // Sets the speaker volume on the PC. This setting sets the WAVEOUT volume of the system (not the master volume).
    // [in] unsigned long volume: value between 0 and 100 where 0 = silence, and 100 = max volume. The scale is linear, so 50 = half volume
    pICCNMediaTerm->SetSpeakerVolume(-1, altavoz);
    
    // Sets the microphone volume. This setting changes the PC’s microphone volume or audio capture volume.
    // [in] unsigned long volume: value between 0 and 100 where 0 = silence, and 100 = max volume. The scale is linear, so 50 = half volume
    pICCNMediaTerm->SetMicrophoneVolume(-1, micro);
    
 
    //char mensaje[1024];
    //sprintf(mensaje, "%s %s %d %d %d\n",sos, direccionSOS, port, altavoz, micro);
    //MessageBox(NULL, mensaje, NULL, 0);
    //MessageBox(NULL, (LPCSTR)direccionSOS, NULL, 0);
 
    char comando[1024];
 
    while (true)
    {
        fscanf (stdin, "%s",comando);
 
        MessageBox(NULL, comando, NULL, 0);
 
 
        if (strcmp(comando, "pause") == 0)
        {
            pICCNMediaTerm->StopRX();
            pICCNMediaTerm->StopTX();
        }
        else if (strcmp(comando, "resume") == 0)
        {
            pICCNMediaTerm->StartRX(-1);
            pICCNMediaTerm->StartTX(-1);
        }
        else if (strcmp(comando, "StartRX") == 0)
        {
            pICCNMediaTerm->StartRX(-1);
        }
        else if (strcmp(comando, "StopRX") == 0)
        {
            pICCNMediaTerm->StopRX();
        }
        else if (strcmp(comando, "StartTX") == 0)
        {
            pICCNMediaTerm->StartTX(-1);
        }
        else if (strcmp(comando, "StopTX") == 0)
        {
            pICCNMediaTerm->StopTX();
        }
        else if (strcmp(comando, "SetSpeakerVolume") == 0)
        {
            fscanf (stdin, "%d",&altavoz);
            pICCNMediaTerm->SetSpeakerVolume(-1, altavoz);
        }
        else if (strcmp(comando, "SetMicrophoneVolume") == 0)
        {
            fscanf (stdin, "%d",&micro);
            pICCNMediaTerm->SetMicrophoneVolume(-1, micro);
        }
        else if ((strcmp(comando, "close") == 0) || (strcmp(comando, "stop") == 0))
        {
 
            // Desconexion
 
            pICCNMediaTerm->StopRX();
            pICCNMediaTerm->StopTX();
            pICCNMediaTerm->UnInitialize();
            pICCNMediaTerm = 0;
            CoUninitialize();
            exit(0);
        }
        else if (strcmp(comando, "GetSpeakerVolume") == 0)
        {
            fprintf(stdout, "%d\r", altavoz);
            fflush(stdout);
        }
        else if (strcmp(comando, "GetMicrophoneVolume") == 0)
        {
            fprintf(stdout, "%d\r", micro);
            fflush(stdout);
        }
 
    }
 
    return 0;
}
 
 
 
 
 
 
 
int main(int argc, char * argv[])
{
 
    //altavoz = atoi(argv[1]);
    //micro = atoi(argv[2]);
    //port = atoi(argv[3]);
    //sos = argv[4];
 
    altavoz = 50;
    micro = 50;
    port = 6666;
    sos = "172.16.11.209";
 
    #ifndef _UNICODE
        OLECHAR* oleChar = NULL;
        oleChar = (OLECHAR*)calloc(strlen(sos)+1, sizeof(OLECHAR));
        MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, sos, -1, oleChar, strlen(sos)+1);  
        direccionSOS = SysAllocString(oleChar);
        free(oleChar);
        oleChar = NULL;
    #else
        direccionSOS = SysAllocString(sos);
    #endif
 
    
    // Control
 
    DWORD threadId;
    CreateThread( NULL, 0, controladorIn, NULL, 0, &threadId);
 
    while (true)
    {
        Sleep(60000);
    }
 
 
    return 0;
}