]> git.sesse.net Git - vlc/blob - include/vlc_codec.h
macosx: Fix resume playback in certain situations
[vlc] / include / vlc_codec.h
1 /*****************************************************************************
2  * vlc_codec.h: Definition of the decoder and encoder structures
3  *****************************************************************************
4  * Copyright (C) 1999-2003 VLC authors and VideoLAN
5  * $Id$
6  *
7  * Authors: Gildas Bazin <gbazin@netcourrier.com>
8  *
9  * This program is free software; you can redistribute it and/or modify it
10  * under the terms of the GNU Lesser General Public License as published by
11  * the Free Software Foundation; either version 2.1 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public License
20  * along with this program; if not, write to the Free Software Foundation,
21  * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23
24 #ifndef VLC_CODEC_H
25 #define VLC_CODEC_H 1
26
27 #include <vlc_block.h>
28 #include <vlc_es.h>
29 #include <vlc_picture.h>
30 #include <vlc_subpicture.h>
31
32 /**
33  * \file
34  * This file defines the structure and types used by decoders and encoders
35  */
36
37 typedef struct decoder_owner_sys_t decoder_owner_sys_t;
38
39 /**
40  * \defgroup decoder Decoder
41  *
42  * The structure describing a decoder
43  *
44  * @{
45  */
46
47 /*
48  * BIG FAT WARNING : the code relies in the first 4 members of filter_t
49  * and decoder_t to be the same, so if you have anything to add, do it
50  * at the end of the structure.
51  */
52 struct decoder_t
53 {
54     VLC_COMMON_MEMBERS
55
56     /* Module properties */
57     module_t *          p_module;
58     decoder_sys_t *     p_sys;
59
60     /* Input format ie from demuxer (XXX: a lot of field could be invalid) */
61     es_format_t         fmt_in;
62
63     /* Output format of decoder/packetizer */
64     es_format_t         fmt_out;
65
66     /* Some decoders only accept packetized data (ie. not truncated) */
67     bool                b_need_packetized;
68
69     /* Tell the decoder if it is allowed to drop frames */
70     bool                b_pace_control;
71
72     /* */
73     picture_t *         ( * pf_decode_video )( decoder_t *, block_t ** );
74     block_t *           ( * pf_decode_audio )( decoder_t *, block_t ** );
75     subpicture_t *      ( * pf_decode_sub)   ( decoder_t *, block_t ** );
76     block_t *           ( * pf_packetize )   ( decoder_t *, block_t ** );
77
78     /* Closed Caption (CEA 608/708) extraction.
79      * If set, it *may* be called after pf_decode_video/pf_packetize
80      * returned data. It should return CC for the pictures returned by the
81      * last pf_packetize/pf_decode_video call only,
82      * pb_present will be used to known which cc channel are present (but
83      * globaly, not necessary for the current packet */
84     block_t *           ( * pf_get_cc )      ( decoder_t *, bool pb_present[4] );
85
86     /* Meta data at codec level
87      *  The decoder owner set it back to NULL once it has retreived what it needs.
88      *  The decoder owner is responsible of its release except when you overwrite it.
89      */
90     vlc_meta_t          *p_description;
91
92     /*
93      * Owner fields
94      * XXX You MUST not use them directly.
95      */
96
97     /* Video output callbacks
98      * XXX use decoder_NewPicture/decoder_DeletePicture
99      * and decoder_UnlinkPicture */
100     int             (*pf_vout_format_update)( decoder_t * );
101     picture_t      *(*pf_vout_buffer_new)( decoder_t * );
102     void            (*pf_vout_buffer_del)( decoder_t *, picture_t * );
103     void            (*pf_picture_unlink) ( decoder_t *, picture_t * );
104
105     /**
106      * Number of extra (ie in addition to the DPB) picture buffers
107      * needed for decoding.
108      */
109     int             i_extra_picture_buffers;
110
111     /* Audio output callbacks */
112     int             (*pf_aout_format_update)( decoder_t * );
113
114     /* SPU output callbacks
115      * XXX use decoder_NewSubpicture and decoder_DeleteSubpicture */
116     subpicture_t   *(*pf_spu_buffer_new)( decoder_t *, const subpicture_updater_t * );
117     void            (*pf_spu_buffer_del)( decoder_t *, subpicture_t * );
118
119     /* Input attachments
120      * XXX use decoder_GetInputAttachments */
121     int             (*pf_get_attachments)( decoder_t *p_dec, input_attachment_t ***ppp_attachment, int *pi_attachment );
122
123     /* Display date
124      * XXX use decoder_GetDisplayDate */
125     mtime_t         (*pf_get_display_date)( decoder_t *, mtime_t );
126
127     /* Display rate
128      * XXX use decoder_GetDisplayRate */
129     int             (*pf_get_display_rate)( decoder_t * );
130
131     /* Private structure for the owner of the decoder */
132     decoder_owner_sys_t *p_owner;
133
134     bool                b_error;
135 };
136
137 /**
138  * @}
139  */
140
141 /**
142  * \defgroup encoder Encoder
143  *
144  * The structure describing a Encoder
145  *
146  * @{
147  */
148
149 struct encoder_t
150 {
151     VLC_COMMON_MEMBERS
152
153     /* Module properties */
154     module_t *          p_module;
155     encoder_sys_t *     p_sys;
156
157     /* Properties of the input data fed to the encoder */
158     es_format_t         fmt_in;
159
160     /* Properties of the output of the encoder */
161     es_format_t         fmt_out;
162
163     block_t *           ( * pf_encode_video )( encoder_t *, picture_t * );
164     block_t *           ( * pf_encode_audio )( encoder_t *, block_t * );
165     block_t *           ( * pf_encode_sub )( encoder_t *, subpicture_t * );
166
167     /* Common encoder options */
168     int i_threads;               /* Number of threads to use during encoding */
169     int i_iframes;               /* One I frame per i_iframes */
170     int i_bframes;               /* One B frame per i_bframes */
171     int i_tolerance;             /* Bitrate tolerance */
172
173     /* Encoder config */
174     config_chain_t *p_cfg;
175 };
176
177 /**
178  * @}
179  */
180
181
182 /**
183  * This function notifies the video output pipeline of a new video output
184  * format (fmt_out.video). If there is currently no video output or if the
185  * video output format has changed, a new audio video will be set up.
186  * @return 0 if the video output is working, -1 if not. */
187 static inline int decoder_UpdateVideoFormat( decoder_t *dec )
188 {
189     if( dec->pf_vout_format_update != NULL )
190         return dec->pf_vout_format_update( dec );
191     else
192         return -1;
193 }
194
195 /**
196  * This function will return a new picture usable by a decoder as an output
197  * buffer. You have to release it using decoder_DeletePicture or by returning
198  * it to the caller as a pf_decode_video return value.
199  */
200 VLC_API picture_t * decoder_NewPicture( decoder_t * ) VLC_USED;
201
202 /**
203  * This function will release a picture create by decoder_NewPicture.
204  */
205 VLC_API void decoder_DeletePicture( decoder_t *, picture_t *p_picture );
206
207 /**
208  * This function will decrease the picture reference count.
209  * (picture_Release is not usable.)
210  */
211 VLC_API void decoder_UnlinkPicture( decoder_t *, picture_t * );
212
213 /**
214  * This function notifies the audio output pipeline of a new audio output
215  * format (fmt_out.audio). If there is currently no audio output or if the
216  * audio output format has changed, a new audio output will be set up.
217  * @return 0 if the audio output is working, -1 if not. */
218 static inline int decoder_UpdateAudioFormat( decoder_t *dec )
219 {
220     if( dec->pf_aout_format_update != NULL )
221         return dec->pf_aout_format_update( dec );
222     else
223         return -1;
224 }
225
226 /**
227  * This function will return a new audio buffer usable by a decoder as an
228  * output buffer. You have to release it using decoder_DeleteAudioBuffer
229  * or by returning it to the caller as a pf_decode_audio return value.
230  */
231 VLC_API block_t * decoder_NewAudioBuffer( decoder_t *, int i_size ) VLC_USED;
232
233 /**
234  * This function will return a new subpicture usable by a decoder as an output
235  * buffer. You have to release it using decoder_DeleteSubpicture or by returning
236  * it to the caller as a pf_decode_sub return value.
237  */
238 VLC_API subpicture_t * decoder_NewSubpicture( decoder_t *, const subpicture_updater_t * ) VLC_USED;
239
240 /**
241  * This function will release a subpicture created by decoder_NewSubicture.
242  */
243 VLC_API void decoder_DeleteSubpicture( decoder_t *, subpicture_t *p_subpicture );
244
245 /**
246  * This function gives all input attachments at once.
247  *
248  * You MUST release the returned values
249  */
250 VLC_API int decoder_GetInputAttachments( decoder_t *, input_attachment_t ***ppp_attachment, int *pi_attachment );
251
252 /**
253  * This function converts a decoder timestamp into a display date comparable
254  * to mdate().
255  * You MUST use it *only* for gathering statistics about speed.
256  */
257 VLC_API mtime_t decoder_GetDisplayDate( decoder_t *, mtime_t ) VLC_USED;
258
259 /**
260  * This function returns the current input rate.
261  * You MUST use it *only* for gathering statistics about speed.
262  */
263 VLC_API int decoder_GetDisplayRate( decoder_t * ) VLC_USED;
264
265 #endif /* _VLC_CODEC_H */