亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? annexb.c

?? h264標準的VC實現
?? C
字號:

/*!
 *************************************************************************************
 * \file annexb.c
 *
 * \brief
 *    Annex B Byte Stream format
 *
 * \author
 *    Main contributors (see contributors.h for copyright, address and affiliation details)
 *      - Stephan Wenger                  <stewe@cs.tu-berlin.de>
 *************************************************************************************
 */

#include <stdlib.h>
#include <string.h>

#include "global.h"
#include "annexb.h"
#include "memalloc.h"


FILE *bits = NULL;                //!< the bit stream file
static int FindStartCode (unsigned char *Buf, int zeros_in_startcode);

int IsFirstByteStreamNALU=1;
int LastAccessUnitExists=0;
int NALUCount=0;


/*!
 ************************************************************************
 * \brief
 *    Returns the size of the NALU (bits between start codes in case of
 *    Annex B.  nalu->buf and nalu->len are filled.  Other field in
 *    nalu-> remain uninitialized (will be taken care of by NALUtoRBSP.
 *
 * \return
 *     0 if there is nothing any more to read (EOF)
 *    -1 in case of any error
 *
 *  \note Side-effect: Returns length of start-code in bytes. 
 *
 * \note
 *   GetAnnexbNALU expects start codes at byte aligned positions in the file
 *
 ************************************************************************
 */

int GetAnnexbNALU (NALU_t *nalu)
{
  int info2, info3, pos = 0;
  int StartCodeFound, rewind;
  char *Buf;
  int LeadingZero8BitsCount=0, TrailingZero8Bits=0;
    
  if ((Buf = (char*)calloc (nalu->max_size , sizeof(char))) == NULL) no_mem_exit("GetAnnexbNALU: Buf");

  while(!feof(bits) && (Buf[pos++]=fgetc(bits))==0);
  
  if(feof(bits))
  {
    if(pos==0)
    return 0;
    else
    {
      printf( "GetAnnexbNALU can't read start code\n");
      free(Buf);
      return -1;
    }
  }

  if(Buf[pos-1]!=1)
  {
    printf ("GetAnnexbNALU: no Start Code at the begin of the NALU, return -1\n");
    free(Buf);
    return -1;
  }

  if(pos<3)
  {
    printf ("GetAnnexbNALU: no Start Code at the begin of the NALU, return -1\n");
    free(Buf);
    return -1;
  }
  else if(pos==3)
  {
    nalu->startcodeprefix_len = 3;
    LeadingZero8BitsCount = 0;
  }
  else
  {
    LeadingZero8BitsCount = pos-4;
    nalu->startcodeprefix_len = 4;
  }

  //the 1st byte stream NAL unit can has leading_zero_8bits, but subsequent ones are not
  //allowed to contain it since these zeros(if any) are considered trailing_zero_8bits
  //of the previous byte stream NAL unit.
  if(!IsFirstByteStreamNALU && LeadingZero8BitsCount>0)
  {
    printf ("GetAnnexbNALU: The leading_zero_8bits syntax can only be present in the first byte stream NAL unit, return -1\n");
    free(Buf);
    return -1;
  }
  IsFirstByteStreamNALU=0;

  StartCodeFound = 0;
  info2 = 0;
  info3 = 0;

  while (!StartCodeFound)
  {
    if (feof (bits))
    {
      //Count the trailing_zero_8bits
      while(Buf[pos-2-TrailingZero8Bits]==0)
        TrailingZero8Bits++;
      nalu->len = (pos-1)-nalu->startcodeprefix_len-LeadingZero8BitsCount-TrailingZero8Bits;
      memcpy (nalu->buf, &Buf[LeadingZero8BitsCount+nalu->startcodeprefix_len], nalu->len);     
      nalu->forbidden_bit = (nalu->buf[0]>>7) & 1;
      nalu->nal_reference_idc = (nalu->buf[0]>>5) & 3;
      nalu->nal_unit_type = (nalu->buf[0]) & 0x1f;

// printf ("GetAnnexbNALU, eof case: pos %d nalu->len %d, nalu->reference_idc %d, nal_unit_type %d \n", pos, nalu->len, nalu->nal_reference_idc, nalu->nal_unit_type);

#if TRACE
  fprintf (p_trace, "\n\nLast NALU in File\n\n");
  fprintf (p_trace, "Annex B NALU w/ %s startcode, len %d, forbidden_bit %d, nal_reference_idc %d, nal_unit_type %d\n\n",
    nalu->startcodeprefix_len == 4?"long":"short", nalu->len, nalu->forbidden_bit, nalu->nal_reference_idc, nalu->nal_unit_type);
  fflush (p_trace);
#endif
      free(Buf);
      return pos-1;
    }
    Buf[pos++] = fgetc (bits);
    info3 = FindStartCode(&Buf[pos-4], 3);
    if(info3 != 1)
      info2 = FindStartCode(&Buf[pos-3], 2);
    StartCodeFound = (info2 == 1 || info3 == 1);
  }

  //Count the trailing_zero_8bits
  if(info3==1)	//if the detected start code is 00 00 01, trailing_zero_8bits is sure not to be present
  {
    while(Buf[pos-5-TrailingZero8Bits]==0)
      TrailingZero8Bits++;
  }
  // Here, we have found another start code (and read length of startcode bytes more than we should
  // have.  Hence, go back in the file
  rewind = 0;
  if(info3 == 1)
    rewind = -4;
  else if (info2 == 1)
    rewind = -3;
  else
    printf(" Panic: Error in next start code search \n");

  if (0 != fseek (bits, rewind, SEEK_CUR))
  {
    snprintf (errortext, ET_SIZE, "GetAnnexbNALU: Cannot fseek %d in the bit stream file", rewind);
    free(Buf);
    error(errortext, 600);
  }

  // Here the leading zeros(if any), Start code, the complete NALU, trailing zeros(if any)
  // and the next start code is in the Buf.
  // The size of Buf is pos, pos+rewind are the number of bytes excluding the next
  // start code, and (pos+rewind)-startcodeprefix_len-LeadingZero8BitsCount-TrailingZero8Bits
  // is the size of the NALU.

  nalu->len = (pos+rewind)-nalu->startcodeprefix_len-LeadingZero8BitsCount-TrailingZero8Bits;
  memcpy (nalu->buf, &Buf[LeadingZero8BitsCount+nalu->startcodeprefix_len], nalu->len);
  nalu->forbidden_bit = (nalu->buf[0]>>7) & 1;
  nalu->nal_reference_idc = (nalu->buf[0]>>5) & 3;
  nalu->nal_unit_type = (nalu->buf[0]) & 0x1f;


//printf ("GetAnnexbNALU, regular case: pos %d nalu->len %d, nalu->reference_idc %d, nal_unit_type %d \n", pos, nalu->len, nalu->nal_reference_idc, nalu->nal_unit_type);
#if TRACE
  fprintf (p_trace, "\n\nAnnex B NALU w/ %s startcode, len %d, forbidden_bit %d, nal_reference_idc %d, nal_unit_type %d\n\n",
    nalu->startcodeprefix_len == 4?"long":"short", nalu->len, nalu->forbidden_bit, nalu->nal_reference_idc, nalu->nal_unit_type);
  fflush (p_trace);
#endif
  
  free(Buf);
 
  return (pos+rewind);
}




