OSDN Git Service

eba152f35d24462a159c85a29b81158a2519416e
[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
119     int             vcodec;
120     float           vquality;
121     int             vbitrate;
122     int             vrate;
123     int             vrate_base;
124     int             pass;
125     int             h264_13;
126         int                             h264_level;
127         int                             crf;
128         
129     /* Audio tracks:
130          Indexes in hb_title_t's audios list, starting from 0.
131          -1 indicates the end of the list */
132     int             audios[8];
133
134     /* Audio settings:
135          acodec:   output codec
136          abitrate: output bitrate (kbps)
137          arate:    output samplerate (Hz)
138        HB_ACODEC_AC3 means pass-through, then abitrate and arate are
139        ignored */
140 #define HB_ACODEC_MASK   0x00FF00
141 #define HB_ACODEC_FAAC   0x000100
142 #define HB_ACODEC_LAME   0x000200
143 #define HB_ACODEC_VORBIS 0x000400
144 #define HB_ACODEC_AC3    0x000800
145 #define HB_ACODEC_MPGA   0x001000
146 #define HB_ACODEC_LPCM   0x002000
147     int             acodec;
148     int             abitrate;
149     int             arate;
150
151     /* Subtitle settings:
152          subtitle: index in hb_title_t's subtitles list, starting
153          from 0. -1 means no subtitle */
154     int             subtitle;
155
156     /* Muxer settings
157          mux:  output file format
158          file: file path */
159 #define HB_MUX_MASK 0xFF0000
160 #define HB_MUX_MP4  0x010000
161 #define HB_MUX_PSP  0x020000
162 #define HB_MUX_AVI  0x040000
163 #define HB_MUX_OGM  0x080000
164 #define HB_MUX_IPOD 0x100000
165         
166     int             mux;
167     char          * file;
168
169 #ifdef __LIBHB__
170     /* Internal data */
171     hb_handle_t   * h;
172     hb_lock_t     * pause;
173     volatile int  * die;
174     volatile int    done;
175
176     hb_fifo_t     * fifo_mpeg2;   /* MPEG-2 video ES */
177     hb_fifo_t     * fifo_raw;     /* Raw pictures */
178     hb_fifo_t     * fifo_sync;    /* Raw pictures, framerate corrected */
179     hb_fifo_t     * fifo_render;  /* Raw pictures, scaled */
180     hb_fifo_t     * fifo_mpeg4;   /* MPEG-4 video ES */
181
182     hb_thread_t   * reader;
183     hb_thread_t   * muxer;
184
185     hb_list_t     * list_work;
186
187     hb_esconfig_t config;
188
189     hb_mux_data_t * mux_data;
190 #endif
191 };
192
193 struct hb_audio_s
194 {
195     int  id;
196     char lang[1024];
197     char lang_simple[1024];
198     int  codec;
199     int  rate;
200     int  bitrate;
201     int  channels;
202
203 #ifdef __LIBHB__
204     /* Internal data */
205     hb_fifo_t * fifo_in;   /* AC3/MPEG/LPCM ES */
206     hb_fifo_t * fifo_raw;  /* Raw audio */
207     hb_fifo_t * fifo_sync; /* Resampled, synced raw audio */
208     hb_fifo_t * fifo_out;  /* MP3/AAC/Vorbis ES */
209
210     hb_esconfig_t config;
211     hb_mux_data_t * mux_data;
212 #endif
213 };
214
215 struct hb_chapter_s
216 {
217     int      index;
218     int      cell_start;
219     int      cell_end;
220     int      block_start;
221     int      block_end;
222     int      block_count;
223
224     /* Visual-friendly duration */
225     int      hours;
226     int      minutes;
227     int      seconds;
228
229     /* Exact duration (in 1/90000s) */
230     uint64_t duration;
231 };
232
233 struct hb_subtitle_s
234 {
235     int  id;
236     char lang[1024];
237
238 #ifdef __LIBHB__
239     /* Internal data */
240     hb_fifo_t * fifo_in;  /* SPU ES */
241     hb_fifo_t * fifo_raw; /* Decodec SPU */
242 #endif
243 };
244
245 struct hb_title_s
246 {
247     char        dvd[1024];
248     char        name[1024];
249     int         index;
250     int         vts;
251     int         ttn;
252     int         cell_start;
253     int         cell_end;
254     int         block_start;
255     int         block_end;
256     int         block_count;
257
258     /* Visual-friendly duration */
259     int         hours;
260     int         minutes;
261     int         seconds;
262
263     /* Exact duration (in 1/90000s) */
264     uint64_t    duration;
265
266     int         width;
267     int         height;
268     int         aspect;
269     int         rate;
270     int         rate_base;
271     int         crop[4];
272
273     uint32_t    palette[16];
274
275     hb_list_t * list_chapter;
276     hb_list_t * list_audio;
277     hb_list_t * list_subtitle;
278
279     /* Job template for this title */
280     hb_job_t  * job;
281 };
282
283
284 struct hb_state_s
285 {
286 #define HB_STATE_IDLE     1
287 #define HB_STATE_SCANNING 2
288 #define HB_STATE_SCANDONE 4
289 #define HB_STATE_WORKING  8
290 #define HB_STATE_PAUSED   16
291 #define HB_STATE_WORKDONE 32
292     int state;
293
294     union
295     {
296         struct
297         {
298             /* HB_STATE_SCANNING */
299             int title_cur;
300             int title_count;
301         } scanning;
302
303         struct
304         {
305             /* HB_STATE_WORKING */
306             float progress;
307             int   job_cur;
308             int   job_count;
309             float rate_cur;
310             float rate_avg;
311             int   hours;
312             int   minutes;
313             int   seconds;
314         } working;
315
316         struct
317         {
318             /* HB_STATE_WORKDONE */
319 #define HB_ERROR_NONE     0
320 #define HB_ERROR_CANCELED 1
321 #define HB_ERROR_UNKNOWN  2
322             int error;
323         } workdone;
324
325     } param;
326 };
327
328 struct hb_work_object_s
329 {
330     int                 id;
331     char              * name;
332
333 #ifdef __LIBHB__
334     int              (* init)  ( hb_work_object_t *, hb_job_t * );
335     int              (* work)  ( hb_work_object_t *, hb_buffer_t **,
336                                  hb_buffer_t ** );
337     void             (* close) ( hb_work_object_t * );
338
339     hb_fifo_t         * fifo_in;
340     hb_fifo_t         * fifo_out;
341     hb_esconfig_t     * config;
342
343     hb_work_private_t * private_data;
344
345     hb_thread_t       * thread;
346     volatile int      * done;
347
348     hb_work_object_t  * next;
349 #endif
350 };
351
352 extern hb_work_object_t hb_sync;
353 extern hb_work_object_t hb_decmpeg2;
354 extern hb_work_object_t hb_decsub;
355 extern hb_work_object_t hb_render;
356 extern hb_work_object_t hb_encavcodec;
357 extern hb_work_object_t hb_encxvid;
358 extern hb_work_object_t hb_encx264;
359 extern hb_work_object_t hb_deca52;
360 extern hb_work_object_t hb_decavcodec;
361 extern hb_work_object_t hb_declpcm;
362 extern hb_work_object_t hb_encfaac;
363 extern hb_work_object_t hb_enclame;
364 extern hb_work_object_t hb_encvorbis;
365
366 #endif