1 /*****************************************************************************
2 * vlc_demux.h: Demuxer descriptor, queries and methods
3 *****************************************************************************
4 * Copyright (C) 1999-2005 VLC authors and VideoLAN
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 *****************************************************************************/
31 #include <vlc_stream.h>
32 #include <vlc_es_out.h>
35 * \defgroup demux Demultiplexer
37 * Demultiplexers (file format parsers)
40 * Demultiplexer modules interface
47 /* Module properties */
50 /* eg informative but needed (we can have access+demux) */
60 * Depending on the module capability:
61 * - "demux": input byte stream (not NULL)
62 * - "access_demux": a NULL pointer
63 * - "demux_filter": undefined
69 * If the module capability is "demux_filter", this is the upstream
70 * demuxer or demux filter. Otherwise, this is undefined.
76 es_out_t
*out
; /* our p_es_out */
78 bool b_preparsing
; /* True if the demux is used to preparse */
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 */
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 */
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
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 */
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
136 * An access-demuxer is a demuxer without input, i.e. demux_t.s == NULL).
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.
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.
153 DEMUX_CAN_PAUSE
= 0x002,
155 /** Whether the stream can be read at an arbitrary pace.
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.
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.
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.
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.
200 /** Seeks to the beginning of a chapter of the current title.
202 * The control is never used if DEMUX_GET_TITLE_INFO fails.
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
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
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
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 */
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
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 */
271 DEMUX_HAS_UNSUPPORTED_META
, /* arg1= bool * res can fail */
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) */
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.
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
304 * \warning The prototype is different from STREAM_IS_DIRECTORY.
306 * Can fail if the stream is not a playlist (same as returning false).
311 /* Menu (VCD/DVD/BD) Navigation */
312 /** Activate the navigation item selected. Can fail */
314 /** Use the up arrow to select a navigation item above. Can fail */
316 /** Use the down arrow to select a navigation item under. Can fail */
318 /** Use the left arrow to select a navigation item on the left. Can fail */
320 /** Use the right arrow to select a navigation item on the right. Can fail */
322 /** Activate the popup Menu (for BD). Can fail */
324 /** Activate disc Root Menu. Can fail */
325 DEMUX_NAV_MENU
, /* res=can fail */
328 /*************************************************************************
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
, ... )
357 va_start( args
, i_query
);
358 i_result
= demux_vaControl( p_demux
, i_query
, args
);
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
;
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
) )
400 static inline bool demux_IsContentType(demux_t
*demux
, const char *type
)
402 return stream_IsMimeType(demux
->s
, type
);
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
) )
414 * This function will create a packetizer suitable for a demuxer that parses
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
);
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;\
436 * \defgroup chained_demux Chained demultiplexer
437 * Demultiplexers wrapped by another demultiplexer
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
,
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
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
,
498 static inline int vlc_demux_chained_Control(vlc_demux_chained_t
*dc
, int query
,
505 ret
= vlc_demux_chained_ControlVa(dc
, query
, ap
);