input/meta: narrow scope of iteration variables
[vlc.git] / include / vlc_codec.h
blobaf7b979fe298a3a11e43f857f76246286bf40e93
1 /*****************************************************************************
2 * vlc_codec.h: Definition of the decoder and encoder structures
3 *****************************************************************************
4 * Copyright (C) 1999-2003 VLC authors and VideoLAN
5 * $Id$
7 * Authors: Gildas Bazin <gbazin@netcourrier.com>
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.
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.
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 *****************************************************************************/
24 #ifndef VLC_CODEC_H
25 #define VLC_CODEC_H 1
27 #include <vlc_block.h>
28 #include <vlc_es.h>
29 #include <vlc_picture.h>
30 #include <vlc_subpicture.h>
32 /**
33 * \defgroup codec Codec
34 * Decoders and encoders
35 * @{
36 * \file
37 * Decoder and encoder modules interface
39 * \defgroup decoder Decoder
40 * Audio, video and text decoders
41 * @{
44 typedef struct decoder_owner_sys_t decoder_owner_sys_t;
47 * BIG FAT WARNING : the code relies in the first 4 members of filter_t
48 * and decoder_t to be the same, so if you have anything to add, do it
49 * at the end of the structure.
51 struct decoder_t
53 VLC_COMMON_MEMBERS
55 /* Module properties */
56 module_t * p_module;
57 decoder_sys_t * p_sys;
59 /* Input format ie from demuxer (XXX: a lot of field could be invalid) */
60 es_format_t fmt_in;
62 /* Output format of decoder/packetizer */
63 es_format_t fmt_out;
65 /* Tell the decoder if it is allowed to drop frames */
66 bool b_frame_drop_allowed;
68 /* All pf_decode_* and pf_packetize functions have the same behavior.
70 * These functions are called in a loop with the same pp_block argument
71 * until they return NULL. This allows a module implementation to return
72 * more than one frames/samples for one input block.
74 * pp_block or *pp_block can be NULL.
76 * If pp_block and *pp_block are not NULL, the module implementation will
77 * own the input block (*pp_block) and should process and release it. The
78 * module can also process a part of the block. In that case, it should
79 * modify (*pp_block)->p_buffer/i_buffer accordingly and return a valid
80 * frame/samples. The module can also set *pp_block to NULL when the input
81 * block is consumed.
83 * If pp_block is not NULL but *pp_block is NULL, a previous call of the pf
84 * function has set the *pp_block to NULL. Here, the module can return new
85 * frames/samples for the same, already processed, input block (the pf
86 * function will be called as long as the module return a frame/samples).
88 * When the pf function returns NULL, the next call to this function will
89 * have a new a valid pp_block (if the decoder is not drained).
91 * If pp_block is NULL, the decoder asks the module to drain itself. In
92 * that case, the module has to return all frames/samples available (the pf
93 * function will be called as long as the module return a frame/samples).
95 picture_t * ( * pf_decode_video )( decoder_t *, block_t **pp_block );
96 block_t * ( * pf_decode_audio )( decoder_t *, block_t **pp_block );
97 subpicture_t * ( * pf_decode_sub) ( decoder_t *, block_t **pp_block );
98 block_t * ( * pf_packetize ) ( decoder_t *, block_t **pp_block );
99 /* */
100 void ( * pf_flush ) ( decoder_t * );
102 /* Closed Caption (CEA 608/708) extraction.
103 * If set, it *may* be called after pf_decode_video/pf_packetize
104 * returned data. It should return CC for the pictures returned by the
105 * last pf_packetize/pf_decode_video call only,
106 * pb_present will be used to known which cc channel are present (but
107 * globaly, not necessary for the current packet */
108 block_t * ( * pf_get_cc ) ( decoder_t *, bool pb_present[4] );
110 /* Meta data at codec level
111 * The decoder owner set it back to NULL once it has retreived what it needs.
112 * The decoder owner is responsible of its release except when you overwrite it.
114 vlc_meta_t *p_description;
117 * Owner fields
118 * XXX You MUST not use them directly.
121 /* Video output callbacks
122 * XXX use decoder_NewPicture */
123 int (*pf_vout_format_update)( decoder_t * );
124 picture_t *(*pf_vout_buffer_new)( decoder_t * );
127 * Number of extra (ie in addition to the DPB) picture buffers
128 * needed for decoding.
130 int i_extra_picture_buffers;
132 /* Audio output callbacks */
133 int (*pf_aout_format_update)( decoder_t * );
135 /* SPU output callbacks
136 * XXX use decoder_NewSubpicture */
137 subpicture_t *(*pf_spu_buffer_new)( decoder_t *, const subpicture_updater_t * );
139 /* Input attachments
140 * XXX use decoder_GetInputAttachments */
141 int (*pf_get_attachments)( decoder_t *p_dec, input_attachment_t ***ppp_attachment, int *pi_attachment );
143 /* Display date
144 * XXX use decoder_GetDisplayDate */
145 mtime_t (*pf_get_display_date)( decoder_t *, mtime_t );
147 /* Display rate
148 * XXX use decoder_GetDisplayRate */
149 int (*pf_get_display_rate)( decoder_t * );
151 /* XXX use decoder_QueueVideo */
152 int (*pf_queue_video)( decoder_t *, picture_t * );
153 /* XXX use decoder_QueueAudio */
154 int (*pf_queue_audio)( decoder_t *, block_t * );
155 /* XXX use decoder_QueueSub */
156 int (*pf_queue_sub)( decoder_t *, subpicture_t *);
158 /* Private structure for the owner of the decoder */
159 decoder_owner_sys_t *p_owner;
161 bool b_error;
165 * @}
169 * \defgroup encoder Encoder
170 * Audio, video and text encoders
171 * @{
174 struct encoder_t
176 VLC_COMMON_MEMBERS
178 /* Module properties */
179 module_t * p_module;
180 encoder_sys_t * p_sys;
182 /* Properties of the input data fed to the encoder */
183 es_format_t fmt_in;
185 /* Properties of the output of the encoder */
186 es_format_t fmt_out;
188 block_t * ( * pf_encode_video )( encoder_t *, picture_t * );
189 block_t * ( * pf_encode_audio )( encoder_t *, block_t * );
190 block_t * ( * pf_encode_sub )( encoder_t *, subpicture_t * );
192 /* Common encoder options */
193 int i_threads; /* Number of threads to use during encoding */
194 int i_iframes; /* One I frame per i_iframes */
195 int i_bframes; /* One B frame per i_bframes */
196 int i_tolerance; /* Bitrate tolerance */
198 /* Encoder config */
199 config_chain_t *p_cfg;
203 * @}
205 * \ingroup decoder
206 * @{
210 * Updates the video output format.
212 * This function notifies the video output pipeline of a new video output
213 * format (fmt_out.video). If there was no video output from the decoder so far
214 * or if the video output format has changed, a new video output will be set
215 * up. decoder_NewPicture() can then be used to allocate picture buffers.
217 * If the format is unchanged, this function has no effects and returns zero.
219 * \note
220 * This function is not reentrant.
222 * @return 0 if the video output was set up successfully, -1 otherwise.
224 static inline int decoder_UpdateVideoFormat( decoder_t *dec )
226 if( dec->pf_vout_format_update != NULL )
227 return dec->pf_vout_format_update( dec );
228 else
229 return -1;
233 * Allocates an output picture buffer.
235 * This function pulls an output picture buffer for the decoder from the
236 * buffer pool of the video output. The picture must be released with
237 * picture_Release() when it is no longer referenced by the decoder.
239 * \note
240 * This function is reentrant. However, decoder_UpdateVideoFormat() cannot be
241 * used concurrently; the caller is responsible for serialization.
243 * \warning
244 * The behaviour is undefined if decoder_UpdateVideoFormat() was not called or
245 * if the last call returned an error.
247 * \return a picture buffer on success, NULL on error
249 VLC_USED
250 static inline picture_t *decoder_NewPicture( decoder_t *dec )
252 return dec->pf_vout_buffer_new( dec );
256 * Abort any calls of decoder_NewPicture
258 * If b_abort is true, all pending and futures calls of decoder_NewPicture
259 * will be aborted. This function can be used by asynchronous video decoders
260 * to unblock a thread that is waiting for a picture.
262 VLC_API void decoder_AbortPictures( decoder_t *dec, bool b_abort );
265 * This function queues a picture to the video output.
267 * \note
268 * The caller doesn't own the picture anymore after this call (even in case of
269 * error).
270 * FIXME: input_DecoderFrameNext won't work if a module use this function.
272 * \return 0 if the picture is queued, -1 on error
274 static inline int decoder_QueueVideo( decoder_t *dec, picture_t *p_pic )
276 if( !dec->pf_queue_video )
278 picture_Release( p_pic );
279 return -1;
281 return dec->pf_queue_video( dec, p_pic );
285 * This function queues an audio block to the audio output.
287 * \note
288 * The caller doesn't own the audio block anymore after this call (even in case
289 * of error).
291 * \return 0 if the block is queued, -1 on error
293 static inline int decoder_QueueAudio( decoder_t *dec, block_t *p_aout_buf )
295 if( !dec->pf_queue_audio )
297 block_Release( p_aout_buf );
298 return -1;
300 return dec->pf_queue_audio( dec, p_aout_buf );
304 * This function queues a subtitle to the video output.
306 * \note
307 * The caller doesn't own the subtitle anymore after this call (even in case of
308 * error).
310 * \return 0 if the subtitle is queued, -1 on error
312 static inline int decoder_QueueSub( decoder_t *dec, subpicture_t *p_spu )
314 if( !dec->pf_queue_sub )
316 subpicture_Delete( p_spu );
317 return -1;
319 return dec->pf_queue_sub( dec, p_spu );
323 * This function notifies the audio output pipeline of a new audio output
324 * format (fmt_out.audio). If there is currently no audio output or if the
325 * audio output format has changed, a new audio output will be set up.
326 * @return 0 if the audio output is working, -1 if not. */
327 static inline int decoder_UpdateAudioFormat( decoder_t *dec )
329 if( dec->pf_aout_format_update != NULL )
330 return dec->pf_aout_format_update( dec );
331 else
332 return -1;
336 * This function will return a new audio buffer usable by a decoder as an
337 * output buffer. It must be released with block_Release() or returned it to
338 * the caller as a pf_decode_audio return value.
340 VLC_API block_t * decoder_NewAudioBuffer( decoder_t *, int i_size ) VLC_USED;
343 * This function will return a new subpicture usable by a decoder as an output
344 * buffer. You have to release it using subpicture_Delete() or by returning
345 * it to the caller as a pf_decode_sub return value.
347 VLC_API subpicture_t * decoder_NewSubpicture( decoder_t *, const subpicture_updater_t * ) VLC_USED;
350 * Request that the decoder should be reloaded. The current module will be
351 * unloaded. Reloading a module may cause a loss of frames. There is no
352 * warranty that pf_decode_* callbacks won't be called again after this call.
354 VLC_API void decoder_RequestReload( decoder_t * );
357 * This function gives all input attachments at once.
359 * You MUST release the returned values
361 VLC_API int decoder_GetInputAttachments( decoder_t *, input_attachment_t ***ppp_attachment, int *pi_attachment );
364 * This function converts a decoder timestamp into a display date comparable
365 * to mdate().
366 * You MUST use it *only* for gathering statistics about speed.
368 VLC_API mtime_t decoder_GetDisplayDate( decoder_t *, mtime_t ) VLC_USED;
371 * This function returns the current input rate.
372 * You MUST use it *only* for gathering statistics about speed.
374 VLC_API int decoder_GetDisplayRate( decoder_t * ) VLC_USED;
376 /** @} */
377 /** @} */
378 #endif /* _VLC_CODEC_H */