summaryrefslogtreecommitdiff
path: root/apps/plugins
diff options
context:
space:
mode:
authorMichael Sevakis <jethead71@rockbox.org>2007-12-07 13:00:31 +0000
committerMichael Sevakis <jethead71@rockbox.org>2007-12-07 13:00:31 +0000
commit2b5f979d75a3d1c85b498c87ba6ae4c98c3011bc (patch)
treed9c40aa330a2bd973794eca11c86d559549422ca /apps/plugins
parent5886efabf5e4c96a8a96836d665aad935c727e31 (diff)
downloadrockbox-2b5f979d75a3d1c85b498c87ba6ae4c98c3011bc.zip
rockbox-2b5f979d75a3d1c85b498c87ba6ae4c98c3011bc.tar.gz
rockbox-2b5f979d75a3d1c85b498c87ba6ae4c98c3011bc.tar.bz2
rockbox-2b5f979d75a3d1c85b498c87ba6ae4c98c3011bc.tar.xz
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
Diffstat (limited to 'apps/plugins')
-rw-r--r--apps/plugins/mpegplayer/decode.c490
-rw-r--r--apps/plugins/mpegplayer/header.c592
-rw-r--r--apps/plugins/mpegplayer/idct.c109
-rw-r--r--apps/plugins/mpegplayer/idct_arm.S12
-rw-r--r--apps/plugins/mpegplayer/idct_coldfire.S12
-rw-r--r--apps/plugins/mpegplayer/motion_comp.c4
-rw-r--r--apps/plugins/mpegplayer/mpeg2.h106
-rw-r--r--apps/plugins/mpegplayer/mpeg2_internal.h78
-rw-r--r--apps/plugins/mpegplayer/slice.c1453
-rw-r--r--apps/plugins/mpegplayer/vlc.h40
10 files changed, 1785 insertions, 1111 deletions
diff --git a/apps/plugins/mpegplayer/decode.c b/apps/plugins/mpegplayer/decode.c
index ca3d29a..fac724c 100644
--- a/apps/plugins/mpegplayer/decode.c
+++ b/apps/plugins/mpegplayer/decode.c
@@ -33,9 +33,15 @@ extern struct plugin_api* rb;
#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)
{
- return &(mpeg2dec->info);
+ return &mpeg2dec->info;
}
static inline int skip_chunk (mpeg2dec_t * mpeg2dec, int bytes)
@@ -46,27 +52,34 @@ static inline int skip_chunk (mpeg2dec_t * mpeg2dec, int bytes)
uint8_t byte;
if (!bytes)
- return 0;
+ return 0;
current = mpeg2dec->buf_start;
shift = mpeg2dec->shift;
limit = current + bytes;
- do {
- byte = *current++;
- if (shift == 0x00000100) {
- int skipped;
+ do
+ {
+ byte = *current++;
+
+ if (shift == 0x00000100)
+ {
+ int skipped;
- mpeg2dec->shift = 0xffffff00;
- skipped = current - mpeg2dec->buf_start;
- mpeg2dec->buf_start = current;
- return skipped;
- }
- shift = (shift | byte) << 8;
- } while (current < limit);
+ mpeg2dec->shift = 0xffffff00;
+ skipped = current - mpeg2dec->buf_start;
+ mpeg2dec->buf_start = current;
+
+ return skipped;
+ }
+
+ shift = (shift | byte) << 8;
+ }
+ while (current < limit);
mpeg2dec->shift = shift;
mpeg2dec->buf_start = current;
+
return 0;
}
@@ -79,27 +92,32 @@ static inline int copy_chunk (mpeg2dec_t * mpeg2dec, int bytes)
uint8_t byte;
if (!bytes)
- return 0;
+ return 0;
current = mpeg2dec->buf_start;
shift = mpeg2dec->shift;
chunk_ptr = mpeg2dec->chunk_ptr;
limit = current + bytes;
- do {
- byte = *current++;
- if (shift == 0x00000100) {
- int copied;
-
- mpeg2dec->shift = 0xffffff00;
- mpeg2dec->chunk_ptr = chunk_ptr + 1;
- copied = current - mpeg2dec->buf_start;
- mpeg2dec->buf_start = current;
- return copied;
- }
- shift = (shift | byte) << 8;
- *chunk_ptr++ = byte;
- } while (current < limit);
+ do
+ {
+ byte = *current++;
+
+ if (shift == 0x00000100)
+ {
+ int copied;
+
+ mpeg2dec->shift = 0xffffff00;
+ mpeg2dec->chunk_ptr = chunk_ptr + 1;
+ copied = current - mpeg2dec->buf_start;
+ mpeg2dec->buf_start = current;
+ return copied;
+ }
+
+ shift = (shift | byte) << 8;
+ *chunk_ptr++ = byte;
+ }
+ while (current < limit);
mpeg2dec->shift = shift;
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;
skipped = skip_chunk (mpeg2dec, size);
- if (!skipped) {
- mpeg2dec->bytes_since_tag += size;
- return STATE_BUFFER;
+
+ if (!skipped)
+ {
+ mpeg2dec->bytes_since_tag += size;
+ return STATE_BUFFER;
}
+
mpeg2dec->bytes_since_tag += skipped;
mpeg2dec->code = mpeg2dec->buf_start[-1];
+
return (mpeg2_state_t)-1;
}
mpeg2_state_t mpeg2_seek_header (mpeg2dec_t * mpeg2dec)
{
while (mpeg2dec->code != 0xb3 &&
- ((mpeg2dec->code != 0xb7 && mpeg2dec->code != 0xb8 &&
- mpeg2dec->code) || mpeg2dec->sequence.width == (unsigned)-1))
- if (seek_chunk (mpeg2dec) == STATE_BUFFER)
- return STATE_BUFFER;
- mpeg2dec->chunk_start = mpeg2dec->chunk_ptr = mpeg2dec->chunk_buffer;
+ ((mpeg2dec->code != 0xb7 &&
+ mpeg2dec->code != 0xb8 &&
+ mpeg2dec->code) ||
+ mpeg2dec->sequence.width == (unsigned)-1))
+ {
+ if (seek_chunk (mpeg2dec) == STATE_BUFFER)
+ return STATE_BUFFER;
+ }
+
+ mpeg2dec->chunk_start =
+ mpeg2dec->chunk_ptr = mpeg2dec->chunk_buffer;
+
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))
@@ -151,146 +182,187 @@ mpeg2_state_t mpeg2_parse (mpeg2dec_t * mpeg2dec)
{
int size_buffer, size_chunk, copied;
- if (mpeg2dec->action) {
- mpeg2_state_t state;
+ if (mpeg2dec->action)
+ {
+ mpeg2_state_t state;
- state = mpeg2dec->action (mpeg2dec);
- if ((int)state >= 0)
- return state;
+ state = mpeg2dec->action (mpeg2dec);
+
+ if ((int)state >= 0)
+ return state;
}
- while (1) {
- while ((unsigned) (mpeg2dec->code - mpeg2dec->first_decode_slice) <
- mpeg2dec->nb_decode_slices) {
- size_buffer = mpeg2dec->buf_end - mpeg2dec->buf_start;
- size_chunk = (mpeg2dec->chunk_buffer + BUFFER_SIZE -
- mpeg2dec->chunk_ptr);
- if (size_buffer <= size_chunk) {
- copied = copy_chunk (mpeg2dec, size_buffer);
- if (!copied) {
- mpeg2dec->bytes_since_tag += size_buffer;
- mpeg2dec->chunk_ptr += size_buffer;
- return STATE_BUFFER;
- }
- } else {
- copied = copy_chunk (mpeg2dec, size_chunk);
- if (!copied) {
- /* filled the chunk buffer without finding a start code */
- mpeg2dec->bytes_since_tag += size_chunk;
- mpeg2dec->action = seek_chunk;
- return STATE_INVALID;
- }
+ while (1)
+ {
+ while ((unsigned) (mpeg2dec->code - mpeg2dec->first_decode_slice) <
+ mpeg2dec->nb_decode_slices)
+ {
+ size_buffer = mpeg2dec->buf_end - mpeg2dec->buf_start;
+ size_chunk = mpeg2dec->chunk_buffer + BUFFER_SIZE -
+ mpeg2dec->chunk_ptr;
+
+ if (size_buffer <= size_chunk)
+ {
+ copied = copy_chunk (mpeg2dec, size_buffer);
+
+ if (!copied)
+ {
+ mpeg2dec->bytes_since_tag += size_buffer;
+ mpeg2dec->chunk_ptr += size_buffer;
+ return STATE_BUFFER;
+ }
+ }
+ else
+ {
+ copied = copy_chunk (mpeg2dec, size_chunk);
+
+ if (!copied)
+ {
+ /* filled the chunk buffer without finding a start code */
+ mpeg2dec->bytes_since_tag += size_chunk;
+ mpeg2dec->action = seek_chunk;
+ return STATE_INVALID;
+ }
+ }
+
+ mpeg2dec->bytes_since_tag += copied;
+
+ mpeg2_slice (&mpeg2dec->decoder, mpeg2dec->code,
+ mpeg2dec->chunk_start);
+ mpeg2dec->code = mpeg2dec->buf_start[-1];
+ mpeg2dec->chunk_ptr = mpeg2dec->chunk_start;
}
- mpeg2dec->bytes_since_tag += copied;
-
- mpeg2_slice (&(mpeg2dec->decoder), mpeg2dec->code,
- mpeg2dec->chunk_start);
- mpeg2dec->code = mpeg2dec->buf_start[-1];
- mpeg2dec->chunk_ptr = mpeg2dec->chunk_start;
- }
- if ((unsigned) (mpeg2dec->code - 1) >= 0xb0 - 1)
- break;
- if (seek_chunk (mpeg2dec) == STATE_BUFFER)
- return STATE_BUFFER;
+
+ if ((unsigned) (mpeg2dec->code - 1) >= 0xb0 - 1)
+ break;
+
+ if (seek_chunk (mpeg2dec) == STATE_BUFFER)
+ return STATE_BUFFER;
}
- switch (mpeg2dec->code) {
+ switch (mpeg2dec->code)
+ {
case 0x00:
- mpeg2dec->action = mpeg2_header_picture_start;
- return mpeg2dec->state;
+ mpeg2dec->action = mpeg2_header_picture_start;
+ return mpeg2dec->state;
case 0xb7:
- mpeg2dec->action = mpeg2_header_end;
- break;
+ mpeg2dec->action = mpeg2_header_end;
+ break;
case 0xb3:
case 0xb8:
- mpeg2dec->action = mpeg2_parse_header;
- break;
+ mpeg2dec->action = mpeg2_parse_header;
+ break;
default:
- mpeg2dec->action = seek_chunk;
- return STATE_INVALID;
+ mpeg2dec->action = seek_chunk;
+ return STATE_INVALID;
}
+
return (mpeg2dec->state == STATE_SLICE) ? STATE_SLICE : STATE_INVALID;
}
mpeg2_state_t mpeg2_parse_header (mpeg2dec_t * mpeg2dec)
{
- static int (* process_header[]) (mpeg2dec_t * mpeg2dec) = {
- mpeg2_header_picture, mpeg2_header_extension, mpeg2_header_user_data,
- mpeg2_header_sequence, NULL, NULL, NULL, NULL, mpeg2_header_gop
+ 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
};
+
int size_buffer, size_chunk, copied;
mpeg2dec->action = mpeg2_parse_header;
- mpeg2dec->info.user_data = NULL; mpeg2dec->info.user_data_len = 0;
- while (1) {
- size_buffer = mpeg2dec->buf_end - mpeg2dec->buf_start;
- size_chunk = (mpeg2dec->chunk_buffer + BUFFER_SIZE -
- mpeg2dec->chunk_ptr);
- if (size_buffer <= size_chunk) {
- copied = copy_chunk (mpeg2dec, size_buffer);
- if (!copied) {
- mpeg2dec->bytes_since_tag += size_buffer;
- mpeg2dec->chunk_ptr += size_buffer;
- return STATE_BUFFER;
- }
- } else {
- copied = copy_chunk (mpeg2dec, size_chunk);
- if (!copied) {
- /* filled the chunk buffer without finding a start code */
- mpeg2dec->bytes_since_tag += size_chunk;
- mpeg2dec->code = 0xb4;
- mpeg2dec->action = mpeg2_seek_header;
- return STATE_INVALID;
- }
- }
- mpeg2dec->bytes_since_tag += copied;
-
- if (process_header[mpeg2dec->code & 0x0b] (mpeg2dec)) {
- mpeg2dec->code = mpeg2dec->buf_start[-1];
- mpeg2dec->action = mpeg2_seek_header;
- return STATE_INVALID;
- }
-
- mpeg2dec->code = mpeg2dec->buf_start[-1];
- switch (RECEIVED (mpeg2dec->code, mpeg2dec->state)) {
-
- /* state transition after a sequence header */
- case RECEIVED (0x00, STATE_SEQUENCE):
- mpeg2dec->action = mpeg2_header_picture_start;
- case RECEIVED (0xb8, STATE_SEQUENCE):
- mpeg2_header_sequence_finalize (mpeg2dec);
- break;
-
- /* other legal state transitions */
- case RECEIVED (0x00, STATE_GOP):
- mpeg2_header_gop_finalize (mpeg2dec);
- mpeg2dec->action = mpeg2_header_picture_start;
- break;
- case RECEIVED (0x01, STATE_PICTURE):
- case RECEIVED (0x01, STATE_PICTURE_2ND):
- mpeg2_header_picture_finalize (mpeg2dec);
- mpeg2dec->action = mpeg2_header_slice_start;
- break;
-
- /* legal headers within a given state */
- case RECEIVED (0xb2, STATE_SEQUENCE):
- case RECEIVED (0xb2, STATE_GOP):
- case RECEIVED (0xb2, STATE_PICTURE):
- case RECEIVED (0xb2, STATE_PICTURE_2ND):
- case RECEIVED (0xb5, STATE_SEQUENCE):
- case RECEIVED (0xb5, STATE_PICTURE):
- case RECEIVED (0xb5, STATE_PICTURE_2ND):
- mpeg2dec->chunk_ptr = mpeg2dec->chunk_start;
- continue;
-
- default:
- mpeg2dec->action = mpeg2_seek_header;
- return STATE_INVALID;
- }
-
- mpeg2dec->chunk_start = mpeg2dec->chunk_ptr = mpeg2dec->chunk_buffer;
- mpeg2dec->user_data_len = 0;
- return mpeg2dec->state;
+ mpeg2dec->info.user_data = NULL;
+ mpeg2dec->info.user_data_len = 0;
+
+ while (1)
+ {
+ size_buffer = mpeg2dec->buf_end - mpeg2dec->buf_start;
+ size_chunk = mpeg2dec->chunk_buffer + BUFFER_SIZE -
+ mpeg2dec->chunk_ptr;
+
+ if (size_buffer <= size_chunk)
+ {
+ copied = copy_chunk (mpeg2dec, size_buffer);
+
+ if (!copied)
+ {
+ mpeg2dec->bytes_since_tag += size_buffer;
+ mpeg2dec->chunk_ptr += size_buffer;
+ return STATE_BUFFER;
+ }
+ }
+ else
+ {
+ copied = copy_chunk (mpeg2dec, size_chunk);
+
+ if (!copied)
+ {
+ /* filled the chunk buffer without finding a start code */
+ mpeg2dec->bytes_since_tag += size_chunk;
+ mpeg2dec->code = 0xb4;
+ mpeg2dec->action = mpeg2_seek_header;
+ return STATE_INVALID;
+ }
+ }
+
+ mpeg2dec->bytes_since_tag += copied;
+
+ if (process_header[mpeg2dec->code & 0x0b] (mpeg2dec))
+ {
+ mpeg2dec->code = mpeg2dec->buf_start[-1];
+ mpeg2dec->action = mpeg2_seek_header;
+ return STATE_INVALID;
+ }
+
+ mpeg2dec->code = mpeg2dec->buf_start[-1];
+
+ switch (RECEIVED (mpeg2dec->code, mpeg2dec->state))
+ {
+ /* state transition after a sequence header */
+ case RECEIVED (0x00, STATE_SEQUENCE):
+ mpeg2dec->action = mpeg2_header_picture_start;
+ case RECEIVED (0xb8, STATE_SEQUENCE):
+ mpeg2_header_sequence_finalize (mpeg2dec);
+ break;
+
+ /* other legal state transitions */
+ case RECEIVED (0x00, STATE_GOP):
+ mpeg2_header_gop_finalize (mpeg2dec);
+ mpeg2dec->action = mpeg2_header_picture_start;
+ break;
+ case RECEIVED (0x01, STATE_PICTURE):
+ case RECEIVED (0x01, STATE_PICTURE_2ND):
+ mpeg2_header_picture_finalize (mpeg2dec);
+ mpeg2dec->action = mpeg2_header_slice_start;
+ break;
+
+ /* legal headers within a given state */
+ case RECEIVED (0xb2, STATE_SEQUENCE):
+ case RECEIVED (0xb2, STATE_GOP):
+ case RECEIVED (0xb2, STATE_PICTURE):
+ case RECEIVED (0xb2, STATE_PICTURE_2ND):
+ case RECEIVED (0xb5, STATE_SEQUENCE):
+ case RECEIVED (0xb5, STATE_PICTURE):
+ case RECEIVED (0xb5, STATE_PICTURE_2ND):
+ mpeg2dec->chunk_ptr = mpeg2dec->chunk_start;
+ continue;
+
+ default:
+ mpeg2dec->action = mpeg2_seek_header;
+ return STATE_INVALID;
+ }
+
+ mpeg2dec->chunk_start = mpeg2dec->chunk_ptr = mpeg2dec->chunk_buffer;
+ mpeg2dec->user_data_len = 0;
+
+ 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;
int error;
- error = convert (MPEG2_CONVERT_SET, NULL, &(mpeg2dec->sequence), 0,
- arg, &convert_init);
- if (!error) {
- mpeg2dec->convert = convert;
- mpeg2dec->convert_arg = arg;
- mpeg2dec->convert_id_size = convert_init.id_size;
- mpeg2dec->convert_stride = 0;
+ error = convert (MPEG2_CONVERT_SET, NULL, &mpeg2dec->sequence, 0,
+ arg, &convert_init);
+
+ if (!error)
+ {
+ mpeg2dec->convert = convert;
+ mpeg2dec->convert_arg = arg;
+ mpeg2dec->convert_id_size = convert_init.id_size;
+ mpeg2dec->convert_stride = 0;
}
+
return error;
}
int mpeg2_stride (mpeg2dec_t * mpeg2dec, int stride)
{
- if (!mpeg2dec->convert) {
- if (stride < (int) mpeg2dec->sequence.width)
- stride = mpeg2dec->sequence.width;
- mpeg2dec->decoder.stride_frame = stride;
- } else {
- mpeg2_convert_init_t convert_init;
-
- stride = mpeg2dec->convert (MPEG2_CONVERT_STRIDE, NULL,
- &(mpeg2dec->sequence), stride,
- mpeg2dec->convert_arg,
- &convert_init);
- mpeg2dec->convert_id_size = convert_init.id_size;
- mpeg2dec->convert_stride = stride;
+ if (!mpeg2dec->convert)
+ {
+ if (stride < (int) mpeg2dec->sequence.width)
+ stride = mpeg2dec->sequence.width;
+
+ mpeg2dec->decoder.stride_frame = stride;
+ }
+ else
+ {
+ mpeg2_convert_init_t convert_init;
+
+ stride = mpeg2dec->convert(MPEG2_CONVERT_STRIDE, NULL,
+ &mpeg2dec->sequence, stride,
+ mpeg2dec->convert_arg,
+ &convert_init);
+
+ mpeg2dec->convert_id_size = convert_init.id_size;
+ mpeg2dec->convert_stride = stride;
}
+
return stride;
}
@@ -333,21 +414,29 @@ void mpeg2_set_buf (mpeg2dec_t * mpeg2dec, uint8_t * buf[3], void * id)
{
mpeg2_fbuf_t * fbuf;
- if (mpeg2dec->custom_fbuf) {
- if (mpeg2dec->state == STATE_SEQUENCE) {
- mpeg2dec->fbuf[2] = mpeg2dec->fbuf[1];
- mpeg2dec->fbuf[1] = mpeg2dec->fbuf[0];
- }
- mpeg2_set_fbuf (mpeg2dec, (mpeg2dec->decoder.coding_type ==
- PIC_FLAG_CODING_TYPE_B));
- fbuf = mpeg2dec->fbuf[0];
- } else {
- fbuf = &(mpeg2dec->fbuf_alloc[mpeg2dec->alloc_index].fbuf);
- mpeg2dec->alloc_index_user = ++mpeg2dec->alloc_index;
+ if (mpeg2dec->custom_fbuf)
+ {
+ if (mpeg2dec->state == STATE_SEQUENCE)
+ {
+ mpeg2dec->fbuf[2] = mpeg2dec->fbuf[1];
+ mpeg2dec->fbuf[1] = mpeg2dec->fbuf[0];
+ }
+
+ mpeg2_set_fbuf (mpeg2dec, (mpeg2dec->decoder.coding_type ==
+ PIC_FLAG_CODING_TYPE_B));
+
+ fbuf = mpeg2dec->fbuf[0];
+ }
+ else
+ {
+ fbuf = &mpeg2dec->fbuf_alloc[mpeg2dec->alloc_index].fbuf;
+ mpeg2dec->alloc_index_user = ++mpeg2dec->alloc_index;
}
+
fbuf->buf[0] = buf[0];
fbuf->buf[1] = buf[1];
fbuf->buf[2] = buf[2];
+
fbuf->id = id;
}
@@ -390,31 +479,26 @@ void mpeg2_reset (mpeg2dec_t * mpeg2dec, int full_reset)
mpeg2dec->state = STATE_INVALID;
mpeg2dec->first = 1;
- mpeg2_reset_info(&(mpeg2dec->info));
+ mpeg2_reset_info(&mpeg2dec->info);
mpeg2dec->info.gop = NULL;
mpeg2dec->info.user_data = NULL;
mpeg2dec->info.user_data_len = 0;
- if (full_reset) {
- mpeg2dec->info.sequence = NULL;
- mpeg2_header_state_init (mpeg2dec);
- }
+ if (full_reset)
+ {
+ mpeg2dec->info.sequence = NULL;
+ 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 * mpeg2dec;
mpeg2_idct_init ();
- mpeg2dec = (mpeg2dec_t *) mpeg2_malloc (sizeof (mpeg2dec_t),
- MPEG2_ALLOC_MPEG2DEC);
+ mpeg2dec = (mpeg2dec_t *)mpeg2_malloc(sizeof (mpeg2dec_t),
+ MPEG2_ALLOC_MPEG2DEC);
if (mpeg2dec == NULL)
return NULL;
@@ -425,8 +509,8 @@ mpeg2dec_t * mpeg2_init (void)
rb->memset (mpeg2dec->decoder.DCTblock, 0, 64 * sizeof (int16_t));
rb->memset (mpeg2dec->quantizer_matrix, 0, 4 * 64 * sizeof (uint8_t));
- mpeg2dec->chunk_buffer = (uint8_t *) mpeg2_malloc (BUFFER_SIZE + 4,
- MPEG2_ALLOC_CHUNK);
+ mpeg2dec->chunk_buffer = (uint8_t *)mpeg2_malloc(BUFFER_SIZE + 4,
+ MPEG2_ALLOC_CHUNK);
mpeg2dec->sequence.width = (unsigned)-1;
mpeg2_reset (mpeg2dec, 1);
diff --git a/apps/plugins/mpegplayer/header.c b/apps/plugins/mpegplayer/header.c
index 664be4b..52a301f 100644
--- a/apps/plugins/mpegplayer/header.c
+++ b/apps/plugins/mpegplayer/header.c
@@ -40,7 +40,8 @@ extern struct plugin_api* rb;
#define PIC_CODING_EXT 0x100
/* default intra quant matrix, in zig-zag order */
-static const uint8_t default_intra_quantizer_matrix[64] = {
+static const uint8_t default_intra_quantizer_matrix[64] =
+{
8,
16, 16,
19, 16, 19,
@@ -58,20 +59,30 @@ static const uint8_t default_intra_quantizer_matrix[64] = {
83
};
-const uint8_t default_mpeg2_scan_norm[64] = {
+const uint8_t default_mpeg2_scan_norm[64] =
+{
/* Zig-Zag scan pattern */
- 0, 1, 8, 16, 9, 2, 3, 10, 17, 24, 32, 25, 18, 11, 4, 5,
- 12, 19, 26, 33, 40, 48, 41, 34, 27, 20, 13, 6, 7, 14, 21, 28,
- 35, 42, 49, 56, 57, 50, 43, 36, 29, 22, 15, 23, 30, 37, 44, 51,
- 58, 59, 52, 45, 38, 31, 39, 46, 53, 60, 61, 54, 47, 55, 62, 63
+ 0, 1, 8, 16, 9, 2, 3, 10,
+ 17, 24, 32, 25, 18, 11, 4, 5,
+ 12, 19, 26, 33, 40, 48, 41, 34,
+ 27, 20, 13, 6, 7, 14, 21, 28,
+ 35, 42, 49, 56, 57, 50, 43, 36,
+ 29, 22, 15, 23, 30, 37, 44, 51,
+ 58, 59, 52, 45, 38, 31, 39, 46,
+ 53, 60, 61, 54, 47, 55, 62, 63
};
-const uint8_t default_mpeg2_scan_alt[64] = {
+const uint8_t default_mpeg2_scan_alt[64] =
+{
/* Alternate scan pattern */
- 0, 8, 16, 24, 1, 9, 2, 10, 17, 25, 32, 40, 48, 56, 57, 49,
- 41, 33, 26, 18, 3, 11, 4, 12, 19, 27, 34, 42, 50, 58, 35, 43,
- 51, 59, 20, 28, 5, 13, 6, 14, 21, 29, 36, 44, 52, 60, 37, 45,
- 53, 61, 22, 30, 7, 15, 23, 31, 38, 46, 54, 62, 39, 47, 55, 63
+ 0, 8, 16, 24, 1, 9, 2, 10,
+ 17, 25, 32, 40, 48, 56, 57, 49,
+ 41, 33, 26, 18, 3, 11, 4, 12,
+ 19, 27, 34, 42, 50, 58, 35, 43,
+ 51, 59, 20, 28, 5, 13, 6, 14,
+ 21, 29, 36, 44, 52, 60, 37, 45,
+ 53, 61, 22, 30, 7, 15, 23, 31,
+ 38, 46, 54, 62, 39, 47, 55, 63
};
uint8_t mpeg2_scan_norm[64] IDATA_ATTR;
@@ -79,33 +90,49 @@ uint8_t mpeg2_scan_alt[64] IDATA_ATTR;
void mpeg2_header_state_init (mpeg2dec_t * mpeg2dec)
{
- if (mpeg2dec->sequence.width != (unsigned)-1) {
+ if (mpeg2dec->sequence.width != (unsigned)-1)
+ {
int i;
mpeg2dec->sequence.width = (unsigned)-1;
+
if (!mpeg2dec->custom_fbuf)
+ {
for (i = mpeg2dec->alloc_index_user;
- i < mpeg2dec->alloc_index; i++) {
- mpeg2_free (mpeg2dec->fbuf_alloc[i].fbuf.buf[0]);
- mpeg2_free (mpeg2dec->fbuf_alloc[i].fbuf.buf[1]);
- mpeg2_free (mpeg2dec->fbuf_alloc[i].fbuf.buf[2]);
+ i < mpeg2dec->alloc_index; i++)
+ {
+ mpeg2_free(mpeg2dec->fbuf_alloc[i].fbuf.buf[0]);
+ mpeg2_free(mpeg2dec->fbuf_alloc[i].fbuf.buf[1]);
+ mpeg2_free(mpeg2dec->fbuf_alloc[i].fbuf.buf[2]);
}
+ }
+
if (mpeg2dec->convert_start)
- for (i = 0; i < 3; i++) {
- mpeg2_free (mpeg2dec->yuv_buf[i][0]);
- mpeg2_free (mpeg2dec->yuv_buf[i][1]);
- mpeg2_free (mpeg2dec->yuv_buf[i][2]);
+ {
+ for (i = 0; i < 3; i++)
+ {
+ mpeg2_free(mpeg2dec->yuv_buf[i][0]);
+ mpeg2_free(mpeg2dec->yuv_buf[i][1]);
+ mpeg2_free(mpeg2dec->yuv_buf[i][2]);
}
+ }
+
if (mpeg2dec->decoder.convert_id)
- mpeg2_free (mpeg2dec->decoder.convert_id);
+ {
+ mpeg2_free(mpeg2dec->decoder.convert_id);
+ }
}
+
mpeg2dec->decoder.coding_type = I_TYPE;
mpeg2dec->decoder.convert = NULL;
mpeg2dec->decoder.convert_id = NULL;
+
mpeg2dec->picture = mpeg2dec->pictures;
+
mpeg2dec->fbuf[0] = &mpeg2dec->fbuf_alloc[0].fbuf;
mpeg2dec->fbuf[1] = &mpeg2dec->fbuf_alloc[1].fbuf;
mpeg2dec->fbuf[2] = &mpeg2dec->fbuf_alloc[2].fbuf;
+
mpeg2dec->first = 1;
mpeg2dec->alloc_index = 0;
mpeg2dec->alloc_index_user = 0;
@@ -119,14 +146,21 @@ void mpeg2_header_state_init (mpeg2dec_t * mpeg2dec)
void mpeg2_reset_info (mpeg2_info_t * info)
{
- info->current_picture = info->current_picture_2nd = NULL;
- info->display_picture = info->display_picture_2nd = NULL;
- info->current_fbuf = info->display_fbuf = info->discard_fbuf = NULL;
+ info->current_picture =
+ info->current_picture_2nd = NULL;
+
+ info->display_picture =
+ info->display_picture_2nd = NULL;
+
+ info->current_fbuf =
+ info->display_fbuf =
+ info->discard_fbuf = NULL;
}
static void info_user_data (mpeg2dec_t * mpeg2dec)
{
- if (mpeg2dec->user_data_len) {
+ if (mpeg2dec->user_data_len)
+ {
mpeg2dec->info.user_data = mpeg2dec->chunk_buffer;
mpeg2dec->info.user_data_len = mpeg2dec->user_data_len - 3;
}
@@ -134,60 +168,81 @@ static void info_user_data (mpeg2dec_t * mpeg2dec)
int mpeg2_header_sequence (mpeg2dec_t * mpeg2dec)
{
- uint8_t * buffer = mpeg2dec->chunk_start;
- mpeg2_sequence_t * sequence = &(mpeg2dec->new_sequence);
- static unsigned int frame_period[16] = {
+ static const unsigned int frame_period[16] =
+ {
0, 1126125, 1125000, 1080000, 900900, 900000, 540000, 450450, 450000,
/* unofficial: xing 15 fps */
1800000,
/* unofficial: libmpeg3 "Unofficial economy rates" 5/10/12/15 fps */
5400000, 2700000, 2250000, 1800000, 0, 0
};
+
+ uint8_t * buffer = mpeg2dec->chunk_start;
+ mpeg2_sequence_t * sequence = &mpeg2dec->new_sequence;
int i;
if ((buffer[6] & 0x20) != 0x20) /* missing marker_bit */
return 1;
i = (buffer[0] << 16) | (buffer[1] << 8) | buffer[2];
- if (! (sequence->display_width = sequence->picture_width = i >> 12))
+
+ if (!(sequence->display_width = sequence->picture_width = i >> 12))
return 1;
- if (! (sequence->display_height = sequence->picture_height = i & 0xfff))
+
+ if (!(sequence->display_height = sequence->picture_height = i & 0xfff))
return 1;
+
sequence->width = (sequence->picture_width + 15) & ~15;
sequence->height = (sequence->picture_height + 15) & ~15;
sequence->chroma_width = sequence->width >> 1;
sequence->chroma_height = sequence->height >> 1;
- sequence->flags = (SEQ_FLAG_PROGRESSIVE_SEQUENCE |
- SEQ_VIDEO_FORMAT_UNSPECIFIED);
+ sequence->flags = SEQ_FLAG_PROGRESSIVE_SEQUENCE |
+ SEQ_VIDEO_FORMAT_UNSPECIFIED;
sequence->pixel_width = buffer[3] >> 4; /* aspect ratio */
sequence->frame_period = frame_period[buffer[3] & 15];
sequence->byte_rate = (buffer[4]<<10) | (buffer[5]<<2) | (buffer[6]>>6);
- sequence->vbv_buffer_size = ((buffer[6]<<16)|(buffer[7]<<8))&0x1ff800;
+ sequence->vbv_buffer_size = ((buffer[6]<<16) | (buffer[7]<<8)) & 0x1ff800;
if (buffer[7] & 4)
sequence->flags |= SEQ_FLAG_CONSTRAINED_PARAMETERS;
mpeg2dec->copy_matrix = 3;
- if (buffer[7] & 2) {
+
+ if (buffer[7] & 2)
+ {
for (i = 0; i < 64; i++)
+ {
mpeg2dec->new_quantizer_matrix[0][mpeg2_scan_norm[i]] =
(buffer[i+7] << 7) | (buffer[i+8] >> 1);
+ }
+
buffer += 64;
- } else
+ }
+ else
+ {
for (i = 0; i < 64; i++)
+ {
mpeg2dec->new_quantizer_matrix[0][mpeg2_scan_norm[i]] =
default_intra_quantizer_matrix[i];
+ }
+ }
if (buffer[7] & 1)
+ {
for (i = 0; i < 64; i++)
+ {
mpeg2dec->new_quantizer_matrix[1][mpeg2_scan_norm[i]] =
buffer[i+8];
+ }
+ }
else
+ {
rb->memset (mpeg2dec->new_quantizer_matrix[1], 16, 64);
+ }
sequence->profile_level_id = 0x80;
sequence->colour_primaries = 0;
@@ -196,7 +251,9 @@ int mpeg2_header_sequence (mpeg2dec_t * mpeg2dec)
mpeg2dec->ext_state = SEQ_EXT;
mpeg2dec->state = STATE_SEQUENCE;
- mpeg2dec->display_offset_x = mpeg2dec->display_offset_y = 0;
+
+ mpeg2dec->display_offset_x =
+ mpeg2dec->display_offset_y = 0;
return 0;
}
@@ -204,7 +261,7 @@ int mpeg2_header_sequence (mpeg2dec_t * mpeg2dec)
static int sequence_ext (mpeg2dec_t * mpeg2dec)
{
uint8_t * buffer = mpeg2dec->chunk_start;
- mpeg2_sequence_t * sequence = &(mpeg2dec->new_sequence);
+ mpeg2_sequence_t * sequence = &mpeg2dec->new_sequence;
uint32_t flags;
if (!(buffer[3] & 1))
@@ -212,23 +269,32 @@ static int sequence_ext (mpeg2dec_t * mpeg2dec)
sequence->profile_level_id = (buffer[0] << 4) | (buffer[1] >> 4);
- sequence->display_width = sequence->picture_width +=
- ((buffer[1] << 13) | (buffer[2] << 5)) & 0x3000;
- sequence->display_height = sequence->picture_height +=
- (buffer[2] << 7) & 0x3000;
+ sequence->picture_width += ((buffer[1] << 13) | (buffer[2] << 5)) & 0x3000;
+ sequence->display_width = sequence->picture_width;
+
+ sequence->picture_height += (buffer[2] << 7) & 0x3000;
+ sequence->display_height = sequence->picture_height;
+
sequence->width = (sequence->picture_width + 15) & ~15;
sequence->height = (sequence->picture_height + 15) & ~15;
+
flags = sequence->flags | SEQ_FLAG_MPEG2;
- if (!(buffer[1] & 8)) {
+
+ if (!(buffer[1] & 8))
+ {
flags &= ~SEQ_FLAG_PROGRESSIVE_SEQUENCE;
sequence->height = (sequence->height + 31) & ~31;
}
+
if (buffer[5] & 0x80)
flags |= SEQ_FLAG_LOW_DELAY;
+
sequence->flags = flags;
sequence->chroma_width = sequence->width;
sequence->chroma_height = sequence->height;
- switch (buffer[1] & 6) {
+
+ switch (buffer[1] & 6)
+ {
case 0: /* invalid */
return 1;
case 2: /* 4:2:0 */
@@ -252,12 +318,14 @@ static int sequence_ext (mpeg2dec_t * mpeg2dec)
static int sequence_display_ext (mpeg2dec_t * mpeg2dec)
{
uint8_t * buffer = mpeg2dec->chunk_start;
- mpeg2_sequence_t * sequence = &(mpeg2dec->new_sequence);
+ mpeg2_sequence_t * sequence = &mpeg2dec->new_sequence;
uint32_t flags;
- flags = ((sequence->flags & ~SEQ_MASK_VIDEO_FORMAT) |
- ((buffer[0]<<4) & SEQ_MASK_VIDEO_FORMAT));
- if (buffer[0] & 1) {
+ flags = (sequence->flags & ~SEQ_MASK_VIDEO_FORMAT) |
+ ((buffer[0] << 4) & SEQ_MASK_VIDEO_FORMAT);
+
+ if (buffer[0] & 1)
+ {
flags |= SEQ_FLAG_COLOUR_DESCRIPTION;
sequence->colour_primaries = buffer[1];
sequence->transfer_characteristics = buffer[2];
@@ -268,9 +336,11 @@ static int sequence_display_ext (mpeg2dec_t * mpeg2dec)
if (!(buffer[2] & 2)) /* missing marker_bit */
return 1;
- sequence->display_width = (buffer[1] << 6) | (buffer[2] >> 2);
+ sequence->display_width =
+ (buffer[1] << 6) | (buffer[2] >> 2);
+
sequence->display_height =
- ((buffer[2]& 1 ) << 13) | (buffer[3] << 5) | (buffer[4] >> 3);
+ ((buffer[2] & 1) << 13) | (buffer[3] << 5) | (buffer[4] >> 3);
return 0;
}
@@ -282,37 +352,63 @@ static inline void finalize_sequence (mpeg2_sequence_t * sequence)
sequence->byte_rate *= 50;
- if (sequence->flags & SEQ_FLAG_MPEG2) {
- switch (sequence->pixel_width) {
+ if (sequence->flags & SEQ_FLAG_MPEG2)
+ {
+ switch (sequence->pixel_width)
+ {
case 1: /* square pixels */
- sequence->pixel_width = sequence->pixel_height = 1; return;
+ sequence->pixel_width =
+ sequence->pixel_height = 1;
+ return;
case 2: /* 4:3 aspect ratio */
- width = 4; height = 3; break;
+ width = 4;
+ height = 3;
+ break;
case 3: /* 16:9 aspect ratio */
- width = 16; height = 9; break;
+ width = 16;
+ height = 9;
+ break;
case 4: /* 2.21:1 aspect ratio */
- width = 221; height = 100; break;
+ width = 221;
+ height = 100;
+ break;
default: /* illegal */
- sequence->pixel_width = sequence->pixel_height = 0; return;
+ sequence->pixel_width =
+ sequence->pixel_height = 0;
+ return;
}
+
width *= sequence->display_height;
height *= sequence->display_width;
-
- } else {
- if (sequence->byte_rate == 50 * 0x3ffff)
- sequence->byte_rate = 0; /* mpeg-1 VBR */
-
- switch (sequence->pixel_width) {
- case 0: case 15: /* illegal */
- sequence->pixel_width = sequence->pixel_height = 0; return;
+ }
+ else
+ {
+ if (sequence->byte_rate == 50 * 0x3ffff)
+ sequence->byte_rate = 0; /* mpeg-1 VBR */
+
+ switch (sequence->pixel_width)
+ {
+ case 0:
+ case 15: /* illegal */
+ sequence->pixel_width =
+ sequence->pixel_height = 0;
+ return;
case 1: /* square pixels */
- sequence->pixel_width = sequence->pixel_height = 1; return;
+ sequence->pixel_width =
+ sequence->pixel_height = 1;
+ return;
case 3: /* 720x576 16:9 */
- sequence->pixel_width = 64; sequence->pixel_height = 45; return;
+ sequence->pixel_width = 64;
+ sequence->pixel_height = 45;
+ return;
case 6: /* 720x480 16:9 */
- sequence->pixel_width = 32; sequence->pixel_height = 27; return;
+ sequence->pixel_width = 32;
+ sequence->pixel_height = 27;
+ return;
case 12: /* 720*480 4:3 */
- sequence->pixel_width = 8; sequence->pixel_height = 9; return;
+ sequence->pixel_width = 8;
+ sequence->pixel_height = 9;
+ return;
default:
height = 88 * sequence->pixel_width + 1171;
width = 2000;
@@ -321,11 +417,15 @@ static inline void finalize_sequence (mpeg2_sequence_t * sequence)
sequence->pixel_width = width;
sequence->pixel_height = height;
- while (width) { /* find greatest common divisor */
+
+ /* find greatest common divisor */
+ while (width)
+ {
int tmp = width;
width = height % tmp;
height = tmp;
}
+
sequence->pixel_width /= height;
sequence->pixel_height /= height;
}
@@ -333,59 +433,73 @@ static inline void finalize_sequence (mpeg2_sequence_t * sequence)
static void copy_matrix (mpeg2dec_t * mpeg2dec, int index)
{
if (rb->memcmp (mpeg2dec->quantizer_matrix[index],
- mpeg2dec->new_quantizer_matrix[index], 64)) {
+ mpeg2dec->new_quantizer_matrix[index], 64))
+ {
rb->memcpy (mpeg2dec->quantizer_matrix[index],
mpeg2dec->new_quantizer_matrix[index], 64);
+
mpeg2dec->scaled[index] = -1;
}
}
static void finalize_matrix (mpeg2dec_t * mpeg2dec)
{
- mpeg2_decoder_t * decoder = &(mpeg2dec->decoder);
+ mpeg2_decoder_t *decoder = &mpeg2dec->decoder;
int i;
- for (i = 0; i < 2; i++) {
+ for (i = 0; i < 2; i++)
+ {
if (mpeg2dec->copy_matrix & (1 << i))
copy_matrix (mpeg2dec, i);
+
if ((mpeg2dec->copy_matrix & (4 << i)) &&
- rb->memcmp (mpeg2dec->quantizer_matrix[i],
- mpeg2dec->new_quantizer_matrix[i+2], 64)) {
+ rb->memcmp(mpeg2dec->quantizer_matrix[i],
+ mpeg2dec->new_quantizer_matrix[i+2], 64))
+ {
copy_matrix (mpeg2dec, i + 2);
decoder->chroma_quantizer[i] = decoder->quantizer_prescale[i+2];
- } else if (mpeg2dec->copy_matrix & (5 << i))
+ }
+ else if (mpeg2dec->copy_matrix & (5 << i))
+ {
decoder->chroma_quantizer[i] = decoder->quantizer_prescale[i];
+ }
}
}
static mpeg2_state_t invalid_end_action (mpeg2dec_t * mpeg2dec)
{
- mpeg2_reset_info (&(mpeg2dec->info));
+ mpeg2_reset_info (&mpeg2dec->info);
+
mpeg2dec->info.gop = NULL;
+
info_user_data (mpeg2dec);
+
mpeg2_header_state_init (mpeg2dec);
+
mpeg2dec->sequence = mpeg2dec->new_sequence;
mpeg2dec->action = mpeg2_seek_header;
mpeg2dec->state = STATE_SEQUENCE;
+
return STATE_SEQUENCE;
}
void mpeg2_header_sequence_finalize (mpeg2dec_t * mpeg2dec)
{
- mpeg2_sequence_t * sequence = &(mpeg2dec->new_sequence);
- mpeg2_decoder_t * decoder = &(mpeg2dec->decoder);
+ mpeg2_sequence_t * sequence = &mpeg2dec->new_sequence;
+ mpeg2_decoder_t * decoder = &mpeg2dec->decoder;
- finalize_sequence (sequence);
- finalize_matrix (mpeg2dec);
+ finalize_sequence(sequence);
+ finalize_matrix(mpeg2dec);
decoder->mpeg1 = !(sequence->flags & SEQ_FLAG_MPEG2);
decoder->width = sequence->width;
decoder->height = sequence->height;
- decoder->vertical_position_extension = (sequence->picture_height > 2800);
- decoder->chroma_format = ((sequence->chroma_width == sequence->width) +
- (sequence->chroma_height == sequence->height));
+ decoder->vertical_position_extension = sequence->picture_height > 2800;
+ decoder->chroma_format = (sequence->chroma_width == sequence->width) +
+ (sequence->chroma_height == sequence->height);
- if (mpeg2dec->sequence.width != (unsigned)-1) {
+ if (mpeg2dec->sequence.width != (unsigned)-1)
+ {
unsigned int new_byte_rate;
/*
@@ -400,38 +514,50 @@ void mpeg2_header_sequence_finalize (mpeg2dec_t * mpeg2dec)
*/
new_byte_rate = sequence->byte_rate;
sequence->byte_rate = mpeg2dec->sequence.byte_rate;
- if (rb->memcmp (&(mpeg2dec->sequence), sequence,
- sizeof (mpeg2_sequence_t))) {
+
+ if (rb->memcmp(&mpeg2dec->sequence, sequence,
+ sizeof (mpeg2_sequence_t)))
+ {
decoder->stride_frame = sequence->width;
sequence->byte_rate = new_byte_rate;
+
mpeg2_header_end (mpeg2dec);
+
mpeg2dec->action = invalid_end_action;
mpeg2dec->state = STATE_INVALID_END;
return;
}
+
sequence->byte_rate = new_byte_rate;
mpeg2dec->state = STATE_SEQUENCE_REPEATED;
- } else
+ }
+ else
+ {
decoder->stride_frame = sequence->width;
+ }
+
mpeg2dec->sequence = *sequence;
- mpeg2_reset_info (&(mpeg2dec->info));
- mpeg2dec->info.sequence = &(mpeg2dec->sequence);
+ mpeg2_reset_info(&mpeg2dec->info);
+ mpeg2dec->info.sequence = &mpeg2dec->sequence;
mpeg2dec->info.gop = NULL;
+
info_user_data (mpeg2dec);
}
int mpeg2_header_gop (mpeg2dec_t * mpeg2dec)
{
uint8_t * buffer = mpeg2dec->chunk_start;
- mpeg2_gop_t * gop = &(mpeg2dec->new_gop);
+ mpeg2_gop_t * gop = &mpeg2dec->new_gop;
- if (! (buffer[1] & 8))
+ if (!(buffer[1] & 8))
return 1;
+
gop->hours = (buffer[0] >> 2) & 31;
gop->minutes = ((buffer[0] << 4) | (buffer[1] >> 4)) & 63;
gop->seconds = ((buffer[1] << 3) | (buffer[2] >> 5)) & 63;
gop->pictures = ((buffer[2] << 1) | (buffer[3] >> 7)) & 63;
gop->flags = (buffer[0] >> 7) | ((buffer[3] >> 4) & 6);
+
mpeg2dec->state = STATE_GOP;
return 0;
}
@@ -439,8 +565,8 @@ int mpeg2_header_gop (mpeg2dec_t * mpeg2dec)
void mpeg2_header_gop_finalize (mpeg2dec_t * mpeg2dec)
{
mpeg2dec->gop = mpeg2dec->new_gop;
- mpeg2_reset_info (&(mpeg2dec->info));
- mpeg2dec->info.gop = &(mpeg2dec->gop);
+ mpeg2_reset_info (&mpeg2dec->info);
+ mpeg2dec->info.gop = &mpeg2dec->gop;
info_user_data (mpeg2dec);
}
@@ -449,52 +575,67 @@ void mpeg2_set_fbuf (mpeg2dec_t * mpeg2dec, int b_type)
int i;
for (i = 0; i < 3; i++)
+ {
if (mpeg2dec->fbuf[1] != &mpeg2dec->fbuf_alloc[i].fbuf &&
- mpeg2dec->fbuf[2] != &mpeg2dec->fbuf_alloc[i].fbuf) {
+ mpeg2dec->fbuf[2] != &mpeg2dec->fbuf_alloc[i].fbuf)
+ {
mpeg2dec->fbuf[0] = &mpeg2dec->fbuf_alloc[i].fbuf;
mpeg2dec->info.current_fbuf = mpeg2dec->fbuf[0];
- if (b_type || (mpeg2dec->sequence.flags & SEQ_FLAG_LOW_DELAY)) {
+
+ if (b_type || (mpeg2dec->sequence.flags & SEQ_FLAG_LOW_DELAY))
+ {
if (b_type || mpeg2dec->convert)
mpeg2dec->info.discard_fbuf = mpeg2dec->fbuf[0];
+
mpeg2dec->info.display_fbuf = mpeg2dec->fbuf[0];
}
+
break;
}
+ }
}
mpeg2_state_t mpeg2_header_picture_start (mpeg2dec_t * mpeg2dec)
{
- mpeg2_picture_t * picture = &(mpeg2dec->new_picture);
+ mpeg2_picture_t * picture = &mpeg2dec->new_picture;
- mpeg2dec->state = ((mpeg2dec->state != STATE_SLICE_1ST) ?
- STATE_PICTURE : STATE_PICTURE_2ND);
+ mpeg2dec->state = (mpeg2dec->state != STATE_SLICE_1ST) ?
+ STATE_PICTURE : STATE_PICTURE_2ND;
picture->flags = 0;
picture->tag = picture->tag2 = 0;
- if (mpeg2dec->num_tags) {
- if (mpeg2dec->bytes_since_tag >= 4) {
+
+ if (mpeg2dec->num_tags)
+ {
+ if (mpeg2dec->bytes_since_tag >= 4)
+ {
mpeg2dec->num_tags = 0;
picture->tag = mpeg2dec->tag_current;
picture->tag2 = mpeg2dec->tag2_current;
picture->flags = PIC_FLAG_TAGS;
- } else if (mpeg2dec->num_tags > 1) {
+ }
+ else if (mpeg2dec->num_tags > 1)
+ {
mpeg2dec->num_tags = 1;
picture->tag = mpeg2dec->tag_previous;
picture->tag2 = mpeg2dec->tag2_previous;
picture->flags = PIC_FLAG_TAGS;
}
}
+
picture->display_offset[0].x = picture->display_offset[1].x =
picture->display_offset[2].x = mpeg2dec->display_offset_x;
+
picture->display_offset[0].y = picture->display_offset[1].y =
picture->display_offset[2].y = mpeg2dec->display_offset_y;
+
return mpeg2_parse_header (mpeg2dec);
}
int mpeg2_header_picture (mpeg2dec_t * mpeg2dec)
{
uint8_t * buffer = mpeg2dec->chunk_start;
- mpeg2_picture_t * picture = &(mpeg2dec->new_picture);
- mpeg2_decoder_t * decoder = &(mpeg2dec->decoder);
+ mpeg2_picture_t * picture = &mpeg2dec->new_picture;
+ mpeg2_decoder_t * decoder = &mpeg2dec->decoder;
int type;
type = (buffer [1] >> 3) & 7;
@@ -504,7 +645,8 @@ int mpeg2_header_picture (mpeg2dec_t * mpeg2dec)
picture->flags |= type;
- if (type == PIC_FLAG_CODING_TYPE_P || type == PIC_FLAG_CODING_TYPE_B) {
+ if (type == PIC_FLAG_CODING_TYPE_P || type == PIC_FLAG_CODING_TYPE_B)
+ {
/* forward_f_code and backward_f_code - used in mpeg1 only */
decoder->f_motion.f_code[1] = (buffer[3] >> 2) & 1;
decoder->f_motion.f_code[0] =
@@ -531,8 +673,8 @@ int mpeg2_header_picture (mpeg2dec_t * mpeg2dec)
static int picture_coding_ext (mpeg2dec_t * mpeg2dec)
{
uint8_t * buffer = mpeg2dec->chunk_start;
- mpeg2_picture_t * picture = &(mpeg2dec->new_picture);
- mpeg2_decoder_t * decoder = &(mpeg2dec->decoder);
+ mpeg2_picture_t * picture = &mpeg2dec->new_picture;
+ mpeg2_decoder_t * decoder = &mpeg2dec->decoder;
uint32_t flags;
/* pre subtract 1 for use later in compute_motion_vector */
@@ -542,24 +684,32 @@ static int picture_coding_ext (mpeg2dec_t * mpeg2dec)
decoder->b_motion.f_code[1] = (buffer[2] >> 4) - 1;
flags = picture->flags;
+
decoder->intra_dc_precision = 7 - ((buffer[2] >> 2) & 3);
decoder->picture_structure = buffer[2] & 3;
- switch (decoder->picture_structure) {
+
+ switch (decoder->picture_structure)
+ {
case TOP_FIELD:
flags |= PIC_FLAG_TOP_FIELD_FIRST;
case BOTTOM_FIELD:
picture->nb_fields = 1;
break;
case FRAME_PICTURE:
- if (!(mpeg2dec->sequence.flags & SEQ_FLAG_PROGRESSIVE_SEQUENCE)) {
+ if (!(mpeg2dec->sequence.flags & SEQ_FLAG_PROGRESSIVE_SEQUENCE))
+ {
picture->nb_fields = (buffer[3] & 2) ? 3 : 2;
flags |= (buffer[3] & 128) ? PIC_FLAG_TOP_FIELD_FIRST : 0;
- } else
+ }
+ else
+ {
picture->nb_fields = (buffer[3]&2) ? ((buffer[3]&128) ? 6 : 4) : 2;
+ }
break;
default:
return 1;
}
+
decoder->top_field_first = buffer[3] >> 7;
decoder->frame_pred_frame_dct = (buffer[3] >> 6) & 1;
decoder->concealment_motion_vectors = (buffer[3] >> 5) & 1;
@@ -567,9 +717,13 @@ static int picture_coding_ext (mpeg2dec_t * mpeg2dec)
decoder->intra_vlc_format = (buffer[3] >> 3) & 1;
decoder->scan = (buffer[3] & 4) ? mpeg2_scan_alt : mpeg2_scan_norm;
flags |= (buffer[4] & 0x80) ? PIC_FLAG_PROGRESSIVE_FRAME : 0;
+
if (buffer[4] & 0x40)
+ {
flags |= (((buffer[4]<<26) | (buffer[5]<<18) | (buffer[6]<<10)) &
PIC_MASK_COMPOSITE_DISPLAY) | PIC_FLAG_COMPOSITE_DISPLAY;
+ }
+
picture->flags = flags;
mpeg2dec->ext_state = PIC_DISPLAY_EXT | COPYRIGHT_EXT | QUANT_MATRIX_EXT;
@@ -580,124 +734,162 @@ static int picture_coding_ext (mpeg2dec_t * mpeg2dec)
static int picture_display_ext (mpeg2dec_t * mpeg2dec)
{
uint8_t * buffer = mpeg2dec->chunk_start;
- mpeg2_picture_t * picture = &(mpeg2dec->new_picture);
+ mpeg2_picture_t * picture = &mpeg2dec->new_picture;
int i, nb_pos;
nb_pos = picture->nb_fields;
+
if (mpeg2dec->sequence.flags & SEQ_FLAG_PROGRESSIVE_SEQUENCE)
nb_pos >>= 1;
- for (i = 0; i < nb_pos; i++) {
+ for (i = 0; i < nb_pos; i++)
+ {
int x, y;
x = ((buffer[4*i] << 24) | (buffer[4*i+1] << 16) |
(buffer[4*i+2] << 8) | buffer[4*i+3]) >> (11-2*i);
+
y = ((buffer[4*i+2] << 24) | (buffer[4*i+3] << 16) |
(buffer[4*i+4] << 8) | buffer[4*i+5]) >> (10-2*i);
+
if (! (x & y & 1))
return 1;
+
picture->display_offset[i].x = mpeg2dec->display_offset_x = x >> 1;
picture->display_offset[i].y = mpeg2dec->display_offset_y = y >> 1;
}
- for (; i < 3; i++) {
+
+ for (; i < 3; i++)
+ {
picture->display_offset[i].x = mpeg2dec->display_offset_x;
picture->display_offset[i].y = mpeg2dec->display_offset_y;
}
+
return 0;
}
void mpeg2_header_picture_finalize (mpeg2dec_t * mpeg2dec)
{
- mpeg2_decoder_t * decoder = &(mpeg2dec->decoder);
- int old_type_b = (decoder->coding_type == B_TYPE);
+ mpeg2_decoder_t * decoder = &mpeg2dec->decoder;
+ int old_type_b = decoder->coding_type == B_TYPE;
int low_delay = mpeg2dec->sequence.flags & SEQ_FLAG_LOW_DELAY;
finalize_matrix (mpeg2dec);
decoder->coding_type = mpeg2dec->new_picture.flags & PIC_MASK_CODING_TYPE;
- if (mpeg2dec->state == STATE_PICTURE) {
+ if (mpeg2dec->state == STATE_PICTURE)
+ {
mpeg2_picture_t * picture;
mpeg2_picture_t * other;
decoder->second_field = 0;
picture = other = mpeg2dec->pictures;
+
if (old_type_b ^ (mpeg2dec->picture < mpeg2dec->pictures + 2))
picture += 2;
else
other += 2;
+
mpeg2dec->picture = picture;
*picture = mpeg2dec->new_picture;
- if (!old_type_b) {
+ if (!old_type_b)
+ {
mpeg2dec->fbuf[2] = mpeg2dec->fbuf[1];
mpeg2dec->fbuf[1] = mpeg2dec->fbuf[0];
}
+
mpeg2dec->fbuf[0] = NULL;
- mpeg2_reset_info (&(mpeg2dec->info));
+ mpeg2_reset_info (&mpeg2dec->info);
mpeg2dec->info.current_picture = picture;
mpeg2dec->info.display_picture = picture;
- if (decoder->coding_type != B_TYPE) {
- if (!low_delay) {
- if (mpeg2dec->first) {
+
+ if (decoder->coding_type != B_TYPE)
+ {
+ if (!low_delay)
+ {
+ if (mpeg2dec->first)
+ {
mpeg2dec->info.display_picture = NULL;
mpeg2dec->first = 0;
- } else {
+ }
+ else
+ {
mpeg2dec->info.display_picture = other;
+
if (other->nb_fields == 1)
mpeg2dec->info.display_picture_2nd = other + 1;
+
mpeg2dec->info.display_fbuf = mpeg2dec->fbuf[1];
}
}
+
if (!low_delay + !mpeg2dec->convert)
+ {
mpeg2dec->info.discard_fbuf =
mpeg2dec->fbuf[!low_delay + !mpeg2dec->convert];
+ }
}
- if (mpeg2dec->convert) {
+
+ if (mpeg2dec->convert)
+ {
mpeg2_convert_init_t convert_init;
- if (!mpeg2dec->convert_start) {
+
+ if (!mpeg2dec->convert_start)
+ {
int y_size, uv_size;
mpeg2dec->decoder.convert_id =
mpeg2_malloc (mpeg2dec->convert_id_size,
MPEG2_ALLOC_CONVERT_ID);
+
mpeg2dec->convert (MPEG2_CONVERT_START,
mpeg2dec->decoder.convert_id,
- &(mpeg2dec->sequence),
+ &mpeg2dec->sequence,
mpeg2dec->convert_stride,
mpeg2dec->convert_arg, &convert_init);
+
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);
+
mpeg2dec->yuv_buf[0][0] =
- (uint8_t *) mpeg2_malloc (y_size, MPEG2_ALLOC_YUV);
+ (uint8_t *) mpeg2_malloc(y_size, MPEG2_ALLOC_YUV);
mpeg2dec->yuv_buf[0][1] =
- (uint8_t *) mpeg2_malloc (uv_size, MPEG2_ALLOC_YUV);
+ (uint8_t *) mpeg2_malloc(uv_size, MPEG2_ALLOC_YUV);
mpeg2dec->yuv_buf[0][2] =
- (uint8_t *) mpeg2_malloc (uv_size, MPEG2_ALLOC_YUV);
+ (uint8_t *) mpeg2_malloc(uv_size, MPEG2_ALLOC_YUV);
+
mpeg2dec->yuv_buf[1][0] =
- (uint8_t *) mpeg2_malloc (y_size, MPEG2_ALLOC_YUV);
+ (uint8_t *) mpeg2_malloc(y_size, MPEG2_ALLOC_YUV);
mpeg2dec->yuv_buf[1][1] =
- (uint8_t *) mpeg2_malloc (uv_size, MPEG2_ALLOC_YUV);
+ (uint8_t *) mpeg2_malloc(uv_size, MPEG2_ALLOC_YUV);
mpeg2dec->yuv_buf[1][2] =
- (uint8_t *) mpeg2_malloc (uv_size, MPEG2_ALLOC_YUV);
+ (uint8_t *) mpeg2_malloc(uv_size, MPEG2_ALLOC_YUV);
+
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);
+ (uint8_t *) mpeg2_malloc(y_size, MPEG2_ALLOC_YUV);
mpeg2dec->yuv_buf[2][1] =
- (uint8_t *) mpeg2_malloc (uv_size, MPEG2_ALLOC_YUV);
+ (uint8_t *) mpeg2_malloc(uv_size, MPEG2_ALLOC_YUV);
mpeg2dec->yuv_buf[2][2] =
- (uint8_t *) mpeg2_malloc (uv_size, MPEG2_ALLOC_YUV);
+ (uint8_t *) mpeg2_malloc(uv_size, MPEG2_ALLOC_YUV);
}
- if (!mpeg2dec->custom_fbuf) {
- while (mpeg2dec->alloc_index < 3) {
+
+ if (!mpeg2dec->custom_fbuf)
+ {
+ while (mpeg2dec->alloc_index < 3)
+ {
mpeg2_fbuf_t * fbuf;
fbuf = &mpeg2dec->fbuf_alloc[mpeg2dec->alloc_index++].fbuf;
fbuf->id = NULL;
+
fbuf->buf[0] =
(uint8_t *) mpeg2_malloc (convert_init.buf_size[0],
MPEG2_ALLOC_CONVERTED);
@@ -710,15 +902,21 @@ void mpeg2_header_picture_finalize (mpeg2dec_t * mpeg2dec)
}
mpeg2_set_fbuf (mpeg2dec, (decoder->coding_type == B_TYPE));
}
- } else if (!mpeg2dec->custom_fbuf) {
- while (mpeg2dec->alloc_index < 3) {
+ }
+ else if (!mpeg2dec->custom_fbuf)
+ {
+ while (mpeg2dec->alloc_index < 3)
+ {
mpeg2_fbuf_t * fbuf;
int y_size, uv_size;
- fbuf = &(mpeg2dec->fbuf_alloc[mpeg2dec->alloc_index++].fbuf);
+ 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);
+
fbuf->buf[0] = (uint8_t *) mpeg2_malloc (y_size,
MPEG2_ALLOC_YUV);
fbuf->buf[1] = (uint8_t *) mpeg2_malloc (uv_size,
@@ -726,13 +924,19 @@ void mpeg2_header_picture_finalize (mpeg2dec_t * mpeg2dec)
fbuf->buf[2] = (uint8_t *) mpeg2_malloc (uv_size,
MPEG2_ALLOC_YUV);
}
+
mpeg2_set_fbuf (mpeg2dec, (decoder->coding_type == B_TYPE));
}
- } else {
+ }
+ else
+ {
decoder->second_field = 1;
mpeg2dec->picture++; /* second field picture */
+
*(mpeg2dec->picture) = mpeg2dec->new_picture;
+
mpeg2dec->info.current_picture_2nd = mpeg2dec->picture;
+
if (low_delay || decoder->coding_type == B_TYPE)
mpeg2dec->info.display_picture_2nd = mpeg2dec->picture;
}
@@ -752,23 +956,38 @@ static int quant_matrix_ext (mpeg2dec_t * mpeg2dec)
int i, j;
for (i = 0; i < 4; i++)
- if (buffer[0] & (8 >> i)) {
+ {
+ if (buffer[0] & (8 >> i))
+ {
for (j = 0; j < 64; j++)
+ {
mpeg2dec->new_quantizer_matrix[i][mpeg2_scan_norm[j]] =
(buffer[j] << (i+5)) | (buffer[j+1] >> (3-i));
+ }
+
mpeg2dec->copy_matrix |= 1 << i;
buffer += 64;
}
+ }
return 0;
}
int mpeg2_header_extension (mpeg2dec_t * mpeg2dec)
{
- static int (* parser[]) (mpeg2dec_t *) = {
- 0, sequence_ext, sequence_display_ext, quant_matrix_ext,
- copyright_ext, 0, 0, picture_display_ext, picture_coding_ext
+ static int (* const parser[9]) (mpeg2dec_t *) =
+ {
+ NULL,
+ sequence_ext,
+ sequence_display_ext,
+ quant_matrix_ext,
+ copyright_ext,
+ NULL,
+ NULL,
+ picture_display_ext,
+ picture_coding_ext
};
+
int ext, ext_bit;
ext = mpeg2dec->chunk_start[0] >> 4;
@@ -776,7 +995,9 @@ int mpeg2_header_extension (mpeg2dec_t * mpeg2dec)
if (!(mpeg2dec->ext_state & ext_bit))
return 0; /* ignore illegal extensions */
+
mpeg2dec->ext_state &= ~ext_bit;
+
return parser[ext] (mpeg2dec);
}
@@ -784,89 +1005,119 @@ int mpeg2_header_user_data (mpeg2dec_t * mpeg2dec)
{
mpeg2dec->user_data_len += mpeg2dec->chunk_ptr - 1 - mpeg2dec->chunk_start;
mpeg2dec->chunk_start = mpeg2dec->chunk_ptr - 1;
-
+
return 0;
}
static void prescale (mpeg2dec_t * mpeg2dec, int index)
{
- static int non_linear_scale [] = {
+ static const int non_linear_scale[32] =
+ {
0, 1, 2, 3, 4, 5, 6, 7,
8, 10, 12, 14, 16, 18, 20, 22,
24, 28, 32, 36, 40, 44, 48, 52,
56, 64, 72, 80, 88, 96, 104, 112
};
+
int i, j, k;
- mpeg2_decoder_t * decoder = &(mpeg2dec->decoder);
+ mpeg2_decoder_t * decoder = &mpeg2dec->decoder;
- if (mpeg2dec->scaled[index] != mpeg2dec->q_scale_type) {
+ if (mpeg2dec->scaled[index] != mpeg2dec->q_scale_type)
+ {
mpeg2dec->scaled[index] = mpeg2dec->q_scale_type;
- for (i = 0; i < 32; i++) {
+
+ for (i = 0; i < 32; i++)
+ {
k = mpeg2dec->q_scale_type ? non_linear_scale[i] : (i << 1);
+
for (j = 0; j < 64; j++)
+ {
decoder->quantizer_prescale[index][i][j] =
k * mpeg2dec->quantizer_matrix[index][j];
+ }
}
}
}
mpeg2_state_t mpeg2_header_slice_start (mpeg2dec_t * mpeg2dec)
{
- mpeg2_decoder_t * decoder = &(mpeg2dec->decoder);
+ mpeg2_decoder_t * decoder = &mpeg2dec->decoder;
- mpeg2dec->info.user_data = NULL; mpeg2dec->info.user_data_len = 0;
- mpeg2dec->state = ((mpeg2dec->picture->nb_fields > 1 ||
- mpeg2dec->state == STATE_PICTURE_2ND) ?
- STATE_SLICE : STATE_SLICE_1ST);
+ mpeg2dec->info.user_data = NULL;
+ mpeg2dec->info.user_data_len = 0;
+ mpeg2dec->state = (mpeg2dec->picture->nb_fields > 1 ||
+ mpeg2dec->state == STATE_PICTURE_2ND) ?
+ STATE_SLICE : STATE_SLICE_1ST;
- if (mpeg2dec->decoder.coding_type != D_TYPE) {
+ if (mpeg2dec->decoder.coding_type != D_TYPE)
+ {
prescale (mpeg2dec, 0);
+
if (decoder->chroma_quantizer[0] == decoder->quantizer_prescale[2])
prescale (mpeg2dec, 2);
- if (mpeg2dec->decoder.coding_type != I_TYPE) {
+
+ if (mpeg2dec->decoder.coding_type != I_TYPE)
+ {
prescale (mpeg2dec, 1);
+
if (decoder->chroma_quantizer[1] == decoder->quantizer_prescale[3])
prescale (mpeg2dec, 3);
}
}
if (!(mpeg2dec->nb_decode_slices))
+ {
mpeg2dec->picture->flags |= PIC_FLAG_SKIP;
- else if (mpeg2dec->convert_start) {
+ }
+ else if (mpeg2dec->convert_start)
+ {
mpeg2dec->convert_start (decoder->convert_id, mpeg2dec->fbuf[0],
mpeg2dec->picture, mpeg2dec->info.gop);
if (mpeg2dec->decoder.coding_type == B_TYPE)
- mpeg2_init_fbuf (&(mpeg2dec->decoder), mpeg2dec->yuv_buf[2],
+ {
+ mpeg2_init_fbuf (&mpeg2dec->decoder, mpeg2dec->yuv_buf[2],
mpeg2dec->yuv_buf[mpeg2dec->yuv_index ^ 1],
mpeg2dec->yuv_buf[mpeg2dec->yuv_index]);
- else {
- mpeg2_init_fbuf (&(mpeg2dec->decoder),
+ }
+ else
+ {
+ mpeg2_init_fbuf (&mpeg2dec->decoder,
mpeg2dec->yuv_buf[mpeg2dec->yuv_index ^ 1],
mpeg2dec->yuv_buf[mpeg2dec->yuv_index],
mpeg2dec->yuv_buf[mpeg2dec->yuv_index]);
+
if (mpeg2dec->state == STATE_SLICE)
mpeg2dec->yuv_index ^= 1;
}
- } else {
+ }
+ else
+ {
int b_type;
b_type = (mpeg2dec->decoder.coding_type == B_TYPE);
- mpeg2_init_fbuf (&(mpeg2dec->decoder), mpeg2dec->fbuf[0]->buf,
+
+ mpeg2_init_fbuf (&mpeg2dec->decoder, mpeg2dec->fbuf[0]->buf,
mpeg2dec->fbuf[b_type + 1]->buf,
mpeg2dec->fbuf[b_type]->buf);
}
+
mpeg2dec->action = NULL;
+
return (mpeg2_state_t)-1;
}
static mpeg2_state_t seek_sequence (mpeg2dec_t * mpeg2dec)
{
- mpeg2_reset_info (&(mpeg2dec->info));
+ mpeg2_reset_info (&mpeg2dec->info);
+
mpeg2dec->info.sequence = NULL;
mpeg2dec->info.gop = NULL;
+
mpeg2_header_state_init (mpeg2dec);
+
mpeg2dec->action = mpeg2_seek_header;
+
return mpeg2_seek_header (mpeg2dec);
}
@@ -877,19 +1128,30 @@ mpeg2_state_t mpeg2_header_end (mpeg2dec_t * mpeg2dec)
b_type = (mpeg2dec->decoder.coding_type == B_TYPE);
picture = mpeg2dec->pictures;
+
if ((mpeg2dec->picture >= picture + 2) ^ b_type)
picture = mpeg2dec->pictures + 2;
- mpeg2_reset_info (&(mpeg2dec->info));
- if (!(mpeg2dec->sequence.flags & SEQ_FLAG_LOW_DELAY)) {
+ mpeg2_reset_info (&mpeg2dec->info);
+
+ if (!(mpeg2dec->sequence.flags & SEQ_FLAG_LOW_DELAY))
+ {
mpeg2dec->info.display_picture = picture;
+
if (picture->nb_fields == 1)
mpeg2dec->info.display_picture_2nd = picture + 1;
+
mpeg2dec->info.display_fbuf = mpeg2dec->fbuf[b_type];
+
if (!mpeg2dec->convert)
mpeg2dec->info.discard_fbuf = mpeg2dec->fbuf[b_type + 1];
- } else if (!mpeg2dec->convert)
+ }
+ else if (!mpeg2dec->convert)
+ {
mpeg2dec->info.discard_fbuf = mpeg2dec->fbuf[b_type];
+ }
+
mpeg2dec->action = seek_sequence;
+
return STATE_END;
}
diff --git a/apps/plugins/mpegplayer/idct.c b/apps/plugins/mpegplayer/idct.c
index 1cd1d91..f9e3b7d 100644
--- a/apps/plugins/mpegplayer/idct.c
+++ b/apps/plugins/mpegplayer/idct.c
@@ -29,26 +29,11 @@
#include "attributes.h"
#include "mpeg2_internal.h"
-/* idct main entry point */
-void (* mpeg2_idct_copy) (int16_t * block, uint8_t * dest, int stride);
-void (* mpeg2_idct_add) (int last, int16_t * block,
- uint8_t * dest, int stride);
-
-#ifdef CPU_COLDFIRE
-/* 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 */
+#if defined(CPU_COLDFIRE) || defined (CPU_ARM)
+#define IDCT_ASM
+#endif
+
+#ifndef IDCT_ASM
#define W1 2841 /* 2048 * sqrt (2) * cos (1 * 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
* column inputs are 16-bit values.
*/
-uint8_t mpeg2_clip[3840 * 2 + 256] IBSS_ATTR;
-#define CLIP(i) ((mpeg2_clip + 3840)[i])
+#define CLIP(i) \
+ ({ typeof (i) _i = (i); \
+ if ((_i & 0xff) != _i) \
+ _i = ~(_i >> (8*sizeof(_i) - 1)); \
+ _i; })
#if 0
#define BUTTERFLY(t0,t1,W0,W1,d0,d1) \
@@ -89,7 +77,8 @@ static inline void idct_row (int16_t * const block)
/* shortcut */
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);
tmp |= tmp << 16;
((int32_t *)block)[0] = tmp;
@@ -175,16 +164,19 @@ static inline void idct_col (int16_t * const block)
block[8*7] = (a0 - b0) >> 17;
}
-static void mpeg2_idct_copy_c (int16_t * block, uint8_t * dest,
- const int stride)
+void mpeg2_idct_copy (int16_t * block, uint8_t * dest,
+ const int stride)
{
int i;
for (i = 0; i < 8; i++)
idct_row (block + 8 * i);
+
for (i = 0; i < 8; i++)
idct_col (block + i);
- do {
+
+ do
+ {
dest[0] = CLIP (block[0]);
dest[1] = CLIP (block[1]);
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[7] = CLIP (block[7]);
- ((int32_t *)block)[0] = 0; ((int32_t *)block)[1] = 0;
- ((int32_t *)block)[2] = 0; ((int32_t *)block)[3] = 0;
+ ((int32_t *)block)[0] = 0;
+ ((int32_t *)block)[1] = 0;
+ ((int32_t *)block)[2] = 0;
+ ((int32_t *)block)[3] = 0;
dest += stride;
block += 8;
- } while (--i);
+ }
+ while (--i);
}
-static void mpeg2_idct_add_c (const int last, 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)
{
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++)
idct_row (block + 8 * i);
+
for (i = 0; i < 8; i++)
idct_col (block + i);
- do {
+
+ do
+ {
dest[0] = CLIP (block[0] + dest[0]);
dest[1] = CLIP (block[1] + dest[1]);
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[7] = CLIP (block[7] + dest[7]);
- ((int32_t *)block)[0] = 0; ((int32_t *)block)[1] = 0;
- ((int32_t *)block)[2] = 0; ((int32_t *)block)[3] = 0;
+ ((int32_t *)block)[0] = 0;
+ ((int32_t *)block)[1] = 0;
+ ((int32_t *)block)[2] = 0;
+ ((int32_t *)block)[3] = 0;
dest += stride;
block += 8;
- } while (--i);
- } else {
- int DC;
-
- DC = (block[0] + 64) >> 7;
+ }
+ while (--i);
+ }
+ else
+ {
+ int DC = (block[0] + 64) >> 7;
block[0] = block[63] = 0;
i = 8;
- do {
+
+ do
+ {
dest[0] = CLIP (DC + dest[0]);
dest[1] = CLIP (DC + dest[1]);
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[7] = CLIP (DC + dest[7]);
dest += stride;
- } while (--i);
+ }
+ while (--i);
}
}
-#endif /* CPU selection */
+#endif /* IDCT_ASM */
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;
-#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++)
{
j = default_mpeg2_scan_norm[i];
diff --git a/apps/plugins/mpegplayer/idct_arm.S b/apps/plugins/mpegplayer/idct_arm.S
index 66a84c8..21f47bb 100644
--- a/apps/plugins/mpegplayer/idct_arm.S
+++ b/apps/plugins/mpegplayer/idct_arm.S
@@ -17,10 +17,10 @@
*
****************************************************************************/
- .global mpeg2_idct_copy_arm
- .type mpeg2_idct_copy_arm, %function
- .global mpeg2_idct_add_arm
- .type mpeg2_idct_add_arm, %function
+ .global mpeg2_idct_copy
+ .type mpeg2_idct_copy, %function
+ .global mpeg2_idct_add
+ .type mpeg2_idct_add, %function
/* Custom calling convention:
@@ -265,7 +265,7 @@
sub r0, r0, #16
bx lr
-mpeg2_idct_copy_arm:
+mpeg2_idct_copy:
stmfd sp!, { r1-r2, r4-r12, lr }
bl .idct
ldmfd sp!, { r1-r2 }
@@ -313,7 +313,7 @@ mpeg2_idct_copy_arm:
blo 1b
ldmfd sp!, { r4-r12, pc }
-mpeg2_idct_add_arm:
+mpeg2_idct_add:
cmp r0, #129
mov r0, r1
ldreqsh r1, [r0, #0]
diff --git a/apps/plugins/mpegplayer/idct_coldfire.S b/apps/plugins/mpegplayer/idct_coldfire.S
index 9459c28..aa9a75b 100644
--- a/apps/plugins/mpegplayer/idct_coldfire.S
+++ b/apps/plugins/mpegplayer/idct_coldfire.S
@@ -18,10 +18,10 @@
*
****************************************************************************/
- .global mpeg2_idct_copy_coldfire
- .type mpeg2_idct_copy_coldfire, @function
- .global mpeg2_idct_add_coldfire
- .type mpeg2_idct_add_coldfire, @function
+ .global mpeg2_idct_copy
+ .type mpeg2_idct_copy, @function
+ .global mpeg2_idct_add
+ .type mpeg2_idct_add, @function
/* The IDCT itself.
* Input: %a0: block pointer
@@ -240,7 +240,7 @@
.align 2
-mpeg2_idct_copy_coldfire:
+mpeg2_idct_copy:
lea.l (-11*4,%sp), %sp
movem.l %d2-%d7/%a2-%a6, (%sp) | save some registers
move.l (11*4+4,%sp), %a0 | %a0 - block pointer for idct
@@ -339,7 +339,7 @@ mpeg2_idct_copy_coldfire:
.align 2
-mpeg2_idct_add_coldfire:
+mpeg2_idct_add:
lea.l (-11*4,%sp), %sp
movem.l %d2-%d7/%a2-%a6, (%sp)
movem.l (11*4+4,%sp), %d0/%a0-%a2 | %d0 - last value
diff --git a/apps/plugins/mpegplayer/motion_comp.c b/apps/plugins/mpegplayer/motion_comp.c
index beb5c00..e76b65f 100644
--- a/apps/plugins/mpegplayer/motion_comp.c
+++ b/apps/plugins/mpegplayer/motion_comp.c
@@ -19,6 +19,8 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * $Id$
*/
#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_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,
diff --git a/apps/plugins/mpegplayer/mpeg2.h b/apps/plugins/mpegplayer/mpeg2.h
index 01b3de4..605a353 100644
--- a/apps/plugins/mpegplayer/mpeg2.h
+++ b/apps/plugins/mpegplayer/mpeg2.h
@@ -27,21 +27,22 @@
#define MPEG2_VERSION(a,b,c) (((a)<<16)|((b)<<8)|(c))
#define MPEG2_RELEASE MPEG2_VERSION (0, 4, 0) /* 0.4.0 */
-#define SEQ_FLAG_MPEG2 1
+#define SEQ_FLAG_MPEG2 1
#define SEQ_FLAG_CONSTRAINED_PARAMETERS 2
-#define SEQ_FLAG_PROGRESSIVE_SEQUENCE 4
-#define SEQ_FLAG_LOW_DELAY 8
-#define SEQ_FLAG_COLOUR_DESCRIPTION 16
-
-#define SEQ_MASK_VIDEO_FORMAT 0xe0
-#define SEQ_VIDEO_FORMAT_COMPONENT 0
-#define SEQ_VIDEO_FORMAT_PAL 0x20
-#define SEQ_VIDEO_FORMAT_NTSC 0x40
-#define SEQ_VIDEO_FORMAT_SECAM 0x60
-#define SEQ_VIDEO_FORMAT_MAC 0x80
+#define SEQ_FLAG_PROGRESSIVE_SEQUENCE 4
+#define SEQ_FLAG_LOW_DELAY 8
+#define SEQ_FLAG_COLOUR_DESCRIPTION 16
+
+#define SEQ_MASK_VIDEO_FORMAT 0xe0
+#define SEQ_VIDEO_FORMAT_COMPONENT 0x00
+#define SEQ_VIDEO_FORMAT_PAL 0x20
+#define SEQ_VIDEO_FORMAT_NTSC 0x40
+#define SEQ_VIDEO_FORMAT_SECAM 0x60
+#define SEQ_VIDEO_FORMAT_MAC 0x80
#define SEQ_VIDEO_FORMAT_UNSPECIFIED 0xa0
-typedef struct mpeg2_sequence_s {
+typedef struct mpeg2_sequence_s
+{
unsigned int width, height;
unsigned int chroma_width, chroma_height;
unsigned int byte_rate;
@@ -59,11 +60,12 @@ typedef struct mpeg2_sequence_s {
uint8_t matrix_coefficients;
} mpeg2_sequence_t;
-#define GOP_FLAG_DROP_FRAME 1
+#define GOP_FLAG_DROP_FRAME 1
#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 minutes;
uint8_t seconds;
@@ -71,35 +73,39 @@ typedef struct mpeg2_gop_s {
uint32_t flags;
} mpeg2_gop_t;
-#define PIC_MASK_CODING_TYPE 7
+#define PIC_MASK_CODING_TYPE 7
#define PIC_FLAG_CODING_TYPE_I 1
#define PIC_FLAG_CODING_TYPE_P 2
#define PIC_FLAG_CODING_TYPE_B 3
#define PIC_FLAG_CODING_TYPE_D 4
-#define PIC_FLAG_TOP_FIELD_FIRST 8
+#define PIC_FLAG_TOP_FIELD_FIRST 8
#define PIC_FLAG_PROGRESSIVE_FRAME 16
#define PIC_FLAG_COMPOSITE_DISPLAY 32
-#define PIC_FLAG_SKIP 64
-#define PIC_FLAG_TAGS 128
+#define PIC_FLAG_SKIP 64
+#define PIC_FLAG_TAGS 128
#define PIC_MASK_COMPOSITE_DISPLAY 0xfffff000
-typedef struct mpeg2_picture_s {
+typedef struct mpeg2_picture_s
+{
unsigned int temporal_reference;
unsigned int nb_fields;
uint32_t tag, tag2;
uint32_t flags;
- struct {
- int x, y;
+ struct
+ {
+ int x, y;
} display_offset[3];
} mpeg2_picture_t;
-typedef struct mpeg2_fbuf_s {
+typedef struct mpeg2_fbuf_s
+{
uint8_t * buf[3];
void * id;
} mpeg2_fbuf_t;
-typedef struct mpeg2_info_s {
+typedef struct mpeg2_info_s
+{
const mpeg2_sequence_t * sequence;
const mpeg2_gop_t * gop;
const mpeg2_picture_t * current_picture;
@@ -116,32 +122,37 @@ typedef struct mpeg2_info_s {
typedef struct mpeg2dec_s mpeg2dec_t;
typedef struct mpeg2_decoder_s mpeg2_decoder_t;
-typedef enum {
- STATE_BUFFER = 0,
- STATE_SEQUENCE = 1,
+typedef enum
+{
+ STATE_BUFFER = 0,
+ STATE_SEQUENCE = 1,
STATE_SEQUENCE_REPEATED = 2,
- STATE_GOP = 3,
- STATE_PICTURE = 4,
- STATE_SLICE_1ST = 5,
- STATE_PICTURE_2ND = 6,
- STATE_SLICE = 7,
- STATE_END = 8,
- STATE_INVALID = 9,
- STATE_INVALID_END = 10
+ STATE_GOP = 3,
+ STATE_PICTURE = 4,
+ STATE_SLICE_1ST = 5,
+ STATE_PICTURE_2ND = 6,
+ STATE_SLICE = 7,
+ STATE_END = 8,
+ STATE_INVALID = 9,
+ STATE_INVALID_END = 10
} mpeg2_state_t;
-typedef struct mpeg2_convert_init_s {
+typedef struct mpeg2_convert_init_s
+{
unsigned int id_size;
unsigned int buf_size[3];
- 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);
+ 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);
} mpeg2_convert_init_t;
-typedef enum {
- MPEG2_CONVERT_SET = 0,
+
+typedef enum
+{
+ MPEG2_CONVERT_SET = 0,
MPEG2_CONVERT_STRIDE = 1,
- MPEG2_CONVERT_START = 2
+ MPEG2_CONVERT_START = 2
} mpeg2_convert_stage_t;
+
typedef int mpeg2_convert_t (int stage, void * id,
const mpeg2_sequence_t * sequence, int stride,
void * arg, mpeg2_convert_init_t * result);
@@ -168,12 +179,13 @@ 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_slice (mpeg2_decoder_t * decoder, int code, const uint8_t * buffer);
-typedef enum {
- MPEG2_ALLOC_MPEG2DEC = 0,
- MPEG2_ALLOC_CHUNK = 1,
- MPEG2_ALLOC_YUV = 2,
+typedef enum
+{
+ MPEG2_ALLOC_MPEG2DEC = 0,
+ MPEG2_ALLOC_CHUNK = 1,
+ MPEG2_ALLOC_YUV = 2,
MPEG2_ALLOC_CONVERT_ID = 3,
- MPEG2_ALLOC_CONVERTED = 4
+ MPEG2_ALLOC_CONVERTED = 4
} mpeg2_alloc_t;
void * mpeg2_malloc (unsigned size, mpeg2_alloc_t reason);
diff --git a/apps/plugins/mpegplayer/mpeg2_internal.h b/apps/plugins/mpegplayer/mpeg2_internal.h
index 1ec85c6..ba46b85 100644
--- a/apps/plugins/mpegplayer/mpeg2_internal.h
+++ b/apps/plugins/mpegplayer/mpeg2_internal.h
@@ -20,26 +20,28 @@
* along with this program; if not, write to the Free Software
* 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 */
/* macroblock modes */
-#define MACROBLOCK_INTRA 1
-#define MACROBLOCK_PATTERN 2
-#define MACROBLOCK_MOTION_BACKWARD 4
-#define MACROBLOCK_MOTION_FORWARD 8
-#define MACROBLOCK_QUANT 16
-#define DCT_TYPE_INTERLACED 32
+#define MACROBLOCK_INTRA 1
+#define MACROBLOCK_PATTERN 2
+#define MACROBLOCK_MOTION_BACKWARD 4
+#define MACROBLOCK_MOTION_FORWARD 8
+#define MACROBLOCK_QUANT 16
+#define DCT_TYPE_INTERLACED 32
/* motion_type */
#define MOTION_TYPE_SHIFT 6
#define MC_FIELD 1
#define MC_FRAME 2
-#define MC_16X8 2
-#define MC_DMV 3
+#define MC_16X8 2
+#define MC_DMV 3
/* picture structure */
-#define TOP_FIELD 1
-#define BOTTOM_FIELD 2
+#define TOP_FIELD 1
+#define BOTTOM_FIELD 2
#define FRAME_PICTURE 3
/* picture coding type */
@@ -50,18 +52,20 @@
typedef void mpeg2_mc_fct (uint8_t *, const uint8_t *, int, int);
-typedef struct {
+typedef struct
+{
uint8_t * ref[2][3];
uint8_t ** ref2[2];
int pmv[2][2];
int f_code[2];
} motion_t;
-typedef void motion_parser_t (mpeg2_decoder_t * decoder,
- motion_t * motion,
- mpeg2_mc_fct * const * table);
+typedef void motion_parser_t(mpeg2_decoder_t * decoder,
+ motion_t * motion,
+ mpeg2_mc_fct * const * table);
-struct mpeg2_decoder_s {
+struct mpeg2_decoder_s
+{
/* first, state that carries information from one macroblock to the */
/* next inside a slice, and is never used outside of mpeg2_slice() */
@@ -102,7 +106,7 @@ struct mpeg2_decoder_s {
uint8_t * picture_dest[3];
void (* convert) (void * convert_id, uint8_t * const * src,
- unsigned int v_offset);
+ unsigned int v_offset);
void * convert_id;
int dmv_offset;
@@ -152,11 +156,13 @@ struct mpeg2_decoder_s {
int mpeg1;
};
-typedef struct {
+typedef struct
+{
mpeg2_fbuf_t fbuf;
} fbuf_alloc_t;
-struct mpeg2dec_s {
+struct mpeg2dec_s
+{
mpeg2_decoder_t decoder;
mpeg2_info_t info;
@@ -208,8 +214,8 @@ struct mpeg2dec_s {
unsigned int convert_id_size;
int convert_stride;
void (* convert_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);
uint8_t * buf_start;
uint8_t * buf_end;
@@ -222,19 +228,6 @@ struct mpeg2dec_s {
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 */
mpeg2_state_t mpeg2_seek_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 */
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 */
void mpeg2_mc_init (void);
-typedef struct {
+typedef struct
+{
mpeg2_mc_fct * put [8];
mpeg2_mc_fct * avg [8];
} mpeg2_mc_t;
+
+extern const mpeg2_mc_t mpeg2_mc;
+
+#endif /* MPEG2_INTERNAL_H */
+
diff --git a/apps/plugins/mpegplayer/slice.c b/apps/plugins/mpegplayer/slice.c
index 7c1c07b..a039eb8 100644
--- a/apps/plugins/mpegplayer/slice.c
+++ b/apps/plugins/mpegplayer/slice.c
@@ -30,11 +30,6 @@
#include "attributes.h"
#include "mpeg2_internal.h"
-extern mpeg2_mc_t mpeg2_mc;
-extern void (* mpeg2_idct_copy) (int16_t * block, uint8_t * dest, int stride);
-extern void (* mpeg2_idct_add) (int last, int16_t * block,
- uint8_t * dest, int stride);
-
#include "vlc.h"
static inline int get_macroblock_modes (mpeg2_decoder_t * const decoder)
@@ -42,18 +37,20 @@ static inline int get_macroblock_modes (mpeg2_decoder_t * const decoder)
#define bit_buf (decoder->bitstream_buf)
#define bits (decoder->bitstream_bits)
#define bit_ptr (decoder->bitstream_ptr)
+
int macroblock_modes;
const MBtab * tab;
- switch (decoder->coding_type) {
+ switch (decoder->coding_type)
+ {
case I_TYPE:
-
tab = MB_I + UBITS (bit_buf, 1);
DUMPBITS (bit_buf, bits, tab->len);
macroblock_modes = tab->modes;
- if ((! (decoder->frame_pred_frame_dct)) &&
- (decoder->picture_structure == FRAME_PICTURE)) {
+ if (!(decoder->frame_pred_frame_dct) &&
+ decoder->picture_structure == FRAME_PICTURE)
+ {
macroblock_modes |= UBITS (bit_buf, 1) * DCT_TYPE_INTERLACED;
DUMPBITS (bit_buf, bits, 1);
}
@@ -61,55 +58,75 @@ static inline int get_macroblock_modes (mpeg2_decoder_t * const decoder)
return macroblock_modes;
case P_TYPE:
-
tab = MB_P + UBITS (bit_buf, 5);
DUMPBITS (bit_buf, bits, tab->len);
macroblock_modes = tab->modes;
- if (decoder->picture_structure != FRAME_PICTURE) {
- if (macroblock_modes & MACROBLOCK_MOTION_FORWARD) {
+ if (decoder->picture_structure != FRAME_PICTURE)
+ {
+ if (macroblock_modes & MACROBLOCK_MOTION_FORWARD)
+ {
macroblock_modes |= UBITS (bit_buf, 2) << MOTION_TYPE_SHIFT;
DUMPBITS (bit_buf, bits, 2);
}
+
return macroblock_modes | MACROBLOCK_MOTION_FORWARD;
- } else if (decoder->frame_pred_frame_dct) {
+ }
+ else if (decoder->frame_pred_frame_dct)
+ {
if (macroblock_modes & MACROBLOCK_MOTION_FORWARD)
macroblock_modes |= MC_FRAME << MOTION_TYPE_SHIFT;
+
return macroblock_modes | MACROBLOCK_MOTION_FORWARD;
- } else {
- if (macroblock_modes & MACROBLOCK_MOTION_FORWARD) {
+ }
+ else
+ {
+ if (macroblock_modes & MACROBLOCK_MOTION_FORWARD)
+ {
macroblock_modes |= UBITS (bit_buf, 2) << MOTION_TYPE_SHIFT;
DUMPBITS (bit_buf, bits, 2);
}
- if (macroblock_modes & (MACROBLOCK_INTRA | MACROBLOCK_PATTERN)) {
+
+ if (macroblock_modes & (MACROBLOCK_INTRA | MACROBLOCK_PATTERN))
+ {
macroblock_modes |= UBITS (bit_buf, 1) * DCT_TYPE_INTERLACED;
DUMPBITS (bit_buf, bits, 1);
}
+
return macroblock_modes | MACROBLOCK_MOTION_FORWARD;
}
case B_TYPE:
-
tab = MB_B + UBITS (bit_buf, 6);
DUMPBITS (bit_buf, bits, tab->len);
macroblock_modes = tab->modes;
- if (decoder->picture_structure != FRAME_PICTURE) {
- if (! (macroblock_modes & MACROBLOCK_INTRA)) {
+ if (decoder->picture_structure != FRAME_PICTURE)
+ {
+ if (! (macroblock_modes & MACROBLOCK_INTRA))
+ {
macroblock_modes |= UBITS (bit_buf, 2) << MOTION_TYPE_SHIFT;
DUMPBITS (bit_buf, bits, 2);
}
+
return macroblock_modes;
- } else if (decoder->frame_pred_frame_dct) {
+ }
+ else if (decoder->frame_pred_frame_dct)
+ {
/* if (! (macroblock_modes & MACROBLOCK_INTRA)) */
macroblock_modes |= MC_FRAME << MOTION_TYPE_SHIFT;
return macroblock_modes;
- } else {
+ }
+ else
+ {
if (macroblock_modes & MACROBLOCK_INTRA)
goto intra;
+
macroblock_modes |= UBITS (bit_buf, 2) << MOTION_TYPE_SHIFT;
DUMPBITS (bit_buf, bits, 2);
- if (macroblock_modes & (MACROBLOCK_INTRA | MACROBLOCK_PATTERN)) {
+
+ if (macroblock_modes & (MACROBLOCK_INTRA | MACROBLOCK_PATTERN))
+ {
intra:
macroblock_modes |= UBITS (bit_buf, 1) * DCT_TYPE_INTERLACED;
DUMPBITS (bit_buf, bits, 1);
@@ -118,7 +135,6 @@ static inline int get_macroblock_modes (mpeg2_decoder_t * const decoder)
}
case D_TYPE:
-
DUMPBITS (bit_buf, bits, 1);
return MACROBLOCK_INTRA;
@@ -143,10 +159,13 @@ static inline void get_quantizer_scale (mpeg2_decoder_t * const decoder)
decoder->quantizer_matrix[0] =
decoder->quantizer_prescale[0][quantizer_scale_code];
+
decoder->quantizer_matrix[1] =
decoder->quantizer_prescale[1][quantizer_scale_code];
+
decoder->quantizer_matrix[2] =
decoder->chroma_quantizer[0][quantizer_scale_code];
+
decoder->quantizer_matrix[3] =
decoder->chroma_quantizer[1][quantizer_scale_code];
#undef bit_buf
@@ -165,11 +184,13 @@ static inline int get_motion_delta (mpeg2_decoder_t * const decoder,
int sign;
const MVtab * tab;
- if (bit_buf & 0x80000000) {
+ if (bit_buf & 0x80000000)
+ {
DUMPBITS (bit_buf, bits, 1);
return 0;
- } else if (bit_buf >= 0x0c000000) {
-
+ }
+ else if (bit_buf >= 0x0c000000)
+ {
tab = MV_4 + UBITS (bit_buf, 4);
delta = (tab->delta << f_code) + 1;
bits += tab->len + f_code + 1;
@@ -183,9 +204,9 @@ static inline int get_motion_delta (mpeg2_decoder_t * const decoder,
bit_buf <<= f_code;
return (delta ^ sign) - sign;
-
- } else {
-
+ }
+ else
+ {
tab = MV_10 + UBITS (bit_buf, 10);
delta = (tab->delta << f_code) + 1;
bits += tab->len + 1;
@@ -194,7 +215,8 @@ static inline int get_motion_delta (mpeg2_decoder_t * const decoder,
sign = SBITS (bit_buf, 1);
bit_buf <<= 1;
- if (f_code) {
+ if (f_code)
+ {
NEEDBITS (bit_buf, bits, bit_ptr);
delta += UBITS (bit_buf, f_code);
DUMPBITS (bit_buf, bits, f_code);
@@ -224,6 +246,7 @@ static inline int get_dmv (mpeg2_decoder_t * const decoder)
tab = DMV_2 + UBITS (bit_buf, 2);
DUMPBITS (bit_buf, bits, tab->len);
return tab->dmv;
+
#undef bit_buf
#undef bits
#undef bit_ptr
@@ -239,14 +262,14 @@ static inline int get_coded_block_pattern (mpeg2_decoder_t * const decoder)
NEEDBITS (bit_buf, bits, bit_ptr);
- if (bit_buf >= 0x20000000) {
-
+ if (bit_buf >= 0x20000000)
+ {
tab = CBP_7 + (UBITS (bit_buf, 7) - 16);
DUMPBITS (bit_buf, bits, tab->len);
return tab->cbp;
-
- } else {
-
+ }
+ else
+ {
tab = CBP_9 + UBITS (bit_buf, 9);
DUMPBITS (bit_buf, bits, tab->len);
return tab->cbp;
@@ -262,25 +285,33 @@ static inline int get_luma_dc_dct_diff (mpeg2_decoder_t * const decoder)
#define bit_buf (decoder->bitstream_buf)
#define bits (decoder->bitstream_bits)
#define bit_ptr (decoder->bitstream_ptr)
+
const DCtab * tab;
int size;
int dc_diff;
- if (bit_buf < 0xf8000000) {
+ if (bit_buf < 0xf8000000)
+ {
tab = DC_lum_5 + UBITS (bit_buf, 5);
size = tab->size;
- if (size) {
+
+ if (size)
+ {
bits += tab->len + size;
bit_buf <<= tab->len;
dc_diff =
UBITS (bit_buf, size) - UBITS (SBITS (~bit_buf, 1), size);
bit_buf <<= size;
return dc_diff << decoder->intra_dc_precision;
- } else {
+ }
+ else
+ {
DUMPBITS (bit_buf, bits, 3);
return 0;
}
- } else {
+ }
+ else
+ {
tab = DC_long + (UBITS (bit_buf, 9) - 0x1e0);
size = tab->size;
DUMPBITS (bit_buf, bits, tab->len);
@@ -289,6 +320,7 @@ static inline int get_luma_dc_dct_diff (mpeg2_decoder_t * const decoder)
DUMPBITS (bit_buf, bits, size);
return dc_diff << decoder->intra_dc_precision;
}
+
#undef bit_buf
#undef bits
#undef bit_ptr
@@ -299,25 +331,33 @@ static inline int get_chroma_dc_dct_diff (mpeg2_decoder_t * const decoder)
#define bit_buf (decoder->bitstream_buf)
#define bits (decoder->bitstream_bits)
#define bit_ptr (decoder->bitstream_ptr)
+
const DCtab * tab;
int size;
int dc_diff;
- if (bit_buf < 0xf8000000) {
+ if (bit_buf < 0xf8000000)
+ {
tab = DC_chrom_5 + UBITS (bit_buf, 5);
size = tab->size;
- if (size) {
+
+ if (size)
+ {
bits += tab->len + size;
bit_buf <<= tab->len;
dc_diff =
UBITS (bit_buf, size) - UBITS (SBITS (~bit_buf, 1), size);
bit_buf <<= size;
return dc_diff << decoder->intra_dc_precision;
- } else {
+ }
+ else
+ {
DUMPBITS (bit_buf, bits, 2);
return 0;
}
- } else {
+ }
+ else
+ {
tab = DC_long + (UBITS (bit_buf, 10) - 0x3e0);
size = tab->size;
DUMPBITS (bit_buf, bits, tab->len + 1);
@@ -326,17 +366,18 @@ static inline int get_chroma_dc_dct_diff (mpeg2_decoder_t * const decoder)
DUMPBITS (bit_buf, bits, size);
return dc_diff << decoder->intra_dc_precision;
}
+
#undef bit_buf
#undef bits
#undef bit_ptr
}
-#define SATURATE(val) \
-do { \
- val <<= 4; \
- if (unlikely (val != (int16_t) val)) \
- val = (SBITS (val, 1) ^ 2047) << 4; \
-} while (0)
+#define SATURATE(val) \
+ do { \
+ val <<= 4; \
+ if (unlikely (val != (int16_t) val)) \
+ val = (SBITS (val, 1) ^ 2047) << 4; \
+ } while (0)
static void get_intra_block_B14 (mpeg2_decoder_t * const decoder,
const uint16_t * const quant_matrix)
@@ -361,9 +402,10 @@ static void get_intra_block_B14 (mpeg2_decoder_t * const decoder,
NEEDBITS (bit_buf, bits, bit_ptr);
- while (1) {
- if (bit_buf >= 0x28000000) {
-
+ while (1)
+ {
+ if (bit_buf >= 0x28000000)
+ {
tab = DCT_B14AC_5 + (UBITS (bit_buf, 5) - 5);
i += tab->run;
@@ -387,9 +429,9 @@ static void get_intra_block_B14 (mpeg2_decoder_t * const decoder,
NEEDBITS (bit_buf, bits, bit_ptr);
continue;
-
- } else if (bit_buf >= 0x04000000) {
-
+ }
+ else if (bit_buf >= 0x04000000)
+ {
tab = DCT_B14_8 + (UBITS (bit_buf, 8) - 4);
i += tab->run;
@@ -416,23 +458,30 @@ static void get_intra_block_B14 (mpeg2_decoder_t * const decoder,
NEEDBITS (bit_buf, bits, bit_ptr);
continue;
-
- } else if (bit_buf >= 0x02000000) {
+ }
+ else if (bit_buf >= 0x02000000)
+ {
tab = DCT_B14_10 + (UBITS (bit_buf, 10) - 8);
i += tab->run;
if (i < 64)
goto normal_code;
- } else if (bit_buf >= 0x00800000) {
+ }
+ else if (bit_buf >= 0x00800000)
+ {
tab = DCT_13 + (UBITS (bit_buf, 13) - 16);
i += tab->run;
if (i < 64)
goto normal_code;
- } else if (bit_buf >= 0x00200000) {
+ }
+ else if (bit_buf >= 0x00200000)
+ {
tab = DCT_15 + (UBITS (bit_buf, 15) - 16);
i += tab->run;
if (i < 64)
goto normal_code;
- } else {
+ }
+ else
+ {
tab = DCT_16 + UBITS (bit_buf, 16);
bit_buf <<= 16;
GETWORD (bit_buf, bits + 16, bit_ptr);
@@ -442,6 +491,7 @@ static void get_intra_block_B14 (mpeg2_decoder_t * const decoder,
}
break; /* illegal, check needed to avoid buffer overflow */
}
+
dest[63] ^= mismatch & 16;
DUMPBITS (bit_buf, bits, 2); /* dump end of block code */
decoder->bitstream_buf = bit_buf;
@@ -472,14 +522,16 @@ static void get_intra_block_B15 (mpeg2_decoder_t * const decoder,
NEEDBITS (bit_buf, bits, bit_ptr);
- while (1) {
- if (bit_buf >= 0x04000000) {
-
+ while (1)
+ {
+ if (bit_buf >= 0x04000000)
+ {
tab = DCT_B15_8 + (UBITS (bit_buf, 8) - 4);
i += tab->run;
- if (i < 64) {
+ if (i < 64)
+ {
normal_code:
j = scan[i];
bit_buf <<= tab->len;
@@ -497,9 +549,9 @@ static void get_intra_block_B15 (mpeg2_decoder_t * const decoder,
NEEDBITS (bit_buf, bits, bit_ptr);
continue;
-
- } else {
-
+ }
+ else
+ {
/* end of block. I commented out this code because if we */
/* dont exit here we will still exit at the later test :) */
@@ -525,24 +577,31 @@ static void get_intra_block_B15 (mpeg2_decoder_t * const decoder,
NEEDBITS (bit_buf, bits, bit_ptr);
continue;
-
}
- } else if (bit_buf >= 0x02000000) {
+ }
+ else if (bit_buf >= 0x02000000)
+ {
tab = DCT_B15_10 + (UBITS (bit_buf, 10) - 8);
i += tab->run;
if (i < 64)
goto normal_code;
- } else if (bit_buf >= 0x00800000) {
+ }
+ else if (bit_buf >= 0x00800000)
+ {
tab = DCT_13 + (UBITS (bit_buf, 13) - 16);
i += tab->run;
if (i < 64)
goto normal_code;
- } else if (bit_buf >= 0x00200000) {
+ }
+ else if (bit_buf >= 0x00200000)
+ {
tab = DCT_15 + (UBITS (bit_buf, 15) - 16);
i += tab->run;
if (i < 64)
goto normal_code;
- } else {
+ }
+ else
+ {
tab = DCT_16 + UBITS (bit_buf, 16);
bit_buf <<= 16;
GETWORD (bit_buf, bits + 16, bit_ptr);
@@ -552,6 +611,7 @@ static void get_intra_block_B15 (mpeg2_decoder_t * const decoder,
}
break; /* illegal, check needed to avoid buffer overflow */
}
+
dest[63] ^= mismatch & 16;
DUMPBITS (bit_buf, bits, 4); /* dump end of block code */
decoder->bitstream_buf = bit_buf;
@@ -581,15 +641,21 @@ static int get_non_intra_block (mpeg2_decoder_t * const decoder,
bit_ptr = decoder->bitstream_ptr;
NEEDBITS (bit_buf, bits, bit_ptr);
- if (bit_buf >= 0x28000000) {
+
+ if (bit_buf >= 0x28000000)
+ {
tab = DCT_B14DC_5 + (UBITS (bit_buf, 5) - 5);
goto entry_1;
- } else
+ }
+ else
+ {
goto entry_2;
+ }
- while (1) {
- if (bit_buf >= 0x28000000) {
-
+ while (1)
+ {
+ if (bit_buf >= 0x28000000)
+ {
tab = DCT_B14AC_5 + (UBITS (bit_buf, 5) - 5);
entry_1:
@@ -614,12 +680,11 @@ static int get_non_intra_block (mpeg2_decoder_t * const decoder,
NEEDBITS (bit_buf, bits, bit_ptr);
continue;
-
}
entry_2:
- if (bit_buf >= 0x04000000) {
-
+ if (bit_buf >= 0x04000000)
+ {
tab = DCT_B14_8 + (UBITS (bit_buf, 8) - 4);
i += tab->run;
@@ -647,23 +712,30 @@ static int get_non_intra_block (mpeg2_decoder_t * const decoder,
NEEDBITS (bit_buf, bits, bit_ptr);
continue;
-
- } else if (bit_buf >= 0x02000000) {
+ }
+ else if (bit_buf >= 0x02000000)
+ {
tab = DCT_B14_10 + (UBITS (bit_buf, 10) - 8);
i += tab->run;
if (i < 64)
goto normal_code;
- } else if (bit_buf >= 0x00800000) {
+ }
+ else if (bit_buf >= 0x00800000)
+ {
tab = DCT_13 + (UBITS (bit_buf, 13) - 16);
i += tab->run;
if (i < 64)
goto normal_code;
- } else if (bit_buf >= 0x00200000) {
+ }
+ else if (bit_buf >= 0x00200000)
+ {
tab = DCT_15 + (UBITS (bit_buf, 15) - 16);
i += tab->run;
if (i < 64)
goto normal_code;
- } else {
+ }
+ else
+ {
tab = DCT_16 + UBITS (bit_buf, 16);
bit_buf <<= 16;
GETWORD (bit_buf, bits + 16, bit_ptr);
@@ -673,6 +745,7 @@ static int get_non_intra_block (mpeg2_decoder_t * const decoder,
}
break; /* illegal, check needed to avoid buffer overflow */
}
+
dest[63] ^= mismatch & 16;
DUMPBITS (bit_buf, bits, 2); /* dump end of block code */
decoder->bitstream_buf = bit_buf;
@@ -702,9 +775,10 @@ static void get_mpeg1_intra_block (mpeg2_decoder_t * const decoder)
NEEDBITS (bit_buf, bits, bit_ptr);
- while (1) {
- if (bit_buf >= 0x28000000) {
-
+ while (1)
+ {
+ if (bit_buf >= 0x28000000)
+ {
tab = DCT_B14AC_5 + (UBITS (bit_buf, 5) - 5);
i += tab->run;
@@ -730,9 +804,9 @@ static void get_mpeg1_intra_block (mpeg2_decoder_t * const decoder)
NEEDBITS (bit_buf, bits, bit_ptr);
continue;
-
- } else if (bit_buf >= 0x04000000) {
-
+ }
+ else if (bit_buf >= 0x04000000)
+ {
tab = DCT_B14_8 + (UBITS (bit_buf, 8) - 4);
i += tab->run;
@@ -750,10 +824,13 @@ static void get_mpeg1_intra_block (mpeg2_decoder_t * const decoder)
DUMPBITS (bit_buf, bits, 12);
NEEDBITS (bit_buf, bits, bit_ptr);
val = SBITS (bit_buf, 8);
- if (! (val & 0x7f)) {
+
+ if (! (val & 0x7f))
+ {
DUMPBITS (bit_buf, bits, 8);
val = UBITS (bit_buf, 8) + 2 * val;
}
+
val = (val * quant_matrix[j]) / 16;
/* oddification */
@@ -766,23 +843,30 @@ static void get_mpeg1_intra_block (mpeg2_decoder_t * const decoder)
NEEDBITS (bit_buf, bits, bit_ptr);
continue;
-
- } else if (bit_buf >= 0x02000000) {
+ }
+ else if (bit_buf >= 0x02000000)
+ {
tab = DCT_B14_10 + (UBITS (bit_buf, 10) - 8);
i += tab->run;
if (i < 64)
goto normal_code;
- } else if (bit_buf >= 0x00800000) {
+ }
+ else if (bit_buf >= 0x00800000)
+ {
tab = DCT_13 + (UBITS (bit_buf, 13) - 16);
i += tab->run;
if (i < 64)
goto normal_code;
- } else if (bit_buf >= 0x00200000) {
+ }
+ else if (bit_buf >= 0x00200000)
+ {
tab = DCT_15 + (UBITS (bit_buf, 15) - 16);
i += tab->run;
if (i < 64)
goto normal_code;
- } else {
+ }
+ else
+ {
tab = DCT_16 + UBITS (bit_buf, 16);
bit_buf <<= 16;
GETWORD (bit_buf, bits + 16, bit_ptr);
@@ -792,6 +876,7 @@ static void get_mpeg1_intra_block (mpeg2_decoder_t * const decoder)
}
break; /* illegal, check needed to avoid buffer overflow */
}
+
DUMPBITS (bit_buf, bits, 2); /* dump end of block code */
decoder->bitstream_buf = bit_buf;
decoder->bitstream_bits = bits;
@@ -818,15 +903,20 @@ static int get_mpeg1_non_intra_block (mpeg2_decoder_t * const decoder)
bit_ptr = decoder->bitstream_ptr;
NEEDBITS (bit_buf, bits, bit_ptr);
- if (bit_buf >= 0x28000000) {
+ if (bit_buf >= 0x28000000)
+ {
tab = DCT_B14DC_5 + (UBITS (bit_buf, 5) - 5);
goto entry_1;
- } else
+ }
+ else
+ {
goto entry_2;
+ }
- while (1) {
- if (bit_buf >= 0x28000000) {
-
+ while (1)
+ {
+ if (bit_buf >= 0x28000000)
+ {
tab = DCT_B14AC_5 + (UBITS (bit_buf, 5) - 5);
entry_1:
@@ -853,12 +943,11 @@ static int get_mpeg1_non_intra_block (mpeg2_decoder_t * const decoder)
NEEDBITS (bit_buf, bits, bit_ptr);
continue;
-
}
entry_2:
- if (bit_buf >= 0x04000000) {
-
+ if (bit_buf >= 0x04000000)
+ {
tab = DCT_B14_8 + (UBITS (bit_buf, 8) - 4);
i += tab->run;
@@ -876,10 +965,13 @@ static int get_mpeg1_non_intra_block (mpeg2_decoder_t * const decoder)
DUMPBITS (bit_buf, bits, 12);
NEEDBITS (bit_buf, bits, bit_ptr);
val = SBITS (bit_buf, 8);
- if (! (val & 0x7f)) {
+
+ if (! (val & 0x7f))
+ {
DUMPBITS (bit_buf, bits, 8);
val = UBITS (bit_buf, 8) + 2 * val;
}
+
val = 2 * (val + SBITS (val, 1)) + 1;
val = (val * quant_matrix[j]) / 32;
@@ -894,22 +986,30 @@ static int get_mpeg1_non_intra_block (mpeg2_decoder_t * const decoder)
continue;
- } else if (bit_buf >= 0x02000000) {
+ }
+ else if (bit_buf >= 0x02000000)
+ {
tab = DCT_B14_10 + (UBITS (bit_buf, 10) - 8);
i += tab->run;
if (i < 64)
goto normal_code;
- } else if (bit_buf >= 0x00800000) {
+ }
+ else if (bit_buf >= 0x00800000)
+ {
tab = DCT_13 + (UBITS (bit_buf, 13) - 16);
i += tab->run;
if (i < 64)
goto normal_code;
- } else if (bit_buf >= 0x00200000) {
+ }
+ else if (bit_buf >= 0x00200000)
+ {
tab = DCT_15 + (UBITS (bit_buf, 15) - 16);
i += tab->run;
if (i < 64)
goto normal_code;
- } else {
+ }
+ else
+ {
tab = DCT_16 + UBITS (bit_buf, 16);
bit_buf <<= 16;
GETWORD (bit_buf, bits + 16, bit_ptr);
@@ -919,6 +1019,7 @@ static int get_mpeg1_non_intra_block (mpeg2_decoder_t * const decoder)
}
break; /* illegal, check needed to avoid buffer overflow */
}
+
DUMPBITS (bit_buf, bits, 2); /* dump end of block code */
decoder->bitstream_buf = bit_buf;
decoder->bitstream_bits = bits;
@@ -933,23 +1034,37 @@ static inline void slice_intra_DCT (mpeg2_decoder_t * const decoder,
#define bit_buf (decoder->bitstream_buf)
#define bits (decoder->bitstream_bits)
#define bit_ptr (decoder->bitstream_ptr)
+
NEEDBITS (bit_buf, bits, bit_ptr);
/* Get the intra DC coefficient and inverse quantize it */
if (cc == 0)
- decoder->DCTblock[0] =
- decoder->dc_dct_pred[0] += get_luma_dc_dct_diff (decoder);
+ {
+ decoder->dc_dct_pred[0] += get_luma_dc_dct_diff (decoder);
+ decoder->DCTblock[0] = decoder->dc_dct_pred[0];
+
+ }
else
- decoder->DCTblock[0] =
- decoder->dc_dct_pred[cc] += get_chroma_dc_dct_diff (decoder);
+ {
+ decoder->dc_dct_pred[cc] += get_chroma_dc_dct_diff (decoder);
+ decoder->DCTblock[0] = decoder->dc_dct_pred[cc];
+ }
- if (decoder->mpeg1) {
+ if (decoder->mpeg1)
+ {
if (decoder->coding_type != D_TYPE)
get_mpeg1_intra_block (decoder);
- } else if (decoder->intra_vlc_format)
+ }
+ else if (decoder->intra_vlc_format)
+ {
get_intra_block_B15 (decoder, decoder->quantizer_matrix[cc ? 2 : 0]);
+ }
else
+ {
get_intra_block_B14 (decoder, decoder->quantizer_matrix[cc ? 2 : 0]);
+ }
+
mpeg2_idct_copy (decoder->DCTblock, dest, stride);
+
#undef bit_buf
#undef bits
#undef bit_ptr
@@ -962,289 +1077,366 @@ static inline void slice_non_intra_DCT (mpeg2_decoder_t * const decoder,
int last;
if (decoder->mpeg1)
+ {
last = get_mpeg1_non_intra_block (decoder);
+ }
else
+ {
last = get_non_intra_block (decoder,
decoder->quantizer_matrix[cc ? 3 : 1]);
+ }
+
mpeg2_idct_add (last, decoder->DCTblock, dest, stride);
}
-#define MOTION_420(table,ref,motion_x,motion_y,size,y) \
- pos_x = 2 * decoder->offset + motion_x; \
- pos_y = 2 * decoder->v_offset + motion_y + 2 * y; \
- if (unlikely (pos_x > decoder->limit_x)) { \
+#define MOTION_420(table, ref, motion_x, motion_y, size, y) \
+ pos_x = 2 * decoder->offset + motion_x; \
+ pos_y = 2 * decoder->v_offset + motion_y + 2 * y; \
+ \
+ if (unlikely (pos_x > decoder->limit_x)) \
+ { \
pos_x = ((int)pos_x < 0) ? 0 : decoder->limit_x; \
- motion_x = pos_x - 2 * decoder->offset; \
- } \
- if (unlikely (pos_y > decoder->limit_y_ ## size)) { \
- pos_y = ((int)pos_y < 0) ? 0 : decoder->limit_y_ ## size; \
- motion_y = pos_y - 2 * decoder->v_offset - 2 * y; \
- } \
- xy_half = ((pos_y & 1) << 1) | (pos_x & 1); \
+ motion_x = pos_x - 2 * decoder->offset; \
+ } \
+ \
+ if (unlikely (pos_y > decoder->limit_y_ ## size)) \
+ { \
+ pos_y = ((int)pos_y < 0) ? 0 : decoder->limit_y_ ## size; \
+ motion_y = pos_y - 2 * decoder->v_offset - 2 * y; \
+ } \
+ \
+ xy_half = ((pos_y & 1) << 1) | (pos_x & 1); \
table[xy_half] (decoder->dest[0] + y * decoder->stride + decoder->offset, \
ref[0] + (pos_x >> 1) + (pos_y >> 1) * decoder->stride, \
- decoder->stride, size); \
- motion_x /= 2; motion_y /= 2; \
- xy_half = ((motion_y & 1) << 1) | (motion_x & 1); \
- offset = (((decoder->offset + motion_x) >> 1) + \
- ((((decoder->v_offset + motion_y) >> 1) + y/2) * \
- decoder->uv_stride)); \
- table[4+xy_half] (decoder->dest[1] + y/2 * decoder->uv_stride + \
- (decoder->offset >> 1), ref[1] + offset, \
- decoder->uv_stride, size/2); \
- table[4+xy_half] (decoder->dest[2] + y/2 * decoder->uv_stride + \
- (decoder->offset >> 1), ref[2] + offset, \
+ decoder->stride, size); \
+ \
+ motion_x /= 2; \
+ motion_y /= 2; \
+ xy_half = ((motion_y & 1) << 1) | (motion_x & 1); \
+ offset = ((decoder->offset + motion_x) >> 1) + \
+ ((((decoder->v_offset + motion_y) >> 1) + y/2) * \
+ decoder->uv_stride); \
+ \
+ table[4+xy_half] (decoder->dest[1] + y/2 * decoder->uv_stride + \
+ (decoder->offset >> 1), ref[1] + offset, \
+ decoder->uv_stride, size/2); \
+ table[4+xy_half] (decoder->dest[2] + y/2 * decoder->uv_stride + \
+ (decoder->offset >> 1), ref[2] + offset, \
decoder->uv_stride, size/2)
-#define MOTION_FIELD_420(table,ref,motion_x,motion_y,dest_field,op,src_field) \
- pos_x = 2 * decoder->offset + motion_x; \
- pos_y = decoder->v_offset + motion_y; \
- if (unlikely (pos_x > decoder->limit_x)) { \
+#define MOTION_FIELD_420(table, ref, motion_x, motion_y, \
+ dest_field, op, src_field) \
+ pos_x = 2 * decoder->offset + motion_x; \
+ pos_y = decoder->v_offset + motion_y; \
+ \
+ if (unlikely (pos_x > decoder->limit_x)) \
+ { \
pos_x = ((int)pos_x < 0) ? 0 : decoder->limit_x; \
- motion_x = pos_x - 2 * decoder->offset; \
- } \
- if (unlikely (pos_y > decoder->limit_y)) { \
+ motion_x = pos_x - 2 * decoder->offset; \
+ } \
+ \
+ if (unlikely (pos_y > decoder->limit_y)) \
+ { \
pos_y = ((int)pos_y < 0) ? 0 : decoder->limit_y; \
- motion_y = pos_y - decoder->v_offset; \
- } \
- xy_half = ((pos_y & 1) << 1) | (pos_x & 1); \
- table[xy_half] (decoder->dest[0] + dest_field * decoder->stride + \
- decoder->offset, \
- (ref[0] + (pos_x >> 1) + \
- ((pos_y op) + src_field) * decoder->stride), \
- 2 * decoder->stride, 8); \
- motion_x /= 2; motion_y /= 2; \
- xy_half = ((motion_y & 1) << 1) | (motion_x & 1); \
- offset = (((decoder->offset + motion_x) >> 1) + \
- (((decoder->v_offset >> 1) + (motion_y op) + src_field) * \
- decoder->uv_stride)); \
+ motion_y = pos_y - decoder->v_offset; \
+ } \
+ \
+ xy_half = ((pos_y & 1) << 1) | (pos_x & 1); \
+ table[xy_half] (decoder->dest[0] + dest_field * decoder->stride + \
+ decoder->offset, \
+ (ref[0] + (pos_x >> 1) + \
+ ((pos_y op) + src_field) * decoder->stride), \
+ 2 * decoder->stride, 8); \
+ \
+ motion_x /= 2; \
+ motion_y /= 2; \
+ xy_half = ((motion_y & 1) << 1) | (motion_x & 1); \
+ offset = ((decoder->offset + motion_x) >> 1) + \
+ (((decoder->v_offset >> 1) + (motion_y op) + src_field) * \
+ decoder->uv_stride); \
+ \
table[4+xy_half] (decoder->dest[1] + dest_field * decoder->uv_stride + \
- (decoder->offset >> 1), ref[1] + offset, \
- 2 * decoder->uv_stride, 4); \
+ (decoder->offset >> 1), ref[1] + offset, \
+ 2 * decoder->uv_stride, 4); \
table[4+xy_half] (decoder->dest[2] + dest_field * decoder->uv_stride + \
- (decoder->offset >> 1), ref[2] + offset, \
+ (decoder->offset >> 1), ref[2] + offset, \
2 * decoder->uv_stride, 4)
-#define MOTION_DMV_420(table,ref,motion_x,motion_y) \
- pos_x = 2 * decoder->offset + motion_x; \
- pos_y = decoder->v_offset + motion_y; \
- if (unlikely (pos_x > decoder->limit_x)) { \
+#define MOTION_DMV_420(table, ref, motion_x, motion_y) \
+ pos_x = 2 * decoder->offset + motion_x; \
+ pos_y = decoder->v_offset + motion_y; \
+ \
+ if (unlikely (pos_x > decoder->limit_x)) \
+ { \
pos_x = ((int)pos_x < 0) ? 0 : decoder->limit_x; \
- motion_x = pos_x - 2 * decoder->offset; \
- } \
- if (unlikely (pos_y > decoder->limit_y)) { \
+ motion_x = pos_x - 2 * decoder->offset; \
+ } \
+ \
+ if (unlikely (pos_y > decoder->limit_y)) \
+ { \
pos_y = ((int)pos_y < 0) ? 0 : decoder->limit_y; \
- motion_y = pos_y - decoder->v_offset; \
- } \
- xy_half = ((pos_y & 1) << 1) | (pos_x & 1); \
- offset = (pos_x >> 1) + (pos_y & ~1) * decoder->stride; \
- table[xy_half] (decoder->dest[0] + decoder->offset, \
- ref[0] + offset, 2 * decoder->stride, 8); \
+ motion_y = pos_y - decoder->v_offset; \
+ } \
+ \
+ xy_half = ((pos_y & 1) << 1) | (pos_x & 1); \
+ offset = (pos_x >> 1) + (pos_y & ~1) * decoder->stride; \
+ table[xy_half] (decoder->dest[0] + decoder->offset, \
+ ref[0] + offset, 2 * decoder->stride, 8); \
table[xy_half] (decoder->dest[0] + decoder->stride + decoder->offset, \
- ref[0] + decoder->stride + offset, \
- 2 * decoder->stride, 8); \
- motion_x /= 2; motion_y /= 2; \
- xy_half = ((motion_y & 1) << 1) | (motion_x & 1); \
- offset = (((decoder->offset + motion_x) >> 1) + \
- (((decoder->v_offset >> 1) + (motion_y & ~1)) * \
- decoder->uv_stride)); \
+ ref[0] + decoder->stride + offset, \
+ 2 * decoder->stride, 8); \
+ \
+ motion_x /= 2; \
+ motion_y /= 2; \
+ xy_half = ((motion_y & 1) << 1) | (motion_x & 1); \
+ offset = ((decoder->offset + motion_x) >> 1) + \
+ (((decoder->v_offset >> 1) + (motion_y & ~1)) * \
+ decoder->uv_stride); \
+ \
table[4+xy_half] (decoder->dest[1] + (decoder->offset >> 1), \
- ref[1] + offset, 2 * decoder->uv_stride, 4); \
- table[4+xy_half] (decoder->dest[1] + decoder->uv_stride + \
- (decoder->offset >> 1), \
- ref[1] + decoder->uv_stride + offset, \
- 2 * decoder->uv_stride, 4); \
+ ref[1] + offset, 2 * decoder->uv_stride, 4); \
+ table[4+xy_half] (decoder->dest[1] + decoder->uv_stride + \
+ (decoder->offset >> 1), \
+ ref[1] + decoder->uv_stride + offset, \
+ 2 * decoder->uv_stride, 4); \
table[4+xy_half] (decoder->dest[2] + (decoder->offset >> 1), \
- ref[2] + offset, 2 * decoder->uv_stride, 4); \
- table[4+xy_half] (decoder->dest[2] + decoder->uv_stride + \
- (decoder->offset >> 1), \
- ref[2] + decoder->uv_stride + offset, \
+ ref[2] + offset, 2 * decoder->uv_stride, 4); \
+ table[4+xy_half] (decoder->dest[2] + decoder->uv_stride + \
+ (decoder->offset >> 1), \
+ ref[2] + decoder->uv_stride + offset, \
2 * decoder->uv_stride, 4)
-#define MOTION_ZERO_420(table,ref) \
- table[0] (decoder->dest[0] + decoder->offset, \
- (ref[0] + decoder->offset + \
+#define MOTION_ZERO_420(table, ref) \
+ table[0] (decoder->dest[0] + decoder->offset, \
+ (ref[0] + decoder->offset + \
decoder->v_offset * decoder->stride), decoder->stride, 16); \
- offset = ((decoder->offset >> 1) + \
- (decoder->v_offset >> 1) * decoder->uv_stride); \
+ \
+ offset = ((decoder->offset >> 1) + \
+ (decoder->v_offset >> 1) * decoder->uv_stride); \
+ \
table[4] (decoder->dest[1] + (decoder->offset >> 1), \
- ref[1] + offset, decoder->uv_stride, 8); \
+ ref[1] + offset, decoder->uv_stride, 8); \
table[4] (decoder->dest[2] + (decoder->offset >> 1), \
ref[2] + offset, decoder->uv_stride, 8)
-#define MOTION_422(table,ref,motion_x,motion_y,size,y) \
- pos_x = 2 * decoder->offset + motion_x; \
- pos_y = 2 * decoder->v_offset + motion_y + 2 * y; \
- if (unlikely (pos_x > decoder->limit_x)) { \
+#define MOTION_422(table, ref, motion_x, motion_y, size, y) \
+ pos_x = 2 * decoder->offset + motion_x; \
+ pos_y = 2 * decoder->v_offset + motion_y + 2 * y; \
+ \
+ if (unlikely (pos_x > decoder->limit_x)) \
+ { \
pos_x = ((int)pos_x < 0) ? 0 : decoder->limit_x; \
- motion_x = pos_x - 2 * decoder->offset; \
- } \
- if (unlikely (pos_y > decoder->limit_y_ ## size)) { \
- pos_y = ((int)pos_y < 0) ? 0 : decoder->limit_y_ ## size; \
- motion_y = pos_y - 2 * decoder->v_offset - 2 * y; \
- } \
- xy_half = ((pos_y & 1) << 1) | (pos_x & 1); \
- offset = (pos_x >> 1) + (pos_y >> 1) * decoder->stride; \
+ motion_x = pos_x - 2 * decoder->offset; \
+ } \
+ \
+ if (unlikely (pos_y > decoder->limit_y_ ## size)) \
+ { \
+ pos_y = ((int)pos_y < 0) ? 0 : decoder->limit_y_ ## size; \
+ motion_y = pos_y - 2 * decoder->v_offset - 2 * y; \
+ } \
+ \
+ xy_half = ((pos_y & 1) << 1) | (pos_x & 1); \
+ offset = (pos_x >> 1) + (pos_y >> 1) * decoder->stride; \
+ \
table[xy_half] (decoder->dest[0] + y * decoder->stride + decoder->offset, \
- ref[0] + offset, decoder->stride, size); \
- offset = (offset + (motion_x & (motion_x < 0))) >> 1; \
- motion_x /= 2; \
- xy_half = ((pos_y & 1) << 1) | (motion_x & 1); \
- table[4+xy_half] (decoder->dest[1] + y * decoder->uv_stride + \
- (decoder->offset >> 1), ref[1] + offset, \
+ ref[0] + offset, decoder->stride, size); \
+ \
+ offset = (offset + (motion_x & (motion_x < 0))) >> 1; \
+ motion_x /= 2; \
+ xy_half = ((pos_y & 1) << 1) | (motion_x & 1); \
+ \
+ table[4+xy_half] (decoder->dest[1] + y * decoder->uv_stride + \
+ (decoder->offset >> 1), ref[1] + offset, \
decoder->uv_stride, size); \
- table[4+xy_half] (decoder->dest[2] + y * decoder->uv_stride + \
- (decoder->offset >> 1), ref[2] + offset, \
+ table[4+xy_half] (decoder->dest[2] + y * decoder->uv_stride + \
+ (decoder->offset >> 1), ref[2] + offset, \
decoder->uv_stride, size)
-#define MOTION_FIELD_422(table,ref,motion_x,motion_y,dest_field,op,src_field) \
- pos_x = 2 * decoder->offset + motion_x; \
- pos_y = decoder->v_offset + motion_y; \
- if (unlikely (pos_x > decoder->limit_x)) { \
+#define MOTION_FIELD_422(table, ref, motion_x, motion_y, \
+ dest_field, op, src_field) \
+ pos_x = 2 * decoder->offset + motion_x; \
+ pos_y = decoder->v_offset + motion_y; \
+ \
+ if (unlikely (pos_x > decoder->limit_x)) \
+ { \
pos_x = ((int)pos_x < 0) ? 0 : decoder->limit_x; \
- motion_x = pos_x - 2 * decoder->offset; \
- } \
- if (unlikely (pos_y > decoder->limit_y)) { \
+ motion_x = pos_x - 2 * decoder->offset; \
+ } \
+ \
+ if (unlikely (pos_y > decoder->limit_y)) \
+ { \
pos_y = ((int)pos_y < 0) ? 0 : decoder->limit_y; \
- motion_y = pos_y - decoder->v_offset; \
- } \
- xy_half = ((pos_y & 1) << 1) | (pos_x & 1); \
- offset = (pos_x >> 1) + ((pos_y op) + src_field) * decoder->stride; \
- table[xy_half] (decoder->dest[0] + dest_field * decoder->stride + \
- decoder->offset, ref[0] + offset, \
- 2 * decoder->stride, 8); \
- offset = (offset + (motion_x & (motion_x < 0))) >> 1; \
- motion_x /= 2; \
- xy_half = ((pos_y & 1) << 1) | (motion_x & 1); \
+ motion_y = pos_y - decoder->v_offset; \
+ } \
+ \
+ xy_half = ((pos_y & 1) << 1) | (pos_x & 1); \
+ offset = (pos_x >> 1) + ((pos_y op) + src_field) * decoder->stride; \
+ \
+ table[xy_half] (decoder->dest[0] + dest_field * decoder->stride + \
+ decoder->offset, ref[0] + offset, \
+ 2 * decoder->stride, 8); \
+ \
+ offset = (offset + (motion_x & (motion_x < 0))) >> 1; \
+ motion_x /= 2; \
+ xy_half = ((pos_y & 1) << 1) | (motion_x & 1); \
+ \
table[4+xy_half] (decoder->dest[1] + dest_field * decoder->uv_stride + \
- (decoder->offset >> 1), ref[1] + offset, \
- 2 * decoder->uv_stride, 8); \
+ (decoder->offset >> 1), ref[1] + offset, \
+ 2 * decoder->uv_stride, 8); \
table[4+xy_half] (decoder->dest[2] + dest_field * decoder->uv_stride + \
- (decoder->offset >> 1), ref[2] + offset, \
+ (decoder->offset >> 1), ref[2] + offset, \
2 * decoder->uv_stride, 8)
-#define MOTION_DMV_422(table,ref,motion_x,motion_y) \
- pos_x = 2 * decoder->offset + motion_x; \
- pos_y = decoder->v_offset + motion_y; \
- if (unlikely (pos_x > decoder->limit_x)) { \
+#define MOTION_DMV_422(table, ref, motion_x, motion_y) \
+ pos_x = 2 * decoder->offset + motion_x; \
+ pos_y = decoder->v_offset + motion_y; \
+ \
+ if (unlikely (pos_x > decoder->limit_x)) \
+ { \
pos_x = ((int)pos_x < 0) ? 0 : decoder->limit_x; \
- motion_x = pos_x - 2 * decoder->offset; \
- } \
- if (unlikely (pos_y > decoder->limit_y)) { \
+ motion_x = pos_x - 2 * decoder->offset; \
+ } \
+ \
+ if (unlikely (pos_y > decoder->limit_y)) \
+ { \
pos_y = ((int)pos_y < 0) ? 0 : decoder->limit_y; \
- motion_y = pos_y - decoder->v_offset; \
- } \
- xy_half = ((pos_y & 1) << 1) | (pos_x & 1); \
- offset = (pos_x >> 1) + (pos_y & ~1) * decoder->stride; \
- table[xy_half] (decoder->dest[0] + decoder->offset, \
- ref[0] + offset, 2 * decoder->stride, 8); \
+ motion_y = pos_y - decoder->v_offset; \
+ } \
+ \
+ xy_half = ((pos_y & 1) << 1) | (pos_x & 1); \
+ offset = (pos_x >> 1) + (pos_y & ~1) * decoder->stride; \
+ \
+ table[xy_half] (decoder->dest[0] + decoder->offset, \
+ ref[0] + offset, 2 * decoder->stride, 8); \
table[xy_half] (decoder->dest[0] + decoder->stride + decoder->offset, \
- ref[0] + decoder->stride + offset, \
- 2 * decoder->stride, 8); \
- offset = (offset + (motion_x & (motion_x < 0))) >> 1; \
- motion_x /= 2; \
- xy_half = ((pos_y & 1) << 1) | (motion_x & 1); \
+ ref[0] + decoder->stride + offset, \
+ 2 * decoder->stride, 8); \
+ \
+ offset = (offset + (motion_x & (motion_x < 0))) >> 1; \
+ motion_x /= 2; \
+ xy_half = ((pos_y & 1) << 1) | (motion_x & 1); \
+ \
table[4+xy_half] (decoder->dest[1] + (decoder->offset >> 1), \
- ref[1] + offset, 2 * decoder->uv_stride, 8); \
- table[4+xy_half] (decoder->dest[1] + decoder->uv_stride + \
- (decoder->offset >> 1), \
- ref[1] + decoder->uv_stride + offset, \
- 2 * decoder->uv_stride, 8); \
+ ref[1] + offset, 2 * decoder->uv_stride, 8); \
+ table[4+xy_half] (decoder->dest[1] + decoder->uv_stride + \
+ (decoder->offset >> 1), \
+ ref[1] + decoder->uv_stride + offset, \
+ 2 * decoder->uv_stride, 8); \
table[4+xy_half] (decoder->dest[2] + (decoder->offset >> 1), \
- ref[2] + offset, 2 * decoder->uv_stride, 8); \
- table[4+xy_half] (decoder->dest[2] + decoder->uv_stride + \
- (decoder->offset >> 1), \
- ref[2] + decoder->uv_stride + offset, \
+ ref[2] + offset, 2 * decoder->uv_stride, 8); \
+ table[4+xy_half] (decoder->dest[2] + decoder->uv_stride + \
+ (decoder->offset >> 1), \
+ ref[2] + decoder->uv_stride + offset, \
2 * decoder->uv_stride, 8)
-#define MOTION_ZERO_422(table,ref) \
- offset = decoder->offset + decoder->v_offset * decoder->stride; \
- table[0] (decoder->dest[0] + decoder->offset, \
- ref[0] + offset, decoder->stride, 16); \
- offset >>= 1; \
+#define MOTION_ZERO_422(table, ref) \
+ offset = decoder->offset + decoder->v_offset * decoder->stride; \
+ table[0] (decoder->dest[0] + decoder->offset, \
+ ref[0] + offset, decoder->stride, 16); \
+ offset >>= 1; \
table[4] (decoder->dest[1] + (decoder->offset >> 1), \
- ref[1] + offset, decoder->uv_stride, 16); \
+ ref[1] + offset, decoder->uv_stride, 16); \
table[4] (decoder->dest[2] + (decoder->offset >> 1), \
ref[2] + offset, decoder->uv_stride, 16)
-#define MOTION_444(table,ref,motion_x,motion_y,size,y) \
- pos_x = 2 * decoder->offset + motion_x; \
- pos_y = 2 * decoder->v_offset + motion_y + 2 * y; \
- if (unlikely (pos_x > decoder->limit_x)) { \
+#define MOTION_444(table, ref, motion_x, motion_y, size, y) \
+ pos_x = 2 * decoder->offset + motion_x; \
+ pos_y = 2 * decoder->v_offset + motion_y + 2 * y; \
+ \
+ if (unlikely (pos_x > decoder->limit_x)) \
+ { \
pos_x = ((int)pos_x < 0) ? 0 : decoder->limit_x; \
- motion_x = pos_x - 2 * decoder->offset; \
- } \
- if (unlikely (pos_y > decoder->limit_y_ ## size)) { \
- pos_y = ((int)pos_y < 0) ? 0 : decoder->limit_y_ ## size; \
- motion_y = pos_y - 2 * decoder->v_offset - 2 * y; \
- } \
- xy_half = ((pos_y & 1) << 1) | (pos_x & 1); \
- offset = (pos_x >> 1) + (pos_y >> 1) * decoder->stride; \
+ motion_x = pos_x - 2 * decoder->offset; \
+ } \
+ \
+ if (unlikely (pos_y > decoder->limit_y_ ## size)) \
+ { \
+ pos_y = ((int)pos_y < 0) ? 0 : decoder->limit_y_ ## size; \
+ motion_y = pos_y - 2 * decoder->v_offset - 2 * y; \
+ } \
+ \
+ xy_half = ((pos_y & 1) << 1) | (pos_x & 1); \
+ offset = (pos_x >> 1) + (pos_y >> 1) * decoder->stride; \
+ \
table[xy_half] (decoder->dest[0] + y * decoder->stride + decoder->offset, \
- ref[0] + offset, decoder->stride, size); \
+ ref[0] + offset, decoder->stride, size); \
table[xy_half] (decoder->dest[1] + y * decoder->stride + decoder->offset, \
- ref[1] + offset, decoder->stride, size); \
+ ref[1] + offset, decoder->stride, size); \
table[xy_half] (decoder->dest[2] + y * decoder->stride + decoder->offset, \
ref[2] + offset, decoder->stride, size)
-#define MOTION_FIELD_444(table,ref,motion_x,motion_y,dest_field,op,src_field) \
- pos_x = 2 * decoder->offset + motion_x; \
- pos_y = decoder->v_offset + motion_y; \
- if (unlikely (pos_x > decoder->limit_x)) { \
+#define MOTION_FIELD_444(table, ref, motion_x, motion_y, \
+ dest_field, op, src_field) \
+ pos_x = 2 * decoder->offset + motion_x; \
+ pos_y = decoder->v_offset + motion_y; \
+ \
+ if (unlikely (pos_x > decoder->limit_x)) \
+ { \
pos_x = ((int)pos_x < 0) ? 0 : decoder->limit_x; \
- motion_x = pos_x - 2 * decoder->offset; \
- } \
- if (unlikely (pos_y > decoder->limit_y)) { \
+ motion_x = pos_x - 2 * decoder->offset; \
+ } \
+ \
+ if (unlikely (pos_y > decoder->limit_y)) \
+ { \
pos_y = ((int)pos_y < 0) ? 0 : decoder->limit_y; \
- motion_y = pos_y - decoder->v_offset; \
- } \
- xy_half = ((pos_y & 1) << 1) | (pos_x & 1); \
- offset = (pos_x >> 1) + ((pos_y op) + src_field) * decoder->stride; \
- table[xy_half] (decoder->dest[0] + dest_field * decoder->stride + \
- decoder->offset, ref[0] + offset, \
- 2 * decoder->stride, 8); \
- table[xy_half] (decoder->dest[1] + dest_field * decoder->stride + \
- decoder->offset, ref[1] + offset, \
- 2 * decoder->stride, 8); \
- table[xy_half] (decoder->dest[2] + dest_field * decoder->stride + \
- decoder->offset, ref[2] + offset, \
+ motion_y = pos_y - decoder->v_offset; \
+ } \
+ \
+ xy_half = ((pos_y & 1) << 1) | (pos_x & 1); \
+ offset = (pos_x >> 1) + ((pos_y op) + src_field) * decoder->stride; \
+ \
+ table[xy_half] (decoder->dest[0] + dest_field * decoder->stride + \
+ decoder->offset, ref[0] + offset, \
+ 2 * decoder->stride, 8); \
+ table[xy_half] (decoder->dest[1] + dest_field * decoder->stride + \
+ decoder->offset, ref[1] + offset, \
+ 2 * decoder->stride, 8); \
+ table[xy_half] (decoder->dest[2] + dest_field * decoder->stride + \
+ decoder->offset, ref[2] + offset, \
2 * decoder->stride, 8)
-#define MOTION_DMV_444(table,ref,motion_x,motion_y) \
- pos_x = 2 * decoder->offset + motion_x; \
- pos_y = decoder->v_offset + motion_y; \
- if (unlikely (pos_x > decoder->limit_x)) { \
+#define MOTION_DMV_444(table, ref, motion_x, motion_y) \
+ pos_x = 2 * decoder->offset + motion_x; \
+ pos_y = decoder->v_offset + motion_y; \
+ \
+ if (unlikely (pos_x > decoder->limit_x)) \
+ { \
pos_x = ((int)pos_x < 0) ? 0 : decoder->limit_x; \
- motion_x = pos_x - 2 * decoder->offset; \
- } \
- if (unlikely (pos_y > decoder->limit_y)) { \
+ motion_x = pos_x - 2 * decoder->offset; \
+ } \
+ \
+ if (unlikely (pos_y > decoder->limit_y)) \
+ { \
pos_y = ((int)pos_y < 0) ? 0 : decoder->limit_y; \
- motion_y = pos_y - decoder->v_offset; \
- } \
- xy_half = ((pos_y & 1) << 1) | (pos_x & 1); \
- offset = (pos_x >> 1) + (pos_y & ~1) * decoder->stride; \
- table[xy_half] (decoder->dest[0] + decoder->offset, \
- ref[0] + offset, 2 * decoder->stride, 8); \
+ motion_y = pos_y - decoder->v_offset; \
+ } \
+ \
+ xy_half = ((pos_y & 1) << 1) | (pos_x & 1); \
+ offset = (pos_x >> 1) + (pos_y & ~1) * decoder->stride; \
+ \
+ table[xy_half] (decoder->dest[0] + decoder->offset, \
+ ref[0] + offset, 2 * decoder->stride, 8); \
table[xy_half] (decoder->dest[0] + decoder->stride + decoder->offset, \
- ref[0] + decoder->stride + offset, \
- 2 * decoder->stride, 8); \
- table[xy_half] (decoder->dest[1] + decoder->offset, \
- ref[1] + offset, 2 * decoder->stride, 8); \
+ ref[0] + decoder->stride + offset, \
+ 2 * decoder->stride, 8); \
+ table[xy_half] (decoder->dest[1] + decoder->offset, \
+ ref[1] + offset, 2 * decoder->stride, 8); \
table[xy_half] (decoder->dest[1] + decoder->stride + decoder->offset, \
- ref[1] + decoder->stride + offset, \
- 2 * decoder->stride, 8); \
- table[xy_half] (decoder->dest[2] + decoder->offset, \
- ref[2] + offset, 2 * decoder->stride, 8); \
+ ref[1] + decoder->stride + offset, \
+ 2 * decoder->stride, 8); \
+ table[xy_half] (decoder->dest[2] + decoder->offset, \
+ ref[2] + offset, 2 * decoder->stride, 8); \
table[xy_half] (decoder->dest[2] + decoder->stride + decoder->offset, \
- ref[2] + decoder->stride + offset, \
+ ref[2] + decoder->stride + offset, \
2 * decoder->stride, 8)
-#define MOTION_ZERO_444(table,ref) \
- offset = decoder->offset + decoder->v_offset * decoder->stride; \
- table[0] (decoder->dest[0] + decoder->offset, \
- ref[0] + offset, decoder->stride, 16); \
- table[4] (decoder->dest[1] + decoder->offset, \
- ref[1] + offset, decoder->stride, 16); \
+#define MOTION_ZERO_444(table, ref) \
+ offset = decoder->offset + decoder->v_offset * decoder->stride; \
+ \
+ table[0] (decoder->dest[0] + decoder->offset, \
+ ref[0] + offset, decoder->stride, 16); \
+ table[4] (decoder->dest[1] + decoder->offset, \
+ ref[1] + offset, decoder->stride, 16); \
table[4] (decoder->dest[2] + (decoder->offset >> 1), \
ref[2] + offset, decoder->stride, 16)
@@ -1260,17 +1452,17 @@ static void motion_mp1 (mpeg2_decoder_t * const decoder,
unsigned int pos_x, pos_y, xy_half, offset;
NEEDBITS (bit_buf, bits, bit_ptr);
- motion_x = (motion->pmv[0][0] +
+ motion_x = motion->pmv[0][0] +
(get_motion_delta (decoder,
- motion->f_code[0]) << motion->f_code[1]));
+ motion->f_code[0]) << motion->f_code[1]);
motion_x = bound_motion_vector (motion_x,
motion->f_code[0] + motion->f_code[1]);
motion->pmv[0][0] = motion_x;
NEEDBITS (bit_buf, bits, bit_ptr);
- motion_y = (motion->pmv[0][1] +
+ motion_y = motion->pmv[0][1] +
(get_motion_delta (decoder,
- motion->f_code[0]) << motion->f_code[1]));
+ motion->f_code[0]) << motion->f_code[1]);
motion_y = bound_motion_vector (motion_y,
motion->f_code[0] + motion->f_code[1]);
motion->pmv[0][1] = motion_y;
@@ -1278,227 +1470,228 @@ static void motion_mp1 (mpeg2_decoder_t * const decoder,
MOTION_420 (table, motion->ref[0], motion_x, motion_y, 16, 0);
}
-#define MOTION_FUNCTIONS(FORMAT,MOTION,MOTION_FIELD,MOTION_DMV,MOTION_ZERO) \
+#define MOTION_FUNCTIONS(FORMAT, MOTION, MOTION_FIELD, \
+ MOTION_DMV, MOTION_ZERO) \
\
-static void motion_fr_frame_##FORMAT (mpeg2_decoder_t * const decoder, \
- motion_t * const motion, \
+static void motion_fr_frame_##FORMAT (mpeg2_decoder_t * const decoder, \
+ motion_t * const motion, \
mpeg2_mc_fct * const * const table) \
-{ \
- int motion_x, motion_y; \
- unsigned int pos_x, pos_y, xy_half, offset; \
+{ \
+ int motion_x, motion_y; \
+ unsigned int pos_x, pos_y, xy_half, offset; \
\
- NEEDBITS (bit_buf, bits, bit_ptr); \
- motion_x = motion->pmv[0][0] + get_motion_delta (decoder, \
+ NEEDBITS (bit_buf, bits, bit_ptr); \
+ motion_x = motion->pmv[0][0] + get_motion_delta (decoder, \
motion->f_code[0]); \
- motion_x = bound_motion_vector (motion_x, motion->f_code[0]); \
- motion->pmv[1][0] = motion->pmv[0][0] = motion_x; \
+ motion_x = bound_motion_vector (motion_x, motion->f_code[0]); \
+ motion->pmv[1][0] = motion->pmv[0][0] = motion_x; \
\
- NEEDBITS (bit_buf, bits, bit_ptr); \
- motion_y = motion->pmv[0][1] + get_motion_delta (decoder, \
+ NEEDBITS (bit_buf, bits, bit_ptr); \
+ motion_y = motion->pmv[0][1] + get_motion_delta (decoder, \
motion->f_code[1]); \
- motion_y = bound_motion_vector (motion_y, motion->f_code[1]); \
- motion->pmv[1][1] = motion->pmv[0][1] = motion_y; \
+ motion_y = bound_motion_vector (motion_y, motion->f_code[1]); \
+ motion->pmv[1][1] = motion->pmv[0][1] = motion_y; \
\
- MOTION (table, motion->ref[0], motion_x, motion_y, 16, 0); \
-} \
+ MOTION (table, motion->ref[0], motion_x, motion_y, 16, 0); \
+} \
\
-static void motion_fr_field_##FORMAT (mpeg2_decoder_t * const decoder, \
- motion_t * const motion, \
+static void motion_fr_field_##FORMAT (mpeg2_decoder_t * const decoder, \
+ motion_t * const motion, \
mpeg2_mc_fct * const * const table) \
-{ \
- int motion_x, motion_y, field; \
- unsigned int pos_x, pos_y, xy_half, offset; \
+{ \
+ int motion_x, motion_y, field; \
+ unsigned int pos_x, pos_y, xy_half, offset; \
\
- NEEDBITS (bit_buf, bits, bit_ptr); \
- field = UBITS (bit_buf, 1); \
+ NEEDBITS (bit_buf, bits, bit_ptr); \
+ field = UBITS (bit_buf, 1); \
DUMPBITS (bit_buf, bits, 1); \
\
- motion_x = motion->pmv[0][0] + get_motion_delta (decoder, \
+ motion_x = motion->pmv[0][0] + get_motion_delta (decoder, \
motion->f_code[0]); \
- motion_x = bound_motion_vector (motion_x, motion->f_code[0]); \
- motion->pmv[0][0] = motion_x; \
+ motion_x = bound_motion_vector (motion_x, motion->f_code[0]); \
+ motion->pmv[0][0] = motion_x; \
\
- NEEDBITS (bit_buf, bits, bit_ptr); \
- motion_y = ((motion->pmv[0][1] >> 1) + \
- get_motion_delta (decoder, motion->f_code[1])); \
- /* motion_y = bound_motion_vector (motion_y, motion->f_code[1]); */ \
- motion->pmv[0][1] = motion_y << 1; \
+ NEEDBITS (bit_buf, bits, bit_ptr); \
+ motion_y = ((motion->pmv[0][1] >> 1) + \
+ get_motion_delta (decoder, motion->f_code[1])); \
+ /* motion_y = bound_motion_vector (motion_y, motion->f_code[1]); */ \
+ motion->pmv[0][1] = motion_y << 1; \
\
MOTION_FIELD (table, motion->ref[0], motion_x, motion_y, 0, & ~1, field); \
\
- NEEDBITS (bit_buf, bits, bit_ptr); \
- field = UBITS (bit_buf, 1); \
+ NEEDBITS (bit_buf, bits, bit_ptr); \
+ field = UBITS (bit_buf, 1); \
DUMPBITS (bit_buf, bits, 1); \
\
- motion_x = motion->pmv[1][0] + get_motion_delta (decoder, \
+ motion_x = motion->pmv[1][0] + get_motion_delta (decoder, \
motion->f_code[0]); \
- motion_x = bound_motion_vector (motion_x, motion->f_code[0]); \
- motion->pmv[1][0] = motion_x; \
+ motion_x = bound_motion_vector (motion_x, motion->f_code[0]); \
+ motion->pmv[1][0] = motion_x; \
\
- NEEDBITS (bit_buf, bits, bit_ptr); \
- motion_y = ((motion->pmv[1][1] >> 1) + \
- get_motion_delta (decoder, motion->f_code[1])); \
- /* motion_y = bound_motion_vector (motion_y, motion->f_code[1]); */ \
- motion->pmv[1][1] = motion_y << 1; \
+ NEEDBITS (bit_buf, bits, bit_ptr); \
+ motion_y = ((motion->pmv[1][1] >> 1) + \
+ get_motion_delta (decoder, motion->f_code[1])); \
+ /* motion_y = bound_motion_vector (motion_y, motion->f_code[1]); */ \
+ motion->pmv[1][1] = motion_y << 1; \
\
MOTION_FIELD (table, motion->ref[0], motion_x, motion_y, 1, & ~1, field); \
-} \
+} \
\
-static void motion_fr_dmv_##FORMAT (mpeg2_decoder_t * const decoder, \
- motion_t * const motion, \
- mpeg2_mc_fct * const * const table) \
-{ \
- int motion_x, motion_y, dmv_x, dmv_y, m, other_x, other_y; \
- unsigned int pos_x, pos_y, xy_half, offset; \
+static void motion_fr_dmv_##FORMAT (mpeg2_decoder_t * const decoder, \
+ motion_t * const motion, \
+ mpeg2_mc_fct * const * const table) \
+{ \
+ int motion_x, motion_y, dmv_x, dmv_y, m, other_x, other_y; \
+ unsigned int pos_x, pos_y, xy_half, offset; \
\
(void)table; \
- NEEDBITS (bit_buf, bits, bit_ptr); \
- motion_x = motion->pmv[0][0] + get_motion_delta (decoder, \
+ NEEDBITS (bit_buf, bits, bit_ptr); \
+ motion_x = motion->pmv[0][0] + get_motion_delta (decoder, \
motion->f_code[0]); \
- motion_x = bound_motion_vector (motion_x, motion->f_code[0]); \
- motion->pmv[1][0] = motion->pmv[0][0] = motion_x; \
- NEEDBITS (bit_buf, bits, bit_ptr); \
- dmv_x = get_dmv (decoder); \
- \
- motion_y = ((motion->pmv[0][1] >> 1) + \
- get_motion_delta (decoder, motion->f_code[1])); \
- /* motion_y = bound_motion_vector (motion_y, motion->f_code[1]); */ \
- motion->pmv[1][1] = motion->pmv[0][1] = motion_y << 1; \
- dmv_y = get_dmv (decoder); \
- \
- m = decoder->top_field_first ? 1 : 3; \
- other_x = ((motion_x * m + (motion_x > 0)) >> 1) + dmv_x; \
- other_y = ((motion_y * m + (motion_y > 0)) >> 1) + dmv_y - 1; \
+ motion_x = bound_motion_vector (motion_x, motion->f_code[0]); \
+ motion->pmv[1][0] = motion->pmv[0][0] = motion_x; \
+ NEEDBITS (bit_buf, bits, bit_ptr); \
+ dmv_x = get_dmv (decoder); \
+ \
+ motion_y = ((motion->pmv[0][1] >> 1) + \
+ get_motion_delta (decoder, motion->f_code[1])); \
+ /* motion_y = bound_motion_vector (motion_y, motion->f_code[1]); */ \
+ motion->pmv[1][1] = motion->pmv[0][1] = motion_y << 1; \
+ dmv_y = get_dmv (decoder); \
+ \
+ m = decoder->top_field_first ? 1 : 3; \
+ other_x = ((motion_x * m + (motion_x > 0)) >> 1) + dmv_x; \
+ other_y = ((motion_y * m + (motion_y > 0)) >> 1) + dmv_y - 1; \
MOTION_FIELD (mpeg2_mc.put, motion->ref[0], other_x, other_y, 0, | 1, 0); \
\
- m = decoder->top_field_first ? 3 : 1; \
- other_x = ((motion_x * m + (motion_x > 0)) >> 1) + dmv_x; \
- other_y = ((motion_y * m + (motion_y > 0)) >> 1) + dmv_y + 1; \
+ m = decoder->top_field_first ? 3 : 1; \
+ other_x = ((motion_x * m + (motion_x > 0)) >> 1) + dmv_x; \
+ other_y = ((motion_y * m + (motion_y > 0)) >> 1) + dmv_y + 1; \
MOTION_FIELD (mpeg2_mc.put, motion->ref[0], other_x, other_y, 1, & ~1, 0);\
\
- MOTION_DMV (mpeg2_mc.avg, motion->ref[0], motion_x, motion_y); \
-} \
+ MOTION_DMV (mpeg2_mc.avg, motion->ref[0], motion_x, motion_y); \
+} \
\
-static void motion_reuse_##FORMAT (mpeg2_decoder_t * const decoder, \
- motion_t * const motion, \
- mpeg2_mc_fct * const * const table) \
-{ \
- int motion_x, motion_y; \
- unsigned int pos_x, pos_y, xy_half, offset; \
+static void motion_reuse_##FORMAT (mpeg2_decoder_t * const decoder, \
+ motion_t * const motion, \
+ mpeg2_mc_fct * const * const table) \
+{ \
+ int motion_x, motion_y; \
+ unsigned int pos_x, pos_y, xy_half, offset; \
\
- motion_x = motion->pmv[0][0]; \
- motion_y = motion->pmv[0][1]; \
+ motion_x = motion->pmv[0][0]; \
+ motion_y = motion->pmv[0][1]; \
\
- MOTION (table, motion->ref[0], motion_x, motion_y, 16, 0); \
-} \
+ MOTION (table, motion->ref[0], motion_x, motion_y, 16, 0); \
+} \
\
-static void motion_zero_##FORMAT (mpeg2_decoder_t * const decoder, \
- motion_t * const motion, \
- mpeg2_mc_fct * const * const table) \
-{ \
+static void motion_zero_##FORMAT (mpeg2_decoder_t * const decoder, \
+ motion_t * const motion, \
+ mpeg2_mc_fct * const * const table) \
+{ \
unsigned int offset; \
\
- motion->pmv[0][0] = motion->pmv[0][1] = 0; \
- motion->pmv[1][0] = motion->pmv[1][1] = 0; \
+ motion->pmv[0][0] = motion->pmv[0][1] = 0; \
+ motion->pmv[1][0] = motion->pmv[1][1] = 0; \
\
MOTION_ZERO (table, motion->ref[0]); \
-} \
+} \
\
-static void motion_fi_field_##FORMAT (mpeg2_decoder_t * const decoder, \
- motion_t * const motion, \
+static void motion_fi_field_##FORMAT (mpeg2_decoder_t * const decoder, \
+ motion_t * const motion, \
mpeg2_mc_fct * const * const table) \
-{ \
- int motion_x, motion_y; \
- uint8_t ** ref_field; \
- unsigned int pos_x, pos_y, xy_half, offset; \
+{ \
+ int motion_x, motion_y; \
+ uint8_t ** ref_field; \
+ unsigned int pos_x, pos_y, xy_half, offset; \
\
- NEEDBITS (bit_buf, bits, bit_ptr); \
- ref_field = motion->ref2[UBITS (bit_buf, 1)]; \
+ NEEDBITS (bit_buf, bits, bit_ptr); \
+ ref_field = motion->ref2[UBITS (bit_buf, 1)]; \
DUMPBITS (bit_buf, bits, 1); \
\
- motion_x = motion->pmv[0][0] + get_motion_delta (decoder, \
+ motion_x = motion->pmv[0][0] + get_motion_delta (decoder, \
motion->f_code[0]); \
- motion_x = bound_motion_vector (motion_x, motion->f_code[0]); \
- motion->pmv[1][0] = motion->pmv[0][0] = motion_x; \
+ motion_x = bound_motion_vector (motion_x, motion->f_code[0]); \
+ motion->pmv[1][0] = motion->pmv[0][0] = motion_x; \
\
- NEEDBITS (bit_buf, bits, bit_ptr); \
- motion_y = motion->pmv[0][1] + get_motion_delta (decoder, \
+ NEEDBITS (bit_buf, bits, bit_ptr); \
+ motion_y = motion->pmv[0][1] + get_motion_delta (decoder, \
motion->f_code[1]); \
- motion_y = bound_motion_vector (motion_y, motion->f_code[1]); \
- motion->pmv[1][1] = motion->pmv[0][1] = motion_y; \
+ motion_y = bound_motion_vector (motion_y, motion->f_code[1]); \
+ motion->pmv[1][1] = motion->pmv[0][1] = motion_y; \
\
- MOTION (table, ref_field, motion_x, motion_y, 16, 0); \
-} \
+ MOTION (table, ref_field, motion_x, motion_y, 16, 0); \
+} \
\
-static void motion_fi_16x8_##FORMAT (mpeg2_decoder_t * const decoder, \
- motion_t * const motion, \
+static void motion_fi_16x8_##FORMAT (mpeg2_decoder_t * const decoder, \
+ motion_t * const motion, \
mpeg2_mc_fct * const * const table) \
-{ \
- int motion_x, motion_y; \
- uint8_t ** ref_field; \
- unsigned int pos_x, pos_y, xy_half, offset; \
+{ \
+ int motion_x, motion_y; \
+ uint8_t ** ref_field; \
+ unsigned int pos_x, pos_y, xy_half, offset; \
\
- NEEDBITS (bit_buf, bits, bit_ptr); \
- ref_field = motion->ref2[UBITS (bit_buf, 1)]; \
+ NEEDBITS (bit_buf, bits, bit_ptr); \
+ ref_field = motion->ref2[UBITS (bit_buf, 1)]; \
DUMPBITS (bit_buf, bits, 1); \
\
- motion_x = motion->pmv[0][0] + get_motion_delta (decoder, \
+ motion_x = motion->pmv[0][0] + get_motion_delta (decoder, \
motion->f_code[0]); \
- motion_x = bound_motion_vector (motion_x, motion->f_code[0]); \
- motion->pmv[0][0] = motion_x; \
+ motion_x = bound_motion_vector (motion_x, motion->f_code[0]); \
+ motion->pmv[0][0] = motion_x; \
\
- NEEDBITS (bit_buf, bits, bit_ptr); \
- motion_y = motion->pmv[0][1] + get_motion_delta (decoder, \
+ NEEDBITS (bit_buf, bits, bit_ptr); \
+ motion_y = motion->pmv[0][1] + get_motion_delta (decoder, \
motion->f_code[1]); \
- motion_y = bound_motion_vector (motion_y, motion->f_code[1]); \
- motion->pmv[0][1] = motion_y; \
+ motion_y = bound_motion_vector (motion_y, motion->f_code[1]); \
+ motion->pmv[0][1] = motion_y; \
\
MOTION (table, ref_field, motion_x, motion_y, 8, 0); \
\
- NEEDBITS (bit_buf, bits, bit_ptr); \
- ref_field = motion->ref2[UBITS (bit_buf, 1)]; \
+ NEEDBITS (bit_buf, bits, bit_ptr); \
+ ref_field = motion->ref2[UBITS (bit_buf, 1)]; \
DUMPBITS (bit_buf, bits, 1); \
\
- motion_x = motion->pmv[1][0] + get_motion_delta (decoder, \
+ motion_x = motion->pmv[1][0] + get_motion_delta (decoder, \
motion->f_code[0]); \
- motion_x = bound_motion_vector (motion_x, motion->f_code[0]); \
- motion->pmv[1][0] = motion_x; \
+ motion_x = bound_motion_vector (motion_x, motion->f_code[0]); \
+ motion->pmv[1][0] = motion_x; \
\
- NEEDBITS (bit_buf, bits, bit_ptr); \
- motion_y = motion->pmv[1][1] + get_motion_delta (decoder, \
+ NEEDBITS (bit_buf, bits, bit_ptr); \
+ motion_y = motion->pmv[1][1] + get_motion_delta (decoder, \
motion->f_code[1]); \
- motion_y = bound_motion_vector (motion_y, motion->f_code[1]); \
- motion->pmv[1][1] = motion_y; \
+ motion_y = bound_motion_vector (motion_y, motion->f_code[1]); \
+ motion->pmv[1][1] = motion_y; \
\
MOTION (table, ref_field, motion_x, motion_y, 8, 8); \
-} \
+} \
\
-static void motion_fi_dmv_##FORMAT (mpeg2_decoder_t * const decoder, \
- motion_t * const motion, \
- mpeg2_mc_fct * const * const table) \
-{ \
- int motion_x, motion_y, other_x, other_y; \
- unsigned int pos_x, pos_y, xy_half, offset; \
+static void motion_fi_dmv_##FORMAT (mpeg2_decoder_t * const decoder, \
+ motion_t * const motion, \
+ mpeg2_mc_fct * const * const table) \
+{ \
+ int motion_x, motion_y, other_x, other_y; \
+ unsigned int pos_x, pos_y, xy_half, offset; \
\
(void)table; \
- NEEDBITS (bit_buf, bits, bit_ptr); \
- motion_x = motion->pmv[0][0] + get_motion_delta (decoder, \
+ NEEDBITS (bit_buf, bits, bit_ptr); \
+ motion_x = motion->pmv[0][0] + get_motion_delta (decoder, \
motion->f_code[0]); \
- motion_x = bound_motion_vector (motion_x, motion->f_code[0]); \
- motion->pmv[1][0] = motion->pmv[0][0] = motion_x; \
- NEEDBITS (bit_buf, bits, bit_ptr); \
- other_x = ((motion_x + (motion_x > 0)) >> 1) + get_dmv (decoder); \
+ motion_x = bound_motion_vector (motion_x, motion->f_code[0]); \
+ motion->pmv[1][0] = motion->pmv[0][0] = motion_x; \
+ NEEDBITS (bit_buf, bits, bit_ptr); \
+ other_x = ((motion_x + (motion_x > 0)) >> 1) + get_dmv (decoder); \
\
- motion_y = motion->pmv[0][1] + get_motion_delta (decoder, \
+ motion_y = motion->pmv[0][1] + get_motion_delta (decoder, \
motion->f_code[1]); \
- motion_y = bound_motion_vector (motion_y, motion->f_code[1]); \
- motion->pmv[1][1] = motion->pmv[0][1] = motion_y; \
- other_y = (((motion_y + (motion_y > 0)) >> 1) + get_dmv (decoder) + \
- decoder->dmv_offset); \
+ motion_y = bound_motion_vector (motion_y, motion->f_code[1]); \
+ motion->pmv[1][1] = motion->pmv[0][1] = motion_y; \
+ other_y = (((motion_y + (motion_y > 0)) >> 1) + get_dmv (decoder) + \
+ decoder->dmv_offset); \
\
- MOTION (mpeg2_mc.put, motion->ref[0], motion_x, motion_y, 16, 0); \
- MOTION (mpeg2_mc.avg, motion->ref[1], other_x, other_y, 16, 0); \
-} \
+ MOTION (mpeg2_mc.put, motion->ref[0], motion_x, motion_y, 16, 0); \
+ MOTION (mpeg2_mc.avg, motion->ref[1], other_x, other_y, 16, 0); \
+} \
MOTION_FUNCTIONS (420, MOTION_420, MOTION_FIELD_420, MOTION_DMV_420,
MOTION_ZERO_420)
@@ -1534,16 +1727,21 @@ static void motion_fi_conceal (mpeg2_decoder_t * const decoder)
NEEDBITS (bit_buf, bits, bit_ptr);
DUMPBITS (bit_buf, bits, 1); /* remove field_select */
- tmp = (decoder->f_motion.pmv[0][0] +
- get_motion_delta (decoder, decoder->f_motion.f_code[0]));
+ tmp = decoder->f_motion.pmv[0][0] +
+ get_motion_delta (decoder, decoder->f_motion.f_code[0]);
tmp = bound_motion_vector (tmp, decoder->f_motion.f_code[0]);
- decoder->f_motion.pmv[1][0] = decoder->f_motion.pmv[0][0] = tmp;
+
+ decoder->f_motion.pmv[1][0] =
+ decoder->f_motion.pmv[0][0] = tmp;
NEEDBITS (bit_buf, bits, bit_ptr);
+
tmp = (decoder->f_motion.pmv[0][1] +
- get_motion_delta (decoder, decoder->f_motion.f_code[1]));
+ get_motion_delta (decoder, decoder->f_motion.f_code[1]));
tmp = bound_motion_vector (tmp, decoder->f_motion.f_code[1]);
- decoder->f_motion.pmv[1][1] = decoder->f_motion.pmv[0][1] = tmp;
+
+ decoder->f_motion.pmv[1][1] =
+ decoder->f_motion.pmv[0][1] = tmp;
DUMPBITS (bit_buf, bits, 1); /* remove marker_bit */
}
@@ -1552,34 +1750,44 @@ static void motion_fi_conceal (mpeg2_decoder_t * const decoder)
#undef bits
#undef bit_ptr
-#define MOTION_CALL(routine,direction) \
-do { \
- if ((direction) & MACROBLOCK_MOTION_FORWARD) \
- routine (decoder, &(decoder->f_motion), mpeg2_mc.put); \
- if ((direction) & MACROBLOCK_MOTION_BACKWARD) \
- routine (decoder, &(decoder->b_motion), \
- ((direction) & MACROBLOCK_MOTION_FORWARD ? \
- mpeg2_mc.avg : mpeg2_mc.put)); \
+#define MOTION_CALL(routine, direction) \
+do { \
+ if ((direction) & MACROBLOCK_MOTION_FORWARD) \
+ routine (decoder, &decoder->f_motion, mpeg2_mc.put); \
+ \
+ if ((direction) & MACROBLOCK_MOTION_BACKWARD) \
+ { \
+ routine (decoder, &decoder->b_motion, \
+ ((direction) & MACROBLOCK_MOTION_FORWARD ? \
+ mpeg2_mc.avg : mpeg2_mc.put)); \
+ } \
} while (0)
-#define NEXT_MACROBLOCK \
+#define NEXT_MACROBLOCK \
do { \
decoder->offset += 16; \
- if (decoder->offset == decoder->width) { \
+ \
+ if (decoder->offset == decoder->width) \
+ { \
do { /* just so we can use the break statement */ \
- if (decoder->convert) { \
+ if (decoder->convert) \
+ { \
decoder->convert (decoder->convert_id, decoder->dest, \
decoder->v_offset); \
if (decoder->coding_type == B_TYPE) \
break; \
} \
+ \
decoder->dest[0] += decoder->slice_stride; \
decoder->dest[1] += decoder->slice_uv_stride; \
decoder->dest[2] += decoder->slice_uv_stride; \
} while (0); \
+ \
decoder->v_offset += 16; \
+ \
if (decoder->v_offset > decoder->limit_y) \
return; \
+ \
decoder->offset = 0; \
} \
} while (0)
@@ -1606,7 +1814,8 @@ void mpeg2_init_fbuf (mpeg2_decoder_t * decoder, uint8_t * current_fbuf[3],
decoder->b_motion.ref[0][1] = backward_fbuf[1] + (offset >> 1);
decoder->b_motion.ref[0][2] = backward_fbuf[2] + (offset >> 1);
- if (decoder->picture_structure != FRAME_PICTURE) {
+ if (decoder->picture_structure != FRAME_PICTURE)
+ {
decoder->dmv_offset = bottom_field ? 1 : -1;
decoder->f_motion.ref2[0] = decoder->f_motion.ref[bottom_field];
decoder->f_motion.ref2[1] = decoder->f_motion.ref[!bottom_field];
@@ -1639,44 +1848,59 @@ void mpeg2_init_fbuf (mpeg2_decoder_t * decoder, uint8_t * current_fbuf[3],
decoder->limit_y_8 = 2 * height - 16;
decoder->limit_y = height - 16;
- if (decoder->mpeg1) {
+ if (decoder->mpeg1)
+ {
decoder->motion_parser[0] = motion_zero_420;
decoder->motion_parser[MC_FRAME] = motion_mp1;
decoder->motion_parser[4] = motion_reuse_420;
- } else if (decoder->picture_structure == FRAME_PICTURE) {
- if (decoder->chroma_format == 0) {
+ }
+ else if (decoder->picture_structure == FRAME_PICTURE)
+ {
+ if (decoder->chroma_format == 0)
+ {
decoder->motion_parser[0] = motion_zero_420;
decoder->motion_parser[MC_FIELD] = motion_fr_field_420;
decoder->motion_parser[MC_FRAME] = motion_fr_frame_420;
decoder->motion_parser[MC_DMV] = motion_fr_dmv_420;
decoder->motion_parser[4] = motion_reuse_420;
- } else if (decoder->chroma_format == 1) {
+ }
+ else if (decoder->chroma_format == 1)
+ {
decoder->motion_parser[0] = motion_zero_422;
decoder->motion_parser[MC_FIELD] = motion_fr_field_422;
decoder->motion_parser[MC_FRAME] = motion_fr_frame_422;
decoder->motion_parser[MC_DMV] = motion_fr_dmv_422;
decoder->motion_parser[4] = motion_reuse_422;
- } else {
+ }
+ else
+ {
decoder->motion_parser[0] = motion_zero_444;
decoder->motion_parser[MC_FIELD] = motion_fr_field_444;
decoder->motion_parser[MC_FRAME] = motion_fr_frame_444;
decoder->motion_parser[MC_DMV] = motion_fr_dmv_444;
decoder->motion_parser[4] = motion_reuse_444;
}
- } else {
- if (decoder->chroma_format == 0) {
+ }
+ else
+ {
+ if (decoder->chroma_format == 0)
+ {
decoder->motion_parser[0] = motion_zero_420;
decoder->motion_parser[MC_FIELD] = motion_fi_field_420;
decoder->motion_parser[MC_16X8] = motion_fi_16x8_420;
decoder->motion_parser[MC_DMV] = motion_fi_dmv_420;
decoder->motion_parser[4] = motion_reuse_420;
- } else if (decoder->chroma_format == 1) {
+ }
+ else if (decoder->chroma_format == 1)
+ {
decoder->motion_parser[0] = motion_zero_422;
decoder->motion_parser[MC_FIELD] = motion_fi_field_422;
decoder->motion_parser[MC_16X8] = motion_fi_16x8_422;
decoder->motion_parser[MC_DMV] = motion_fi_dmv_422;
decoder->motion_parser[4] = motion_reuse_422;
- } else {
+ }
+ else
+ {
decoder->motion_parser[0] = motion_zero_444;
decoder->motion_parser[MC_FIELD] = motion_fi_field_444;
decoder->motion_parser[MC_16X8] = motion_fi_16x8_444;
@@ -1691,6 +1915,7 @@ static inline int slice_init (mpeg2_decoder_t * const decoder, int code)
#define bit_buf (decoder->bitstream_buf)
#define bits (decoder->bitstream_bits)
#define bit_ptr (decoder->bitstream_ptr)
+
int offset;
const MBAtab * mba;
@@ -1702,14 +1927,19 @@ static inline int slice_init (mpeg2_decoder_t * const decoder, int code)
decoder->b_motion.pmv[0][0] = decoder->b_motion.pmv[0][1] = 0;
decoder->b_motion.pmv[1][0] = decoder->b_motion.pmv[1][1] = 0;
- if (decoder->vertical_position_extension) {
+ if (decoder->vertical_position_extension)
+ {
code += UBITS (bit_buf, 3) << 7;
DUMPBITS (bit_buf, bits, 3);
}
+
decoder->v_offset = (code - 1) * 16;
offset = 0;
+
if (!(decoder->convert) || decoder->coding_type != B_TYPE)
+ {
offset = (code - 1) * decoder->slice_stride;
+ }
decoder->dest[0] = decoder->picture_dest[0] + offset;
offset >>= (2 - decoder->chroma_format);
@@ -1719,51 +1949,68 @@ static inline int slice_init (mpeg2_decoder_t * const decoder, int code)
get_quantizer_scale (decoder);
/* ignore intra_slice and all the extra data */
- while (bit_buf & 0x80000000) {
+ while (bit_buf & 0x80000000)
+ {
DUMPBITS (bit_buf, bits, 9);
NEEDBITS (bit_buf, bits, bit_ptr);
}
/* decode initial macroblock address increment */
offset = 0;
- while (1) {
- if (bit_buf >= 0x08000000) {
+ while (1)
+ {
+ if (bit_buf >= 0x08000000)
+ {
mba = MBA_5 + (UBITS (bit_buf, 6) - 2);
break;
- } else if (bit_buf >= 0x01800000) {
+ }
+ else if (bit_buf >= 0x01800000)
+ {
mba = MBA_11 + (UBITS (bit_buf, 12) - 24);
break;
- } else switch (UBITS (bit_buf, 12)) {
- case 8: /* macroblock_escape */
- offset += 33;
- DUMPBITS (bit_buf, bits, 11);
- NEEDBITS (bit_buf, bits, bit_ptr);
- continue;
- case 15: /* macroblock_stuffing (MPEG1 only) */
- bit_buf &= 0xfffff;
- DUMPBITS (bit_buf, bits, 11);
- NEEDBITS (bit_buf, bits, bit_ptr);
- continue;
- default: /* error */
- return 1;
+ }
+ else
+ {
+ switch (UBITS (bit_buf, 12))
+ {
+ case 8: /* macroblock_escape */
+ offset += 33;
+ DUMPBITS (bit_buf, bits, 11);
+ NEEDBITS (bit_buf, bits, bit_ptr);
+ continue;
+ case 15: /* macroblock_stuffing (MPEG1 only) */
+ bit_buf &= 0xfffff;
+ DUMPBITS (bit_buf, bits, 11);
+ NEEDBITS (bit_buf, bits, bit_ptr);
+ continue;
+ default: /* error */
+ return 1;
+ }
}
}
+
DUMPBITS (bit_buf, bits, mba->len + 1);
decoder->offset = (offset + mba->mba) << 4;
- while (decoder->offset - decoder->width >= 0) {
+ while (decoder->offset - decoder->width >= 0)
+ {
decoder->offset -= decoder->width;
- if (!(decoder->convert) || decoder->coding_type != B_TYPE) {
+
+ if (!(decoder->convert) || decoder->coding_type != B_TYPE)
+ {
decoder->dest[0] += decoder->slice_stride;
decoder->dest[1] += decoder->slice_uv_stride;
decoder->dest[2] += decoder->slice_uv_stride;
}
+
decoder->v_offset += 16;
}
+
if (decoder->v_offset > decoder->limit_y)
return 1;
return 0;
+
#undef bit_buf
#undef bits
#undef bit_ptr
@@ -1781,7 +2028,8 @@ void mpeg2_slice (mpeg2_decoder_t * const decoder, const int code,
if (slice_init (decoder, code))
return;
- while (1) {
+ while (1)
+ {
int macroblock_modes;
int mba_inc;
const MBAtab * mba;
@@ -1794,28 +2042,34 @@ void mpeg2_slice (mpeg2_decoder_t * const decoder, const int code,
if (macroblock_modes & MACROBLOCK_QUANT)
get_quantizer_scale (decoder);
- if (macroblock_modes & MACROBLOCK_INTRA) {
-
+ if (macroblock_modes & MACROBLOCK_INTRA)
+ {
int DCT_offset, DCT_stride;
int offset;
uint8_t * dest_y;
- if (decoder->concealment_motion_vectors) {
+ if (decoder->concealment_motion_vectors)
+ {
if (decoder->picture_structure == FRAME_PICTURE)
motion_fr_conceal (decoder);
else
motion_fi_conceal (decoder);
- } else {
+ }
+ else
+ {
decoder->f_motion.pmv[0][0] = decoder->f_motion.pmv[0][1] = 0;
decoder->f_motion.pmv[1][0] = decoder->f_motion.pmv[1][1] = 0;
decoder->b_motion.pmv[0][0] = decoder->b_motion.pmv[0][1] = 0;
decoder->b_motion.pmv[1][0] = decoder->b_motion.pmv[1][1] = 0;
}
- if (macroblock_modes & DCT_TYPE_INTERLACED) {
+ if (macroblock_modes & DCT_TYPE_INTERLACED)
+ {
DCT_offset = decoder->stride;
DCT_stride = decoder->stride * 2;
- } else {
+ }
+ else
+ {
DCT_offset = decoder->stride * 8;
DCT_stride = decoder->stride;
}
@@ -1826,27 +2080,38 @@ void mpeg2_slice (mpeg2_decoder_t * const decoder, const int code,
slice_intra_DCT (decoder, 0, dest_y + 8, DCT_stride);
slice_intra_DCT (decoder, 0, dest_y + DCT_offset, DCT_stride);
slice_intra_DCT (decoder, 0, dest_y + DCT_offset + 8, DCT_stride);
- if (likely (decoder->chroma_format == 0)) {
+
+ if (likely (decoder->chroma_format == 0))
+ {
slice_intra_DCT (decoder, 1, decoder->dest[1] + (offset >> 1),
decoder->uv_stride);
slice_intra_DCT (decoder, 2, decoder->dest[2] + (offset >> 1),
decoder->uv_stride);
- if (decoder->coding_type == D_TYPE) {
+
+ if (decoder->coding_type == D_TYPE)
+ {
NEEDBITS (bit_buf, bits, bit_ptr);
DUMPBITS (bit_buf, bits, 1);
}
- } else if (likely (decoder->chroma_format == 1)) {
+ }
+ else if (likely (decoder->chroma_format == 1))
+ {
uint8_t * dest_u = decoder->dest[1] + (offset >> 1);
uint8_t * dest_v = decoder->dest[2] + (offset >> 1);
+
DCT_stride >>= 1;
DCT_offset >>= 1;
+
slice_intra_DCT (decoder, 1, dest_u, DCT_stride);
slice_intra_DCT (decoder, 2, dest_v, DCT_stride);
slice_intra_DCT (decoder, 1, dest_u + DCT_offset, DCT_stride);
slice_intra_DCT (decoder, 2, dest_v + DCT_offset, DCT_stride);
- } else {
+ }
+ else
+ {
uint8_t * dest_u = decoder->dest[1] + offset;
uint8_t * dest_v = decoder->dest[2] + offset;
+
slice_intra_DCT (decoder, 1, dest_u, DCT_stride);
slice_intra_DCT (decoder, 2, dest_v, DCT_stride);
slice_intra_DCT (decoder, 1, dest_u + DCT_offset, DCT_stride);
@@ -1858,52 +2123,66 @@ void mpeg2_slice (mpeg2_decoder_t * const decoder, const int code,
slice_intra_DCT (decoder, 2, dest_v + DCT_offset + 8,
DCT_stride);
}
- } else {
-
+ }
+ else
+ {
motion_parser_t * parser;
parser =
decoder->motion_parser[macroblock_modes >> MOTION_TYPE_SHIFT];
MOTION_CALL (parser, macroblock_modes);
- if (macroblock_modes & MACROBLOCK_PATTERN) {
+ if (macroblock_modes & MACROBLOCK_PATTERN)
+ {
int coded_block_pattern;
int DCT_offset, DCT_stride;
- if (macroblock_modes & DCT_TYPE_INTERLACED) {
+ if (macroblock_modes & DCT_TYPE_INTERLACED)
+ {
DCT_offset = decoder->stride;
DCT_stride = decoder->stride * 2;
- } else {
+ }
+ else
+ {
DCT_offset = decoder->stride * 8;
DCT_stride = decoder->stride;
}
coded_block_pattern = get_coded_block_pattern (decoder);
- if (likely (decoder->chroma_format == 0)) {
+ if (likely (decoder->chroma_format == 0))
+ {
int offset = decoder->offset;
uint8_t * dest_y = decoder->dest[0] + offset;
+
if (coded_block_pattern & 1)
slice_non_intra_DCT (decoder, 0, dest_y, DCT_stride);
+
if (coded_block_pattern & 2)
slice_non_intra_DCT (decoder, 0, dest_y + 8,
DCT_stride);
+
if (coded_block_pattern & 4)
slice_non_intra_DCT (decoder, 0, dest_y + DCT_offset,
DCT_stride);
+
if (coded_block_pattern & 8)
slice_non_intra_DCT (decoder, 0,
dest_y + DCT_offset + 8,
DCT_stride);
+
if (coded_block_pattern & 16)
slice_non_intra_DCT (decoder, 1,
decoder->dest[1] + (offset >> 1),
decoder->uv_stride);
+
if (coded_block_pattern & 32)
slice_non_intra_DCT (decoder, 2,
decoder->dest[2] + (offset >> 1),
decoder->uv_stride);
- } else if (likely (decoder->chroma_format == 1)) {
+ }
+ else if (likely (decoder->chroma_format == 1))
+ {
int offset;
uint8_t * dest_y;
@@ -1912,14 +2191,18 @@ void mpeg2_slice (mpeg2_decoder_t * const decoder, const int code,
offset = decoder->offset;
dest_y = decoder->dest[0] + offset;
+
if (coded_block_pattern & 1)
slice_non_intra_DCT (decoder, 0, dest_y, DCT_stride);
+
if (coded_block_pattern & 2)
slice_non_intra_DCT (decoder, 0, dest_y + 8,
DCT_stride);
+
if (coded_block_pattern & 4)
slice_non_intra_DCT (decoder, 0, dest_y + DCT_offset,
DCT_stride);
+
if (coded_block_pattern & 8)
slice_non_intra_DCT (decoder, 0,
dest_y + DCT_offset + 8,
@@ -1927,23 +2210,29 @@ void mpeg2_slice (mpeg2_decoder_t * const decoder, const int code,
DCT_stride >>= 1;
DCT_offset = (DCT_offset + offset) >> 1;
+
if (coded_block_pattern & 16)
slice_non_intra_DCT (decoder, 1,
decoder->dest[1] + (offset >> 1),
DCT_stride);
+
if (coded_block_pattern & 32)
slice_non_intra_DCT (decoder, 2,
decoder->dest[2] + (offset >> 1),
DCT_stride);
+
if (coded_block_pattern & (2 << 30))
slice_non_intra_DCT (decoder, 1,
decoder->dest[1] + DCT_offset,
DCT_stride);
+
if (coded_block_pattern & (1 << 30))
slice_non_intra_DCT (decoder, 2,
decoder->dest[2] + DCT_offset,
DCT_stride);
- } else {
+ }
+ else
+ {
int offset;
uint8_t * dest_y, * dest_u, * dest_v;
@@ -1957,12 +2246,15 @@ void mpeg2_slice (mpeg2_decoder_t * const decoder, const int code,
if (coded_block_pattern & 1)
slice_non_intra_DCT (decoder, 0, dest_y, DCT_stride);
+
if (coded_block_pattern & 2)
slice_non_intra_DCT (decoder, 0, dest_y + 8,
DCT_stride);
+
if (coded_block_pattern & 4)
slice_non_intra_DCT (decoder, 0, dest_y + DCT_offset,
DCT_stride);
+
if (coded_block_pattern & 8)
slice_non_intra_DCT (decoder, 0,
dest_y + DCT_offset + 8,
@@ -1970,24 +2262,31 @@ void mpeg2_slice (mpeg2_decoder_t * const decoder, const int code,
if (coded_block_pattern & 16)
slice_non_intra_DCT (decoder, 1, dest_u, DCT_stride);
+
if (coded_block_pattern & 32)
slice_non_intra_DCT (decoder, 2, dest_v, DCT_stride);
+
if (coded_block_pattern & (32 << 26))
slice_non_intra_DCT (decoder, 1, dest_u + DCT_offset,
DCT_stride);
+
if (coded_block_pattern & (16 << 26))
slice_non_intra_DCT (decoder, 2, dest_v + DCT_offset,
DCT_stride);
+
if (coded_block_pattern & (8 << 26))
slice_non_intra_DCT (decoder, 1, dest_u + 8,
DCT_stride);
+
if (coded_block_pattern & (4 << 26))
slice_non_intra_DCT (decoder, 2, dest_v + 8,
DCT_stride);
+
if (coded_block_pattern & (2 << 26))
slice_non_intra_DCT (decoder, 1,
dest_u + DCT_offset + 8,
DCT_stride);
+
if (coded_block_pattern & (1 << 26))
slice_non_intra_DCT (decoder, 2,
dest_v + DCT_offset + 8,
@@ -2003,46 +2302,66 @@ void mpeg2_slice (mpeg2_decoder_t * const decoder, const int code,
NEEDBITS (bit_buf, bits, bit_ptr);
mba_inc = 0;
- while (1) {
- if (bit_buf >= 0x10000000) {
+
+ while (1)
+ {
+ if (bit_buf >= 0x10000000)
+ {
mba = MBA_5 + (UBITS (bit_buf, 5) - 2);
break;
- } else if (bit_buf >= 0x03000000) {
+ }
+ else if (bit_buf >= 0x03000000)
+ {
mba = MBA_11 + (UBITS (bit_buf, 11) - 24);
break;
- } else switch (UBITS (bit_buf, 11)) {
- case 8: /* macroblock_escape */
- mba_inc += 33;
- /* pass through */
- case 15: /* macroblock_stuffing (MPEG1 only) */
- DUMPBITS (bit_buf, bits, 11);
- NEEDBITS (bit_buf, bits, bit_ptr);
- continue;
- default: /* end of slice, or error */
- return;
+ }
+ else
+ {
+ switch (UBITS (bit_buf, 11))
+ {
+ case 8: /* macroblock_escape */
+ mba_inc += 33;
+ /* pass through */
+ case 15: /* macroblock_stuffing (MPEG1 only) */
+ DUMPBITS (bit_buf, bits, 11);
+ NEEDBITS (bit_buf, bits, bit_ptr);
+ continue;
+ default: /* end of slice, or error */
+ return;
+ }
}
}
+
DUMPBITS (bit_buf, bits, mba->len);
mba_inc += mba->mba;
- if (mba_inc) {
+ if (mba_inc)
+ {
decoder->dc_dct_pred[0] = decoder->dc_dct_pred[1] =
decoder->dc_dct_pred[2] = 16384;
- if (decoder->coding_type == P_TYPE) {
- do {
+ if (decoder->coding_type == P_TYPE)
+ {
+ do
+ {
MOTION_CALL (decoder->motion_parser[0],
MACROBLOCK_MOTION_FORWARD);
NEXT_MACROBLOCK;
- } while (--mba_inc);
- } else {
- do {
+ }
+ while (--mba_inc);
+ }
+ else
+ {
+ do
+ {
MOTION_CALL (decoder->motion_parser[4], macroblock_modes);
NEXT_MACROBLOCK;
- } while (--mba_inc);
+ }
+ while (--mba_inc);
}
}
}
+
#undef bit_buf
#undef bits
#undef bit_ptr
diff --git a/apps/plugins/mpegplayer/vlc.h b/apps/plugins/mpegplayer/vlc.h
index dbef8f8..90245cc 100644
--- a/apps/plugins/mpegplayer/vlc.h
+++ b/apps/plugins/mpegplayer/vlc.h
@@ -21,35 +21,35 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#define GETWORD(bit_buf,shift,bit_ptr) \
-do { \
- bit_buf |= ((bit_ptr[0] << 8) | bit_ptr[1]) << (shift); \
- bit_ptr += 2; \
+#define GETWORD(bit_buf, shift, bit_ptr) \
+do { \
+ bit_buf |= ((bit_ptr[0] << 8) | bit_ptr[1]) << (shift); \
+ bit_ptr += 2; \
} while (0)
static inline void bitstream_init (mpeg2_decoder_t * decoder,
- const uint8_t * start)
+ const uint8_t * start)
{
decoder->bitstream_buf =
- (start[0] << 24) | (start[1] << 16) | (start[2] << 8) | start[3];
+ (start[0] << 24) | (start[1] << 16) | (start[2] << 8) | start[3];
decoder->bitstream_ptr = start + 4;
decoder->bitstream_bits = -16;
}
/* make sure that there are at least 16 valid bits in bit_buf */
-#define NEEDBITS(bit_buf,bits,bit_ptr) \
-do { \
- if (unlikely (bits > 0)) { \
- GETWORD (bit_buf, bits, bit_ptr); \
- bits -= 16; \
- } \
+#define NEEDBITS(bit_buf, bits, bit_ptr) \
+do { \
+ if (unlikely (bits > 0)) { \
+ GETWORD (bit_buf, bits, bit_ptr); \
+ bits -= 16; \
+ } \
} while (0)
/* remove num valid bits from bit_buf */
-#define DUMPBITS(bit_buf,bits,num) \
-do { \
- bit_buf <<= (num); \
- bits += (num); \
+#define DUMPBITS(bit_buf, bits, num) \
+do { \
+ bit_buf <<= (num); \
+ bits += (num); \
} while (0)
/* take num bits from the high part of bit_buf and zero extend them */
@@ -124,7 +124,7 @@ static const MBtab MB_B [] ICONST_ATTR = {
{0, 0}, {INTRA|QUANT, 6},
{BWD|CODED|QUANT, 6}, {FWD|CODED|QUANT, 6},
{INTER|CODED|QUANT, 5}, {INTER|CODED|QUANT, 5},
- {INTRA, 5}, {INTRA, 5},
+ {INTRA, 5}, {INTRA, 5},
{FWD, 4}, {FWD, 4}, {FWD, 4}, {FWD, 4},
{FWD|CODED, 4}, {FWD|CODED, 4}, {FWD|CODED, 4}, {FWD|CODED, 4},
{BWD, 3}, {BWD, 3}, {BWD, 3}, {BWD, 3},
@@ -301,7 +301,7 @@ static const DCTtab DCT_B14_8 [] ICONST_ATTR = {
};
static const DCTtab DCT_B14AC_5 [] ICONST_ATTR = {
- { 1, 3, 5}, { 5, 1, 5}, { 4, 1, 5},
+ { 1, 3, 5}, { 5, 1, 5}, { 4, 1, 5},
{ 1, 2, 4}, { 1, 2, 4}, { 3, 1, 4}, { 3, 1, 4},
{ 2, 1, 3}, { 2, 1, 3}, { 2, 1, 3}, { 2, 1, 3},
{129, 0, 2}, {129, 0, 2}, {129, 0, 2}, {129, 0, 2},
@@ -311,7 +311,7 @@ static const DCTtab DCT_B14AC_5 [] ICONST_ATTR = {
};
static const DCTtab DCT_B14DC_5 [] ICONST_ATTR = {
- { 1, 3, 5}, { 5, 1, 5}, { 4, 1, 5},
+ { 1, 3, 5}, { 5, 1, 5}, { 4, 1, 5},
{ 1, 2, 4}, { 1, 2, 4}, { 3, 1, 4}, { 3, 1, 4},
{ 2, 1, 3}, { 2, 1, 3}, { 2, 1, 3}, { 2, 1, 3},
{ 1, 1, 1}, { 1, 1, 1}, { 1, 1, 1}, { 1, 1, 1},
@@ -393,7 +393,7 @@ static const DCTtab DCT_B15_8 [] ICONST_ATTR = {
static const MBAtab MBA_5 [] ICONST_ATTR = {
- {6, 5}, {5, 5}, {4, 4}, {4, 4}, {3, 4}, {3, 4},
+ {6, 5}, {5, 5}, {4, 4}, {4, 4}, {3, 4}, {3, 4},
{2, 3}, {2, 3}, {2, 3}, {2, 3}, {1, 3}, {1, 3}, {1, 3}, {1, 3},
{0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1},
{0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1}, {0, 1}