OSDN Git Service

WinGui:
[handbrake-jp/handbrake-jp-git.git] / libhb / common.h
1 /* $Id: common.h,v 1.51 2005/11/04 13:09:40 titer Exp $
2
3    This file is part of the HandBrake source code.
4    Homepage: <http://handbrake.fr/>.
5    It may be used under the terms of the GNU General Public License. */
6
7 #ifndef HB_COMMON_H
8 #define HB_COMMON_H
9
10 #include <math.h>
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <stdarg.h>
14 #include <string.h>
15 #include <unistd.h>
16 #include <inttypes.h>
17 #include <sys/types.h>
18 #include <sys/stat.h>
19 #include <dirent.h>
20
21 #if defined( __GNUC__ ) && !(defined( _WIN32 ) || defined( __MINGW32__ ))
22 #   define HB_WPRINTF(s,v) __attribute__((format(printf,s,v)))
23 #else
24 #   define HB_WPRINTF(s,v)
25 #endif
26
27 #if defined( SYS_MINGW )
28 #   define fseek fseeko64
29 #   define ftell ftello64
30 #   undef  fseeko
31 #   define fseeko fseeko64
32 #   undef  ftello
33 #   define ftello ftello64
34 #   define flockfile(...)
35 #   define funlockfile(...)
36 #   define getc_unlocked getc
37 #   undef  off_t
38 #   define off_t off64_t
39 #endif
40
41 #ifndef MIN
42 #define MIN( a, b ) ( (a) > (b) ? (b) : (a) )
43 #endif
44 #ifndef MAX
45 #define MAX( a, b ) ( (a) > (b) ? (a) : (b) )
46 #endif
47
48 #define EVEN( a )        ( (a) + ( (a) & 1 ) )
49 #define MULTIPLE_16( a ) ( 16 * ( ( (a) + 8 ) / 16 ) )
50 #define MULTIPLE_MOD( a, b ) ((b==1)?a:( b * ( ( (a) + (b / 2) - 1) / b ) ))
51 #define MULTIPLE_MOD_DOWN( a, b ) ((b==1)?a:( b * ( (a) / b ) ))
52
53 #define HB_DVD_READ_BUFFER_SIZE 2048
54
55 typedef struct hb_handle_s hb_handle_t;
56 typedef struct hb_list_s hb_list_t;
57 typedef struct hb_rate_s hb_rate_t;
58 typedef struct hb_mixdown_s hb_mixdown_t;
59 typedef struct hb_job_s  hb_job_t;
60 typedef struct hb_title_s hb_title_t;
61 typedef struct hb_chapter_s hb_chapter_t;
62 typedef struct hb_audio_s hb_audio_t;
63 typedef struct hb_audio_config_s hb_audio_config_t;
64 typedef struct hb_subtitle_s hb_subtitle_t;
65 typedef struct hb_subtitle_config_s hb_subtitle_config_t;
66 typedef struct hb_metadata_s hb_metadata_t;
67 typedef struct hb_state_s hb_state_t;
68 typedef union  hb_esconfig_u     hb_esconfig_t;
69 typedef struct hb_work_private_s hb_work_private_t;
70 typedef struct hb_work_object_s  hb_work_object_t;
71 typedef struct hb_filter_private_s hb_filter_private_t;
72 typedef struct hb_filter_object_s  hb_filter_object_t;
73 typedef struct hb_buffer_s hb_buffer_t;
74 typedef struct hb_fifo_s hb_fifo_t;
75 typedef struct hb_lock_s hb_lock_t;
76
77 #include "ports.h"
78 #ifdef __LIBHB__
79 #include "internal.h"
80 #define PRIVATE
81 #else
82 #define PRIVATE const
83 #endif
84
85 hb_list_t * hb_list_init();
86 int         hb_list_count( hb_list_t * );
87 void        hb_list_add( hb_list_t *, void * );
88 void        hb_list_rem( hb_list_t *, void * );
89 void      * hb_list_item( hb_list_t *, int );
90 void        hb_list_close( hb_list_t ** );
91
92 void hb_reduce( int *x, int *y, int num, int den );
93
94 #define HB_KEEP_WIDTH  0
95 #define HB_KEEP_HEIGHT 1
96 void hb_fix_aspect( hb_job_t * job, int keep );
97
98 int hb_calc_bitrate( hb_job_t *, int size );
99
100 hb_audio_t *hb_audio_copy(const hb_audio_t *src);
101 void hb_audio_config_init(hb_audio_config_t * audiocfg);
102 int hb_audio_add(const hb_job_t * job, const hb_audio_config_t * audiocfg);
103 hb_audio_config_t * hb_list_audio_config_item(hb_list_t * list, int i);
104
105 int hb_subtitle_add(const hb_job_t * job, const hb_subtitle_config_t * subtitlecfg, int track);
106 int hb_srt_add(const hb_job_t * job, const hb_subtitle_config_t * subtitlecfg, 
107                const char *lang);
108
109
110 struct hb_rate_s
111 {
112     char * string;
113     int    rate;
114 };
115
116 struct hb_mixdown_s
117 {
118     char * human_readable_name;
119     char * internal_name;
120     char * short_name;
121     int    amixdown;
122 };
123
124 struct hb_subtitle_config_s
125 {
126     enum subdest { RENDERSUB, PASSTHRUSUB } dest;
127     int  force;
128     int  default_track; 
129     
130     /* SRT subtitle tracks only */
131     char src_filename[128];
132     char src_codeset[40];
133     int64_t offset;
134 };
135
136 #define HB_VIDEO_RATE_BASE   27000000
137
138 extern hb_rate_t    hb_video_rates[];
139 extern int          hb_video_rates_count;
140 extern hb_rate_t    hb_audio_rates[];
141 extern int          hb_audio_rates_count;
142 extern int          hb_audio_rates_default;
143 extern hb_rate_t    hb_audio_bitrates[];
144 extern int          hb_audio_bitrates_count;
145 extern int          hb_audio_bitrates_default;
146 extern hb_mixdown_t hb_audio_mixdowns[];
147 extern int          hb_audio_mixdowns_count;
148 int hb_mixdown_get_mixdown_from_short_name( const char * short_name );
149 const char * hb_mixdown_get_short_name_from_mixdown( int amixdown );
150
151 /******************************************************************************
152  * hb_job_t: settings to be filled by the UI
153  *****************************************************************************/
154 struct hb_job_s
155 {
156     /* ID assigned by UI so it can groups job passes together */
157     int             sequence_id;
158
159     /* Pointer to the title to be ripped */
160     hb_title_t    * title;
161     int             feature; // Detected DVD feature title
162
163     /* Chapter selection */
164     int             chapter_start;
165     int             chapter_end;
166
167         /* Include chapter marker track in mp4? */
168     int             chapter_markers;
169
170     /* Picture settings:
171          crop:                must be multiples of 2 (top/bottom/left/right)
172          deinterlace:         0 or 1
173          width:               must be a multiple of 2
174          height:              must be a multiple of 2
175          keep_ratio:          used by UIs
176          grayscale:           black and white encoding
177          pixel_ratio:         store pixel aspect ratio in the video
178          pixel_aspect_width:  numerator for pixel aspect ratio
179          pixel_aspect_height: denominator for pixel aspect ratio
180          modulus:             set a number for dimensions to be multiples of
181          maxWidth:            keep width below this
182          maxHeight:           keep height below this */
183     int             crop[4];
184     int             deinterlace;
185     hb_list_t     * filters;
186     int             width;
187     int             height;
188     int             keep_ratio;
189     int             grayscale;
190
191     struct
192     {
193         int             mode;
194         int             itu_par;
195         int             par_width;
196         int             par_height;
197         int             dar_width;
198         int             dar_height;
199         int             keep_display_aspect;
200     } anamorphic;
201
202     int             modulus;
203     int             maxWidth;
204     int             maxHeight;
205
206     /* Video settings:
207          vcodec:            output codec
208          vquality:          output quality (0.0..1.0)
209                             if < 0.0 or > 1.0, bitrate is used instead,
210                             except with x264, to use its real QP/RF scale
211          vbitrate:          output bitrate (kbps)
212          vrate, vrate_base: output framerate is vrate / vrate_base
213          cfr:               0 (vfr), 1 (cfr), 2 (pfr) [see render.c]
214          pass:              0, 1 or 2 (or -1 for scan)
215          h264_level:        vestigial boolean to decide if we're encoding for iPod
216          x264opts:          string of extra x264 options
217          areBframes:        boolean to note if b-frames are included in x264opts */
218 #define HB_VCODEC_MASK   0x0000FF
219 #define HB_VCODEC_FFMPEG 0x000001
220 #define HB_VCODEC_X264   0x000002
221 #define HB_VCODEC_THEORA 0x000004
222
223     int             vcodec;
224     float           vquality;
225     int             vbitrate;
226     int             vrate;
227     int             vrate_base;
228     int             vfr;
229     int             cfr;
230     int             pass;
231     int             h264_13;
232     int             h264_level;
233     char            *x264opts;
234     int             areBframes;
235     int             color_matrix;
236
237     /* List of audio settings. */
238     hb_list_t     * list_audio;
239
240     /* Subtitles
241      */
242     hb_list_t     * list_subtitle;
243
244     /* Muxer settings
245          mux:  output file format
246          file: file path */
247 #define HB_MUX_MASK 0xFF0000
248 #define HB_MUX_MP4  0x010000
249 #define HB_MUX_PSP  0x020000
250 #define HB_MUX_AVI  0x040000
251 #define HB_MUX_OGM  0x080000
252 #define HB_MUX_IPOD 0x100000
253 #define HB_MUX_MKV  0x200000
254
255     int             mux;
256     const char          * file;
257
258     /* Allow MP4 files > 4 gigs */
259     int             largeFileSize;
260     int             mp4_optimize;
261     int             ipod_atom;
262
263     int                     indepth_scan;
264     hb_subtitle_config_t    select_subtitle_config;
265
266     int             angle;              // dvd angle to encode
267     int             frame_to_start;     // declare eof when we hit this frame
268     int64_t         pts_to_start;       // drop frames until  we pass this pts 
269                                         //  in the time-linearized input stream
270     int             frame_to_stop;      // declare eof when we hit this frame
271     int64_t         pts_to_stop;        // declare eof when we pass this pts in
272                                         //  the time-linearized input stream
273     int             start_at_preview;   // if non-zero, encoding will start
274                                         //  at the position of preview n
275     int             seek_points;        //  out of N previews
276     uint32_t        frames_to_skip;     // decode but discard this many frames
277                                         //  initially (for frame accurate positioning
278                                         //  to non-I frames).
279
280 #ifdef __LIBHB__
281     /* Internal data */
282     hb_handle_t   * h;
283     hb_lock_t     * pause;
284     volatile int  * die;
285     volatile int    done;
286
287     uint64_t        st_pause_date;
288     uint64_t        st_paused;
289
290     hb_fifo_t     * fifo_mpeg2;   /* MPEG-2 video ES */
291     hb_fifo_t     * fifo_raw;     /* Raw pictures */
292     hb_fifo_t     * fifo_sync;    /* Raw pictures, framerate corrected */
293     hb_fifo_t     * fifo_render;  /* Raw pictures, scaled */
294     hb_fifo_t     * fifo_mpeg4;   /* MPEG-4 video ES */
295
296     hb_thread_t   * reader;
297
298     hb_list_t     * list_work;
299
300     hb_esconfig_t config;
301
302     hb_mux_data_t * mux_data;
303 #endif
304 };
305
306 /* Audio starts here */
307 /* Audio Codecs */
308 #define HB_ACODEC_MASK   0x00FF00
309 #define HB_ACODEC_FAAC   0x000100
310 #define HB_ACODEC_LAME   0x000200
311 #define HB_ACODEC_VORBIS 0x000400
312 #define HB_ACODEC_AC3    0x000800
313 #define HB_ACODEC_MPGA   0x001000
314 #define HB_ACODEC_LPCM   0x002000
315 #define HB_ACODEC_DCA    0x004000
316 #define HB_ACODEC_FFMPEG 0x008000
317 #define HB_ACODEC_CA_AAC 0x010000
318
319 /* Audio Mixdown */
320 /* define some masks, used to extract the various information from the HB_AMIXDOWN_XXXX values */
321 #define HB_AMIXDOWN_DCA_FORMAT_MASK             0x00FFF000
322 #define HB_AMIXDOWN_A52_FORMAT_MASK             0x00000FF0
323 #define HB_AMIXDOWN_DISCRETE_CHANNEL_COUNT_MASK 0x0000000F
324 /* define the HB_AMIXDOWN_XXXX values */
325 #define HB_AMIXDOWN_MONO                        0x01000001
326 // DCA_FORMAT of DCA_MONO                  = 0    = 0x000
327 // A52_FORMAT of A52_MONO                  = 1    = 0x01
328 // discrete channel count of 1
329 #define HB_AMIXDOWN_STEREO                      0x02002022
330 // DCA_FORMAT of DCA_STEREO                = 2    = 0x002
331 // A52_FORMAT of A52_STEREO                = 2    = 0x02
332 // discrete channel count of 2
333 #define HB_AMIXDOWN_DOLBY                       0x042070A2
334 // DCA_FORMAT of DCA_3F1R | DCA_OUT_DPLI   = 519  = 0x207
335 // A52_FORMAT of A52_DOLBY                 = 10   = 0x0A
336 // discrete channel count of 2
337 #define HB_AMIXDOWN_DOLBYPLII                   0x084094A2
338 // DCA_FORMAT of DCA_3F2R | DCA_OUT_DPLII  = 1033 = 0x409
339 // A52_FORMAT of A52_DOLBY | A52_USE_DPLII = 74   = 0x4A
340 // discrete channel count of 2
341 #define HB_AMIXDOWN_6CH                         0x10089176
342 // DCA_FORMAT of DCA_3F2R | DCA_LFE        = 137  = 0x089
343 // A52_FORMAT of A52_3F2R | A52_LFE        = 23   = 0x17
344 // discrete channel count of 6
345 /* define some macros to extract the various information from the HB_AMIXDOWN_XXXX values */
346 #define HB_AMIXDOWN_GET_DCA_FORMAT( a ) ( ( a & HB_AMIXDOWN_DCA_FORMAT_MASK ) >> 12 )
347 #define HB_AMIXDOWN_GET_A52_FORMAT( a ) ( ( a & HB_AMIXDOWN_A52_FORMAT_MASK ) >> 4 )
348 #define HB_AMIXDOWN_GET_DISCRETE_CHANNEL_COUNT( a ) ( ( a & HB_AMIXDOWN_DISCRETE_CHANNEL_COUNT_MASK ) )
349
350 /* Input Channel Layout */
351 /* define some masks, used to extract the various information from the HB_AMIXDOWN_XXXX values */
352 #define HB_INPUT_CH_LAYOUT_DISCRETE_FRONT_MASK  0x00F0000
353 #define HB_INPUT_CH_LAYOUT_DISCRETE_REAR_MASK   0x000F000
354 #define HB_INPUT_CH_LAYOUT_DISCRETE_LFE_MASK    0x0000F00
355 #define HB_INPUT_CH_LAYOUT_DISCRETE_NO_LFE_MASK 0xFFFF0FF
356 #define HB_INPUT_CH_LAYOUT_ENCODED_FRONT_MASK   0x00000F0
357 #define HB_INPUT_CH_LAYOUT_ENCODED_REAR_MASK    0x000000F
358 /* define the input channel layouts used to describe the channel layout of this audio */
359 #define HB_INPUT_CH_LAYOUT_MONO    0x0110010
360 #define HB_INPUT_CH_LAYOUT_STEREO  0x0220020
361 #define HB_INPUT_CH_LAYOUT_DOLBY   0x0320031
362 #define HB_INPUT_CH_LAYOUT_3F      0x0430030
363 #define HB_INPUT_CH_LAYOUT_2F1R    0x0521021
364 #define HB_INPUT_CH_LAYOUT_3F1R    0x0631031
365 #define HB_INPUT_CH_LAYOUT_2F2R    0x0722022
366 #define HB_INPUT_CH_LAYOUT_3F2R    0x0832032
367 #define HB_INPUT_CH_LAYOUT_4F2R    0x0942042
368 #define HB_INPUT_CH_LAYOUT_3F4R    0x0a34034
369 #define HB_INPUT_CH_LAYOUT_HAS_LFE 0x0000100
370 /* define some macros to extract the various information from the HB_AMIXDOWN_XXXX values */
371 #define HB_INPUT_CH_LAYOUT_GET_DISCRETE_FRONT_COUNT( a ) ( ( a & HB_INPUT_CH_LAYOUT_DISCRETE_FRONT_MASK ) >> 16 )
372 #define HB_INPUT_CH_LAYOUT_GET_DISCRETE_REAR_COUNT( a )  ( ( a & HB_INPUT_CH_LAYOUT_DISCRETE_REAR_MASK ) >> 12 )
373 #define HB_INPUT_CH_LAYOUT_GET_DISCRETE_LFE_COUNT( a )   ( ( a & HB_INPUT_CH_LAYOUT_DISCRETE_LFE_MASK ) >> 8 )
374 #define HB_INPUT_CH_LAYOUT_GET_DISCRETE_COUNT( a ) ( ( ( a & HB_INPUT_CH_LAYOUT_DISCRETE_FRONT_MASK ) >> 16 ) + ( ( a & HB_INPUT_CH_LAYOUT_DISCRETE_REAR_MASK ) >> 12 ) + ( ( a & HB_INPUT_CH_LAYOUT_DISCRETE_LFE_MASK ) >> 8 ) )
375 #define HB_INPUT_CH_LAYOUT_GET_ENCODED_FRONT_COUNT( a )   ( ( a & HB_INPUT_CH_LAYOUT_ENCODED_FRONT_MASK ) >> 4 )
376 #define HB_INPUT_CH_LAYOUT_GET_ENCODED_REAR_COUNT( a )   ( ( a & HB_INPUT_CH_LAYOUT_ENCODED_REAR_MASK ) )
377
378 struct hb_audio_config_s
379 {
380     /* Output */
381     struct
382     {
383             int track;      /* Output track number */
384             uint32_t codec;  /* Output audio codec.
385                                  * HB_ACODEC_AC3 means pass-through, then bitrate and samplerate
386                                  * are ignored.
387                                  */
388             int samplerate; /* Output sample rate (Hz) */
389             int bitrate;    /* Output bitrate (kbps) */
390             int mixdown;    /* The mixdown format to be used for this audio track (see HB_AMIXDOWN_*) */
391             double dynamic_range_compression; /* Amount of DRC that gets applied to this track */
392             char * name;    /* Output track name */
393     } out;
394
395     /* Input */
396     struct
397     {
398         int track;                /* Input track number */
399         PRIVATE uint32_t codec;   /* Input audio codec */
400         PRIVATE uint32_t codec_param; /* per-codec config info */
401         PRIVATE uint32_t version; /* Bitsream version */
402         PRIVATE uint32_t mode;    /* Bitstream mode, codec dependent encoding */
403         PRIVATE int samplerate; /* Input sample rate (Hz) */
404         PRIVATE int bitrate;    /* Input bitrate (kbps) */
405         PRIVATE int channel_layout;
406         /* channel_layout is the channel layout of this audio this is used to
407         * provide a common way of describing the source audio
408         */
409     } in;
410
411     /* Misc. */
412     union
413     {
414         PRIVATE int ac3;    /* flags.ac3 is only set when the source audio format is HB_ACODEC_AC3 */
415         PRIVATE int dca;    /* flags.dca is only set when the source audio format is HB_ACODEC_DCA */
416     } flags;
417 #define AUDIO_F_DOLBY (1 << 31)  /* set if source uses Dolby Surround */
418
419     struct
420     {
421         PRIVATE char description[1024];
422         PRIVATE char simple[1024];
423         PRIVATE char iso639_2[4];
424         PRIVATE uint8_t type; /* normal, visually impared, directors */
425     } lang;
426 };
427
428 #ifdef __LIBHB__
429 struct hb_audio_s
430 {
431     int id;
432
433     hb_audio_config_t config;
434
435     struct {
436         hb_fifo_t * fifo_in;   /* AC3/MPEG/LPCM ES */
437         hb_fifo_t * fifo_raw;  /* Raw audio */
438         hb_fifo_t * fifo_sync; /* Resampled, synced raw audio */
439         hb_fifo_t * fifo_out;  /* MP3/AAC/Vorbis ES */
440
441         hb_esconfig_t config;
442         hb_mux_data_t * mux_data;
443         hb_fifo_t     * scan_cache;
444     } priv;
445 };
446 #endif
447
448 struct hb_chapter_s
449 {
450     int      index;
451     int      pgcn;
452     int      pgn;
453     int      cell_start;
454     int      cell_end;
455     int      block_start;
456     int      block_end;
457     int      block_count;
458
459     /* Visual-friendly duration */
460     int      hours;
461     int      minutes;
462     int      seconds;
463
464     /* Exact duration (in 1/90000s) */
465     uint64_t duration;
466
467     /* Optional chapter title */
468     char     title[1024];
469 };
470
471 /*
472  * A subtitle track.
473  * 
474  * Required fields when a demuxer creates a subtitle track are:
475  * > id
476  *     - ID of this track
477  *     - must be unique for all tracks within a single job,
478  *       since it is used to look up the appropriate in-FIFO with GetFifoForId()
479  * > format
480  *     - format of the packets the subtitle decoder work-object sends to sub->fifo_raw
481  *     - for passthru subtitles, is also the format of the final packets sent to sub->fifo_out
482  *     - PICTURESUB for banded 8-bit YAUV pixels; see decvobsub.c documentation for more info
483  *     - TEXTSUB for UTF-8 text marked up with <b>, <i>, or <u>
484  *     - read by the muxers, and by the subtitle burn-in logic in the hb_sync_video work-object
485  * > source
486  *     - used to create the appropriate subtitle decoder work-object in do_job()
487  * > config.dest
488  *     - whether to render the subtitle on the video track (RENDERSUB) or 
489  *       to pass it through its own subtitle track in the output container (PASSTHRUSUB)
490  *     - for legacy compatibility, all newly created VOBSUB tracks should default to RENDERSUB
491  *     - since only VOBSUBs are renderable (as of 2010-04-25), all other newly created
492  *       subtitle track types should default to PASSTHRUSUB
493  * > lang
494  *     - user-readable description of the subtitle track
495  *     - may correspond to the language of the track (see the 'iso639_2' field)
496  *     - may correspond to the type of track (see the 'type' field; ex: "Closed Captions")
497  * > iso639_2
498  *     - language code for the subtitle, or "und" if unknown
499  */
500 struct hb_subtitle_s
501 {
502     int  id;
503     int  track;
504
505     hb_subtitle_config_t config;
506
507     enum subtype { PICTURESUB, TEXTSUB } format;
508     enum subsource { VOBSUB, SRTSUB, CC608SUB, /*unused*/CC708SUB, UTF8SUB, TX3GSUB, SSASUB } source;
509     char lang[1024];
510     char iso639_2[4];
511     uint8_t type; /* Closed Caption, Childrens, Directors etc */
512     
513     // Color lookup table for VOB subtitle tracks. Each entry is in YCbCr format.
514     // Must be filled out by the demuxer for VOB subtitle tracks.
515     uint32_t    palette[16];
516     int         width;
517     int         height;
518
519     int hits;     /* How many hits/occurrences of this subtitle */
520     int forced_hits; /* How many forced hits in this subtitle */
521
522 #ifdef __LIBHB__
523     /* Internal data */
524     hb_fifo_t * fifo_in;  /* SPU ES */
525     hb_fifo_t * fifo_raw; /* Decoded SPU */
526     hb_fifo_t * fifo_sync;/* Synced */
527     hb_fifo_t * fifo_out; /* Correct Timestamps, ready to be muxed */
528     hb_mux_data_t * mux_data;
529 #endif
530 };
531
532 struct hb_metadata_s 
533 {
534     char  name[255];
535     char  artist[255];
536     char  composer[255];
537     char  release_date[255];
538     char  comment[1024];
539     char  album[255];
540     char  genre[255];
541     uint32_t coverart_size;
542     uint8_t *coverart;
543 };
544
545 struct hb_title_s
546 {
547     enum { HB_DVD_TYPE, HB_STREAM_TYPE } type;
548     char        path[1024];
549     char        name[1024];
550     int         index;
551     int         vts;
552     int         ttn;
553     int         cell_start;
554     int         cell_end;
555     int         block_start;
556     int         block_end;
557     int         block_count;
558     int         angle_count;
559
560     /* Visual-friendly duration */
561     int         hours;
562     int         minutes;
563     int         seconds;
564
565     /* Exact duration (in 1/90000s) */
566     uint64_t    duration;
567
568     double      aspect;             // aspect ratio for the title's video
569     double      container_aspect;   // aspect ratio from container (0 if none)
570     int         width;
571     int         height;
572     int         pixel_aspect_width;
573     int         pixel_aspect_height;
574     int         rate;
575     int         rate_base;
576     int         crop[4];
577     enum { HB_MPEG2_PS_DEMUXER = 0, HB_MPEG2_TS_DEMUXER, HB_NULL_DEMUXER } demuxer;
578     int         detected_interlacing;
579     int         video_id;               /* demuxer stream id for video */
580     int         video_codec;            /* worker object id of video codec */
581     int         video_codec_param;      /* codec specific config */
582     const char  *video_codec_name;
583     int         video_bitrate;
584     const char  *container_name;
585     int         data_rate;
586
587     hb_metadata_t *metadata;
588
589     hb_list_t * list_chapter;
590     hb_list_t * list_audio;
591     hb_list_t * list_subtitle;
592
593     /* Job template for this title */
594     hb_job_t  * job;
595
596     uint32_t    flags;
597                 // set if video stream doesn't have IDR frames
598 #define         HBTF_NO_IDR (1 << 0)
599 };
600
601
602 struct hb_state_s
603 {
604 #define HB_STATE_IDLE     1
605 #define HB_STATE_SCANNING 2
606 #define HB_STATE_SCANDONE 4
607 #define HB_STATE_WORKING  8
608 #define HB_STATE_PAUSED   16
609 #define HB_STATE_WORKDONE 32
610 #define HB_STATE_MUXING   64
611 #define HB_STATE_SEARCHING 128
612     int state;
613
614     union
615     {
616         struct
617         {
618             /* HB_STATE_SCANNING */
619             int title_cur;
620             int title_count;
621         } scanning;
622
623         struct
624         {
625             /* HB_STATE_WORKING */
626             float progress;
627             int   job_cur;
628             int   job_count;
629             float rate_cur;
630             float rate_avg;
631             int   hours;
632             int   minutes;
633             int   seconds;
634             int   sequence_id;
635         } working;
636
637         struct
638         {
639             /* HB_STATE_WORKDONE */
640 #define HB_ERROR_NONE     0
641 #define HB_ERROR_CANCELED 1
642 #define HB_ERROR_UNKNOWN  2
643             int error;
644         } workdone;
645
646         struct
647         {
648             /* HB_STATE_MUXING */
649             float progress;
650         } muxing;
651     } param;
652 };
653
654 typedef struct hb_work_info_s
655 {
656     const char *name;
657     int     profile;
658     int     level;
659     int     bitrate;
660     int     rate;
661     int     rate_base;
662     int     flags;
663     int     version;
664     int     mode;
665     union {
666         struct {    // info only valid for video decoders
667             int     width;
668             int     height;
669             int     pixel_aspect_width;
670             int     pixel_aspect_height;
671             double  aspect;
672         };
673         struct {    // info only valid for audio decoders
674             int     channel_layout;
675         };
676     };
677 } hb_work_info_t;
678
679 struct hb_work_object_s
680 {
681     int                 id;
682     char              * name;
683
684 #ifdef __LIBHB__
685     int              (* init)  ( hb_work_object_t *, hb_job_t * );
686     int              (* work)  ( hb_work_object_t *, hb_buffer_t **,
687                                  hb_buffer_t ** );
688     void             (* close) ( hb_work_object_t * );
689     /* the info entry point is used by scan to get bitstream information
690      * during a decode (i.e., it should only be called after at least one
691      * call to the 'work' entry point). currently it's only called for
692      * video streams & can be null for other work objects. */
693     int              (* info)  ( hb_work_object_t *, hb_work_info_t * );
694     /* the bitstream info entry point is used by scan to get bitstream
695      * information from a buffer. it doesn't have to be called during a
696      * decode (it can be called even if init & work haven't been).
697      * currently it's only called for audio streams & can be null for
698      * other work objects. */
699     int              (* bsinfo)  ( hb_work_object_t *, const hb_buffer_t *, 
700                                    hb_work_info_t * );
701
702     hb_fifo_t         * fifo_in;
703     hb_fifo_t         * fifo_out;
704     hb_esconfig_t     * config;
705
706     /* Pointer hb_audio_t so we have access to the info in the audio worker threads. */
707     hb_audio_t        * audio;
708
709     /* Pointer hb_subtitle_t so we have access to the info in the subtitle worker threads. */
710     hb_subtitle_t     * subtitle;
711
712     hb_work_private_t * private_data;
713
714     hb_thread_t       * thread;
715     volatile int      * done;
716     int                 status;
717     int                 codec_param;
718     hb_title_t        * title;
719
720     hb_work_object_t  * next;
721     int                 thread_sleep_interval;
722 #endif
723 };
724
725 extern hb_work_object_t hb_sync_video;
726 extern hb_work_object_t hb_sync_audio;
727 extern hb_work_object_t hb_decmpeg2;
728 extern hb_work_object_t hb_decvobsub;
729 extern hb_work_object_t hb_encvobsub;
730 extern hb_work_object_t hb_deccc608;
731 extern hb_work_object_t hb_decsrtsub;
732 extern hb_work_object_t hb_decutf8sub;
733 extern hb_work_object_t hb_dectx3gsub;
734 extern hb_work_object_t hb_decssasub;
735 extern hb_work_object_t hb_render;
736 extern hb_work_object_t hb_encavcodec;
737 extern hb_work_object_t hb_encx264;
738 extern hb_work_object_t hb_enctheora;
739 extern hb_work_object_t hb_deca52;
740 extern hb_work_object_t hb_decdca;
741 extern hb_work_object_t hb_decavcodec;
742 extern hb_work_object_t hb_decavcodecv;
743 extern hb_work_object_t hb_decavcodecvi;
744 extern hb_work_object_t hb_decavcodecai;
745 extern hb_work_object_t hb_declpcm;
746 extern hb_work_object_t hb_encfaac;
747 extern hb_work_object_t hb_enclame;
748 extern hb_work_object_t hb_encvorbis;
749 extern hb_work_object_t hb_muxer;
750 extern hb_work_object_t hb_encca_aac;
751
752 #define FILTER_OK      0
753 #define FILTER_DELAY   1
754 #define FILTER_FAILED  2
755 #define FILTER_DROP    3
756
757 struct hb_filter_object_s
758 {
759     int                     id;
760     char                  * name;
761     char                  * settings;
762
763 #ifdef __LIBHB__
764     hb_filter_private_t* (* init)  ( int, int, int, char * );
765
766     int                  (* work)  ( const hb_buffer_t *, hb_buffer_t **,
767                                      int, int, int, hb_filter_private_t * );
768
769     void                 (* close) ( hb_filter_private_t * );
770
771     hb_filter_private_t   * private_data;
772     //hb_buffer_t           * buffer;
773 #endif
774 };
775
776 #define HB_FILTER_DETELECINE    1
777 #define HB_FILTER_DEINTERLACE   2
778 #define HB_FILTER_DEBLOCK       3
779 #define HB_FILTER_DENOISE       4
780 #define HB_FILTER_DECOMB        5
781 #define HB_FILTER_ROTATE        6
782
783 extern hb_filter_object_t hb_filter_detelecine;
784 extern hb_filter_object_t hb_filter_deinterlace;
785 extern hb_filter_object_t hb_filter_deblock;
786 extern hb_filter_object_t hb_filter_denoise;
787 extern hb_filter_object_t hb_filter_decomb;
788 extern hb_filter_object_t hb_filter_rotate;
789
790 typedef void hb_error_handler_t( const char *errmsg );
791
792 extern void hb_register_error_handler( hb_error_handler_t * handler );
793
794 char * hb_strdup_printf( char * fmt, ... );
795
796 int hb_yuv2rgb(int yuv);
797 int hb_rgb2yuv(int rgb);
798
799 #endif