当前位置: 首页 > news >正文

君正Ingenic webRTC P2P库libyangpeerconnection7编程指南

概述

libyangpeerconnection7是一个实现P2P媒体传输/数据通道的一个轻量级的webRTC库,基于metaRTC7.0的传输模块构建,支持H264/H265视频编码,通过 P2P 连接为用户提供高效、低延迟的音视频和数据通信。

君正版libyangpeerconnection7可适用于t31/x2000等多个君正SOC系列,助力基于君正webRTC P2P应用快速开发。

下载

https://download.csdn.net/download/m0_56595685/90910661

依赖文件

  • 头文件:YangPeerConnection7.h
  • 库文件:libyangpeerconnection7.so

示例代码

对象分配与释放

YangPeerConnection7* peer = (YangPeerConnection7*)calloc(1, sizeof(YangPeerConnection7));YangPeerInfo* peerInfo=&peer->peer.peerInfo;
yang_init_peerParam(peerInfo);peerInfo->uid = uid;
peerInfo->userId=userId;
peerInfo->direction = YangSendonly;
peerInfo->rtc.rtcLocalPort = 16000;
peerInfo->rtc.isControlled = yangtrue;
peerInfo->rtc.iceCandidateType = 2;peerInfo->pushAudio.sample = 8000;
peerInfo->pushAudio.channel = 1;
peerInfo->pushAudio.audioEncoderType = Yang_AED_PCMA;peerInfo->pushVideo.width = 1280;
peerInfo->pushVideo.height = 720;
peerInfo->pushVideo.fps = 30;
peerInfo->pushVideo.videoEncoderType = Yang_VED_H264;peerInfo->rtc.iceServerPort=3478;
strcpy(peerInfo->rtc.iceServerIP, "192.168.0.104");
strcpy(peerInfo->rtc.iceUserName, "metartc");
strcpy(peerInfo->rtc.icePassword, "metartc");peer->peer.peerCallback.sslCallback.context = session;
peer->peer.peerCallback.sslCallback.sslAlert = ipc_rtcrecv_sslAlert;
peer->peer.peerCallback.recvCallback.context = session;peer->peer.peerCallback.recvCallback.receiveAudio = ipc_rtcrecv_receiveAudio;
peer->peer.peerCallback.recvCallback.receiveVideo = ipc_rtcrecv_receiveVideo;
peer->peer.peerCallback.recvCallback.receiveMsg = ipc_rtcrecv_receiveMsg;peer->peer.peerCallback.iceCallback.context = session;
peer->peer.peerCallback.iceCallback.onConnectionStateChange=ipc_onConnectionStateChange;
peer->peer.peerCallback.iceCallback.onIceStateChange=ipc_onIceStateChange;
peer->peer.peerCallback.iceCallback.onIceCandidate=ipc_onIceCandidate;yang_create_peerConnection7(peer);peer->addAudioTrack(&peer->peer,Yang_AED_PCMA);
peer->addVideoTrack(&peer->peer,Yang_VED_H264);
peer->addTransceiver(&peer->peer,YangMediaAudio,peer->peer.peerInfo.direction);
peer->addTransceiver(&peer->peer,YangMediaVideo,peer->peer.peerInfo.direction);//通过信令取得对端sdpif((ret = peer->setRemoteDescription(&peer->peer, sdp))!=Yang_Ok){
goto cleanup;
}//取得answer通过信令传回对端
if((ret = peer->createAnswer(&peer->peer, answer))!=Yang_Ok){
goto cleanup;
}//free peer
if(peer){yang_destroy_peerConnection7(peer);free(peer);
}

交换ICE Candidate

//通过信令取得对端candidate
peer->addIceCandidate(&peer->peer,candidate);
//回调函数
static void ipc_onIceCandidate(void* context, int32_t uid,char* candidateStr){if (context == NULL) return;//取得candidate 通过信令传到对端
}

回调函数

