1
0
Fork 0
forked from len0rd/rockbox

Reformat and code police (tabs, trailing whitespace, annoying overuse of parentheses, etc.) in libmpeg2 so I can stomach working on it. Don't call IDCT functions through pointers - I don't feel like extracting that change just for relevance sake.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@15892 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Michael Sevakis 2007-12-07 13:00:31 +00:00
parent 5886efabf5
commit 2b5f979d75
10 changed files with 1772 additions and 1098 deletions

View file

@ -33,9 +33,15 @@ extern struct plugin_api* rb;
#define BUFFER_SIZE (1194 * 1024) #define BUFFER_SIZE (1194 * 1024)
#ifdef CPU_COLDFIRE
/* twice as large as on other targets because coldfire uses
* a secondary, transposed buffer for optimisation */
static int16_t static_dct_block[128] IBSS_ATTR ATTR_ALIGN(16);
#endif
const mpeg2_info_t * mpeg2_info (mpeg2dec_t * mpeg2dec) const mpeg2_info_t * mpeg2_info (mpeg2dec_t * mpeg2dec)
{ {
return &(mpeg2dec->info); return &mpeg2dec->info;
} }
static inline int skip_chunk (mpeg2dec_t * mpeg2dec, int bytes) static inline int skip_chunk (mpeg2dec_t * mpeg2dec, int bytes)
@ -52,21 +58,28 @@ static inline int skip_chunk (mpeg2dec_t * mpeg2dec, int bytes)
shift = mpeg2dec->shift; shift = mpeg2dec->shift;
limit = current + bytes; limit = current + bytes;
do { do
{
byte = *current++; byte = *current++;
if (shift == 0x00000100) {
if (shift == 0x00000100)
{
int skipped; int skipped;
mpeg2dec->shift = 0xffffff00; mpeg2dec->shift = 0xffffff00;
skipped = current - mpeg2dec->buf_start; skipped = current - mpeg2dec->buf_start;
mpeg2dec->buf_start = current; mpeg2dec->buf_start = current;
return skipped; return skipped;
} }
shift = (shift | byte) << 8; shift = (shift | byte) << 8;
} while (current < limit); }
while (current < limit);
mpeg2dec->shift = shift; mpeg2dec->shift = shift;
mpeg2dec->buf_start = current; mpeg2dec->buf_start = current;
return 0; return 0;
} }
@ -86,9 +99,12 @@ static inline int copy_chunk (mpeg2dec_t * mpeg2dec, int bytes)
chunk_ptr = mpeg2dec->chunk_ptr; chunk_ptr = mpeg2dec->chunk_ptr;
limit = current + bytes; limit = current + bytes;
do { do
{
byte = *current++; byte = *current++;
if (shift == 0x00000100) {
if (shift == 0x00000100)
{
int copied; int copied;
mpeg2dec->shift = 0xffffff00; mpeg2dec->shift = 0xffffff00;
@ -97,9 +113,11 @@ static inline int copy_chunk (mpeg2dec_t * mpeg2dec, int bytes)
mpeg2dec->buf_start = current; mpeg2dec->buf_start = current;
return copied; return copied;
} }
shift = (shift | byte) << 8; shift = (shift | byte) << 8;
*chunk_ptr++ = byte; *chunk_ptr++ = byte;
} while (current < limit); }
while (current < limit);
mpeg2dec->shift = shift; mpeg2dec->shift = shift;
mpeg2dec->buf_start = current; mpeg2dec->buf_start = current;
@ -123,26 +141,39 @@ static inline mpeg2_state_t seek_chunk (mpeg2dec_t * mpeg2dec)
size = mpeg2dec->buf_end - mpeg2dec->buf_start; size = mpeg2dec->buf_end - mpeg2dec->buf_start;
skipped = skip_chunk (mpeg2dec, size); skipped = skip_chunk (mpeg2dec, size);
if (!skipped) {
if (!skipped)
{
mpeg2dec->bytes_since_tag += size; mpeg2dec->bytes_since_tag += size;
return STATE_BUFFER; return STATE_BUFFER;
} }
mpeg2dec->bytes_since_tag += skipped; mpeg2dec->bytes_since_tag += skipped;
mpeg2dec->code = mpeg2dec->buf_start[-1]; mpeg2dec->code = mpeg2dec->buf_start[-1];
return (mpeg2_state_t)-1; return (mpeg2_state_t)-1;
} }
mpeg2_state_t mpeg2_seek_header (mpeg2dec_t * mpeg2dec) mpeg2_state_t mpeg2_seek_header (mpeg2dec_t * mpeg2dec)
{ {
while (mpeg2dec->code != 0xb3 && while (mpeg2dec->code != 0xb3 &&
((mpeg2dec->code != 0xb7 && mpeg2dec->code != 0xb8 && ((mpeg2dec->code != 0xb7 &&
mpeg2dec->code) || mpeg2dec->sequence.width == (unsigned)-1)) mpeg2dec->code != 0xb8 &&
mpeg2dec->code) ||
mpeg2dec->sequence.width == (unsigned)-1))
{
if (seek_chunk (mpeg2dec) == STATE_BUFFER) if (seek_chunk (mpeg2dec) == STATE_BUFFER)
return STATE_BUFFER; return STATE_BUFFER;
mpeg2dec->chunk_start = mpeg2dec->chunk_ptr = mpeg2dec->chunk_buffer; }
mpeg2dec->chunk_start =
mpeg2dec->chunk_ptr = mpeg2dec->chunk_buffer;
mpeg2dec->user_data_len = 0; mpeg2dec->user_data_len = 0;
return (mpeg2dec->code ? mpeg2_parse_header (mpeg2dec) :
mpeg2_header_picture_start (mpeg2dec)); return mpeg2dec->code ?
mpeg2_parse_header(mpeg2dec) :
mpeg2_header_picture_start(mpeg2dec);
} }
#define RECEIVED(code,state) (((state) << 8) + (code)) #define RECEIVED(code,state) (((state) << 8) + (code))
@ -151,50 +182,66 @@ mpeg2_state_t mpeg2_parse (mpeg2dec_t * mpeg2dec)
{ {
int size_buffer, size_chunk, copied; int size_buffer, size_chunk, copied;
if (mpeg2dec->action) { if (mpeg2dec->action)
{
mpeg2_state_t state; mpeg2_state_t state;
state = mpeg2dec->action (mpeg2dec); state = mpeg2dec->action (mpeg2dec);
if ((int)state >= 0) if ((int)state >= 0)
return state; return state;
} }
while (1) { while (1)
{
while ((unsigned) (mpeg2dec->code - mpeg2dec->first_decode_slice) < while ((unsigned) (mpeg2dec->code - mpeg2dec->first_decode_slice) <
mpeg2dec->nb_decode_slices) { mpeg2dec->nb_decode_slices)
{
size_buffer = mpeg2dec->buf_end - mpeg2dec->buf_start; size_buffer = mpeg2dec->buf_end - mpeg2dec->buf_start;
size_chunk = (mpeg2dec->chunk_buffer + BUFFER_SIZE - size_chunk = mpeg2dec->chunk_buffer + BUFFER_SIZE -
mpeg2dec->chunk_ptr); mpeg2dec->chunk_ptr;
if (size_buffer <= size_chunk) {
if (size_buffer <= size_chunk)
{
copied = copy_chunk (mpeg2dec, size_buffer); copied = copy_chunk (mpeg2dec, size_buffer);
if (!copied) {
if (!copied)
{
mpeg2dec->bytes_since_tag += size_buffer; mpeg2dec->bytes_since_tag += size_buffer;
mpeg2dec->chunk_ptr += size_buffer; mpeg2dec->chunk_ptr += size_buffer;
return STATE_BUFFER; return STATE_BUFFER;
} }
} else { }
else
{
copied = copy_chunk (mpeg2dec, size_chunk); copied = copy_chunk (mpeg2dec, size_chunk);
if (!copied) {
if (!copied)
{
/* filled the chunk buffer without finding a start code */ /* filled the chunk buffer without finding a start code */
mpeg2dec->bytes_since_tag += size_chunk; mpeg2dec->bytes_since_tag += size_chunk;
mpeg2dec->action = seek_chunk; mpeg2dec->action = seek_chunk;
return STATE_INVALID; return STATE_INVALID;
} }
} }
mpeg2dec->bytes_since_tag += copied; mpeg2dec->bytes_since_tag += copied;
mpeg2_slice (&(mpeg2dec->decoder), mpeg2dec->code, mpeg2_slice (&mpeg2dec->decoder, mpeg2dec->code,
mpeg2dec->chunk_start); mpeg2dec->chunk_start);
mpeg2dec->code = mpeg2dec->buf_start[-1]; mpeg2dec->code = mpeg2dec->buf_start[-1];
mpeg2dec->chunk_ptr = mpeg2dec->chunk_start; mpeg2dec->chunk_ptr = mpeg2dec->chunk_start;
} }
if ((unsigned) (mpeg2dec->code - 1) >= 0xb0 - 1) if ((unsigned) (mpeg2dec->code - 1) >= 0xb0 - 1)
break; break;
if (seek_chunk (mpeg2dec) == STATE_BUFFER) if (seek_chunk (mpeg2dec) == STATE_BUFFER)
return STATE_BUFFER; return STATE_BUFFER;
} }
switch (mpeg2dec->code) { switch (mpeg2dec->code)
{
case 0x00: case 0x00:
mpeg2dec->action = mpeg2_header_picture_start; mpeg2dec->action = mpeg2_header_picture_start;
return mpeg2dec->state; return mpeg2dec->state;
@ -209,33 +256,54 @@ mpeg2_state_t mpeg2_parse (mpeg2dec_t * mpeg2dec)
mpeg2dec->action = seek_chunk; mpeg2dec->action = seek_chunk;
return STATE_INVALID; return STATE_INVALID;
} }
return (mpeg2dec->state == STATE_SLICE) ? STATE_SLICE : STATE_INVALID; return (mpeg2dec->state == STATE_SLICE) ? STATE_SLICE : STATE_INVALID;
} }
mpeg2_state_t mpeg2_parse_header (mpeg2dec_t * mpeg2dec) mpeg2_state_t mpeg2_parse_header (mpeg2dec_t * mpeg2dec)
{ {
static int (* process_header[]) (mpeg2dec_t * mpeg2dec) = { static int (* const process_header[9]) (mpeg2dec_t *) =
mpeg2_header_picture, mpeg2_header_extension, mpeg2_header_user_data, {
mpeg2_header_sequence, NULL, NULL, NULL, NULL, mpeg2_header_gop mpeg2_header_picture,
mpeg2_header_extension,
mpeg2_header_user_data,
mpeg2_header_sequence,
NULL,
NULL,
NULL,
NULL,
mpeg2_header_gop
}; };
int size_buffer, size_chunk, copied; int size_buffer, size_chunk, copied;
mpeg2dec->action = mpeg2_parse_header; mpeg2dec->action = mpeg2_parse_header;
mpeg2dec->info.user_data = NULL; mpeg2dec->info.user_data_len = 0; mpeg2dec->info.user_data = NULL;
while (1) { mpeg2dec->info.user_data_len = 0;
while (1)
{
size_buffer = mpeg2dec->buf_end - mpeg2dec->buf_start; size_buffer = mpeg2dec->buf_end - mpeg2dec->buf_start;
size_chunk = (mpeg2dec->chunk_buffer + BUFFER_SIZE - size_chunk = mpeg2dec->chunk_buffer + BUFFER_SIZE -
mpeg2dec->chunk_ptr); mpeg2dec->chunk_ptr;
if (size_buffer <= size_chunk) {
if (size_buffer <= size_chunk)
{
copied = copy_chunk (mpeg2dec, size_buffer); copied = copy_chunk (mpeg2dec, size_buffer);
if (!copied) {
if (!copied)
{
mpeg2dec->bytes_since_tag += size_buffer; mpeg2dec->bytes_since_tag += size_buffer;
mpeg2dec->chunk_ptr += size_buffer; mpeg2dec->chunk_ptr += size_buffer;
return STATE_BUFFER; return STATE_BUFFER;
} }
} else { }
else
{
copied = copy_chunk (mpeg2dec, size_chunk); copied = copy_chunk (mpeg2dec, size_chunk);
if (!copied) {
if (!copied)
{
/* filled the chunk buffer without finding a start code */ /* filled the chunk buffer without finding a start code */
mpeg2dec->bytes_since_tag += size_chunk; mpeg2dec->bytes_since_tag += size_chunk;
mpeg2dec->code = 0xb4; mpeg2dec->code = 0xb4;
@ -243,17 +311,20 @@ mpeg2_state_t mpeg2_parse_header (mpeg2dec_t * mpeg2dec)
return STATE_INVALID; return STATE_INVALID;
} }
} }
mpeg2dec->bytes_since_tag += copied; mpeg2dec->bytes_since_tag += copied;
if (process_header[mpeg2dec->code & 0x0b] (mpeg2dec)) { if (process_header[mpeg2dec->code & 0x0b] (mpeg2dec))
{
mpeg2dec->code = mpeg2dec->buf_start[-1]; mpeg2dec->code = mpeg2dec->buf_start[-1];
mpeg2dec->action = mpeg2_seek_header; mpeg2dec->action = mpeg2_seek_header;
return STATE_INVALID; return STATE_INVALID;
} }
mpeg2dec->code = mpeg2dec->buf_start[-1]; mpeg2dec->code = mpeg2dec->buf_start[-1];
switch (RECEIVED (mpeg2dec->code, mpeg2dec->state)) {
switch (RECEIVED (mpeg2dec->code, mpeg2dec->state))
{
/* state transition after a sequence header */ /* state transition after a sequence header */
case RECEIVED (0x00, STATE_SEQUENCE): case RECEIVED (0x00, STATE_SEQUENCE):
mpeg2dec->action = mpeg2_header_picture_start; mpeg2dec->action = mpeg2_header_picture_start;
@ -290,6 +361,7 @@ mpeg2_state_t mpeg2_parse_header (mpeg2dec_t * mpeg2dec)
mpeg2dec->chunk_start = mpeg2dec->chunk_ptr = mpeg2dec->chunk_buffer; mpeg2dec->chunk_start = mpeg2dec->chunk_ptr = mpeg2dec->chunk_buffer;
mpeg2dec->user_data_len = 0; mpeg2dec->user_data_len = 0;
return mpeg2dec->state; return mpeg2dec->state;
} }
} }
@ -299,33 +371,42 @@ int mpeg2_convert (mpeg2dec_t * mpeg2dec, mpeg2_convert_t convert, void * arg)
mpeg2_convert_init_t convert_init; mpeg2_convert_init_t convert_init;
int error; int error;
error = convert (MPEG2_CONVERT_SET, NULL, &(mpeg2dec->sequence), 0, error = convert (MPEG2_CONVERT_SET, NULL, &mpeg2dec->sequence, 0,
arg, &convert_init); arg, &convert_init);
if (!error) {
if (!error)
{
mpeg2dec->convert = convert; mpeg2dec->convert = convert;
mpeg2dec->convert_arg = arg; mpeg2dec->convert_arg = arg;
mpeg2dec->convert_id_size = convert_init.id_size; mpeg2dec->convert_id_size = convert_init.id_size;
mpeg2dec->convert_stride = 0; mpeg2dec->convert_stride = 0;
} }
return error; return error;
} }
int mpeg2_stride (mpeg2dec_t * mpeg2dec, int stride) int mpeg2_stride (mpeg2dec_t * mpeg2dec, int stride)
{ {
if (!mpeg2dec->convert) { if (!mpeg2dec->convert)
{
if (stride < (int) mpeg2dec->sequence.width) if (stride < (int) mpeg2dec->sequence.width)
stride = mpeg2dec->sequence.width; stride = mpeg2dec->sequence.width;
mpeg2dec->decoder.stride_frame = stride; mpeg2dec->decoder.stride_frame = stride;
} else { }
else
{
mpeg2_convert_init_t convert_init; mpeg2_convert_init_t convert_init;
stride = mpeg2dec->convert (MPEG2_CONVERT_STRIDE, NULL, stride = mpeg2dec->convert(MPEG2_CONVERT_STRIDE, NULL,
&(mpeg2dec->sequence), stride, &mpeg2dec->sequence, stride,
mpeg2dec->convert_arg, mpeg2dec->convert_arg,
&convert_init); &convert_init);
mpeg2dec->convert_id_size = convert_init.id_size; mpeg2dec->convert_id_size = convert_init.id_size;
mpeg2dec->convert_stride = stride; mpeg2dec->convert_stride = stride;
} }
return stride; return stride;
} }
@ -333,21 +414,29 @@ void mpeg2_set_buf (mpeg2dec_t * mpeg2dec, uint8_t * buf[3], void * id)
{ {
mpeg2_fbuf_t * fbuf; mpeg2_fbuf_t * fbuf;
if (mpeg2dec->custom_fbuf) { if (mpeg2dec->custom_fbuf)
if (mpeg2dec->state == STATE_SEQUENCE) { {
if (mpeg2dec->state == STATE_SEQUENCE)
{
mpeg2dec->fbuf[2] = mpeg2dec->fbuf[1]; mpeg2dec->fbuf[2] = mpeg2dec->fbuf[1];
mpeg2dec->fbuf[1] = mpeg2dec->fbuf[0]; mpeg2dec->fbuf[1] = mpeg2dec->fbuf[0];
} }
mpeg2_set_fbuf (mpeg2dec, (mpeg2dec->decoder.coding_type == mpeg2_set_fbuf (mpeg2dec, (mpeg2dec->decoder.coding_type ==
PIC_FLAG_CODING_TYPE_B)); PIC_FLAG_CODING_TYPE_B));
fbuf = mpeg2dec->fbuf[0]; fbuf = mpeg2dec->fbuf[0];
} else { }
fbuf = &(mpeg2dec->fbuf_alloc[mpeg2dec->alloc_index].fbuf); else
{
fbuf = &mpeg2dec->fbuf_alloc[mpeg2dec->alloc_index].fbuf;
mpeg2dec->alloc_index_user = ++mpeg2dec->alloc_index; mpeg2dec->alloc_index_user = ++mpeg2dec->alloc_index;
} }
fbuf->buf[0] = buf[0]; fbuf->buf[0] = buf[0];
fbuf->buf[1] = buf[1]; fbuf->buf[1] = buf[1];
fbuf->buf[2] = buf[2]; fbuf->buf[2] = buf[2];
fbuf->id = id; fbuf->id = id;
} }
@ -390,30 +479,25 @@ void mpeg2_reset (mpeg2dec_t * mpeg2dec, int full_reset)
mpeg2dec->state = STATE_INVALID; mpeg2dec->state = STATE_INVALID;
mpeg2dec->first = 1; mpeg2dec->first = 1;
mpeg2_reset_info(&(mpeg2dec->info)); mpeg2_reset_info(&mpeg2dec->info);
mpeg2dec->info.gop = NULL; mpeg2dec->info.gop = NULL;
mpeg2dec->info.user_data = NULL; mpeg2dec->info.user_data = NULL;
mpeg2dec->info.user_data_len = 0; mpeg2dec->info.user_data_len = 0;
if (full_reset) {
if (full_reset)
{
mpeg2dec->info.sequence = NULL; mpeg2dec->info.sequence = NULL;
mpeg2_header_state_init (mpeg2dec); mpeg2_header_state_init (mpeg2dec);
} }
} }
#ifdef CPU_COLDFIRE
/* twice as large as on other targets because coldfire uses
* a secondary, transposed buffer for optimisation */
static int16_t static_dct_block[128] IBSS_ATTR ATTR_ALIGN(16);
#endif
mpeg2dec_t * mpeg2_init (void) mpeg2dec_t * mpeg2_init (void)
{ {
mpeg2dec_t * mpeg2dec; mpeg2dec_t * mpeg2dec;
mpeg2_idct_init (); mpeg2_idct_init ();
mpeg2dec = (mpeg2dec_t *) mpeg2_malloc (sizeof (mpeg2dec_t), mpeg2dec = (mpeg2dec_t *)mpeg2_malloc(sizeof (mpeg2dec_t),
MPEG2_ALLOC_MPEG2DEC); MPEG2_ALLOC_MPEG2DEC);
if (mpeg2dec == NULL) if (mpeg2dec == NULL)
return NULL; return NULL;
@ -425,7 +509,7 @@ mpeg2dec_t * mpeg2_init (void)
rb->memset (mpeg2dec->decoder.DCTblock, 0, 64 * sizeof (int16_t)); rb->memset (mpeg2dec->decoder.DCTblock, 0, 64 * sizeof (int16_t));
rb->memset (mpeg2dec->quantizer_matrix, 0, 4 * 64 * sizeof (uint8_t)); rb->memset (mpeg2dec->quantizer_matrix, 0, 4 * 64 * sizeof (uint8_t));
mpeg2dec->chunk_buffer = (uint8_t *) mpeg2_malloc (BUFFER_SIZE + 4, mpeg2dec->chunk_buffer = (uint8_t *)mpeg2_malloc(BUFFER_SIZE + 4,
MPEG2_ALLOC_CHUNK); MPEG2_ALLOC_CHUNK);
mpeg2dec->sequence.width = (unsigned)-1; mpeg2dec->sequence.width = (unsigned)-1;

File diff suppressed because it is too large Load diff

View file

@ -29,26 +29,11 @@
#include "attributes.h" #include "attributes.h"
#include "mpeg2_internal.h" #include "mpeg2_internal.h"
/* idct main entry point */ #if defined(CPU_COLDFIRE) || defined (CPU_ARM)
void (* mpeg2_idct_copy) (int16_t * block, uint8_t * dest, int stride); #define IDCT_ASM
void (* mpeg2_idct_add) (int last, int16_t * block, #endif
uint8_t * dest, int stride);
#ifdef CPU_COLDFIRE #ifndef IDCT_ASM
/* assembler functions */
extern void mpeg2_idct_copy_coldfire(int16_t * block, uint8_t * dest,
const int stride);
extern void mpeg2_idct_add_coldfire(const int last, int16_t * block,
uint8_t * dest, const int stride);
#elif defined CPU_ARM
/* assembler functions */
extern void mpeg2_idct_copy_arm(int16_t * block, uint8_t * dest,
const int stride);
extern void mpeg2_idct_add_arm(const int last, int16_t * block,
uint8_t * dest, const int stride);
#else /* !CPU_COLDFIRE, !CPU_ARM */
#define W1 2841 /* 2048 * sqrt (2) * cos (1 * pi / 16) */ #define W1 2841 /* 2048 * sqrt (2) * cos (1 * pi / 16) */
#define W2 2676 /* 2048 * sqrt (2) * cos (2 * pi / 16) */ #define W2 2676 /* 2048 * sqrt (2) * cos (2 * pi / 16) */
@ -63,8 +48,11 @@ extern void mpeg2_idct_add_arm(const int last, int16_t * block,
* to +-3826 - this is the worst case for a column IDCT where the * to +-3826 - this is the worst case for a column IDCT where the
* column inputs are 16-bit values. * column inputs are 16-bit values.
*/ */
uint8_t mpeg2_clip[3840 * 2 + 256] IBSS_ATTR; #define CLIP(i) \
#define CLIP(i) ((mpeg2_clip + 3840)[i]) ({ typeof (i) _i = (i); \
if ((_i & 0xff) != _i) \
_i = ~(_i >> (8*sizeof(_i) - 1)); \
_i; })
#if 0 #if 0
#define BUTTERFLY(t0,t1,W0,W1,d0,d1) \ #define BUTTERFLY(t0,t1,W0,W1,d0,d1) \
@ -89,7 +77,8 @@ static inline void idct_row (int16_t * const block)
/* shortcut */ /* shortcut */
if (likely (!(block[1] | ((int32_t *)block)[1] | ((int32_t *)block)[2] | if (likely (!(block[1] | ((int32_t *)block)[1] | ((int32_t *)block)[2] |
((int32_t *)block)[3]))) { ((int32_t *)block)[3])))
{
uint32_t tmp = (uint16_t) (block[0] >> 1); uint32_t tmp = (uint16_t) (block[0] >> 1);
tmp |= tmp << 16; tmp |= tmp << 16;
((int32_t *)block)[0] = tmp; ((int32_t *)block)[0] = tmp;
@ -175,16 +164,19 @@ static inline void idct_col (int16_t * const block)
block[8*7] = (a0 - b0) >> 17; block[8*7] = (a0 - b0) >> 17;
} }
static void mpeg2_idct_copy_c (int16_t * block, uint8_t * dest, void mpeg2_idct_copy (int16_t * block, uint8_t * dest,
const int stride) const int stride)
{ {
int i; int i;
for (i = 0; i < 8; i++) for (i = 0; i < 8; i++)
idct_row (block + 8 * i); idct_row (block + 8 * i);
for (i = 0; i < 8; i++) for (i = 0; i < 8; i++)
idct_col (block + i); idct_col (block + i);
do {
do
{
dest[0] = CLIP (block[0]); dest[0] = CLIP (block[0]);
dest[1] = CLIP (block[1]); dest[1] = CLIP (block[1]);
dest[2] = CLIP (block[2]); dest[2] = CLIP (block[2]);
@ -194,25 +186,32 @@ static void mpeg2_idct_copy_c (int16_t * block, uint8_t * dest,
dest[6] = CLIP (block[6]); dest[6] = CLIP (block[6]);
dest[7] = CLIP (block[7]); dest[7] = CLIP (block[7]);
((int32_t *)block)[0] = 0; ((int32_t *)block)[1] = 0; ((int32_t *)block)[0] = 0;
((int32_t *)block)[2] = 0; ((int32_t *)block)[3] = 0; ((int32_t *)block)[1] = 0;
((int32_t *)block)[2] = 0;
((int32_t *)block)[3] = 0;
dest += stride; dest += stride;
block += 8; block += 8;
} while (--i); }
while (--i);
} }
static void mpeg2_idct_add_c (const int last, int16_t * block, void mpeg2_idct_add (const int last, int16_t * block,
uint8_t * dest, const int stride) uint8_t * dest, const int stride)
{ {
int i; int i;
if (last != 129 || (block[0] & (7 << 4)) == (4 << 4)) { if (last != 129 || (block[0] & (7 << 4)) == (4 << 4))
{
for (i = 0; i < 8; i++) for (i = 0; i < 8; i++)
idct_row (block + 8 * i); idct_row (block + 8 * i);
for (i = 0; i < 8; i++) for (i = 0; i < 8; i++)
idct_col (block + i); idct_col (block + i);
do {
do
{
dest[0] = CLIP (block[0] + dest[0]); dest[0] = CLIP (block[0] + dest[0]);
dest[1] = CLIP (block[1] + dest[1]); dest[1] = CLIP (block[1] + dest[1]);
dest[2] = CLIP (block[2] + dest[2]); dest[2] = CLIP (block[2] + dest[2]);
@ -222,19 +221,24 @@ static void mpeg2_idct_add_c (const int last, int16_t * block,
dest[6] = CLIP (block[6] + dest[6]); dest[6] = CLIP (block[6] + dest[6]);
dest[7] = CLIP (block[7] + dest[7]); dest[7] = CLIP (block[7] + dest[7]);
((int32_t *)block)[0] = 0; ((int32_t *)block)[1] = 0; ((int32_t *)block)[0] = 0;
((int32_t *)block)[2] = 0; ((int32_t *)block)[3] = 0; ((int32_t *)block)[1] = 0;
((int32_t *)block)[2] = 0;
((int32_t *)block)[3] = 0;
dest += stride; dest += stride;
block += 8; block += 8;
} while (--i); }
} else { while (--i);
int DC; }
else
DC = (block[0] + 64) >> 7; {
int DC = (block[0] + 64) >> 7;
block[0] = block[63] = 0; block[0] = block[63] = 0;
i = 8; i = 8;
do {
do
{
dest[0] = CLIP (DC + dest[0]); dest[0] = CLIP (DC + dest[0]);
dest[1] = CLIP (DC + dest[1]); dest[1] = CLIP (DC + dest[1]);
dest[2] = CLIP (DC + dest[2]); dest[2] = CLIP (DC + dest[2]);
@ -244,34 +248,17 @@ static void mpeg2_idct_add_c (const int last, int16_t * block,
dest[6] = CLIP (DC + dest[6]); dest[6] = CLIP (DC + dest[6]);
dest[7] = CLIP (DC + dest[7]); dest[7] = CLIP (DC + dest[7]);
dest += stride; dest += stride;
} while (--i); }
while (--i);
} }
} }
#endif /* CPU selection */ #endif /* IDCT_ASM */
void mpeg2_idct_init (void) void mpeg2_idct_init (void)
{ {
extern uint8_t default_mpeg2_scan_norm[64];
extern uint8_t default_mpeg2_scan_alt[64];
extern uint8_t mpeg2_scan_norm[64];
extern uint8_t mpeg2_scan_alt[64];
int i, j; int i, j;
#ifdef CPU_COLDFIRE
mpeg2_idct_copy = mpeg2_idct_copy_coldfire;
mpeg2_idct_add = mpeg2_idct_add_coldfire;
#elif defined CPU_ARM
mpeg2_idct_copy = mpeg2_idct_copy_arm;
mpeg2_idct_add = mpeg2_idct_add_arm;
#else
mpeg2_idct_copy = mpeg2_idct_copy_c;
mpeg2_idct_add = mpeg2_idct_add_c;
for (i = -3840; i < 3840 + 256; i++)
CLIP(i) = (i < 0) ? 0 : ((i > 255) ? 255 : i);
#endif
for (i = 0; i < 64; i++) for (i = 0; i < 64; i++)
{ {
j = default_mpeg2_scan_norm[i]; j = default_mpeg2_scan_norm[i];

View file

@ -17,10 +17,10 @@
* *
****************************************************************************/ ****************************************************************************/
.global mpeg2_idct_copy_arm .global mpeg2_idct_copy
.type mpeg2_idct_copy_arm, %function .type mpeg2_idct_copy, %function
.global mpeg2_idct_add_arm .global mpeg2_idct_add
.type mpeg2_idct_add_arm, %function .type mpeg2_idct_add, %function
/* Custom calling convention: /* Custom calling convention:
@ -265,7 +265,7 @@
sub r0, r0, #16 sub r0, r0, #16
bx lr bx lr
mpeg2_idct_copy_arm: mpeg2_idct_copy:
stmfd sp!, { r1-r2, r4-r12, lr } stmfd sp!, { r1-r2, r4-r12, lr }
bl .idct bl .idct
ldmfd sp!, { r1-r2 } ldmfd sp!, { r1-r2 }
@ -313,7 +313,7 @@ mpeg2_idct_copy_arm:
blo 1b blo 1b
ldmfd sp!, { r4-r12, pc } ldmfd sp!, { r4-r12, pc }
mpeg2_idct_add_arm: mpeg2_idct_add:
cmp r0, #129 cmp r0, #129
mov r0, r1 mov r0, r1
ldreqsh r1, [r0, #0] ldreqsh r1, [r0, #0]

View file

@ -18,10 +18,10 @@
* *
****************************************************************************/ ****************************************************************************/
.global mpeg2_idct_copy_coldfire .global mpeg2_idct_copy
.type mpeg2_idct_copy_coldfire, @function .type mpeg2_idct_copy, @function
.global mpeg2_idct_add_coldfire .global mpeg2_idct_add
.type mpeg2_idct_add_coldfire, @function .type mpeg2_idct_add, @function
/* The IDCT itself. /* The IDCT itself.
* Input: %a0: block pointer * Input: %a0: block pointer
@ -240,7 +240,7 @@
.align 2 .align 2
mpeg2_idct_copy_coldfire: mpeg2_idct_copy:
lea.l (-11*4,%sp), %sp lea.l (-11*4,%sp), %sp
movem.l %d2-%d7/%a2-%a6, (%sp) | save some registers movem.l %d2-%d7/%a2-%a6, (%sp) | save some registers
move.l (11*4+4,%sp), %a0 | %a0 - block pointer for idct move.l (11*4+4,%sp), %a0 | %a0 - block pointer for idct
@ -339,7 +339,7 @@ mpeg2_idct_copy_coldfire:
.align 2 .align 2
mpeg2_idct_add_coldfire: mpeg2_idct_add:
lea.l (-11*4,%sp), %sp lea.l (-11*4,%sp), %sp
movem.l %d2-%d7/%a2-%a6, (%sp) movem.l %d2-%d7/%a2-%a6, (%sp)
movem.l (11*4+4,%sp), %d0/%a0-%a2 | %d0 - last value movem.l (11*4+4,%sp), %d0/%a0-%a2 | %d0 - last value

View file

@ -19,6 +19,8 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* $Id$
*/ */
#include "plugin.h" #include "plugin.h"
@ -48,7 +50,7 @@ extern mpeg2_mc_fct MC_avg_y_8;
extern mpeg2_mc_fct MC_avg_xy_16; extern mpeg2_mc_fct MC_avg_xy_16;
extern mpeg2_mc_fct MC_avg_xy_8; extern mpeg2_mc_fct MC_avg_xy_8;
mpeg2_mc_t mpeg2_mc = const mpeg2_mc_t mpeg2_mc =
{ {
{ {
MC_put_o_16, MC_put_x_16, MC_put_y_16, MC_put_xy_16, MC_put_o_16, MC_put_x_16, MC_put_y_16, MC_put_xy_16,

View file

@ -34,14 +34,15 @@
#define SEQ_FLAG_COLOUR_DESCRIPTION 16 #define SEQ_FLAG_COLOUR_DESCRIPTION 16
#define SEQ_MASK_VIDEO_FORMAT 0xe0 #define SEQ_MASK_VIDEO_FORMAT 0xe0
#define SEQ_VIDEO_FORMAT_COMPONENT 0 #define SEQ_VIDEO_FORMAT_COMPONENT 0x00
#define SEQ_VIDEO_FORMAT_PAL 0x20 #define SEQ_VIDEO_FORMAT_PAL 0x20
#define SEQ_VIDEO_FORMAT_NTSC 0x40 #define SEQ_VIDEO_FORMAT_NTSC 0x40
#define SEQ_VIDEO_FORMAT_SECAM 0x60 #define SEQ_VIDEO_FORMAT_SECAM 0x60
#define SEQ_VIDEO_FORMAT_MAC 0x80 #define SEQ_VIDEO_FORMAT_MAC 0x80
#define SEQ_VIDEO_FORMAT_UNSPECIFIED 0xa0 #define SEQ_VIDEO_FORMAT_UNSPECIFIED 0xa0
typedef struct mpeg2_sequence_s { typedef struct mpeg2_sequence_s
{
unsigned int width, height; unsigned int width, height;
unsigned int chroma_width, chroma_height; unsigned int chroma_width, chroma_height;
unsigned int byte_rate; unsigned int byte_rate;
@ -63,7 +64,8 @@ typedef struct mpeg2_sequence_s {
#define GOP_FLAG_BROKEN_LINK 2 #define GOP_FLAG_BROKEN_LINK 2
#define GOP_FLAG_CLOSED_GOP 4 #define GOP_FLAG_CLOSED_GOP 4
typedef struct mpeg2_gop_s { typedef struct mpeg2_gop_s
{
uint8_t hours; uint8_t hours;
uint8_t minutes; uint8_t minutes;
uint8_t seconds; uint8_t seconds;
@ -84,22 +86,26 @@ typedef struct mpeg2_gop_s {
#define PIC_FLAG_TAGS 128 #define PIC_FLAG_TAGS 128
#define PIC_MASK_COMPOSITE_DISPLAY 0xfffff000 #define PIC_MASK_COMPOSITE_DISPLAY 0xfffff000
typedef struct mpeg2_picture_s { typedef struct mpeg2_picture_s
{
unsigned int temporal_reference; unsigned int temporal_reference;
unsigned int nb_fields; unsigned int nb_fields;
uint32_t tag, tag2; uint32_t tag, tag2;
uint32_t flags; uint32_t flags;
struct { struct
{
int x, y; int x, y;
} display_offset[3]; } display_offset[3];
} mpeg2_picture_t; } mpeg2_picture_t;
typedef struct mpeg2_fbuf_s { typedef struct mpeg2_fbuf_s
{
uint8_t * buf[3]; uint8_t * buf[3];
void * id; void * id;
} mpeg2_fbuf_t; } mpeg2_fbuf_t;
typedef struct mpeg2_info_s { typedef struct mpeg2_info_s
{
const mpeg2_sequence_t * sequence; const mpeg2_sequence_t * sequence;
const mpeg2_gop_t * gop; const mpeg2_gop_t * gop;
const mpeg2_picture_t * current_picture; const mpeg2_picture_t * current_picture;
@ -116,7 +122,8 @@ typedef struct mpeg2_info_s {
typedef struct mpeg2dec_s mpeg2dec_t; typedef struct mpeg2dec_s mpeg2dec_t;
typedef struct mpeg2_decoder_s mpeg2_decoder_t; typedef struct mpeg2_decoder_s mpeg2_decoder_t;
typedef enum { typedef enum
{
STATE_BUFFER = 0, STATE_BUFFER = 0,
STATE_SEQUENCE = 1, STATE_SEQUENCE = 1,
STATE_SEQUENCE_REPEATED = 2, STATE_SEQUENCE_REPEATED = 2,
@ -130,18 +137,22 @@ typedef enum {
STATE_INVALID_END = 10 STATE_INVALID_END = 10
} mpeg2_state_t; } mpeg2_state_t;
typedef struct mpeg2_convert_init_s { typedef struct mpeg2_convert_init_s
{
unsigned int id_size; unsigned int id_size;
unsigned int buf_size[3]; unsigned int buf_size[3];
void (* start) (void * id, const mpeg2_fbuf_t * fbuf, void (* start)(void * id, const mpeg2_fbuf_t * fbuf,
const mpeg2_picture_t * picture, const mpeg2_gop_t * gop); const mpeg2_picture_t * picture, const mpeg2_gop_t * gop);
void (* copy) (void * id, uint8_t * const * src, unsigned int v_offset); void (* copy)(void * id, uint8_t * const * src, unsigned int v_offset);
} mpeg2_convert_init_t; } mpeg2_convert_init_t;
typedef enum {
typedef enum
{
MPEG2_CONVERT_SET = 0, MPEG2_CONVERT_SET = 0,
MPEG2_CONVERT_STRIDE = 1, MPEG2_CONVERT_STRIDE = 1,
MPEG2_CONVERT_START = 2 MPEG2_CONVERT_START = 2
} mpeg2_convert_stage_t; } mpeg2_convert_stage_t;
typedef int mpeg2_convert_t (int stage, void * id, typedef int mpeg2_convert_t (int stage, void * id,
const mpeg2_sequence_t * sequence, int stride, const mpeg2_sequence_t * sequence, int stride,
void * arg, mpeg2_convert_init_t * result); void * arg, mpeg2_convert_init_t * result);
@ -168,7 +179,8 @@ void mpeg2_init_fbuf (mpeg2_decoder_t * decoder, uint8_t * current_fbuf[3],
uint8_t * forward_fbuf[3], uint8_t * backward_fbuf[3]); uint8_t * forward_fbuf[3], uint8_t * backward_fbuf[3]);
void mpeg2_slice (mpeg2_decoder_t * decoder, int code, const uint8_t * buffer); void mpeg2_slice (mpeg2_decoder_t * decoder, int code, const uint8_t * buffer);
typedef enum { typedef enum
{
MPEG2_ALLOC_MPEG2DEC = 0, MPEG2_ALLOC_MPEG2DEC = 0,
MPEG2_ALLOC_CHUNK = 1, MPEG2_ALLOC_CHUNK = 1,
MPEG2_ALLOC_YUV = 2, MPEG2_ALLOC_YUV = 2,

View file

@ -20,6 +20,8 @@
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#ifndef MPEG2_INTERNAL_H
#define MPEG2_INTERNAL_H
#include "config.h" /* for Rockbox CPU_ #defines */ #include "config.h" /* for Rockbox CPU_ #defines */
@ -50,18 +52,20 @@
typedef void mpeg2_mc_fct (uint8_t *, const uint8_t *, int, int); typedef void mpeg2_mc_fct (uint8_t *, const uint8_t *, int, int);
typedef struct { typedef struct
{
uint8_t * ref[2][3]; uint8_t * ref[2][3];
uint8_t ** ref2[2]; uint8_t ** ref2[2];
int pmv[2][2]; int pmv[2][2];
int f_code[2]; int f_code[2];
} motion_t; } motion_t;
typedef void motion_parser_t (mpeg2_decoder_t * decoder, typedef void motion_parser_t(mpeg2_decoder_t * decoder,
motion_t * motion, motion_t * motion,
mpeg2_mc_fct * const * table); mpeg2_mc_fct * const * table);
struct mpeg2_decoder_s { struct mpeg2_decoder_s
{
/* first, state that carries information from one macroblock to the */ /* first, state that carries information from one macroblock to the */
/* next inside a slice, and is never used outside of mpeg2_slice() */ /* next inside a slice, and is never used outside of mpeg2_slice() */
@ -152,11 +156,13 @@ struct mpeg2_decoder_s {
int mpeg1; int mpeg1;
}; };
typedef struct { typedef struct
{
mpeg2_fbuf_t fbuf; mpeg2_fbuf_t fbuf;
} fbuf_alloc_t; } fbuf_alloc_t;
struct mpeg2dec_s { struct mpeg2dec_s
{
mpeg2_decoder_t decoder; mpeg2_decoder_t decoder;
mpeg2_info_t info; mpeg2_info_t info;
@ -222,19 +228,6 @@ struct mpeg2dec_s {
uint8_t new_quantizer_matrix[4][64]; uint8_t new_quantizer_matrix[4][64];
}; };
typedef struct {
#ifdef ARCH_PPC
uint8_t regv[12*16];
#endif
int dummy;
} cpu_state_t;
/* cpu_accel.c */
uint32_t mpeg2_detect_accel (void);
/* cpu_state.c */
void mpeg2_cpu_state_init (uint32_t accel);
/* decode.c */ /* decode.c */
mpeg2_state_t mpeg2_seek_header (mpeg2dec_t * mpeg2dec); mpeg2_state_t mpeg2_seek_header (mpeg2dec_t * mpeg2dec);
mpeg2_state_t mpeg2_parse_header (mpeg2dec_t * mpeg2dec); mpeg2_state_t mpeg2_parse_header (mpeg2dec_t * mpeg2dec);
@ -257,11 +250,26 @@ void mpeg2_set_fbuf (mpeg2dec_t * mpeg2dec, int b_type);
/* idct.c */ /* idct.c */
void mpeg2_idct_init (void); void mpeg2_idct_init (void);
void mpeg2_idct_copy(int16_t * block, uint8_t * dest,
const int stride);
void mpeg2_idct_add(const int last, int16_t * block,
uint8_t * dest, const int stride);
extern const uint8_t default_mpeg2_scan_norm[64];
extern const uint8_t default_mpeg2_scan_alt[64];
extern uint8_t mpeg2_scan_norm[64];
extern uint8_t mpeg2_scan_alt[64];
/* motion_comp.c */ /* motion_comp.c */
void mpeg2_mc_init (void); void mpeg2_mc_init (void);
typedef struct { typedef struct
{
mpeg2_mc_fct * put [8]; mpeg2_mc_fct * put [8];
mpeg2_mc_fct * avg [8]; mpeg2_mc_fct * avg [8];
} mpeg2_mc_t; } mpeg2_mc_t;
extern const mpeg2_mc_t mpeg2_mc;
#endif /* MPEG2_INTERNAL_H */

File diff suppressed because it is too large Load diff

View file

@ -21,7 +21,7 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#define GETWORD(bit_buf,shift,bit_ptr) \ #define GETWORD(bit_buf, shift, bit_ptr) \
do { \ do { \
bit_buf |= ((bit_ptr[0] << 8) | bit_ptr[1]) << (shift); \ bit_buf |= ((bit_ptr[0] << 8) | bit_ptr[1]) << (shift); \
bit_ptr += 2; \ bit_ptr += 2; \
@ -37,7 +37,7 @@ static inline void bitstream_init (mpeg2_decoder_t * decoder,
} }
/* make sure that there are at least 16 valid bits in bit_buf */ /* make sure that there are at least 16 valid bits in bit_buf */
#define NEEDBITS(bit_buf,bits,bit_ptr) \ #define NEEDBITS(bit_buf, bits, bit_ptr) \
do { \ do { \
if (unlikely (bits > 0)) { \ if (unlikely (bits > 0)) { \
GETWORD (bit_buf, bits, bit_ptr); \ GETWORD (bit_buf, bits, bit_ptr); \
@ -46,7 +46,7 @@ do { \
} while (0) } while (0)
/* remove num valid bits from bit_buf */ /* remove num valid bits from bit_buf */
#define DUMPBITS(bit_buf,bits,num) \ #define DUMPBITS(bit_buf, bits, num) \
do { \ do { \
bit_buf <<= (num); \ bit_buf <<= (num); \
bits += (num); \ bits += (num); \