d3d11va: fill the formatTexture in the context
[vlc.git] / include / vlc_demux.h
blob4905d3e8a8c7fa6de02df2e2548160c080409fca
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 VLC_COMMON_MEMBERS
47 /* Module properties */
48 module_t *p_module;
50 /* eg informative but needed (we can have access+demux) */
51 char *psz_access;
52 char *psz_demux;
53 char *psz_location;
54 char *psz_file;
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 /* Seekpoint/Title at demux level */
91 int i_title; /* idem, start from 0 (could be menu) */
92 int i_seekpoint; /* idem, start from 0 */
93 } info;
94 demux_sys_t *p_sys;
96 /* Weak link to parent input */
97 input_thread_t *p_input;
100 /* pf_demux return values */
101 #define VLC_DEMUXER_EOF 0
102 #define VLC_DEMUXER_EGENERIC -1
103 #define VLC_DEMUXER_SUCCESS 1
105 /* demux_t.info.i_update field */
106 #define INPUT_UPDATE_TITLE 0x0010
107 #define INPUT_UPDATE_SEEKPOINT 0x0020
108 #define INPUT_UPDATE_META 0x0040
109 #define INPUT_UPDATE_TITLE_LIST 0x0100
111 /* demux_meta_t is returned by "meta reader" module to the demuxer */
112 typedef struct demux_meta_t
114 VLC_COMMON_MEMBERS
115 input_item_t *p_item; /***< the input item that is being read */
117 vlc_meta_t *p_meta; /**< meta data */
119 int i_attachments; /**< number of attachments */
120 input_attachment_t **attachments; /**< array of attachments */
121 } demux_meta_t;
124 * Control query identifiers for use with demux_t.pf_control
126 * In the individual identifier description, the input stream refers to
127 * demux_t.s if non-NULL, and the output refers to demux_t.out.
129 * A demuxer is synchronous if it only accesses its input stream and the
130 * output from within its demux_t callbacks, i.e. demux.pf_demux and
131 * demux_t.pf_control.
133 * A demuxer is threaded if it accesses either or both input and output
134 * asynchronously.
136 * An access-demuxer is a demuxer without input, i.e. demux_t.s == NULL).
138 enum demux_query_e
140 /** Checks whether the stream supports seeking.
141 * Can fail if seeking is not supported (same as returning false).
142 * \bug Failing should not be allowed.
144 * arg1 = bool * */
145 DEMUX_CAN_SEEK,
147 /** Checks whether (long) pause then stream resumption is supported.
148 * Can fail only if synchronous and <b>not</b> an access-demuxer. The
149 * underlying input stream then determines if pause is supported.
150 * \bug Failing should not be allowed.
152 * arg1= bool * */
153 DEMUX_CAN_PAUSE = 0x002,
155 /** Whether the stream can be read at an arbitrary pace.
156 * Cannot fail.
158 * arg1= bool * */
159 DEMUX_CAN_CONTROL_PACE,
161 /** Retrieves the PTS delay (roughly the default buffer duration).
162 * Can fail only if synchronous and <b>not</b> an access-demuxer. The
163 * underlying input stream then determines the PTS delay.
165 * arg1= int64_t * */
166 DEMUX_GET_PTS_DELAY = 0x101,
168 /** Retrieves stream meta-data.
169 * Should fail if no meta-data were retrieved.
171 * arg1= vlc_meta_t * */
172 DEMUX_GET_META = 0x105,
174 /** Retrieves an estimate of signal quality and strength.
175 * Can fail.
177 * arg1=double *quality, arg2=double *strength */
178 DEMUX_GET_SIGNAL = 0x107,
180 /** Sets the paused or playing/resumed state.
182 * Streams are initially in playing state. The control always specifies a
183 * change from paused to playing (false) or from playing to paused (true)
184 * and streams are initially playing; a no-op cannot be requested.
186 * The control is never used if DEMUX_CAN_PAUSE fails.
187 * Can fail.
189 * arg1= bool */
190 DEMUX_SET_PAUSE_STATE = 0x200,
192 /** Seeks to the beginning of a title.
194 * The control is never used if DEMUX_GET_TITLE_INFO fails.
195 * Can fail.
197 * arg1= int */
198 DEMUX_SET_TITLE,
200 /** Seeks to the beginning of a chapter of the current title.
202 * The control is never used if DEMUX_GET_TITLE_INFO fails.
203 * Can fail.
205 * arg1= int */
206 DEMUX_SET_SEEKPOINT, /* arg1= int can fail */
208 /** Check which INPUT_UPDATE_XXX flag is set and reset the ones set.
210 * The unsigned* argument is set with the flags needed to be checked,
211 * on return it contains the values that were reset during the call
213 * This can can fail, in which case flags from demux_t.info.i_update
214 * are read/reset
216 * arg1= unsigned * */
217 DEMUX_TEST_AND_CLEAR_FLAGS, /* arg1= unsigned* can fail */
219 /** Read the title number currently playing
221 * Can fail, in which case demux_t.info.i_title is used
223 * arg1= int * */
224 DEMUX_GET_TITLE, /* arg1= int* can fail */
226 /* Read the seekpoint/chapter currently playing
228 * Can fail, in which case demux_t.info.i_seekpoint is used
230 * arg1= int * */
231 DEMUX_GET_SEEKPOINT, /* arg1= int* can fail */
233 /* I. Common queries to access_demux and demux */
234 /* POSITION double between 0.0 and 1.0 */
235 DEMUX_GET_POSITION = 0x300, /* arg1= double * res= */
236 DEMUX_SET_POSITION, /* arg1= double arg2= bool b_precise res=can fail */
238 /* LENGTH/TIME in microsecond, 0 if unknown */
239 DEMUX_GET_LENGTH, /* arg1= int64_t * res= */
240 DEMUX_GET_TIME, /* arg1= int64_t * res= */
241 DEMUX_SET_TIME, /* arg1= int64_t arg2= bool b_precise res=can fail */
244 * \todo Document
246 * \warning The prototype is different from STREAM_GET_TITLE_INFO
248 * Can fail, meaning there is only one title and one chapter.
250 * arg1= input_title_t ***, arg2=int *, arg3=int *pi_title_offset(0),
251 * arg4= int *pi_seekpoint_offset(0) */
252 DEMUX_GET_TITLE_INFO,
254 /* DEMUX_SET_GROUP/SET_ES only a hint for demuxer (mainly DVB) to allow not
255 * reading everything (you should not use this to call es_out_Control)
256 * if you don't know what to do with it, just IGNORE it, it is safe(r)
257 * -1 means all group, 0 default group (first es added) */
258 DEMUX_SET_GROUP, /* arg1= int, arg2=const vlc_list_t * can fail */
259 DEMUX_SET_ES, /* arg1= int can fail */
261 /* Ask the demux to demux until the given date at the next pf_demux call
262 * but not more (and not less, at the precision available of course).
263 * XXX: not mandatory (except for subtitle demux) but will help a lot
264 * for multi-input
266 DEMUX_SET_NEXT_DEMUX_TIME, /* arg1= int64_t can fail */
267 /* FPS for correct subtitles handling */
268 DEMUX_GET_FPS, /* arg1= double * res=can fail */
270 /* Meta data */
271 DEMUX_HAS_UNSUPPORTED_META, /* arg1= bool * res can fail */
273 /* Attachments */
274 DEMUX_GET_ATTACHMENTS, /* arg1=input_attachment_t***, int* res=can fail */
276 /* RECORD you are ensured that it is never called twice with the same state
277 * you should accept it only if the stream can be recorded without
278 * any modification or header addition. */
279 DEMUX_CAN_RECORD, /* arg1=bool* res=can fail(assume false) */
281 * \todo Document
283 * \warning The prototype is different from STREAM_SET_RECORD_STATE
285 * The control is never used if DEMUX_CAN_RECORD fails or returns false.
286 * Can fail.
288 * arg1= bool */
289 DEMUX_SET_RECORD_STATE,
291 /* II. Specific access_demux queries */
293 /* DEMUX_CAN_CONTROL_RATE is called only if DEMUX_CAN_CONTROL_PACE has
294 * returned false. *pb_rate should be true when the rate can be changed
295 * (using DEMUX_SET_RATE). */
296 DEMUX_CAN_CONTROL_RATE, /* arg1= bool*pb_rate */
297 /* DEMUX_SET_RATE is called only if DEMUX_CAN_CONTROL_RATE has returned true.
298 * It should return the value really used in *pi_rate */
299 DEMUX_SET_RATE, /* arg1= int*pi_rate can fail */
301 /** Checks whether the stream is actually a playlist, rather than a real
302 * stream.
304 * \warning The prototype is different from STREAM_IS_DIRECTORY.
306 * Can fail if the stream is not a playlist (same as returning false).
308 * arg1= bool * */
309 DEMUX_IS_PLAYLIST,
311 /* Menu (VCD/DVD/BD) Navigation */
312 /** Activate the navigation item selected. Can fail */
313 DEMUX_NAV_ACTIVATE,
314 /** Use the up arrow to select a navigation item above. Can fail */
315 DEMUX_NAV_UP,
316 /** Use the down arrow to select a navigation item under. Can fail */
317 DEMUX_NAV_DOWN,
318 /** Use the left arrow to select a navigation item on the left. Can fail */
319 DEMUX_NAV_LEFT,
320 /** Use the right arrow to select a navigation item on the right. Can fail */
321 DEMUX_NAV_RIGHT,
322 /** Activate the popup Menu (for BD). Can fail */
323 DEMUX_NAV_POPUP,
324 /** Activate disc Root Menu. Can fail */
325 DEMUX_NAV_MENU, /* res=can fail */
328 /*************************************************************************
329 * Main Demux
330 *************************************************************************/
332 /* stream_t *s could be null and then it mean a access+demux in one */
333 VLC_API demux_t *demux_New( vlc_object_t *p_obj, const char *psz_name,
334 const char *psz_path, stream_t *s, es_out_t *out );
336 VLC_API void demux_Delete( demux_t * );
339 VLC_API int demux_vaControlHelper( stream_t *, int64_t i_start, int64_t i_end,
340 int64_t i_bitrate, int i_align, int i_query, va_list args );
342 VLC_USED static inline int demux_Demux( demux_t *p_demux )
344 if( !p_demux->pf_demux )
345 return VLC_DEMUXER_SUCCESS;
347 return p_demux->pf_demux( p_demux );
350 VLC_API int demux_vaControl( demux_t *p_demux, int i_query, va_list args );
352 static inline int demux_Control( demux_t *p_demux, int i_query, ... )
354 va_list args;
355 int i_result;
357 va_start( args, i_query );
358 i_result = demux_vaControl( p_demux, i_query, args );
359 va_end( args );
360 return i_result;
363 /*************************************************************************
364 * Miscellaneous helpers for demuxers
365 *************************************************************************/
367 static inline void demux_UpdateTitleFromStream( demux_t *demux )
369 stream_t *s = demux->s;
370 unsigned title, seekpoint;
372 if( vlc_stream_Control( s, STREAM_GET_TITLE, &title ) == VLC_SUCCESS
373 && title != (unsigned)demux->info.i_title )
375 demux->info.i_title = title;
376 demux->info.i_update |= INPUT_UPDATE_TITLE;
379 if( vlc_stream_Control( s, STREAM_GET_SEEKPOINT,
380 &seekpoint ) == VLC_SUCCESS
381 && seekpoint != (unsigned)demux->info.i_seekpoint )
383 demux->info.i_seekpoint = seekpoint;
384 demux->info.i_update |= INPUT_UPDATE_SEEKPOINT;
388 VLC_USED
389 static inline bool demux_IsPathExtension( demux_t *p_demux, const char *psz_extension )
391 const char *name = (p_demux->psz_file != NULL) ? p_demux->psz_file
392 : p_demux->psz_location;
393 const char *psz_ext = strrchr ( name, '.' );
394 if( !psz_ext || strcasecmp( psz_ext, psz_extension ) )
395 return false;
396 return true;
399 VLC_USED
400 static inline bool demux_IsContentType(demux_t *demux, const char *type)
402 return stream_IsMimeType(demux->s, type);
405 VLC_USED
406 static inline bool demux_IsForced( demux_t *p_demux, const char *psz_name )
408 if( !p_demux->psz_demux || strcmp( p_demux->psz_demux, psz_name ) )
409 return false;
410 return true;
414 * This function will create a packetizer suitable for a demuxer that parses
415 * elementary stream.
417 * The provided es_format_t will be cleaned on error or by
418 * demux_PacketizerDestroy.
420 VLC_API decoder_t * demux_PacketizerNew( demux_t *p_demux, es_format_t *p_fmt, const char *psz_msg ) VLC_USED;
423 * This function will destroy a packetizer create by demux_PacketizerNew.
425 VLC_API void demux_PacketizerDestroy( decoder_t *p_packetizer );
427 /* */
428 #define DEMUX_INIT_COMMON() do { \
429 p_demux->pf_control = Control; \
430 p_demux->pf_demux = Demux; \
431 p_demux->p_sys = calloc( 1, sizeof( demux_sys_t ) ); \
432 if( !p_demux->p_sys ) return VLC_ENOMEM;\
433 } while(0)
436 * \defgroup chained_demux Chained demultiplexer
437 * Demultiplexers wrapped by another demultiplexer
438 * @{
441 typedef struct vlc_demux_chained_t vlc_demux_chained_t;
444 * Creates a chained demuxer.
446 * This creates a thread running a demuxer whose input stream is generated
447 * directly by the caller. This typically handles some sort of stream within a
448 * stream, e.g. MPEG-TS within something else.
450 * \note There are a number of limitations to this approach. The chained
451 * demuxer is run asynchronously in a separate thread. Most demuxer controls
452 * are synchronous and therefore unavailable in this case. Also the input
453 * stream is a simple FIFO, so the chained demuxer cannot perform seeks.
454 * Lastly, most errors cannot be detected.
456 * \param parent parent VLC object
457 * \param name chained demux module name (e.g. "ts")
458 * \param out elementary stream output for the chained demux
459 * \return a non-NULL pointer on success, NULL on failure.
461 VLC_API vlc_demux_chained_t *vlc_demux_chained_New(vlc_object_t *parent,
462 const char *name,
463 es_out_t *out);
466 * Destroys a chained demuxer.
468 * Sends an end-of-stream to the chained demuxer, and releases all underlying
469 * allocated resources.
471 VLC_API void vlc_demux_chained_Delete(vlc_demux_chained_t *);
474 * Sends data to a chained demuxer.
476 * This queues data for a chained demuxer to consume.
478 * \param block data block to queue
480 VLC_API void vlc_demux_chained_Send(vlc_demux_chained_t *, block_t *block);
483 * Controls a chained demuxer.
485 * This performs a <b>demux</b> (i.e. DEMUX_...) control request on a chained
486 * demux.
488 * \note In most cases, vlc_demux_chained_Control() should be used instead.
489 * \warning As per vlc_demux_chained_New(), most demux controls are not, and
490 * cannot be, supported; VLC_EGENERIC is returned.
492 * \param query demux control (see \ref demux_query_e)
493 * \param args variable arguments (depending on the query)
495 VLC_API int vlc_demux_chained_ControlVa(vlc_demux_chained_t *, int query,
496 va_list args);
498 static inline int vlc_demux_chained_Control(vlc_demux_chained_t *dc, int query,
499 ...)
501 va_list ap;
502 int ret;
504 va_start(ap, query);
505 ret = vlc_demux_chained_ControlVa(dc, query, ap);
506 va_end(ap);
507 return ret;
511 * @}
515 * @}
518 #endif