首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往
您找到你想要的搜索结果了吗?
是的
没有找到

最近做RTSP流媒体的实时广播节目

//h264视频流打包代码 // NALDecoder.cpp : Defines the entry point for the console application. #include <stdio.h> #include <stdlib.h> #include <string.h> #include <memory.h> #include “h264.h” #include “initsock.h” CInitSock initSock;  // 初始化Winsock库 //为NALU_t结构体分配内存空间 NALU_t *AllocNALU(int buffersize) {  NALU_t *pNalu;  if ((pNalu = (NALU_t*)calloc (1, sizeof (NALU_t))) == NULL) {   printf(“AllocNALU: Nalu”);   exit(0);  }  pNalu->max_size=buffersize;  if ((pNalu->buf = (char*)calloc (buffersize, sizeof (char))) == NULL) {   free (pNalu);   printf (“AllocNALU: Nalu->buf”);   exit(0);  }  return pNalu; } //释放 void FreeNALU(NALU_t *pNalu) {  if (pNalu) {   if (pNalu->buf) {    free(pNalu->buf);    pNalu->buf=NULL;   }   free (pNalu);  } } static int FindStartCode2 (unsigned char *Buf) {  if(Buf[0]!=0 Buf[1]!=0 Buf[2] !=1) return 0; //推断是否为0x000001,假设是返回1  else return 1; } static int FindStartCode3 (unsigned char *Buf) {  if(Buf[0]!=0 Buf[1]!=0 Buf[2] !=0 Buf[3] !=1) return 0;//推断是否为0x00000001,假设是返回1  else return 1; } // 这个函数输入为一个NAL结构体。主要功能为得到一个完整的NALU并保存在NALU_t的buf中,获取他的长度。填充F,IDC,TYPE位。 // 而且返回两个開始字符之间间隔的字节数,即包括有前缀的NALU的长度 int GetAnnexbNALU (NALU_t *pNalu, FILE *bits) {  int info2=0, info3=0;  int pos = 0;  int StartCodeFound, rewind;  unsigned char *Buf;  if ((Buf = (unsigned char*)calloc (pNalu->max_size , sizeof(char))) == NULL)   printf (“GetAnnexbNALU: Could not allocate Buf memory\n”);  if (3 != fread (Buf, 1, 3, bits)) {  //从码流中读3个字节   free(Buf);   return -1;     }  if (Buf[0]!=0 Buf[1]!=0) {   free(Buf);   return -1;  }  if (Buf[2]==1) {   pNalu->startcodeprefix_len=3;   //初始化码流序列的開始字符为3个字节   pos =3;  }else {   if (1 != fread (Buf+3, 1, 1, bits)) {  //从码流中读1个字节    free(Buf);    return -1;   }   if (Buf[2]!=0 Buf[3]!=1) {    free(Buf);    return -1;   }   pos = 4;   pNalu->startcodeprefix_len = 4;  }  //查找下一个開始字符的标志位  StartCodeFound = 0;  info2 = 0;  info3 = 0;     while (!StartCodeFound)  {   if (feof (bits)) { //推断是否到了文件尾    break;   }   Buf[pos++] = fgetc (bits);//读一个字节到BUF中   info3 = FindStartCod

01
领券