00001
00015 #include "global.h"
00016 #include "nalu.h"
00017 #include "annexb.h"
00018 #include "rtp.h"
00019
00020 BitsFile bitsfile;
00021
00022 static int LastAccessUnitExists = 0;
00023 static int NALUCount = 0;
00024
00025
00037 void initBitsFile (int filemode)
00038 {
00039 switch (filemode)
00040 {
00041 case PAR_OF_ANNEXB:
00042 bitsfile.OpenBitsFile = OpenAnnexBFile;
00043 bitsfile.CloseBitsFile = CloseAnnexBFile;
00044 bitsfile.GetNALU = GetAnnexbNALU;
00045 break;
00046 case PAR_OF_RTP:
00047 bitsfile.OpenBitsFile = OpenRTPFile;
00048 bitsfile.CloseBitsFile = CloseRTPFile;
00049 bitsfile.GetNALU = GetRTPNALU;
00050 break;
00051 default:
00052 error ("initBitsFile: Unknown bitstream file mode", 255);
00053 break;
00054 }
00055 }
00056
00070 static int NALUtoRBSP (NALU_t *nalu)
00071 {
00072 assert (nalu != NULL);
00073
00074 nalu->len = EBSPtoRBSP (nalu->buf, nalu->len, 1) ;
00075
00076 return nalu->len ;
00077 }
00078
00085 int read_next_nalu(NALU_t *nalu)
00086 {
00087 int ret;
00088
00089 ret = bitsfile.GetNALU(nalu);
00090
00091 if (ret < 0)
00092 {
00093 snprintf (errortext, ET_SIZE, "Error while getting the NALU in file format %s, exit\n", params->FileFormat==PAR_OF_ANNEXB?"Annex B":"RTP");
00094 error (errortext, 601);
00095 }
00096 if (ret == 0)
00097 {
00098 FreeNALU(nalu);
00099 return 0;
00100 }
00101
00102
00103
00104 CheckZeroByteNonVCL(nalu);
00105
00106 ret = NALUtoRBSP(nalu);
00107
00108 if (ret < 0)
00109 error ("Invalid startcode emulation prevention found.", 602);
00110
00111
00112
00113 if (nalu->forbidden_bit)
00114 {
00115 error ("Found NALU with forbidden_bit set, bit error?", 603);
00116 }
00117
00118 return nalu->len;
00119 }
00120
00121 void CheckZeroByteNonVCL(NALU_t *nalu)
00122 {
00123 int CheckZeroByte=0;
00124
00125
00126 if(nalu->nal_unit_type>=1&&nalu->nal_unit_type<=5)
00127 return;
00128
00129
00130 if(nalu->nal_unit_type==NALU_TYPE_SPS || nalu->nal_unit_type==NALU_TYPE_PPS)
00131 CheckZeroByte=1;
00132
00133 if(nalu->nal_unit_type==NALU_TYPE_AUD || nalu->nal_unit_type==NALU_TYPE_SPS ||
00134 nalu->nal_unit_type==NALU_TYPE_PPS || nalu->nal_unit_type==NALU_TYPE_SEI ||
00135 (nalu->nal_unit_type>=13 && nalu->nal_unit_type<=18))
00136 {
00137 if(LastAccessUnitExists)
00138 {
00139 LastAccessUnitExists=0;
00140 NALUCount=0;
00141 }
00142 }
00143 NALUCount++;
00144
00145 if(NALUCount==1)
00146 CheckZeroByte=1;
00147 if(CheckZeroByte && nalu->startcodeprefix_len==3)
00148 {
00149 printf("Warning: zero_byte shall exist\n");
00150
00151 }
00152 }
00153
00154 void CheckZeroByteVCL(NALU_t *nalu)
00155 {
00156 int CheckZeroByte=0;
00157
00158
00159 if(!(nalu->nal_unit_type>=1&&nalu->nal_unit_type<=5))
00160 return;
00161
00162 if(LastAccessUnitExists)
00163 {
00164 NALUCount=0;
00165 }
00166 NALUCount++;
00167
00168
00169 if(NALUCount == 1)
00170 CheckZeroByte = 1;
00171 LastAccessUnitExists = 1;
00172 if(CheckZeroByte && nalu->startcodeprefix_len==3)
00173 {
00174 printf("warning: zero_byte shall exist\n");
00175
00176 }
00177 }