Compare commits

..

No commits in common. "base1" and "master" have entirely different histories.

5 changed files with 34 additions and 73 deletions

View File

@ -32,7 +32,7 @@ int main()
LOG_DEBUG << "RTCContext init failed";
return -1;
}
if (!RTCContext::instance().initSend(srcRoomId, destRoomId, destChannelIndex, 1)) {
if (!RTCContext::instance().initSend(destRoomId, destChannelIndex)) {
LOG_DEBUG << "RTCContext initSend failed";
return -1;
}

View File

@ -20,7 +20,7 @@ int main()
LOG_DEBUG << "RTCContext init failed";
return -1;
}
if (!RTCContext::instance().initSend(srcRoomId, destRoomId, destChannelIndex, 1)) {
if (!RTCContext::instance().initSend(destRoomId, destChannelIndex)) {
LOG_DEBUG << "RTCContext initSend failed";
return -1;
}

View File

@ -2,6 +2,9 @@
#include "drogon/drogon_test.h"
#include <iostream>
#include <unistd.h>
void RTCContext::onRoom(uint32_t typeId, RTCENGINE_NAMESPACE::MRTCRoomInfo& roomInfo) {
//LOG_DEBUG << "RTCContext::onRoom():" << roomInfo.roomId << "," << roomInfo.displayName << "," << roomInfo.userId << "," << roomInfo.message;
LOG_DEBUG << "RTCContext::onRoom()";
@ -9,30 +12,10 @@ void RTCContext::onRoom(uint32_t typeId, RTCENGINE_NAMESPACE::MRTCRoomInfo& room
isOnRoom_ = true;
}
void RTCContext::onConsumer(uint32_t msgId, const char* roomId, const char* peerId, RTCENGINE_NAMESPACE::MRTCConsumerInfo& consumerInfo) {
//LOG_DEBUG << "RTCContext::onConsumer()";
LOG_DEBUG << "RTCContext::onConsumer():msgId:" << msgId << ", roomId:" << consumerInfo.roomId << ", displayName:"
<< consumerInfo.displayName << ", channelIndex" << consumerInfo.channelIndex;
LOG_DEBUG << "RTCContext::onConsumer():" << consumerInfo.roomId << "," << consumerInfo.displayName << "," << consumerInfo.channelIndex;
std::lock_guard<std::mutex> lock(mutex_);
isOnConsumer_ = true;
LOG_DEBUG << "registerSoundLevelListener";
int16_t ret1 = rtcEngine_->registerSoundLevelListener(mrtc::TYPE_AUDIO_SOURCE_CUSTOM, roomId,
peerId, consumerInfo.channelIndex, this);
if (0 != ret1)
{
LOG_DEBUG << "RTCContext::instance().registerSoundLevelListener() inUser failed, ret:" << ret1;
return;
}
LOG_DEBUG << "muteAudio";
int16_t ret2 = rtcEngine_->muteAudio(roomId, peerId, mrtc::TYPE_AUDIO_SOURCE_CUSTOM,
false, consumerInfo.channelIndex);
if (0 != ret2)
{
LOG_DEBUG << "RTCContext::instance().muteAudio() failed, ret:" << ret2;
return;
}
LOG_DEBUG << "init recv succ";
//LOG_DEBUG << "RTCContext::onConsumer()";
}
void RTCContext::onRender(const char* roomId, const char* peerId,
RTCENGINE_NAMESPACE::MRTCVideoSourceType sourceType, const RTCENGINE_NAMESPACE::MRTCVideoFrame& videoFrame) {
@ -128,35 +111,43 @@ bool RTCContext::initRecv(const char* destRoomId, const char* srcUserId, const i
LOG_DEBUG << "wait for OnConsumer";
sleep(3);
}
LOG_DEBUG << "registerSoundLevelListener";
int16_t ret1 = rtcEngine_->registerSoundLevelListener(mrtc::TYPE_AUDIO_SOURCE_CUSTOM, destRoomId,
srcUserId, destChannelIndex, this);
if (0 != ret1)
{
LOG_DEBUG << "RTCContext::instance().registerSoundLevelListener() inUser failed, ret:" << ret1;
return false;
}
LOG_DEBUG << "muteAudio";
int16_t ret2 = rtcEngine_->muteAudio(destRoomId, srcUserId, mrtc::TYPE_AUDIO_SOURCE_CUSTOM, false, destChannelIndex);
if (0 != ret2)
{
LOG_DEBUG << "RTCContext::instance().muteAudio() failed, ret:" << ret2;
return false;
}
LOG_DEBUG << "init recv succ";
return true;
}
bool RTCContext::initSend(const char* srcRoomId, const char* destRoomId, const int16_t destChannelIndex,
const uint8_t channelNum)
bool RTCContext::initSend(const char* destRoomId, const int16_t destChannelIndex)
{
while (!isOnRoom_)
{
LOG_DEBUG << "wait for OnRoom";
sleep(3);
}
if (std::string(srcRoomId) != std::string(destRoomId)) {
isMultiRoom_ = true;
LOG_DEBUG << "join multi room";
int16_t ret1 = rtcEngine_->joinMultiRoom(destRoomId);
if (ret1 != 0) {
LOG_DEBUG << "joinMultiRoom fail, ret:" << ret1;
return false;
}
} else {
isMultiRoom_ = false;
LOG_DEBUG << "join multi room";
int16_t ret1 = rtcEngine_->joinMultiRoom(destRoomId);
if (ret1 != 0)
{
LOG_DEBUG << "joinMultiRoom fail, ret:" << ret1;
return false;
}
mrtc::MRTCAudioOption option;
if (std::string(srcRoomId) != std::string(destRoomId)) {
strcpy(option.dstRoomId, destRoomId);
}
strcpy(option.dstRoomId, destRoomId);
option.channelIndex = destChannelIndex;
option.channel = channelNum;
LOG_DEBUG << "startCustomAudio";
int16_t ret2 = rtcEngine_->startCustomAudio(option);
if (ret2 != 0)
@ -184,16 +175,11 @@ int16_t RTCContext::sendAudioData(uint8_t channelIndex, const void* pData, int32
int16_t RTCContext::sendCustomAudioData(const int16_t channelIndex, void* customData, int32_t sampleRate,
uint64_t channelNum, uint64_t dataLen)
{
while(!isOnRoom_ || (isMultiRoom_ && !isJoinMultiRoom_)) {
while(!isOnRoom_ || !isJoinMultiRoom_) {
LOG_DEBUG << "wait for room and multi room before send";
sleep(3);
}
std::lock_guard<std::mutex> lock(mutex_);
if (customData == nullptr) {
LOG_DEBUG << "customData is null";
return -1;
}
LOG_DEBUG << "customData addr is:" << customData;
return rtcEngine_->sendCustomAudioData(channelIndex, customData, sampleRate, channelNum, dataLen);
}
mrtc::IMRTCEngine* RTCContext::getRtcEngine() const

View File

@ -4,27 +4,10 @@
#include <mutex>
#include <cstring>
#include <filesystem> // C++17
#include <iostream>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <sys/stat.h>
namespace fs = std::filesystem;
#define ENV_PRODUCT
//#define SEND_MODE
// 音频数据帧
struct RetAudioFrame final
{
std::unique_ptr<int16_t[]> data;
int dataCount = 0;
int sampleRate = 48000;
int numChannels = 1;
int channelIndex = 0;
};
class RTCContext :
public RTCENGINE_NAMESPACE::IMRTCRoomCallBack,
public RTCENGINE_NAMESPACE::IMRTCConsumerCallBack,
@ -56,7 +39,7 @@ public:
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* srcRoomId, const char* destRoomId, const int16_t destChannelIndex, const uint8_t channelNum);
bool initSend(const char* destRoomId, const int16_t destChannelIndex);
void* getpData() const;
void setpData(void* pData);
@ -76,7 +59,6 @@ private:
bool isOnRoom_ = false;
bool isOnConsumer_ = false;
bool isJoinMultiRoom_ = false;
bool isMultiRoom_ = 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

@ -118,15 +118,8 @@ int main()
LOG_DEBUG << "RTCContext init failed";
return -1;
}
if (!RTCContext::instance().initSend(srcRoomId, destRoomId, destChannelIndex, 1)) {
if (!RTCContext::instance().initSend(destRoomId, destChannelIndex)) {
LOG_DEBUG << "RTCContext initSend failed";
return -1;
}
app().getLoop()->loop();
app().setLogLevel(trantor::Logger::kDebug);
app().run();
LOG_INFO << "bye!";
return 0;
}