/*!
 ************************************************************************
 * \brief
 *    Opens the bit stream file named fn
 * \return
 *    none
 ************************************************************************
 */
void OpenBitstreamFile (char *fn)
{
  if (NULL == (bits=fopen(fn, "rb")))
  {
    snprintf (errortext, ET_SIZE, "Cannot open Annex B ByteStream file '%s'", input->infile);
    error(errortext,500);
  }
}


/*!
 ************************************************************************
 * \brief
 *    Closes the bit stream file
 ************************************************************************
 */
void CloseBitstreamFile()
{
  fclose (bits);
}


/*!
 ************************************************************************
 * \brief
 *    returns if new start code is found at byte aligned position buf.
 *    new-startcode is of form N 0x00 bytes, followed by a 0x01 byte.
 *
 *  \return
 *     1 if start-code is found or                      \n
 *     0, indicating that there is no start code
 *
 *  \param Buf
 *     pointer to byte-stream
 *  \param zeros_in_startcode
 *     indicates number of 0x00 bytes in start-code.
 ************************************************************************
 */
static int FindStartCode (unsigned char *Buf, int zeros_in_startcode)
{
  int info;
  int i;

  info = 1;
  for (i = 0; i < zeros_in_startcode; i++)
    if(Buf[i] != 0)
      info = 0;

  if(Buf[i] != 1)
    info = 0;
  return info;
}

