OSDN Git Service

Add Bluray support
[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 stream_type; /* stream type from source stream */
401         PRIVATE uint32_t codec_param; /* per-codec config info */
402         PRIVATE uint32_t version; /* Bitsream version */
403         PRIVATE uint32_t mode;    /* Bitstream mode, codec dependent encoding */
404         PRIVATE int samplerate; /* Input sample rate (Hz) */
405         PRIVATE int bitrate;    /* Input bitrate (kbps) */
406         PRIVATE int channel_layout;
407         /* channel_layout is the channel layout of this audio this is used to
408         * provide a common way of describing the source audio
409         */
410     } in;
411
412     /* Misc. */
413     union
414     {
415         PRIVATE int ac3;    /* flags.ac3 is only set when the source audio format is HB_ACODEC_AC3 */
416         PRIVATE int dca;    /* flags.dca is only set when the source audio format is HB_ACODEC_DCA */
417     } flags;
418 #define AUDIO_F_DOLBY (1 << 31)  /* set if source uses Dolby Surround */
419
420     struct
421     {
422         PRIVATE char description[1024];
423         PRIVATE char simple[1024];
424         PRIVATE char iso639_2[4];
425         PRIVATE uint8_t type; /* normal, visually impared, directors */
426     } lang;
427 };
428
429 #ifdef __LIBHB__
430 struct hb_audio_s
431 {
432     int id;
433
434     hb_audio_config_t config;
435
436     struct {
437         hb_fifo_t * fifo_in;   /* AC3/MPEG/LPCM ES */
438         hb_fifo_t * fifo_raw;  /* Raw audio */
439         hb_fifo_t * fifo_sync; /* Resampled, synced raw audio */
440         hb_fifo_t * fifo_out;  /* MP3/AAC/Vorbis ES */
441
442         hb_esconfig_t config;
443         hb_mux_data_t * mux_data;
444         hb_fifo_t     * scan_cache;
445     } priv;
446 };
447 #endif
448
449 struct hb_chapter_s
450 {
451     int      index;
452     int      pgcn;
453     int      pgn;
454     int      cell_start;
455     int      cell_end;
456     uint64_t block_start;
457     uint64_t block_end;
458     uint64_t block_count;
459
460     /* Visual-friendly duration */
461     int      hours;
462     int      minutes;
463     int      seconds;
464
465     /* Exact duration (in 1/90000s) */
466     uint64_t duration;
467
468     /* Optional chapter title */
469     char     title[1024];
470 };
471
472 /*
473  * A subtitle track.
474  * 
475  * Required fields when a demuxer creates a subtitle track are:
476  * > id
477  *     - ID of this track
478  *     - must be unique for all tracks within a single job,
479  *       since it is used to look up the appropriate in-FIFO with GetFifoForId()
480  * > format
481  *     - format of the packets the subtitle decoder work-object sends to sub->fifo_raw
482  *     - for passthru subtitles, is also the format of the final packets sent to sub->fifo_out
483  *     - PICTURESUB for banded 8-bit YAUV pixels; see decvobsub.c documentation for more info
484  *     - TEXTSUB for UTF-8 text marked up with <b>, <i>, or <u>
485  *     - read by the muxers, and by the subtitle burn-in logic in the hb_sync_video work-object
486  * > source
487  *     - used to create the appropriate subtitle decoder work-object in do_job()
488  * > config.dest
489  *     - whether to render the subtitle on the video track (RENDERSUB) or 
490  *       to pass it through its own subtitle track in the output container (PASSTHRUSUB)
491  *     - for legacy compatibility, all newly created VOBSUB tracks should default to RENDERSUB
492  *     - since only VOBSUBs are renderable (as of 2010-04-25), all other newly created
493  *       subtitle track types should default to PASSTHRUSUB
494  * > lang
495  *     - user-readable description of the subtitle track
496  *     - may correspond to the language of the track (see the 'iso639_2' field)
497  *     - may correspond to the type of track (see the 'type' field; ex: "Closed Captions")
498  * > iso639_2
499  *     - language code for the subtitle, or "und" if unknown
500  */
501 struct hb_subtitle_s
502 {
503     int  id;
504     int  track;
505
506     hb_subtitle_config_t config;
507
508     enum subtype { PICTURESUB, TEXTSUB } format;
509     enum subsource { VOBSUB, SRTSUB, CC608SUB, /*unused*/CC708SUB, UTF8SUB, TX3GSUB, SSASUB } source;
510     char lang[1024];
511     char iso639_2[4];
512     uint8_t type; /* Closed Caption, Childrens, Directors etc */
513     
514     // Color lookup table for VOB subtitle tracks. Each entry is in YCbCr format.
515     // Must be filled out by the demuxer for VOB subtitle tracks.
516     uint32_t    palette[16];
517     int         width;
518     int         height;
519
520     int hits;     /* How many hits/occurrences of this subtitle */
521     int forced_hits; /* How many forced hits in this subtitle */
522
523 #ifdef __LIBHB__
524     /* Internal data */
525     hb_fifo_t * fifo_in;  /* SPU ES */
526     hb_fifo_t * fifo_raw; /* Decoded SPU */
527     hb_fifo_t * fifo_sync;/* Synced */
528     hb_fifo_t * fifo_out; /* Correct Timestamps, ready to be muxed */
529     hb_mux_data_t * mux_data;
530 #endif
531 };
532
533 struct hb_metadata_s 
534 {
535     char  name[255];
536     char  artist[255];
537     char  composer[255];
538     char  release_date[255];
539     char  comment[1024];
540     char  album[255];
541     char  genre[255];
542     uint32_t coverart_size;
543     uint8_t *coverart;
544 };
545
546 struct hb_title_s
547 {
548     enum { HB_DVD_TYPE, HB_BD_TYPE, HB_STREAM_TYPE } type;
549     uint32_t    reg_desc;
550     char        path[1024];
551     char        name[1024];
552     int         index;
553     int         vts;
554     int         ttn;
555     int         cell_start;
556     int         cell_end;
557     uint64_t    block_start;
558     uint64_t    block_end;
559     uint64_t    block_count;
560     int         angle_count;
561
562     /* Visual-friendly duration */
563     int         hours;
564     int         minutes;
565     int         seconds;
566
567     /* Exact duration (in 1/90000s) */
568     uint64_t    duration;
569
570     double      aspect;             // aspect ratio for the title's video
571     double      container_aspect;   // aspect ratio from container (0 if none)
572     int         width;
573     int         height;
574     int         pixel_aspect_width;
575     int         pixel_aspect_height;
576     int         rate;
577     int         rate_base;
578     int         crop[4];
579     enum { HB_MPEG2_PS_DEMUXER = 0, HB_MPEG2_TS_DEMUXER, HB_NULL_DEMUXER } demuxer;
580     int         detected_interlacing;
581     int         pcr_pid;                /* PCR PID for TS streams */
582     int         video_id;               /* demuxer stream id for video */
583     int         video_codec;            /* worker object id of video codec */
584     uint32_t    video_stream_type;      /* stream type from source stream */
585     int         video_codec_param;      /* codec specific config */
586     const char  *video_codec_name;
587     int         video_bitrate;
588     const char  *container_name;
589     int         data_rate;
590
591     hb_metadata_t *metadata;
592
593     hb_list_t * list_chapter;
594     hb_list_t * list_audio;
595     hb_list_t * list_subtitle;
596
597     /* Job template for this title */
598     hb_job_t  * job;
599
600     uint32_t    flags;
601                 // set if video stream doesn't have IDR frames
602 #define         HBTF_NO_IDR (1 << 0)
603 };
604
605
606 struct hb_state_s
607 {
608 #define HB_STATE_IDLE     1
609 #define HB_STATE_SCANNING 2
610 #define HB_STATE_SCANDONE 4
611 #define HB_STATE_WORKING  8
612 #define HB_STATE_PAUSED   16
613 #define HB_STATE_WORKDONE 32
614 #define HB_STATE_MUXING   64
615 #define HB_STATE_SEARCHING 128
616     int state;
617
618     union
619     {
620         struct
621         {
622             /* HB_STATE_SCANNING */
623             int title_cur;
624             int title_count;
625         } scanning;
626
627         struct
628         {
629             /* HB_STATE_WORKING */
630             float progress;
631             int   job_cur;
632             int   job_count;
633             float rate_cur;
634             float rate_avg;
635             int   hours;
636             int   minutes;
637             int   seconds;
638             int   sequence_id;
639         } working;
640
641         struct
642         {
643             /* HB_STATE_WORKDONE */
644 #define HB_ERROR_NONE     0
645 #define HB_ERROR_CANCELED 1
646 #define HB_ERROR_UNKNOWN  2
647             int error;
648         } workdone;
649
650         struct
651         {
652             /* HB_STATE_MUXING */
653             float progress;
654         } muxing;
655     } param;
656 };
657
658 typedef struct hb_work_info_s
659 {
660     const char *name;
661     int     profile;
662     int     level;
663     int     bitrate;
664     int     rate;
665     int     rate_base;
666     int     flags;
667     int     version;
668     int     mode;
669     union {
670         struct {    // info only valid for video decoders
671             int     width;
672             int     height;
673             int     pixel_aspect_width;
674             int     pixel_aspect_height;
675             double  aspect;
676         };
677         struct {    // info only valid for audio decoders
678             int     channel_layout;
679         };
680     };
681 } hb_work_info_t;
682
683 struct hb_work_object_s
684 {
685     int                 id;
686     char              * name;
687
688 #ifdef __LIBHB__
689     int              (* init)  ( hb_work_object_t *, hb_job_t * );
690     int              (* work)  ( hb_work_object_t *, hb_buffer_t **,
691                                  hb_buffer_t ** );
692     void             (* close) ( hb_work_object_t * );
693     /* the info entry point is used by scan to get bitstream information
694      * during a decode (i.e., it should only be called after at least one
695      * call to the 'work' entry point). currently it's only called for
696      * video streams & can be null for other work objects. */
697     int              (* info)  ( hb_work_object_t *, hb_work_info_t * );
698     /* the bitstream info entry point is used by scan to get bitstream
699      * information from a buffer. it doesn't have to be called during a
700      * decode (it can be called even if init & work haven't been).
701      * currently it's only called for audio streams & can be null for
702      * other work objects. */
703     int              (* bsinfo)  ( hb_work_object_t *, const hb_buffer_t *, 
704                                    hb_work_info_t * );
705
706     hb_fifo_t         * fifo_in;
707     hb_fifo_t         * fifo_out;
708     hb_esconfig_t     * config;
709
710     /* Pointer hb_audio_t so we have access to the info in the audio worker threads. */
711     hb_audio_t        * audio;
712
713     /* Pointer hb_subtitle_t so we have access to the info in the subtitle worker threads. */
714     hb_subtitle_t     * subtitle;
715
716     hb_work_private_t * private_data;
717
718     hb_thread_t       * thread;
719     volatile int      * done;
720     int                 status;
721     int                 codec_param;
722     hb_title_t        * title;
723
724     hb_work_object_t  * next;
725     int                 thread_sleep_interval;
726 #endif
727 };
728
729 extern hb_work_object_t hb_sync_video;
730 extern hb_work_object_t hb_sync_audio;
731 extern hb_work_object_t hb_decmpeg2;
732 extern hb_work_object_t hb_decvobsub;
733 extern hb_work_object_t hb_encvobsub;
734 extern hb_work_object_t hb_deccc608;
735 extern hb_work_object_t hb_decsrtsub;
736 extern hb_work_object_t hb_decutf8sub;
737 extern hb_work_object_t hb_dectx3gsub;
738 extern hb_work_object_t hb_decssasub;
739 extern hb_work_object_t hb_render;
740 extern hb_work_object_t hb_encavcodec;
741 extern hb_work_object_t hb_encx264;
742 extern hb_work_object_t hb_enctheora;
743 extern hb_work_object_t hb_deca52;
744 extern hb_work_object_t hb_decdca;
745 extern hb_work_object_t hb_decavcodec;
746 extern hb_work_object_t hb_decavcodecv;
747 extern hb_work_object_t hb_decavcodecvi;
748 extern hb_work_object_t hb_decavcodecai;
749 extern hb_work_object_t hb_declpcm;
750 extern hb_work_object_t hb_encfaac;
751 extern hb_work_object_t hb_enclame;
752 extern hb_work_object_t hb_encvorbis;
753 extern hb_work_object_t hb_muxer;
754 extern hb_work_object_t hb_encca_aac;
755
756 #define FILTER_OK      0
757 #define FILTER_DELAY   1
758 #define FILTER_FAILED  2
759 #define FILTER_DROP    3
760
761 struct hb_filter_object_s
762 {
763     int                     id;
764     char                  * name;
765     char                  * settings;
766
767 #ifdef __LIBHB__
768     hb_filter_private_t* (* init)  ( int, int, int, char * );
769
770     int                  (* work)  ( const hb_buffer_t *, hb_buffer_t **,
771                                      int, int, int, hb_filter_private_t * );
772
773     void                 (* close) ( hb_filter_private_t * );
774
775     hb_filter_private_t   * private_data;
776     //hb_buffer_t           * buffer;
777 #endif
778 };
779
780 #define HB_FILTER_DETELECINE    1
781 #define HB_FILTER_DEINTERLACE   2
782 #define HB_FILTER_DEBLOCK       3
783 #define HB_FILTER_DENOISE       4
784 #define HB_FILTER_DECOMB        5
785 #define HB_FILTER_ROTATE        6
786
787 extern hb_filter_object_t hb_filter_detelecine;
788 extern hb_filter_object_t hb_filter_deinterlace;
789 extern hb_filter_object_t hb_filter_deblock;
790 extern hb_filter_object_t hb_filter_denoise;
791 extern hb_filter_object_t hb_filter_decomb;
792 extern hb_filter_object_t hb_filter_rotate;
793
794 typedef void hb_error_handler_t( const char *errmsg );
795
796 extern void hb_register_error_handler( hb_error_handler_t * handler );
797
798 char * hb_strdup_printf( char * fmt, ... );
799
800 int hb_yuv2rgb(int yuv);
801 int hb_rgb2yuv(int rgb);
802
803 #endif