OSDN Git Service

Get rid of excessive video & audio drops on some content by implementing the last...
[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.fr/>.
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 void hb_error( char * fmt, ...);
12
13 int  hb_list_bytes( hb_list_t * );
14 void hb_list_seebytes( hb_list_t * l, uint8_t * dst, int size );
15 void hb_list_getbytes( hb_list_t * l, uint8_t * dst, int size,
16                        uint64_t * pts, uint64_t * pos );
17 void hb_list_empty( hb_list_t ** );
18
19 hb_title_t * hb_title_init( char * dvd, int index );
20 void         hb_title_close( hb_title_t ** );
21
22 void         hb_filter_close( hb_filter_object_t ** );
23
24 /***********************************************************************
25  * hb.c
26  **********************************************************************/
27 int  hb_get_pid( hb_handle_t * );
28 void hb_set_state( hb_handle_t *, hb_state_t * );
29
30 /***********************************************************************
31  * fifo.c
32  **********************************************************************/
33 struct hb_buffer_s
34 {
35     int           size;
36     int           alloc;
37     uint8_t *     data;
38     int           cur;
39
40     int64_t       sequence;
41
42     int           id;
43     int64_t       start;
44     int64_t       stop;
45     int           new_chap;
46
47 #define HB_FRAME_IDR    0x01
48 #define HB_FRAME_I      0x02
49 #define HB_FRAME_AUDIO  0x04
50 #define HB_FRAME_P      0x10
51 #define HB_FRAME_B      0x20
52 #define HB_FRAME_BREF   0x40
53 #define HB_FRAME_KEY    0x0F
54 #define HB_FRAME_REF    0xF0
55     uint8_t       frametype;
56     uint16_t       flags;
57
58     /* Holds the output PTS from x264, for use by b-frame offsets in muxmp4.c */
59     int64_t     renderOffset;
60
61     int           x;
62     int           y;
63     int           width;
64     int           height;
65
66     hb_buffer_t * sub;
67
68     hb_buffer_t * next;
69 };
70
71 void hb_buffer_pool_init( void );
72 void hb_buffer_pool_free( void );
73
74 hb_buffer_t * hb_buffer_init( int size );
75 void          hb_buffer_realloc( hb_buffer_t *, int size );
76 void          hb_buffer_close( hb_buffer_t ** );
77 void          hb_buffer_copy_settings( hb_buffer_t * dst,
78                                        const hb_buffer_t * src );
79
80 hb_fifo_t   * hb_fifo_init();
81 int           hb_fifo_size( hb_fifo_t * );
82 int           hb_fifo_is_full( hb_fifo_t * );
83 float         hb_fifo_percent_full( hb_fifo_t * f );
84 hb_buffer_t * hb_fifo_get( hb_fifo_t * );
85 hb_buffer_t * hb_fifo_see( hb_fifo_t * );
86 hb_buffer_t * hb_fifo_see2( hb_fifo_t * );
87 void          hb_fifo_push( hb_fifo_t *, hb_buffer_t * );
88 void          hb_fifo_close( hb_fifo_t ** );
89
90 /***********************************************************************
91  * Threads: update.c, scan.c, work.c, reader.c, muxcommon.c
92  **********************************************************************/
93 hb_thread_t * hb_update_init( int * build, char * version );
94 hb_thread_t * hb_scan_init( hb_handle_t *, const char * path,
95                             int title_index, hb_list_t * list_title );
96 hb_thread_t * hb_work_init( hb_list_t * jobs, int cpu_count,
97                             volatile int * die, int * error, hb_job_t ** job );
98 hb_thread_t  * hb_reader_init( hb_job_t * );
99 hb_thread_t  * hb_muxer_init( hb_job_t * );
100 hb_work_object_t * hb_get_work( int );
101 hb_work_object_t * hb_codec_decoder( int );
102 hb_work_object_t * hb_codec_encoder( int );
103
104 /***********************************************************************
105  * mpegdemux.c
106  **********************************************************************/
107 typedef struct {
108     int64_t last_scr;       /* unadjusted SCR from most recent pack */
109     int     scr_changes;    /* number of SCR discontinuities */
110 } hb_psdemux_t;
111
112 int hb_demux_ps( hb_buffer_t * ps_buf, hb_list_t * es_list, hb_psdemux_t * );
113 int hb_demux_null( hb_buffer_t * ps_buf, hb_list_t * es_list, hb_psdemux_t * );
114
115 /***********************************************************************
116  * dvd.c
117  **********************************************************************/
118 typedef struct hb_dvd_s hb_dvd_t;
119 typedef struct hb_stream_s hb_stream_t;
120
121 hb_dvd_t *   hb_dvd_init( char * path );
122 int          hb_dvd_title_count( hb_dvd_t * );
123 hb_title_t * hb_dvd_title_scan( hb_dvd_t *, int title );
124 int          hb_dvd_start( hb_dvd_t *, int title, int chapter );
125 void         hb_dvd_stop( hb_dvd_t * );
126 int          hb_dvd_seek( hb_dvd_t *, float );
127 int          hb_dvd_read( hb_dvd_t *, hb_buffer_t * );
128 int          hb_dvd_chapter( hb_dvd_t * );
129 int          hb_dvd_is_break( hb_dvd_t * d );
130 void         hb_dvd_close( hb_dvd_t ** );
131
132 hb_stream_t * hb_stream_open( char * path, hb_title_t *title );
133 void             hb_stream_close( hb_stream_t ** );
134 hb_title_t * hb_stream_title_scan( hb_stream_t *);
135 int          hb_stream_read( hb_stream_t *, hb_buffer_t *);
136 int          hb_stream_seek( hb_stream_t *, float );
137
138 void       * hb_ffmpeg_context( int codec_param );
139 void       * hb_ffmpeg_avstream( int codec_param );
140
141 /***********************************************************************
142  * Work objects
143  **********************************************************************/
144 #define HB_CONFIG_MAX_SIZE 8192
145 union hb_esconfig_u
146 {
147
148     struct
149     {
150         uint8_t bytes[HB_CONFIG_MAX_SIZE];
151         int     length;
152     } mpeg4;
153
154         struct
155         {
156             uint8_t  sps[HB_CONFIG_MAX_SIZE];
157             int       sps_length;
158             uint8_t  pps[HB_CONFIG_MAX_SIZE];
159             int       pps_length;
160         } h264;
161
162     struct
163     {
164         uint8_t headers[3][HB_CONFIG_MAX_SIZE];
165     } theora;
166
167     struct
168     {
169         uint8_t bytes[HB_CONFIG_MAX_SIZE];
170         int     length;
171     } aac;
172
173     struct
174     {
175         uint8_t headers[3][HB_CONFIG_MAX_SIZE];
176         char *language;
177     } vorbis;
178
179     struct
180     {
181         /* ac3flags stores the flags from the AC3 source, as found in scan.c */
182         int  ac3flags;
183     } a52;
184
185     struct
186     {
187         /* dcaflags stores the flags from the DCA source, as found in scan.c */
188         int  dcaflags;
189     } dca;
190
191 };
192
193 enum
194 {
195     WORK_SYNC = 1,
196     WORK_DECMPEG2,
197     WORK_DECSUB,
198     WORK_RENDER,
199     WORK_ENCAVCODEC,
200     WORK_ENCXVID,
201     WORK_ENCX264,
202     WORK_ENCTHEORA,
203     WORK_DECA52,
204     WORK_DECDCA,
205     WORK_DECAVCODEC,
206     WORK_DECAVCODECV,
207     WORK_DECAVCODECVI,
208     WORK_DECAVCODECAI,
209     WORK_DECLPCM,
210     WORK_ENCFAAC,
211     WORK_ENCLAME,
212     WORK_ENCVORBIS
213 };
214
215 enum
216 {
217     FILTER_DEINTERLACE = 1,
218     FILTER_DEBLOCK,
219     FILTER_DENOISE,
220     FILTER_DETELECINE,
221     FILTER_DECOMB
222 };
223
224 extern hb_work_object_t * hb_objects;
225
226 #define HB_WORK_IDLE     0
227 #define HB_WORK_OK       1
228 #define HB_WORK_ERROR    2
229 #define HB_WORK_DONE     3
230
231 /***********************************************************************
232  * Muxers
233  **********************************************************************/
234 typedef struct hb_mux_object_s hb_mux_object_t;
235 typedef struct hb_mux_data_s   hb_mux_data_t;
236
237 #define HB_MUX_COMMON \
238     int (*init)      ( hb_mux_object_t * ); \
239     int (*mux)       ( hb_mux_object_t *, hb_mux_data_t *, \
240                        hb_buffer_t * ); \
241     int (*end)       ( hb_mux_object_t * );
242
243 #define DECLARE_MUX( a ) \
244     hb_mux_object_t  * hb_mux_##a##_init( hb_job_t * );
245
246 DECLARE_MUX( mp4 );
247 DECLARE_MUX( avi );
248 DECLARE_MUX( ogm );
249 DECLARE_MUX( mkv );
250