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