1 /*!
2  ************************************************************************
3  * \file params.h
4  *
5  * \brief
6  *    Input parameters related definitions
7  *
8  * \author
9  *
10  ************************************************************************
11  */
12 
13 #ifndef _PARAMS_H_
14 #define _PARAMS_H_
15 
16 #include "defines.h"
17 #include "types.h"
18 #include "vui_params.h"
19 #include "frame.h"
20 #include "io_video.h"
21 
22 //! all input parameters
23 struct inp_par_enc
24 {
25   int ProfileIDC;                       //!< value of syntax element profile_idc
26   int LevelIDC;                         //!< value of syntax element level_idc
27   int IntraProfile;                     //!< Enable Intra profiles
28 
29   int no_frames;                        //!< number of frames to be encoded
30   int qp[NUM_SLICE_TYPES];              //!< QP values for all slice types
31   int qp2frame;                         //!< frame in display order from which to apply the Change QP offsets
32   int qp2off[NUM_SLICE_TYPES];          //!< Change QP offset values for all slice types
33   int qpsp;                             //!< QPSP quantization value
34   int frame_skip;                       //!< number of frames to skip in input sequence (e.g 2 takes frame 0,3,6,9...)
35   int jumpd;                            /*!< number of frames to skip in input sequence including intermediate pictures
36                                              (e.g 2 takes frame 0,3,6,9...) */
37   int DisableSubpelME[2];               //!< Disable sub-pixel motion estimation
38   int search_range[2];                  /*!< search range - integer pel search and 16x16 blocks.  The search window is
39                                              generally around the predicted vector. Max vector is 2xmcrange.  */
40   int num_ref_frames;                   //!< number of reference frames to be used
41   int P_List0_refs[2];                  //!< number of reference picture in list 0 in P pictures
42   int B_List0_refs[2];                  //!< number of reference picture in list 0 in B pictures
43   int B_List1_refs[2];                  //!< number of reference picture in list 1 in B pictures
44   int num_ref_frames_org;
45   int P_List0_refs_org[2];                  //!< number of reference picture in list 0 in P pictures
46   int B_List0_refs_org[2];                  //!< number of reference picture in list 0 in B pictures
47   int B_List1_refs_org[2];                  //!< number of reference picture in list 1 in B pictures
48   int Log2MaxFNumMinus4;                //!< value of syntax element log2_max_frame_num
49   int Log2MaxPOCLsbMinus4;              //!< value of syntax element log2_max_pic_order_cnt_lsb_minus4
50 
51   // Input/output sequence format related variables
52   FrameFormat source;                   //!< source related information
53   FrameFormat output;                   //!< output related information
54   int is_interleaved;
55   int src_resize;                       //!< Control if input sequence will be resized (currently only cropping is supported)
56   int src_BitDepthRescale;              //!< Control if input sequence bitdepth should be adjusted
57   int yuv_format;                       //!< YUV format (0=4:0:0, 1=4:2:0, 2=4:2:2, 3=4:4:4)
58   int intra_upd;                        /*!< For error robustness. 0: no special action. 1: One GOB/frame is intra coded
59                                              as regular 'update'. 2: One GOB every 2 frames is intra coded etc.
60                                              In connection with this intra update, restrictions is put on motion vectors
61                                              to prevent errors to propagate from the past                                */
62 
63   int slice_mode;                       //!< Indicate what algorithm to use for setting slices
64   int slice_argument;                   //!< Argument to the specified slice algorithm
65   int UseConstrainedIntraPred;          //!< 0: Inter MB pixels are allowed for intra prediction 1: Not allowed
66   int  SetFirstAsLongTerm;              //!< Support for temporal considerations for CB plus encoding
67   int  infile_header;                   //!< If input file has a header set this to the length of the header
68   int  MultiSourceData;
69   VideoDataFile   input_file2;          //!< Input video file2
70   VideoDataFile   input_file3;          //!< Input video file3
71   int num_of_views;                     //!< number of views to encode (1=1view, 2=2views)
72 #if (MVC_EXTENSION_ENABLE)
73   char View1ConfigName[FILE_NAME_SIZE];    //!<Filename for View1 configuration
74   int EnhLayerDFDisableIdc[2][NUM_SLICE_TYPES];
75   int EnhLayerDFAlpha     [2][NUM_SLICE_TYPES];
76   int EnhLayerDFBeta      [2][NUM_SLICE_TYPES];
77   int MVCInterViewReorder;              //!< Reorder References according to interview pictures
78   int MVCFlipViews;                     //!< Reverse the order of the views in the bitstream (view 1 has VOIdx 0 and view 1 has VOIdx 0)
79   int MVCInterViewForceB;               //!< Force B slices for enhancement layer
80   int View1QPOffset;                    //!< QP offset during rate control for View 1
81   int enable_inter_view_flag;           //!< Enables inter_view_flag (allows pictures that are to be used for inter-view only prediction)
82   double enh_layer_lambda_multiplier;   //!< Weight lambda for enhancement layer
83   double enh_layer_me_lambda_multiplier;//!< Weight ME lambda for enhancement layer
84 
85 #endif
86   VideoDataFile   input_file1;          //!< Input video file1
87   char outfile       [FILE_NAME_SIZE];  //!< H.264 compressed output bitstream
88   char ReconFile     [FILE_NAME_SIZE];  //!< Reconstructed Pictures (view 0 for MVC profile)
89   char ReconFile2    [FILE_NAME_SIZE];  //!< Reconstructed Pictures (view 1)
90   char TraceFile     [FILE_NAME_SIZE];  //!< Trace Outputs
91   char StatsFile     [FILE_NAME_SIZE];  //!< Stats File
92   char QmatrixFile   [FILE_NAME_SIZE];  //!< Q matrix cfg file
93   int  ProcessInput;                    //!< Filter Input Sequence
94   int  EnableOpenGOP;                   //!< support for open gops.
95   int  EnableIDRGOP;                    //!< support for IDR closed gops with no shared B coded pictures.
96   int  grayscale;                       //!< encode in grayscale (Currently only works for 8 bit, YUV 420)
97 
98   int idr_period;                       //!< IDR picture period
99   int intra_period;                     //!< intra picture period
100   int intra_delay;                      //!< IDR picture delay
101   int adaptive_idr_period;
102   int adaptive_intra_period;            //!< reinitialize start of intra period
103 
104   int start_frame;                      //!< Encode sequence starting from Frame start_frame
105 
106   int enable_32_pulldown;
107 
108   int GenerateMultiplePPS;
109   int GenerateSEIMessage;
110   char SEIMessageText[INPUT_TEXT_SIZE];
111 
112   int ResendSPS;
113   int ResendPPS;
114 
115   int SendAUD;                          //!< send Access Unit Delimiter NALU
116   int skip_gl_stats;
117 
118   // B pictures
119   int NumberBFrames;                    //!< number of B frames that will be used
120   int PReplaceBSlice;
121   int qpBRSOffset;                      //!< QP for reference B slice coded pictures
122   int direct_spatial_mv_pred_flag;      //!< Direct Mode type to be used (0: Temporal, 1: Spatial)
123   int directInferenceFlag;              //!< Direct Mode Inference Flag
124 
125   int BiPredMotionEstimation;           //!< Use of Bipredictive motion estimation
126   int BiPredSearch[4];                  //!< Bipredictive motion estimation for modes 16x16, 16x8, 8x16, and 8x8
127   int BiPredMERefinements;              //!< Max number of Iterations for Bi-predictive motion estimation
128   int BiPredMESearchRange[2];           //!< Search range of Bi-predictive motion estimation
129   int BiPredMESubPel;                   //!< Use of subpixel refinement for Bi-predictive motion estimation
130 
131   // SP/SI Pictures
132   int sp_periodicity;                   //!< The periodicity of SP-pictures
133   int sp_switch_period;                 //!< Switch period (in terms of switching SP/SI frames) between bitstream 1 and bitstream 2
134   int si_frame_indicator;               //!< Flag indicating whether SI frames should be encoded rather than SP frames (0: not used, 1: used)
135   int sp2_frame_indicator;              //!< Flag indicating whether switching SP frames should be encoded rather than SP frames (0: not used, 1: used)
136   int sp_output_indicator;              //!< Flag indicating whether coefficients are output to allow future encoding of switchin SP frames (0: not used, 1: used)
137   char sp_output_filename[FILE_NAME_SIZE];    //!<Filename where SP coefficients are output
138   char sp2_input_filename1[FILE_NAME_SIZE];   //!<Filename of coefficients of the first bitstream when encoding SP frames to switch bitstreams
139   char sp2_input_filename2[FILE_NAME_SIZE];   //!<Filenames of coefficients of the second bitstream when encoding SP frames to switch bitstreams
140 
141   // Weighted Prediction
142   int WeightedPrediction;               //!< Weighted prediction for P frames (0: not used, 1: explicit)
143   int WeightedBiprediction;             //!< Weighted prediction for B frames (0: not used, 1: explicit, 2: implicit)
144   int WPMethod;                         //!< WP method (0: DC, 1: LMS)
145   int WPIterMC;                         //!< Iterative WP method
146   int WPMCPrecision;
147   int WPMCPrecFullRef;
148   int WPMCPrecBSlice;
149   int EnhancedBWeightSupport;
150   int ChromaWeightSupport;           //!< Weighted prediction support for chroma (0: disabled, 1: enabled)
151   int UseWeightedReferenceME;        //!< Use Weighted Reference for ME.
152   int RDPictureDecision;             //!< Perform RD optimal decision between various coded versions of same picture
153   int RDPSliceBTest;                 //!< Tests B slice replacement for P.
154   int RDPSliceITest;                 //!< Tests I slice replacement for P.
155   int RDPictureMaxPassISlice;        //!< Max # of coding passes for I-slice
156   int RDPictureMaxPassPSlice;        //!< Max # of coding passes for P-slice
157   int RDPictureMaxPassBSlice;        //!< Max # of coding passes for B-slice
158   int RDPictureDeblocking;           //!< Whether to choose between deblocked and non-deblocked picture
159   int RDPictureDirectMode;           //!< Whether to check the other direct mode for B slices
160   int RDPictureFrameQPPSlice;        //!< Whether to check additional frame level QP values for P slices
161   int RDPictureFrameQPBSlice;        //!< Whether to check additional frame level QP values for B slices
162 
163   int SkipIntraInInterSlices;        //!< Skip intra type checking in inter slices if best_mode is skip/direct
164   int PSliceSkipDecisionMethod;             //!< Use of a NaturalSkip method for deciding skip modes in P slices
165   int BRefPictures;                  //!< B coded reference pictures replace P pictures (0: not used, 1: used)
166   int HierarchicalCoding;
167   int HierarchyLevelQPEnable;
168   char ExplicitHierarchyFormat[INPUT_TEXT_SIZE]; //!< Explicit GOP format (HierarchicalCoding==3).
169   // explicit sequence information parameters
170   int  ExplicitSeqCoding;
171   char ExplicitSeqFile[FILE_NAME_SIZE];
172   int  LowDelay;                      //!< Apply HierarchicalCoding without delay (i.e., encode in the captured/display order)
173 
174   int  ReferenceReorder;              //!< Reordering based on Poc distances
175   int  EnableReorderBslice;           //!< Perform reordering for B slice List0. Only makes sense if MSE reordering is used.
176   int  UseDistortionReorder;          //!< for method ReferenceReorder = 1, use distortion based reordering
177   int  PocMemoryManagement;           //!< Memory management based on Poc distances for hierarchical coding
178 
179   int symbol_mode;                   //!< Specifies the mode the symbols are mapped on bits
180   int of_mode;                       //!< Specifies the mode of the output file
181   int partition_mode;                //!< Specifies the mode of data partitioning
182 
183 // #if (MVC_EXTENSION_ENABLE)
184   int SepViewInterSearch;
185   int View1NoResidueRDO;
186 // #endif
187   int InterSearch[2][2][8];
188 
189   int DisableIntra4x4;
190   int DisableIntra16x16;
191   int FastMDEnable;
192   int FastIntraMD;
193   int FastIntra4x4;
194   int FastIntra16x16;
195   int FastIntra8x8;
196   int FastIntraChroma;
197 
198   int DisableIntraInInter[2];
199   int IntraDisableInterOnly;
200   int Intra4x4ParDisable;
201   int Intra4x4DiagDisable;
202   int Intra4x4DirDisable;
203   int Intra16x16ParDisable;
204   int Intra16x16PlaneDisable;
205   int ChromaIntraDisable;
206 
207   int EnableIPCM;
208 
209   double FrameRate;
210 
211   int chroma_qp_index_offset;
212   int full_search;
213 
214   int rdopt;
215   int de;     //!< the algorithm to estimate the distortion in the decoder
216   int I16rdo;
217   int MDReference[2];
218   int subMBCodingState;
219   int Distortion[TOTAL_DIST_TYPES];
220   double VisualResWavPSNR;
221   int SSIMOverlapSize;
222   int DistortionYUVtoRGB;
223   int CtxAdptLagrangeMult;    //!< context adaptive lagrangian multiplier
224   int FastCrIntraDecision;
225   int disthres;
226   int nobskip;
227   int BiasSkipRDO;
228   int ForceTrueRateRDO;
229 
230 #ifdef _LEAKYBUCKET_
231   int  NumberLeakyBuckets;
232   char LeakyBucketRateFile[FILE_NAME_SIZE];
233   char LeakyBucketParamFile[FILE_NAME_SIZE];
234 #endif
235 
236   int PicInterlace;           //!< picture adaptive frame/field
237   int MbInterlace;            //!< macroblock adaptive frame/field
238   int IntraBottom;            //!< Force Intra Bottom at GOP periods.
239 
240   // Error resilient RDO parameters
241   double LossRateA;              //!< assumed loss probablility of partition A (or full slice), in per cent, used for loss-aware R/D optimization
242   double LossRateB;              //!< assumed loss probablility of partition B, in per cent, used for loss-aware R/D
243   double LossRateC;              //!< assumed loss probablility of partition C, in per cent, used for loss-aware R/D
244   int FirstFrameCorrect;      //!< the first frame is encoded under the assumption that it is always correctly received.
245   int NoOfDecoders;
246   int ErrorConcealment;       //!< Error concealment method used for loss-aware RDO (0: Copy Concealment)
247   int RestrictRef;
248   int NumFramesInELSubSeq;
249 
250   int RandomIntraMBRefresh;     //!< Number of pseudo-random intra-MBs per picture
251 
252   int OnTheFlyFractMCP;         //!< On the fly interpolation mode
253 
254   // Chroma interpolation and buffering
255   int ChromaMCBuffer;
256   int ChromaMEEnable;
257   int ChromaMEWeight;
258   int MESoftenSSEMetric;
259   int MEErrorMetric[3];
260   int ModeDecisionMetric;
261   int SkipDeBlockNonRef;
262 
263   //  Deblocking Filter parameters
264   int DFSendParameters;
265   int DFDisableIdc[2][NUM_SLICE_TYPES];
266   int DFAlpha     [2][NUM_SLICE_TYPES];
267   int DFBeta      [2][NUM_SLICE_TYPES];
268 
269   int SparePictureOption;
270   int SPDetectionThreshold;
271   int SPPercentageThreshold;
272 
273   // FMO
274   char SliceGroupConfigFileName[FILE_NAME_SIZE];    //!< Filename for config info fot type 0, 2, 6
275   int num_slice_groups_minus1;           //!< "FmoNumSliceGroups" in encoder.cfg, same as FmoNumSliceGroups, which should be erased later
276   int slice_group_map_type;
277 
278   unsigned int *top_left;                         //!< top_left and bottom_right store values indicating foregrounds
279   unsigned int *bottom_right;
280   byte *slice_group_id;                   //!< slice_group_id is for slice group type being 6
281   int *run_length_minus1;                //!< run_length_minus1 is for slice group type being 0
282 
283   int slice_group_change_direction_flag;
284   int slice_group_change_rate_minus1;
285   int slice_group_change_cycle;
286 
287   int redundant_pic_flag;   //! encoding of redundant pictures
288   int pic_order_cnt_type;   //! POC type
289 
290   int context_init_method;
291   int model_number;
292   int Transform8x8Mode;
293   int ReportFrameStats;
294   int DisplayEncParams;
295   int Verbose;
296 
297   //! Rate Control parameters
298   int RCEnable;
299   int bit_rate;
300   int SeinitialQP;
301   unsigned int basicunit;
302   int channel_type;
303   int RCUpdateMode;
304   double RCIoverPRatio;
305   double RCBoverPRatio;
306   double RCISliceBitRatio;
307   double RCBSliceBitRatio[RC_MAX_TEMPORAL_LEVELS];
308   int    RCMinQP[NUM_SLICE_TYPES];
309   int    RCMaxQP[NUM_SLICE_TYPES];
310   int    RCMaxQPChange;
311 
312   // Motion Estimation related parameters
313   int    UseMVLimits;
314   int    SetMVXLimit;
315   int    SetMVYLimit;
316 
317   // Search Algorithm
318   SearchType SearchMode[2];
319 
320   // UMHEX related parameters
321   int UMHexDSR;
322   int UMHexScale;
323 
324   // EPZS related parameters
325   int EPZSPattern;
326   int EPZSDual;
327   int EPZSFixed;
328   int EPZSAggressiveWindow;
329 #if (MVC_EXTENSION_ENABLE)
330   int EPZSTemporal[2];
331 #else
332   int EPZSTemporal;
333 #endif
334   int EPZSSpatialMem;
335   int EPZSBlockType;
336 #if (MVC_EXTENSION_ENABLE)
337   int EnableEnhLayerEPZSScalers;
338   int EPZSMinThresScale[2];
339   int EPZSMaxThresScale[2];
340   int EPZSMedThresScale[2];
341   int EPZSSubPelThresScale[2];
342 #else
343   int EPZSMinThresScale;
344   int EPZSMaxThresScale;
345   int EPZSMedThresScale;
346   int EPZSSubPelThresScale;
347 #endif
348   int DisableMEPrediction;
349   int EPZSSubPelGrid;
350   int EPZSSubPelME;
351   int EPZSSubPelMEBiPred;
352   int EPZSUseHMEPredictors;
353 
354   // HME Related parameter
355   int HMEEnable;
356   int HMEDisableMMCO;
357   int PyramidLevels;
358 
359 
360   // IDR min distance
361   int MinIDRDistance;
362   // Lambda Params
363   int UseExplicitLambdaParams;
364   int DisableDistanceLambdaScale;
365   int UpdateLambdaChromaME;
366   double LambdaWeight[6];
367   double FixedLambda[6];
368 
369   char QOffsetMatrixFile[FILE_NAME_SIZE];        //!< Quantization Offset matrix cfg file
370   int  OffsetMatrixPresentFlag;                  //!< Enable Explicit Quantization Offset Matrices
371 
372   int AdaptiveRounding;                          //!< Adaptive Rounding parameter based on JVT-N011
373   int AdaptRoundingFixed;                        //!< Global rounding for all qps
374   int AdaptRndPeriod;                            //!< Set period for adaptive rounding of JVT-N011 in MBs
375   int AdaptRndChroma;
376   int AdaptRndWFactor  [2][NUM_SLICE_TYPES];     //!< Weighting factors for luma component based on reference indicator and slice type
377   int AdaptRndCrWFactor[2][NUM_SLICE_TYPES];     //!< Weighting factors for chroma components based on reference indicator and slice type
378   int OffsetMatrixFlat;
379 
380 //////////////////////////////////////////////////////////////////////////
381   // Fidelity Range Extensions
382   int ScalingMatrixPresentFlag;
383   int ScalingListPresentFlag[12];
384 
385   int cb_qp_index_offset;
386   int cr_qp_index_offset;
387   // Lossless Coding
388   int LosslessCoding;
389 
390   // Fast Mode Decision
391   int EarlySkipEnable;
392   int SelectiveIntraEnable;
393   int DisposableP;
394   int DispPQPOffset;
395 
396   //Redundant picture
397   int NumRedundantHierarchy;   //!< number of entries to allocate redundant pictures in a GOP
398   int PrimaryGOPLength;        //!< GOP length of primary pictures
399   int NumRefPrimary;           //!< number of reference frames for primary picture
400 
401   // tone mapping SEI message
402   int ToneMappingSEIPresentFlag;
403   char ToneMappingFile[FILE_NAME_SIZE];    //!< ToneMapping SEI message cfg file
404 
405   // prediction structure
406   int PreferDispOrder;       //!< Prefer display order when building the prediction structure as opposed to coding order
407   int PreferPowerOfTwo;      //!< Prefer prediction structures that have lengths expressed as powers of two
408   int FrmStructBufferLength; //!< Number of frames that is populated every time populate_frm_struct is called
409   // support for "soft" 3:2 pulldown
410   int rc_cpb_size;
411   int SEIVUI32Pulldown;                //!< Enable 3:2 pulldown through VUI and SEI metadata signalling. Three methods are supported.
412   int SEIFPAType;                      //!< Value of frame_packing_arrangement_type in SEI FPA message
413 
414   int separate_colour_plane_flag;
415   double WeightY;
416   double WeightCb;
417   double WeightCr;
418   int UseRDOQuant;
419   int RDOQ_DC;
420   int RDOQ_CR;
421   int RDOQ_DC_CR;
422   int RDOQ_QP_Num;
423   int RDOQ_CP_Mode;
424   int RDOQ_CP_MV;
425   int RDOQ_Fast;
426 
427   int EnableVUISupport;
428   // VUI parameters
429   VUIParameters VUI;
430   // end of VUI parameters
431 
432   // LZL additions
433   int stdRange;                         //!< 1 - standard range, 0 - full range
434   int videoCode;                        //!< 1 - 709, 3 - 601:  See VideoCode in io_tiff.
435 
436 #if B0_MORE_REF
437   int BLevel0MoreRef;
438 #endif
439 #if KEEP_B_SAME_LIST
440   int BIdenticalList;
441 #endif
442 #if CRA
443   int useCRA;
444 #endif
445 #if HM50_LIKE_MMCO
446   int HM50RefStructure;
447 #endif
448 #if LD_REF_SETTING
449   int LDRefSetting;
450   int UnconstrainedLDRef;
451 #endif
452 };
453 
454 #endif
455 
456