forked from slomkowski/mumsi
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathPjsuaCommunicator.hpp
156 lines (115 loc) · 4.28 KB
/
PjsuaCommunicator.hpp
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
#pragma once
#include "IncomingConnectionValidator.hpp"
#include "AudioFramesMixer.hpp"
#include <pjmedia.h>
#include <pjsua-lib/pjsua.h>
#include <pjsua2.hpp>
#undef isblank
#include <log4cpp/Category.hh>
#include <boost/noncopyable.hpp>
#include <string>
#include <stdexcept>
#include <climits>
#include <bits/unique_ptr.h>
// for userState enum
#include <mumlib.hpp>
#include "main.hpp"
enum dtmf_modes_t {DTMF_MODE_UNAUTH, DTMF_MODE_ROOT, DTMF_MODE_STAR};
namespace sip {
constexpr int DEFAULT_PORT = 5060;
constexpr int SAMPLING_RATE = 16000;
constexpr int MAX_CALLER_PIN_LEN = 64;
constexpr int MAX_PIN_FAILS = 2;
class Exception : public std::runtime_error {
public:
Exception(const char *title) : std::runtime_error(title) {
mesg += title;
}
Exception(std::string title) : std::runtime_error(title) {
mesg += title;
}
Exception(const char *title, pj_status_t status) : std::runtime_error(title) {
char errorMsgBuffer[500];
pj_strerror(status, errorMsgBuffer, sizeof(errorMsgBuffer));
mesg += title;
mesg += ": ";
mesg += errorMsgBuffer;
}
virtual const char *what() const throw() override {
return mesg.c_str();
}
private:
std::string mesg;
};
class _LogWriter;
class _Account;
class _Call;
class _MumlibAudioMedia;
struct call {
unsigned index;
std::unique_ptr<mixer::AudioFramesMixer> mixer;
std::unique_ptr<sip::_MumlibAudioMedia> media;
pj_caching_pool cachingPool;
std::function<void(std::string)> onStateChange;
std::function<void(int16_t *, int)> onIncomingPcmSamples;
std::function<void(int)> onMuteDeafChange;
std::function<void(mumlib::UserState field, bool val)> sendUserState;
std::function<void(mumlib::UserState field, std::string val)> sendUserStateStr;
std::function<void(mumlib::MessageType field, std::string val)> sendTextMessageStr;
std::function<void(const std::string& address)> onConnect;
std::function<void()> onDisconnect;
std::function<void()> onCallerAuth;
std::function<void()> joinAuthChannel; // DEPRECATE ?
std::function<void(std::string channelNameRegex)> joinOtherChannel;
std::function<void()> joinDefaultChannel;
};
class PjsuaCommunicator : boost::noncopyable {
public:
PjsuaCommunicator(IncomingConnectionValidator &validator, int frameTimeLength, int maxCalls);
void connect(
std::string host,
std::string user,
std::string password,
unsigned int port = DEFAULT_PORT);
virtual ~PjsuaCommunicator();
void sendPcmSamples(
int callId,
int sessionId,
int sequenceNumber,
int16_t *samples,
unsigned int length);
// config params we get from config.ini
std::string caller_pin;
std::string file_welcome;
std::string file_prompt_pin;
std::string file_entering_channel;
std::string file_announce_new_caller;
std::string file_invalid_pin;
std::string file_goodbye;
std::string file_mute_on;
std::string file_mute_off;
std::string file_menu;
int max_calls;
// TODO: move these to private?
std::string got_dtmf;
dtmf_modes_t dtmf_mode = DTMF_MODE_ROOT;
int pin_fails = 0;
pj_status_t mediaPortGetFrame(pjmedia_port *port, pjmedia_frame *frame);
pj_status_t mediaPortPutFrame(pjmedia_port *port, pjmedia_frame *frame);
call calls[MY_MAX_CALLS];
std::unordered_map<std::string, std::string> pins;
private:
log4cpp::Category &logger;
log4cpp::Category &pjsuaLogger;
std::unique_ptr<_LogWriter> logWriter;
std::unique_ptr<_Account> account;
pj::Endpoint endpoint;
IncomingConnectionValidator &uriValidator;
void registerAccount(std::string host,
std::string user,
std::string password);
friend class _Call;
friend class _Account;
friend class _MumlibAudioMedia;
};
}