OSCL_EXPORT_REF int16 iGetM4VConfigInfo(uint8 *buffer, int32 length, int32 *width, int32 *height, int32 *display_width, int32 *display_height) { int16 status; mp4StreamType psBits; psBits.data = buffer; psBits.numBytes = length; psBits.bitBuf = 0; psBits.bitPos = 32; psBits.bytePos = 0; psBits.dataBitPos = 0; *width = *height = *display_height = *display_width = 0; if (length == 0) { return MP4_INVALID_VOL_PARAM; } int32 profilelevel = 0; // dummy value discarded here /* Mobile Media Lab. Start */ int32 is_valid = 0; uint32 tmp; /* check input buffer has visual_object_sequence_start_code or visual_object_start_code or video_object_start_code or video_object_layer_start_code or short video header */ ShowBits(&psBits, 32, &tmp); if (tmp == VISUAL_OBJECT_SEQUENCE_START_CODE || tmp == VISUAL_OBJECT_START_CODE || (tmp >= 0x0100 && tmp <= 0x011F) || /* video_object_start_code */ ((tmp & 0x20) == 0x20)) /* video_object_layer_start_code */ { /* check MPEG-4 start code */ is_valid = 1; } else { /* check short video header */ ShowBits(&psBits, SHORT_VIDEO_START_MARKER_LENGTH, &tmp); if (tmp == SHORT_VIDEO_START_MARKER) is_valid = 1; } if (is_valid == 0) { /* this stream may have a garbage data */ return MP4_INVALID_VOL_PARAM; } /* Mobile Media Lab. End */ status = iDecodeVOLHeader(&psBits, width, height, display_width, display_height, &profilelevel); return status; }
static void _bit_out_psc_layer(Bitstream *bs) { if (ShowBits(bs,17)!=1) { /* check for startcode in Arithmetic Decoder FIFO */ bit = GetOneBit(bs); if(zerorun > 13) { /* if number of consecutive zeros = 14 */ if (!bit) { #ifdef TRACE if (trace) printf("PSC/GBSC, Header Data, or Encoded Stream Error \n"); #endif zerorun = 1; } else { /* if there is a 'stuffing bit present */ #ifdef TRACE if (trace) printf("Removing Startcode Emulation Prevention bit \n"); #endif bit = GetOneBit(bs); /* overwrite the last bit */ zerorun = !bit; /* zerorun=1 if bit is a '0' */ } } else { /* if consecutive zero's not exceeded 14 */ if (!bit) zerorun++; else zerorun = 0; } } /* end of if !(ShowBits(bs,17)) */ else { bit = 0; #ifdef TRACE if (trace) printf("Startcode Found:Finishing Arithmetic Decoding using " "'Garbage bits'\n"); #endif } /* printf("lastbit = %ld bit = %ld zerorun = %ld \n", lastbit, bit, zerorun); lastbit = bit; */ /* latent diagnostics */ }
int code_from_bitstream_2d(SyntaxElement *sym, DataPartition *dP, int *lentab, int *codtab, int tabwidth, int tabheight, int *code) { Bitstream *currStream = dP->bitstream; int frame_bitoffset = currStream->frame_bitoffset; byte *buf = currStream->streamBuffer; int BitstreamLengthInBytes = currStream->bitstream_length; int i,j; int len, cod; // this VLC decoding method is not optimized for speed for (j = 0; j < tabheight; j++) { for (i = 0; i < tabwidth; i++) { len = lentab[i]; if (!len) continue; cod = codtab[i]; if ((ShowBits(buf, frame_bitoffset, BitstreamLengthInBytes, len) == cod)) { sym->value1 = i; sym->value2 = j; currStream->frame_bitoffset += len; // move bitstream pointer sym->len = len; goto found_code; } } lentab += tabwidth; codtab += tabwidth; } return -1; // failed to find code found_code: *code = cod; return 0; }
void _getblock(H263Global *h263Data, int comp, int mode) { int val, i, j, sign; unsigned int code; VLCtab *tab; short *bp; int run, last, level, QP; short *qval; bp = h263Data->block[comp]; /* decode AC coefficients */ for (i=(mode==0); ; i++) { code = ShowBits(h263Data->bs,12); if (code>=512) tab = &DCT3Dtab0[(code>>5)-16]; else if (code>=128) tab = &DCT3Dtab1[(code>>2)-32]; else if (code>=8)
int main() { Board b; int choice; do { b.Draw(std::cout); choice = askForInt("1: Move Piece\n0: Quit:", 1, 0); if(choice == 1) { std::pair<unsigned, unsigned> move = GetMove(b); b.Move(move); ShowBits(std::cout, b.GetAllPieces()); std::cout << std::endl; std::cin.get(); } }while(choice != 0); std::cin.get(); return 0; }
// name: iDecodeVOLHeader // Purpose: decode VOL header // return: error code OSCL_EXPORT_REF int16 iDecodeVOLHeader(mp4StreamType *psBits, int32 *width, int32 *height, int32 *display_width, int32 *display_height, int32 *profilelevel, uint32 *interlaced) { int16 iErrorStat; uint32 codeword; int32 time_increment_resolution, nbits_time_increment; int32 i, j; *profilelevel = 0x0000FFFF; // init to some invalid value. When this value is returned, then no profilelevel info is available ShowBits(psBits, 32, &codeword); if (codeword == VISUAL_OBJECT_SEQUENCE_START_CODE) { //DV: this is the wrong way to skip bits, use FLush or Read psBits->dataBitPos += 32; ReadBits(psBits, 32, &codeword); // skip 32 bits of the Start code ReadBits(psBits, 8, &codeword); // record profile and level *profilelevel = (int) codeword; ShowBits(psBits, 32, &codeword); if (codeword == USER_DATA_START_CODE) { iErrorStat = DecodeUserData(psBits); if (iErrorStat) return MP4_INVALID_VOL_PARAM; } ReadBits(psBits, 32, &codeword); if (codeword != VISUAL_OBJECT_START_CODE) return MP4_INVALID_VOL_PARAM; /* is_visual_object_identifier */ ReadBits(psBits, 1, &codeword); if (codeword) { /* visual_object_verid */ ReadBits(psBits, 4, &codeword); /* visual_object_priority */ ReadBits(psBits, 3, &codeword); } /* visual_object_type */ ReadBits(psBits, 4, &codeword); if (codeword == 1) { /* video_signal_type */ ReadBits(psBits, 1, &codeword); if (codeword == 1) { /* video_format */ ReadBits(psBits, 3, &codeword); /* video_range */ ReadBits(psBits, 1, &codeword); /* color_description */ ReadBits(psBits, 1, &codeword); if (codeword == 1) { /* color_primaries */ ReadBits(psBits, 8, &codeword);; /* transfer_characteristics */ ReadBits(psBits, 8, &codeword); /* matrix_coefficients */ ReadBits(psBits, 8, &codeword); } } } else { int16 status = 0; do { /* Search for VOL_HEADER */ status = SearchNextM4VFrame(psBits); /* search 0x00 0x00 0x01 */ if (status != 0) return MP4_INVALID_VOL_PARAM; status = ReadBits(psBits, VOL_START_CODE_LENGTH, &codeword); } while ((codeword != VOL_START_CODE) && (status == 0)); goto decode_vol; } /* next_start_code() */ ByteAlign(psBits); ShowBits(psBits, 32, &codeword); if (codeword == USER_DATA_START_CODE) { iErrorStat = DecodeUserData(psBits); if (iErrorStat) return MP4_INVALID_VOL_PARAM; } ShowBits(psBits, 27, &codeword); } else { ShowBits(psBits, 27, &codeword); } if (codeword == VO_START_CODE) { ReadBits(psBits, 32, &codeword); /* video_object_layer_start_code */ ReadBits(psBits, 28, &codeword); if (codeword != VOL_START_CODE) { if (psBits->dataBitPos >= (psBits->numBytes << 3)) { return SHORT_HEADER_MODE; /* SH */ } else { int16 status = 0; do { /* Search for VOL_HEADER */ status = SearchNextM4VFrame(psBits); /* search 0x00 0x00 0x01 */ if (status != 0) return MP4_INVALID_VOL_PARAM; status = ReadBits(psBits, VOL_START_CODE_LENGTH, &codeword); } while ((codeword != VOL_START_CODE) && (status == 0)); goto decode_vol; } } decode_vol: uint32 vol_id; /* vol_id (4 bits) */ ReadBits(psBits, 4, & vol_id); // RandomAccessibleVOLFlag ReadBits(psBits, 1, &codeword); //Video Object Type Indication ReadBits(psBits, 8, &codeword); if (codeword != 1) { //return MP4_INVALID_VOL_PARAM; //TI supports this feature } // is_object_layer_identifier ReadBits(psBits, 1, &codeword); if (codeword) { ReadBits(psBits, 4, &codeword); ReadBits(psBits, 3, &codeword); } // aspect ratio ReadBits(psBits, 4, &codeword); if (codeword == 0xF) { // Extended Parameter /* width */ ReadBits(psBits, 8, &codeword); /* height */ ReadBits(psBits, 8, &codeword); } ReadBits(psBits, 1, &codeword); if (codeword) { ReadBits(psBits, 2, &codeword); if (codeword != 1) { return MP4_INVALID_VOL_PARAM; } ReadBits(psBits, 1, &codeword); if (!codeword) { //return MP4_INVALID_VOL_PARAM; //TI supports this feature } ReadBits(psBits, 1, &codeword); if (codeword) /* if (vbv_parameters) {}, page 36 */ { ReadBits(psBits, 15, &codeword); ReadBits(psBits, 1, &codeword); if (codeword != 1) { return MP4_INVALID_VOL_PARAM; } ReadBits(psBits, 15, &codeword); ReadBits(psBits, 1, &codeword); if (codeword != 1) { return MP4_INVALID_VOL_PARAM; } ReadBits(psBits, 19, &codeword); if (!(codeword & 0x8)) { return MP4_INVALID_VOL_PARAM; } ReadBits(psBits, 11, &codeword); ReadBits(psBits, 1, &codeword); if (codeword != 1) { return MP4_INVALID_VOL_PARAM; } ReadBits(psBits, 15, &codeword); ReadBits(psBits, 1, &codeword); if (codeword != 1) { return MP4_INVALID_VOL_PARAM; } } } ReadBits(psBits, 2, &codeword); if (codeword != 0) { return MP4_INVALID_VOL_PARAM; } ReadBits(psBits, 1, &codeword); if (codeword != 1) { return MP4_INVALID_VOL_PARAM; } ReadBits(psBits, 16, &codeword); time_increment_resolution = codeword; ReadBits(psBits, 1, &codeword); if (codeword != 1) { return MP4_INVALID_VOL_PARAM; } ReadBits(psBits, 1, &codeword); if (codeword && time_increment_resolution > 2) { i = time_increment_resolution - 1; j = 1; while (i >>= 1) { j++; } nbits_time_increment = j; ReadBits(psBits, nbits_time_increment, &codeword); }
int readSyntaxElement_NumCoeffTrailingOnes(SyntaxElement *sym, DataPartition *dP, char *type) { Bitstream *currStream = dP->bitstream; int frame_bitoffset = currStream->frame_bitoffset; byte *buf = currStream->streamBuffer; int BitstreamLengthInBytes = currStream->bitstream_length; int vlcnum, retval; int code, *ct, *lt; int lentab[3][4][17] = { { // 0702 { 1, 6, 8, 9,10,11,13,13,13,14,14,15,15,16,16,16,16}, { 0, 2, 6, 8, 9,10,11,13,13,14,14,15,15,15,16,16,16}, { 0, 0, 3, 7, 8, 9,10,11,13,13,14,14,15,15,16,16,16}, { 0, 0, 0, 5, 6, 7, 8, 9,10,11,13,14,14,15,15,16,16}, }, { { 2, 6, 6, 7, 8, 8, 9,11,11,12,12,12,13,13,13,14,14}, { 0, 2, 5, 6, 6, 7, 8, 9,11,11,12,12,13,13,14,14,14}, { 0, 0, 3, 6, 6, 7, 8, 9,11,11,12,12,13,13,13,14,14}, { 0, 0, 0, 4, 4, 5, 6, 6, 7, 9,11,11,12,13,13,13,14}, }, { { 4, 6, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 9,10,10,10,10}, { 0, 4, 5, 5, 5, 5, 6, 6, 7, 8, 8, 9, 9, 9,10,10,10}, { 0, 0, 4, 5, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9,10,10,10}, { 0, 0, 0, 4, 4, 4, 4, 4, 5, 6, 7, 8, 8, 9,10,10,10}, }, }; int codtab[3][4][17] = { { { 1, 5, 7, 7, 7, 7,15,11, 8,15,11,15,11,15,11, 7,4}, { 0, 1, 4, 6, 6, 6, 6,14,10,14,10,14,10, 1,14,10,6}, { 0, 0, 1, 5, 5, 5, 5, 5,13, 9,13, 9,13, 9,13, 9,5}, { 0, 0, 0, 3, 3, 4, 4, 4, 4, 4,12,12, 8,12, 8,12,8}, }, { { 3,11, 7, 7, 7, 4, 7,15,11,15,11, 8,15,11, 7, 9,7}, { 0, 2, 7,10, 6, 6, 6, 6,14,10,14,10,14,10,11, 8,6}, { 0, 0, 3, 9, 5, 5, 5, 5,13, 9,13, 9,13, 9, 6,10,5}, { 0, 0, 0, 5, 4, 6, 8, 4, 4, 4,12, 8,12,12, 8, 1,4}, }, { {15,15,11, 8,15,11, 9, 8,15,11,15,11, 8,13, 9, 5,1}, { 0,14,15,12,10, 8,14,10,14,14,10,14,10, 7,12, 8,4}, { 0, 0,13,14,11, 9,13, 9,13,10,13, 9,13, 9,11, 7,3}, { 0, 0, 0,12,11,10, 9, 8,13,12,12,12, 8,12,10, 6,2}, }, }; vlcnum = sym->value1; // vlcnum is the index of Table used to code coeff_token // vlcnum==3 means (8<=nC) which uses 6bit FLC if (vlcnum == 3) { // read 6 bit FLC code = ShowBits(buf, frame_bitoffset, BitstreamLengthInBytes, 6); currStream->frame_bitoffset += 6; sym->value2 = code & 3; sym->value1 = (code >> 2); if (!sym->value1 && sym->value2 == 3) { // #c = 0, #t1 = 3 => #c = 0 sym->value2 = 0; } else sym->value1++; sym->len = 6; retval = 0; }