
本文为社区投稿,原文作者@Hanson bakedcorn
原文链接:
https://www.rtcdeveloper.cn/cn/community/blog/25270
本文介绍如何通过声网 SDK 应用在 NvidiaNano 芯片上搭建一个简易的家庭视频监控小系统。
开发环境准备
搭建好NvidiaNano开发板环境
采集端(NvidiaNano)集成SDK
由于Nvidia芯片集成的是armv8架构芯片,因此在选择sdk包时,选择Agora嵌入式端的SDK,否则编译时会出现格式不兼容的情况出现。使用下面链接的sdk包,不然会报格式不对的错误。
浏览端(Chrome)集成SDK
代码部分
准备工作,创建并获取AgoraRTC的AppID
Nvidia Nano 端代码
RtcNanoIPC_init() //初始化Nano的USB Camera,Mac,Ethernet等设备,初始化相关变量char acAppID[] = "AppID***********************"agora_rtc_init(); //初始化Agora相关环境变量void *pAppid = acAppID;typedef struct tagServConfig{char *pSdkLog;char *pChannelID;unsigned int uiUserID;unsigned int uiArea;// video related configvideo_data_type_e enVideoType;int iVideoSendFrameRate;// audio related configaudio_data_type_e enAudioData;audio_codec_type_e enAudioCodec;// advanced configbool bSndVideoFlag;bool bSndOnly;} SEV_CONFIG_S;SEV_CONFIG_S g_stSevConfig = {.pChannelID = DEFAULT_CHANNEL_NAME,.uiUserID = 0,.uiArea = AREA_CODE_GLOB,// video related config.enVideoType = VIDEO_DATA_TYPE_H264,.iVideoSendFrameRate = DEFAULT_SEND_VIDEO_FRAME_RATE,// audio related config.enAudioData = AUDIO_DATA_TYPE_PCM,.enAudioCodec = AUDIO_CODEC_TYPE_OPUS,// advanced config.bSndVideoFlag = false,.bSndOnly = true,};/*设置事件响应回调, 本工程比较简单,只用到oin,audio,video相关,mute静音等暂未用到/agora_rtc_event_handler_t stEventHandler = { 0 };init_event_handler(&stEventHandler , &g_stSevConfig );/初始化/rtc_service_option_t stServiceOption = { 0 };stServiceOption .area_code = g_stSevConfig.uiArea;stServiceOption .log_cfg.log_level = RTC_LOG_INFO;stServiceOption .log_cfg.log_path = g_stSevConfig.pSdkLog;agora_rtc_init(p_appid, &event_handler, &service_opt);connection_id_t g_stConnId = {0};agora_rtc_create_connection(&g_stConnId);rtc_channel_options_t g_stChannelOptions = {0};agora_rtc_join_channel(g_stConnId, g_stSevConfig.pChannelID , g_stSevConfig.uiUserID+1, pAppid, &g_stChannelOptions );pthread_t stVideoThdID;pthread_t stAudioThdID;pthread_create(&stVideoThdID, NULL, video_send_process, 0);pthread_create(&stAudioThdID, NULL, audio_send_process, 0)
var vBrowseClient = AgoraRTC.createClient({ mode: "rtc", codec: "h264" }); //与采集端要一致,采用H264// Join a channel and create local tracks. Best practice is to use Promise.all and run them concurrently.[ options.uid, localTracks.audioTrack, localTracks.videoTrack ] = await Promise.all([// Join the channel.vBrowseClient .join(options.appid, options.channel, options.token || null, options.uid || null);vBrowseClient .on("user-published", handleUserPublished);function handleUserPublished(user, mediaType) {const id = user.uid;remoteUsers[id] = user;subscribe(user, mediaType);}async function subscribe(user, mediaType) {const uid = user.uid;// subscribe to a remote userawait client.subscribe(user, mediaType);console.log("subscribe success");if (mediaType === 'video') {const player = $(`<div id="player-wrapper-${uid}"><p class="player-name">remoteUser(${uid})</p><div id="player-${uid}" class="player"></div></div>`);$("#remote-playerlist").append(player);user.videoTrack.play(`player-${uid}`);}if (mediaType === 'audio') {user.audioTrack.play();}}
关注实时互动领域的
技术实践、行业洞察、人物观点
☟☟☟

