2015-11-18 00:17:25 +01:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <pjmedia.h>
|
|
|
|
|
|
|
|
#include <log4cpp/Category.hh>
|
|
|
|
#include <boost/noncopyable.hpp>
|
|
|
|
|
|
|
|
#include <mutex>
|
2015-11-18 02:16:34 +01:00
|
|
|
#include <unordered_map>
|
2015-11-18 00:17:25 +01:00
|
|
|
|
|
|
|
namespace mixer {
|
|
|
|
|
2015-11-18 02:16:34 +01:00
|
|
|
constexpr int MAX_BUFFER_LENGTH = 5000;
|
|
|
|
|
2015-11-18 00:17:25 +01:00
|
|
|
class Exception : public std::runtime_error {
|
|
|
|
public:
|
2015-11-18 02:16:34 +01:00
|
|
|
Exception(std::string title) : std::runtime_error(title) {
|
2015-11-18 00:17:25 +01:00
|
|
|
mesg += title;
|
|
|
|
}
|
|
|
|
|
2015-11-18 02:16:34 +01:00
|
|
|
Exception(std::string title, pj_status_t status) : std::runtime_error(title) {
|
2015-11-18 00:17:25 +01:00
|
|
|
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 AudioFramesMixer : boost::noncopyable {
|
|
|
|
public:
|
|
|
|
AudioFramesMixer(pj_pool_factory &poolFactory);
|
|
|
|
|
|
|
|
virtual ~AudioFramesMixer();
|
|
|
|
|
|
|
|
void addFrameToBuffer(int sessionId, int sequenceNumber, int16_t *samples, int samplesLength);
|
|
|
|
|
|
|
|
int getMixedSamples(int16_t *mixedSamples, int requestedLength);
|
|
|
|
|
2015-11-18 02:16:34 +01:00
|
|
|
void clear();
|
2015-11-18 00:17:25 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
log4cpp::Category &logger;
|
|
|
|
|
|
|
|
pj_pool_t *pool = nullptr;
|
|
|
|
|
2015-11-18 02:16:34 +01:00
|
|
|
std::unordered_map<int, pjmedia_circ_buf *> buffersMap;
|
2015-11-18 00:17:25 +01:00
|
|
|
|
|
|
|
std::mutex inBuffAccessMutex;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|