mumsi/PjsuaCommunicator.hpp

115 lines
2.7 KiB
C++
Raw Normal View History

2015-11-03 02:13:15 +01:00
#pragma once
2015-11-09 00:51:51 +01:00
#include "IncomingConnectionValidator.hpp"
#include "AudioFramesMixer.hpp"
#include <pjmedia.h>
#include <pjsua-lib/pjsua.h>
2015-11-07 16:32:21 +01:00
#include <pjsua2.hpp>
#undef isblank
2015-11-04 01:22:59 +01:00
#include <log4cpp/Category.hh>
#include <boost/noncopyable.hpp>
#include <string>
#include <stdexcept>
2015-11-06 02:23:48 +01:00
#include <climits>
2015-11-07 16:32:21 +01:00
#include <bits/unique_ptr.h>
2015-10-16 22:41:37 +02:00
namespace sip {
2015-10-17 22:27:37 +02:00
constexpr int DEFAULT_PORT = 5060;
2015-10-16 22:41:37 +02:00
constexpr int SAMPLING_RATE = 48000;
2015-10-16 22:41:37 +02:00
class Exception : public std::runtime_error {
public:
2015-11-04 00:53:52 +01:00
Exception(const char *title) : std::runtime_error(title) {
mesg += title;
}
Exception(std::string title) : std::runtime_error(title) {
mesg += title;
}
2015-10-16 22:41:37 +02:00
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 {
2015-10-16 22:41:37 +02:00
return mesg.c_str();
}
private:
std::string mesg;
};
2015-11-07 16:32:21 +01:00
class _LogWriter;
class _Account;
class _Call;
class _MumlibAudioMedia;
2015-10-16 22:41:37 +02:00
class PjsuaCommunicator : boost::noncopyable {
public:
PjsuaCommunicator(IncomingConnectionValidator &validator, int frameTimeLength);
2015-11-02 23:41:49 +01:00
void connect(
2015-09-29 02:26:45 +02:00
std::string host,
std::string user,
2015-10-17 22:27:37 +02:00
std::string password,
unsigned int port = DEFAULT_PORT);
virtual ~PjsuaCommunicator();
void sendPcmSamples(
int sessionId,
int sequenceNumber,
int16_t *samples,
unsigned int length);
std::function<void(int16_t *, int)> onIncomingPcmSamples;
2015-11-04 00:53:52 +01:00
std::function<void(std::string)> onStateChange;
2015-11-06 02:23:48 +01:00
pj_status_t mediaPortGetFrame(pjmedia_port *port, pjmedia_frame *frame);
pj_status_t mediaPortPutFrame(pjmedia_port *port, pjmedia_frame *frame);
private:
2015-10-16 22:41:37 +02:00
log4cpp::Category &logger;
2015-11-07 16:32:21 +01:00
log4cpp::Category &pjsuaLogger;
2015-10-16 22:41:37 +02:00
std::unique_ptr<mixer::AudioFramesMixer> mixer;
2015-11-07 16:32:21 +01:00
std::unique_ptr<_LogWriter> logWriter;
std::unique_ptr<_Account> account;
std::unique_ptr<_MumlibAudioMedia> media;
pj_caching_pool cachingPool;
2015-10-16 22:41:37 +02:00
pj::Endpoint endpoint;
2015-10-16 22:41:37 +02:00
2015-11-09 00:51:51 +01:00
IncomingConnectionValidator &uriValidator;
2015-10-16 22:41:37 +02:00
void registerAccount(std::string host,
std::string user,
std::string password);
2015-11-07 16:32:21 +01:00
friend class _Call;
friend class _Account;
friend class _MumlibAudioMedia;
};
}