xine-lib  1.2.9
input_plugin.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2000-2017 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_INPUT_PLUGIN_H
22 #define HAVE_INPUT_PLUGIN_H
23 
24 #include <sys/types.h>
25 
26 #include <xine/os_types.h>
27 #include <xine/xineutils.h>
28 #include <xine/buffer.h>
29 #include <xine/configfile.h>
30 
31 #ifdef XINE_COMPILE
32 # include <xine/plugin_catalog.h>
33 #endif
34 
35 #define INPUT_PLUGIN_IFACE_VERSION 18
36 
37 typedef struct input_class_s input_class_t ;
39 
40 struct input_class_s {
41 
42  /*
43  * create a new instance of this plugin class
44  * return NULL if the plugin does'nt handle the given mrl
45  */
46  input_plugin_t* (*get_instance) (input_class_t *this_gen, xine_stream_t *stream, const char *mrl);
47 
51  const char *identifier;
52 
58  const char *description;
59 
63  const char *text_domain;
64 
65  /*
66  * ls function, optional: may be NULL
67  * return value: NULL => filename is a file, **char=> filename is a dir
68  */
69  xine_mrl_t ** (*get_dir) (input_class_t *this_gen, const char *filename, int *nFiles);
70 
71  /*
72  * generate autoplay list, optional: may be NULL
73  * return value: list of MRLs
74  */
75  const char * const * (*get_autoplay_list) (input_class_t *this_gen, int *num_files);
76 
77  /*
78  * close down, free all resources
79  */
80  void (*dispose) (input_class_t *this_gen);
81 
82  /*
83  * eject/load the media (if possible), optional: may be NULL
84  *
85  * returns 0 for temporary failures
86  */
87  int (*eject_media) (input_class_t *this_gen);
88 };
89 
90 #define default_input_class_dispose (void (*) (input_class_t *this_gen))free
91 
93 
94  /*
95  * open the stream
96  * return 0 if an error occured
97  */
98  int (*open) (input_plugin_t *this_gen);
99 
100  /*
101  * return capabilities of the current playable entity. See
102  * get_current_pos below for a description of a "playable entity"
103  * Capabilities a created by "OR"ing a mask of constants listed
104  * below which start "INPUT_CAP".
105  *
106  * depending on the values set, some of the functions below
107  * will or will not get called or should (not) be able to
108  * do certain tasks.
109  *
110  * for example if INPUT_CAP_SEEKABLE is set,
111  * the seek() function is expected to work fully at any time.
112  * however, if the flag is not set, the seek() function should
113  * make a best-effort attempt to seek, e.g. at least
114  * relative forward seeking should work.
115  */
116  uint32_t (*get_capabilities) (input_plugin_t *this_gen);
117 
118  /*
119  * read nlen bytes, return number of bytes read
120  * Should block until some bytes available for read;
121  * a return value of 0 indicates no data available
122  */
123  off_t (*read) (input_plugin_t *this_gen, void *buf, off_t nlen);
124 
125 
126  /*
127  * read one block, return newly allocated block (or NULL on failure)
128  * for blocked input sources len must be == blocksize
129  * the fifo parameter is only used to get access to the buffer_pool_alloc function
130  */
131  buf_element_t *(*read_block)(input_plugin_t *this_gen, fifo_buffer_t *fifo, off_t len);
132 
133 
134  /*
135  * seek position, return new position
136  *
137  * if seeking failed, -1 is returned
138  */
139  off_t (*seek) (input_plugin_t *this_gen, off_t offset, int origin);
140 
141 
142  /*
143  * seek to time position, return new position
144  * time_offset is given in miliseconds
145  *
146  * if seeking failed, -1 is returned
147  *
148  * note: only SEEK_SET (0) is currently supported as origin
149  * note: may be NULL is not supported
150  */
151  off_t (*seek_time) (input_plugin_t *this_gen, int time_offset, int origin);
152 
153 
154  /*
155  * get current position in stream.
156  *
157  */
158  off_t (*get_current_pos) (input_plugin_t *this_gen);
159 
160 
161  /*
162  * get current time position in stream in miliseconds.
163  *
164  * note: may be NULL is not supported
165  */
166  int (*get_current_time) (input_plugin_t *this_gen);
167 
168 
169  /*
170  * return number of bytes in the next playable entity or -1 if the
171  * input is unlimited, as would be the case in a network stream.
172  *
173  * A "playable entity" tends to be the entities listed in a playback
174  * list or the units on which playback control generally works on.
175  * It might be the number of bytes in a VCD "segment" or "track" (if
176  * the track has no "entry" subdivisions), or the number of bytes in
177  * a PS (Program Segment or "Chapter") of a DVD. If there are no
178  * subdivisions of the input medium and it is considered one
179  * indivisible entity, it would be the byte count of that entity;
180  * for example, the length in bytes of an MPEG file.
181 
182  * This length information is used, for example when in setting the
183  * absolute or relative play position or possibly calculating the
184  * bit rate.
185  */
186  off_t (*get_length) (input_plugin_t *this_gen);
187 
188 
189  /*
190  * return block size in bytes of next complete playable entity (if
191  * supported, 0 otherwise). See the description above under
192  * get_length for a description of a "complete playable entity".
193  *
194  * this block size is only used for mpeg streams stored on
195  * a block oriented storage media, e.g. DVDs and VCDs, to speed
196  * up the demuxing process. only set this (and the INPUT_CAP_BLOCK
197  * flag) if this is the case for your input plugin.
198  *
199  * make this function simply return 0 if unsure.
200  */
201 
202  uint32_t (*get_blocksize) (input_plugin_t *this_gen);
203 
204 
205  /*
206  * return current MRL
207  */
208  const char * (*get_mrl) (input_plugin_t *this_gen);
209 
210 
211  /*
212  * request optional data from input plugin.
213  */
214  int (*get_optional_data) (input_plugin_t *this_gen, void *data, int data_type);
215 
216 
217  /*
218  * close stream, free instance resources
219  */
220  void (*dispose) (input_plugin_t *this_gen);
221 
222  /*
223  * "backward" link to input plugin class struct
224  */
225 
227 
234 #ifdef XINE_COMPILE
236 #else
237  void *node;
238 #endif
239 
240 };
241 
242 /*
243  * possible capabilites an input plugin can have:
244  */
245 #define INPUT_CAP_NOCAP 0x00000000
246 
247 /*
248  * INPUT_CAP_SEEKABLE:
249  * seek () works reliably.
250  * even for plugins that do not have this flag set
251  * it is a good idea to implement the seek() function
252  * in a "best effort" style anyway, so at least
253  * throw away data for network streams when seeking forward
254  */
255 
256 #define INPUT_CAP_SEEKABLE 0x00000001
257 
258 /*
259  * INPUT_CAP_BLOCK:
260  * means more or less that a block device sits behind
261  * this input plugin. get_blocksize must be implemented.
262  * will be used for fast and efficient demuxing of
263  * mpeg streams (demux_mpeg_block).
264  */
265 
266 #define INPUT_CAP_BLOCK 0x00000002
267 
268 /*
269  * INPUT_CAP_AUDIOLANG:
270  * INPUT_CAP_SPULANG:
271  * input plugin knows something about audio/spu languages,
272  * e.g. knows that audio stream #0 is english,
273  * audio stream #1 is german, ...
274  * *((int *)data) will provide the requested channel number
275  * and awaits the language back in (char *)data
276  */
277 
278 #define INPUT_CAP_AUDIOLANG 0x00000008
279 #define INPUT_CAP_SPULANG 0x00000010
280 
281 /*
282  * INPUT_CAP_PREVIEW:
283  * get_optional_data can handle INPUT_OPTIONAL_DATA_PREVIEW
284  * so a non-seekable stream plugin can povide the first
285  * few bytes for demuxers to look at them and decide wheter
286  * they can handle the stream or not. the preview data must
287  * be buffered and delivered again through subsequent
288  * read() calls.
289  * caller must provide a buffer allocated with at least
290  * MAX_PREVIEW_SIZE bytes.
291  */
292 
293 #define INPUT_CAP_PREVIEW 0x00000040
294 
295 /*
296  * INPUT_CAP_CHAPTERS:
297  * The media streams provided by this plugin have an internal
298  * structure dividing it into segments usable for navigation.
299  * For those plugins, the behaviour of the skip button in UIs
300  * should be changed from "next MRL" to "next chapter" by
301  * sending XINE_EVENT_INPUT_NEXT.
302  */
303 
304 #define INPUT_CAP_CHAPTERS 0x00000080
305 
306 /*
307  * INPUT_CAP_RIP_FORBIDDEN:
308  * means that rip/disk saving must not be used.
309  * (probably at author's request)
310  */
311 
312 #define INPUT_CAP_RIP_FORBIDDEN 0x00000100
313 
314 /*
315  * INPUT_CAP_NO_CACHE:
316  * do not use input cache plugin
317  */
318 #define INPUT_CAP_NO_CACHE 0x00000200
319 
320 
321 #define INPUT_IS_SEEKABLE(input) (((input)->get_capabilities(input) & INPUT_CAP_SEEKABLE) != 0)
322 
323 #define INPUT_OPTIONAL_UNSUPPORTED 0
324 #define INPUT_OPTIONAL_SUCCESS 1
325 
326 #define INPUT_OPTIONAL_DATA_AUDIOLANG 2
327 #define INPUT_OPTIONAL_DATA_SPULANG 3
328 #define INPUT_OPTIONAL_DATA_PREVIEW 7
329 
330 /* buffer is a const char **; the string is freed by the input plugin. */
331 #define INPUT_OPTIONAL_DATA_MIME_TYPE 8
332 /* buffer is unused; true if the demuxer should be determined by the MIME type */
333 #define INPUT_OPTIONAL_DATA_DEMUX_MIME_TYPE 9
334 /* buffer is a const char **; the string is static or freed by the input plugin. */
335 #define INPUT_OPTIONAL_DATA_DEMUXER 10
336 
337 #define MAX_MRL_ENTRIES 255
338 #define MAX_PREVIEW_SIZE 4096
339 
340 /* Types of mrls returned by get_dir() */
341 #define mrl_unknown (0 << 0)
342 #define mrl_dvd (1 << 0)
343 #define mrl_vcd (1 << 1)
344 #define mrl_net (1 << 2)
345 #define mrl_rtp (1 << 3)
346 #define mrl_stdin (1 << 4)
347 #define mrl_cda (1 << 5)
348 #define mrl_file (1 << 6)
349 #define mrl_file_fifo (1 << 7)
350 #define mrl_file_chardev (1 << 8)
351 #define mrl_file_directory (1 << 9)
352 #define mrl_file_blockdev (1 << 10)
353 #define mrl_file_normal (1 << 11)
354 #define mrl_file_symlink (1 << 12)
355 #define mrl_file_sock (1 << 13)
356 #define mrl_file_exec (1 << 14)
357 #define mrl_file_backup (1 << 15)
358 #define mrl_file_hidden (1 << 16)
359 
360 /*
361  * Freeing/zeroing all of entries of given mrl.
362  */
363 #define MRL_ZERO(m) { \
364  if((m)) { \
365  free((m)->origin); \
366  free((m)->mrl); \
367  free((m)->link); \
368  (m)->origin = NULL; \
369  (m)->mrl = NULL; \
370  (m)->link = NULL; \
371  (m)->type = 0; \
372  (m)->size = (off_t) 0; \
373  } \
374  }
375 
376 /*
377  * Duplicate two mrls entries (s = source, d = destination).
378  */
379 #define MRL_DUPLICATE(s, d) { \
380  _x_assert((s) != NULL); \
381  _x_assert((d) != NULL); \
382  \
383  free((d)->origin); \
384  (d)->origin = (s)->origin ? strdup((s)->origin) : NULL; \
385  \
386  free((d)->mrl); \
387  (d)->mrl = (s)->mrl ? strdup((s)->mrl) : NULL; \
388  \
389  free((d)->link); \
390  (d)->link = (s)->link ? strdup((s)->link) : NULL; \
391  \
392  (d)->type = (s)->type; \
393  (d)->size = (s)->size; \
394  }
395 
396 /*
397  * Duplicate two arrays of mrls (s = source, d = destination).
398  */
399 #define MRLS_DUPLICATE(s, d) { \
400  int i = 0; \
401  \
402  _x_assert((s) != NULL); \
403  _x_assert((d) != NULL); \
404  \
405  while((s) != NULL) { \
406  d[i] = (xine_mrl_t *) malloc(sizeof(xine_mrl_t)); \
407  MRL_DUPLICATE(s[i], d[i]); \
408  i++; \
409  } \
410 }
411 
412 
413 #endif
off_t(* seek)(input_plugin_t *this_gen, off_t offset, int origin)
Definition: input_plugin.h:139
input_class_t * input_class
Definition: input_plugin.h:226
const char * description
human readable (verbose = 1 line) description for this plugin class
Definition: input_plugin.h:58
const char * identifier
short human readable identifier for this plugin class
Definition: input_plugin.h:51
off_t(* get_current_pos)(input_plugin_t *this_gen)
Definition: input_plugin.h:158
int(* open)(input_plugin_t *this_gen)
Definition: input_plugin.h:98
off_t(* seek_time)(input_plugin_t *this_gen, int time_offset, int origin)
Definition: input_plugin.h:151
Definition: buffer.h:334
Definition: plugin_catalog.h:44
off_t(* read)(input_plugin_t *this_gen, void *buf, off_t nlen)
Definition: input_plugin.h:123
Definition: xine.h:1095
off_t(* get_length)(input_plugin_t *this_gen)
Definition: input_plugin.h:186
void(* dispose)(input_class_t *this_gen)
Definition: input_plugin.h:80
Definition: xine_internal.h:210
void(* dispose)(input_plugin_t *this_gen)
Definition: input_plugin.h:220
uint32_t(* get_blocksize)(input_plugin_t *this_gen)
Definition: input_plugin.h:202
const char * text_domain
Optional non-standard catalog to use with dgettext() for description.
Definition: input_plugin.h:63
int(* get_current_time)(input_plugin_t *this_gen)
Definition: input_plugin.h:166
Definition: input_plugin.h:92
int(* get_optional_data)(input_plugin_t *this_gen, void *data, int data_type)
Definition: input_plugin.h:214
int(* eject_media)(input_class_t *this_gen)
Definition: input_plugin.h:87
uint32_t(* get_capabilities)(input_plugin_t *this_gen)
Definition: input_plugin.h:116
Definition: input_plugin.h:40
Definition: buffer.h:578
plugin_node_t * node
Pointer to the loaded plugin node.
Definition: input_plugin.h:235