-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathaudiosession.cpp
118 lines (94 loc) · 2.65 KB
/
audiosession.cpp
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
/**
* \file audiosession.cpp
*/
#include <mipconfig.h>
#if (defined(MIPCONFIG_SUPPORT_WINMM) || defined(MIPCONFIG_SUPPORT_OSS) || defined(MIPCONFIG_SUPPORT_PORTAUDIO) )
#include <mipavcodecencoder.h>
#include <mipaudiosession.h>
#include <mippainputoutput.h>
#include <iostream>
#include <jrtplib3/rtpipv4address.h>
using namespace jrtplib;
void checkRet(bool ret,const MIPErrorBase &obj)
{
if (!ret)
{
std::cerr << obj.getErrorString() << std::endl;
exit(-1);
}
}
class MyAudioSession : public MIPAudioSession
{
protected:
void onInputThreadExit(bool err, const std::string &compName, const std::string &errStr)
{
if (err)
{
std::cerr << "Input chain thread exited due to an error" << std::endl;
std::cerr << "Component: " << compName << std::endl;
std::cerr << "Error: " << errStr << std::endl;
}
}
void onOutputThreadExit(bool err, const std::string &compName, const std::string &errStr)
{
if (err)
{
std::cerr << "Output chain thread exited due to an error" << std::endl;
std::cerr << "Component: " << compName << std::endl;
std::cerr << "Error: " << errStr << std::endl;
}
}
};
int main(void)
{
#ifdef WIN32
WSADATA dat;
WSAStartup(MAKEWORD(2,2),&dat);
#endif // WIN32
#ifdef MIPCONFIG_SUPPORT_PORTAUDIO
std::string errStr;
if (!MIPPAInputOutput::initializePortAudio(errStr))
{
std::cerr << "Can't initialize PortAudio: " << errStr << std::endl;
return -1;
}
#endif // MIPCONFIG_SUPPORT_PORTAUDIO
MIPAudioSessionParams Aparams;
MyAudioSession audioSess;
bool ret;
int audioPort = 6000;
Aparams.setPortbase(audioPort);
// Aparams.setCompressionType(MIPAudioSessionParams::Speex);
// Aparams.setAcceptOwnPackets(true);
// Aparams.setInputDevice("/dev/dsp1");
// Aparams.setOutputDevice("/dev/dsp");
// Aparams.setSpeexEncoding(MIPAudioSessionParams::UltraWideBand);
// Aparams.setSpeexOutgoingPayloadType(97);
Aparams.setSpeexIncomingPayloadType(97);
Aparams.setOpusIncomingPayloadType(98);
std::cout << "Starting audio session at portbase " << audioPort << std::endl;
ret = audioSess.init(&Aparams);
checkRet(ret, audioSess);
uint8_t ipLocal[4] = { 127, 0, 0, 1 };
ret = audioSess.addDestination(RTPIPv4Address(ipLocal, audioPort));
std::string dummy;
std::cout << "Type something to exit" << std::endl;
std::cin >> dummy;
std::cout << "Exiting..." << std::endl;
audioSess.destroy();
#ifdef MIPCONFIG_SUPPORT_PORTAUDIO
MIPPAInputOutput::terminatePortAudio();
#endif // MIPCONFIG_SUPPORT_PORTAUDIO
#ifdef WIN32
WSACleanup();
#endif // WIN32
return 0;
}
#else
#include <iostream>
int main(void)
{
std::cerr << "Not all necessary components are available to run this example." << std::endl;
return 0;
}
#endif