1 /* $Id: common.h,v 1.51 2005/11/04 13:09:40 titer Exp $
3 This file is part of the HandBrake source code.
4 Homepage: <http://handbrake.m0k.org/>.
5 It may be used under the terms of the GNU General Public License. */
17 #include <sys/types.h>
22 #define MIN( a, b ) ( (a) > (b) ? (b) : (a) )
25 #define MAX( a, b ) ( (a) > (b) ? (a) : (b) )
28 #define EVEN( a ) ( (a) + ( (a) & 1 ) )
29 #define MULTIPLE_16( a ) ( 16 * ( ( (a) + 8 ) / 16 ) )
31 typedef struct hb_handle_s hb_handle_t;
32 typedef struct hb_list_s hb_list_t;
33 typedef struct hb_rate_s hb_rate_t;
34 typedef struct hb_job_s hb_job_t;
35 typedef struct hb_title_s hb_title_t;
36 typedef struct hb_chapter_s hb_chapter_t;
37 typedef struct hb_audio_s hb_audio_t;
38 typedef struct hb_subtitle_s hb_subtitle_t;
39 typedef struct hb_state_s hb_state_t;
40 typedef union hb_esconfig_u hb_esconfig_t;
41 typedef struct hb_work_private_s hb_work_private_t;
42 typedef struct hb_work_object_s hb_work_object_t;
43 typedef struct hb_buffer_s hb_buffer_t;
44 typedef struct hb_fifo_s hb_fifo_t;
45 typedef struct hb_lock_s hb_lock_t;
52 hb_list_t * hb_list_init();
53 int hb_list_count( hb_list_t * );
54 void hb_list_add( hb_list_t *, void * );
55 void hb_list_rem( hb_list_t *, void * );
56 void * hb_list_item( hb_list_t *, int );
57 void hb_list_close( hb_list_t ** );
59 void hb_reduce( int *x, int *y, int num, int den );
61 #define HB_KEEP_WIDTH 0
62 #define HB_KEEP_HEIGHT 1
63 void hb_fix_aspect( hb_job_t * job, int keep );
65 int hb_calc_bitrate( hb_job_t *, int size );
73 #define HB_ASPECT_BASE 9
74 #define HB_VIDEO_RATE_BASE 27000000
76 extern hb_rate_t hb_video_rates[];
77 extern int hb_video_rates_count;
78 extern hb_rate_t hb_audio_rates[];
79 extern int hb_audio_rates_count;
80 extern int hb_audio_rates_default;
81 extern hb_rate_t hb_audio_bitrates[];
82 extern int hb_audio_bitrates_count;
83 extern int hb_audio_bitrates_default;
85 /******************************************************************************
86 * hb_job_t: settings to be filled by the UI
87 *****************************************************************************/
90 /* Pointer to the title to be ripped */
93 /* Chapter selection */
98 crop: must be multiples of 2 (top/bottom/left/right)
100 width: must be a multiple of 16
101 height: must be a multiple of 16
102 keep_ratio: used by UIs
103 pixel_ratio: store pixel aspect ratio in the video
104 pixel_aspect_width: numerator for pixel aspect ratio
105 pixel_aspect_height: denominator for pixel aspect ratio
106 maxWidth: keep width below this
107 maxHeight: keep height below this */
116 int pixel_aspect_width;
117 int pixel_aspect_height;
124 vquality: output quality (0.0..1.0)
125 if < 0.0 or > 1.0, bitrate is used instead
126 vbitrate: output bitrate (kbps)
128 vrate, vrate_base: output framerate is vrate / vrate_base
129 h264_level: boolean for whether or not we're encoding for iPod
130 crf: boolean for whether to use constant rate factor with x264
131 x264opts: string of extra x264 options
132 areBframes: boolean to note if b-frames are included in x264opts */
133 #define HB_VCODEC_MASK 0x0000FF
134 #define HB_VCODEC_FFMPEG 0x000001
135 #define HB_VCODEC_XVID 0x000002
136 #define HB_VCODEC_X264 0x000004
147 const char *x264opts;
151 audios: Indexes in hb_title_t's audios list, starting from 0.
152 -1 indicates the end of the list
153 surround: 1 if 5.1 should be preserved for AAC, 0 otherwise */
159 abitrate: output bitrate (kbps)
160 arate: output samplerate (Hz)
161 HB_ACODEC_AC3 means pass-through, then abitrate and arate are
163 #define HB_ACODEC_MASK 0x00FF00
164 #define HB_ACODEC_FAAC 0x000100
165 #define HB_ACODEC_LAME 0x000200
166 #define HB_ACODEC_VORBIS 0x000400
167 #define HB_ACODEC_AC3 0x000800
168 #define HB_ACODEC_MPGA 0x001000
169 #define HB_ACODEC_LPCM 0x002000
174 /* Subtitle settings:
175 subtitle: index in hb_title_t's subtitles list, starting
176 from 0. -1 means no subtitle */
180 mux: output file format
182 #define HB_MUX_MASK 0xFF0000
183 #define HB_MUX_MP4 0x010000
184 #define HB_MUX_PSP 0x020000
185 #define HB_MUX_AVI 0x040000
186 #define HB_MUX_OGM 0x080000
187 #define HB_MUX_IPOD 0x100000
199 hb_fifo_t * fifo_mpeg2; /* MPEG-2 video ES */
200 hb_fifo_t * fifo_raw; /* Raw pictures */
201 hb_fifo_t * fifo_sync; /* Raw pictures, framerate corrected */
202 hb_fifo_t * fifo_render; /* Raw pictures, scaled */
203 hb_fifo_t * fifo_mpeg4; /* MPEG-4 video ES */
205 hb_thread_t * reader;
208 hb_list_t * list_work;
210 hb_esconfig_t config;
212 hb_mux_data_t * mux_data;
220 char lang_simple[1024];
224 /* channels: The # of normal channels in the last used audio
225 lfechannels: The # of lfe channels in the last used audio
226 channelsused: The # of channels we will actually use for this job -
227 calculated based on surround, channels and lfechannels
235 hb_fifo_t * fifo_in; /* AC3/MPEG/LPCM ES */
236 hb_fifo_t * fifo_raw; /* Raw audio */
237 hb_fifo_t * fifo_sync; /* Resampled, synced raw audio */
238 hb_fifo_t * fifo_out; /* MP3/AAC/Vorbis ES */
240 hb_esconfig_t config;
241 hb_mux_data_t * mux_data;
254 /* Visual-friendly duration */
259 /* Exact duration (in 1/90000s) */
270 hb_fifo_t * fifo_in; /* SPU ES */
271 hb_fifo_t * fifo_raw; /* Decodec SPU */
288 /* Visual-friendly duration */
293 /* Exact duration (in 1/90000s) */
303 uint32_t palette[16];
305 hb_list_t * list_chapter;
306 hb_list_t * list_audio;
307 hb_list_t * list_subtitle;
309 /* Job template for this title */
316 #define HB_STATE_IDLE 1
317 #define HB_STATE_SCANNING 2
318 #define HB_STATE_SCANDONE 4
319 #define HB_STATE_WORKING 8
320 #define HB_STATE_PAUSED 16
321 #define HB_STATE_WORKDONE 32
322 #define HB_STATE_MUXING 64
329 /* HB_STATE_SCANNING */
336 /* HB_STATE_WORKING */
349 /* HB_STATE_WORKDONE */
350 #define HB_ERROR_NONE 0
351 #define HB_ERROR_CANCELED 1
352 #define HB_ERROR_UNKNOWN 2
358 /* HB_STATE_MUXING */
364 struct hb_work_object_s
370 int (* init) ( hb_work_object_t *, hb_job_t * );
371 int (* work) ( hb_work_object_t *, hb_buffer_t **,
373 void (* close) ( hb_work_object_t * );
376 hb_fifo_t * fifo_out;
377 hb_esconfig_t * config;
379 hb_work_private_t * private_data;
381 hb_thread_t * thread;
384 hb_work_object_t * next;
385 int thread_sleep_interval;
389 extern hb_work_object_t hb_sync;
390 extern hb_work_object_t hb_decmpeg2;
391 extern hb_work_object_t hb_decsub;
392 extern hb_work_object_t hb_render;
393 extern hb_work_object_t hb_encavcodec;
394 extern hb_work_object_t hb_encxvid;
395 extern hb_work_object_t hb_encx264;
396 extern hb_work_object_t hb_deca52;
397 extern hb_work_object_t hb_decavcodec;
398 extern hb_work_object_t hb_declpcm;
399 extern hb_work_object_t hb_encfaac;
400 extern hb_work_object_t hb_enclame;
401 extern hb_work_object_t hb_encvorbis;