1 /* 2 * Copyright (C) 2017 Amlogic, Inc. All rights reserved. 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation; either version 2 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 12 * more details. 13 * 14 * You should have received a copy of the GNU General Public License along 15 * with this program; if not, write to the Free Software Foundation, Inc., 16 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 * 18 * Description: 19 */ 20 21 #ifndef AVCODEC_MPEG4VIDEO_H 22 #define AVCODEC_MPEG4VIDEO_H 23 24 #include "../aml_vcodec_drv.h" 25 #include "../utils/pixfmt.h" 26 #include "../utils/common.h" 27 28 //mpeg4 profile 29 #define FF_PROFILE_MPEG4_SIMPLE 0 30 #define FF_PROFILE_MPEG4_SIMPLE_SCALABLE 1 31 #define FF_PROFILE_MPEG4_CORE 2 32 #define FF_PROFILE_MPEG4_MAIN 3 33 #define FF_PROFILE_MPEG4_N_BIT 4 34 #define FF_PROFILE_MPEG4_SCALABLE_TEXTURE 5 35 #define FF_PROFILE_MPEG4_SIMPLE_FACE_ANIMATION 6 36 #define FF_PROFILE_MPEG4_BASIC_ANIMATED_TEXTURE 7 37 #define FF_PROFILE_MPEG4_HYBRID 8 38 #define FF_PROFILE_MPEG4_ADVANCED_REAL_TIME 9 39 #define FF_PROFILE_MPEG4_CORE_SCALABLE 10 40 #define FF_PROFILE_MPEG4_ADVANCED_CODING 11 41 #define FF_PROFILE_MPEG4_ADVANCED_CORE 12 42 #define FF_PROFILE_MPEG4_ADVANCED_SCALABLE_TEXTURE 13 43 #define FF_PROFILE_MPEG4_SIMPLE_STUDIO 14 44 #define FF_PROFILE_MPEG4_ADVANCED_SIMPLE 15 45 46 // shapes 47 #define RECT_SHAPE 0 48 #define BIN_SHAPE 1 49 #define BIN_ONLY_SHAPE 2 50 #define GRAY_SHAPE 3 51 52 #define SIMPLE_VO_TYPE 1 53 #define CORE_VO_TYPE 3 54 #define MAIN_VO_TYPE 4 55 #define NBIT_VO_TYPE 5 56 #define ARTS_VO_TYPE 10 57 #define ACE_VO_TYPE 12 58 #define SIMPLE_STUDIO_VO_TYPE 14 59 #define CORE_STUDIO_VO_TYPE 15 60 #define ADV_SIMPLE_VO_TYPE 17 61 62 #define VOT_VIDEO_ID 1 63 #define VOT_STILL_TEXTURE_ID 2 64 65 #define FF_PROFILE_UNKNOWN -99 66 #define FF_PROFILE_RESERVED -100 67 68 // aspect_ratio_info 69 #define EXTENDED_PAR 15 70 71 //vol_sprite_usage / sprite_enable 72 #define STATIC_SPRITE 1 73 #define GMC_SPRITE 2 74 75 #define MOTION_MARKER 0x1F001 76 #define DC_MARKER 0x6B001 77 78 #define VOS_STARTCODE 0x1B0 79 #define USER_DATA_STARTCODE 0x1B2 80 #define GOP_STARTCODE 0x1B3 81 #define VISUAL_OBJ_STARTCODE 0x1B5 82 #define VOP_STARTCODE 0x1B6 83 #define SLICE_STARTCODE 0x1B7 84 #define EXT_STARTCODE 0x1B8 85 86 #define QUANT_MATRIX_EXT_ID 0x3 87 88 /* smaller packets likely don't contain a real frame */ 89 #define MAX_NVOP_SIZE 19 90 91 #define IS_3IV1 0 92 93 #define CHROMA_420 1 94 #define CHROMA_422 2 95 #define CHROMA_444 3 96 97 #define FF_ASPECT_EXTENDED 15 98 99 #define AV_NOPTS_VALUE (LONG_MIN) 100 101 /** 102 * Return value for header parsers if frame is not coded. 103 * */ 104 #define FRAME_SKIPPED 100 105 106 enum AVPictureType { 107 AV_PICTURE_TYPE_NONE = 0, ///< Undefined 108 AV_PICTURE_TYPE_I, ///< Intra 109 AV_PICTURE_TYPE_P, ///< Predicted 110 AV_PICTURE_TYPE_B, ///< Bi-dir predicted 111 AV_PICTURE_TYPE_S, ///< S(GMC)-VOP MPEG-4 112 AV_PICTURE_TYPE_SI, ///< Switching Intra 113 AV_PICTURE_TYPE_SP, ///< Switching Predicted 114 AV_PICTURE_TYPE_BI, ///< BI type 115 }; 116 117 struct VLC { 118 int bits; 119 short (*table)[2]; ///< code, bits 120 int table_size, table_allocated; 121 }; 122 123 /** 124 * MpegEncContext. 125 */ 126 struct MpegEncContext { 127 struct mpeg4_dec_param *ctx; 128 129 /* the following parameters must be initialized before encoding */ 130 int width, height;///< picture size. must be a multiple of 16 131 int codec_tag; ///< internal codec_tag upper case converted from avctx codec_tag 132 int picture_number; //FIXME remove, unclear definition 133 134 /** matrix transmitted in the bitstream */ 135 u16 intra_matrix[64]; 136 u16 chroma_intra_matrix[64]; 137 u16 inter_matrix[64]; 138 u16 chroma_inter_matrix[64]; 139 140 /* MPEG-4 specific */ 141 int studio_profile; 142 int time_base; ///< time in seconds of last I,P,S Frame 143 int quant_precision; 144 int quarter_sample; ///< 1->qpel, 0->half pel ME/MC 145 int aspect_ratio_info; //FIXME remove 146 int sprite_warping_accuracy; 147 int data_partitioning; ///< data partitioning flag from header 148 int low_delay; ///< no reordering needed / has no B-frames 149 int vo_type; 150 int mpeg_quant; 151 152 /* divx specific, used to workaround (many) bugs in divx5 */ 153 int divx_packed; 154 155 /* MPEG-2-specific - I wished not to have to support this mess. */ 156 int progressive_sequence; 157 158 int progressive_frame; 159 int interlaced_dct; 160 161 int h_edge_pos, v_edge_pos;///< horizontal / vertical position of the right/bottom edge (pixel replication) 162 const u8 *y_dc_scale_table; ///< qscale -> y_dc_scale table 163 const u8 *c_dc_scale_table; ///< qscale -> c_dc_scale table 164 int qscale; ///< QP 165 int chroma_qscale; ///< chroma QP 166 int pict_type; ///< AV_PICTURE_TYPE_I, AV_PICTURE_TYPE_P, AV_PICTURE_TYPE_B, ... 167 int f_code; ///< forward MV resolution 168 int b_code; ///< backward MV resolution for B-frames (MPEG-4) 169 int no_rounding; /**< apply no rounding to motion compensation (MPEG-4, msmpeg4, ...) 170 for B-frames rounding mode is always 0 */ 171 int last_time_base; 172 long time; ///< time of current frame 173 long last_non_b_time; 174 u16 pp_time; ///< time distance between the last 2 p,s,i frames 175 u16 pb_time; ///< time distance between the last b and p,s,i frame 176 u16 pp_field_time; 177 u16 pb_field_time; ///< like above, just for interlaced 178 int real_sprite_warping_points; 179 int sprite_offset[2][2]; ///< sprite offset[isChroma][isMVY] 180 int sprite_delta[2][2]; ///< sprite_delta [isY][isMVY] 181 int mcsel; 182 int partitioned_frame; ///< is current frame partitioned 183 int top_field_first; 184 int alternate_scan; 185 int last_dc[3]; ///< last DC values for MPEG-1 186 int dct_precision; 187 int intra_dc_precision; 188 int frame_pred_frame_dct; 189 int q_scale_type; 190 int context_reinit; 191 int chroma_format; 192 }; 193 194 struct mpeg4_dec_param { 195 struct MpegEncContext m; 196 197 /// number of bits to represent the fractional part of time 198 int time_increment_bits; 199 int shape; 200 int vol_sprite_usage; 201 int sprite_brightness_change; 202 int num_sprite_warping_points; 203 /// sprite trajectory points 204 u16 sprite_traj[4][2]; 205 /// sprite shift [isChroma] 206 int sprite_shift[2]; 207 208 // reversible vlc 209 int rvlc; 210 /// could this stream contain resync markers 211 int resync_marker; 212 /// time distance of first I -> B, used for interlaced B-frames 213 int t_frame; 214 215 int new_pred; 216 int enhancement_type; 217 int scalability; 218 int use_intra_dc_vlc; 219 220 /// QP above which the ac VLC should be used for intra dc 221 int intra_dc_threshold; 222 223 /* bug workarounds */ 224 int divx_version; 225 int divx_build; 226 int xvid_build; 227 int lavc_build; 228 229 /// flag for having shown the warning about invalid Divx B-frames 230 int showed_packed_warning; 231 /** does the stream contain the low_delay flag, 232 * used to work around buggy encoders. */ 233 int vol_control_parameters; 234 int cplx_estimation_trash_i; 235 int cplx_estimation_trash_p; 236 int cplx_estimation_trash_b; 237 238 struct VLC studio_intra_tab[12]; 239 struct VLC studio_luma_dc; 240 struct VLC studio_chroma_dc; 241 242 int rgb; 243 244 struct AVRational time_base; 245 int ticks_per_frame; 246 enum AVPixelFormat pix_fmt; 247 struct AVRational sample_aspect_ratio; 248 enum AVColorPrimaries color_primaries; 249 enum AVColorTransferCharacteristic color_trc; 250 enum AVColorSpace colorspace; 251 enum AVColorRange color_range; 252 enum AVChromaLocation chroma_sample_location; 253 int err_recognition; 254 int idct_algo; 255 int bits_per_raw_sample; 256 int profile; 257 int level; 258 struct AVRational framerate; 259 int flags; 260 }; 261 262 struct mpeg4_param_sets { 263 bool head_parsed; 264 /* currently active parameter sets */ 265 struct mpeg4_dec_param dec_ps; 266 }; 267 268 int mpeg4_decode_extradata_ps(u8 *buf, int size, struct mpeg4_param_sets *ps); 269 270 #endif 271 272