1
0
Fork 0
forked from len0rd/rockbox

libmpeg2: Decode only Y on grayscale targets. The chroma skip code is probably less than optimal since it's basically the decoding code with minimum reading of the bitstream but it does the trick for now and gets some more FPS.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@16093 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Michael Sevakis 2008-01-16 01:22:56 +00:00
parent 74d61058dc
commit 0c7f2372d5
7 changed files with 680 additions and 115 deletions

View file

@ -144,7 +144,7 @@ bool mpeg_alloc_init(unsigned char *buf, size_t mallocsize)
return false;
}
IF_COP(flush_icache());
IF_COP(invalidate_icache());
return true;
}

View file

@ -37,6 +37,10 @@ extern struct plugin_api* rb;
/* 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);
#define DCT_BLOCKSIZE (128 * sizeof (int16_t))
#else
static int16_t static_dct_block[64] IBSS_ATTR ATTR_ALIGN(16);
#define DCT_BLOCKSIZE (64 * sizeof (int16_t))
#endif
const mpeg2_info_t * mpeg2_info (mpeg2dec_t * mpeg2dec)
@ -410,7 +414,7 @@ int mpeg2_stride (mpeg2dec_t * mpeg2dec, int stride)
return stride;
}
void mpeg2_set_buf (mpeg2dec_t * mpeg2dec, uint8_t * buf[3], void * id)
void mpeg2_set_buf (mpeg2dec_t * mpeg2dec, uint8_t * buf[MPEG2_COMPONENTS], void * id)
{
mpeg2_fbuf_t * fbuf;
@ -434,8 +438,10 @@ void mpeg2_set_buf (mpeg2dec_t * mpeg2dec, uint8_t * buf[3], void * id)
}
fbuf->buf[0] = buf[0];
#if MPEG2_COLOR
fbuf->buf[1] = buf[1];
fbuf->buf[2] = buf[2];
#endif
fbuf->id = id;
}
@ -502,12 +508,11 @@ mpeg2dec_t * mpeg2_init (void)
if (mpeg2dec == NULL)
return NULL;
#ifdef CPU_COLDFIRE
mpeg2dec->decoder.DCTblock = static_dct_block;
#endif
rb->memset (mpeg2dec->decoder.DCTblock, 0, 64 * sizeof (int16_t));
rb->memset (mpeg2dec->quantizer_matrix, 0, 4 * 64 * sizeof (uint8_t));
rb->memset (mpeg2dec->decoder.DCTblock, 0, DCT_BLOCKSIZE);
DEBUGF("DCTblock: %p\n", mpeg2dec->decoder.DCTblock);
mpeg2dec->chunk_buffer = (uint8_t *)mpeg2_bufalloc(BUFFER_SIZE + 4,
MPEG2_ALLOC_CHUNK);

View file

@ -102,8 +102,10 @@ void mpeg2_header_state_init (mpeg2dec_t * mpeg2dec)
i < mpeg2dec->alloc_index; i++)
{
mpeg2_free(mpeg2dec->fbuf_alloc[i].fbuf.buf[0]);
#if MPEG2_COLOR
mpeg2_free(mpeg2dec->fbuf_alloc[i].fbuf.buf[1]);
mpeg2_free(mpeg2dec->fbuf_alloc[i].fbuf.buf[2]);
#endif
}
}
@ -113,8 +115,10 @@ void mpeg2_header_state_init (mpeg2dec_t * mpeg2dec)
for (i = 0; i < 3; i++)
{
mpeg2_free(mpeg2dec->yuv_buf[i][0]);
#if MPEG2_COLOR
mpeg2_free(mpeg2dec->yuv_buf[i][1]);
mpeg2_free(mpeg2dec->yuv_buf[i][2]);
#endif
}
}
@ -840,8 +844,6 @@ void mpeg2_header_picture_finalize (mpeg2dec_t * mpeg2dec)
if (!mpeg2dec->convert_start)
{
int y_size, uv_size;
mpeg2dec->decoder.convert_id =
mpeg2_malloc (mpeg2dec->convert_id_size,
MPEG2_ALLOC_CONVERT_ID);
@ -855,32 +857,39 @@ void mpeg2_header_picture_finalize (mpeg2dec_t * mpeg2dec)
mpeg2dec->convert_start = convert_init.start;
mpeg2dec->decoder.convert = convert_init.copy;
y_size = decoder->stride_frame * mpeg2dec->sequence.height;
uv_size = y_size >> (2 - mpeg2dec->decoder.chroma_format);
int y_size = decoder->stride_frame * mpeg2dec->sequence.height;
mpeg2dec->yuv_buf[0][0] =
(uint8_t *) mpeg2_malloc(y_size, MPEG2_ALLOC_YUV);
#if MPEG2_COLOR
int uv_size = y_size >> (2 - mpeg2dec->decoder.chroma_format);
mpeg2dec->yuv_buf[0][1] =
(uint8_t *) mpeg2_malloc(uv_size, MPEG2_ALLOC_YUV);
mpeg2dec->yuv_buf[0][2] =
(uint8_t *) mpeg2_malloc(uv_size, MPEG2_ALLOC_YUV);
#endif
mpeg2dec->yuv_buf[1][0] =
(uint8_t *) mpeg2_malloc(y_size, MPEG2_ALLOC_YUV);
#if MPEG2_COLOR
mpeg2dec->yuv_buf[1][1] =
(uint8_t *) mpeg2_malloc(uv_size, MPEG2_ALLOC_YUV);
mpeg2dec->yuv_buf[1][2] =
(uint8_t *) mpeg2_malloc(uv_size, MPEG2_ALLOC_YUV);
#endif
y_size = decoder->stride_frame * 32;
uv_size = y_size >> (2 - mpeg2dec->decoder.chroma_format);
mpeg2dec->yuv_buf[2][0] =
(uint8_t *) mpeg2_malloc(y_size, MPEG2_ALLOC_YUV);
#if MPEG2_COLOR
uv_size = y_size >> (2 - mpeg2dec->decoder.chroma_format);
mpeg2dec->yuv_buf[2][1] =
(uint8_t *) mpeg2_malloc(uv_size, MPEG2_ALLOC_YUV);
mpeg2dec->yuv_buf[2][2] =
(uint8_t *) mpeg2_malloc(uv_size, MPEG2_ALLOC_YUV);
#endif
}
if (!mpeg2dec->custom_fbuf)
@ -895,13 +904,16 @@ void mpeg2_header_picture_finalize (mpeg2dec_t * mpeg2dec)
fbuf->buf[0] =
(uint8_t *) mpeg2_malloc (convert_init.buf_size[0],
MPEG2_ALLOC_CONVERTED);
#if MPEG2_COLOR
fbuf->buf[1] =
(uint8_t *) mpeg2_malloc (convert_init.buf_size[1],
MPEG2_ALLOC_CONVERTED);
fbuf->buf[2] =
(uint8_t *) mpeg2_malloc (convert_init.buf_size[2],
MPEG2_ALLOC_CONVERTED);
#endif
}
mpeg2_set_fbuf (mpeg2dec, (decoder->coding_type == B_TYPE));
}
}
@ -910,21 +922,23 @@ void mpeg2_header_picture_finalize (mpeg2dec_t * mpeg2dec)
while (mpeg2dec->alloc_index < 3)
{
mpeg2_fbuf_t * fbuf;
int y_size, uv_size;
fbuf = &mpeg2dec->fbuf_alloc[mpeg2dec->alloc_index++].fbuf;
fbuf->id = NULL;
y_size = decoder->stride_frame * mpeg2dec->sequence.height;
uv_size = y_size >> (2 - decoder->chroma_format);
int y_size = decoder->stride_frame * mpeg2dec->sequence.height;
fbuf->buf[0] = (uint8_t *) mpeg2_malloc (y_size,
MPEG2_ALLOC_YUV);
#if MPEG2_COLOR
int uv_size = y_size >> (2 - decoder->chroma_format);
fbuf->buf[1] = (uint8_t *) mpeg2_malloc (uv_size,
MPEG2_ALLOC_YUV);
fbuf->buf[2] = (uint8_t *) mpeg2_malloc (uv_size,
MPEG2_ALLOC_YUV);
#endif
}
mpeg2_set_fbuf (mpeg2dec, (decoder->coding_type == B_TYPE));

View file

@ -24,6 +24,8 @@
#ifndef MPEG2_H
#define MPEG2_H
#include "mpeg2dec_config.h"
#define MPEG2_VERSION(a,b,c) (((a)<<16)|((b)<<8)|(c))
#define MPEG2_RELEASE MPEG2_VERSION (0, 4, 0) /* 0.4.0 */
@ -100,7 +102,7 @@ typedef struct mpeg2_picture_s
typedef struct mpeg2_fbuf_s
{
uint8_t * buf[3];
uint8_t * buf[MPEG2_COMPONENTS];
void * id;
} mpeg2_fbuf_t;
@ -140,7 +142,7 @@ typedef enum
typedef struct mpeg2_convert_init_s
{
unsigned int id_size;
unsigned int buf_size[3];
unsigned int buf_size[MPEG2_COMPONENTS];
void (* start)(void * id, const mpeg2_fbuf_t * fbuf,
const mpeg2_picture_t * picture, const mpeg2_gop_t * gop);
void (* copy)(void * id, uint8_t * const * src, unsigned int v_offset);
@ -158,7 +160,8 @@ typedef int mpeg2_convert_t (int stage, void * id,
void * arg, mpeg2_convert_init_t * result);
int mpeg2_convert (mpeg2dec_t * mpeg2dec, mpeg2_convert_t convert, void * arg);
int mpeg2_stride (mpeg2dec_t * mpeg2dec, int stride);
void mpeg2_set_buf (mpeg2dec_t * mpeg2dec, uint8_t * buf[3], void * id);
void mpeg2_set_buf (mpeg2dec_t * mpeg2dec, uint8_t * buf[MPEG2_COMPONENTS],
void * id);
void mpeg2_custom_fbuf (mpeg2dec_t * mpeg2dec, int custom_fbuf);
mpeg2dec_t * mpeg2_init (void);
@ -175,8 +178,10 @@ void mpeg2_slice_region (mpeg2dec_t * mpeg2dec, int start, int end);
void mpeg2_tag_picture (mpeg2dec_t * mpeg2dec, uint32_t tag, uint32_t tag2);
void mpeg2_init_fbuf (mpeg2_decoder_t * decoder, uint8_t * current_fbuf[3],
uint8_t * forward_fbuf[3], uint8_t * backward_fbuf[3]);
void mpeg2_init_fbuf (mpeg2_decoder_t * decoder,
uint8_t * current_fbuf[MPEG2_COMPONENTS],
uint8_t * forward_fbuf[MPEG2_COMPONENTS],
uint8_t * backward_fbuf[MPEG2_COMPONENTS]);
void mpeg2_slice (mpeg2_decoder_t * decoder, int code, const uint8_t * buffer);
typedef enum

View file

@ -54,7 +54,7 @@ typedef void mpeg2_mc_fct (uint8_t *, const uint8_t *, int, int);
typedef struct
{
uint8_t * ref[2][3];
uint8_t * ref[2][MPEG2_COMPONENTS];
uint8_t ** ref2[2];
int pmv[2][2];
int f_code[2];
@ -74,7 +74,7 @@ struct mpeg2_decoder_s
int bitstream_bits; /* used bits in working set */
const uint8_t * bitstream_ptr; /* buffer with stream data */
uint8_t * dest[3];
uint8_t * dest[MPEG2_COMPONENTS];
int offset;
int stride;
@ -95,16 +95,12 @@ struct mpeg2_decoder_s
motion_parser_t * motion_parser[5];
/* predictor for DC coefficients in intra blocks */
int16_t dc_dct_pred[3];
int16_t dc_dct_pred[MPEG2_COMPONENTS];
/* DCT coefficients */
#ifdef CPU_COLDFIRE
int16_t *DCTblock; /* put buffer separately to have it in IRAM */
#else
int16_t DCTblock[64] ATTR_ALIGN(64);
#endif
int16_t * ATTR_ALIGN(16) DCTblock; /* put buffer separately to have it in IRAM */
uint8_t * picture_dest[3];
uint8_t * picture_dest[MPEG2_COMPONENTS];
void (* convert) (void * convert_id, uint8_t * const * src,
unsigned int v_offset);
void * convert_id;
@ -174,7 +170,7 @@ struct mpeg2dec_s
uint32_t ext_state;
/* allocated in init - gcc has problems allocating such big structures */
uint8_t * chunk_buffer;
uint8_t * ATTR_ALIGN(4) chunk_buffer;
/* pointer to start of the current chunk */
uint8_t * chunk_start;
/* pointer to current position in chunk_buffer */
@ -207,7 +203,7 @@ struct mpeg2dec_s
fbuf_alloc_t fbuf_alloc[3];
int custom_fbuf;
uint8_t * yuv_buf[3][3];
uint8_t * yuv_buf[3][MPEG2_COMPONENTS];
int yuv_index;
mpeg2_convert_t * convert;
void * convert_arg;

View file

@ -1,2 +1,15 @@
/* $Id$ */
#ifndef MPEG2DEC_CONFIG_H
#define MPEG2DEC_CONFIG_H
#define ATTRIBUTE_ALIGNED_MAX 16
#ifdef HAVE_LCD_COLOR
#define MPEG2_COLOR 1
#define MPEG2_COMPONENTS 3
#else
#define MPEG2_COLOR 0
#define MPEG2_COMPONENTS 1
#endif
#endif /* MPEG2DEC_CONFIG_H */

File diff suppressed because it is too large Load diff