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