OSDN Git Service

a0c22ff27fe811d90c31837a0ebd89aaa1af1e16
[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_PSP  0x020000
159 #define HB_MUX_AVI  0x040000
160 #define HB_MUX_OGM  0x080000
161     int             mux;
162     char          * file;
163
164 #ifdef __LIBHB__
165     /* Internal data */
166     hb_handle_t   * h;
167     hb_lock_t     * pause;
168     volatile int  * die;
169     volatile int    done;
170
171     hb_fifo_t     * fifo_mpeg2;   /* MPEG-2 video ES */
172     hb_fifo_t     * fifo_raw;     /* Raw pictures */
173     hb_fifo_t     * fifo_sync;    /* Raw pictures, framerate corrected */
174     hb_fifo_t     * fifo_render;  /* Raw pictures, scaled */
175     hb_fifo_t     * fifo_mpeg4;   /* MPEG-4 video ES */
176
177     hb_thread_t   * reader;
178     hb_thread_t   * muxer;
179
180     hb_list_t     * list_work;
181
182     hb_esconfig_t config;
183
184     hb_mux_data_t * mux_data;
185 #endif
186 };
187
188 struct hb_audio_s
189 {
190     int  id;
191     char lang[1024];
192     int  codec;
193     int  rate;
194     int  bitrate;
195     int  channels;
196
197 #ifdef __LIBHB__
198     /* Internal data */
199     hb_fifo_t * fifo_in;   /* AC3/MPEG/LPCM ES */
200     hb_fifo_t * fifo_raw;  /* Raw audio */
201     hb_fifo_t * fifo_sync; /* Resampled, synced raw audio */
202     hb_fifo_t * fifo_out;  /* MP3/AAC/Vorbis ES */
203
204     hb_esconfig_t config;
205     hb_mux_data_t * mux_data;
206 #endif
207 };
208
209 struct hb_chapter_s
210 {
211     int      index;
212     int      cell_start;
213     int      cell_end;
214     int      block_start;
215     int      block_end;
216     int      block_count;
217
218     /* Visual-friendly duration */
219     int      hours;
220     int      minutes;
221     int      seconds;
222
223     /* Exact duration (in 1/90000s) */
224     uint64_t duration;
225 };
226
227 struct hb_subtitle_s
228 {
229     int  id;
230     char lang[1024];
231
232 #ifdef __LIBHB__
233     /* Internal data */
234     hb_fifo_t * fifo_in;  /* SPU ES */
235     hb_fifo_t * fifo_raw; /* Decodec SPU */
236 #endif
237 };
238
239 struct hb_title_s
240 {
241     char        dvd[1024];
242     int         index;
243     int         vts;
244     int         ttn;
245     int         cell_start;
246     int         cell_end;
247     int         block_start;
248     int         block_end;
249     int         block_count;
250
251     /* Visual-friendly duration */
252     int         hours;
253     int         minutes;
254     int         seconds;
255
256     /* Exact duration (in 1/90000s) */
257     uint64_t    duration;
258
259     int         width;
260     int         height;
261     int         aspect;
262     int         rate;
263     int         rate_base;
264     int         crop[4];
265
266     uint32_t    palette[16];
267
268     hb_list_t * list_chapter;
269     hb_list_t * list_audio;
270     hb_list_t * list_subtitle;
271
272     /* Job template for this title */
273     hb_job_t  * job;
274 };
275
276
277 struct hb_state_s
278 {
279 #define HB_STATE_IDLE     1
280 #define HB_STATE_SCANNING 2
281 #define HB_STATE_SCANDONE 4
282 #define HB_STATE_WORKING  8
283 #define HB_STATE_PAUSED   16
284 #define HB_STATE_WORKDONE 32
285     int state;
286
287     union
288     {
289         struct
290         {
291             /* HB_STATE_SCANNING */
292             int title_cur;
293             int title_count;
294         } scanning;
295
296         struct
297         {
298             /* HB_STATE_WORKING */
299             float progress;
300             int   job_cur;
301             int   job_count;
302             float rate_cur;
303             float rate_avg;
304             int   hours;
305             int   minutes;
306             int   seconds;
307         } working;
308
309         struct
310         {
311             /* HB_STATE_WORKDONE */
312 #define HB_ERROR_NONE     0
313 #define HB_ERROR_CANCELED 1
314 #define HB_ERROR_UNKNOWN  2
315             int error;
316         } workdone;
317
318     } param;
319 };
320
321 struct hb_work_object_s
322 {
323     int                 id;
324     char              * name;
325
326 #ifdef __LIBHB__
327     int              (* init)  ( hb_work_object_t *, hb_job_t * );
328     int              (* work)  ( hb_work_object_t *, hb_buffer_t **,
329                                  hb_buffer_t ** );
330     void             (* close) ( hb_work_object_t * );
331
332     hb_fifo_t         * fifo_in;
333     hb_fifo_t         * fifo_out;
334     hb_esconfig_t     * config;
335
336     hb_work_private_t * private_data;
337
338     hb_thread_t       * thread;
339     volatile int      * done;
340
341     hb_work_object_t  * next;
342 #endif
343 };
344
345 extern hb_work_object_t hb_sync;
346 extern hb_work_object_t hb_decmpeg2;
347 extern hb_work_object_t hb_decsub;
348 extern hb_work_object_t hb_render;
349 extern hb_work_object_t hb_encavcodec;
350 extern hb_work_object_t hb_encxvid;
351 extern hb_work_object_t hb_encx264;
352 extern hb_work_object_t hb_deca52;
353 extern hb_work_object_t hb_decavcodec;
354 extern hb_work_object_t hb_declpcm;
355 extern hb_work_object_t hb_encfaac;
356 extern hb_work_object_t hb_enclame;
357 extern hb_work_object_t hb_encvorbis;
358
359 #endif