1 /*****************************************************************************
2 * vlc_codec.h: Definition of the decoder and encoder structures
3 *****************************************************************************
4 * Copyright (C) 1999-2003 VLC authors and VideoLAN
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 *****************************************************************************/
27 #include <vlc_block.h>
29 #include <vlc_picture.h>
30 #include <vlc_subpicture.h>
33 * \defgroup codec Codec
34 * Decoders and encoders
37 * Decoder and encoder modules interface
39 * \defgroup decoder Decoder
40 * Audio, video and text decoders
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.
55 /* Module properties */
57 decoder_sys_t
* p_sys
;
59 /* Input format ie from demuxer (XXX: a lot of field could be invalid) */
62 /* Output format of decoder/packetizer */
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
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
);
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
;
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
* );
140 * XXX use decoder_GetInputAttachments */
141 int (*pf_get_attachments
)( decoder_t
*p_dec
, input_attachment_t
***ppp_attachment
, int *pi_attachment
);
144 * XXX use decoder_GetDisplayDate */
145 mtime_t (*pf_get_display_date
)( decoder_t
*, mtime_t
);
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
;
169 * \defgroup encoder Encoder
170 * Audio, video and text encoders
178 /* Module properties */
180 encoder_sys_t
* p_sys
;
182 /* Properties of the input data fed to the encoder */
185 /* Properties of the output of the encoder */
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 */
199 config_chain_t
*p_cfg
;
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_GetPicture() can then be used to allocate picture buffers.
217 * If the format is unchanged, this function has no effects and returns zero.
220 * This function is not reentrant.
222 * @return 0 if the video output was set up succesfully, -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
);
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.
240 * This function is reentrant. However, decoder_UpdateVideoFormat() cannot be
241 * used concurrently; the caller is responsible for serialization.
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
250 static inline picture_t
*decoder_GetPicture( decoder_t
*dec
)
252 return dec
->pf_vout_buffer_new( dec
);
256 * Checks the format and allocates a picture buffer.
258 * This common helper function sets the output video output format and
259 * allocates a picture buffer in that format. The picture must be released with
260 * picture_Release() when it is no longer referenced by the decoder.
263 * Lile decoder_UpdateVideoFormat(), this function is not reentrant.
265 * \return a picture buffer on success, NULL on error
268 static inline picture_t
*decoder_NewPicture( decoder_t
*dec
)
270 if( decoder_UpdateVideoFormat(dec
) )
272 return decoder_GetPicture( dec
);
276 * Abort any calls of decoder_NewPicture / decoder_GetPicture
278 * If b_abort is true, all pending and futures calls of decoder_NewPicture /
279 * decoder_GetPicture will be aborted. This function can be used by
280 * asynchronous video decoders to unblock a thread that is waiting for a
283 VLC_API
void decoder_AbortPictures( decoder_t
*dec
, bool b_abort
);
286 * This function queues a picture to the video output.
289 * The caller doesn't own the picture anymore after this call (even in case of
291 * FIXME: input_DecoderFrameNext won't work if a module use this function.
293 * \return 0 if the picture is queued, -1 on error
295 static inline int decoder_QueueVideo( decoder_t
*dec
, picture_t
*p_pic
)
297 if( !dec
->pf_queue_video
)
299 picture_Release( p_pic
);
302 return dec
->pf_queue_video( dec
, p_pic
);
306 * This function queues an audio block to the audio output.
309 * The caller doesn't own the audio block anymore after this call (even in case
312 * \return 0 if the block is queued, -1 on error
314 static inline int decoder_QueueAudio( decoder_t
*dec
, block_t
*p_aout_buf
)
316 if( !dec
->pf_queue_audio
)
318 block_Release( p_aout_buf
);
321 return dec
->pf_queue_audio( dec
, p_aout_buf
);
325 * This function queues a subtitle to the video output.
328 * The caller doesn't own the subtitle anymore after this call (even in case of
331 * \return 0 if the subtitle is queued, -1 on error
333 static inline int decoder_QueueSub( decoder_t
*dec
, subpicture_t
*p_spu
)
335 if( !dec
->pf_queue_sub
)
337 subpicture_Delete( p_spu
);
340 return dec
->pf_queue_sub( dec
, p_spu
);
344 * This function notifies the audio output pipeline of a new audio output
345 * format (fmt_out.audio). If there is currently no audio output or if the
346 * audio output format has changed, a new audio output will be set up.
347 * @return 0 if the audio output is working, -1 if not. */
348 static inline int decoder_UpdateAudioFormat( decoder_t
*dec
)
350 if( dec
->pf_aout_format_update
!= NULL
)
351 return dec
->pf_aout_format_update( dec
);
357 * This function will return a new audio buffer usable by a decoder as an
358 * output buffer. It must be released with block_Release() or returned it to
359 * the caller as a pf_decode_audio return value.
361 VLC_API block_t
* decoder_NewAudioBuffer( decoder_t
*, int i_size
) VLC_USED
;
364 * This function will return a new subpicture usable by a decoder as an output
365 * buffer. You have to release it using subpicture_Delete() or by returning
366 * it to the caller as a pf_decode_sub return value.
368 VLC_API subpicture_t
* decoder_NewSubpicture( decoder_t
*, const subpicture_updater_t
* ) VLC_USED
;
371 * This function gives all input attachments at once.
373 * You MUST release the returned values
375 VLC_API
int decoder_GetInputAttachments( decoder_t
*, input_attachment_t
***ppp_attachment
, int *pi_attachment
);
378 * This function converts a decoder timestamp into a display date comparable
380 * You MUST use it *only* for gathering statistics about speed.
382 VLC_API mtime_t
decoder_GetDisplayDate( decoder_t
*, mtime_t
) VLC_USED
;
385 * This function returns the current input rate.
386 * You MUST use it *only* for gathering statistics about speed.
388 VLC_API
int decoder_GetDisplayRate( decoder_t
* ) VLC_USED
;
392 #endif /* _VLC_CODEC_H */