1 /*****************************************************************************
2 * input_internal.h: Internal input structures
3 *****************************************************************************
4 * Copyright (C) 1998-2006 VLC authors and VideoLAN
6 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU Lesser General Public License as published by
10 * the Free Software Foundation; either version 2.1 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with this program; if not, write to the Free Software Foundation,
20 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
21 *****************************************************************************/
23 #ifndef LIBVLC_INPUT_INTERNAL_H
24 #define LIBVLC_INPUT_INTERNAL_H 1
27 #include <stdatomic.h>
29 #include <vlc_access.h>
30 #include <vlc_demux.h>
31 #include <vlc_input.h>
32 #include <vlc_viewpoint.h>
34 #include "input_interface.h"
35 #include "misc/interrupt.h"
39 /*****************************************************************************
40 * input defines/constants.
41 *****************************************************************************/
44 * Main structure representing an input thread. This structure is mostly
45 * private. The only public fields are read-only and constant.
47 typedef struct input_thread_t
49 struct vlc_object_t obj
;
52 /*****************************************************************************
53 * Input events and variables
54 *****************************************************************************/
59 * This enum is used by the variable "state"
61 typedef enum input_state_e
74 * You can catch input event by adding a callback on the variable "intf-event".
75 * This variable is an integer that will hold a input_event_type_e value.
77 typedef enum input_event_type_e
79 /* "state" has changed */
84 /* "rate" has changed */
87 /* "capabilities" has changed */
88 INPUT_EVENT_CAPABILITIES
,
90 /* At least one of "position" or "time" */
93 /* "length" has changed */
96 /* A title has been added or removed or selected.
97 * It implies that the chapter has changed (no chapter event is sent) */
99 /* A chapter has been added or removed or selected. */
102 /* A program ("program") has been added or removed or selected,
103 * or "program-scrambled" has changed.*/
105 /* A ES has been added or removed or selected */
108 /* "record" has changed */
111 /* input_item_t media has changed */
112 INPUT_EVENT_ITEM_META
,
113 /* input_item_t info has changed */
114 INPUT_EVENT_ITEM_INFO
,
115 /* input_item_t epg has changed */
116 INPUT_EVENT_ITEM_EPG
,
118 /* Input statistics have been updated */
119 INPUT_EVENT_STATISTICS
,
120 /* At least one of "signal-quality" or "signal-strength" has changed */
123 /* "bookmark" has changed */
124 INPUT_EVENT_BOOKMARK
,
126 /* cache" has changed */
129 /* A vout_thread_t object has been created/deleted by *the input* */
132 /* (pre-)parsing events */
133 INPUT_EVENT_SUBITEMS
,
135 /* vbi_page has changed */
136 INPUT_EVENT_VBI_PAGE
,
137 /* vbi_transparent has changed */
138 INPUT_EVENT_VBI_TRANSPARENCY
,
140 /* subs_fps has changed */
141 INPUT_EVENT_SUBS_FPS
,
143 /* Thumbnail generation */
144 INPUT_EVENT_THUMBNAIL_READY
,
145 } input_event_type_e
;
147 #define VLC_INPUT_CAPABILITIES_SEEKABLE (1<<0)
148 #define VLC_INPUT_CAPABILITIES_PAUSEABLE (1<<1)
149 #define VLC_INPUT_CAPABILITIES_CHANGE_RATE (1<<2)
150 #define VLC_INPUT_CAPABILITIES_REWINDABLE (1<<3)
151 #define VLC_INPUT_CAPABILITIES_RECORDABLE (1<<4)
153 struct vlc_input_event_position
159 struct vlc_input_event_title
162 VLC_INPUT_TITLE_NEW_LIST
,
163 VLC_INPUT_TITLE_SELECTED
,
169 input_title_t
*const *array
;
176 struct vlc_input_event_chapter
182 struct vlc_input_event_program
{
184 VLC_INPUT_PROGRAM_ADDED
,
185 VLC_INPUT_PROGRAM_DELETED
,
186 VLC_INPUT_PROGRAM_UPDATED
,
187 VLC_INPUT_PROGRAM_SELECTED
,
188 VLC_INPUT_PROGRAM_SCRAMBLED
,
197 struct vlc_input_event_es
{
200 VLC_INPUT_ES_DELETED
,
201 VLC_INPUT_ES_UPDATED
,
202 VLC_INPUT_ES_SELECTED
,
203 VLC_INPUT_ES_UNSELECTED
,
206 * ES track id: only valid from the event callback, unless the id is held
207 * by the user with vlc_es_Hold(). */
210 * Title of ES track, can be updated after the VLC_INPUT_ES_UPDATED event.
214 * ES track information, can be updated after the VLC_INPUT_ES_UPDATED event.
216 const es_format_t
*fmt
;
219 struct vlc_input_event_signal
{
224 struct vlc_input_event_vout
227 VLC_INPUT_EVENT_VOUT_ADDED
,
228 VLC_INPUT_EVENT_VOUT_DELETED
,
231 enum vlc_vout_order order
;
235 struct vlc_input_event
237 input_event_type_e type
;
240 /* INPUT_EVENT_STATE */
242 /* INPUT_EVENT_RATE */
244 /* INPUT_EVENT_CAPABILITIES */
245 int capabilities
; /**< cf. VLC_INPUT_CAPABILITIES_* bitwise flags */
246 /* INPUT_EVENT_POSITION */
247 struct vlc_input_event_position position
;
248 /* INPUT_EVENT_LENGTH */
250 /* INPUT_EVENT_TITLE */
251 struct vlc_input_event_title title
;
252 /* INPUT_EVENT_CHAPTER */
253 struct vlc_input_event_chapter chapter
;
254 /* INPUT_EVENT_PROGRAM */
255 struct vlc_input_event_program program
;
257 struct vlc_input_event_es es
;
258 /* INPUT_EVENT_RECORD */
260 /* INPUT_EVENT_STATISTICS */
261 const struct input_stats_t
*stats
;
262 /* INPUT_EVENT_SIGNAL */
263 struct vlc_input_event_signal signal
;
264 /* INPUT_EVENT_CACHE */
266 /* INPUT_EVENT_VOUT */
267 struct vlc_input_event_vout vout
;
268 /* INPUT_EVENT_SUBITEMS */
269 input_item_node_t
*subitems
;
270 /* INPUT_EVENT_VBI_PAGE */
272 /* INPUT_EVENT_VBI_TRANSPARENCY */
273 bool vbi_transparent
;
274 /* INPUT_EVENT_SUBS_FPS */
276 /* INPUT_EVENT_THUMBNAIL_READY */
277 picture_t
*thumbnail
;
281 typedef void (*input_thread_events_cb
)( input_thread_t
*input
,
282 const struct vlc_input_event
*event
,
285 /*****************************************************************************
287 *****************************************************************************/
288 input_thread_t
* input_Create( vlc_object_t
*p_parent
,
289 input_thread_events_cb event_cb
, void *events_data
,
290 input_item_t
*, input_resource_t
*,
291 vlc_renderer_item_t
* p_renderer
) VLC_USED
;
292 #define input_Create(a,b,c,d,e,f) input_Create(VLC_OBJECT(a),b,c,d,e,f)
296 * Creates an item preparser.
298 * Creates an input thread to preparse an item. The input needs to be started
299 * with input_Start() afterwards.
301 * @param obj parent object
302 * @param item input item to preparse
303 * @return an input thread or NULL on error
305 input_thread_t
*input_CreatePreparser(vlc_object_t
*obj
,
306 input_thread_events_cb events_cb
,
307 void *events_data
, input_item_t
*item
)
311 input_thread_t
*input_CreateThumbnailer(vlc_object_t
*obj
,
312 input_thread_events_cb events_cb
,
313 void *events_data
, input_item_t
*item
)
316 int input_Start( input_thread_t
* );
318 void input_Stop( input_thread_t
* );
320 void input_Close( input_thread_t
* );
322 void input_SetTime( input_thread_t
*, vlc_tick_t i_time
, bool b_fast
);
324 void input_SetPosition( input_thread_t
*, float f_position
, bool b_fast
);
327 * Set the delay of an ES category
329 * If called before input_Start(), the delay will be applied for next ES
330 * tracks. If called after input_Start(), the delay will be applied for all
331 * tracks of the category (and all future tracks).
333 void input_SetCategoryDelay(input_thread_t
*input
, enum es_format_category_e cat
,
337 * Set the delay of an ES identifier
339 void input_SetEsIdDelay(input_thread_t
*input
, vlc_es_id_t
*es_id
,
343 * Get the input item for an input thread
345 * You have to keep a reference to the input or to the input_item_t until
346 * you do not need it anymore.
348 input_item_t
* input_GetItem( input_thread_t
* ) VLC_USED
;
350 /*****************************************************************************
351 * Private input fields
352 *****************************************************************************/
354 #define INPUT_CONTROL_FIFO_SIZE 100
356 /* input_source_t: gathers all information per input source */
359 demux_t
*p_demux
; /**< Demux object (most downstream) */
361 /* Title infos for that input */
362 bool b_title_demux
; /* Titles/Seekpoints provided by demux */
364 input_title_t
**title
;
367 int i_seekpoint_offset
;
371 int i_seekpoint_start
;
376 bool b_can_pace_control
;
377 bool b_can_rate_control
;
378 bool b_can_stream_record
;
382 /* sub-fps handling */
387 vlc_tick_t i_pts_delay
;
389 bool b_eof
; /* eof of demuxer */
396 vlc_viewpoint_t viewpoint
;
399 enum es_format_category_e cat
;
418 } input_control_param_t
;
423 input_control_param_t param
;
426 /** Private input fields */
427 typedef struct input_thread_private_t
429 struct input_thread_t input
;
431 input_thread_events_cb events_cb
;
434 /* Global properties */
437 bool b_can_rate_control
;
438 bool b_can_pace_control
;
448 /* Playtime configuration and state */
449 vlc_tick_t i_start
; /* :start-time,0 by default */
450 vlc_tick_t i_stop
; /* :stop-time, 0 if none */
451 vlc_tick_t i_time
; /* Current time */
454 bool b_out_pace_control
; /* XXX Move it ot es_sout ? */
455 sout_instance_t
*p_sout
; /* Idem ? */
457 es_out_t
*p_es_out_display
;
458 vlc_viewpoint_t viewpoint
;
459 bool viewpoint_changed
;
460 vlc_renderer_item_t
*p_renderer
;
464 int i_seekpoint_offset
;
466 /* Input attachment */
468 input_attachment_t
**attachment
;
469 const demux_t
**attachment_demux
;
471 /* Main input properties */
474 input_item_t
*p_item
;
477 input_source_t
*master
;
478 /* Slave sources (subs, and others) */
480 input_source_t
**slave
;
481 float slave_subs_rate
;
484 enum es_format_category_e i_last_es_cat
;
488 input_resource_t
*p_resource
;
489 input_resource_t
*p_resource_private
;
492 struct input_stats
*stats
;
494 /* Buffer of pending actions */
495 vlc_mutex_t lock_control
;
496 vlc_cond_t wait_control
;
498 input_control_t control
[INPUT_CONTROL_FIFO_SIZE
];
501 vlc_interrupt_t interrupt
;
502 } input_thread_private_t
;
504 static inline input_thread_private_t
*input_priv(input_thread_t
*input
)
506 return container_of(input
, input_thread_private_t
, input
);
509 /***************************************************************************
510 * Internal control helpers
511 ***************************************************************************/
514 INPUT_CONTROL_SET_STATE
,
516 INPUT_CONTROL_SET_RATE
,
518 INPUT_CONTROL_SET_POSITION
,
519 INPUT_CONTROL_JUMP_POSITION
,
521 INPUT_CONTROL_SET_TIME
,
522 INPUT_CONTROL_JUMP_TIME
,
524 INPUT_CONTROL_SET_PROGRAM
,
526 INPUT_CONTROL_SET_TITLE
,
527 INPUT_CONTROL_SET_TITLE_NEXT
,
528 INPUT_CONTROL_SET_TITLE_PREV
,
530 INPUT_CONTROL_SET_SEEKPOINT
,
531 INPUT_CONTROL_SET_SEEKPOINT_NEXT
,
532 INPUT_CONTROL_SET_SEEKPOINT_PREV
,
534 INPUT_CONTROL_SET_BOOKMARK
,
536 INPUT_CONTROL_NAV_ACTIVATE
, // NOTE: INPUT_CONTROL_NAV_* values must be
537 INPUT_CONTROL_NAV_UP
, // contiguous and in the same order as
538 INPUT_CONTROL_NAV_DOWN
, // INPUT_NAV_* and DEMUX_NAV_*.
539 INPUT_CONTROL_NAV_LEFT
,
540 INPUT_CONTROL_NAV_RIGHT
,
541 INPUT_CONTROL_NAV_POPUP
,
542 INPUT_CONTROL_NAV_MENU
,
544 INPUT_CONTROL_SET_ES_BY_ID
,
545 INPUT_CONTROL_RESTART_ES_BY_ID
,
547 INPUT_CONTROL_SET_ES
,
548 INPUT_CONTROL_SET_ES_LIST
, // select a list of ES atomically
549 INPUT_CONTROL_UNSET_ES
,
550 INPUT_CONTROL_RESTART_ES
,
552 INPUT_CONTROL_SET_VIEWPOINT
, // new absolute viewpoint
553 INPUT_CONTROL_SET_INITIAL_VIEWPOINT
, // set initial viewpoint (generally from video)
554 INPUT_CONTROL_UPDATE_VIEWPOINT
, // update viewpoint relative to current
556 INPUT_CONTROL_ADD_SLAVE
,
557 INPUT_CONTROL_SET_SUBS_FPS
,
559 INPUT_CONTROL_SET_RECORD_STATE
,
561 INPUT_CONTROL_SET_FRAME_NEXT
,
563 INPUT_CONTROL_SET_RENDERER
,
565 INPUT_CONTROL_SET_VBI_PAGE
,
566 INPUT_CONTROL_SET_VBI_TRANSPARENCY
,
569 /* Internal helpers */
571 void input_ControlPush( input_thread_t
*, int, const input_control_param_t
* );
573 /* XXX for string value you have to allocate it before calling
574 * input_ControlPushHelper
576 static inline void input_ControlPushHelper( input_thread_t
*p_input
, int i_type
, vlc_value_t
*val
)
580 input_control_param_t param
= { .val
= *val
};
581 input_ControlPush( p_input
, i_type
, ¶m
);
585 input_ControlPush( p_input
, i_type
, NULL
);
589 static inline void input_ControlPushEsHelper( input_thread_t
*p_input
, int i_type
,
592 assert( i_type
== INPUT_CONTROL_SET_ES
|| i_type
== INPUT_CONTROL_UNSET_ES
||
593 i_type
== INPUT_CONTROL_RESTART_ES
);
594 input_ControlPush( p_input
, i_type
, &(input_control_param_t
) {
595 .id
= vlc_es_id_Hold( id
),
599 bool input_Stopped( input_thread_t
* );
601 int input_GetAttachments(input_thread_t
*input
, input_attachment_t
***attachments
);
603 input_attachment_t
*input_GetAttachment(input_thread_t
*input
, const char *name
);
605 /* Bound pts_delay */
606 #define INPUT_PTS_DELAY_MAX VLC_TICK_FROM_SEC(60)
608 /**********************************************************************
610 **********************************************************************/
611 /* input_ExtractAttachmentAndCacheArt:
612 * Be careful: p_item lock will be taken! */
613 void input_ExtractAttachmentAndCacheArt( input_thread_t
*, const char *name
);
615 /***************************************************************************
616 * Internal prototypes
617 ***************************************************************************/
621 void input_ConfigVarInit ( input_thread_t
* );
624 int subtitles_Detect( input_thread_t
*, char *, const char *, input_item_slave_t
***, int * );
625 int subtitles_Filter( const char *);
628 void vlc_audio_replay_gain_MergeFromMeta( audio_replay_gain_t
*p_dst
,
629 const vlc_meta_t
*p_meta
);
632 typedef struct input_rate_t
645 input_rate_t input_bitrate
;
646 input_rate_t demux_bitrate
;
647 atomic_uintmax_t demux_corrupted
;
648 atomic_uintmax_t demux_discontinuity
;
649 atomic_uintmax_t decoded_audio
;
650 atomic_uintmax_t decoded_video
;
651 atomic_uintmax_t played_abuffers
;
652 atomic_uintmax_t lost_abuffers
;
653 atomic_uintmax_t displayed_pictures
;
654 atomic_uintmax_t lost_pictures
;
657 struct input_stats
*input_stats_Create(void);
658 void input_stats_Destroy(struct input_stats
*);
659 void input_rate_Add(input_rate_t
*, uintmax_t);
660 void input_stats_Compute(struct input_stats
*, input_stats_t
*);