OSDN Git Service

HandBrake 0.7.0
[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     union
176     {
177         struct
178         {
179             uint8_t * config;
180             int       config_length;
181         } mpeg4;
182
183         struct
184         {
185             uint8_t * sps;
186             int       sps_length;
187             uint8_t * pps;
188             int       pps_length;
189         } h264;
190
191     } config;
192
193     /* MPEG-4 / AVC */
194     uint8_t       * es_config;
195     int             es_config_length;
196
197     hb_mux_data_t * mux_data;
198 #endif
199 };
200
201 struct hb_audio_s
202 {
203     int  id;
204     char lang[1024];
205     int  codec;
206     int  rate;
207     int  bitrate;
208     int  channels;
209
210 #ifdef __LIBHB__
211     /* Internal data */
212     hb_fifo_t * fifo_in;   /* AC3/MPEG/LPCM ES */
213     hb_fifo_t * fifo_raw;  /* Raw audio */
214     hb_fifo_t * fifo_sync; /* Resampled, synced raw audio */
215     hb_fifo_t * fifo_out;  /* MP3/AAC/Vorbis ES */
216
217     union
218     {
219         struct
220         {
221             uint8_t       * decinfo;
222             unsigned long   size;
223         } faac;
224
225         struct
226         {
227             uint8_t * headers[3];
228             int       sizes[3];
229         } vorbis;
230
231     } config;
232
233     hb_mux_data_t * mux_data;
234 #endif
235 };
236
237 struct hb_chapter_s
238 {
239     int      index;
240     int      cell_start;
241     int      cell_end;
242     int      block_start;
243     int      block_end;
244     int      block_count;
245
246     /* Visual-friendly duration */
247     int      hours;
248     int      minutes;
249     int      seconds;
250
251     /* Exact duration (in 1/90000s) */
252     uint64_t duration;
253 };
254
255 struct hb_subtitle_s
256 {
257     int  id;
258     char lang[1024];
259
260 #ifdef __LIBHB__
261     /* Internal data */
262     hb_fifo_t * fifo_in;  /* SPU ES */
263     hb_fifo_t * fifo_raw; /* Decodec SPU */
264 #endif
265 };
266
267 struct hb_title_s
268 {
269     char        dvd[1024];
270     int         index;
271     int         vts;
272     int         ttn;
273     int         cell_start;
274     int         cell_end;
275     int         block_start;
276     int         block_end;
277     int         block_count;
278
279     /* Visual-friendly duration */
280     int         hours;
281     int         minutes;
282     int         seconds;
283
284     /* Exact duration (in 1/90000s) */
285     uint64_t    duration;
286
287     int         width;
288     int         height;
289     int         aspect;
290     int         rate;
291     int         rate_base;
292     int         crop[4];
293
294     uint32_t    palette[16];
295
296     hb_list_t * list_chapter;
297     hb_list_t * list_audio;
298     hb_list_t * list_subtitle;
299
300     /* Job template for this title */
301     hb_job_t  * job;
302 };
303
304
305 struct hb_state_s
306 {
307 #define HB_STATE_IDLE     1
308 #define HB_STATE_SCANNING 2
309 #define HB_STATE_SCANDONE 4
310 #define HB_STATE_WORKING  8
311 #define HB_STATE_PAUSED   16
312 #define HB_STATE_WORKDONE 32
313     int state;
314
315     union
316     {
317         struct
318         {
319             /* HB_STATE_SCANNING */
320             int title_cur;
321             int title_count;
322         } scanning;
323
324         struct
325         {
326             /* HB_STATE_WORKING */
327             float progress;
328             int   job_cur;
329             int   job_count;
330             float rate_cur;
331             float rate_avg;
332             int   hours;
333             int   minutes;
334             int   seconds;
335         } working;
336
337         struct
338         {
339             /* HB_STATE_WORKDONE */
340 #define HB_ERROR_NONE     0
341 #define HB_ERROR_CANCELED 1
342 #define HB_ERROR_UNKNOWN  2
343             int error;
344         } workdone;
345
346     } param;
347 };
348
349 #endif