OSDN Git Service

dea4a48009dc527361443f5c8cee49561cc59626
[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.m0k.org/>.
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 <stdio.h>
11 #include <stdlib.h>
12 #include <stdarg.h>
13 #include <string.h>
14 #include <unistd.h>
15 #include <inttypes.h>
16 #include <sys/types.h>
17 #include <sys/stat.h>
18 #include <dirent.h>
19
20 #ifndef MIN
21 #define MIN( a, b ) ( (a) > (b) ? (b) : (a) )
22 #endif
23 #ifndef MAX
24 #define MAX( a, b ) ( (a) > (b) ? (a) : (b) )
25 #endif
26
27 #define EVEN( a )        ( (a) + ( (a) & 1 ) )
28 #define MULTIPLE_16( a ) ( 16 * ( ( (a) + 8 ) / 16 ) )
29
30 typedef struct hb_handle_s hb_handle_t;
31 typedef struct hb_list_s hb_list_t;
32 typedef struct hb_rate_s hb_rate_t;
33 typedef struct hb_job_s  hb_job_t;
34 typedef struct hb_title_s hb_title_t;
35 typedef struct hb_chapter_s hb_chapter_t;
36 typedef struct hb_audio_s hb_audio_t;
37 typedef struct hb_subtitle_s hb_subtitle_t;
38 typedef struct hb_state_s hb_state_t;
39 typedef union  hb_esconfig_u     hb_esconfig_t;
40 typedef struct hb_work_private_s hb_work_private_t;
41 typedef struct hb_work_object_s  hb_work_object_t;
42 typedef struct hb_buffer_s hb_buffer_t;
43 typedef struct hb_fifo_s hb_fifo_t;
44 typedef struct hb_lock_s hb_lock_t;
45
46 #include "ports.h"
47 #ifdef __LIBHB__
48 #include "internal.h"
49 #endif
50
51 hb_list_t * hb_list_init();
52 int         hb_list_count( hb_list_t * );
53 void        hb_list_add( hb_list_t *, void * );
54 void        hb_list_rem( hb_list_t *, void * );
55 void      * hb_list_item( hb_list_t *, int );
56 void        hb_list_close( hb_list_t ** );
57
58 #define HB_KEEP_WIDTH  0
59 #define HB_KEEP_HEIGHT 1
60 void hb_fix_aspect( hb_job_t * job, int keep );
61
62 int hb_calc_bitrate( hb_job_t *, int size );
63
64 struct hb_rate_s
65 {
66     char * string;
67     int    rate;
68 };
69
70 #define HB_ASPECT_BASE 9
71 #define HB_VIDEO_RATE_BASE   27000000
72
73 extern hb_rate_t hb_video_rates[];
74 extern int       hb_video_rates_count;
75 extern hb_rate_t hb_audio_rates[];
76 extern int       hb_audio_rates_count;
77 extern int       hb_audio_rates_default;
78 extern hb_rate_t hb_audio_bitrates[];
79 extern int       hb_audio_bitrates_count;
80 extern int       hb_audio_bitrates_default;
81
82 /******************************************************************************
83  * hb_job_t: settings to be filled by the UI
84  *****************************************************************************/
85 struct hb_job_s
86 {
87     /* Pointer to the title to be ripped */
88     hb_title_t    * title;
89     
90     /* Chapter selection */
91     int             chapter_start;
92     int             chapter_end;
93
94     /* Picture settings:
95          crop:        must be multiples of 2 (top/bottom/left/right)
96          deinterlace: 0 or 1
97          width:       must be a multiple of 16
98          height:      must be a multiple of 16
99          keep_ratio:  used by UIs */
100     int             crop[4];
101     int             deinterlace;
102     int             width;
103     int             height;
104     int             keep_ratio;
105     int             grayscale;
106
107     /* Video settings:
108          vcodec:            output codec
109          vquality:          output quality (0.0..1.0)
110                             if < 0.0 or > 1.0, bitrate is used instead
111          vbitrate:          output bitrate (kbps)
112          pass:              0, 1 or 2
113          vrate, vrate_base: output framerate is vrate / vrate_base */
114 #define HB_VCODEC_MASK   0x0000FF
115 #define HB_VCODEC_FFMPEG 0x000001
116 #define HB_VCODEC_XVID   0x000002
117 #define HB_VCODEC_X264   0x000004
118     int             vcodec;
119     float           vquality;
120     int             vbitrate;
121     int             vrate;
122     int             vrate_base;
123     int             pass;
124     int             h264_13;
125
126     /* Audio tracks:
127          Indexes in hb_title_t's audios list, starting from 0.
128          -1 indicates the end of the list */
129     int             audios[8];
130
131     /* Audio settings:
132          acodec:   output codec
133          abitrate: output bitrate (kbps)
134          arate:    output samplerate (Hz)
135        HB_ACODEC_AC3 means pass-through, then abitrate and arate are
136        ignored */
137 #define HB_ACODEC_MASK   0x00FF00
138 #define HB_ACODEC_FAAC   0x000100
139 #define HB_ACODEC_LAME   0x000200
140 #define HB_ACODEC_VORBIS 0x000400
141 #define HB_ACODEC_AC3    0x000800
142 #define HB_ACODEC_MPGA   0x001000
143 #define HB_ACODEC_LPCM   0x002000
144     int             acodec;
145     int             abitrate;
146     int             arate;
147
148     /* Subtitle settings:
149          subtitle: index in hb_title_t's subtitles list, starting
150          from 0. -1 means no subtitle */
151     int             subtitle;
152
153     /* Muxer settings
154          mux:  output file format
155          file: file path */
156 #define HB_MUX_MASK 0xFF0000
157 #define HB_MUX_MP4  0x010000
158 #define HB_MUX_AVI  0x020000
159 #define HB_MUX_OGM  0x040000
160     int             mux;
161     char          * file;
162
163 #ifdef __LIBHB__
164     /* Internal data */
165     hb_handle_t   * h;
166     hb_lock_t     * pause;
167     volatile int  * die;
168     volatile int    done;
169
170     hb_fifo_t     * fifo_mpeg2;   /* MPEG-2 video ES */
171     hb_fifo_t     * fifo_raw;     /* Raw pictures */
172     hb_fifo_t     * fifo_sync;    /* Raw pictures, framerate corrected */
173     hb_fifo_t     * fifo_render;  /* Raw pictures, scaled */
174     hb_fifo_t     * fifo_mpeg4;   /* MPEG-4 video ES */
175
176     hb_thread_t   * reader;
177     hb_thread_t   * muxer;
178
179     hb_list_t     * list_work;
180
181     hb_esconfig_t config;
182
183     hb_mux_data_t * mux_data;
184 #endif
185 };
186
187 struct hb_audio_s
188 {
189     int  id;
190     char lang[1024];
191     int  codec;
192     int  rate;
193     int  bitrate;
194     int  channels;
195
196 #ifdef __LIBHB__
197     /* Internal data */
198     hb_fifo_t * fifo_in;   /* AC3/MPEG/LPCM ES */
199     hb_fifo_t * fifo_raw;  /* Raw audio */
200     hb_fifo_t * fifo_sync; /* Resampled, synced raw audio */
201     hb_fifo_t * fifo_out;  /* MP3/AAC/Vorbis ES */
202
203     hb_esconfig_t config;
204     hb_mux_data_t * mux_data;
205 #endif
206 };
207
208 struct hb_chapter_s
209 {
210     int      index;
211     int      cell_start;
212     int      cell_end;
213     int      block_start;
214     int      block_end;
215     int      block_count;
216
217     /* Visual-friendly duration */
218     int      hours;
219     int      minutes;
220     int      seconds;
221
222     /* Exact duration (in 1/90000s) */
223     uint64_t duration;
224 };
225
226 struct hb_subtitle_s
227 {
228     int  id;
229     char lang[1024];
230
231 #ifdef __LIBHB__
232     /* Internal data */
233     hb_fifo_t * fifo_in;  /* SPU ES */
234     hb_fifo_t * fifo_raw; /* Decodec SPU */
235 #endif
236 };
237
238 struct hb_title_s
239 {
240     char        dvd[1024];
241     int         index;
242     int         vts;
243     int         ttn;
244     int         cell_start;
245     int         cell_end;
246     int         block_start;
247     int         block_end;
248     int         block_count;
249
250     /* Visual-friendly duration */
251     int         hours;
252     int         minutes;
253     int         seconds;
254
255     /* Exact duration (in 1/90000s) */
256     uint64_t    duration;
257
258     int         width;
259     int         height;
260     int         aspect;
261     int         rate;
262     int         rate_base;
263     int         crop[4];
264
265     uint32_t    palette[16];
266
267     hb_list_t * list_chapter;
268     hb_list_t * list_audio;
269     hb_list_t * list_subtitle;
270
271     /* Job template for this title */
272     hb_job_t  * job;
273 };
274
275
276 struct hb_state_s
277 {
278 #define HB_STATE_IDLE     1
279 #define HB_STATE_SCANNING 2
280 #define HB_STATE_SCANDONE 4
281 #define HB_STATE_WORKING  8
282 #define HB_STATE_PAUSED   16
283 #define HB_STATE_WORKDONE 32
284     int state;
285
286     union
287     {
288         struct
289         {
290             /* HB_STATE_SCANNING */
291             int title_cur;
292             int title_count;
293         } scanning;
294
295         struct
296         {
297             /* HB_STATE_WORKING */
298             float progress;
299             int   job_cur;
300             int   job_count;
301             float rate_cur;
302             float rate_avg;
303             int   hours;
304             int   minutes;
305             int   seconds;
306         } working;
307
308         struct
309         {
310             /* HB_STATE_WORKDONE */
311 #define HB_ERROR_NONE     0
312 #define HB_ERROR_CANCELED 1
313 #define HB_ERROR_UNKNOWN  2
314             int error;
315         } workdone;
316
317     } param;
318 };
319
320 struct hb_work_object_s
321 {
322     int                 id;
323     char              * name;
324
325 #ifdef __LIBHB__
326     int              (* init)  ( hb_work_object_t *, hb_job_t * );
327     int              (* work)  ( hb_work_object_t *, hb_buffer_t **,
328                                  hb_buffer_t ** );
329     void             (* close) ( hb_work_object_t * );
330
331     hb_fifo_t         * fifo_in;
332     hb_fifo_t         * fifo_out;
333     hb_esconfig_t     * config;
334
335     hb_work_private_t * private_data;
336
337     hb_thread_t       * thread;
338     volatile int      * done;
339
340     hb_work_object_t  * next;
341 #endif
342 };
343
344 extern hb_work_object_t hb_sync;
345 extern hb_work_object_t hb_decmpeg2;
346 extern hb_work_object_t hb_decsub;
347 extern hb_work_object_t hb_render;
348 extern hb_work_object_t hb_encavcodec;
349 extern hb_work_object_t hb_encxvid;
350 extern hb_work_object_t hb_encx264;
351 extern hb_work_object_t hb_deca52;
352 extern hb_work_object_t hb_decavcodec;
353 extern hb_work_object_t hb_declpcm;
354 extern hb_work_object_t hb_encfaac;
355 extern hb_work_object_t hb_enclame;
356 extern hb_work_object_t hb_encvorbis;
357
358 #endif