1 /*****************************************************************************
2  * input_internal.h: Internal input structures
3  *****************************************************************************
4  * Copyright (C) 1998-2006 VLC authors and VideoLAN
5  * $Id: af9b35967d147c03017ac0eace19695c56aa8e5f $
6  *
7  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
8  *
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.
13  *
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.
18  *
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  *****************************************************************************/
23 
24 #ifndef LIBVLC_INPUT_INTERNAL_H
25 #define LIBVLC_INPUT_INTERNAL_H 1
26 
27 #include <stddef.h>
28 
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"
36 
37 /*****************************************************************************
38  *  Private input fields
39  *****************************************************************************/
40 
41 #define INPUT_CONTROL_FIFO_SIZE    100
42 
43 /* input_source_t: gathers all information per input source */
44 typedef struct
45 {
46     VLC_COMMON_MEMBERS
47 
48     demux_t  *p_demux; /**< Demux object (most downstream) */
49 
50     /* Title infos for that input */
51     bool         b_title_demux; /* Titles/Seekpoints provided by demux */
52     int          i_title;
53     input_title_t **title;
54 
55     int i_title_offset;
56     int i_seekpoint_offset;
57 
58     int i_title_start;
59     int i_title_end;
60     int i_seekpoint_start;
61     int i_seekpoint_end;
62 
63     /* Properties */
64     bool b_can_pause;
65     bool b_can_pace_control;
66     bool b_can_rate_control;
67     bool b_can_stream_record;
68     bool b_rescale_ts;
69     double f_fps;
70 
71     /* */
72     int64_t i_pts_delay;
73 
74     bool       b_eof;   /* eof of demuxer */
75 
76 } input_source_t;
77 
78 typedef struct
79 {
80     int         i_type;
81     vlc_value_t val;
82 } input_control_t;
83 
84 /** Private input fields */
85 typedef struct input_thread_private_t
86 {
87     struct input_thread_t input;
88 
89     /* Global properties */
90     bool        b_preparsing;
91     bool        b_can_pause;
92     bool        b_can_rate_control;
93     bool        b_can_pace_control;
94 
95     /* Current state */
96     int         i_state;
97     bool        is_running;
98     bool        is_stopped;
99     bool        b_recording;
100     int         i_rate;
101 
102     /* Playtime configuration and state */
103     int64_t     i_start;    /* :start-time,0 by default */
104     int64_t     i_stop;     /* :stop-time, 0 if none */
105     int64_t     i_time;     /* Current time */
106     bool        b_fast_seek;/* :input-fast-seek */
107 
108     /* Output */
109     bool            b_out_pace_control; /* XXX Move it ot es_sout ? */
110     sout_instance_t *p_sout;            /* Idem ? */
111     es_out_t        *p_es_out;
112     es_out_t        *p_es_out_display;
113     vlc_viewpoint_t viewpoint;
114     bool            viewpoint_changed;
115     vlc_renderer_item_t *p_renderer;
116 
117     /* Title infos FIXME multi-input (not easy) ? */
118     int          i_title;
119     const input_title_t **title;
120 
121     int i_title_offset;
122     int i_seekpoint_offset;
123 
124     /* User bookmarks FIXME won't be easy with multiples input */
125     seekpoint_t bookmark;
126     int         i_bookmark;
127     seekpoint_t **pp_bookmark;
128 
129     /* Input attachment */
130     int i_attachment;
131     input_attachment_t **attachment;
132     const demux_t **attachment_demux;
133 
134     /* Main input properties */
135 
136     /* Input item */
137     input_item_t   *p_item;
138 
139     /* Main source */
140     input_source_t *master;
141     /* Slave sources (subs, and others) */
142     int            i_slave;
143     input_source_t **slave;
144 
145     /* Resources */
146     input_resource_t *p_resource;
147     input_resource_t *p_resource_private;
148 
149     /* Stats counters */
150     struct {
151         counter_t *p_read_packets;
152         counter_t *p_read_bytes;
153         counter_t *p_input_bitrate;
154         counter_t *p_demux_read;
155         counter_t *p_demux_bitrate;
156         counter_t *p_demux_corrupted;
157         counter_t *p_demux_discontinuity;
158         counter_t *p_decoded_audio;
159         counter_t *p_decoded_video;
160         counter_t *p_decoded_sub;
161         counter_t *p_sout_sent_packets;
162         counter_t *p_sout_sent_bytes;
163         counter_t *p_sout_send_bitrate;
164         counter_t *p_played_abuffers;
165         counter_t *p_lost_abuffers;
166         counter_t *p_displayed_pictures;
167         counter_t *p_lost_pictures;
168         vlc_mutex_t counters_lock;
169     } counters;
170 
171     /* Buffer of pending actions */
172     vlc_mutex_t lock_control;
173     vlc_cond_t  wait_control;
174     int i_control;
175     input_control_t control[INPUT_CONTROL_FIFO_SIZE];
176 
177     vlc_thread_t thread;
178     vlc_interrupt_t interrupt;
179 } input_thread_private_t;
180 
input_priv(input_thread_t * input)181 static inline input_thread_private_t *input_priv(input_thread_t *input)
182 {
183     return container_of(input, input_thread_private_t, input);
184 }
185 
186 /***************************************************************************
187  * Internal control helpers
188  ***************************************************************************/
189 enum input_control_e
190 {
191     INPUT_CONTROL_SET_STATE,
192 
193     INPUT_CONTROL_SET_RATE,
194 
195     INPUT_CONTROL_SET_POSITION,
196 
197     INPUT_CONTROL_SET_TIME,
198 
199     INPUT_CONTROL_SET_PROGRAM,
200 
201     INPUT_CONTROL_SET_TITLE,
202     INPUT_CONTROL_SET_TITLE_NEXT,
203     INPUT_CONTROL_SET_TITLE_PREV,
204 
205     INPUT_CONTROL_SET_SEEKPOINT,
206     INPUT_CONTROL_SET_SEEKPOINT_NEXT,
207     INPUT_CONTROL_SET_SEEKPOINT_PREV,
208 
209     INPUT_CONTROL_SET_BOOKMARK,
210 
211     INPUT_CONTROL_NAV_ACTIVATE, // NOTE: INPUT_CONTROL_NAV_* values must be
212     INPUT_CONTROL_NAV_UP,       // contiguous and in the same order as
213     INPUT_CONTROL_NAV_DOWN,     // INPUT_NAV_* and DEMUX_NAV_*.
214     INPUT_CONTROL_NAV_LEFT,
215     INPUT_CONTROL_NAV_RIGHT,
216     INPUT_CONTROL_NAV_POPUP,
217     INPUT_CONTROL_NAV_MENU,
218 
219     INPUT_CONTROL_SET_ES,
220     INPUT_CONTROL_RESTART_ES,
221 
222     INPUT_CONTROL_SET_VIEWPOINT,    // new absolute viewpoint
223     INPUT_CONTROL_SET_INITIAL_VIEWPOINT, // set initial viewpoint (generally from video)
224     INPUT_CONTROL_UPDATE_VIEWPOINT, // update viewpoint relative to current
225 
226     INPUT_CONTROL_SET_AUDIO_DELAY,
227     INPUT_CONTROL_SET_SPU_DELAY,
228 
229     INPUT_CONTROL_ADD_SLAVE,
230 
231     INPUT_CONTROL_SET_RECORD_STATE,
232 
233     INPUT_CONTROL_SET_FRAME_NEXT,
234 
235     INPUT_CONTROL_SET_RENDERER,
236 };
237 
238 /* Internal helpers */
239 
240 /* XXX for string value you have to allocate it before calling
241  * input_ControlPush
242  */
243 void input_ControlPush( input_thread_t *, int i_type, vlc_value_t * );
244 
245 bool input_Stopped( input_thread_t * );
246 
247 /* Bound pts_delay */
248 #define INPUT_PTS_DELAY_MAX INT64_C(60000000)
249 
250 /**********************************************************************
251  * Item metadata
252  **********************************************************************/
253 /* input_ExtractAttachmentAndCacheArt:
254  *  Be careful: p_item lock will be taken! */
255 void input_ExtractAttachmentAndCacheArt( input_thread_t *, const char *name );
256 
257 /***************************************************************************
258  * Internal prototypes
259  ***************************************************************************/
260 
261 /* var.c */
262 void input_ControlVarInit ( input_thread_t * );
263 void input_ControlVarStop( input_thread_t * );
264 void input_ControlVarNavigation( input_thread_t * );
265 void input_ControlVarTitle( input_thread_t *, int i_title );
266 
267 void input_ConfigVarInit ( input_thread_t * );
268 
269 /* Subtitles */
270 int subtitles_Detect( input_thread_t *, char *, const char *, input_item_slave_t ***, int * );
271 int subtitles_Filter( const char *);
272 
273 /* input.c */
274 void input_SplitMRL( const char **, const char **, const char **,
275                      const char **, char * );
276 
277 /* meta.c */
278 void vlc_audio_replay_gain_MergeFromMeta( audio_replay_gain_t *p_dst,
279                                           const vlc_meta_t *p_meta );
280 
281 /* item.c */
282 void input_item_node_PostAndDelete( input_item_node_t *p_node );
283 
284 #endif
285