?? bitstream.h
字號:
/**
* @file bitstream.h
* @brief This file contains some operations for bitstream manipulation.
*
*/
#ifndef _BITSTREAM_H_
#define _BITSTREAM_H_
#include "portab.h"
#include "ftmcp100.h"
#include "decoder.h"
#include "encoder.h"
/*****************************************************************************
* Constants
****************************************************************************/
// comment any #defs we dont use
#define VIDO_RESYN_MARKER 0x1
#define VIDOBJ_START_CODE 0x00000100 /* ..0x0000011f */
#define VIDOBJLAY_START_CODE 0x00000120 /* ..0x0000012f */
#define VISOBJSEQ_START_CODE 0x000001b0
#define VISOBJSEQ_STOP_CODE 0x000001b1 /* ??? */
#define USERDATA_START_CODE 0x000001b2
#define GRPOFVOP_START_CODE 0x000001b3
//#define VIDSESERR_ERROR_CODE 0x000001b4
#define VISOBJ_START_CODE 0x000001b5
//#define SLICE_START_CODE 0x000001b7
//#define EXT_START_CODE 0x000001b8
#define VISOBJ_TYPE_VIDEO 1
//#define VISOBJ_TYPE_STILLTEXTURE 2
//#define VISOBJ_TYPE_MESH 3
//#define VISOBJ_TYPE_FBA 4
//#define VISOBJ_TYPE_3DMESH 5
#define VIDOBJLAY_TYPE_SIMPLE 1
//#define VIDOBJLAY_TYPE_SIMPLE_SCALABLE 2
#define VIDOBJLAY_TYPE_CORE 3
#define VIDOBJLAY_TYPE_MAIN 4
//#define VIDOBJLAY_AR_SQUARE 1
//#define VIDOBJLAY_AR_625TYPE_43 2
//#define VIDOBJLAY_AR_525TYPE_43 3
//#define VIDOBJLAY_AR_625TYPE_169 8
//#define VIDOBJLAY_AR_525TYPE_169 9
#define VIDOBJLAY_AR_EXTPAR 15
#define VIDOBJLAY_SHAPE_RECTANGULAR 0
#define VIDOBJLAY_SHAPE_BINARY 1
#define VIDOBJLAY_SHAPE_BINARY_ONLY 2
#define VIDOBJLAY_SHAPE_GRAYSCALE 3
#define VO_START_CODE 0x8
#define VOL_START_CODE 0x12
#define VOP_START_CODE0 0x0
#define VOP_START_CODE1 0x1b6
#define VIDO_SHORT_HEADER 0x20
#define VIDO_SHORT_HEADER_END 0x3f
//#define READ_MARKER() BitstreamSkip(bs, 1)
#define WRITE_MARKER() BitstreamPutBit(1,pCodec)
// vop coding types
// intra, prediction, backward, sprite, not_coded
#define I_VOP 0
#define P_VOP 1
#define B_VOP 2
#define S_VOP 3
#define N_VOP 4
// resync-specific
#define NUMBITS_VP_RESYNC_MARKER 17
#define RESYNC_MARKER 1
static const int stuffing_codes[8] =
{
/* nbits stuffing code */
0, /* 1 0 */
1, /* 2 01 */
3, /* 3 011 */
7, /* 4 0111 */
0xf, /* 5 01111 */
0x1f, /* 6 011111 */
0x3f, /* 7 0111111 */
0x7f, /* 8 01111111 */
};
/*****************************************************************************
* Prototypes
****************************************************************************/
void BitstreamWriteVolHeader(const MBParam * pParam,
const FRAMEINFO * frame,FTMCP100_CODEC *pCodec);
void BitstreamWriteVopHeader(const MBParam * pParam,
const FRAMEINFO * frame,
int vop_coded,FTMCP100_CODEC *pCodec);
void BitstreamWriteShortHeader(MBParam * pParam,
const FRAMEINFO * frame,
int vop_coded,FTMCP100_CODEC *pCodec);
/*****************************************************************************
* Inlined functions
****************************************************************************/
/* initialise bitstream structure */
static void __inline
BitstreamInit(Bitstream * const bs,
void *const bitstream,
uint32_t length)
{
bs->start = bs->tail = (uint32_t *) bitstream;
// bs->bufa = *(uint32_t *) bitstream;
// bs->bufb = *((uint32_t *) bitstream + 1);
// bs->buf = 0;
// bs->pos = 0;
bs->length = length;
}
/* bitstream length (unit bits) */
//static uint32_t __inline BitstreamPos(const Bitstream * const bs)
//{
// return 8 * ((ptr_t)bs->tail - (ptr_t)bs->start) + bs->pos;
//}
/* flush the bitstream & return length (unit bytes)
NOTE: assumes no futher bitstream functions will be called.
*/
//static uint32_t __inline
//BitstreamLength(Bitstream * const bs)
//{
// uint32_t len = (ptr_t) bs->tail - (ptr_t) bs->start;
//
// if (bs->pos) {
// len += (bs->pos + 7) >> 3;
// *bs->tail = bs->buf;
// }
// return len;
//}
/* pad bitstream to the next byte boundary */
/* write n bits to bitstream */
static void __inline
BitstreamPutBits(const uint32_t value,
const uint32_t size,FTMCP100_CODEC *pCodec)
{
DECLARE_MP4_PTR
SET_BADR(value)
SET_BALR(size)
}
/* pad bitstream to the next byte boundary */
static void __inline
BitstreamPad(FTMCP100_CODEC *pCodec)
{
int bits;
uint32_t code;
DECLARE_MP4_PTR
FA526_DrainWriteBuffer();
READ_VOADR(bits)
bits = 8 - (bits & 0x7); // bits % 8
code = stuffing_codes[bits - 1];
if (bits < 8) {
SET_BADR(code)
SET_BALR(bits)
}
}
static void __inline
BitstreamPadAlways(FTMCP100_CODEC *pCodec)
{
int bits;
uint32_t code;
DECLARE_MP4_PTR
#ifdef CORE_VERSION_2
int32_t cpsts;
// check VLC done
do {
READ_CPSTS(cpsts)
} while (!(cpsts&0x08000));
FA526_DrainWriteBuffer();
#endif
READ_VOADR(bits) /// 弄
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -