upgrade libvpx+lv2, fix dbl tap play bug, add multi nest/unnest clips, add del top...
[goodguy/cinelerra.git] / cinelerra-5.1 / mpeg2enc / global.h
1 /* global.h, global variables, function prototypes                          */
2
3 /* Copyright (C) 1996, MPEG Software Simulation Group. All Rights Reserved. */
4
5 /*
6  * Disclaimer of Warranty
7  *
8  * These software programs are available to the user without any license fee or
9  * royalty on an "as is" basis.  The MPEG Software Simulation Group disclaims
10  * any and all warranties, whether express, implied, or statuary, including any
11  * implied warranties or merchantability or of fitness for a particular
12  * purpose.  In no event shall the copyright-holder be liable for any
13  * incidental, punitive, or consequential damages of any kind whatsoever
14  * arising from the use of these programs.
15  *
16  * This disclaimer of warranty extends to the user of these programs and user's
17  * customers, employees, agents, transferees, successors, and assigns.
18  *
19  * The MPEG Software Simulation Group does not represent or warrant that the
20  * programs furnished hereunder are free of infringement of any third-party
21  * patents.
22  *
23  * Commercial implementations of MPEG-1 and MPEG-2 video, including shareware,
24  * are subject to royalty fees to patent holders.  Many of these patents are
25  * general enough such that they are unavoidable regardless of implementation
26  * design.
27  *
28  */
29
30 #include "libzmpeg3.h"
31 #include "mpeg2enc.h"
32
33 #include <pthread.h>
34 #include <stdint.h>
35
36 /* choose between declaration (GLOBAL_ undefined)
37  * and definition (GLOBAL_ defined)
38  * GLOBAL_ is defined in exactly one file (mpeg2enc.c)
39  */
40
41 #ifndef GLOBAL_
42 #define EXTERN_ extern
43 #else
44 #define EXTERN_
45 #endif
46
47 /* global variables */
48
49
50 /* zig-zag scan */
51 EXTERN_ unsigned char mpeg2_zig_zag_scan[64]
52 #ifdef GLOBAL_
53 =
54 {
55   0,1,8,16,9,2,3,10,17,24,32,25,18,11,4,5,
56   12,19,26,33,40,48,41,34,27,20,13,6,7,14,21,28,
57   35,42,49,56,57,50,43,36,29,22,15,23,30,37,44,51,
58   58,59,52,45,38,31,39,46,53,60,61,54,47,55,62,63
59 }
60 #endif
61 ;
62
63 /* alternate scan */
64 EXTERN_ unsigned char alternate_scan_hv[64]
65 #ifdef GLOBAL_
66 =
67 {
68   0,8,16,24,1,9,2,10,17,25,32,40,48,56,57,49,
69   41,33,26,18,3,11,4,12,19,27,34,42,50,58,35,43,
70   51,59,20,28,5,13,6,14,21,29,36,44,52,60,37,45,
71   53,61,22,30,7,15,23,31,38,46,54,62,39,47,55,63
72 }
73 #endif
74 ;
75
76 /* default intra quantization matrix */
77 EXTERN_ uint16_t default_intra_quantizer_matrix_hv[64]
78 #ifdef GLOBAL_
79 =
80 {
81    8, 16, 19, 22, 26, 27, 29, 34,
82   16, 16, 22, 24, 27, 29, 34, 37,
83   19, 22, 26, 27, 29, 34, 34, 38,
84   22, 22, 26, 27, 29, 34, 37, 40,
85   22, 26, 27, 29, 32, 35, 40, 48,
86   26, 27, 29, 32, 35, 40, 48, 58,
87   26, 27, 29, 34, 38, 46, 56, 69,
88   27, 29, 35, 38, 46, 56, 69, 83
89 }
90 #endif
91 ;
92
93 EXTERN_ uint16_t hires_intra_quantizer_matrix_hv[64]
94 #ifdef GLOBAL_
95 =
96 {
97    8, 16, 18, 20, 24, 25, 26, 30,
98   16, 16, 20, 23, 25, 26, 30, 30,
99   18, 20, 22, 24, 26, 28, 29, 31,
100   20, 21, 23, 24, 26, 28, 31, 31,
101   21, 23, 24, 25, 28, 30, 30, 33,
102   23, 24, 25, 28, 30, 30, 33, 36,
103   24, 25, 26, 29, 29, 31, 34, 38,
104   25, 26, 28, 29, 31, 34, 38, 42
105 }
106 #endif
107 ;
108
109 /* Our default non intra quantization matrix
110         This is *not* the MPEG default
111          */
112 EXTERN_ uint16_t default_nonintra_quantizer_matrix_hv[64]
113 #ifdef GLOBAL_
114 =
115
116 {
117   16, 17, 18, 19, 20, 21, 22, 23,
118   17, 18, 19, 20, 21, 22, 23, 24,
119   18, 19, 20, 21, 22, 23, 24, 25,
120   19, 20, 21, 22, 23, 24, 26, 27,
121   20, 21, 22, 23, 25, 26, 27, 28,
122   21, 22, 23, 24, 26, 27, 28, 30,
123   22, 23, 24, 26, 27, 28, 30, 31,
124   23, 24, 25, 27, 28, 30, 31, 33
125  
126 }   
127 #endif
128 ;
129
130 /* Hires non intra quantization matrix.  THis *is*
131         the MPEG default...      */
132 EXTERN_ uint16_t hires_nonintra_quantizer_matrix_hv[64]
133 #ifdef GLOBAL_
134 =
135 {
136         16, 16, 16, 16, 16, 16, 16, 16,
137         16, 16, 16, 16, 16, 16, 16, 16,
138         16, 16, 16, 16, 16, 16, 16, 16,
139         16, 16, 16, 16, 16, 16, 16, 16,
140         16, 16, 16, 16, 16, 16, 16, 16,
141         16, 16, 16, 16, 16, 16, 16, 16,
142         16, 16, 16, 16, 16, 16, 16, 16,
143         16, 16, 16, 16, 16, 16, 16, 16
144 }
145 #endif
146 ;
147
148 /* non-linear quantization coefficient table */
149 EXTERN_ unsigned char non_linear_mquant_table_hv[32]
150 #ifdef GLOBAL_
151 =
152 {
153    0, 1, 2, 3, 4, 5, 6, 7,
154    8,10,12,14,16,18,20,22,
155   24,28,32,36,40,44,48,52,
156   56,64,72,80,88,96,104,112
157 }
158 #endif
159 ;
160
161 /* non-linear mquant table for mapping from scale to code
162  * since reconstruction levels are not bijective with the index map,
163  * it is up to the designer to determine most of the quantization levels
164  */
165
166 EXTERN_ unsigned char map_non_linear_mquant_hv[113] 
167 #ifdef GLOBAL_
168 =
169 {
170 0,1,2,3,4,5,6,7,8,8,9,9,10,10,11,11,12,12,13,13,14,14,15,15,16,16,
171 16,17,17,17,18,18,18,18,19,19,19,19,20,20,20,20,21,21,21,21,22,22,
172 22,22,23,23,23,23,24,24,24,24,24,24,24,25,25,25,25,25,25,25,26,26,
173 26,26,26,26,26,26,27,27,27,27,27,27,27,27,28,28,28,28,28,28,28,29,
174 29,29,29,29,29,29,29,29,29,30,30,30,30,30,30,30,31,31,31,31,31
175 }
176 #endif
177 ;
178
179 struct mc_result
180 {
181         uint16_t weight;
182         int8_t x;
183         int8_t y;
184 };
185
186 typedef struct mc_result mc_result_s;
187
188 typedef struct motion_comp
189 {
190         uint8_t **oldorg, **neworg;
191         uint8_t **oldref, **newref;
192         uint8_t **cur, **curref;
193         int sxf, syf, sxb, syb;
194 } motion_comp_s;
195
196 typedef struct mbinfo mbinfo_s;
197
198 typedef struct pict_data
199 {
200
201         /* picture structure (header) data */
202
203         int temp_ref; /* temporal reference */
204         int pict_type; /* picture coding type (I, P or B) */
205         int vbv_delay; /* video buffering verifier delay (1/90000 seconds) */
206         int forw_hor_f_code, forw_vert_f_code;
207         int back_hor_f_code, back_vert_f_code; /* motion vector ranges */
208         int dc_prec;                            /* DC coefficient prec for intra blocks */
209         int pict_struct;                        /* picture structure (frame, top / bottom) */
210         int topfirst;                           /* display top field first */
211         int frame_pred_dct;                     /* Use only frame prediction... */
212         int intravlc;                           /* Intra VLC format */
213         int q_scale_type;                       /* Quantiser scale... */
214         int altscan;                            /* Alternate scan  */
215         int repeatfirst;                        /* repeat first field after second field */
216         int prog_frame;                         /* progressive frame */
217
218         /* 8*8 block data, raw (unquantised) and quantised, and (eventually but
219            not yet inverse quantised */
220         int16_t (*blocks)[64];
221         int16_t (*qblocks)[64];
222
223         unsigned char **curorg, **curref;
224         /* macroblock side information array */
225         mbinfo_s *mbinfo;
226         /* motion estimation parameters */
227 } pict_data_s;
228
229 typedef struct
230 {
231         int start_row, end_row;
232         pthread_mutex_t input_lock, output_lock;
233         pthread_t tid;   /* ID of thread */
234         int done;
235
236         motion_comp_s *motion_comp;
237         pict_data_s *pict_data;
238         int secondfield;
239         int ipflag;
240
241 #define MAX_44_MATCHES (256*256/(4*4))
242         int sub22_num_mcomps;
243         int sub44_num_mcomps;
244         mc_result_s sub44_mcomps[MAX_44_MATCHES];
245         mc_result_s sub22_mcomps[MAX_44_MATCHES*4];
246 } motion_engine_t;
247
248 #if 0
249 typedef struct
250 {
251   pthread_mutex_t ratectl_lock;
252
253   double R, T, d;
254   double actsum;
255   int Np, Nb;
256   double S, Q;
257   int prev_mquant;
258   double bitcnt_EOP;
259   double next_ip_delay; /* due to frame reordering delay */
260   double decoding_time;
261   int Xi, Xp, Xb, r, d0i, d0p, d0b;
262   double avg_act;
263 } ratectl_t;
264 #endif
265
266 typedef struct
267 {
268 /*
269  *   bitcnt_EOP = 0.0;
270  *   next_ip_delay = 0.0;
271  *   decoding_time = 0.0;
272  *   P =                                          0;  // P distance between complete intra slice refresh 
273  *   r =                                          0;  // r (reaction parameter) 
274  *   avg_act =                            0;  // avg_act (initial average activity) 
275  *   Xi =                                         0;  // Xi (initial I frame global complexity measure) 
276  *   Xp =                                         0;  // Xp (initial P frame global complexity measure) 
277  *   Xb =                                         0;  // Xb (initial B frame global complexity measure) 
278  *   d0i =                                0;  // d0i (initial I frame virtual buffer fullness) 
279  *   d0p =                                0;  // d0p (initial P frame virtual buffer fullness) 
280  *   d0b =                                0;  // d0b (initial B frame virtual buffer fullness) 
281  */
282   pthread_mutex_t ratectl_lock;
283
284   double Xi, Xp, Xb;
285   int r;
286   int d0i, d0pb;
287   double R;
288   int d;
289   double T;
290   int CarryR;
291   int CarryRLim;
292
293 /* bitcnt_EOP - Position in generated bit-stream for latest
294                         end-of-picture Comparing these values with the
295                         bit-stream position for when the picture is due to be
296                         displayed allows us to see what the vbv buffer is up
297                         to.
298
299    gop_undershoot - If we *undershoot* our bit target the vbv buffer
300                                 calculations based on the actual length of the
301                                 bitstream will be wrong because in the final system
302                                 stream these bits will be padded away.  I.e. frames
303                                 *won't* arrive as early as the length of the video
304                                 stream would suggest they would.  To get it right we
305                                 have to keep track of the bits that would appear in
306                                 padding.
307                         
308                                                                         
309 */
310
311   int64_t bitcnt_EOP;
312   int gop_undershoot;
313
314 /*
315   actsum - Total activity (sum block variances) in frame
316   actcovered - Activity macroblocks so far quantised (used to
317                          fine tune quantisation to avoid starving highly
318                    active blocks appearing late in frame...) UNUSED
319   avg_act - Current average activity...
320 */
321   double actsum;
322   double actcovered;
323   double sum_avg_act;
324   double avg_act;
325   double peak_act;
326
327   int Np, Nb;
328   int64_t S;
329   double IR;
330
331 /* Note: eventually we may wish to tweak these to suit image content */
332   double Ki;    /* Down-scaling of I/B/P-frame complexity */
333   double Kb;    /* relative to others in bit-allocation   */
334   double Kp;    /* calculations.  We only need 2 but have all
335                                                    3 for readability */
336
337   int min_d,max_d;
338   int min_q, max_q;
339
340 /* TODO EXPERIMENT */
341   double avg_KI;  /* TODO: These values empirically determined            */
342   double avg_KB;   /* for MPEG-1, may need tuning for MPEG-2   */
343   double avg_KP;
344 #define K_AVG_WINDOW_I 4.0      /* TODO: MPEG-1, hard-wired settings */
345 #define K_AVG_WINDOW_P   10.0
346 #define K_AVG_WINDOW_B   20.0
347   double bits_per_mb;
348
349   double SQ;
350   double AQ;
351
352         double current_quant;
353         int64_t frame_start;
354         int64_t frame_end;
355 } ratectl_t;
356
357 typedef struct
358 {
359   int start_row, end_row;
360   pthread_mutex_t input_lock, output_lock;
361   pthread_t tid;   /* ID of thread */
362   int done;
363
364   pict_data_s *picture;
365   unsigned char **pred;
366   unsigned char **cur;
367 // Temp for MMX
368   unsigned char temp[128];
369 } transform_engine_t;
370
371 typedef struct
372 {
373         int start_row, end_row;
374         pthread_mutex_t input_lock, output_lock;
375         pthread_t tid;   /* ID of thread */
376         int done;
377
378         int prev_mquant;
379
380 /* prediction values for DCT coefficient (0,0) */
381         int dc_dct_pred[3];
382         
383         unsigned char *frame;
384         unsigned char *slice_buffer;
385         long slice_size;
386         long slice_allocated;
387         pict_data_s *picture;
388         ratectl_t *ratectl;
389         unsigned char outbfr;
390         int outcnt;
391 } slice_engine_t;
392
393 EXTERN_ pthread_mutex_t test_lock;
394 EXTERN_ motion_engine_t *motion_engines;
395 EXTERN_ transform_engine_t *transform_engines;
396 EXTERN_ transform_engine_t *itransform_engines;
397 EXTERN_ slice_engine_t *slice_engines;
398 EXTERN_ ratectl_t **ratectl;
399 EXTERN_ int quiet; /* suppress warnings */
400
401
402
403
404 EXTERN_ pict_data_s cur_picture;
405
406 /* reconstructed frames */
407 EXTERN_ unsigned char *newrefframe[3], *oldrefframe[3], *auxframe[3];
408 /* original frames */
409 EXTERN_ unsigned char *neworgframe[3], *oldorgframe[3], *auxorgframe[3];
410 /* prediction of current frame */
411 EXTERN_ unsigned char *predframe[3];
412 /* motion estimation parameters */
413 EXTERN_ struct motion_data *motion_data;
414
415 /* SCale factor for fast integer arithmetic routines */
416 /* Changed this and you *must* change the quantisation routines as they depend on its absolute
417         value */
418 #define IQUANT_SCALE_POW2 16
419 #define IQUANT_SCALE (1<<IQUANT_SCALE_POW2)
420 #define COEFFSUM_SCALE (1<<16)
421
422 /* Orginal intra / non_intra quantization matrices */
423 EXTERN_ uint16_t intra_q[64], inter_q[64];
424 EXTERN_ uint16_t i_intra_q[64], i_inter_q[64];
425
426 /* Table driven intra / non-intra quantization matrices */
427 EXTERN_ uint16_t intra_q_tbl[113][64], inter_q_tbl[113][64];
428 EXTERN_ uint16_t i_intra_q_tbl[113][64], i_inter_q_tbl[113][64];
429 EXTERN_ float intra_q_tblf[113][64], inter_q_tblf[113][64];
430 EXTERN_ float i_intra_q_tblf[113][64], i_inter_q_tblf[113][64];
431
432 EXTERN_ uint16_t chrom_intra_q[64],chrom_inter_q[64];
433
434
435
436
437
438 /* clipping (=saturation) table */
439 EXTERN_ unsigned char *clp;
440
441 /* name strings */
442 EXTERN_ char id_string[256], tplorg[256], tplref[256], out_path[256];
443 EXTERN_ char iqname[256], niqname[256];
444 EXTERN_ char statname[256];
445 EXTERN_ char errortext[256];
446
447 EXTERN_ FILE *outfile; /* file descriptors */
448 EXTERN_ FILE *statfile; /* file descriptors */
449 EXTERN_ int inputtype; /* format of input frames */
450
451 /*
452   How many frames to read ahead (eventually intended to support
453   scene change based GOP structuring.  READ_LOOK_AHEAD/2 must be
454   greater than M (otherwise buffers will be overwritten that are
455   still in use).
456
457   It should also be a multiple of 4 due to the way buffers are
458   filled (in 1/4's).
459 */
460
461 #define READ_LOOK_AHEAD 4 
462 EXTERN_ uint8_t ***frame_buffers;
463
464
465 /* These determine what input format to use */
466 EXTERN_ mpeg3_t *mpeg_file;
467 EXTERN_ int do_stdin;
468 EXTERN_ FILE *stdin_fd;
469
470
471 EXTERN_ int do_buffers;
472 EXTERN_ pthread_mutex_t input_lock;
473 EXTERN_ pthread_mutex_t output_lock;
474 EXTERN_ pthread_mutex_t copy_lock;
475 EXTERN_ char *input_buffer_y;
476 EXTERN_ char *input_buffer_u;
477 EXTERN_ char *input_buffer_v;
478 EXTERN_ int input_buffer_end;
479
480
481 EXTERN_ int verbose;
482 EXTERN_ unsigned char *frame_buffer;
483 EXTERN_ unsigned char **row_pointers;
484 EXTERN_ int fixed_mquant;
485 EXTERN_ double quant_floor;             /* quantisation floor [1..10] (0 for CBR) */
486 EXTERN_ double act_boost;               /* Quantisation reduction for highly active blocks */
487 EXTERN_ int use_hires_quant;
488 EXTERN_ int use_denoise_quant;
489 /* Number of processors */
490 EXTERN_ int processors;
491 EXTERN_ long start_frame, end_frame;    /* Range to encode in source framerate units */
492 EXTERN_ int seq_header_every_gop;
493
494 /* coding model parameters */
495
496 EXTERN_ int N; /* number of frames in Group of Pictures */
497 EXTERN_ int M; /* distance between I/P frames */
498 EXTERN_ int P; /* intra slice refresh interval */
499 EXTERN_ int nframes; /* total number of frames to encode */
500 EXTERN_ long frames_scaled; /* frame count normalized to output frame rate */
501 EXTERN_ int frame0, tc0; /* number and timecode of first frame */
502 EXTERN_ int mpeg1; /* ISO/IEC IS 11172-2 sequence */
503 EXTERN_ int fieldpic; /* use field pictures */
504
505 /* sequence specific data (sequence header) */
506
507 EXTERN_ int qsubsample_offset, 
508            fsubsample_offset,
509                rowsums_offset,
510                colsums_offset;          /* Offset from picture buffer start of sub-sampled data... */
511 EXTERN_ int mb_per_pict;                        /* Number of macro-blocks in a picture */                                                     
512 EXTERN_ int fast_mc_frac;        /* inverse proportion of fast motion estimates
513                                                          consider in detail */
514 EXTERN_ int mc_44_red;                  /* Sub-mean population reduction passes for 4x4 and 2x2 */
515 EXTERN_ int mc_22_red;                  /* Motion compensation stages                                           */
516
517
518
519 EXTERN_ int horizontal_size, vertical_size; /* frame size (pels) */
520 EXTERN_ int width, height; /* encoded frame size (pels) multiples of 16 or 32 */
521 EXTERN_ int chrom_width, chrom_height, block_count;
522 EXTERN_ int mb_width, mb_height; /* frame size (macroblocks) */
523 EXTERN_ int width2, height2, mb_height2, chrom_width2; /* picture size adjusted for interlacing */
524 EXTERN_ int aspectratio; /* aspect ratio information (pel or display) */
525 EXTERN_ int frame_rate_code; /* coded value of frame rate */
526 EXTERN_ int dctsatlim;                  /* Value to saturated DCT coeffs to */
527 EXTERN_ double frame_rate; /* frames per second */
528 EXTERN_ double input_frame_rate; /* input frame rate */
529 EXTERN_ double bit_rate; /* bits per second */
530 EXTERN_ int video_buffer_size;
531 EXTERN_ int vbv_buffer_size; /* size of VBV buffer (* 16 kbit) */
532 EXTERN_ int constrparms; /* constrained parameters flag (MPEG-1 only) */
533 EXTERN_ int load_iquant, load_niquant; /* use non-default quant. matrices */
534 EXTERN_ int load_ciquant,load_cniquant;
535
536
537 /* sequence specific data (sequence extension) */
538
539 EXTERN_ int profile, level; /* syntax / parameter constraints */
540 EXTERN_ int prog_seq; /* progressive sequence */
541 EXTERN_ int chroma_format;
542 EXTERN_ int low_delay; /* no B pictures, skipped pictures */
543
544
545 /* sequence specific data (sequence display extension) */
546
547 EXTERN_ int video_format; /* component, PAL, NTSC, SECAM or MAC */
548 EXTERN_ int color_primaries; /* source primary chromaticity coordinates */
549 EXTERN_ int transfer_characteristics; /* opto-electronic transfer char. (gamma) */
550 EXTERN_ int matrix_coefficients; /* Eg,Eb,Er / Y,Cb,Cr matrix coefficients */
551 EXTERN_ int display_horizontal_size, display_vertical_size; /* display size */
552
553
554 /* picture specific data (picture coding extension) */
555 EXTERN_ int opt_dc_prec;
556 EXTERN_ int opt_prog_frame;
557 EXTERN_ int opt_repeatfirst;
558 EXTERN_ int opt_topfirst;
559
560 /* use only frame prediction and frame DCT (I,P,B,current) */
561 EXTERN_ int frame_pred_dct_tab[3];
562 EXTERN_ int conceal_tab[3]; /* use concealment motion vectors (I,P,B) */
563 EXTERN_ int qscale_tab[3]; /* linear/non-linear quantizaton table */
564 EXTERN_ int intravlc_tab[3]; /* intra vlc format (I,P,B,current) */
565 EXTERN_ int altscan_tab[3]; /* alternate scan (I,P,B,current) */
566
567 /* prototypes of global functions */
568
569 /* conform.c */
570 void range_checks _ANSI_ARGS_((void));
571 void profile_and_level_checks _ANSI_ARGS_(());
572
573 /* fdctref.c */
574 void init_fdct _ANSI_ARGS_((void));
575
576 /* idct.c */
577 void init_idct _ANSI_ARGS_((void));
578
579 /* motion.c */
580 void motion_estimation _ANSI_ARGS_((pict_data_s *picture,
581         motion_comp_s *mc_data,
582         int secondfield, int ipflag));
583 void init_motion();
584 void start_motion_engines();
585 void stop_motion_engines();
586 void fast_motion_data(uint8_t *blk, int picture_struct);
587
588
589 /* mpeg2enc.c */
590 void error _ANSI_ARGS_((char *text));
591
592 /* predict.c */
593 void predict _ANSI_ARGS_((pict_data_s *picture, 
594                          uint8_t *reff[],
595                          uint8_t *refb[],
596                          uint8_t *cur[3],
597                          int secondfield));
598 void init_predict_hv();
599
600 /* putbits.c */
601 void slice_initbits(slice_engine_t *engine);
602 void slice_putbits(slice_engine_t *engine, long val, int n);
603 void slice_alignbits(slice_engine_t *engine);
604 void slice_finishslice(slice_engine_t *engine);
605
606
607 void mpeg2_initbits _ANSI_ARGS_((void));
608 void mpeg2enc_putbits _ANSI_ARGS_((int val, int n));
609 void putbits _ANSI_ARGS_((int val, int n));
610 void alignbits _ANSI_ARGS_((void));
611 double bitcount _ANSI_ARGS_((void));
612
613 /* puthdr.c */
614 void putseqhdr _ANSI_ARGS_((void));
615 void putseqext _ANSI_ARGS_((void));
616 void putseqdispext _ANSI_ARGS_((void));
617 void putuserdata _ANSI_ARGS_((char *userdata));
618 void putgophdr _ANSI_ARGS_((int frame, int closed_gop));
619 void putpicthdr _ANSI_ARGS_((pict_data_s *picture));
620 void putpictcodext _ANSI_ARGS_((pict_data_s *picture));
621 void putseqend _ANSI_ARGS_((void));
622
623 /* putmpg.c */
624 void putintrablk _ANSI_ARGS_((slice_engine_t *engine, pict_data_s *picture, short *blk, int cc));
625 void putnonintrablk _ANSI_ARGS_((slice_engine_t *engine, pict_data_s *picture, short *blk));
626 void putmv _ANSI_ARGS_((slice_engine_t *engine, int dmv, int f_code));
627
628 /* putpic.c */
629 void putpict _ANSI_ARGS_((pict_data_s *picture));
630 void start_slice_engines();
631 void stop_slice_engines();
632
633 /* putseq.c */
634 void putseq _ANSI_ARGS_((void));
635
636 /* putvlc.c */
637 void putDClum _ANSI_ARGS_((slice_engine_t *engine, int val));
638 void putDCchrom _ANSI_ARGS_((slice_engine_t *engine, int val));
639 void putACfirst _ANSI_ARGS_((slice_engine_t *engine, int run, int val));
640 void putAC _ANSI_ARGS_((slice_engine_t *engine, int run, int signed_level, int vlcformat));
641 void putaddrinc _ANSI_ARGS_((slice_engine_t *engine, int addrinc));
642 void putmbtype _ANSI_ARGS_((slice_engine_t *engine, int pict_type, int mb_type));
643 void putmotioncode _ANSI_ARGS_((slice_engine_t *engine, int motion_code));
644 void putdmv _ANSI_ARGS_((slice_engine_t *engine, int dmv));
645 void putcbp _ANSI_ARGS_((slice_engine_t *engine, int cbp));
646
647 extern int (*pquant_non_intra)(pict_data_s *picture, int16_t *src, int16_t *dst,
648                                                 int mquant, int *nonsat_mquant);
649
650 extern int (*pquant_weight_coeff_sum)(int16_t *blk, uint16_t*i_quant_mat );
651
652 /* quantize.c */
653
654 void iquantize( pict_data_s *picture );
655 void quant_intra_hv (   pict_data_s *picture,
656                                         int16_t *src, int16_t *dst, 
657                                         int mquant, int *nonsat_mquant);
658 int quant_non_intra_hv( pict_data_s *picture,
659                                                    int16_t *src, int16_t *dst,
660                                                         int mquant, int *nonsat_mquant);
661 void iquant_intra ( int16_t *src, int16_t *dst, int dc_prec, int mquant);
662 void iquant_non_intra (int16_t *src, int16_t *dst, int mquant);
663 void init_quantizer_hv();
664 int  next_larger_quant_hv( pict_data_s *picture, int quant );
665
666 extern int (*pquant_non_intra)(pict_data_s *picture, int16_t *src, int16_t *dst,
667                                                 int mquant, int *nonsat_mquant);
668
669 extern int (*pquant_weight_coeff_sum)(int16_t *blk, uint16_t*i_quant_mat );
670
671 /* ratectl.c */
672 void ratectl_init_seq _ANSI_ARGS_((ratectl_t *ratectl));
673 void ratectl_init_GOP _ANSI_ARGS_((ratectl_t *ratectl, int np, int nb));
674 void ratectl_init_pict _ANSI_ARGS_((ratectl_t *ratectl, pict_data_s *picture));
675 void ratectl_update_pict _ANSI_ARGS_((ratectl_t *ratectl, pict_data_s *picture));
676 int ratectl_start_mb _ANSI_ARGS_((ratectl_t *ratectl, pict_data_s *picture));
677 int ratectl_calc_mquant _ANSI_ARGS_((ratectl_t *ratectl, pict_data_s *picture, int j));
678 void vbv_end_of_picture _ANSI_ARGS_((void));
679 void calc_vbv_delay _ANSI_ARGS_((void));
680
681 /* readpic.c */
682 void readframe _ANSI_ARGS_((int frame_num, uint8_t *frame[]));
683
684 /* stats.c */
685 void calcSNR _ANSI_ARGS_((unsigned char *org[3], unsigned char *rec[3]));
686 void stats _ANSI_ARGS_((void));
687
688 /* transfrm.c */
689 void transform _ANSI_ARGS_((pict_data_s *picture,
690                                 uint8_t *pred[], 
691                                 uint8_t *cur[]));
692 void itransform _ANSI_ARGS_((pict_data_s *picture,
693                                   uint8_t *pred[], uint8_t *cur[]));
694 void dct_type_estimation _ANSI_ARGS_((pict_data_s *picture,
695         uint8_t *pred, uint8_t *cur));
696 void init_transform_hv();
697 void start_transform_engines();
698 void stop_transform_engines();
699 void start_itransform_engines();
700 void stop_itransform_engines();
701
702 /* writepic.c */
703 void writeframe(int number, unsigned char *frame[]);