如下是一个总体接入流程,详细细节请参见 RTC服务开通指南。
int VideoCallRtcEngineWrap::initAndJoinRTCRoom() { // 初始化 RTC Video 对象 // Initialize the RTC Video object video_engine_(nullptr,[](bytertc::IRTCVideo* self) { bytertc::destroyRTCVideo();}), video_engine_.reset(bytertc::createRTCVideo(app_id.c_str(), this, "")); // 初始化 RTC Room 对象 // Initialize the RTC Room object rtcRoom_ = std::shared_ptr<bytertc::IRTCRoom>( video_engine_->createRTCRoom(room_id.c_str()), [=](bytertc::IRTCRoom* room) { room->destroy(); }); // 根据预览页配置开启/关闭相机采集和视频流推送 //Enable/disable video capture and push stream according to the preview page configuration if (DataMgr::instance().camera_on) { video_engine_->startVideoCapture(); rtcRoom->publishStream(bytertc::MediaStreamType::kMediaStreamTypeVideo); } else { video_engine_->stopVideoCapture(); rtcRoom_ ->unpublishStream(bytertc::MediaStreamType::kMediaStreamTypeVideo); } // 根据预览页配置开启/关闭音频采集和流推送 //Enable/disable audio capture and push stream according to the preview page configuration if (DataMgr::instance().mic_on) { video_engine_->startAudioCapture(); rtcRoom->publishStream(bytertc::MediaStreamType::kMediaStreamTypeAudio); } else { video_engine_->stopAudioCapture(); rtcRoom_ ->unpublishStream(bytertc::MediaStreamType::kMediaStreamTypeAudio); } //开启/关闭发言者音量键控 //Turn on/off speaker volume keying bytertc::AudioPropertiesConfig config; config.interval = 1000; video_engine_->enableAudioPropertiesReport(config); //加入房间,开始连麦,需要申请AppId和Token //Join the room, start connecting the microphone, you need to apply for AppId and Token auto userName = videocall::DataMgr::instance().user_name(); auto userId = videocall::DataMgr::instance().user_id() QJsonObject extra_info; extra_info["user_id"] = QString::fromStdString(userId); extra_info["user_name"] = QString::fromStdString(userName); auto infoStr = QString(QJsonDocument(extra_info).toJson()); auto infoStdString = std::string(infoStr.toUtf8()); bytertc::UserInfo user = {uid.c_str(), infoStdString.c_str()}; bytertc::RTCRoomConfig config; config.room_profile_type = bytertc::RoomProfileType::kRoomProfileTypeCommunication; // 开启自动推送(默认开启) // enable automatic push(defult enabled) config.is_auto_publish= true; // 开启自动订阅音视频(默认开启) // Enable automatic subscription of audio and video(defult enabled) config.is_auto_subscribe_audio= true; config.is_auto_subscribe_video= true; rtcRoom_.joinRoom(token, user, config); }
void leaveRTCRoom(){ VideoCallNotify::offAll(); if (screen_shared_uid == self.user_id()) { //停止屏幕音频采集和屏幕流采集 VideoCallRtcVideoWrap::stopScreenAudioCapture(); VideoCallRtcVideoWrap::stopScreenCapture(); } //离开房间 rtcRoom_->leaveRoom(); rtcRoom_->destroy(); }
-onUserJoined
回调。void IRTCRoomEventHandler::onRoomStateChanged(const char* room_id, const char* uid, int state, const char* extra_info) { auto infoArray = QByteArray(extra_info.data(), static_cast<int>(extra_info.size())); auto infoJsonObj = QJsonDocument::fromJson(infoArray).object(); auto joinType = infoJsonObj["join_type"].toInt(); // joinType '0'为首次进房,'1'为重连进房 ;state '0'为加入房间成功 // joinType '0' is the first time entering the room, '1' is the reconnection entering the room; state '0' means join the room successfully if (state == 0 && joinType == 1) { // 执行业务重连API,更新业务状态 userReconnect([=](int code) { //do something }); } }
屏幕共享详见PC 端屏幕共享
功能点 | API |
---|---|
创建 ByteRTCVideo 实例 | createRTCVideo |
设置视频发布参数 | SetVideoEncoderConfig |
开启本地音频采集 | startAudioCapture |
开启本地视频采集 | startVideoCapture |
设置本地视频渲染 | setLocalVideoCanvas |
加入 RTC 房间 | joinRoom |
设置视频渲染视图 | setRemoteVideoCanvas |
离开房间 | leaveRoom |
关闭内部音频采集 | stopAudioCapture |
关闭内部视频采集 | stopVideoCapture |
销毁引擎实例对象 | destroy |
发布本地通过摄像头/麦克风采集的媒体流 | publishStream |
取消发布本地通过摄像头/麦克风采集的媒体流 | unpublishStream |
设置音频播放设备为扬声器或者听筒 | setAudioPlaybackDevice |
开启音量提示 | enableAudioPropertiesReport |
开启镜像 | setLocalVideoMirrorType |
设置音质档位 | setAudioProfile |
功能点 | 回调 |
---|---|
本地进房成功回调 | onRoomStateChanged |
远端可见用户加入房间 | onUserJoined |