• 大小: 5KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-06-04
  • 语言: 其他
  • 标签: RTP协议  H264  

资源简介

通过RTP发送h264码流,网上比较多的版本,可在上位机用vlc播放,是一个学习rtp协议的好例子

资源截图

代码片段和文件信息

// NALDecoder.cpp : Defines the entry point for the console application.
//


#include 
#include 
#include 
#include 
#include “rtp.h“

#include 
#include 
#include 

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 bool flag = true;
static int info2=0 info3=0;
RTP_FIXED_HEADER        *rtp_hdr;

NALU_HEADER *nalu_hdr;
FU_INDICATOR *fu_ind;
FU_HEADER *fu_hdr;

/*BOOL InitWinsock()
{
    int Error;
    WORD VersionRequested;
    WSADATA WsaData;
    VersionRequested=MAKEWORD(22);
    Error=WSAStartup(VersionRequested&WsaData); //启动WinSock2
    if(Error!=0)
    {
        return FALSE;
    }
    else
    {
        if(LOBYTE(WsaData.wVersion)!=2||HIBYTE(WsaData.wHighVersion)!=2)
        {
            WSACleanup();
            return FALSE;
        }
        
    }
    return TRUE;
}*/

//为NALU_t结构体分配内存空间
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\n“);
  exit(0);
  }
}
//这个函数输入为一个NAL结构体,主要功能为得到一个完整的NALU并保存在NALU_t的buf中,获取他的长度,填充FIDCTYPE位。
//并且返回两个开始字符之间间隔的字节数,即包含有前缀的NALU的长度
int GetAnnexbNALU (NALU_t *nalu)
{
  int pos = 0;
  int StartCodeFound rewind;
  unsigned char *Buf;
    
  if ((Buf = (unsigned char*)calloc (nalu->max_size  sizeof(char))) == NULL) 
  printf (“GetAnnexbNALU: Could not allocate Buf memory\n“);

  nalu->startcodeprefix_len=3;//初始化码流序列的开始字符为3个字节
  
   if (3 != fread (Buf 1 3 bits))//从码流中读3个字节
   {
free(Buf);
return 0;
   }
   info2 = FindStartCode2 (Buf);//判断是否为0x000001 
   if(info2 != 1) 
   {
//如果不是,再读一个字节
    if(1 != fread(Buf+3 1 1 bits))//读一个字节
{
 free(Buf);
 return 0;
}
    info3 = FindStartCode3 (Buf);//判断是否为0x00000001
    

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2015-04-18 16:27  RTP_H264\
     文件       13192  2015-04-15 17:32  RTP_H264\rtp.c
     文件        1516  2013-09-23 11:43  RTP_H264\rtp.h

评论

共有 条评论