input: remove deprecated variables documentation
[vlc.git] / src / input / input_internal.h
blob949cff27c5b5ece269dd2bfe2bc2e02d99ece529
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
26 #include <stddef.h>
27 #include <stdatomic.h>
29 #include <vlc_access.h>
30 #include <vlc_demux.h>
31 #include <vlc_input.h>
32 #include <vlc_viewpoint.h>
33 #include <libvlc.h>
34 #include "input_interface.h"
35 #include "misc/interrupt.h"
37 struct input_stats;
39 /*****************************************************************************
40 * input defines/constants.
41 *****************************************************************************/
43 /**
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;
50 } input_thread_t;
52 /*****************************************************************************
53 * Input events and variables
54 *****************************************************************************/
56 /**
57 * Input state
59 * This enum is used by the variable "state"
61 typedef enum input_state_e
63 INIT_S = 0,
64 OPENING_S,
65 PLAYING_S,
66 PAUSE_S,
67 END_S,
68 ERROR_S,
69 } input_state_e;
71 /**
72 * Input events
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 */
80 INPUT_EVENT_STATE,
81 /* b_dead is true */
82 INPUT_EVENT_DEAD,
84 /* "rate" has changed */
85 INPUT_EVENT_RATE,
87 /* "capabilities" has changed */
88 INPUT_EVENT_CAPABILITIES,
90 /* At least one of "position" or "time" */
91 INPUT_EVENT_POSITION,
93 /* "length" has changed */
94 INPUT_EVENT_LENGTH,
96 /* A title has been added or removed or selected.
97 * It implies that the chapter has changed (no chapter event is sent) */
98 INPUT_EVENT_TITLE,
99 /* A chapter has been added or removed or selected. */
100 INPUT_EVENT_CHAPTER,
102 /* A program ("program") has been added or removed or selected,
103 * or "program-scrambled" has changed.*/
104 INPUT_EVENT_PROGRAM,
105 /* A ES has been added or removed or selected */
106 INPUT_EVENT_ES,
108 /* "record" has changed */
109 INPUT_EVENT_RECORD,
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 */
121 INPUT_EVENT_SIGNAL,
123 /* "bookmark" has changed */
124 INPUT_EVENT_BOOKMARK,
126 /* cache" has changed */
127 INPUT_EVENT_CACHE,
129 /* A vout_thread_t object has been created/deleted by *the input* */
130 INPUT_EVENT_VOUT,
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
155 float percentage;
156 vlc_tick_t ms;
159 struct vlc_input_event_title
161 enum {
162 VLC_INPUT_TITLE_NEW_LIST,
163 VLC_INPUT_TITLE_SELECTED,
164 } action;
165 union
167 struct
169 input_title_t *const *array;
170 size_t count;
171 } list;
172 size_t selected_idx;
176 struct vlc_input_event_chapter
178 int title;
179 int seekpoint;
182 struct vlc_input_event_program {
183 enum {
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,
189 } action;
190 int id;
191 union {
192 const char *title;
193 bool scrambled;
197 struct vlc_input_event_es {
198 enum {
199 VLC_INPUT_ES_ADDED,
200 VLC_INPUT_ES_DELETED,
201 VLC_INPUT_ES_UPDATED,
202 VLC_INPUT_ES_SELECTED,
203 VLC_INPUT_ES_UNSELECTED,
204 } action;
206 * ES track id: only valid from the event callback, unless the id is held
207 * by the user with vlc_es_Hold(). */
208 vlc_es_id_t *id;
210 * Title of ES track, can be updated after the VLC_INPUT_ES_UPDATED event.
212 const char *title;
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 {
220 float quality;
221 float strength;
224 struct vlc_input_event_vout
226 enum {
227 VLC_INPUT_EVENT_VOUT_ADDED,
228 VLC_INPUT_EVENT_VOUT_DELETED,
229 } action;
230 vout_thread_t *vout;
231 enum vlc_vout_order order;
232 vlc_es_id_t *id;
235 struct vlc_input_event
237 input_event_type_e type;
239 union {
240 /* INPUT_EVENT_STATE */
241 input_state_e state;
242 /* INPUT_EVENT_RATE */
243 float 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 */
249 vlc_tick_t 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;
256 /* INPUT_EVENT_ES */
257 struct vlc_input_event_es es;
258 /* INPUT_EVENT_RECORD */
259 bool 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 */
265 float 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 */
271 unsigned vbi_page;
272 /* INPUT_EVENT_VBI_TRANSPARENCY */
273 bool vbi_transparent;
274 /* INPUT_EVENT_SUBS_FPS */
275 float 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,
283 void *userdata);
285 /*****************************************************************************
286 * Prototypes
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)
308 VLC_USED;
310 VLC_API
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)
314 VLC_USED;
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,
334 vlc_tick_t delay);
337 * Set the delay of an ES identifier
339 void input_SetEsIdDelay(input_thread_t *input, vlc_es_id_t *es_id,
340 vlc_tick_t delay);
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 */
357 typedef struct
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 */
363 int i_title;
364 input_title_t **title;
366 int i_title_offset;
367 int i_seekpoint_offset;
369 int i_title_start;
370 int i_title_end;
371 int i_seekpoint_start;
372 int i_seekpoint_end;
374 /* Properties */
375 bool b_can_pause;
376 bool b_can_pace_control;
377 bool b_can_rate_control;
378 bool b_can_stream_record;
379 bool b_rescale_ts;
380 double f_fps;
382 /* sub-fps handling */
383 bool b_slave_sub;
384 float sub_rate;
386 /* */
387 vlc_tick_t i_pts_delay;
389 bool b_eof; /* eof of demuxer */
391 } input_source_t;
393 typedef union
395 vlc_value_t val;
396 vlc_viewpoint_t viewpoint;
397 vlc_es_id_t *id;
398 struct {
399 enum es_format_category_e cat;
400 vlc_es_id_t **ids;
401 } list;
402 struct {
403 bool b_fast_seek;
404 vlc_tick_t i_val;
405 } time;
406 struct {
407 bool b_fast_seek;
408 float f_val;
409 } pos;
410 struct {
411 vlc_es_id_t *id;
412 unsigned page;
413 } vbi_page;
414 struct {
415 vlc_es_id_t *id;
416 bool enabled;
417 } vbi_transparency;
418 } input_control_param_t;
420 typedef struct
422 int i_type;
423 input_control_param_t param;
424 } input_control_t;
426 /** Private input fields */
427 typedef struct input_thread_private_t
429 struct input_thread_t input;
431 input_thread_events_cb events_cb;
432 void *events_data;
434 /* Global properties */
435 bool b_preparsing;
436 bool b_can_pause;
437 bool b_can_rate_control;
438 bool b_can_pace_control;
440 /* Current state */
441 int i_state;
442 bool is_running;
443 bool is_stopped;
444 bool b_recording;
445 bool b_thumbnailing;
446 float rate;
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 */
453 /* Output */
454 bool b_out_pace_control; /* XXX Move it ot es_sout ? */
455 sout_instance_t *p_sout; /* Idem ? */
456 es_out_t *p_es_out;
457 es_out_t *p_es_out_display;
458 vlc_viewpoint_t viewpoint;
459 bool viewpoint_changed;
460 vlc_renderer_item_t *p_renderer;
463 int i_title_offset;
464 int i_seekpoint_offset;
466 /* Input attachment */
467 int i_attachment;
468 input_attachment_t **attachment;
469 const demux_t **attachment_demux;
471 /* Main input properties */
473 /* Input item */
474 input_item_t *p_item;
476 /* Main source */
477 input_source_t *master;
478 /* Slave sources (subs, and others) */
479 int i_slave;
480 input_source_t **slave;
481 float slave_subs_rate;
483 /* Last ES added */
484 enum es_format_category_e i_last_es_cat;
485 int i_last_es_id;
487 /* Resources */
488 input_resource_t *p_resource;
489 input_resource_t *p_resource_private;
491 /* Stats counters */
492 struct input_stats *stats;
494 /* Buffer of pending actions */
495 vlc_mutex_t lock_control;
496 vlc_cond_t wait_control;
497 size_t i_control;
498 input_control_t control[INPUT_CONTROL_FIFO_SIZE];
500 vlc_thread_t thread;
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 ***************************************************************************/
512 enum input_control_e
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 )
578 if( val != NULL )
580 input_control_param_t param = { .val = *val };
581 input_ControlPush( p_input, i_type, &param );
583 else
585 input_ControlPush( p_input, i_type, NULL );
589 static inline void input_ControlPushEsHelper( input_thread_t *p_input, int i_type,
590 vlc_es_id_t *id )
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 ),
596 } );
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 /**********************************************************************
609 * Item metadata
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 ***************************************************************************/
619 /* var.c */
621 void input_ConfigVarInit ( input_thread_t * );
623 /* Subtitles */
624 int subtitles_Detect( input_thread_t *, char *, const char *, input_item_slave_t ***, int * );
625 int subtitles_Filter( const char *);
627 /* meta.c */
628 void vlc_audio_replay_gain_MergeFromMeta( audio_replay_gain_t *p_dst,
629 const vlc_meta_t *p_meta );
631 /* stats.c */
632 typedef struct input_rate_t
634 vlc_mutex_t lock;
635 uintmax_t updates;
636 uintmax_t value;
637 struct
639 uintmax_t value;
640 vlc_tick_t date;
641 } samples[2];
642 } input_rate_t;
644 struct input_stats {
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*);
662 #endif