OSDN Git Service

Matroska muxer!
[handbrake-jp/handbrake-jp-git.git] / libhb / internal.h
1 /* $Id: internal.h,v 1.41 2005/11/25 15:05:25 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 /***********************************************************************
8  * common.c
9  **********************************************************************/
10 void hb_log( char * log, ... );
11
12 int  hb_list_bytes( hb_list_t * );
13 void hb_list_seebytes( hb_list_t * l, uint8_t * dst, int size );
14 void hb_list_getbytes( hb_list_t * l, uint8_t * dst, int size,
15                        uint64_t * pts, uint64_t * pos );
16 void hb_list_empty( hb_list_t ** );
17
18 hb_title_t * hb_title_init( char * dvd, int index );
19 void         hb_title_close( hb_title_t ** );
20
21 /***********************************************************************
22  * hb.c
23  **********************************************************************/
24 int  hb_get_pid( hb_handle_t * );
25 void hb_set_state( hb_handle_t *, hb_state_t * );
26
27 /***********************************************************************
28  * fifo.c
29  **********************************************************************/
30 struct hb_buffer_s
31 {
32     int           size;
33     int           alloc;
34     uint8_t *     data;
35     int           cur;
36
37     int           id;
38     int64_t       start;
39     int64_t       stop;
40     int           new_chap;
41
42 #define HB_FRAME_IDR    0x01
43 #define HB_FRAME_I      0x02
44 #define HB_FRAME_AUDIO  0x04
45 #define HB_FRAME_P      0x10
46 #define HB_FRAME_B      0x20
47 #define HB_FRAME_BREF   0x40
48 #define HB_FRAME_KEY    0x0F
49 #define HB_FRAME_REF    0xF0
50     uint8_t       frametype;
51
52     /* Holds the output PTS from x264, for use by b-frame offsets in muxmp4.c */
53     int64_t     renderOffset;
54
55     int           x;
56     int           y;
57     int           width;
58     int           height;
59
60     hb_buffer_t * sub;
61
62     hb_buffer_t * next;
63 };
64
65 hb_buffer_t * hb_buffer_init( int size );
66 void          hb_buffer_realloc( hb_buffer_t *, int size );
67 void          hb_buffer_close( hb_buffer_t ** );
68
69
70 hb_fifo_t   * hb_fifo_init();
71 int           hb_fifo_size( hb_fifo_t * );
72 int           hb_fifo_is_full( hb_fifo_t * );
73 float         hb_fifo_percent_full( hb_fifo_t * f );
74 hb_buffer_t * hb_fifo_get( hb_fifo_t * );
75 hb_buffer_t * hb_fifo_see( hb_fifo_t * );
76 hb_buffer_t * hb_fifo_see2( hb_fifo_t * );
77 void          hb_fifo_push( hb_fifo_t *, hb_buffer_t * );
78 void          hb_fifo_close( hb_fifo_t ** );
79
80 /***********************************************************************
81  * Threads: update.c, scan.c, work.c, reader.c, muxcommon.c
82  **********************************************************************/
83 hb_thread_t * hb_update_init( int * build, char * version );
84 hb_thread_t * hb_scan_init( hb_handle_t *, const char * path,
85                             int title_index, hb_list_t * list_title );
86 hb_thread_t * hb_work_init( hb_list_t * jobs, int cpu_count,
87                             volatile int * die, int * error );
88 hb_thread_t  * hb_reader_init( hb_job_t * );
89 hb_thread_t  * hb_muxer_init( hb_job_t * );
90
91 /***********************************************************************
92  * libmpeg2 wrapper
93  ***********************************************************************
94  * It is exported here because it is used at several places
95  **********************************************************************/
96 typedef struct   hb_libmpeg2_s hb_libmpeg2_t;
97
98 hb_libmpeg2_t  * hb_libmpeg2_init();
99 int              hb_libmpeg2_decode( hb_libmpeg2_t *,
100                                       hb_buffer_t * es_buf,
101                                       hb_list_t * raw_list );
102 void             hb_libmpeg2_info( hb_libmpeg2_t * m, int * width,
103                                     int * height, int * rate, int * aspect_ratio );
104 void             hb_libmpeg2_close( hb_libmpeg2_t ** );
105
106 /***********************************************************************
107  * mpegdemux.c
108  **********************************************************************/
109 int hb_demux_ps( hb_buffer_t * ps_buf, hb_list_t * es_list );
110
111 /***********************************************************************
112  * dvd.c
113  **********************************************************************/
114 typedef struct hb_dvd_s hb_dvd_t;
115 typedef struct hb_stream_s hb_stream_t;
116
117 hb_dvd_t *   hb_dvd_init( char * path );
118 int          hb_dvd_title_count( hb_dvd_t * );
119 hb_title_t * hb_dvd_title_scan( hb_dvd_t *, int title );
120 int          hb_dvd_start( hb_dvd_t *, int title, int chapter );
121 void         hb_dvd_stop( hb_dvd_t * );
122 int          hb_dvd_seek( hb_dvd_t *, float );
123 int          hb_dvd_read( hb_dvd_t *, hb_buffer_t * );
124 int          hb_dvd_chapter( hb_dvd_t * );
125 int          hb_dvd_is_break( hb_dvd_t * d );
126 void         hb_dvd_close( hb_dvd_t ** );
127
128 int         hb_stream_is_stream_type( char * path);
129 hb_stream_t * hb_stream_open( char * path );
130 void             hb_stream_close( hb_stream_t ** );
131 hb_title_t * hb_stream_title_scan( hb_stream_t *);
132 int          hb_stream_read( hb_stream_t *, hb_buffer_t *);
133 int          hb_stream_seek( hb_stream_t *, float );
134 void             hb_stream_update_audio( hb_stream_t *, hb_audio_t *);
135 void             hb_stream_set_selected_audio_pid_index(hb_stream_t *, int);
136
137 /***********************************************************************
138  * Work objects
139  **********************************************************************/
140 #define HB_CONFIG_MAX_SIZE 8192
141 union hb_esconfig_u
142 {
143
144     struct
145     {
146         uint8_t bytes[HB_CONFIG_MAX_SIZE];
147         int     length;
148     } mpeg4;
149
150         struct
151         {
152             uint8_t  sps[HB_CONFIG_MAX_SIZE];
153             int       sps_length;
154             uint8_t  pps[HB_CONFIG_MAX_SIZE];
155             int       pps_length;
156         } h264;
157
158     struct
159     {
160         uint8_t bytes[HB_CONFIG_MAX_SIZE];
161         int     length;
162     } aac;
163
164     struct
165     {
166         uint8_t headers[3][HB_CONFIG_MAX_SIZE];
167         char *language;
168     } vorbis;
169     
170     struct
171     {
172         /* ac3flags stores the flags from the AC3 source, as found in scan.c */
173         int  ac3flags;
174     } a52;
175
176     struct
177     {
178         /* dcaflags stores the flags from the DCA source, as found in scan.c */
179         int  dcaflags;
180     } dca;
181
182 };
183
184 enum
185 {
186     WORK_SYNC = 1,
187     WORK_DECMPEG2,
188     WORK_DECSUB,
189     WORK_RENDER,
190     WORK_ENCAVCODEC,
191     WORK_ENCXVID,
192     WORK_ENCX264,
193     WORK_DECA52,
194     WORK_DECDCA,
195     WORK_DECAVCODEC,
196     WORK_DECLPCM,
197     WORK_ENCFAAC,
198     WORK_ENCLAME,
199     WORK_ENCVORBIS
200 };
201
202 extern hb_work_object_t * hb_objects;
203
204 #define HB_WORK_IDLE     0
205 #define HB_WORK_OK       1
206 #define HB_WORK_ERROR    2
207 #define HB_WORK_DONE     3
208
209 /***********************************************************************
210  * Muxers
211  **********************************************************************/
212 typedef struct hb_mux_object_s hb_mux_object_t;
213 typedef struct hb_mux_data_s   hb_mux_data_t;
214
215 #define HB_MUX_COMMON \
216     int (*init)      ( hb_mux_object_t * ); \
217     int (*mux)       ( hb_mux_object_t *, hb_mux_data_t *, \
218                        hb_buffer_t * ); \
219     int (*end)       ( hb_mux_object_t * );
220
221 #define DECLARE_MUX( a ) \
222     hb_mux_object_t  * hb_mux_##a##_init( hb_job_t * );
223
224 DECLARE_MUX( mp4 );
225 DECLARE_MUX( avi );
226 DECLARE_MUX( ogm );
227 DECLARE_MUX( mkv );
228