1 #ifndef _ENCODERPARAMS_HH 2 #define _ENCODERPARAMS_HH 3 4 /* encoderparams - class holding all the various control parameters for 5 and individual encoder instance. For speed a lot of address offsets/sizes 6 are computed once-and-for-all and held in this object. 7 */ 8 9 /* Copyright (C) 1996, MPEG Software Simulation Group. All Rights Reserved. */ 10 11 /* 12 * Disclaimer of Warranty 13 * 14 * These software programs are available to the user without any license fee or 15 * royalty on an "as is" basis. The MPEG Software Simulation Group disclaims 16 * any and all warranties, whether express, implied, or statuary, including any 17 * implied warranties or merchantability or of fitness for a particular 18 * purpose. In no event shall the copyright-holder be liable for any 19 * incidental, punitive, or consequential damages of any kind whatsoever 20 * arising from the use of these programs. 21 * 22 * This disclaimer of warranty extends to the user of these programs and user's 23 * customers, employees, agents, transferees, successors, and assigns. 24 * 25 * The MPEG Software Simulation Group does not represent or warrant that the 26 * programs furnished hereunder are free of infringement of any third-party 27 * patents. 28 * 29 * Commercial implementations of MPEG-1 and MPEG-2 video, including shareware, 30 * are subject to royalty fees to patent holders. Many of these patents are 31 * general enough such that they are unavoidable regardless of implementation 32 * design. 33 * 34 */ 35 36 /* Modifications and enhancements (C) 2000,2001,2002,2003 Andrew Stevens */ 37 38 /* These modifications are free software; you can redistribute it 39 * and/or modify it under the terms of the GNU General Public License 40 * as published by the Free Software Foundation; either version 2 of 41 * the License, or (at your option) any later version. 42 * 43 * This program is distributed in the hope that it will be useful, 44 * but WITHOUT ANY WARRANTY; without even the implied warranty of 45 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 46 * General Public License for more details. 47 * 48 * You should have received a copy of the GNU General Public License 49 * along with this program; if not, write to the Free Software 50 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 51 * 02111-1307, USA. 52 * 53 */ 54 55 56 #include "mjpeg_types.h" 57 #include "syntaxconsts.h" 58 59 #include <deque> 60 61 using std::deque; 62 63 64 /* 65 Ensure we don't bury a system in wild spawning of 66 threads... 67 */ 68 69 #define MAX_WORKER_THREADS 16 70 71 72 73 /* motion data */ 74 struct motion_data { 75 unsigned int forw_hor_f_code,forw_vert_f_code; /* vector range */ 76 unsigned int sxf,syf; /* search range */ 77 unsigned int back_hor_f_code,back_vert_f_code; 78 unsigned int sxb,syb; 79 }; 80 81 82 class RateCtl; 83 class MPEG2EncOptions; 84 85 class EncoderParams 86 { 87 public: 88 EncoderParams( const MPEG2EncOptions &options); 89 void Init(const MPEG2EncOptions &options); 90 91 private: 92 void InitQuantMatrices(const class MPEG2EncOptions &options); 93 void InitEncodingControls(const class MPEG2EncOptions &options); 94 void RangeChecks(); 95 void ProfileAndLevelChecks(); 96 public: 97 98 /************** 99 * 100 * Global MPEG parameters (set by supplied stream, never 101 * change in a run) 102 * 103 *************/ 104 105 unsigned int horizontal_size, vertical_size; 106 107 unsigned int aspectratio; /* aspect ratio information (pel or display) */ 108 unsigned int frame_rate_code; /* coded value of playback display 109 * frame rate */ 110 int dctsatlim; /* Value to saturated DCT coeffs to */ 111 double frame_rate; /* Playback display frames per second 112 N.b. when 3:2 pullback is active 113 this is higher than the frame 114 decode rate. */ 115 double bit_rate; /* bits per second, rate decode buffers filled (max rate) */ 116 double target_bitrate; /* Target bit rate to achieve overall for VBR 0 if no target set */ 117 unsigned int stream_frames; /* # Frames to representatively sample stream */ 118 double stream_Xhi; /* Total stream complexity */ 119 bool seq_hdr_every_gop; 120 bool seq_end_every_gop; /* Useful for Stills sequences... */ 121 bool svcd_scan_data; 122 unsigned int vbv_buffer_code; /* Code for size of VBV buffer (* 123 * 16 kbit) */ 124 double vbv_buffer_size; 125 126 unsigned int still_size; /* If non-0 encode a stills sequence: 1 127 I-frame per sequence pseudo VBR. Each 128 frame sized to still_size KB */ 129 unsigned int vbv_buffer_still_size; /* vbv_buffer_size holds 130 still size. Ensure still 131 size matches. */ 132 133 bool constrparms; /* constrained parameters flag, MPEG-1 only */ 134 bool load_iquant; 135 bool load_niquant; /* use non-default quant. matrices */ 136 137 138 139 int profile, level; /* syntax / parameter constraints */ 140 bool ignore_constraints; /* Disabled conformance checking of 141 * hor_size, vert_size and 142 * samp_rate */ 143 bool dualprime; /* Allow dual prime motion compensation */ 144 145 146 bool prog_seq; /* progressive sequence */ 147 int low_delay; /* no B pictures, skipped pictures */ 148 149 /******* 150 * 151 * sequence specific data (sequence display extension) 152 * 153 ******/ 154 155 unsigned int video_format; /* component, PAL, NTSC, SECAM or MAC */ 156 unsigned int color_primaries; /* source primary chromaticity coordinates */ 157 unsigned int transfer_characteristics; /* opto-electronic transfer char. (gamma) */ 158 unsigned int matrix_coefficients; /* Eg,Eb,Er / Y,Cb,Cr matrix coefficients */ 159 unsigned int display_horizontal_size; /* display size */ 160 unsigned int display_vertical_size; 161 162 163 bool mpeg1; /* ISO/IEC IS 11172-2 sequence */ 164 bool fieldpic; /* use field pictures */ 165 bool pulldown_32; /* 3:2 Pulldown of movie material */ 166 bool topfirst; 167 168 /************ 169 * 170 * Picture kind specific informatino (picture header flags) 171 * 172 ***********/ 173 174 int frame_pred_dct_tab[3]; /* use only frame prediction and frame 175 DCT (I,P,B) */ 176 int qscale_tab[3]; /* linear/non-linear quantizaton table */ 177 int intravlc_tab[3]; /* intra vlc format (I,P,B) */ 178 int altscan_tab[3]; /* alternate scan (I,P,B */ 179 unsigned int dc_prec; 180 181 /**************************** 182 * Encoder internal derived values and parameters 183 *************************** */ 184 185 int enc_width, 186 enc_height; /* encoded frame size (pels) multiples of 16 or 32 */ 187 188 int phy_width, 189 phy_height; /* Physical Frame buffer size (pels) may differ 190 from encoded size due to alignment 191 constraints */ 192 int enc_chrom_width,enc_chrom_height; 193 int phy_chrom_width,phy_chrom_height; 194 195 int lum_buffer_size, chrom_buffer_size; 196 197 int mb_width, mb_height; /* frame size (macroblocks) */ 198 199 /* Picture dimensioning (allowing for interlaced/non-interlaced coding) */ 200 int phy_width2, phy_height2, enc_height2, 201 mb_height2, phy_chrom_width2; 202 int qsubsample_offset, 203 fsubsample_offset; 204 int mb_per_pict; /* Number of macro-blocks in a picture */ 205 206 207 struct motion_data *motion_data; 208 209 210 /* Selected intra/non_intra quantization matrices both ordinary*/ 211 /* and inverted */ 212 uint16_t *intra_q, *inter_q; 213 214 /* ************************** 215 * Global flags controlling encoding behaviour 216 ************************** */ 217 218 double decode_frame_rate; /* Actual stream frame 219 * decode-rate. This is lower than 220 * playback rate if 3:2 pulldown is 221 * active. 222 */ 223 int video_buffer_size; /* Video buffer requirement target */ 224 225 unsigned int N_max; /* number of frames in Group of Pictures (max) */ 226 unsigned int N_min; /* number of frames in Group of Pictures (min) */ 227 int M; /* distance between I/P frames */ 228 229 int M_min; /* Minimum distance between I/P frames */ 230 231 bool closed_GOPs; /* Force all GOPs to be closed - useful 232 * for satisfying requirements for 233 * multi-angle DVD authoring */ 234 235 int me44_red; /* Sub-mean population reduction passes 236 * for 4x4 and 2x2 */ 237 int me22_red; /* Motion compensation stages */ 238 int seq_length_limit; 239 double nonvid_bit_rate; /* Bit-rate for non-video to assume for 240 sequence splitting calculations */ 241 242 double quant_floor; /* quantisation floor [1..10] (0 for 243 * CBR) */ 244 245 246 double act_boost; /* Quantisation reduction factor for blocks 247 with little texture (low variance) */ 248 249 double boost_var_ceil; /* Variance below which 250 * quantisation boost cuts in */ 251 252 253 int encoding_parallelism; /* Maximum number of concurrent worker threads 254 to be used for encoding */ 255 256 int unit_coeff_elim; /* Threshold of unit coefficient 257 density below which unit 258 coefficient blocks should be 259 zeroed. < 0 implies DCT 260 coefficient should be included. */ 261 262 double coding_tolerance; /* Fraction of bit allocation that 263 actual coding size may deviate from 264 target set by rate controller before 265 a re-encoding is forced */ 266 267 deque<int> chapter_points; /* Frame #'s for where chapters occur (I frames, closed GOP's) */ 268 269 }; 270 271 272 #endif 273 274 /* 275 * Local variables: 276 * c-file-style: "stroustrup" 277 * tab-width: 4 278 * indent-tabs-mode: nil 279 * End: 280 */ 281