当前位置:网站首页>RTP sending PS stream zero copy scheme
RTP sending PS stream zero copy scheme
2022-06-30 16:41:00 【qianbo_ insist】
The code is still there gitee On , Gradual modification
https://gitee.com/guanzhi0319/rtp
Data reach send RTP
After data collection , code h264, perhaps h265, send out ps Stream or h264 Raw stream to the specified server .
void LiveRTPUdpEncoder::OnCaptureVideoBuffer(uint8_t *data, int len, unsigned int timestamp, bool isKeyframe)
{
#define D(x) *(data+x)
if (SimpleThread::IsStop()) return;
#if 0
char buffer[32];
sprintf_s(buffer, "QB:%02x %02x %02x %02x %02x %02x",
D(0), D(1), D(2), D(3), D(4), D(5));
OutputDebugStringA(buffer);
return;
#endif
uint8_t* odata = NULL;
int olen = 0;
uint8_t n = D(4) & 0x1f;
int isIFrame = n == 0x07;
switch (v_stream_type)
{
case en_rtp:
odata = data;
olen = len;
break;
case en_ps_over_rtp:
uint8_t* odata;
int olen;
v_ps.packagingPs(isIFrame, timestamp, data, len, &odata, &olen);
break;
}
//timestamp = GetTimestamp();
{
Lock lock(this);
if(v_stream_type == en_ps_over_rtp)
{
uint8_t* ps = odata + RTP_UDP_HEAD_LEN;
olen = olen - RTP_UDP_HEAD_LEN;
v_rtp.send_video_ps(ps, olen, convertToRTPTimestamp(), isKeyframe);
delete[]odata;
}
else if (v_stream_type == en_rtp)
{
v_rtp.send_video(odata, olen, convertToRTPTimestamp(), isKeyframe);
}
if (!gVideoBegin)
gVideoBegin = true;
}
}
send out RTP ps
stay ps Leave blank in front of the stream 12 byte , Every time 1400 When bytes are sent , Change the front 12 byte RTP package , Note that the packet has been modified , Do not reuse , And the transmission must be synchronized to be correct , The benefit is to avoid data copying .
There are two ways to avoid data copying ,
1、 One is the synchronous buffer , But send asynchronously
2、 The synchronous
3、 Use the process , The synchronous .
This is the client side , There is only one way to send , Used UDP, Just send it synchronously . apply ps In order not to copy data in memory , The front is left blank 12 Bytes as RTP UDP The head of . So when sending every other packet , Push forward the data sent 12 byte , Avoid copying , But this changes the data in the buffer , If you want to reuse , Every time you cover it, put 12 Byte assignment , sent , Restore the bytes .
int c_rtp::send_video_ps(uint8_t* data, int len, uint32_t timestamp, bool iskeyframe)
{
//data There is 12 Byte is empty , structure ps Leave blank when streaming
uint8_t* x = data;
int num = (len - 1) / 1400 + 1;
for (int i = 0; i < num; i++)
{
uint8_t* pos = x - 12;
memset(pos, 0, 12);
RTP_FIXED_HEADER* rtp_hdr; //RTP Head
rtp_hdr = (RTP_FIXED_HEADER*)data;
// Set up RTP HEADER,
rtp_hdr->payload = H264; // Load type number ,
rtp_hdr->version = 2; // Version number , This version is fixed to 2
rtp_hdr->marker = 0; // Sign a , Its value is specified by specific agreement .
rtp_hdr->ssrc = little2big(1111);
rtp_hdr->timestamp = little2big(timestamp);
if (i < num-1)
v_sock.SendTo(pos, 12 + 1400, v_sockaddr);
else
v_sock.SendTo(pos, 12 + len -1400*i,v_sockaddr);
x += 1400;
}
}
there v_sock It is simply synchronous sending socket. Readers are interested in , You can change to asynchronous mode by yourself .
边栏推荐
- 【活动报名】探秘元宇宙,就差你了!7月2号我在深圳现场等你!
- 观测云与 TDengine 达成深度合作,优化企业上云体验
- Solution for IIS failing to load font files (*.woff, *.svg)
- Table responsive layout tips for super nice
- Arcmap操作系列:80平面转经纬度84
- 电子烟强制性国家标准GB 41700-2022发布 2022年10月1日起实施
- AVIC UAV technology innovation board is listed: the fist product with a market value of 38.5 billion is pterodactyl UAV
- [CVE-2019-0193] - Apache Solr DataImport 远程命令执行分析
- [Verilog quick start of Niuke online question series] ~ bit splitting and operation
- 【机器学习】K-means聚类分析
猜你喜欢

云化XR,如何助力产业升级

Rongsheng biology rushes to the scientific innovation board: it plans to raise 1.25 billion yuan, with an annual revenue of 260million yuan

什么是XR扩展现实,XR云串流平台有哪些
MySQL开放远程连接权限的两种方法

MySQL transaction / lock / log summary

How the edge computing platform helps the development of the Internet of things

优惠券种类那么多,先区分清楚再薅羊毛!

猎头5万挖我去VC

CVPR 2022 - Tesla AI proposed: generalized pedestrian re recognition based on graph sampling depth metric learning

AVIC UAV technology innovation board is listed: the fist product with a market value of 38.5 billion is pterodactyl UAV
随机推荐
2020 Blue Bridge Cup group B - move bricks - (greedy sorting +01 backpack)
“低代码”在企业数字化转型中扮演着什么角色?
How cloudxr promotes the future development of XR
topic: Privacy, Deception and Device Abuse
Carry two load balancing notes and find them in the future
MySQL transaction / lock / log summary
Headhunter 50, 000, I'll go to VC
BC1.2 PD协议
Three development trends of enterprise application viewed from the third technological revolution
备战数学建模35-时间序列预测模型
赛芯电子冲刺科创板:拟募资6.2亿 实控人谭健为美国籍
Halcon knowledge: matrix topic [02]
Additional: (not written yet, don't look at ~ ~ ~) corsfilter filter;
云和恩墨中标天津滨海农村商业银行2022-2023年度Oracle维保项目
附加:(还没写,别看~~~)CorsFilter过滤器;
go-zero微服务实战系列(八、如何处理每秒上万次的下单请求)
备战数学建模36-时间序列模型2
2022蓝桥杯国赛B组-费用报销-(线性dp|状态dp)
mysql8报错:ERROR 1410 (42000): You are not allowed to create a user with GRANT解决办法
Is your light on? Before you start to solve a problem, you need to know what the "real problem" is