当前位置:网站首页>Hisilicon hi3531 | Ruixin micro rk1109 realizes H264 streaming with RTSP server
Hisilicon hi3531 | Ruixin micro rk1109 realizes H264 streaming with RTSP server
2022-07-22 08:58:00 【I&You】
Hayes Hi3531|| Ruixin micro RK1109 use rtsp The server realizes streaming
understand RTP baotou
commonly RTSP The flow is based on UDP Agreement based , Header of each package (12 Bytes ) We call it RTP baotou
understand H264 Of nalu head
RTP Package format 1 :RTP baotou +nalu head ( A byte )+ data
Format two :RTP baotou +fu Subcontracting head ( Two bytes )+ data
Format 1
When nalu Data less than or equal to RTP The maximum length of the package will be
nalu Header format :
F:forbidden_zero_bit.1 position , If there is a syntax conflict , Then for 1. When the network recognizes that there is a bit error in this unit , You can set it to 1, So that the receiver can lose the unit .
NRI:nal_ref_idc.2 position , Used to indicate that NALU The importance level of . The bigger the value is. , At present NALU The more important . More specific than 0 What value is taken when , There is no specific provision .
Type:5 position , Pointed out that NALU The type of . The details are shown in the table :
Format two
When nalu The data is greater than RTP The maximum length of the package will be
fu Subcontracting header format :
First byte :
Follow up nalu The head is the same , It's just Type=28 nothing more
The second byte :
S: 1 bit When set to 1, The start bit indicates fragmentation NAL The beginning of the unit . When following FU The load is not piecewise NAL Start of unit load , The start bit is set to 0.
E: 1 bit When set to 1, The end bit indicates fragmentation NAL The end of the unit , namely , The last byte of the load is also divided NAL The last byte of the unit .
When following FU The load is not piecewise NAL The last piece of the unit , The end bit is set to 0.
If it's not the first package and the last package S and E Set to 0
R: 1 bit
Must be set to reserved bit 0, The receiver must ignore this bit .
Type: 5 bits
Here Type Namely NALU In the header Type, take 1-23 The value of , Express NAL Unit load type definition
Server source code
main function
RTSP_PROGRESS_1 function
EventLoop_1 function
ScheduleConnections Function call RtspServer
RtspServer function
This function is RTSP The process that the server processes all kinds of received data and returns data . If you call the change function ERR_CONNECTION_CLOSE and ERR_GENERIC These two kinds of mistakes , Some resources will be released , It is mainly about the handling of connection problems .
int RtspServer(RTSP_buffer *rtsp, int rtsp_num)
{
fd_set rset,wset; /* Reading and writing I/O Description set */
struct timeval t;
int size;
static char buffer[RTSP_BUFFERSIZE+1]; /* +1 to control the final '\0'*/
int n;
int res;
struct sockaddr ClientAddr;
#ifdef RTSP_DEBUG
// fprintf(stderr, "%s, %d\n", __FUNCTION__, __LINE__);
#endif
// memset((void *)&ClientAddr,0,sizeof(ClientAddr));
if (rtsp == NULL)
{
return ERR_NOERROR;
}
/* Variable initialization */
FD_ZERO(&rset);
FD_ZERO(&wset);
t.tv_sec=0; /*select The time interval */
t.tv_usec=100000;
FD_SET(rtsp->fd,&rset);
/* call select Wait for the corresponding descriptor to change */
if (select(g_s32Maxfd+1,&rset,0,0,&t)<0)
{
fprintf(stderr,"select error %s %d\n", __FILE__, __LINE__);
send_reply(500, NULL, rtsp);
return ERR_GENERIC; //errore interno al server
}
/* There is something to read rtsp package */
if (FD_ISSET(rtsp->fd,&rset))
{
memset(buffer,0,sizeof(buffer));
size=sizeof(buffer)-1; /* The last bit is used to fill in the string end identifier */
/* Read data into buffer */
#ifdef RTSP_DEBUG
// fprintf(stderr, "tcp_read, %d\n", __LINE__);
#endif
n= tcp_read(rtsp->fd, buffer, size, &ClientAddr);
if (n==0)
{
return ERR_CONNECTION_CLOSE;
}
if (n<0)
{
fprintf(stderr,"read() error %s %d\n", __FILE__, __LINE__);
send_reply(500, NULL, rtsp); // Server internal error message
return ERR_GENERIC;
}
// Check whether the read data overflows
if (rtsp->in_size+n>RTSP_BUFFERSIZE)
{
fprintf(stderr,"RTSP buffer overflow (input RTSP message is most likely invalid).\n");
send_reply(500, NULL, rtsp);
return ERR_GENERIC;// Data overflow error
}
#ifdef RTSP_DEBUG
fprintf(stderr,"INPUT_BUFFER was:%s\n", buffer);
#endif
/* Fill in the data */
memcpy(&(rtsp->in_buffer[rtsp->in_size]),buffer,n);
rtsp->in_size+=n;
// Empty buffer
memset(buffer, 0, n);
// Add client address information
memcpy( &rtsp->stClientAddr, &ClientAddr, sizeof(ClientAddr));
/* Processing buffer data , Conduct rtsp Handle */
if ((res=RTSP_handler(rtsp, rtsp_num))==ERR_GENERIC)
{
fprintf(stderr,"Invalid input message.\n");
return ERR_NOERROR;
}
}
/* Send data */
if (rtsp->out_size>0)
{
// Send data out
n= tcp_write(rtsp->fd,rtsp->out_buffer,rtsp->out_size);
if (n<0)
{
fprintf(stderr,"tcp_write error %s %i\n", __FILE__, __LINE__);
send_reply(500, NULL, rtsp);
return ERR_GENERIC; //errore interno al server
}
#ifdef RTSP_DEBUG
//fprintf(stderr,"OUTPUT_BUFFER length %d\n%s\n", rtsp->out_size, rtsp->out_buffer);
#endif
// Empty the send buffer
memset(rtsp->out_buffer, 0, rtsp->out_size);
rtsp->out_size = 0;
}
// if necessary RTCP Join right here RTCP Data reception , And stored in the cache .
// And then in schedule_do Process it in the thread .
//rtcp Control processing , Check read RTCP The datagram
return ERR_NOERROR;
}
RTSP_handler function
RTSP_state_machine function
Main call RTSP_state_machine(pRtspBuf, s32Meth); Function to process various client request messages , Then respond to the corresponding response message .
The appended drawings , Client and server RTSP Interaction protocol
schedule1_do function
The function is too long to post
This is in RTSP_PROGRESS_1 Medium ScheduleInit_1 Call in function
schedule_do The main function is to open h264 A file called RtpSend Function to package data RTP Send out .
VLC Play successful
Source download
It's not easy to blog , If you are concerned , Remember to like the collection, thank you ~~~~; If you have questions, you can add VX:a812417530
边栏推荐
- 海思Hi3531||瑞芯微RK1109用rtsp服务器实现h264推流
- JS 数组常用操作全集
- In quantitative trading, it is judged by the moving average system that the upward (downward) momentum is weakened
- Machine learning by Li Hongyi 5 Tips for neural network design
- Typo in static class property declarationeslint
- 指针深度进阶《六》(二维数组相关知识)
- IO 模型详解(通俗易懂)
- Differences between runtime+compiler and runtime only versions
- How to open an account for agricultural futures? Who can open Everbright futures?
- grep,egrep,fgrep字符匹配
猜你喜欢
Self study golang [3.6 slice practice code] slice length, upper limit, copy, delete and increase
serialization and deserialization
类的加载机制以及双亲委托机制
Self study golang [3.3go language loop statement] for loop syntax structure, omit initial conditions, omit incremental conditions, omit the application of end conditions
Quantitative transaction journal - fallback analysis - February 6, 2021
Quantitative transaction Diary - summary in February 2021
Pointer depth solution "II" (pointer points to itself)
La Fondation n'est pas assez solide pour secouer la montagne
海思[Hi3531]GPIO亮灯应用程序和寄存器操作
It takes several years for a trading system to be a successful trading system, and how many years for a profit to be stable?
随机推荐
Advanced pointer depth "six" (two-dimensional array related knowledge)
海思Hi3531||瑞芯微RK1109用rtsp服务器实现h264推流
监督学习(回归、分类问题)与无监督学习(聚类问题)
Science and technology create value | cloud expansion technology is listed in the real list · top 100 of China's scientific and technological innovation brands list
js 判断数据是否为空
js bind
Cannot read property ‘type‘ of undefined Occurred while linting **\index.jsx:1
5G和移动边缘计算服务器如何打造智慧园区
OSPF 重发布
管道,重定向以及正则表达式
刨根问底丨落后的技术,能否造出好卖的产品?
文件操作以及相关函数
2022年华泰开户网上办理安全吗?
海思[Hi3531] Onvif+Gosap自动搜索IP_Discovery和PTZ的实现
Formation and destruction of function stack frames (26 pictures help you understand function stack frames in depth)
Explain the usage of stack, heap and method area in memory
指针总结篇
海思Hi3531||瑞芯微RK1109用rtsp客户端实现h264拉流
JS object deep copy
Quantify three types of market in trading