diff --git a/util/RTCContext.cpp b/util/RTCContext.cpp index be5e132..5ecfbb3 100644 --- a/util/RTCContext.cpp +++ b/util/RTCContext.cpp @@ -6,29 +6,30 @@ void RTCContext::onRoom(uint32_t typeId, RTCENGINE_NAMESPACE::MRTCRoomInfo& room std::lock_guard lock(mutex_); isOnRoom_ = true; } -void RTCContext::onConsumer(uint32_t msgId, const char* roomId, const char* peerId, RTCENGINE_NAMESPACE::MRTCConsumerInfo& consumerInfo) { - std::cout << "RTCContext::onConsumer():" << consumerInfo.roomId << "," << consumerInfo.displayName << "," << consumerInfo.channelIndex; - std::lock_guard lock(mutex_); - isOnConsumer_ = true; - std::cout << "registerSoundLevelListener" << std::endl; - int16_t ret1 = rtcEngine_->registerSoundLevelListener(mrtc::TYPE_AUDIO_SOURCE_CUSTOM, consumerInfo.roomId, - peerId, consumerInfo.channelIndex, this); - if (0 != ret1) - { - std::cout << "RTCContext::instance().registerSoundLevelListener() inUser failed, ret:" << ret1; - return; - } +void RTCContext::onConsumer(uint32_t msgId, const char* roomId, const char* peerId, + RTCENGINE_NAMESPACE::MRTCConsumerInfo& consumerInfo) { + std::cout << "RTCContext::onConsumer():" << consumerInfo.roomId << "," << consumerInfo.displayName << "," + << consumerInfo.channelIndex << std::endl; + if (isRecv_) { + std::lock_guard lock(mutex_); + std::cout << "registerSoundLevelListener" << std::endl; + int16_t ret1 = rtcEngine_->registerSoundLevelListener(mrtc::TYPE_AUDIO_SOURCE_CUSTOM, consumerInfo.roomId, + peerId, consumerInfo.channelIndex, this); + if (0 != ret1) { + std::cout << "RTCContext::instance().registerSoundLevelListener() inUser failed, ret:" << ret1; + return; + } - std::cout << "muteAudio" << std::endl; - int16_t ret2 = rtcEngine_->muteAudio(consumerInfo.roomId, peerId, mrtc::TYPE_AUDIO_SOURCE_CUSTOM, false, consumerInfo.channelIndex); - if (0 != ret2) - { - std::cout << "RTCContext::instance().muteAudio() failed, ret:" << ret2; - return; - } + std::cout << "muteAudio" << std::endl; + int16_t ret2 = rtcEngine_->muteAudio(consumerInfo.roomId, peerId, mrtc::TYPE_AUDIO_SOURCE_CUSTOM, + false, consumerInfo.channelIndex); + if (0 != ret2) { + std::cout << "RTCContext::instance().muteAudio() failed, ret:" << ret2; + return; + } - std::cout << "init recv succ" << std::endl; - //std::cout << "RTCContext::onConsumer()" << std::endl; + std::cout << "init recv succ" << std::endl; + } } void RTCContext::onRender(const char* roomId, const char* peerId, RTCENGINE_NAMESPACE::MRTCVideoSourceType sourceType, const RTCENGINE_NAMESPACE::MRTCVideoFrame& videoFrame) { @@ -241,37 +242,7 @@ bool RTCContext::init(const char* selfUserId, const char* selfDisplayName, const } bool RTCContext::initRecv(const char* destRoomId, const char* srcUserId, const int16_t destChannelIndex) { - std::cout << "initRecv, numpyApi_:" << numpyApi_[93] << std::endl; - if (!numpyApi_ || !numpyApi_[93]) { // 93是PyArray_SimpleNew的偏移量 - std::cout << "numpyApi_ is null in initRecv" << std::endl; - } else { - std::cout << "numpyApi_ is not null in initRecv" << std::endl; - } - /* - while (!isOnConsumer_) - { - std::cout << "wait for OnConsumer" << std::endl; - sleep(3); - } - std::cout << "registerSoundLevelListener" << std::endl; - int16_t ret1 = rtcEngine_->registerSoundLevelListener(mrtc::TYPE_AUDIO_SOURCE_CUSTOM, destRoomId, - srcUserId, destChannelIndex, this); - if (0 != ret1) - { - std::cout << "RTCContext::instance().registerSoundLevelListener() inUser failed, ret:" << ret1; - return false; - } - - std::cout << "muteAudio" << std::endl; - int16_t ret2 = rtcEngine_->muteAudio(destRoomId, srcUserId, mrtc::TYPE_AUDIO_SOURCE_CUSTOM, false, destChannelIndex); - if (0 != ret2) - { - std::cout << "RTCContext::instance().muteAudio() failed, ret:" << ret2; - return false; - } - - std::cout << "init recv succ" << std::endl; - */ + isRecv_ = true; return true; } diff --git a/util/RTCContext.h b/util/RTCContext.h index ea49ad0..6806daf 100644 --- a/util/RTCContext.h +++ b/util/RTCContext.h @@ -104,7 +104,7 @@ private: mrtc::IMRTCEngine * rtcEngine_ = nullptr; void* pData_ = nullptr; bool isOnRoom_ = false; - bool isOnConsumer_ = false; + bool isRecv_ = false; bool isJoinMultiRoom_ = false; bool isMultiRoom_ = false; boost::python::object pyCallback_;