change init format

This commit is contained in:
wangjiyu 2025-04-09 14:49:22 +08:00
parent 338be05383
commit d16c76f693
6 changed files with 189 additions and 269 deletions

View File

@ -2,9 +2,9 @@
#include "../util/RTCContext.h"
using namespace drogon;
int doSend(void* pdata, int32_t sampleRate, uint64_t channelNum, uint64_t dataLen)
int doSend(const int16_t destChannelIndex, void* pdata, int32_t sampleRate, uint64_t channelNum, uint64_t dataLen)
{
int16_t retSend = RTCContext::instance().sendCustomAudioData(RTCContext::instance().destChannelIndex,
int16_t retSend = RTCContext::instance().sendCustomAudioData(destChannelIndex,
pdata, sampleRate, channelNum, dataLen);
if (0!= retSend)
{
@ -19,21 +19,23 @@ int doSend(void* pdata, int32_t sampleRate, uint64_t channelNum, uint64_t dataLe
}
int main()
{
mrtc::IMRTCEngine *rtcEngine = RTCContext::instance().getRtcEngine();
if (!rtcEngine)
{
LOG_DEBUG << "RTCContext::instance().getRtcEngine() failed";
const char* srcUserId = "srcUser1";
const char* destUserId = "destUser1";
const char* srcDisplayName = "srcDisplayName1";
const char* destDisplayName = "destDisplayName1";
const char* srcRoomId = "srcRoom1";
const char* destRoomId = "destRoomId1";
const int16_t srcChannelIndex = 42;
const int16_t destChannelIndex = 43;
if (!RTCContext::instance().init(srcUserId, srcDisplayName, srcRoomId)) {
LOG_DEBUG << "RTCContext init failed";
return -1;
}
int32_t nCount = 0;
if (0 != rtcEngine->getUserCount(nCount))
{
LOG_DEBUG << "RTCContext::instance().getUserCount() failed";
if (!RTCContext::instance().initSend(destRoomId, destChannelIndex)) {
LOG_DEBUG << "RTCContext initSend failed";
return -1;
}
LOG_DEBUG << "nCount: " << nCount;
app().registerHandler(
"/",
[](const HttpRequestPtr &,
@ -69,7 +71,7 @@ int main()
resp->setBody(
"The server has calculated the file's MD5 hash to be " + md5);
//file.save();
doSend((void*)file.fileData(), sampleRate, channelNum, dataLen);
doSend(destChannelIndex, (void*)file.fileData(), sampleRate, channelNum, dataLen);
LOG_INFO << "The uploaded file has been send to RTC";
callback(resp);
},

View File

@ -8,131 +8,29 @@ using namespace drogon;
int main()
{
LOG_DEBUG << "+++++++++++++++++++++++++++++++++++++++++++++++++++++++";
const char* srcUserId = "srcUser1";
const char* destUserId = "destUser1";
mrtc::IMRTCEngine *rtcEngine = RTCContext::instance().getRtcEngine();
if (!rtcEngine)
{
LOG_DEBUG << "RTCContext::instance().getRtcEngine() failed";
const char* srcDisplayName = "srcDisplayName1";
const char* destDisplayName = "destDisplayName1";
const char* srcRoomId = "srcRoom1";
const char* destRoomId = "destRoomId1";
const int16_t srcChannelIndex = 42;
const int16_t destChannelIndex = 43;
if (!RTCContext::instance().init(destUserId, destDisplayName, destRoomId)) {
LOG_DEBUG << "RTCContext init failed";
return -1;
}
if (!RTCContext::instance().initRecv(destRoomId, srcUserId, destChannelIndex)) {
LOG_DEBUG << "RTCContext initRecv failed";
return -1;
}
/*
int32_t nCount = 0;
if (0 != rtcEngine->getUserCount(nCount))
{
LOG_DEBUG << "RTCContext::instance().getUserCount() failed";
return -1;
}
LOG_DEBUG << "nCount: " << nCount;
*/
app().getLoop()->loop();
app().setLogLevel(trantor::Logger::kDebug);
app().run();
LOG_INFO << "bye!";
/*
do
{
sleep(1);
} while (1);
*/
return 0;
/*
RTCImpl impl;
mrtc::IMRTCEngineFactory * rtcFactory = mrtc::getMRTCEngineFactory();
mrtc::IMRTCEngine *rtcEngine = rtcFactory->produceMRTCEngine();
mrtc::MRTCEngineConfig engineConfig;
strcpy(engineConfig.domain, "localhost");
strcpy(engineConfig.applicationId, "appid");
strcpy(engineConfig.appSecrectKey, "appsecret");
engineConfig.port = 34443;
rtcEngine->init(engineConfig, impl);
const char* userId = "user";
const char* displayName = "displayName";
const char* inRoomId = "inRoomId";
const char* outRoomId = "outRoomId";
const int16_t channelIndex = 40;
rtcEngine->setUserInfo(userId, displayName, inRoomId);
rtcEngine->registerListener(mrtc::MRTCListenerType::TYPE_LISTENER_ROOM, impl);
rtcEngine->registerListener(mrtc::MRTCListenerType::TYPE_LISTENER_CONSUMER, impl);
rtcEngine->registerSoundLevelListener(mrtc::TYPE_AUDIO_SOURCE_MIC, inRoomId, userId, channelIndex, impl);
//rtcEngine->muteAudio(inRoomId, userId, mrtc::MRTCAudioSourceType::TYPE_AUDIO_SOURCE_MIC, false, channelIndex);
mrtc::MRTCAudioOption option;
option.channelIndex = channelIndex;
strcpy(option.dstRoomId, outRoomId);
rtcEngine->joinMultiRoom(outRoomId);
rtcEngine->startCustomAudio(option);
rtcEngine->sendCustomAudioData(channelIndex, "");
rtcEngine->stopCustomAudio();
*/
// `registerHandler()` adds a handler to the desired path. The handler is
// responsible for generating a HTTP response upon an HTTP request being
// sent to Drogon
/*
app().registerHandler(
"/",
[](const HttpRequestPtr &,
std::function<void(const HttpResponsePtr &)> &&callback) {
auto resp = HttpResponse::newHttpResponse();
resp->setBody("Hello, World!");
callback(resp);
},
{Get});
// `registerHandler()` also supports parsing and passing the path as
// parameters to the handler. Parameters are specified using {}. The text
// inside the {} does not correspond to the index of parameter passed to the
// handler (nor it has any meaning). Instead, it is only to make it easier
// for users to recognize the function of each parameter.
app().registerHandler(
"/user/{user-name}",
[](const HttpRequestPtr &,
std::function<void(const HttpResponsePtr &)> &&callback,
const std::string &name) {
auto resp = HttpResponse::newHttpResponse();
resp->setBody("Hello, " + name + "!");
callback(resp);
},
{Get});
// You can also specify that the parameter is in the query section of the
// URL!
app().registerHandler(
"/hello?user={user-name}",
[](const HttpRequestPtr &,
std::function<void(const HttpResponsePtr &)> &&callback,
const std::string &name) {
auto resp = HttpResponse::newHttpResponse();
resp->setBody("Hello, " + name + "!");
callback(resp);
},
{Get});
// Or, if you want to, instead of asking drogon to parse it for you. You can
// parse the request yourselves.
app().registerHandler(
"/hello_user",
[](const HttpRequestPtr &req,
std::function<void(const HttpResponsePtr &)> &&callback) {
auto resp = HttpResponse::newHttpResponse();
auto name = req->getOptionalParameter<std::string>("user");
if (!name)
resp->setBody("Please tell me your name");
else
resp->setBody("Hello, " + name.value() + "!");
callback(resp);
},
{Get});
// Ask Drogon to listen on 127.0.0.1 port 8848. Drogon supports listening
// on multiple IP addresses by adding multiple listeners. For example, if
// you want the server also listen on 127.0.0.1 port 5555. Just add another
// line of addListener("127.0.0.1", 5555)
LOG_INFO << "Server running on 127.0.0.1:8848";
app().addListener("127.0.0.1", 8848).run();
*/
}

View File

@ -7,27 +7,26 @@ using namespace drogon;
int main()
{
LOG_DEBUG << "+++++++++++++++++++++++++++++++++++++++++++++++++++++++";
const char* srcUserId = "srcUser1";
const char* destUserId = "destUser1";
mrtc::IMRTCEngine *rtcEngine = RTCContext::instance().getRtcEngine();
if (!rtcEngine)
{
LOG_DEBUG << "RTCContext::instance().getRtcEngine() failed";
const char* srcDisplayName = "srcDisplayName1";
const char* destDisplayName = "destDisplayName1";
const char* srcRoomId = "srcRoom1";
const char* destRoomId = "destRoomId1";
const int16_t srcChannelIndex = 42;
const int16_t destChannelIndex = 43;
if (!RTCContext::instance().init(srcUserId, srcDisplayName, srcRoomId)) {
LOG_DEBUG << "RTCContext init failed";
return -1;
}
/*
int32_t nCount = 0;
if (0 != rtcEngine->getUserCount(nCount))
{
LOG_DEBUG << "RTCContext::instance().getUserCount() failed";
if (!RTCContext::instance().initSend(destRoomId, destChannelIndex)) {
LOG_DEBUG << "RTCContext initSend failed";
return -1;
}
LOG_DEBUG << "nCount: " << nCount;
*/
do
{
int16_t retSend = RTCContext::instance().sendCustomAudioData(RTCContext::instance().destChannelIndex,
int16_t retSend = RTCContext::instance().sendCustomAudioData(destChannelIndex,
(void*)"aaaaaaaaaaaaaaaaaa", 48000, 1, 10);
if (0!= retSend)
{

View File

@ -9,16 +9,16 @@ void RTCContext::onRoom(uint32_t typeId, RTCENGINE_NAMESPACE::MRTCRoomInfo& room
//LOG_DEBUG << "RTCContext::onRoom():" << roomInfo.roomId << "," << roomInfo.displayName << "," << roomInfo.userId << "," << roomInfo.message;
LOG_DEBUG << "RTCContext::onRoom()";
std::lock_guard<std::mutex> lock(mutex_);
isOnRoom = true;
isOnRoom_ = true;
}
void RTCContext::onConsumer(uint32_t msgId, const char* roomId, const char* peerId, RTCENGINE_NAMESPACE::MRTCConsumerInfo& consumerInfo) {
LOG_DEBUG << "RTCContext::onConsumer():" << consumerInfo.roomId << "," << consumerInfo.displayName << "," << consumerInfo.channelIndex;
std::lock_guard<std::mutex> lock(mutex_);
isOnConsumer = true;
isOnConsumer_ = true;
//LOG_DEBUG << "RTCContext::onConsumer()";
}
void RTCContext::onRender(const char* roomId, const char* peerId,
RTCENGINE_NAMESPACE::MRTCVideoSourceType sourceType, const RTCENGINE_NAMESPACE::MRTCVideoFrame& videoFrame) {
RTCENGINE_NAMESPACE::MRTCVideoSourceType sourceType, const RTCENGINE_NAMESPACE::MRTCVideoFrame& videoFrame) {
LOG_DEBUG << "RTCContext::onRender()";
}
void RTCContext::onCallBackMessage(uint32_t msgId, const char* msg) {
@ -26,7 +26,7 @@ void RTCContext::onCallBackMessage(uint32_t msgId, const char* msg) {
std::lock_guard<std::mutex> lock(mutex_);
if (msgId == (uint32_t)mrtc::JOIN_MULTI_ROOM_SUCCESS) {
LOG_DEBUG << "receive join multi room callback" << msgId;
isJoinMultiRoom = true;
isJoinMultiRoom_ = true;
}
LOG_DEBUG << "RTCContext::onCallBackMessage(), msgId:" << msgId << ", msg:" << msg;
@ -38,33 +38,33 @@ void RTCContext::onCallBackCustomData(RTCENGINE_NAMESPACE::MRTCCustomDataObject
}
void RTCContext::onSoundLevelUpdate(const char* roomId, const char* peerId, uint16_t audioSourceType,
uint8_t channelIndex, uint16_t volume, int32_t vad)
{
LOG_DEBUG << "RTCContext::onSoundLevelUpdate()";
}
{
LOG_DEBUG << "RTCContext::onSoundLevelUpdate()";
}
void RTCContext::onAudioProcess(const char* roomId, const char* peerId,
mrtc::MRTCAudioFrame& audioFrame, mrtc::MRTCAudioSourceType audioSourceType)
{
LOG_DEBUG << "-----------------------------------";
LOG_DEBUG << "dataCount:" << audioFrame.dataCount << audioSourceType;
//sendAudioData(audioFrame.channelIndex, audioFrame.data, audioFrame.sampleRate, audioFrame.numChannels,
// audioFrame.dataCount);
}
mrtc::MRTCAudioFrame& audioFrame, mrtc::MRTCAudioSourceType audioSourceType)
{
LOG_DEBUG << "-----------------------------------";
LOG_DEBUG << "dataCount:" << audioFrame.dataCount << audioSourceType;
//sendAudioData(audioFrame.channelIndex, audioFrame.data, audioFrame.sampleRate, audioFrame.numChannels,
// audioFrame.dataCount);
}
void RTCContext::onProducer(uint32_t msgId, mrtc::MRTCProducerInfo& info)
{
LOG_DEBUG << "-----------------------------------";
LOG_DEBUG << "RTCContext::onProducer()";
LOG_DEBUG << "-----------------------------------";
LOG_DEBUG << "RTCContext::onProducer()";
}
bool RTCContext::init()
{
bool RTCContext::init(const char* selfUserId, const char* selfDisplayName, const char* selfRoomId)
{
mrtc::IMRTCEngineFactory * rtcFactory = mrtc::getMRTCEngineFactory();
if (!rtcFactory)
{
return false;
return false;
}
rtcEngine_ = rtcFactory->produceMRTCEngine();
if (!rtcEngine_)
{
return false;
return false;
}
mrtc::MRTCEngineConfig engineConfig;
strcpy(engineConfig.domain, domain);
@ -76,6 +76,7 @@ bool RTCContext::init()
LOG_DEBUG << "RTCContext::instance().init() failed";
return false;
}
/*
#ifdef SEND_MODE
if (0 != rtcEngine_->setUserInfo(srcUserId, srcDisplayName, srcRoomId))
#else
@ -85,7 +86,13 @@ bool RTCContext::init()
LOG_DEBUG << "RTCContext::instance().setUserInfo() failed";
return false;
}
*/
if (0 != rtcEngine_->setUserInfo(selfUserId, selfDisplayName, selfRoomId))
{
LOG_DEBUG << "RTCContext::instance().setUserInfo() failed";
return false;
}
mrtc::MRTCJoinAuthority authority;
strcpy(authority.applicationId, appid);
strcpy(authority.appSecretKey, appSecrectKey);
@ -107,17 +114,17 @@ bool RTCContext::init()
}
return true;
}
bool RTCContext::initRecv()
{
while (!isOnConsumer)
}
bool RTCContext::initRecv(const char* destRoomId, const char* srcUserId, const int16_t destChannelIndex)
{
while (!isOnConsumer_)
{
LOG_DEBUG << "wait for OnConsumer";
sleep(3);
}
LOG_DEBUG << "registerSoundLevelListener";
int16_t ret1 = rtcEngine_->registerSoundLevelListener(mrtc::TYPE_AUDIO_SOURCE_CUSTOM, destRoomId,
srcUserId, destChannelIndex, this);
srcUserId, destChannelIndex, this);
if (0 != ret1)
{
LOG_DEBUG << "RTCContext::instance().registerSoundLevelListener() inUser failed, ret:" << ret1;
@ -133,10 +140,10 @@ bool RTCContext::init()
LOG_DEBUG << "init recv succ";
return true;
}
bool RTCContext::initSend()
{
while (!isOnRoom)
}
bool RTCContext::initSend(const char* destRoomId, const int16_t destChannelIndex)
{
while (!isOnRoom_)
{
LOG_DEBUG << "wait for OnRoom";
sleep(3);
@ -156,48 +163,48 @@ bool RTCContext::init()
int16_t ret2 = rtcEngine_->startCustomAudio(option);
if (ret2 != 0)
{
LOG_DEBUG << "startCustomAudio fail, ret:" << ret2;
return false;
LOG_DEBUG << "startCustomAudio fail, ret:" << ret2;
return false;
}
LOG_DEBUG << "init send succ";
return true;
}
}
void RTCContext::destorySend()
{
rtcEngine_->stopCustomAudio(destChannelIndex);
}
int16_t RTCContext::sendAudioData(uint8_t channelIndex, const void* pData, int32_t nSampleRate, uint64_t nNumberOfChannels, uint64_t dataLength)
{
void RTCContext::destorySend(const int16_t selfChannelIndex)
{
rtcEngine_->stopCustomAudio(selfChannelIndex);
}
int16_t RTCContext::sendAudioData(uint8_t channelIndex, const void* pData, int32_t nSampleRate, uint64_t nNumberOfChannels, uint64_t dataLength)
{
std::lock_guard<std::mutex> lock(mutex_);
if (pData_)
{
return rtcEngine_->sendCustomAudioData(channelIndex, pData, nSampleRate, nNumberOfChannels, dataLength);
return rtcEngine_->sendCustomAudioData(channelIndex, pData, nSampleRate, nNumberOfChannels, dataLength);
}
return 0;
}
int16_t RTCContext::sendCustomAudioData(const int16_t channelIndex, void* customData, int32_t sampleRate,
uint64_t channelNum, uint64_t dataLen)
{
while(!isOnRoom || !isJoinMultiRoom) {
}
int16_t RTCContext::sendCustomAudioData(const int16_t channelIndex, void* customData, int32_t sampleRate,
uint64_t channelNum, uint64_t dataLen)
{
while(!isOnRoom_ || !isJoinMultiRoom_) {
LOG_DEBUG << "wait for room and multi room before send";
sleep(3);
}
std::lock_guard<std::mutex> lock(mutex_);
return rtcEngine_->sendCustomAudioData(channelIndex, customData, sampleRate, channelNum, dataLen);
}
mrtc::IMRTCEngine* RTCContext::getRtcEngine() const
{
}
std::lock_guard<std::mutex> lock(mutex_);
return rtcEngine_->sendCustomAudioData(channelIndex, customData, sampleRate, channelNum, dataLen);
}
mrtc::IMRTCEngine* RTCContext::getRtcEngine() const
{
std::lock_guard<std::mutex> lock(mutex_);
return rtcEngine_;
}
void* RTCContext::getpData() const
{
}
void* RTCContext::getpData() const
{
std::lock_guard<std::mutex> lock(mutex_);
return pData_;
}
void RTCContext::setpData(void* pData)
{
}
void RTCContext::setpData(void* pData)
{
std::lock_guard<std::mutex> lock(mutex_);
pData_ = pData;
}
}

View File

@ -9,72 +9,76 @@ namespace fs = std::filesystem;
//#define SEND_MODE
class RTCContext :
public RTCENGINE_NAMESPACE::IMRTCRoomCallBack,
public RTCENGINE_NAMESPACE::IMRTCConsumerCallBack,
public RTCENGINE_NAMESPACE::IMRTCVideoRenderCallBack,
public RTCENGINE_NAMESPACE::IMRTCMessageCallBack,
public RTCENGINE_NAMESPACE::IMRTCReceivedAudioInfoCallBack,
public RTCENGINE_NAMESPACE::IMRTCProduerCallBack
public RTCENGINE_NAMESPACE::IMRTCRoomCallBack,
public RTCENGINE_NAMESPACE::IMRTCConsumerCallBack,
public RTCENGINE_NAMESPACE::IMRTCVideoRenderCallBack,
public RTCENGINE_NAMESPACE::IMRTCMessageCallBack,
public RTCENGINE_NAMESPACE::IMRTCReceivedAudioInfoCallBack,
public RTCENGINE_NAMESPACE::IMRTCProduerCallBack
{
public:
#ifdef ENV_PRODUCT
const char* appid = "1357389261426393088";
const char* appSecrectKey = "gytr3qrrznsgac2lbdchfg0l4ltqx4x3nf4my0yt1dbx7riz1gnnsnhblrlc2j4o1lx4vdu495lifv8s7jyrmfxtq9lif9rusxnur5smdn5cjopstxp5dim7p52xrezp";
const char* domain = "rtc.migu.cn";
const unsigned short port = 34443;
const char* appid = "1357389261426393088";
const char* appSecrectKey = "gytr3qrrznsgac2lbdchfg0l4ltqx4x3nf4my0yt1dbx7riz1gnnsnhblrlc2j4o1lx4vdu495lifv8s7jyrmfxtq9lif9rusxnur5smdn5cjopstxp5dim7p52xrezp";
const char* domain = "rtc.migu.cn";
const unsigned short port = 34443;
#else
const char* appid = "1357413779192676352";
const char* appid = "1357413779192676352";
const char* appSecrectKey = "q04ex8bivag3mn8ncf504t5lw4asldbc1k2rfbhoy54u7lsqqkmkzp33x0h4d9ww9z3f1deiel34m191lj4k5dc7utidom9s1izg88jhouv1bwy62q372ly9dmd63g4u";
const char* domain = "dorytest.migu.cn";
const unsigned short port = 34443;
#endif
const char* srcUserId = "srcUser1";
const char* destUserId = "destUser1";
/*
const char* srcUserId = "srcUser1";
const char* destUserId = "destUser1";
const char* srcDisplayName = "srcDisplayName1";
const char* destDisplayName = "destDisplayName1";
const char* srcRoomId = "srcRoom1";
const char* destRoomId = "destRoomId1";
const int16_t srcChannelIndex = 42;
const int16_t destChannelIndex = 43;
bool isOnRoom = false;
bool isOnConsumer = false;
bool isJoinMultiRoom = false;
const char* srcDisplayName = "srcDisplayName1";
const char* destDisplayName = "destDisplayName1";
const char* srcRoomId = "srcRoom1";
const char* destRoomId = "destRoomId1";
const int16_t srcChannelIndex = 42;
const int16_t destChannelIndex = 43;
*/
static RTCContext& instance()
{
static RTCContext instance;
return instance;
}
RTCContext(const RTCContext&) = delete;
RTCContext& operator=(const RTCContext&) = delete;
mrtc::IMRTCEngine* getRtcEngine() const;
bool init();
bool initRecv();
bool initSend();
static RTCContext& instance()
{
static RTCContext instance;
return instance;
}
RTCContext(const RTCContext&) = delete;
RTCContext& operator=(const RTCContext&) = delete;
mrtc::IMRTCEngine* getRtcEngine() const;
bool init(const char* selfUserId, const char* selfDisplayName, const char* selfRoomId);
bool initRecv(const char* destRoomId, const char* srcUserId, const int16_t destChannelIndex);
bool initSend(const char* destRoomId, const int16_t destChannelIndex);
void* getpData() const;
void setpData(void* pData);
void* getpData() const;
void setpData(void* pData);
int16_t sendAudioData(uint8_t channelIndex = 0, const void* pData = nullptr, int32_t nSampleRate = 48000, uint64_t nNumberOfChannels = 2, uint64_t dataLength = 0);
int16_t sendCustomAudioData(const int16_t channelIndex, void* customData, int32_t sampleRate,
uint64_t channelNum, uint64_t dataLen);
void destorySend();
int16_t sendAudioData(uint8_t channelIndex = 0, const void* pData = nullptr, int32_t nSampleRate = 48000, uint64_t nNumberOfChannels = 2, uint64_t dataLength = 0);
int16_t sendCustomAudioData(const int16_t channelIndex, void* customData, int32_t sampleRate,
uint64_t channelNum, uint64_t dataLen);
void destorySend(const int16_t selfChannelIndex);
private:
RTCContext()
{
init();
RTCContext()
{
/*
init();
#ifdef SEND_MODE
initSend();
initSend();
#else
initRecv();
initRecv();
#endif
}
mutable std::mutex mutex_;
mrtc::IMRTCEngine * rtcEngine_ = nullptr;
void* pData_ = nullptr;
*/
}
mutable std::mutex mutex_;
mrtc::IMRTCEngine * rtcEngine_ = nullptr;
void* pData_ = nullptr;
bool isOnRoom_ = false;
bool isOnConsumer_ = false;
bool isJoinMultiRoom_ = false;
void onRoom(uint32_t typeId, RTCENGINE_NAMESPACE::MRTCRoomInfo& roomInfo);
void onConsumer(uint32_t msgId, const char* roomId, const char* peerId, RTCENGINE_NAMESPACE::MRTCConsumerInfo& consumerInfo);
void onRender(const char* roomId, const char* peerId,

View File

@ -21,6 +21,15 @@ class WebSocket2RTC : public drogon::WebSocketController<WebSocket2RTC>
WS_PATH_LIST_END
private:
PubSubService<std::string> chatRooms_;
const char* srcUserId = "srcUser1";
const char* destUserId = "destUser1";
const char* srcDisplayName = "srcDisplayName1";
const char* destDisplayName = "destDisplayName1";
const char* srcRoomId = "srcRoom1";
const char* destRoomId = "destRoomId1";
const int16_t srcChannelIndex = 42;
const int16_t destChannelIndex = 43;
};
struct Subscriber
@ -29,30 +38,14 @@ struct Subscriber
drogon::SubscriberID id_;
};
int16_t sendRTC(std::string &&message) {
int16_t sendRTC(const int16_t destChannelIndex, std::string &&message) {
if (message.empty())
{
LOG_DEBUG << "message is empty";
return 0;
}
mrtc::IMRTCEngine *rtcEngine = RTCContext::instance().getRtcEngine();
if (!rtcEngine)
{
LOG_DEBUG << "RTCContext::instance().getRtcEngine() failed";
return -1;
}
/*
int32_t nCount = 0;
if (0 != rtcEngine->getUserCount(nCount))
{
LOG_DEBUG << "RTCContext::instance().getUserCount() failed";
return -1;
}
LOG_DEBUG << "nCount: " << nCount;
*/
int16_t retSend = RTCContext::instance().sendCustomAudioData(RTCContext::instance().destChannelIndex,
int16_t retSend = RTCContext::instance().sendCustomAudioData(destChannelIndex,
(void*)"aaaaaaaaaaaaaaaaaa", 48000, 1, 10);
if (0!= retSend)
{
@ -80,7 +73,7 @@ void WebSocket2RTC::handleNewMessage(const WebSocketConnectionPtr &wsConnPtr,
auto &s = wsConnPtr->getContextRef<Subscriber>();
chatRooms_.publish(s.chatRoomName_, message);
}
if (0 != sendRTC(std::move(message))) {
if (0 != sendRTC(destChannelIndex, std::move(message))) {
LOG_ERROR << "sendRTC() failed";
}
}
@ -111,5 +104,22 @@ void WebSocket2RTC::handleNewConnection(const HttpRequestPtr &req,
int main()
{
const char* srcUserId = "srcUser1";
const char* destUserId = "destUser1";
const char* srcDisplayName = "srcDisplayName1";
const char* destDisplayName = "destDisplayName1";
const char* srcRoomId = "srcRoom1";
const char* destRoomId = "destRoomId1";
const int16_t srcChannelIndex = 42;
const int16_t destChannelIndex = 43;
app().addListener("127.0.0.1", 8848).run();
if (!RTCContext::instance().init(srcUserId, srcDisplayName, srcRoomId)) {
LOG_DEBUG << "RTCContext init failed";
return -1;
}
if (!RTCContext::instance().initSend(destRoomId, destChannelIndex)) {
LOG_DEBUG << "RTCContext initSend failed";
return -1;
}
}