Linux 下RTP实时打包发送H.264码流


Linux 下RTP实时打包发送H.264码流
资源截图
代码片段和文件信息
/*============================================================================= 
 *     FileName: rtp.c 
 *         Desc: rtp payload h.264 data 
 *       Author: licaibiao 
 *   LastChange: 2017-04-07  
 * =============================================================================*/
#include   
#include   
#include   
#include     
#include   
#include   
#include 
#include   
#include  
#include  
#include “rtp.h“  

//#define DEBUG_LOG

typedef struct  
{  
int startcodeprefix_len;      //! 4 for parameter sets and first slice in picture 3 for everything else (suggested)  
unsigned len;                 //! Length of the NAL unit (Excluding the start code which does not belong to the NALU)  
unsigned max_size;            //! Nal Unit Buffer size  
int forbidden_bit;            //! should be always FALSE  
int nal_reference_idc;        //! NALU_PRIORITY_xxxx  
int nal_unit_type;            //! NALU_TYPE_xxxx      
char *buf;                    //! contains the first byte followed by the EBSP  
unsigned short lost_packets;  //! true if packet loss is detected  
} NALU_t;  

FILE *bits = NULL;              //!< the bit stream file  
static int FindStartCode2 (unsigned char *Buf);//查找开始字符0x000001  
static int FindStartCode3 (unsigned char *Buf);//查找开始字符0x00000001  
static int info2=0;
static int info3=0; 
RTP_FIXED_HEADER *rtp_hdr;  
NALU_HEADER      *nalu_hdr;  
FU_INDICATOR     *fu_ind;  
FU_HEADER        *fu_hdr;  

NALU_t *AllocNALU(int buffersize)  
{  
NALU_t *n;  
if ((n = (NALU_t*)calloc (1 sizeof (NALU_t))) == NULL)  
{  
printf(“AllocNALU: n“);  
exit(0);  
}  
n->max_size = buffersize;  
if((n->buf = (char*)calloc (buffersize sizeof (char))) == NULL)  
{  
free (n);  
printf (“AllocNALU: n->buf“);  
exit(0);  
}  
return n;  
}  

void FreeNALU(NALU_t *n)  
{  
if (n)  
{  
if (n->buf)  
{  
free(n->buf);  
n->buf=NULL;  
}  
free (n);  
}  
}  

void OpenBitstreamFile (char *fn)  
{  
if (NULL == (bits = fopen(fn “rb“)))  
{  
printf(“open file error
“);  
exit(0);  
}  
}  

//这个函数输入为一个NAL结构体,主要功能为得到一个完整的NALU并保存在NALU_t的buf中,获取他的长度,填充FIDCTYPE位。  
//并且返回两个开始字符之间间隔的字节数,即包含有前缀的NALU的长度
//前缀之后的第一个字节为 NALU_HEADER   
int GetAnnexbNALU (NALU_t *nalu)  
{  
int pos = 0;  
int rewind; 
int StartCodeFound;
unsigned char *Buf;  

if ((Buf = (unsigned char*)calloc (nalu->max_size  sizeof(char))) == NULL)
printf (“GetAnnexbNALU: Could not allocate Buf memory
“);  

printf(“nalu->max_size=%d
“(int)nalu->max_size);
memset(Buf0nalu->max_size);
nalu->startcodeprefix_len = 3;//初始化码流序列的开始字符为3个字节  
if (3 != fread (Buf 1 3 bits))//从码流中读3个字节  
{  
free(Buf);  
return 0;  
}  
info2 = FindStartCode2 (Buf);//判断是否为0x000001   
if(info2 != 1)   
{  
//如果不是,

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件举报,一经查实,本站将立刻删除。

发表评论

评论列表(条)