2001-02-24 20:28:24 +00:00
|
|
|
/*
|
|
|
|
* mpeg2_internal.h
|
2004-08-02 11:26:43 +00:00
|
|
|
* Copyright (C) 2000-2003 Michel Lespinasse <walken@zoy.org>
|
2003-04-06 16:36:02 +00:00
|
|
|
* Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
|
2001-02-24 20:28:24 +00:00
|
|
|
*
|
|
|
|
* This file is part of mpeg2dec, a free MPEG-2 video stream decoder.
|
2003-04-06 16:36:02 +00:00
|
|
|
* See http://libmpeg2.sourceforge.net/ for updates.
|
2001-02-24 20:28:24 +00:00
|
|
|
*
|
|
|
|
* mpeg2dec is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* mpeg2dec is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* 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
|
2005-02-19 02:32:12 +00:00
|
|
|
*
|
2006-12-09 10:34:27 +00:00
|
|
|
* Modified for use with MPlayer, see libmpeg-0.4.1.diff for the exact changes.
|
2006-06-22 13:34:00 +00:00
|
|
|
* detailed changelog at http://svn.mplayerhq.hu/mplayer/trunk/
|
2005-02-19 02:32:12 +00:00
|
|
|
* $Id$
|
2001-02-24 20:28:24 +00:00
|
|
|
*/
|
|
|
|
|
2001-03-04 21:01:54 +00:00
|
|
|
/* macroblock modes */
|
2001-02-24 20:28:24 +00:00
|
|
|
#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
|
2001-03-04 21:01:54 +00:00
|
|
|
/* motion_type */
|
2004-08-02 11:26:43 +00:00
|
|
|
#define MOTION_TYPE_SHIFT 6
|
|
|
|
#define MC_FIELD 1
|
|
|
|
#define MC_FRAME 2
|
|
|
|
#define MC_16X8 2
|
|
|
|
#define MC_DMV 3
|
2001-02-24 20:28:24 +00:00
|
|
|
|
2001-03-04 21:01:54 +00:00
|
|
|
/* picture structure */
|
2001-02-24 20:28:24 +00:00
|
|
|
#define TOP_FIELD 1
|
|
|
|
#define BOTTOM_FIELD 2
|
|
|
|
#define FRAME_PICTURE 3
|
|
|
|
|
2001-03-04 21:01:54 +00:00
|
|
|
/* picture coding type */
|
2001-02-24 20:28:24 +00:00
|
|
|
#define I_TYPE 1
|
|
|
|
#define P_TYPE 2
|
|
|
|
#define B_TYPE 3
|
|
|
|
#define D_TYPE 4
|
|
|
|
|
2004-08-02 11:26:43 +00:00
|
|
|
typedef void mpeg2_mc_fct (uint8_t *, const uint8_t *, int, int);
|
|
|
|
|
2003-04-06 16:36:02 +00:00
|
|
|
typedef struct {
|
2001-03-04 21:01:54 +00:00
|
|
|
uint8_t * ref[2][3];
|
2003-04-06 16:36:02 +00:00
|
|
|
uint8_t ** ref2[2];
|
2001-03-04 21:01:54 +00:00
|
|
|
int pmv[2][2];
|
|
|
|
int f_code[2];
|
|
|
|
} motion_t;
|
|
|
|
|
2004-08-02 11:26:43 +00:00
|
|
|
typedef void motion_parser_t (mpeg2_decoder_t * decoder,
|
|
|
|
motion_t * motion,
|
|
|
|
mpeg2_mc_fct * const * table);
|
|
|
|
|
|
|
|
struct mpeg2_decoder_s {
|
2001-03-04 21:01:54 +00:00
|
|
|
/* first, state that carries information from one macroblock to the */
|
2003-04-06 16:36:02 +00:00
|
|
|
/* next inside a slice, and is never used outside of mpeg2_slice() */
|
2001-03-04 21:01:54 +00:00
|
|
|
|
|
|
|
/* bit parsing stuff */
|
2003-04-06 16:36:02 +00:00
|
|
|
uint32_t bitstream_buf; /* current 32 bit working set */
|
|
|
|
int bitstream_bits; /* used bits in working set */
|
|
|
|
const uint8_t * bitstream_ptr; /* buffer with stream data */
|
|
|
|
|
|
|
|
uint8_t * dest[3];
|
|
|
|
|
|
|
|
int offset;
|
|
|
|
int stride;
|
|
|
|
int uv_stride;
|
2004-08-02 11:26:43 +00:00
|
|
|
int slice_stride;
|
|
|
|
int slice_uv_stride;
|
|
|
|
int stride_frame;
|
2003-04-06 16:36:02 +00:00
|
|
|
unsigned int limit_x;
|
|
|
|
unsigned int limit_y_16;
|
|
|
|
unsigned int limit_y_8;
|
|
|
|
unsigned int limit_y;
|
2001-03-04 21:01:54 +00:00
|
|
|
|
|
|
|
/* Motion vectors */
|
|
|
|
/* The f_ and b_ correspond to the forward and backward motion */
|
|
|
|
/* predictors */
|
|
|
|
motion_t b_motion;
|
|
|
|
motion_t f_motion;
|
2004-08-02 11:26:43 +00:00
|
|
|
motion_parser_t * motion_parser[5];
|
2001-03-04 21:01:54 +00:00
|
|
|
|
|
|
|
/* predictor for DC coefficients in intra blocks */
|
|
|
|
int16_t dc_dct_pred[3];
|
|
|
|
|
2004-08-02 11:26:43 +00:00
|
|
|
/* DCT coefficients */
|
|
|
|
int16_t DCTblock[64] ATTR_ALIGN(64);
|
|
|
|
|
|
|
|
uint8_t * picture_dest[3];
|
|
|
|
void (* convert) (void * convert_id, uint8_t * const * src,
|
|
|
|
unsigned int v_offset);
|
|
|
|
void * convert_id;
|
|
|
|
|
|
|
|
int dmv_offset;
|
|
|
|
unsigned int v_offset;
|
2001-03-04 21:01:54 +00:00
|
|
|
|
|
|
|
/* now non-slice-specific information */
|
|
|
|
|
|
|
|
/* sequence header stuff */
|
2004-08-02 11:26:43 +00:00
|
|
|
uint16_t * quantizer_matrix[4];
|
|
|
|
uint16_t (* chroma_quantizer[2])[64];
|
|
|
|
uint16_t quantizer_prescale[4][32][64];
|
2001-02-24 20:28:24 +00:00
|
|
|
|
2001-03-04 21:01:54 +00:00
|
|
|
/* The width and height of the picture snapped to macroblock units */
|
2003-04-06 16:36:02 +00:00
|
|
|
int width;
|
|
|
|
int height;
|
|
|
|
int vertical_position_extension;
|
2004-08-02 11:26:43 +00:00
|
|
|
int chroma_format;
|
2001-02-24 20:28:24 +00:00
|
|
|
|
2001-03-04 21:01:54 +00:00
|
|
|
/* picture header stuff */
|
2001-02-24 20:28:24 +00:00
|
|
|
|
2001-03-04 21:01:54 +00:00
|
|
|
/* what type of picture this is (I, P, B, D) */
|
2003-04-06 16:36:02 +00:00
|
|
|
int coding_type;
|
|
|
|
|
2001-03-04 21:01:54 +00:00
|
|
|
/* picture coding extension stuff */
|
2003-04-06 16:36:02 +00:00
|
|
|
|
2001-03-04 21:01:54 +00:00
|
|
|
/* quantization factor for intra dc coefficients */
|
2001-02-24 20:28:24 +00:00
|
|
|
int intra_dc_precision;
|
2001-03-04 21:01:54 +00:00
|
|
|
/* top/bottom/both fields */
|
2001-02-24 20:28:24 +00:00
|
|
|
int picture_structure;
|
2001-03-04 21:01:54 +00:00
|
|
|
/* bool to indicate all predictions are frame based */
|
2001-02-24 20:28:24 +00:00
|
|
|
int frame_pred_frame_dct;
|
2001-03-04 21:01:54 +00:00
|
|
|
/* bool to indicate whether intra blocks have motion vectors */
|
|
|
|
/* (for concealment) */
|
2001-02-24 20:28:24 +00:00
|
|
|
int concealment_motion_vectors;
|
2001-03-04 21:01:54 +00:00
|
|
|
/* bool to use different vlc tables */
|
2001-02-24 20:28:24 +00:00
|
|
|
int intra_vlc_format;
|
2001-03-04 21:01:54 +00:00
|
|
|
/* used for DMV MC */
|
|
|
|
int top_field_first;
|
2001-02-24 20:28:24 +00:00
|
|
|
|
2001-03-04 21:01:54 +00:00
|
|
|
/* stuff derived from bitstream */
|
2001-02-24 20:28:24 +00:00
|
|
|
|
2001-03-04 21:01:54 +00:00
|
|
|
/* pointer to the zigzag scan we're supposed to be using */
|
2003-04-06 16:36:02 +00:00
|
|
|
const uint8_t * scan;
|
2001-02-24 20:28:24 +00:00
|
|
|
|
|
|
|
int second_field;
|
|
|
|
|
2001-03-04 21:01:54 +00:00
|
|
|
int mpeg1;
|
2004-08-02 13:09:17 +00:00
|
|
|
|
|
|
|
/* for MPlayer: */
|
2004-08-24 20:23:11 +00:00
|
|
|
int quantizer_scales[32];
|
2004-08-02 13:09:17 +00:00
|
|
|
int quantizer_scale;
|
|
|
|
char* quant_store;
|
|
|
|
int quant_stride;
|
2003-04-06 16:36:02 +00:00
|
|
|
};
|
2001-02-24 20:28:24 +00:00
|
|
|
|
2003-04-06 16:36:02 +00:00
|
|
|
typedef struct {
|
2004-08-02 11:26:43 +00:00
|
|
|
mpeg2_fbuf_t fbuf;
|
2003-04-06 16:36:02 +00:00
|
|
|
} fbuf_alloc_t;
|
|
|
|
|
|
|
|
struct mpeg2dec_s {
|
2004-08-02 11:26:43 +00:00
|
|
|
mpeg2_decoder_t decoder;
|
2003-04-06 16:36:02 +00:00
|
|
|
|
|
|
|
mpeg2_info_t info;
|
|
|
|
|
|
|
|
uint32_t shift;
|
|
|
|
int is_display_initialized;
|
2004-08-02 11:26:43 +00:00
|
|
|
mpeg2_state_t (* action) (struct mpeg2dec_s * mpeg2dec);
|
|
|
|
mpeg2_state_t state;
|
2003-04-06 16:36:02 +00:00
|
|
|
uint32_t ext_state;
|
|
|
|
|
|
|
|
/* allocated in init - gcc has problems allocating such big structures */
|
|
|
|
uint8_t * chunk_buffer;
|
|
|
|
/* pointer to start of the current chunk */
|
|
|
|
uint8_t * chunk_start;
|
|
|
|
/* pointer to current position in chunk_buffer */
|
|
|
|
uint8_t * chunk_ptr;
|
|
|
|
/* last start code ? */
|
|
|
|
uint8_t code;
|
|
|
|
|
2004-08-02 11:26:43 +00:00
|
|
|
/* picture tags */
|
|
|
|
uint32_t tag_current, tag2_current, tag_previous, tag2_previous;
|
|
|
|
int num_tags;
|
|
|
|
int bytes_since_tag;
|
2003-04-06 16:36:02 +00:00
|
|
|
|
|
|
|
int first;
|
|
|
|
int alloc_index_user;
|
|
|
|
int alloc_index;
|
|
|
|
uint8_t first_decode_slice;
|
|
|
|
uint8_t nb_decode_slices;
|
|
|
|
|
2004-08-02 11:26:43 +00:00
|
|
|
unsigned int user_data_len;
|
|
|
|
|
|
|
|
mpeg2_sequence_t new_sequence;
|
|
|
|
mpeg2_sequence_t sequence;
|
|
|
|
mpeg2_gop_t new_gop;
|
|
|
|
mpeg2_gop_t gop;
|
|
|
|
mpeg2_picture_t new_picture;
|
|
|
|
mpeg2_picture_t pictures[4];
|
|
|
|
mpeg2_picture_t * picture;
|
|
|
|
/*const*/ mpeg2_fbuf_t * fbuf[3]; /* 0: current fbuf, 1-2: prediction fbufs */
|
2003-04-06 16:36:02 +00:00
|
|
|
|
|
|
|
fbuf_alloc_t fbuf_alloc[3];
|
|
|
|
int custom_fbuf;
|
|
|
|
|
|
|
|
uint8_t * yuv_buf[3][3];
|
|
|
|
int yuv_index;
|
2004-08-02 11:26:43 +00:00
|
|
|
mpeg2_convert_t * convert;
|
|
|
|
void * convert_arg;
|
|
|
|
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);
|
2003-04-06 16:36:02 +00:00
|
|
|
|
|
|
|
uint8_t * buf_start;
|
|
|
|
uint8_t * buf_end;
|
|
|
|
|
|
|
|
int16_t display_offset_x, display_offset_y;
|
2004-08-02 11:26:43 +00:00
|
|
|
|
|
|
|
int copy_matrix;
|
|
|
|
int8_t q_scale_type, scaled[4];
|
|
|
|
uint8_t quantizer_matrix[4][64];
|
|
|
|
uint8_t new_quantizer_matrix[4][64];
|
2004-08-24 16:15:56 +00:00
|
|
|
|
|
|
|
/* for MPlayer: */
|
|
|
|
unsigned char *pending_buffer;
|
|
|
|
int pending_length;
|
2003-04-06 16:36:02 +00:00
|
|
|
};
|
2001-02-24 20:28:24 +00:00
|
|
|
|
2003-04-06 16:36:02 +00:00
|
|
|
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 */
|
2004-08-02 11:26:43 +00:00
|
|
|
mpeg2_state_t mpeg2_seek_header (mpeg2dec_t * mpeg2dec);
|
|
|
|
mpeg2_state_t mpeg2_parse_header (mpeg2dec_t * mpeg2dec);
|
2003-04-06 16:36:02 +00:00
|
|
|
|
|
|
|
/* header.c */
|
|
|
|
void mpeg2_header_state_init (mpeg2dec_t * mpeg2dec);
|
2004-08-02 11:26:43 +00:00
|
|
|
void mpeg2_reset_info (mpeg2_info_t * info);
|
2003-04-06 16:36:02 +00:00
|
|
|
int mpeg2_header_sequence (mpeg2dec_t * mpeg2dec);
|
|
|
|
int mpeg2_header_gop (mpeg2dec_t * mpeg2dec);
|
2004-08-02 11:26:43 +00:00
|
|
|
mpeg2_state_t mpeg2_header_picture_start (mpeg2dec_t * mpeg2dec);
|
2003-04-06 16:36:02 +00:00
|
|
|
int mpeg2_header_picture (mpeg2dec_t * mpeg2dec);
|
|
|
|
int mpeg2_header_extension (mpeg2dec_t * mpeg2dec);
|
|
|
|
int mpeg2_header_user_data (mpeg2dec_t * mpeg2dec);
|
|
|
|
void mpeg2_header_sequence_finalize (mpeg2dec_t * mpeg2dec);
|
2004-08-02 11:26:43 +00:00
|
|
|
void mpeg2_header_gop_finalize (mpeg2dec_t * mpeg2dec);
|
|
|
|
void mpeg2_header_picture_finalize (mpeg2dec_t * mpeg2dec, uint32_t accels);
|
|
|
|
mpeg2_state_t mpeg2_header_slice_start (mpeg2dec_t * mpeg2dec);
|
|
|
|
mpeg2_state_t mpeg2_header_end (mpeg2dec_t * mpeg2dec);
|
|
|
|
void mpeg2_set_fbuf (mpeg2dec_t * mpeg2dec, int b_type);
|
2001-02-24 20:28:24 +00:00
|
|
|
|
2001-03-04 21:01:54 +00:00
|
|
|
/* idct.c */
|
2003-04-06 16:36:02 +00:00
|
|
|
void mpeg2_idct_init (uint32_t accel);
|
2001-02-24 20:28:24 +00:00
|
|
|
|
2001-03-04 21:01:54 +00:00
|
|
|
/* idct_mmx.c */
|
2003-04-06 16:36:02 +00:00
|
|
|
void mpeg2_idct_copy_mmxext (int16_t * block, uint8_t * dest, int stride);
|
|
|
|
void mpeg2_idct_add_mmxext (int last, int16_t * block,
|
|
|
|
uint8_t * dest, int stride);
|
|
|
|
void mpeg2_idct_copy_mmx (int16_t * block, uint8_t * dest, int stride);
|
|
|
|
void mpeg2_idct_add_mmx (int last, int16_t * block,
|
|
|
|
uint8_t * dest, int stride);
|
|
|
|
void mpeg2_idct_mmx_init (void);
|
|
|
|
|
|
|
|
/* idct_altivec.c */
|
|
|
|
void mpeg2_idct_copy_altivec (int16_t * block, uint8_t * dest, int stride);
|
|
|
|
void mpeg2_idct_add_altivec (int last, int16_t * block,
|
|
|
|
uint8_t * dest, int stride);
|
|
|
|
void mpeg2_idct_altivec_init (void);
|
|
|
|
|
|
|
|
/* idct_alpha.c */
|
|
|
|
void mpeg2_idct_copy_mvi (int16_t * block, uint8_t * dest, int stride);
|
|
|
|
void mpeg2_idct_add_mvi (int last, int16_t * block,
|
|
|
|
uint8_t * dest, int stride);
|
|
|
|
void mpeg2_idct_copy_alpha (int16_t * block, uint8_t * dest, int stride);
|
|
|
|
void mpeg2_idct_add_alpha (int last, int16_t * block,
|
|
|
|
uint8_t * dest, int stride);
|
2004-08-02 11:26:43 +00:00
|
|
|
void mpeg2_idct_alpha_init (void);
|
2001-02-24 20:28:24 +00:00
|
|
|
|
2001-03-04 21:01:54 +00:00
|
|
|
/* motion_comp.c */
|
2003-04-06 16:36:02 +00:00
|
|
|
void mpeg2_mc_init (uint32_t accel);
|
2001-02-24 20:28:24 +00:00
|
|
|
|
2003-04-06 16:36:02 +00:00
|
|
|
typedef struct {
|
|
|
|
mpeg2_mc_fct * put [8];
|
|
|
|
mpeg2_mc_fct * avg [8];
|
|
|
|
} mpeg2_mc_t;
|
2001-07-08 00:21:20 +00:00
|
|
|
|
2003-04-06 16:36:02 +00:00
|
|
|
#define MPEG2_MC_EXTERN(x) mpeg2_mc_t mpeg2_mc_##x = { \
|
|
|
|
{MC_put_o_16_##x, MC_put_x_16_##x, MC_put_y_16_##x, MC_put_xy_16_##x, \
|
|
|
|
MC_put_o_8_##x, MC_put_x_8_##x, MC_put_y_8_##x, MC_put_xy_8_##x}, \
|
|
|
|
{MC_avg_o_16_##x, MC_avg_x_16_##x, MC_avg_y_16_##x, MC_avg_xy_16_##x, \
|
|
|
|
MC_avg_o_8_##x, MC_avg_x_8_##x, MC_avg_y_8_##x, MC_avg_xy_8_##x} \
|
|
|
|
};
|
2001-07-08 00:21:20 +00:00
|
|
|
|
2003-04-06 16:36:02 +00:00
|
|
|
extern mpeg2_mc_t mpeg2_mc_c;
|
|
|
|
extern mpeg2_mc_t mpeg2_mc_mmx;
|
|
|
|
extern mpeg2_mc_t mpeg2_mc_mmxext;
|
|
|
|
extern mpeg2_mc_t mpeg2_mc_3dnow;
|
|
|
|
extern mpeg2_mc_t mpeg2_mc_altivec;
|
|
|
|
extern mpeg2_mc_t mpeg2_mc_alpha;
|
2004-08-02 11:26:43 +00:00
|
|
|
extern mpeg2_mc_t mpeg2_mc_vis;
|