1 /*
2  * Copyright (C) 2000-2019 the xine project
3  *
4  * This file is part of xine, a free video player.
5  *
6  * xine is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * xine is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
19  */
20 
21 #ifndef HAVE_XINE_INTERNAL_H
22 #define HAVE_XINE_INTERNAL_H
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
28 /*
29  * include public part of xine header
30  */
31 
32 #include <xine.h>
33 #include <xine/tickets.h>
34 #include <xine/refcounter.h>
35 #include <xine/input_plugin.h>
36 #include <xine/demux.h>
37 #include <xine/video_out.h>
38 #include <xine/audio_out.h>
39 #include <xine/metronom.h>
40 #include <xine/osd.h>
41 #include <xine/xineintl.h>
42 #include <xine/plugin_catalog.h>
43 #include <xine/video_decoder.h>
44 #include <xine/audio_decoder.h>
45 #include <xine/spu_decoder.h>
46 #include <xine/scratch.h>
47 #include <xine/broadcaster.h>
48 #include <xine/io_helper.h>
49 #include <xine/info_helper.h>
50 #include <xine/alphablend.h>
51 
52 #define XINE_MAX_EVENT_LISTENERS         50
53 #define XINE_MAX_EVENT_TYPES             100
54 #define XINE_MAX_TICKET_HOLDER_THREADS   64
55 
56 /* used by plugin loader */
57 #define XINE_VERSION_CODE                XINE_MAJOR_VERSION*10000+XINE_MINOR_VERSION*100+XINE_SUB_VERSION
58 
59 
60 /*
61  * log constants
62  */
63 
64 #define XINE_LOG_MSG       0 /* warnings, errors, ... */
65 #define XINE_LOG_PLUGIN    1
66 #define XINE_LOG_TRACE     2
67 #define XINE_LOG_NUM       3 /* # of log buffers defined */
68 
69 #define XINE_STREAM_INFO_MAX 99
70 
71 /*
72  * the "big" xine struct, holding everything together
73  */
74 
75 #ifndef XDG_BASEDIR_H
76 /* present here for internal convenience only */
77 typedef struct { void *reserved; } xdgHandle;
78 #endif
79 
80 struct xine_s {
81 
82   config_values_t           *config;
83 
84   plugin_catalog_t          *plugin_catalog;
85 
86   int                        verbosity;
87 
88   int                        demux_strategy;
89   const char                *save_path;
90 
91   /* log output that may be presented to the user */
92   scratch_buffer_t          *log_buffers[XINE_LOG_NUM];
93 
94   xine_list_t               *streams;
95   pthread_mutex_t            streams_lock;
96 
97   metronom_clock_t          *clock;
98 
99   /** Handle for libxdg-basedir functions. */
100   xdgHandle                  basedir_handle;
101 };
102 
103 /*
104  * xine event queue
105  */
106 
107 struct xine_event_queue_s {
108   xine_list_t               *events;
109   pthread_mutex_t            lock;
110   pthread_cond_t             new_event;
111   pthread_cond_t             events_processed;
112   xine_stream_t             *stream;
113   pthread_t                 *listener_thread;
114   void                      *user_data;
115   xine_event_listener_cb_t   callback;
116   int                        callback_running;
117 };
118 
119 /*
120  * xine_stream - per-stream parts of the xine engine
121  */
122 
123 struct xine_stream_s {
124 
125   /* reference to xine context */
126   xine_t                    *xine;
127 
128   /* metronom instance used by current stream */
129   metronom_t                *metronom;
130 
131   /* demuxers use input_plugin to read data */
132   input_plugin_t            *input_plugin;
133 
134   /* used by video decoders, may change by port rewire */
135   xine_video_port_t         * volatile video_out;
136 
137   /* demuxers send data to video decoders using this fifo */
138   fifo_buffer_t             *video_fifo;
139 
140   /* used by audio decoders, may change by port rewire */
141   xine_audio_port_t         * volatile audio_out;
142 
143   /* demuxers send data to audio decoders using this fifo */
144   fifo_buffer_t             *audio_fifo;
145 
146   /* provide access to osd api */
147   osd_renderer_t            *osd_renderer;
148 
149   /* master/slave streams */
150   xine_stream_t             *master; /* usually a pointer to itself */
151   xine_stream_t             *slave;
152 
153   /* input_dvd uses this one. is it possible to add helper functions instead? */
154   spu_decoder_t             *spu_decoder_plugin;
155 
156   /* dxr3 use this one, should be possible to fix to use the port instead */
157   vo_driver_t               *video_driver;
158 
159   /* these definitely should be made private! */
160   int                        audio_channel_auto;
161   int                        spu_decoder_streamtype;
162   int                        spu_channel_user;
163   int                        spu_channel_auto;
164   int                        spu_channel_letterbox;
165   int                        spu_channel;
166 
167   /* current content detection method, see METHOD_BY_xxx */
168   int                        content_detection_method;
169 };
170 
171 /* when explicitly noted, some functions accept an anonymous stream,
172  * which is a valid stream that does not want to be addressed. */
173 #define XINE_ANON_STREAM ((xine_stream_t *)-1)
174 
175 typedef struct
176 {
177   int total;
178   int ready;
179   int avail;
180 }
181 xine_query_buffers_data_t;
182 
183 typedef struct
184 {
185   xine_query_buffers_data_t vi;
186   xine_query_buffers_data_t ai;
187   xine_query_buffers_data_t vo;
188   xine_query_buffers_data_t ao;
189 }
190 xine_query_buffers_t;
191 
192 /*
193  * private function prototypes:
194  */
195 
196 int _x_query_network_timeout (xine_t *xine) XINE_PROTECTED;
197 int _x_query_buffers(xine_stream_t *stream, xine_query_buffers_t *query) XINE_PROTECTED;
198 int _x_query_buffer_usage(xine_stream_t *stream, int *num_video_buffers, int *num_audio_buffers, int *num_video_frames, int *num_audio_frames) XINE_PROTECTED;
199 int _x_lock_port_rewiring(xine_t *xine, int ms_to_time_out) XINE_PROTECTED;
200 void _x_unlock_port_rewiring(xine_t *xine) XINE_PROTECTED;
201 int _x_lock_frontend(xine_stream_t *stream, int ms_to_time_out) XINE_PROTECTED;
202 void _x_unlock_frontend(xine_stream_t *stream) XINE_PROTECTED;
203 int _x_query_unprocessed_osd_events(xine_stream_t *stream) XINE_PROTECTED;
204 int _x_demux_seek(xine_stream_t *stream, off_t start_pos, int start_time, int playing) XINE_PROTECTED;
205 int _x_continue_stream_processing(xine_stream_t *stream) XINE_PROTECTED;
206 void _x_trigger_relaxed_frame_drop_mode(xine_stream_t *stream) XINE_PROTECTED;
207 void _x_reset_relaxed_frame_drop_mode(xine_stream_t *stream) XINE_PROTECTED;
208 
209 void _x_handle_stream_end      (xine_stream_t *stream, int non_user) XINE_PROTECTED;
210 
211 /* report message to UI. usually these are async errors */
212 
213 int _x_message(xine_stream_t *stream, int type, ...) XINE_SENTINEL XINE_PROTECTED;
214 
215 /* flush the message queues */
216 
217 void _x_flush_events_queues (xine_stream_t *stream) XINE_PROTECTED;
218 
219 /* extra_info operations */
220 void _x_extra_info_reset( extra_info_t *extra_info ) XINE_PROTECTED;
221 
222 void _x_extra_info_merge( extra_info_t *dst, extra_info_t *src ) XINE_PROTECTED;
223 
224 void _x_get_current_info (xine_stream_t *stream, extra_info_t *extra_info, int size) XINE_PROTECTED;
225 
226 
227 /** @brief Register a list of stream keyframes.
228     @param stream The stream that index is for.
229     @param list   The array of entries to add.
230     @param size   The count of entries.
231     @return 0 (OK), 1 (Fail).
232 */
233 int _x_keyframes_set (xine_stream_t *stream, xine_keyframes_entry_t *list, int size) XINE_PROTECTED;
234 
235 /** @brief Register a stream keyframe to seek index.
236     @note  This will try not to duplicate already registered frames.
237     @param stream The stream that index is for.
238     @param pos    The frame time AND normpos.
239     @return  The index *g* into the index where that frame has been added, or -1.
240 */
241 int _x_keyframes_add (xine_stream_t *stream, xine_keyframes_entry_t *pos) XINE_PROTECTED;
242 
243 
244 /* demuxer helper functions from demux.c */
245 
246 /*
247  *  Flush audio and video buffers. It is called from demuxers on
248  *  seek/stop, and may be useful when user input changes a stream and
249  *  xine-lib has cached buffers that have yet to be played.
250  *
251  * warning: after clearing decoders fifos an absolute discontinuity
252  *          indication must be sent. relative discontinuities are likely
253  *          to cause "jumps" on metronom.
254  */
255 void _x_demux_flush_engine         (xine_stream_t *stream) XINE_PROTECTED;
256 
257 void _x_demux_control_nop          (xine_stream_t *stream, uint32_t flags) XINE_PROTECTED;
258 void _x_demux_control_newpts       (xine_stream_t *stream, int64_t pts, uint32_t flags) XINE_PROTECTED;
259 void _x_demux_control_headers_done (xine_stream_t *stream) XINE_PROTECTED;
260 void _x_demux_control_start        (xine_stream_t *stream) XINE_PROTECTED;
261 void _x_demux_control_end          (xine_stream_t *stream, uint32_t flags) XINE_PROTECTED;
262 int _x_demux_start_thread          (xine_stream_t *stream) XINE_PROTECTED;
263 int _x_demux_stop_thread           (xine_stream_t *stream) XINE_PROTECTED;
264 int _x_demux_read_header           (input_plugin_t *input, void *buffer, off_t size) XINE_PROTECTED;
265 int _x_demux_check_extension       (const char *mrl, const char *extensions);
266 
267 off_t _x_read_abort (xine_stream_t *stream, int fd, char *buf, off_t todo) XINE_PROTECTED;
268 
269 int _x_action_pending (xine_stream_t *stream) XINE_PROTECTED;
270 
271 void _x_action_raise (xine_stream_t *stream) XINE_PROTECTED;
272 void _x_action_lower (xine_stream_t *stream) XINE_PROTECTED;
273 
274 void _x_demux_send_data(fifo_buffer_t *fifo, uint8_t *data, int size,
275                         int64_t pts, uint32_t type, uint32_t decoder_flags,
276                         int input_normpos, int input_time, int total_time,
277                         uint32_t frame_number) XINE_PROTECTED;
278 
279 int _x_demux_read_send_data(fifo_buffer_t *fifo, input_plugin_t *input,
280                             int size, int64_t pts, uint32_t type,
281                             uint32_t decoder_flags, off_t input_normpos,
282                             int input_time, int total_time,
283                             uint32_t frame_number) XINE_USED XINE_PROTECTED;
284 
285 void _x_demux_send_mrl_reference (xine_stream_t *stream, int alternative,
286 				  const char *mrl, const char *title,
287 				  int start_time, int duration) XINE_PROTECTED;
288 
289 /*
290  * MRL escaped-character decoding (overwrites the source string)
291  */
292 void _x_mrl_unescape(char *mrl) XINE_PROTECTED;
293 
294 /*
295  * Return a copy of mrl without authentication credentials
296  */
297 char *_x_mrl_remove_auth(const char *mrl) XINE_PROTECTED;
298 
299 /*
300  * plugin_loader functions
301  *
302  */
303 
304 /* allow input plugins to use other input plugins */
305 input_plugin_t *_x_find_input_plugin (xine_stream_t *stream, const char *mrl) XINE_PROTECTED;
306 void _x_free_input_plugin (xine_stream_t *stream, input_plugin_t *input) XINE_PROTECTED;
307 
308 /* on-demand loading of generic modules / sub-plugins */
309 struct xine_module_s; /* xine_module.h */
310 struct xine_module_s *_x_find_module(xine_t *xine, const char *type, const char *id, unsigned sub_type, const void *params) XINE_PROTECTED;
311 void _x_free_module(xine_t *xine, struct xine_module_s **pmodule) XINE_PROTECTED;
312 
313 /* on-demand loading of audio/video/spu decoder plugins */
314 
315 video_decoder_t *_x_get_video_decoder  (xine_stream_t *stream, uint8_t stream_type) XINE_PROTECTED;
316 void             _x_free_video_decoder (xine_stream_t *stream, video_decoder_t *decoder) XINE_PROTECTED;
317 audio_decoder_t *_x_get_audio_decoder  (xine_stream_t *stream, uint8_t stream_type) XINE_PROTECTED;
318 void             _x_free_audio_decoder (xine_stream_t *stream, audio_decoder_t *decoder) XINE_PROTECTED;
319 spu_decoder_t   *_x_get_spu_decoder    (xine_stream_t *stream, uint8_t stream_type) XINE_PROTECTED;
320 void             _x_free_spu_decoder   (xine_stream_t *stream, spu_decoder_t *decoder) XINE_PROTECTED;
321 /* check for decoder availability - but don't try to initialize it */
322 int              _x_decoder_available  (xine_t *xine, uint32_t buftype) XINE_PROTECTED;
323 
324 /* on-demand loading of demux plugins */
325 demux_plugin_t *_x_find_demux_plugin (xine_stream_t *stream, input_plugin_t *input) XINE_PROTECTED;
326 demux_plugin_t *_x_find_demux_plugin_by_name (xine_stream_t *stream, const char *name, input_plugin_t *input) XINE_PROTECTED;
327 void _x_free_demux_plugin (xine_stream_t *stream, demux_plugin_t **demux) XINE_PROTECTED;
328 
329 /*
330  * load_video_output_plugin
331  *
332  * load a specific video output plugin
333  */
334 
335 vo_driver_t *_x_load_video_output_plugin(xine_t *this_gen,
336                                          const char *id, int visual_type,
337                                          const void *visual) XINE_PROTECTED;
338 
339 /*
340  * audio output plugin dynamic loading stuff
341  */
342 
343 /*
344  * load_audio_output_plugin
345  *
346  * load a specific audio output plugin
347  */
348 
349 ao_driver_t *_x_load_audio_output_plugin (xine_t *self, const char *id) XINE_PROTECTED;
350 
351 
352 void _x_set_speed (xine_stream_t *stream, int speed) XINE_PROTECTED;
353 
354 int _x_get_speed (xine_stream_t *stream) XINE_PROTECTED;
355 
356 /* set when pauseing with port ticket granted, for XINE_PARAM_VO_SINGLE_STEP. */
357 /* special values for fine speed. */
358 # define XINE_LIVE_PAUSE_ON 0x7ffffffd
359 # define XINE_LIVE_PAUSE_OFF 0x7ffffffc
360 void _x_set_fine_speed (xine_stream_t *stream, int speed) XINE_PROTECTED;
361 
362 int _x_get_fine_speed (xine_stream_t *stream) XINE_PROTECTED;
363 
364 void _x_select_spu_channel (xine_stream_t *stream, int channel) XINE_PROTECTED;
365 
366 int _x_get_audio_channel (xine_stream_t *stream) XINE_PROTECTED;
367 
368 int _x_get_spu_channel (xine_stream_t *stream) XINE_PROTECTED;
369 
370 int _x_get_video_streamtype (xine_stream_t *) XINE_PROTECTED;
371 
372 /*
373  * internal events
374  */
375 
376 /* sent by dvb frontend to inform ts demuxer of new pids */
377 #define XINE_EVENT_PIDS_CHANGE	          0x80000000
378 /* sent by BluRay input plugin to inform ts demuxer about end of clip */
379 #define XINE_EVENT_END_OF_CLIP            0x80000001
380 
381 /*
382  * pids change event - inform ts demuxer of new pids
383  */
384 typedef struct {
385   int                 vpid; /* video program id */
386   int                 apid; /* audio program id */
387 } xine_pids_data_t;
388 
389 #ifdef __cplusplus
390 }
391 #endif
392 
393 #endif
394 
395