fix rtc send bug
This commit is contained in:
parent
bf66197322
commit
338be05383
|
@ -4,14 +4,17 @@ using namespace drogon;
|
||||||
|
|
||||||
int doSend(void* pdata, int32_t sampleRate, uint64_t channelNum, uint64_t dataLen)
|
int doSend(void* pdata, int32_t sampleRate, uint64_t channelNum, uint64_t dataLen)
|
||||||
{
|
{
|
||||||
LOG_DEBUG << "Sending custom audio data...";
|
int16_t retSend = RTCContext::instance().sendCustomAudioData(RTCContext::instance().destChannelIndex,
|
||||||
int16_t retSend = RTCContext::instance().sendCustomAudioData(RTCContext::instance().outChannelIndex,
|
|
||||||
pdata, sampleRate, channelNum, dataLen);
|
pdata, sampleRate, channelNum, dataLen);
|
||||||
if (0!= retSend)
|
if (0!= retSend)
|
||||||
{
|
{
|
||||||
LOG_DEBUG << "RTCContext::instance().sendCustomAudioData() failed, retSend:" << retSend;
|
LOG_DEBUG << "RTCContext::instance().sendCustomAudioData() failed, retSend:" << retSend;
|
||||||
return -1;
|
return -1;
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
LOG_DEBUG << "Sending custom audio data succ";
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
int main()
|
int main()
|
||||||
|
|
|
@ -27,11 +27,8 @@ int main()
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
if (RTCContext::instance().isOnRoom)
|
int16_t retSend = RTCContext::instance().sendCustomAudioData(RTCContext::instance().destChannelIndex,
|
||||||
{
|
(void*)"aaaaaaaaaaaaaaaaaa", 48000, 1, 10);
|
||||||
LOG_DEBUG << "Sending custom audio data...";
|
|
||||||
int16_t retSend = RTCContext::instance().sendCustomAudioData(RTCContext::instance().outChannelIndex,
|
|
||||||
(void*)"aaaaaaaaaaaaaaaaaaaaaaaaaaaa", 48000, 1, 10);
|
|
||||||
if (0!= retSend)
|
if (0!= retSend)
|
||||||
{
|
{
|
||||||
LOG_DEBUG << "RTCContext::instance().sendCustomAudioData() failed, retSend:" << retSend;
|
LOG_DEBUG << "RTCContext::instance().sendCustomAudioData() failed, retSend:" << retSend;
|
||||||
|
@ -40,7 +37,6 @@ int main()
|
||||||
{
|
{
|
||||||
LOG_DEBUG << "Sending custom audio data succ";
|
LOG_DEBUG << "Sending custom audio data succ";
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
sleep(3);
|
sleep(3);
|
||||||
} while (1);
|
} while (1);
|
||||||
|
|
|
@ -22,8 +22,15 @@ void RTCContext::onRender(const char* roomId, const char* peerId,
|
||||||
LOG_DEBUG << "RTCContext::onRender()";
|
LOG_DEBUG << "RTCContext::onRender()";
|
||||||
}
|
}
|
||||||
void RTCContext::onCallBackMessage(uint32_t msgId, const char* msg) {
|
void RTCContext::onCallBackMessage(uint32_t msgId, const char* msg) {
|
||||||
//LOG_DEBUG << "RTCContext::onCallBackMessage(), msgId:" << msgId << ", msg:" << msg;
|
|
||||||
LOG_DEBUG << "RTCContext::onCallBackMessage()";
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG_DEBUG << "RTCContext::onCallBackMessage(), msgId:" << msgId << ", msg:" << msg;
|
||||||
|
//LOG_DEBUG << "RTCContext::onCallBackMessage()";
|
||||||
}
|
}
|
||||||
void RTCContext::onCallBackCustomData(RTCENGINE_NAMESPACE::MRTCCustomDataObject object) {
|
void RTCContext::onCallBackCustomData(RTCENGINE_NAMESPACE::MRTCCustomDataObject object) {
|
||||||
//LOG_DEBUG << "RTCContext::onCallBackCustomData(), obj:" << object.peerId << "," << object.data << "," << object.data_length;
|
//LOG_DEBUG << "RTCContext::onCallBackCustomData(), obj:" << object.peerId << "," << object.data << "," << object.data_length;
|
||||||
|
@ -69,9 +76,13 @@ bool RTCContext::init()
|
||||||
LOG_DEBUG << "RTCContext::instance().init() failed";
|
LOG_DEBUG << "RTCContext::instance().init() failed";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (0 != rtcEngine_->setUserInfo(inUserId, inDisplayName, inRoomId))
|
#ifdef SEND_MODE
|
||||||
|
if (0 != rtcEngine_->setUserInfo(srcUserId, srcDisplayName, srcRoomId))
|
||||||
|
#else
|
||||||
|
if (0 != rtcEngine_->setUserInfo(destUserId, destDisplayName, destRoomId))
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
LOG_DEBUG << "RTCContext::instance().setUserInfo() inUser failed";
|
LOG_DEBUG << "RTCContext::instance().setUserInfo() failed";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,15 +116,15 @@ bool RTCContext::init()
|
||||||
sleep(3);
|
sleep(3);
|
||||||
}
|
}
|
||||||
LOG_DEBUG << "registerSoundLevelListener";
|
LOG_DEBUG << "registerSoundLevelListener";
|
||||||
int16_t ret1 = rtcEngine_->registerSoundLevelListener(mrtc::TYPE_AUDIO_SOURCE_CUSTOM, inRoomId,
|
int16_t ret1 = rtcEngine_->registerSoundLevelListener(mrtc::TYPE_AUDIO_SOURCE_CUSTOM, destRoomId,
|
||||||
inUserId, inChannelIndex, this);
|
srcUserId, destChannelIndex, this);
|
||||||
if (0 != ret1)
|
if (0 != ret1)
|
||||||
{
|
{
|
||||||
LOG_DEBUG << "RTCContext::instance().registerSoundLevelListener() inUser failed, ret:" << ret1;
|
LOG_DEBUG << "RTCContext::instance().registerSoundLevelListener() inUser failed, ret:" << ret1;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
LOG_DEBUG << "muteAudio";
|
LOG_DEBUG << "muteAudio";
|
||||||
int16_t ret2 = rtcEngine_->muteAudio(inRoomId, inUserId, mrtc::TYPE_AUDIO_SOURCE_CUSTOM, false, inChannelIndex);
|
int16_t ret2 = rtcEngine_->muteAudio(destRoomId, srcUserId, mrtc::TYPE_AUDIO_SOURCE_CUSTOM, false, destChannelIndex);
|
||||||
if (0 != ret2)
|
if (0 != ret2)
|
||||||
{
|
{
|
||||||
LOG_DEBUG << "RTCContext::instance().muteAudio() failed, ret:" << ret2;
|
LOG_DEBUG << "RTCContext::instance().muteAudio() failed, ret:" << ret2;
|
||||||
|
@ -131,7 +142,7 @@ bool RTCContext::init()
|
||||||
sleep(3);
|
sleep(3);
|
||||||
}
|
}
|
||||||
LOG_DEBUG << "join multi room";
|
LOG_DEBUG << "join multi room";
|
||||||
int16_t ret1 = rtcEngine_->joinMultiRoom(outRoomId);
|
int16_t ret1 = rtcEngine_->joinMultiRoom(destRoomId);
|
||||||
if (ret1 != 0)
|
if (ret1 != 0)
|
||||||
{
|
{
|
||||||
LOG_DEBUG << "joinMultiRoom fail, ret:" << ret1;
|
LOG_DEBUG << "joinMultiRoom fail, ret:" << ret1;
|
||||||
|
@ -139,8 +150,8 @@ bool RTCContext::init()
|
||||||
}
|
}
|
||||||
|
|
||||||
mrtc::MRTCAudioOption option;
|
mrtc::MRTCAudioOption option;
|
||||||
strcpy(option.dstRoomId, outRoomId);
|
strcpy(option.dstRoomId, destRoomId);
|
||||||
option.channelIndex = outChannelIndex;
|
option.channelIndex = destChannelIndex;
|
||||||
LOG_DEBUG << "startCustomAudio";
|
LOG_DEBUG << "startCustomAudio";
|
||||||
int16_t ret2 = rtcEngine_->startCustomAudio(option);
|
int16_t ret2 = rtcEngine_->startCustomAudio(option);
|
||||||
if (ret2 != 0)
|
if (ret2 != 0)
|
||||||
|
@ -152,10 +163,9 @@ bool RTCContext::init()
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RTCContext::destorySend(bool isIn)
|
void RTCContext::destorySend()
|
||||||
{
|
{
|
||||||
int16_t channelIndex = isIn ? inChannelIndex : outChannelIndex;
|
rtcEngine_->stopCustomAudio(destChannelIndex);
|
||||||
rtcEngine_->stopCustomAudio(channelIndex);
|
|
||||||
}
|
}
|
||||||
int16_t RTCContext::sendAudioData(uint8_t channelIndex, const void* pData, int32_t nSampleRate, uint64_t nNumberOfChannels, uint64_t dataLength)
|
int16_t RTCContext::sendAudioData(uint8_t channelIndex, const void* pData, int32_t nSampleRate, uint64_t nNumberOfChannels, uint64_t dataLength)
|
||||||
{
|
{
|
||||||
|
@ -169,6 +179,10 @@ bool RTCContext::init()
|
||||||
int16_t RTCContext::sendCustomAudioData(const int16_t channelIndex, void* customData, int32_t sampleRate,
|
int16_t RTCContext::sendCustomAudioData(const int16_t channelIndex, void* customData, int32_t sampleRate,
|
||||||
uint64_t channelNum, uint64_t dataLen)
|
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_);
|
std::lock_guard<std::mutex> lock(mutex_);
|
||||||
return rtcEngine_->sendCustomAudioData(channelIndex, customData, sampleRate, channelNum, dataLen);
|
return rtcEngine_->sendCustomAudioData(channelIndex, customData, sampleRate, channelNum, dataLen);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,9 @@
|
||||||
#include <iostream>
|
|
||||||
#include "IMRTCEngineFactory.hpp"
|
|
||||||
#include "IMRTCEngine.hpp"
|
#include "IMRTCEngine.hpp"
|
||||||
#include "MRTCEngineDefine.hpp"
|
#include "MRTCEngineDefine.hpp"
|
||||||
|
#include "IMRTCEngineFactory.hpp"
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <filesystem> // C++17
|
#include <filesystem> // C++17
|
||||||
#include "trantor/utils/Logger.h"
|
|
||||||
namespace fs = std::filesystem;
|
namespace fs = std::filesystem;
|
||||||
#define ENV_PRODUCT
|
#define ENV_PRODUCT
|
||||||
//#define SEND_MODE
|
//#define SEND_MODE
|
||||||
|
@ -31,24 +29,18 @@ public:
|
||||||
const unsigned short port = 34443;
|
const unsigned short port = 34443;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef SEND_MODE
|
const char* srcUserId = "srcUser1";
|
||||||
const char* inUserId = "inuser1";
|
const char* destUserId = "destUser1";
|
||||||
#else
|
|
||||||
const char* inUserId = "inuser2";
|
|
||||||
#endif
|
|
||||||
|
|
||||||
const char* inDisplayName = "indisplayName";
|
const char* srcDisplayName = "srcDisplayName1";
|
||||||
const char* outRoomId = "outRoomId1";
|
const char* destDisplayName = "destDisplayName1";
|
||||||
const int16_t outChannelIndex = 43;
|
const char* srcRoomId = "srcRoom1";
|
||||||
#ifdef SEND_MODE
|
const char* destRoomId = "destRoomId1";
|
||||||
const char* inRoomId = "inRoomId1";
|
const int16_t srcChannelIndex = 42;
|
||||||
const int16_t inChannelIndex = 42;
|
const int16_t destChannelIndex = 43;
|
||||||
#else
|
|
||||||
const char* inRoomId = outRoomId;
|
|
||||||
const int16_t inChannelIndex = outChannelIndex;
|
|
||||||
#endif
|
|
||||||
bool isOnRoom = false;
|
bool isOnRoom = false;
|
||||||
bool isOnConsumer = false;
|
bool isOnConsumer = false;
|
||||||
|
bool isJoinMultiRoom = false;
|
||||||
|
|
||||||
static RTCContext& instance()
|
static RTCContext& instance()
|
||||||
{
|
{
|
||||||
|
@ -68,7 +60,7 @@ public:
|
||||||
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 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,
|
int16_t sendCustomAudioData(const int16_t channelIndex, void* customData, int32_t sampleRate,
|
||||||
uint64_t channelNum, uint64_t dataLen);
|
uint64_t channelNum, uint64_t dataLen);
|
||||||
void destorySend(bool isIn);
|
void destorySend();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
RTCContext()
|
RTCContext()
|
||||||
|
|
|
@ -35,7 +35,6 @@ int16_t sendRTC(std::string &&message) {
|
||||||
LOG_DEBUG << "message is empty";
|
LOG_DEBUG << "message is empty";
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
LOG_DEBUG << "@@@@@@@@@@@@@@@@@@@@ begin @@@@@@@@@@@@@@@@@@@" << message;
|
|
||||||
mrtc::IMRTCEngine *rtcEngine = RTCContext::instance().getRtcEngine();
|
mrtc::IMRTCEngine *rtcEngine = RTCContext::instance().getRtcEngine();
|
||||||
if (!rtcEngine)
|
if (!rtcEngine)
|
||||||
{
|
{
|
||||||
|
@ -43,6 +42,7 @@ int16_t sendRTC(std::string &&message) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
int32_t nCount = 0;
|
int32_t nCount = 0;
|
||||||
if (0 != rtcEngine->getUserCount(nCount))
|
if (0 != rtcEngine->getUserCount(nCount))
|
||||||
{
|
{
|
||||||
|
@ -51,13 +51,17 @@ int16_t sendRTC(std::string &&message) {
|
||||||
}
|
}
|
||||||
LOG_DEBUG << "nCount: " << nCount;
|
LOG_DEBUG << "nCount: " << nCount;
|
||||||
|
|
||||||
if (0 != RTCContext::instance().sendCustomAudioData(RTCContext::instance().outChannelIndex,
|
*/
|
||||||
(void*)"aaaaaaaaaaaaaaaaaaaaaaaaaaaa", 48000, 1, 10))
|
int16_t retSend = RTCContext::instance().sendCustomAudioData(RTCContext::instance().destChannelIndex,
|
||||||
|
(void*)"aaaaaaaaaaaaaaaaaa", 48000, 1, 10);
|
||||||
|
if (0!= retSend)
|
||||||
{
|
{
|
||||||
LOG_DEBUG << "RTCContext::instance().sendCustomAudioData() failed";
|
LOG_DEBUG << "RTCContext::instance().sendCustomAudioData() failed, retSend:" << retSend;
|
||||||
return -1;
|
return -1;
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
LOG_DEBUG << "Sending custom audio data succ";
|
||||||
}
|
}
|
||||||
LOG_DEBUG << "@@@@@@@@@@@@@@@@@@@@ end @@@@@@@@@@@@@@@@@@@" << message;
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue