支持将UDP数据流接收后进行SRT流的推送,也支持从服务端拉取SRT流,同时支持SRT会话模式的测试。项目依赖于msprotocol: 一个轻量级的网络协议,扩展方便使用简单。可应用于X86和ARM64嵌入式设备,目前已支持file,hls,http,rtmp,msav,raw,rtp,rtsp,tcp,udp,udplite,srt等协议;
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define FLAG "PTC_CLENT"
#define mshostname_ipaddr "192.168.200.244"
#define mshostname_port 50000
#define mshostname_url_http "http://127.0.0.1:8010/ch31.ts"
#define mshostname_url_rtsp "rtsp://127.0.0.1:8010/ch31.ts"
int main(int argc, char **argv)
{
mslog_api_init( 53, ms_null,ms_null, ms_null);
if(argc<2){
ms_error("Userage:%s url" ,argv[0]);
return 0;
}
msthread_api_setName("ptc_client");
msmem_api_init(ms_false);
msptc_api_init();
msptc_api_register();
msmd_api_setUlimit();
ms_debug("Get param");
mslog_api_init( 53, "/home/sugao","client.log", ms_null);
URLContext cilent_ctt;
URLContext *pcilent_ctt=&cilent_ctt;
ms_memset0(pcilent_ctt, sizeof(URLContext));
ms_strcpy(pcilent_ctt->url,(argv[1]));
//Get msptl_in
msptc_api_urlSplit_urlctt(pcilent_ctt);
URLProtocol *msptl_in=msptc_api_match(pcilent_ctt->url_info.protocol_name);
ms_debug("url_open");
if(ms_strncmp_saeq(msptl_in->name, PTLNAME_WEBSOCKECT)){
pcilent_ctt->urlctt_opt.ws_opt.dataType=WDT_TXTDATA;
}
if(msptl_in->url_open(pcilent_ctt)<0){
ms_errGoto(ms_end, "open %s failed",pcilent_ctt->url);
}
ms_sleep(1);
ms_debug("url_write");
ms_byte *sendstr="Hello,I am client";
ms_s32 len_need_send=ms_buflen(sendstr);
ms_s32 len_send=msptl_in->url_write(pcilent_ctt,sendstr,len_need_send);
if(len_send>0){
ms_verbose("test:Send success!(len_send,len_need_send:%d,%d)-Context:%s%s ",len_send,len_need_send,LINE_END,sendstr);
if(ms_strncmp_saeq(msptl_in->name, PTLNAME_WEBSOCKECT)){
ms_verbose("dataType:%d ",pcilent_ctt->urlctt_opt.ws_opt.dataType);
}
}else{
ms_error("test:Send failed!(len_send,len_need_send:%d,%d)-Context:%s%s ",len_send,len_need_send,LINE_END,sendstr);
}
ms_sleep(1);
ms_byte recvbuf[1024]={0};
ms_debug("url_read");
ms_s32 len=msptl_in->url_read(pcilent_ctt,recvbuf,ms_bufsize(recvbuf));
if(len>0){
ms_verbose("test:Read success!Context:%s%s", LINE_END,recvbuf);
if(ms_strncmp_saeq(msptl_in->name, PTLNAME_WEBSOCKECT)){
ms_verbose("dataType:%d ",pcilent_ctt->urlctt_opt.ws_opt.dataType);
}
}else{
ms_error("test:Read failed!");
}
msptl_in->url_close(pcilent_ctt);
ms_end:
msptc_api_deinit();
msmem_api_deinit();
mslog_api_deinit();
}
#undef MAIN_C
支持接收SRT推流,并转换为UDP输出。项目依赖于msprotocol: 一个轻量级的网络协议,扩展方便使用简单。可应用于X86和ARM64嵌入式设备,目前已支持file,hls,http,rtmp,msav,raw,rtp,rtsp,tcp,udp,udplite,srt等协议;
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define FLAG "SRTSERVER_SAMPLE"
static char * pinurl=ms_null;
static char * pouturl=ms_null;
void* srtserver_send(void* args)
{
URLVal *purlval_srt=(URLVal *)args;
URLVal urlval_udp;
memset(&urlval_udp,0,sizeof(URLVal));
urlval_udp.purl_ptl=msptc_api_match(PTLNAME_UDP);
ms_strcpy(urlval_udp.url_ctt.url, pouturl);
urlval_udp.url_ctt.urlctt_opt.udp_opt.interfacein="p2p1";
urlval_udp.url_ctt.urlctt_opt.udp_opt.localhostipin="192.168.200.244";
urlval_udp.url_ctt.flags|=FLAG_WRITE;
if(urlval_udp.purl_ptl->url_open(&urlval_udp.url_ctt)<0){
ms_errExit(-1, "Open in url failed");
}
char data[1316]={0};
while (1){
int recvlen=purlval_srt->purl_ptl->url_read(&purlval_srt->url_ctt,data,sizeof(data));
if(recvlen>0){
if (urlval_udp.purl_ptl->url_write(&urlval_udp.url_ctt, data , recvlen)<0){
printf("url_write failed\r\n");
break;
}
}
}
urlval_udp.purl_ptl->url_close(&urlval_udp.url_ctt);
return NULL;
}
int main(int argc, char **argv)
{
mslog_api_init( 54, ms_null,ms_null, ms_null);
if(3!=argc){
ms_error("usage:%s inurl(srt) outurl(udp)",argv[0]);
mslog_api_deinit();
return -1;
}
pinurl=argv[1];
pouturl=argv[2];
msptc_api_init();
msptc_api_register();
URLVal urlval_srt;
memset(&urlval_srt,0,sizeof(URLVal));
urlval_srt.purl_ptl=msptc_api_match(PTLNAME_SRT);
ms_memset(&urlval_srt.url_ctt,0,sizeof(URLContext));
ms_strcpy(urlval_srt.url_ctt.url, pinurl);
urlval_srt.url_ctt.urlctt_opt.srt_opt.listen=1;
if(urlval_srt.purl_ptl->url_open(&urlval_srt.url_ctt)<0){
ms_errExit(-1, "Open out url failed");
}
char buf[2048]={0};
int len=0;
int recver=0;
while(1){
recver=urlval_srt.purl_ptl->priv_func.srt.accept(&urlval_srt.url_ctt);
if(recver<0){
ms_errRet(-1, "url_accept error");
}
pthread_t rcvthread;
pthread_create(&rcvthread, NULL, srtserver_send, &urlval_srt);
ms_sleep(1);
}
urlval_srt.purl_ptl->url_close(&urlval_srt.url_ctt);
msptc_api_deinit();
mslog_api_deinit();
}
#undef MAIN_C