00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "contributors.h"
00019 #include "global.h"
00020 #include "enc_statistics.h"
00021 #include "biariencode.h"
00022
00023 static const int MbWidthC [4]= { 0, 8, 8, 16};
00024 static const int MbHeightC [4]= { 0, 8, 16, 16};
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 void SODBtoRBSP(Bitstream *currStream)
00040 {
00041 currStream->byte_buf <<= 1;
00042 currStream->byte_buf |= 1;
00043 currStream->bits_to_go--;
00044 currStream->byte_buf <<= currStream->bits_to_go;
00045 currStream->streamBuffer[currStream->byte_pos++] = currStream->byte_buf;
00046 currStream->bits_to_go = 8;
00047 currStream->byte_buf = 0;
00048 }
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073 int RBSPtoEBSP(byte *NaluBuffer, unsigned char *rbsp, int rbsp_size)
00074 {
00075 int j = 0;
00076 int count = 0;
00077 int i;
00078
00079 for(i = 0; i < rbsp_size; i++)
00080 {
00081 if(count == ZEROBYTES_SHORTSTARTCODE && !(rbsp[i] & 0xFC))
00082 {
00083 NaluBuffer[j] = 0x03;
00084 j++;
00085 count = 0;
00086 }
00087 NaluBuffer[j] = rbsp[i];
00088 if(rbsp[i] == 0x00)
00089 count++;
00090 else
00091 count = 0;
00092 j++;
00093 }
00094 return j;
00095 }
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114 int addCabacZeroWords(ImageParameters *p_Img, NALU_t *nalu, StatParameters *cur_stats)
00115 {
00116 seq_parameter_set_rbsp_t *active_sps = p_Img->active_sps;
00117
00118 int stuffing_bytes = 0;
00119 int i = 0;
00120
00121 byte *buf = &nalu->buf[nalu->len];
00122
00123 int RawMbBits = 256 * p_Img->bitdepth_luma + 2 * MbWidthC[active_sps->chroma_format_idc] * MbHeightC[active_sps->chroma_format_idc] * p_Img->bitdepth_chroma;
00124 int min_num_bytes = ((96 * get_pic_bin_count(p_Img)) - (RawMbBits * (int)p_Img->PicSizeInMbs *3) + 1023) / 1024;
00125
00126 if (min_num_bytes > p_Img->bytes_in_picture)
00127 {
00128 stuffing_bytes = min_num_bytes - p_Img->bytes_in_picture;
00129 printf ("Inserting %d/%d cabac_zero_word syntax elements/bytes (Clause 7.4.2.10)\n", ((stuffing_bytes + 2)/3), stuffing_bytes);
00130
00131 for (i = 0; i < stuffing_bytes; i+=3 )
00132 {
00133 *buf++ = 0x00;
00134 *buf++ = 0x00;
00135 *buf++ = 0x03;
00136 }
00137 cur_stats->bit_use_stuffingBits[p_Img->type] += (i<<3);
00138 nalu->len += i;
00139 }
00140
00141 return i;
00142 }
00143