void CheckZeroByteNonVCL(NALU_t *nalu, int * ret)
{
  int CheckZeroByte=0;

  //This function deals only with non-VCL NAL units
  if(nalu->nal_unit_type>=1&&nalu->nal_unit_type<=5)
    return;

  //for SPS and PPS, zero_byte shall exist
  if(nalu->nal_unit_type==NALU_TYPE_SPS || nalu->nal_unit_type==NALU_TYPE_PPS)
    CheckZeroByte=1;
  //check the possibility of the current NALU to be the start of a new access unit, according to 7.4.1.2.3
  if(nalu->nal_unit_type==NALU_TYPE_AUD  || nalu->nal_unit_type==NALU_TYPE_SPS ||
     nalu->nal_unit_type==NALU_TYPE_PPS || nalu->nal_unit_type==NALU_TYPE_SEI ||
    (nalu->nal_unit_type>=13 && nalu->nal_unit_type<=18))
  {
    if(LastAccessUnitExists)
    {
      LastAccessUnitExists=0;		//deliver the last access unit to decoder
      NALUCount=0;
    }
  }
  NALUCount++;
  //for the first NAL unit in an access unit, zero_byte shall exists
  if(NALUCount==1)
    CheckZeroByte=1;
  if(CheckZeroByte && nalu->startcodeprefix_len==3)
  {
    printf("warning: zero_byte shall exist\n");
    //because it is not a very serious problem, we may not indicate an error by setting ret to -1
    //*ret=-1;
  }
}

