33 |
#include "mbcoding.h" |
#include "mbcoding.h" |
34 |
|
|
35 |
|
|
36 |
static uint32_t __inline |
static const uint8_t log2_tab_16[256] = { 0, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4 }; |
37 |
log2bin(uint32_t value) |
|
38 |
|
static uint32_t __inline log2bin(uint32_t value) |
39 |
{ |
{ |
40 |
int n = 0; |
int n = 0; |
41 |
|
if (value & 0xffff0000) { |
42 |
while (value) { |
value >>= 16; |
43 |
value >>= 1; |
n += 16; |
44 |
n++; |
} |
45 |
|
if (value & 0xff00) { |
46 |
|
value >>= 8; |
47 |
|
n += 8; |
48 |
|
} |
49 |
|
if (value & 0xf0) { |
50 |
|
value >>= 4; |
51 |
|
n += 4; |
52 |
} |
} |
53 |
return n; |
return n + log2_tab_16[value]; |
54 |
} |
} |
55 |
|
|
|
|
|
56 |
static const uint32_t intra_dc_threshold_table[] = { |
static const uint32_t intra_dc_threshold_table[] = { |
57 |
32, /* never use */ |
32, /* never use */ |
58 |
13, |
13, |
1408 |
} |
} |
1409 |
|
|
1410 |
} |
} |
1411 |
|
|
1412 |
|
/* |
1413 |
|
* Group of VOP |
1414 |
|
*/ |
1415 |
|
void |
1416 |
|
BitstreamWriteGroupOfVopHeader(Bitstream * const bs, |
1417 |
|
const MBParam * pParam, |
1418 |
|
uint32_t is_closed_gov) |
1419 |
|
{ |
1420 |
|
int64_t time = (pParam->m_stamp + (pParam->fbase/2)) / pParam->fbase; |
1421 |
|
int hours, minutes, seconds; |
1422 |
|
|
1423 |
|
/* compute time_code */ |
1424 |
|
seconds = time % 60; time /= 60; |
1425 |
|
minutes = time % 60; time /= 60; |
1426 |
|
hours = time % 24; /* don't overflow */ |
1427 |
|
|
1428 |
|
BitstreamPutBits(bs, GRPOFVOP_START_CODE, 32); |
1429 |
|
BitstreamPutBits(bs, hours, 5); |
1430 |
|
BitstreamPutBits(bs, minutes, 6); |
1431 |
|
BitstreamPutBit(bs, 1); |
1432 |
|
BitstreamPutBits(bs, seconds, 6); |
1433 |
|
BitstreamPutBits(bs, is_closed_gov, 1); |
1434 |
|
BitstreamPutBits(bs, 0, 1); /* broken_link */ |
1435 |
|
} |
1436 |
|
|
1437 |
|
/* |
1438 |
|
* End of Sequence |
1439 |
|
*/ |
1440 |
|
void |
1441 |
|
BitstreamWriteEndOfSequence(Bitstream * const bs) |
1442 |
|
{ |
1443 |
|
BitstreamPadAlways(bs); |
1444 |
|
BitstreamPutBits(bs, VISOBJSEQ_STOP_CODE, 32); |
1445 |
|
} |
1446 |
|
|
1447 |
|
/* |
1448 |
|
* Video Packet (resync marker) |
1449 |
|
*/ |
1450 |
|
|
1451 |
|
void write_video_packet_header(Bitstream * const bs, |
1452 |
|
const MBParam * pParam, |
1453 |
|
const FRAMEINFO * const frame, |
1454 |
|
int mbnum) |
1455 |
|
{ |
1456 |
|
const int mbnum_bits = log2bin(pParam->mb_width * pParam->mb_height - 1); |
1457 |
|
uint32_t nbitsresyncmarker; |
1458 |
|
int addbits=0; |
1459 |
|
if (frame->coding_type != I_VOP) |
1460 |
|
addbits = frame->fcode -1; |
1461 |
|
if (frame->coding_type == B_VOP) |
1462 |
|
addbits = MAX(frame->fcode, frame->bcode)-1; |
1463 |
|
BitstreamPadAlways(bs); |
1464 |
|
nbitsresyncmarker = NUMBITS_VP_RESYNC_MARKER + addbits; |
1465 |
|
BitstreamPutBits(bs, RESYNC_MARKER, nbitsresyncmarker); |
1466 |
|
BitstreamPutBits(bs, mbnum, mbnum_bits); |
1467 |
|
BitstreamPutBits(bs, frame->quant, 5); |
1468 |
|
BitstreamPutBit(bs, 0); /* hec */ |
1469 |
|
} |