Use endian-neutral bitstream packing/unpacking
Eliminate unnecessary checks on target endianness and associated macros. Change-Id: I1d4e6a9dcee9bfc8940c8196838d31ed31b0e4aa
This commit is contained in:
parent
c351aa7f1b
commit
562f1470ce
@ -58,16 +58,6 @@ extern unsigned int active_section;
|
|||||||
int count_mb_seg[4] = { 0, 0, 0, 0 };
|
int count_mb_seg[4] = { 0, 0, 0, 0 };
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if CONFIG_BIG_ENDIAN
|
|
||||||
# define make_endian_16(a) \
|
|
||||||
(((unsigned int)(a & 0xff)) << 8) | (((unsigned int)(a & 0xff00)) >> 8)
|
|
||||||
# define make_endian_32(a) \
|
|
||||||
(((unsigned int)(a & 0xff)) << 24) | (((unsigned int)(a & 0xff00)) << 8) | \
|
|
||||||
(((unsigned int)(a & 0xff0000)) >> 8) | (((unsigned int)(a & 0xff000000)) >> 24)
|
|
||||||
#else
|
|
||||||
# define make_endian_16(a) a
|
|
||||||
# define make_endian_32(a) a
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static void update_mode(
|
static void update_mode(
|
||||||
vp8_writer *const w,
|
vp8_writer *const w,
|
||||||
@ -1392,13 +1382,20 @@ void vp8_pack_bitstream(VP8_COMP *cpi, unsigned char *dest, unsigned long *size)
|
|||||||
// every keyframe send startcode, width, height, scale factor, clamp and color type
|
// every keyframe send startcode, width, height, scale factor, clamp and color type
|
||||||
if (oh.type == KEY_FRAME)
|
if (oh.type == KEY_FRAME)
|
||||||
{
|
{
|
||||||
|
int v;
|
||||||
|
|
||||||
// Start / synch code
|
// Start / synch code
|
||||||
cx_data[0] = 0x9D;
|
cx_data[0] = 0x9D;
|
||||||
cx_data[1] = 0x01;
|
cx_data[1] = 0x01;
|
||||||
cx_data[2] = 0x2a;
|
cx_data[2] = 0x2a;
|
||||||
|
|
||||||
*((unsigned short *)(cx_data + 3)) = make_endian_16((pc->horiz_scale << 14) | pc->Width);
|
v = (pc->horiz_scale << 14) | pc->Width;
|
||||||
*((unsigned short *)(cx_data + 5)) = make_endian_16((pc->vert_scale << 14) | pc->Height);
|
cx_data[3] = v;
|
||||||
|
cx_data[4] = v >> 8;
|
||||||
|
|
||||||
|
v = (pc->vert_scale << 14) | pc->Height;
|
||||||
|
cx_data[5] = v;
|
||||||
|
cx_data[6] = v >> 8;
|
||||||
|
|
||||||
extra_bytes_packed = 7;
|
extra_bytes_packed = 7;
|
||||||
cx_data += extra_bytes_packed ;
|
cx_data += extra_bytes_packed ;
|
||||||
@ -1666,19 +1663,16 @@ void vp8_pack_bitstream(VP8_COMP *cpi, unsigned char *dest, unsigned long *size)
|
|||||||
*size = cpi->bc2.pos + cpi->bc.pos + VP8_HEADER_SIZE + extra_bytes_packed;
|
*size = cpi->bc2.pos + cpi->bc.pos + VP8_HEADER_SIZE + extra_bytes_packed;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if CONFIG_BIG_ENDIAN
|
|
||||||
{
|
{
|
||||||
int v = (oh.first_partition_length_in_bytes << 5) |
|
int v = (oh.first_partition_length_in_bytes << 5) |
|
||||||
(oh.show_frame << 4) |
|
(oh.show_frame << 4) |
|
||||||
(oh.version << 1) |
|
(oh.version << 1) |
|
||||||
oh.type;
|
oh.type;
|
||||||
|
|
||||||
v = make_endian_32(v);
|
dest[0] = v;
|
||||||
vpx_memcpy(dest, &v, 3);
|
dest[1] = v >> 8;
|
||||||
|
dest[2] = v >> 16;
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
vpx_memcpy(dest, &oh, 3);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef ENTROPY_STATS
|
#ifdef ENTROPY_STATS
|
||||||
|
@ -20,19 +20,6 @@
|
|||||||
|
|
||||||
#define VP8_CAP_POSTPROC (CONFIG_POSTPROC ? VPX_CODEC_CAP_POSTPROC : 0)
|
#define VP8_CAP_POSTPROC (CONFIG_POSTPROC ? VPX_CODEC_CAP_POSTPROC : 0)
|
||||||
|
|
||||||
#if CONFIG_BIG_ENDIAN
|
|
||||||
# define swap4(d)\
|
|
||||||
((d&0x000000ff)<<24) | \
|
|
||||||
((d&0x0000ff00)<<8) | \
|
|
||||||
((d&0x00ff0000)>>8) | \
|
|
||||||
((d&0xff000000)>>24)
|
|
||||||
# define swap2(d)\
|
|
||||||
((d&0x000000ff)<<8) | \
|
|
||||||
((d&0x0000ff00)>>8)
|
|
||||||
#else
|
|
||||||
# define swap4(d) d
|
|
||||||
# define swap2(d) d
|
|
||||||
#endif
|
|
||||||
typedef vpx_codec_stream_info_t vp8_stream_info_t;
|
typedef vpx_codec_stream_info_t vp8_stream_info_t;
|
||||||
|
|
||||||
/* Structures for handling memory allocations */
|
/* Structures for handling memory allocations */
|
||||||
@ -283,8 +270,8 @@ static vpx_codec_err_t vp8_peek_si(const uint8_t *data,
|
|||||||
if (c[0] != 0x9d || c[1] != 0x01 || c[2] != 0x2a)
|
if (c[0] != 0x9d || c[1] != 0x01 || c[2] != 0x2a)
|
||||||
res = VPX_CODEC_UNSUP_BITSTREAM;
|
res = VPX_CODEC_UNSUP_BITSTREAM;
|
||||||
|
|
||||||
si->w = swap2(*(const unsigned short *)(c + 3)) & 0x3fff;
|
si->w = (c[3] | (c[4] << 8)) & 0x3fff;
|
||||||
si->h = swap2(*(const unsigned short *)(c + 5)) & 0x3fff;
|
si->h = (c[5] | (c[6] << 8)) & 0x3fff;
|
||||||
|
|
||||||
/*printf("w=%d, h=%d\n", si->w, si->h);*/
|
/*printf("w=%d, h=%d\n", si->w, si->h);*/
|
||||||
if (!(si->h | si->w))
|
if (!(si->h | si->w))
|
||||||
|
Loading…
Reference in New Issue
Block a user