qt: actions_manager: compareRenderers -> getMatchingRenderer
[vlc.git] / include / vlc_demux.h
blobb27703e480a04ce91e947b7014f0624cb28d9f0c
1 /*****************************************************************************
2 * vlc_demux.h: Demuxer descriptor, queries and methods
3 *****************************************************************************
4 * Copyright (C) 1999-2005 VLC authors and VideoLAN
5 * $Id$
7 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
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_DEMUX_H
25 #define VLC_DEMUX_H 1
27 #include <stdlib.h>
28 #include <string.h>
30 #include <vlc_es.h>
31 #include <vlc_stream.h>
32 #include <vlc_es_out.h>
34 /**
35 * \defgroup demux Demultiplexer
36 * \ingroup input
37 * Demultiplexers (file format parsers)
38 * @{
39 * \file
40 * Demultiplexer modules interface
43 struct demux_t
45 struct vlc_common_members obj;
47 /* Module properties */
48 module_t *p_module;
50 /* eg informative but needed (we can have access+demux) */
51 char *psz_name;
52 char *psz_url;
53 const char *psz_location;
54 char *psz_filepath;
56 union {
57 /**
58 * Input stream
60 * Depending on the module capability:
61 * - "demux": input byte stream (not NULL)
62 * - "access_demux": a NULL pointer
63 * - "demux_filter": undefined
65 stream_t *s;
66 /**
67 * Input demuxer
69 * If the module capability is "demux_filter", this is the upstream
70 * demuxer or demux filter. Otherwise, this is undefined.
72 demux_t *p_next;
75 /* es output */
76 es_out_t *out; /* our p_es_out */
78 bool b_preparsing; /* True if the demux is used to preparse */
80 /* set by demuxer */
81 int (*pf_demux) ( demux_t * ); /* demux one frame only */
82 int (*pf_control)( demux_t *, int i_query, va_list args);
84 /* Demux has to maintain them uptodate
85 * when it is responsible of seekpoint/title */
86 struct
88 unsigned int i_update; /* Demux sets them on change,
89 Input removes them once take into account*/
90 } info;
91 void *p_sys;
93 /* Weak link to parent input */
94 input_thread_t *p_input;
97 /* pf_demux return values */
98 #define VLC_DEMUXER_EOF 0
99 #define VLC_DEMUXER_EGENERIC -1
100 #define VLC_DEMUXER_SUCCESS 1
102 /* demux_t.info.i_update field */
103 #define INPUT_UPDATE_TITLE 0x0010
104 #define INPUT_UPDATE_SEEKPOINT 0x0020
105 #define INPUT_UPDATE_META 0x0040
106 #define INPUT_UPDATE_TITLE_LIST 0x0100
108 /* demux_meta_t is returned by "meta reader" module to the demuxer */
109 typedef struct demux_meta_t
111 struct vlc_common_members obj;
112 input_item_t *p_item; /***< the input item that is being read */
114 vlc_meta_t *p_meta; /**< meta data */
116 int i_attachments; /**< number of attachments */
117 input_attachment_t **attachments; /**< array of attachments */
118 } demux_meta_t;
121 * Control query identifiers for use with demux_t.pf_control
123 * In the individual identifier description, the input stream refers to
124 * demux_t.s if non-NULL, and the output refers to demux_t.out.
126 * A demuxer is synchronous if it only accesses its input stream and the
127 * output from within its demux_t callbacks, i.e. demux.pf_demux and
128 * demux_t.pf_control.
130 * A demuxer is threaded if it accesses either or both input and output
131 * asynchronously.
133 * An access-demuxer is a demuxer without input, i.e. demux_t.s == NULL).
135 enum demux_query_e
137 /** Checks whether the stream supports seeking.
138 * Can fail if seeking is not supported (same as returning false).
139 * \bug Failing should not be allowed.
141 * arg1 = bool * */
142 DEMUX_CAN_SEEK,
144 /** Checks whether (long) pause then stream resumption is supported.
145 * Can fail only if synchronous and <b>not</b> an access-demuxer. The
146 * underlying input stream then determines if pause is supported.
147 * \bug Failing should not be allowed.
149 * arg1= bool * */
150 DEMUX_CAN_PAUSE = 0x002,
152 /** Whether the stream can be read at an arbitrary pace.
153 * Cannot fail.
155 * arg1= bool * */
156 DEMUX_CAN_CONTROL_PACE,
158 /** Retrieves the PTS delay (roughly the default buffer duration).
159 * Can fail only if synchronous and <b>not</b> an access-demuxer. The
160 * underlying input stream then determines the PTS delay.
162 * arg1= int64_t * */
163 DEMUX_GET_PTS_DELAY = 0x101,
165 /** Retrieves stream meta-data.
166 * Should fail if no meta-data were retrieved.
168 * arg1= vlc_meta_t * */
169 DEMUX_GET_META = 0x105,
171 /** Retrieves an estimate of signal quality and strength.
172 * Can fail.
174 * arg1=double *quality, arg2=double *strength */
175 DEMUX_GET_SIGNAL = 0x107,
177 /** Sets the paused or playing/resumed state.
179 * Streams are initially in playing state. The control always specifies a
180 * change from paused to playing (false) or from playing to paused (true)
181 * and streams are initially playing; a no-op cannot be requested.
183 * The control is never used if DEMUX_CAN_PAUSE fails.
184 * Can fail.
186 * arg1= bool */
187 DEMUX_SET_PAUSE_STATE = 0x200,
189 /** Seeks to the beginning of a title.
191 * The control is never used if DEMUX_GET_TITLE_INFO fails.
192 * Can fail.
194 * arg1= int */
195 DEMUX_SET_TITLE,
197 /** Seeks to the beginning of a chapter of the current title.
199 * The control is never used if DEMUX_GET_TITLE_INFO fails.
200 * Can fail.
202 * arg1= int */
203 DEMUX_SET_SEEKPOINT, /* arg1= int can fail */
205 /** Check which INPUT_UPDATE_XXX flag is set and reset the ones set.
207 * The unsigned* argument is set with the flags needed to be checked,
208 * on return it contains the values that were reset during the call
210 * This can can fail, in which case flags from demux_t.info.i_update
211 * are read/reset
213 * arg1= unsigned * */
214 DEMUX_TEST_AND_CLEAR_FLAGS, /* arg1= unsigned* can fail */
216 /** Read the title number currently playing
218 * Can fail.
220 * arg1= int * */
221 DEMUX_GET_TITLE, /* arg1= int* can fail */
223 /* Read the seekpoint/chapter currently playing
225 * Can fail.
227 * arg1= int * */
228 DEMUX_GET_SEEKPOINT, /* arg1= int* can fail */
230 /* I. Common queries to access_demux and demux */
231 /* POSITION double between 0.0 and 1.0 */
232 DEMUX_GET_POSITION = 0x300, /* arg1= double * res= */
233 DEMUX_SET_POSITION, /* arg1= double arg2= bool b_precise res=can fail */
235 /* LENGTH/TIME in microsecond, 0 if unknown */
236 DEMUX_GET_LENGTH, /* arg1= int64_t * res= */
237 DEMUX_GET_TIME, /* arg1= int64_t * res= */
238 DEMUX_SET_TIME, /* arg1= int64_t arg2= bool b_precise res=can fail */
241 * \todo Document
243 * \warning The prototype is different from STREAM_GET_TITLE_INFO
245 * Can fail, meaning there is only one title and one chapter.
247 * arg1= input_title_t ***, arg2=int *, arg3=int *pi_title_offset(0),
248 * arg4= int *pi_seekpoint_offset(0) */
249 DEMUX_GET_TITLE_INFO,
251 /* DEMUX_SET_GROUP/SET_ES only a hint for demuxer (mainly DVB) to allow not
252 * reading everything (you should not use this to call es_out_Control)
253 * if you don't know what to do with it, just IGNORE it, it is safe(r)
254 * -1 means all group, 0 default group (first es added) */
255 DEMUX_SET_GROUP, /* arg1= int, arg2=const vlc_list_t * can fail */
256 DEMUX_SET_ES, /* arg1= int can fail */
258 /* Ask the demux to demux until the given date at the next pf_demux call
259 * but not more (and not less, at the precision available of course).
260 * XXX: not mandatory (except for subtitle demux) but will help a lot
261 * for multi-input
263 DEMUX_SET_NEXT_DEMUX_TIME, /* arg1= int64_t can fail */
264 /* FPS for correct subtitles handling */
265 DEMUX_GET_FPS, /* arg1= double * res=can fail */
267 /* Meta data */
268 DEMUX_HAS_UNSUPPORTED_META, /* arg1= bool * res can fail */
270 /* Attachments */
271 DEMUX_GET_ATTACHMENTS, /* arg1=input_attachment_t***, int* res=can fail */
273 /* RECORD you are ensured that it is never called twice with the same state
274 * you should accept it only if the stream can be recorded without
275 * any modification or header addition. */
276 DEMUX_CAN_RECORD, /* arg1=bool* res=can fail(assume false) */
278 * \todo Document
280 * \warning The prototype is different from STREAM_SET_RECORD_STATE
282 * The control is never used if DEMUX_CAN_RECORD fails or returns false.
283 * Can fail.
285 * arg1= bool */
286 DEMUX_SET_RECORD_STATE,
288 /* II. Specific access_demux queries */
290 /* DEMUX_CAN_CONTROL_RATE is called only if DEMUX_CAN_CONTROL_PACE has
291 * returned false. *pb_rate should be true when the rate can be changed
292 * (using DEMUX_SET_RATE). */
293 DEMUX_CAN_CONTROL_RATE, /* arg1= bool*pb_rate */
294 /* DEMUX_SET_RATE is called only if DEMUX_CAN_CONTROL_RATE has returned true.
295 * It should return the value really used in *pi_rate */
296 DEMUX_SET_RATE, /* arg1= int*pi_rate can fail */
298 /** Checks whether the stream is actually a playlist, rather than a real
299 * stream.
301 * \warning The prototype is different from STREAM_IS_DIRECTORY.
303 * Can fail if the stream is not a playlist (same as returning false).
305 * arg1= bool * */
306 DEMUX_IS_PLAYLIST,
308 /* Menu (VCD/DVD/BD) Navigation */
309 /** Activate the navigation item selected. Can fail */
310 DEMUX_NAV_ACTIVATE,
311 /** Use the up arrow to select a navigation item above. Can fail */
312 DEMUX_NAV_UP,
313 /** Use the down arrow to select a navigation item under. Can fail */
314 DEMUX_NAV_DOWN,
315 /** Use the left arrow to select a navigation item on the left. Can fail */
316 DEMUX_NAV_LEFT,
317 /** Use the right arrow to select a navigation item on the right. Can fail */
318 DEMUX_NAV_RIGHT,
319 /** Activate the popup Menu (for BD). Can fail */
320 DEMUX_NAV_POPUP,
321 /** Activate disc Root Menu. Can fail */
322 DEMUX_NAV_MENU, /* res=can fail */
323 /** Enable/Disable a demux filter
324 * \warning This has limited support, and is likely to break if more than
325 * a single demux_filter is present in the chain. This is not guaranteed to
326 * work in future VLC versions, nor with all demux filters
328 DEMUX_FILTER_ENABLE,
329 DEMUX_FILTER_DISABLE
332 /*************************************************************************
333 * Main Demux
334 *************************************************************************/
336 /* stream_t *s could be null and then it mean a access+demux in one */
337 VLC_API demux_t *demux_New( vlc_object_t *p_obj, const char *psz_name,
338 const char *psz_path, stream_t *s, es_out_t *out );
340 VLC_API void demux_Delete( demux_t * );
343 VLC_API int demux_vaControlHelper( stream_t *, int64_t i_start, int64_t i_end,
344 int64_t i_bitrate, int i_align, int i_query, va_list args );
346 VLC_USED static inline int demux_Demux( demux_t *p_demux )
348 if( !p_demux->pf_demux )
349 return VLC_DEMUXER_SUCCESS;
351 return p_demux->pf_demux( p_demux );
354 VLC_API int demux_vaControl( demux_t *p_demux, int i_query, va_list args );
356 static inline int demux_Control( demux_t *p_demux, int i_query, ... )
358 va_list args;
359 int i_result;
361 va_start( args, i_query );
362 i_result = demux_vaControl( p_demux, i_query, args );
363 va_end( args );
364 return i_result;
367 /*************************************************************************
368 * Miscellaneous helpers for demuxers
369 *************************************************************************/
371 #ifndef __cplusplus
372 static inline void demux_UpdateTitleFromStream( demux_t *demux,
373 int *restrict titlep, int *restrict seekpointp )
375 stream_t *s = demux->s;
376 unsigned title, seekpoint;
378 if( vlc_stream_Control( s, STREAM_GET_TITLE, &title ) == VLC_SUCCESS
379 && title != (unsigned)*titlep )
381 *titlep = title;
382 demux->info.i_update |= INPUT_UPDATE_TITLE;
385 if( vlc_stream_Control( s, STREAM_GET_SEEKPOINT,
386 &seekpoint ) == VLC_SUCCESS
387 && seekpoint != (unsigned)*seekpointp )
389 *seekpointp = seekpoint;
390 demux->info.i_update |= INPUT_UPDATE_SEEKPOINT;
393 # define demux_UpdateTitleFromStream(demux) \
394 demux_UpdateTitleFromStream(demux, \
395 &((demux_sys_t *)((demux)->p_sys))->current_title, \
396 &((demux_sys_t *)((demux)->p_sys))->current_seekpoint)
397 #endif
399 VLC_USED
400 static inline bool demux_IsPathExtension( demux_t *p_demux, const char *psz_extension )
402 const char *name = (p_demux->psz_filepath != NULL) ? p_demux->psz_filepath
403 : p_demux->psz_location;
404 const char *psz_ext = strrchr ( name, '.' );
405 if( !psz_ext || strcasecmp( psz_ext, psz_extension ) )
406 return false;
407 return true;
410 VLC_USED
411 static inline bool demux_IsContentType(demux_t *demux, const char *type)
413 return stream_IsMimeType(demux->s, type);
416 VLC_USED
417 static inline bool demux_IsForced( demux_t *p_demux, const char *psz_name )
419 if( p_demux->psz_name == NULL || strcmp( p_demux->psz_name, psz_name ) )
420 return false;
421 return true;
425 * This function will create a packetizer suitable for a demuxer that parses
426 * elementary stream.
428 * The provided es_format_t will be cleaned on error or by
429 * demux_PacketizerDestroy.
431 VLC_API decoder_t * demux_PacketizerNew( demux_t *p_demux, es_format_t *p_fmt, const char *psz_msg ) VLC_USED;
434 * This function will destroy a packetizer create by demux_PacketizerNew.
436 VLC_API void demux_PacketizerDestroy( decoder_t *p_packetizer );
438 /* */
439 #define DEMUX_INIT_COMMON() do { \
440 p_demux->pf_control = Control; \
441 p_demux->pf_demux = Demux; \
442 p_demux->p_sys = calloc( 1, sizeof( demux_sys_t ) ); \
443 if( !p_demux->p_sys ) return VLC_ENOMEM;\
444 } while(0)
447 * \defgroup chained_demux Chained demultiplexer
448 * Demultiplexers wrapped by another demultiplexer
449 * @{
452 typedef struct vlc_demux_chained_t vlc_demux_chained_t;
455 * Creates a chained demuxer.
457 * This creates a thread running a demuxer whose input stream is generated
458 * directly by the caller. This typically handles some sort of stream within a
459 * stream, e.g. MPEG-TS within something else.
461 * \note There are a number of limitations to this approach. The chained
462 * demuxer is run asynchronously in a separate thread. Most demuxer controls
463 * are synchronous and therefore unavailable in this case. Also the input
464 * stream is a simple FIFO, so the chained demuxer cannot perform seeks.
465 * Lastly, most errors cannot be detected.
467 * \param parent parent VLC object
468 * \param name chained demux module name (e.g. "ts")
469 * \param out elementary stream output for the chained demux
470 * \return a non-NULL pointer on success, NULL on failure.
472 VLC_API vlc_demux_chained_t *vlc_demux_chained_New(vlc_object_t *parent,
473 const char *name,
474 es_out_t *out);
477 * Destroys a chained demuxer.
479 * Sends an end-of-stream to the chained demuxer, and releases all underlying
480 * allocated resources.
482 VLC_API void vlc_demux_chained_Delete(vlc_demux_chained_t *);
485 * Sends data to a chained demuxer.
487 * This queues data for a chained demuxer to consume.
489 * \param block data block to queue
491 VLC_API void vlc_demux_chained_Send(vlc_demux_chained_t *, block_t *block);
494 * Controls a chained demuxer.
496 * This performs a <b>demux</b> (i.e. DEMUX_...) control request on a chained
497 * demux.
499 * \note In most cases, vlc_demux_chained_Control() should be used instead.
500 * \warning As per vlc_demux_chained_New(), most demux controls are not, and
501 * cannot be, supported; VLC_EGENERIC is returned.
503 * \param query demux control (see \ref demux_query_e)
504 * \param args variable arguments (depending on the query)
506 VLC_API int vlc_demux_chained_ControlVa(vlc_demux_chained_t *, int query,
507 va_list args);
509 static inline int vlc_demux_chained_Control(vlc_demux_chained_t *dc, int query,
510 ...)
512 va_list ap;
513 int ret;
515 va_start(ap, query);
516 ret = vlc_demux_chained_ControlVa(dc, query, ap);
517 va_end(ap);
518 return ret;
522 * @}
526 * @}
529 #endif