00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "global.h"
00016 #include "nalu.h"
00017 #include "nal.h"
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044 int RBSPtoNALU (unsigned char *rbsp, NALU_t *nalu, int rbsp_size, int nal_unit_type, int nal_reference_idc, int UseAnnexbLongStartcode)
00045 {
00046 int len;
00047
00048 assert (nalu != NULL);
00049 assert (nal_reference_idc <=3 && nal_reference_idc >=0);
00050 assert (nal_unit_type > 0 && nal_unit_type <= 12);
00051 assert (rbsp_size < MAXRBSPSIZE);
00052
00053 nalu->startcodeprefix_len = UseAnnexbLongStartcode ? 4 : 3;
00054 nalu->forbidden_bit = 0;
00055 nalu->nal_reference_idc = (NalRefIdc) nal_reference_idc;
00056 nalu->nal_unit_type = (NaluType) nal_unit_type;
00057
00058 len = RBSPtoEBSP (nalu->buf, rbsp, rbsp_size);
00059 nalu->len = len;
00060
00061 return len;
00062 }
00063
00064
00065
00066
00067
00068
00069
00070
00071 int Write_AUD_NALU( ImageParameters *p_Img )
00072 {
00073 int RBSPlen = 0;
00074 int NALUlen, len;
00075 byte rbsp[MAXRBSPSIZE];
00076 NALU_t *nalu = AllocNALU( MAXNALUSIZE );
00077
00078 switch( p_Img->type )
00079 {
00080 case I_SLICE:
00081 p_Img->primary_pic_type = 0;
00082 break;
00083 case P_SLICE:
00084 p_Img->primary_pic_type = 1;
00085 break;
00086 case B_SLICE:
00087 p_Img->primary_pic_type = 2;
00088 break;
00089 }
00090 RBSPlen = 1;
00091 rbsp[0] = (byte) (p_Img->primary_pic_type << 5);
00092 rbsp[0] |= (1 << 4);
00093
00094
00095 NALUlen = RBSPtoNALU( rbsp, nalu, RBSPlen, NALU_TYPE_AUD, NALU_PRIORITY_DISPOSABLE, 1 );
00096
00097 len = p_Img->WriteNALU( p_Img, nalu );
00098
00099 FreeNALU( nalu );
00100
00101 return len;
00102 }
00103
00104
00105
00106
00107
00108
00109
00110
00111 int Write_Filler_Data_NALU( ImageParameters *p_Img, int num_bytes )
00112 {
00113 int RBSPlen = num_bytes - 1;
00114 int NALUlen, len, bytes_written = 0;
00115 byte rbsp[MAXRBSPSIZE];
00116 NALU_t *nalu = AllocNALU( MAXNALUSIZE );
00117
00118 num_bytes = iClip3( 1, (MAXRBSPSIZE - 2), num_bytes );
00119 assert( num_bytes > 0 && num_bytes < (MAXRBSPSIZE - 1) );
00120
00121 while ( bytes_written < RBSPlen )
00122 {
00123 rbsp[ bytes_written++ ] = 0xFF;
00124 }
00125 rbsp[ bytes_written++ ] = 0x80;
00126
00127 assert( num_bytes == bytes_written );
00128
00129
00130 NALUlen = RBSPtoNALU( rbsp, nalu, RBSPlen, NALU_TYPE_FILL, NALU_PRIORITY_HIGHEST, 1 );
00131
00132 len = p_Img->WriteNALU( p_Img, nalu );
00133 p_Img->bytes_in_picture += (nalu->len + 1);
00134
00135 FreeNALU( nalu );
00136
00137 return len;
00138 }