Пример #1
0
static void Sequence( mpeg_decode* dec )
{
	int i;

	loadbits(dec);
	dec->width = getbits(dec,12);
	dec->height = getbits(dec,12);

	loadbits(dec);
    dec->aspect = getbits(dec,4);

	dec->Codec.In.Format.PacketRate.Den = 1001;
	dec->Codec.In.Format.PacketRate.Num = FrameRate[getbits(dec,4)];
	dec->Codec.FrameTime = Scale(TICKSPERSEC,dec->Codec.In.Format.PacketRate.Den,dec->Codec.In.Format.PacketRate.Num);

	loadbits(dec);
    dec->Codec.In.Format.ByteRate = getbits(dec,18) * 50;
	if (dec->Codec.In.Format.ByteRate > 8*1024*1024)
		dec->Codec.In.Format.ByteRate = 0;

    flushbits(dec,1); // marker
    flushbits(dec,10); // vbv_buffer_size
    flushbits(dec,1);

	loadbits(dec);
    if (getbits1(dec)) 
	{
        for (i=0;i<64;i++) 
		{
			loadbits(dec);
            dec->IntraMatrix[i] = (uint8_t)getbits(dec,8);
        }
    } 
	else 
	{
        for (i=0;i<64;i++) 
            dec->IntraMatrix[i] = MPEG1_IntraMatrix[dec->zigzag[i]];
    }

    if (getbits1(dec)) 
	{
        for (i=0;i<64;i++) 
		{
			loadbits(dec);
            dec->InterMatrix[i] = (uint8_t)getbits(dec, 8);
        }
    } 
	else 
	{
        for (i=0;i<64;i++) 
            dec->InterMatrix[i] = 16;
    }

	dec->ValidSeq = 1;
}
Пример #2
0
int getTMNMV ()
{
    int code;

    if (trace)
        fprintf (trace_file, "motion_code (");

    if (getbits1 ())
    {
        if (trace)
            fprintf (trace_file, "1): 0\n");
        return 0;
    }
    if ((code = showbits (12)) >= 512)
    {
        code = (code >> 8) - 2;
        flushbits (TMNMVtab0[code].len);

        if (trace)
        {
            fprintf (trace_file, "0");
            printbits (code + 2, 4, TMNMVtab0[code].len);
            fprintf (trace_file, "): %d\n", TMNMVtab0[code].val);
        }
        return TMNMVtab0[code].val;
    }
Пример #3
0
// max 9 bits
static INLINE int getDCsizeLum( mpeg_decode* dec )
{
	int i,code;
	
	if (!getbits1(dec))
		return getbits(dec,1)+1;

	if (!getbits1(dec))
		return getbits(dec,1)*3;
	
	code = showbits(dec,7);

	for (i=1;i<8;i++,code<<=1)
		if (!(code & 64))
		{
			flushbits(dec,i);
			return i+3;
		}

	flushbits(dec,7);
	return 11;
}
Пример #4
0
// max 10 bits
static INLINE int getDCsizeChr( mpeg_decode* dec )
{
	int i,code;
	
	if (!getbits1(dec))
		return getbits(dec,1);
	
	code = showbits(dec,9);

	for (i=1;i<10;i++,code<<=1)
		if (!(code & 256))
		{
			flushbits(dec,i);
			return i+1;
		}

	flushbits(dec,9);
	return 11;
}
Пример #5
0
int gethdr_h263( mp4_decode *dec )
{
	int code;

	bytealign(dec);
	loadbits(dec);

    code = getbits(dec,22-8);
	while (!eofbits(dec))
	{
		loadbits(dec);
		code = ((code << 8) + getbits(dec,8)) & 0x3FFFFF;
		if (code == 32)
			break;
	}

	if (code != 32)
		return 0;

    flushbits(dec,8); // picture timestamp

	loadbits(dec);
	if (!getbits1(dec)) // marker
		return 0;
	if (getbits1(dec)) // h263 id
		return 0;

	flushbits(dec,3);

	code = getbits(dec,3); // format

	if (code == 6 || code == 7)
	{
		if (dec->showerror)
		{
			dec->showerror = 0;
			ShowError(dec->Codec.Node.Class,MPEG4_ID,MPEG4_ERROR_H263);
		}
		//todo: finish
		return 0;
	}
	else
	{
		static const int size[8][2] = {
			{ 0,0 },
			{ 128,96 },
			{ 176,144 },
			{ 352,288 },
			{ 704,576 },
			{ 1408,1152 }};

		int width = size[code][0];
        int height = size[code][1];
		if (!dec->ignoresize && (!width || CodecIDCTSetFormat(&dec->Codec,PF_YUV420,
			dec->Codec.In.Format.Video.Width,dec->Codec.In.Format.Video.Height,width,height) != ERR_NONE))
		{
			dec->validvol = 0;
			return 0;
		}
       
		loadbits(dec);
        dec->prediction_type = getbits(dec,1);
		dec->long_vectors = (char)getbits(dec,1);

		if (getbits1(dec)) // sac not supported
			return 0;

		getbits(dec,1); // obmc
        
		if (getbits1(dec)) // pb frame not supported
			return 0;

		dec->quantizer = getbits(dec,5);
		flushbits(dec,1);

		dec->rounding = 0;
	}

    while (getbits1(dec)) // pei
	{
        flushbits(dec,8);
		loadbits(dec);
    }

	dec->fcode_for = 1;
	dec->validvol = 1;
	dec->Codec.IDCT.Ptr->Set(dec->Codec.IDCT.Ptr,IDCT_ROUNDING,&dec->rounding,sizeof(bool_t));
	return 1;
}