static void ipc_onConnectionStateChange(void* context, int32_t uid,YangRtcConnectionState connectionState){if (context == NULL) return;switch(connectionState){
case Yang_Conn_State_Connecting:{
break;
}
case Yang_Conn_State_Connected:{
break;
}
case Yang_Conn_State_Disconnected:{
break;
}
case Yang_Conn_State_Failed:{
//yang_trace("\nYang_Conn_State_Failed remove uid==%d",uid);
//removePeer(uid);
break;
}
case Yang_Conn_State_Closed:{
break;
}
default:break;
}
}static void ipc_onIceStateChange(void* context,int32_t uid,YangIceCandidateState iceState){if (context == NULL) return;
switch(iceState){
case YangIceSuccess:{
break;
}
case YangIceFail:{
//yang_trace("\nYangIceFail remove uid==%d",uid);
break;
}
default:break;
}
}static void ipc_onIceCandidate(void* context, int32_t uid,char* sdp){if (context == NULL) return;//取得candidate 传到对端
}static void ipc_rtcrecv_sslAlert(void *context, int32_t uid, char *type, char *desc) {if (context == NULL || type == NULL || desc == NULL)return;if (yang_strcmp(type, "warning") == 0 && yang_strcmp(desc, "CN") == 0) {// removePeer( uid);}
}static void ipc_rtcrecv_receiveAudio(void *user, YangFrame *audioFrame) {if (user == NULL || audioFrame == NULL)return;
}static void ipc_rtcrecv_receiveVideo(void *user, YangFrame *videoFrame) {if (user == NULL || videoFrame == NULL)return;
}static void ipc_rtcrecv_receiveMsg(void *user, YangFrame *msgFrame) {if (user == NULL) return;//  receiveMsg(msgFrame->uid,msgFrame->payload,msgFrame->nb);
}

推流

//YangFrame payload 数据 nb:数据长度
//frametype:YANG_Frametype_I(I帧) YANG_Frametype_P(P帧或B帧)
//I帧 四字节sps长度+sps+四字节pps长度+pps+(00,00,00,01)+I帧 如:00,00,00,0e,67,42,c0,1f,8c,8d,40,50,1e,d0,0f,08,84,6a,00,00,00,04,68,ce,3c,80,00,00,00,01,65,b8,00,04,00,00,13,88,c5
//P帧或B帧 如:00,00,00,01,61,e0,00,40,00,be,41,38,22,93,df
//去掉start code 00,00,00,01,取61,e0,00,40,00,be,41,38,22,93,df
rtc->on_video(&rtc->peer, videoFrame)://推视频
rtc->on_audio(&rtc->peer, audioFrame);//推音频
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.dtcms.com/a/213916.html

相关文章:

  • leetcode:2160. 拆分数位后四位数字的最小和(python3解法,数学相关算法题)
  • C++之STL入门
  • 探索LobeChat:开源、可定制的下一代AI对话客户端
  • Spring + MyBatis/MyBatis-Plus 分页方案(limit分页和游标分页)详解
  • 打卡第29天:类的定义和方法
  • React从基础入门到高级实战:React 核心技术 - React 状态管理:Context 与 Redux
  • 第三届京麒CTF Web
  • MyBatis入门:快速搭建数据库操作框架 + 增删改查(CRUD)
  • Web字体本地化的一种方案
  • 电动式传声器与电容式传声器
  • 【区间dp】-----例题4【凸多边形的划分】
  • 【前端基础】Promise 详解
  • Android Studio 介绍
  • 基于Robust Video Matting 使用Unity 实现无绿幕实时人像抠图
  • 编程日志5.19
  • 人工智能100问☞第33问:什么是计算机视觉?
  • 遥感解译项目Land-Cover-Semantic-Segmentation-PyTorch之三制作训练数据
  • 从无符号长整型数中提取字节
  • 力扣刷题Day 56:岛屿数量(200)
  • 策略模式与责任链模式学习笔记:从入门到理解
  • 如何选择自动化编程平台
  • OpenSSL 签名验证详解:PKCS7* p7、cafile 与 RSA 验签实现
  • 【windwos】文本编辑器Notepad++ 替代品Notepad--
  • 支持向量机(SVM)例题
  • 综合实现案例 LVS keepalived mysql 等
  • 深入解析Spring Boot与Redis集成:高效缓存与性能优化实践
  • 《软件工程》第 3 章 -需求工程概论
  • vae 视频截图 复习 gans和vae的原理区别
  • 【通用智能体】Dify API 文件上传功能: 两种传参方式的API传参方式
  • 【Pandas】pandas DataFrame add_prefix