A modern Music Player Daemon based on Rockbox open source high quality audio player
libadwaita audio rust zig deno mpris rockbox mpd
at master 274 lines 7.8 kB view raw
1/* 2 * mpeg2_internal.h 3 * Copyright (C) 2000-2003 Michel Lespinasse <walken@zoy.org> 4 * Copyright (C) 1999-2000 Aaron Holtzman <aholtzma@ess.engr.uvic.ca> 5 * 6 * This file is part of mpeg2dec, a free MPEG-2 video stream decoder. 7 * See http://libmpeg2.sourceforge.net/ for updates. 8 * 9 * mpeg2dec is free software; you can redistribute it and/or modify 10 * it under the terms of the GNU General Public License as published by 11 * the Free Software Foundation; either version 2 of the License, or 12 * (at your option) any later version. 13 * 14 * mpeg2dec is distributed in the hope that it will be useful, 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 * GNU General Public License for more details. 18 * 19 * You should have received a copy of the GNU General Public License 20 * along with this program; if not, write to the Free Software 21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 * 23 * $Id$ 24 * libmpeg2 sync history: 25 * 2008-07-01 - CVS revision 1.89 26 */ 27#ifndef MPEG2_INTERNAL_H 28#define MPEG2_INTERNAL_H 29 30#include "config.h" /* for Rockbox CPU_ #defines */ 31 32/* macroblock modes */ 33#define MACROBLOCK_INTRA 1 34#define MACROBLOCK_PATTERN 2 35#define MACROBLOCK_MOTION_BACKWARD 4 36#define MACROBLOCK_MOTION_FORWARD 8 37#define MACROBLOCK_QUANT 16 38#define DCT_TYPE_INTERLACED 32 39/* motion_type */ 40#define MOTION_TYPE_SHIFT 6 41#define MC_FIELD 1 42#define MC_FRAME 2 43#define MC_16X8 2 44#define MC_DMV 3 45 46/* picture structure */ 47#define TOP_FIELD 1 48#define BOTTOM_FIELD 2 49#define FRAME_PICTURE 3 50 51/* picture coding type */ 52#define I_TYPE 1 53#define P_TYPE 2 54#define B_TYPE 3 55#define D_TYPE 4 56 57typedef void mpeg2_mc_fct (uint8_t *, const uint8_t *, int, int); 58 59typedef struct 60{ 61 uint8_t * ref[2][MPEG2_COMPONENTS]; 62 uint8_t ** ref2[2]; 63 int pmv[2][2]; 64 int f_code[2]; 65} motion_t; 66 67typedef void motion_parser_t(mpeg2_decoder_t * decoder, 68 motion_t * motion, 69 mpeg2_mc_fct * const * table); 70 71struct mpeg2_decoder_s 72{ 73 /* first, state that carries information from one macroblock to the */ 74 /* next inside a slice, and is never used outside of mpeg2_slice() */ 75 76 /* bit parsing stuff */ 77 uint32_t bitstream_buf; /* current 32 bit working set */ 78 int bitstream_bits; /* used bits in working set */ 79 const uint8_t * bitstream_ptr; /* buffer with stream data */ 80 81 uint8_t * dest[MPEG2_COMPONENTS]; 82 83 int offset; 84 int stride; 85 int uv_stride; 86 int slice_stride; 87 int slice_uv_stride; 88 int stride_frame; 89 unsigned int limit_x; 90 unsigned int limit_y_16; 91 unsigned int limit_y_8; 92 unsigned int limit_y; 93 94 /* Motion vectors */ 95 /* The f_ and b_ correspond to the forward and backward motion */ 96 /* predictors */ 97 motion_t b_motion; 98 motion_t f_motion; 99 motion_parser_t * motion_parser[5]; 100 101 /* predictor for DC coefficients in intra blocks */ 102 int16_t dc_dct_pred[MPEG2_COMPONENTS]; 103 104 /* DCT coefficients */ 105 int16_t * DCTblock; /* put buffer separately to have it in IRAM */ 106 107 uint8_t * picture_dest[MPEG2_COMPONENTS]; 108 void (* convert) (void * convert_id, uint8_t * const * src, 109 unsigned int v_offset); 110 void * convert_id; 111 112 int dmv_offset; 113 unsigned int v_offset; 114 115 /* now non-slice-specific information */ 116 117 /* sequence header stuff */ 118 uint16_t * quantizer_matrix[4]; 119 uint16_t (* chroma_quantizer[2])[64]; 120 uint16_t quantizer_prescale[4][32][64]; 121 122 /* The width and height of the picture snapped to macroblock units */ 123 int width; 124 int height; 125 int vertical_position_extension; 126 int chroma_format; 127 128 /* picture header stuff */ 129 130 /* what type of picture this is (I, P, B, D) */ 131 int coding_type; 132 133 /* picture coding extension stuff */ 134 135 /* quantization factor for intra dc coefficients */ 136 int intra_dc_precision; 137 /* top/bottom/both fields */ 138 int picture_structure; 139 /* bool to indicate all predictions are frame based */ 140 int frame_pred_frame_dct; 141 /* bool to indicate whether intra blocks have motion vectors */ 142 /* (for concealment) */ 143 int concealment_motion_vectors; 144 /* bool to use different vlc tables */ 145 int intra_vlc_format; 146 /* used for DMV MC */ 147 int top_field_first; 148 149 /* stuff derived from bitstream */ 150 151 /* pointer to the zigzag scan we're supposed to be using */ 152 const uint8_t * scan; 153 154 int second_field; 155 156 int mpeg1; 157}; 158 159typedef struct 160{ 161 mpeg2_fbuf_t fbuf; 162} fbuf_alloc_t; 163 164struct mpeg2dec_s 165{ 166 mpeg2_decoder_t decoder; 167 168 mpeg2_info_t info; 169 170 uint32_t shift; 171 int is_display_initialized; 172 mpeg2_state_t (* action) (struct mpeg2dec_s * mpeg2dec); 173 mpeg2_state_t state; 174 uint32_t ext_state; 175 176 /* allocated in init - gcc has problems allocating such big structures */ 177 uint8_t * ATTR_ALIGN(4) chunk_buffer; 178 /* pointer to start of the current chunk */ 179 uint8_t * chunk_start; 180 /* pointer to current position in chunk_buffer */ 181 uint8_t * chunk_ptr; 182 /* last start code ? */ 183 uint8_t code; 184 185 /* picture tags */ 186 uint32_t tag_current, tag2_current, tag_previous, tag2_previous; 187 int num_tags; 188 int bytes_since_tag; 189 190 int first; 191 int alloc_index_user; 192 int alloc_index; 193 uint8_t first_decode_slice; 194 uint8_t nb_decode_slices; 195 196 unsigned int user_data_len; 197 198 mpeg2_sequence_t new_sequence; 199 mpeg2_sequence_t sequence; 200 mpeg2_gop_t new_gop; 201 mpeg2_gop_t gop; 202 mpeg2_picture_t new_picture; 203 mpeg2_picture_t pictures[4]; 204 mpeg2_picture_t * picture; 205 /*const*/ mpeg2_fbuf_t * fbuf[3]; /* 0: current fbuf, 1-2: prediction fbufs */ 206 207 fbuf_alloc_t fbuf_alloc[3]; 208 int custom_fbuf; 209 210 uint8_t * yuv_buf[3][MPEG2_COMPONENTS]; 211 int yuv_index; 212 mpeg2_convert_t * convert; 213 void * convert_arg; 214 unsigned int convert_id_size; 215 int convert_stride; 216 void (* convert_start) (void * id, const mpeg2_fbuf_t * fbuf, 217 const mpeg2_picture_t * picture, 218 const mpeg2_gop_t * gop); 219 220 uint8_t * buf_start; 221 uint8_t * buf_end; 222 223 int16_t display_offset_x, display_offset_y; 224 225 int copy_matrix; 226 int8_t q_scale_type, scaled[4]; 227 uint8_t quantizer_matrix[4][64]; 228 uint8_t new_quantizer_matrix[4][64]; 229}; 230 231/* decode.c */ 232mpeg2_state_t mpeg2_seek_header (mpeg2dec_t * mpeg2dec); 233mpeg2_state_t mpeg2_parse_header (mpeg2dec_t * mpeg2dec); 234 235/* header.c */ 236void mpeg2_header_state_init (mpeg2dec_t * mpeg2dec); 237void mpeg2_reset_info (mpeg2_info_t * info); 238int mpeg2_header_sequence (mpeg2dec_t * mpeg2dec); 239int mpeg2_header_gop (mpeg2dec_t * mpeg2dec); 240int mpeg2_header_picture (mpeg2dec_t * mpeg2dec); 241int mpeg2_header_extension (mpeg2dec_t * mpeg2dec); 242int mpeg2_header_user_data (mpeg2dec_t * mpeg2dec); 243void mpeg2_header_sequence_finalize (mpeg2dec_t * mpeg2dec); 244void mpeg2_header_gop_finalize (mpeg2dec_t * mpeg2dec); 245void mpeg2_header_picture_finalize (mpeg2dec_t * mpeg2dec); 246mpeg2_state_t mpeg2_header_slice_start (mpeg2dec_t * mpeg2dec); 247mpeg2_state_t mpeg2_header_end (mpeg2dec_t * mpeg2dec); 248void mpeg2_set_fbuf (mpeg2dec_t * mpeg2dec, int b_type); 249 250/* idct.c */ 251void mpeg2_idct_init (void); 252void mpeg2_idct_copy(int16_t * block, uint8_t * dest, 253 const int stride); 254void mpeg2_idct_add(const int last, int16_t * block, 255 uint8_t * dest, const int stride); 256 257extern const uint8_t default_mpeg2_scan_norm[64]; 258extern const uint8_t default_mpeg2_scan_alt[64]; 259extern uint8_t mpeg2_scan_norm[64]; 260extern uint8_t mpeg2_scan_alt[64]; 261 262/* motion_comp.c */ 263void mpeg2_mc_init (void); 264 265typedef struct 266{ 267 mpeg2_mc_fct * put [8]; 268 mpeg2_mc_fct * avg [8]; 269} mpeg2_mc_t; 270 271extern const mpeg2_mc_t mpeg2_mc; 272 273#endif /* MPEG2_INTERNAL_H */ 274