void CheckZeroByteVCL(NALU_t *nalu, int * ret)
{
  int CheckZeroByte=0;

  //This function deals only with VCL NAL units
  if(!(nalu->nal_unit_type>=1&&nalu->nal_unit_type<=5))
    return;

  if(LastAccessUnitExists)
  {
    NALUCount=0;
  }
  NALUCount++;
  //the first VCL NAL unit that is the first NAL unit after last VCL NAL unit indicates 
  //the start of a new access unit and hence the first NAL unit of the new access unit.						(sounds like a tongue twister :-)
  if(NALUCount==1)
    CheckZeroByte=1;
  LastAccessUnitExists=1;
  if(CheckZeroByte && nalu->startcodeprefix_len==3)
  {
	  printf("warning: zero_byte shall exist\n");
	  //because it is not a very serious problem, we may not indicate an error by setting ret to -1
	  //*ret=-1;
  }
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
久久久精品蜜桃| 国产精品久久久久久户外露出 | 日韩精品视频网| hitomi一区二区三区精品| 欧美色中文字幕| 中文字幕乱码久久午夜不卡| 五月天欧美精品| 91蜜桃免费观看视频| 2023国产精品| 蜜臀久久99精品久久久画质超高清| 成人精品gif动图一区| 日韩片之四级片| 亚洲愉拍自拍另类高清精品| 成人av动漫在线| 久久婷婷久久一区二区三区| 日韩黄色在线观看| 欧美日韩在线免费视频| 国产精品久久久久久久午夜片| 久久成人精品无人区| 欧美日韩国产一级二级| 亚洲欧美aⅴ...| av一本久道久久综合久久鬼色| 精品国产乱码久久久久久蜜臀| 91理论电影在线观看| 久久综合国产精品| 美女高潮久久久| 91精品国产综合久久国产大片| 亚洲一区二区精品久久av| 91丨国产丨九色丨pron| 欧美国产日本韩| 懂色av一区二区夜夜嗨| 久久久久国产精品人| 国产老肥熟一区二区三区| 精品久久人人做人人爽| 另类调教123区| 欧美成人一区二区三区| 蜜臀av一区二区三区| 51精品国自产在线| 美女高潮久久久| 精品播放一区二区| 国产精品自拍一区| 亚洲国产精品传媒在线观看| 国产成人精品在线看| 亚洲国产精品ⅴa在线观看| 国产精品99久久久久久有的能看| 26uuu精品一区二区| 亚洲国产wwwccc36天堂| 中文字幕欧美激情一区| 亚洲日本在线a| 久久精品久久精品| 日韩欧美三级在线| 国产美女主播视频一区| 国产精品视频在线看| 99精品欧美一区| 一区二区成人在线视频| 欧美一区二区三区在| 精品综合久久久久久8888| 久久一留热品黄| 99久精品国产| 午夜精品国产更新| 久久精品水蜜桃av综合天堂| www.久久久久久久久| 亚洲国产乱码最新视频| 日韩精品最新网址| av亚洲精华国产精华精| 视频一区欧美精品| 国产日韩欧美一区二区三区综合| 成人综合在线视频| 亚洲国产精品久久不卡毛片 | 成人美女在线视频| 亚洲狠狠爱一区二区三区| 精品福利一区二区三区 | 一道本成人在线| 日本成人在线电影网| 国产三级久久久| 欧美精品一级二级| 成人黄色在线视频| 婷婷六月综合网| 国产精品乱码一区二区三区软件 | 国产精品一卡二| 成人影视亚洲图片在线| 一区二区三区在线视频观看| 制服丝袜激情欧洲亚洲| 国产91精品欧美| 免费在线一区观看| 亚洲男人天堂av网| 久久久久久免费网| 91精品国产入口在线| av福利精品导航| 精品一区二区免费看| 亚洲最色的网站| 国产精品久久久久久久久免费丝袜 | 国产精品国产三级国产普通话三级| 欧美三级资源在线| 97久久人人超碰| 国产一区中文字幕| 日韩国产欧美在线播放| 一区二区在线电影| 国产精品污网站| 精品日产卡一卡二卡麻豆| 欧美日韩你懂的| 91偷拍与自偷拍精品| 国产一区二区剧情av在线| 三级一区在线视频先锋 | 99精品热视频| 国产成人自拍高清视频在线免费播放| 午夜不卡av在线| 亚洲一区在线视频观看| 亚洲人午夜精品天堂一二香蕉| 久久久三级国产网站| 精品美女在线播放| 日韩免费电影网站| 欧美一区二区视频网站| 欧美日韩大陆一区二区| 欧美电影影音先锋| 在线观看91视频| 91成人在线观看喷潮| 在线区一区二视频| 欧洲一区二区av| 欧美性大战xxxxx久久久| 色琪琪一区二区三区亚洲区| 99精品视频中文字幕| eeuss鲁片一区二区三区| 成人午夜精品在线| 99精品黄色片免费大全| 99精品视频在线观看| 在线视频国产一区| 欧美人牲a欧美精品| 91精品国产黑色紧身裤美女| 日韩一级在线观看| wwww国产精品欧美| 国产精品国产三级国产普通话99| 欧美国产禁国产网站cc| 成人免费在线播放视频| 亚洲精品欧美激情| 亚洲777理论| 久久aⅴ国产欧美74aaa| 国产ts人妖一区二区| 色婷婷综合中文久久一本| 欧美三级韩国三级日本三斤| 欧美一区二区日韩一区二区| 久久综合狠狠综合久久激情| 中文字幕中文字幕中文字幕亚洲无线| 成人精品视频一区二区三区| 99久久久精品| 欧美精品高清视频| 久久久美女毛片| 一区二区三区中文字幕| 日韩精品一二三| 国产·精品毛片| 精品视频免费在线| 久久嫩草精品久久久久| 亚洲欧洲日韩在线| 日本中文字幕一区二区视频| 国产成人精品一区二| 欧美日韩久久久| 国产欧美日韩激情| 亚洲成av人综合在线观看| 国产河南妇女毛片精品久久久| 北条麻妃一区二区三区| 在线综合视频播放| 国产精品成人免费在线| 久久成人精品无人区| 在线观看一区二区精品视频| 精品美女一区二区| 亚洲成人在线免费| 成人免费视频一区二区| 欧美一区二区三区公司| 夜夜操天天操亚洲| 国产成人在线视频网址| 69堂精品视频| 亚洲精品成人在线| 国产a区久久久| 91麻豆精品国产自产在线观看一区 | 日韩一区二区三区高清免费看看| 国产精品久线在线观看| 青青草97国产精品免费观看 | 国产精品护士白丝一区av| 激情六月婷婷综合| 欧美日韩亚洲综合一区| 亚洲欧美综合网| 国产九色精品成人porny| 欧美一区二区三区视频在线观看| 亚洲精品视频自拍| 成人性生交大合| 久久久不卡网国产精品一区| 日本视频一区二区三区| 欧美日韩国产在线观看| 一区二区三区欧美日| 91视视频在线观看入口直接观看www | 国产三级精品三级| 国内精品嫩模私拍在线| 91精品国产手机| 日韩激情av在线| 91精品国产麻豆国产自产在线| 亚洲成在人线在线播放| 欧美日韩综合一区| 亚洲影视在线观看| 在线观看视频一区| 亚洲一区二区三区中文字幕|