OSDN Git Service

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