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 * contents:
22 *
23 * buffer_entry structure - serves as a transport encapsulation
24 * of the mpeg audio/video data through xine
25 *
26 * free buffer pool management routines
27 *
28 * FIFO buffer structures/routines
29 */
30
31 #ifndef HAVE_BUFFER_H
32 #define HAVE_BUFFER_H
33
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37
38 #include <string.h> /* memcmp */
39 #include <sys/types.h> /* pthread_* */
40 #include <pthread.h> /* clang systems seem to need this */
41
42 #include <xine/os_types.h>
43 #include <xine/attributes.h>
44 #include <xine/tickets.h>
45
46 #define BUF_MAX_CALLBACKS 5
47
48 /**
49 * @defgroup buffer_types Buffer Types
50 *
51 * a buffer type ID describes the contents of a buffer
52 * it consists of three fields:
53 *
54 * buf_type = 0xMMDDCCCC
55 *
56 * MM : major buffer type (CONTROL, VIDEO, AUDIO, SPU)
57 * DD : decoder selection (e.g. MPEG, OPENDIVX ... for VIDEO)
58 * CCCC : channel number or other subtype information for the decoder
59 */
60 /*@{*/
61
62 #define BUF_MAJOR_MASK 0xFF000000
63 #define BUF_DECODER_MASK 0x00FF0000
64
65 /**
66 * @defgroup buffer_ctrl Control buffer types
67 */
68 /*@{*/
69 #define BUF_CONTROL_BASE 0x01000000
70 #define BUF_CONTROL_START 0x01000000
71 #define BUF_CONTROL_END 0x01010000
72 #define BUF_CONTROL_QUIT 0x01020000
73 #define BUF_CONTROL_DISCONTINUITY 0x01030000 /**< former AVSYNC_RESET */
74 #define BUF_CONTROL_NOP 0x01040000
75 #define BUF_CONTROL_AUDIO_CHANNEL 0x01050000
76 #define BUF_CONTROL_SPU_CHANNEL 0x01060000
77 #define BUF_CONTROL_NEWPTS 0x01070000
78 #define BUF_CONTROL_RESET_DECODER 0x01080000
79 #define BUF_CONTROL_HEADERS_DONE 0x01090000
80 #define BUF_CONTROL_FLUSH_DECODER 0x010a0000
81 #define BUF_CONTROL_RESET_TRACK_MAP 0x010b0000
82 /*@}*/
83
84 /**
85 * @defgroup buffer_video Video buffer types
86 * @note (please keep in sync with buffer_types.c)
87 */
88 /*@{*/
89 #define BUF_VIDEO_BASE 0x02000000
90 #define BUF_VIDEO_UNKNOWN 0x02ff0000 /**< no decoder should handle this one */
91 #define BUF_VIDEO_MPEG 0x02000000
92 #define BUF_VIDEO_MPEG4 0x02010000
93 #define BUF_VIDEO_CINEPAK 0x02020000
94 #define BUF_VIDEO_SORENSON_V1 0x02030000
95 #define BUF_VIDEO_MSMPEG4_V2 0x02040000
96 #define BUF_VIDEO_MSMPEG4_V3 0x02050000
97 #define BUF_VIDEO_MJPEG 0x02060000
98 #define BUF_VIDEO_IV50 0x02070000
99 #define BUF_VIDEO_IV41 0x02080000
100 #define BUF_VIDEO_IV32 0x02090000
101 #define BUF_VIDEO_IV31 0x020a0000
102 #define BUF_VIDEO_ATIVCR1 0x020b0000
103 #define BUF_VIDEO_ATIVCR2 0x020c0000
104 #define BUF_VIDEO_I263 0x020d0000
105 #define BUF_VIDEO_RV10 0x020e0000
106 #define BUF_VIDEO_RGB 0x02100000
107 #define BUF_VIDEO_YUY2 0x02110000
108 #define BUF_VIDEO_JPEG 0x02120000
109 #define BUF_VIDEO_WMV7 0x02130000
110 #define BUF_VIDEO_WMV8 0x02140000
111 #define BUF_VIDEO_MSVC 0x02150000
112 #define BUF_VIDEO_DV 0x02160000
113 #define BUF_VIDEO_REAL 0x02170000
114 #define BUF_VIDEO_VP31 0x02180000
115 #define BUF_VIDEO_H263 0x02190000
116 #define BUF_VIDEO_3IVX 0x021A0000
117 #define BUF_VIDEO_CYUV 0x021B0000
118 #define BUF_VIDEO_DIVX5 0x021C0000
119 #define BUF_VIDEO_XVID 0x021D0000
120 #define BUF_VIDEO_SMC 0x021E0000
121 #define BUF_VIDEO_RPZA 0x021F0000
122 #define BUF_VIDEO_QTRLE 0x02200000
123 #define BUF_VIDEO_MSRLE 0x02210000
124 #define BUF_VIDEO_DUCKTM1 0x02220000
125 #define BUF_VIDEO_FLI 0x02230000
126 #define BUF_VIDEO_ROQ 0x02240000
127 #define BUF_VIDEO_SORENSON_V3 0x02250000
128 #define BUF_VIDEO_MSMPEG4_V1 0x02260000
129 #define BUF_VIDEO_MSS1 0x02270000
130 #define BUF_VIDEO_IDCIN 0x02280000
131 #define BUF_VIDEO_PGVV 0x02290000
132 #define BUF_VIDEO_ZYGO 0x022A0000
133 #define BUF_VIDEO_TSCC 0x022B0000
134 #define BUF_VIDEO_YVU9 0x022C0000
135 #define BUF_VIDEO_VQA 0x022D0000
136 #define BUF_VIDEO_GREY 0x022E0000
137 #define BUF_VIDEO_XXAN 0x022F0000
138 #define BUF_VIDEO_WC3 0x02300000
139 #define BUF_VIDEO_YV12 0x02310000
140 #define BUF_VIDEO_SEGA 0x02320000
141 #define BUF_VIDEO_RV20 0x02330000
142 #define BUF_VIDEO_RV30 0x02340000
143 #define BUF_VIDEO_MVI2 0x02350000
144 #define BUF_VIDEO_UCOD 0x02360000
145 #define BUF_VIDEO_WMV9 0x02370000
146 #define BUF_VIDEO_INTERPLAY 0x02380000
147 #define BUF_VIDEO_RV40 0x02390000
148 #define BUF_VIDEO_PSX_MDEC 0x023A0000
149 #define BUF_VIDEO_YUV_FRAMES 0x023B0000 /**< uncompressed YUV, delivered by v4l input plugin */
150 #define BUF_VIDEO_HUFFYUV 0x023C0000
151 #define BUF_VIDEO_IMAGE 0x023D0000
152 #define BUF_VIDEO_THEORA 0x023E0000
153 #define BUF_VIDEO_4XM 0x023F0000
154 #define BUF_VIDEO_I420 0x02400000
155 #define BUF_VIDEO_VP4 0x02410000
156 #define BUF_VIDEO_VP5 0x02420000
157 #define BUF_VIDEO_VP6 0x02430000
158 #define BUF_VIDEO_VMD 0x02440000
159 #define BUF_VIDEO_MSZH 0x02450000
160 #define BUF_VIDEO_ZLIB 0x02460000
161 #define BUF_VIDEO_8BPS 0x02470000
162 #define BUF_VIDEO_ASV1 0x02480000
163 #define BUF_VIDEO_ASV2 0x02490000
164 #define BUF_VIDEO_BITPLANE 0x024A0000 /**< Amiga typical picture and animation format */
165 #define BUF_VIDEO_BITPLANE_BR1 0x024B0000 /**< the same with Bytrun compression 1 */
166 #define BUF_VIDEO_FLV1 0x024C0000
167 #define BUF_VIDEO_H264 0x024D0000
168 #define BUF_VIDEO_MJPEG_B 0x024E0000
169 #define BUF_VIDEO_H261 0x024F0000
170 #define BUF_VIDEO_AASC 0x02500000
171 #define BUF_VIDEO_LOCO 0x02510000
172 #define BUF_VIDEO_QDRW 0x02520000
173 #define BUF_VIDEO_QPEG 0x02530000
174 #define BUF_VIDEO_ULTI 0x02540000
175 #define BUF_VIDEO_WNV1 0x02550000
176 #define BUF_VIDEO_XL 0x02560000
177 #define BUF_VIDEO_RT21 0x02570000
178 #define BUF_VIDEO_FPS1 0x02580000
179 #define BUF_VIDEO_DUCKTM2 0x02590000
180 #define BUF_VIDEO_CSCD 0x025A0000
181 #define BUF_VIDEO_ALGMM 0x025B0000
182 #define BUF_VIDEO_ZMBV 0x025C0000
183 #define BUF_VIDEO_AVS 0x025D0000
184 #define BUF_VIDEO_SMACKER 0x025E0000
185 #define BUF_VIDEO_NUV 0x025F0000
186 #define BUF_VIDEO_KMVC 0x02600000
187 #define BUF_VIDEO_FLASHSV 0x02610000
188 #define BUF_VIDEO_CAVS 0x02620000
189 #define BUF_VIDEO_VP6F 0x02630000
190 #define BUF_VIDEO_THEORA_RAW 0x02640000
191 #define BUF_VIDEO_VC1 0x02650000
192 #define BUF_VIDEO_VMNC 0x02660000
193 #define BUF_VIDEO_SNOW 0x02670000
194 #define BUF_VIDEO_VP8 0x02680000
195 #define BUF_VIDEO_VP9 0x02690000
196 #define BUF_VIDEO_HEVC 0x026A0000
197 #define BUF_VIDEO_AV1 0x026B0000
198 #define BUF_VIDEO_PNG 0x026C0000
199
200 /*@}*/
201
202 /**
203 * @defgroup buffer_audio Audio buffer types
204 * @note (please keep in sync with buffer_types.c)
205 */
206 /*@{*/
207 #define BUF_AUDIO_BASE 0x03000000
208 #define BUF_AUDIO_UNKNOWN 0x03ff0000 /**< no decoder should handle this one */
209 #define BUF_AUDIO_A52 0x03000000
210 #define BUF_AUDIO_MPEG 0x03010000
211 #define BUF_AUDIO_LPCM_BE 0x03020000
212 #define BUF_AUDIO_LPCM_LE 0x03030000
213 #define BUF_AUDIO_WMAV1 0x03040000
214 #define BUF_AUDIO_DTS 0x03050000
215 #define BUF_AUDIO_MSADPCM 0x03060000
216 #define BUF_AUDIO_MSIMAADPCM 0x03070000
217 #define BUF_AUDIO_MSGSM 0x03080000
218 #define BUF_AUDIO_VORBIS 0x03090000
219 #define BUF_AUDIO_IMC 0x030a0000
220 #define BUF_AUDIO_LH 0x030b0000
221 #define BUF_AUDIO_VOXWARE 0x030c0000
222 #define BUF_AUDIO_ACELPNET 0x030d0000
223 #define BUF_AUDIO_AAC 0x030e0000
224 #define BUF_AUDIO_DNET 0x030f0000
225 #define BUF_AUDIO_VIVOG723 0x03100000
226 #define BUF_AUDIO_DK3ADPCM 0x03110000
227 #define BUF_AUDIO_DK4ADPCM 0x03120000
228 #define BUF_AUDIO_ROQ 0x03130000
229 #define BUF_AUDIO_QTIMAADPCM 0x03140000
230 #define BUF_AUDIO_MAC3 0x03150000
231 #define BUF_AUDIO_MAC6 0x03160000
232 #define BUF_AUDIO_QDESIGN1 0x03170000
233 #define BUF_AUDIO_QDESIGN2 0x03180000
234 #define BUF_AUDIO_QCLP 0x03190000
235 #define BUF_AUDIO_SMJPEG_IMA 0x031A0000
236 #define BUF_AUDIO_VQA_IMA 0x031B0000
237 #define BUF_AUDIO_MULAW 0x031C0000
238 #define BUF_AUDIO_ALAW 0x031D0000
239 #define BUF_AUDIO_GSM610 0x031E0000
240 #define BUF_AUDIO_EA_ADPCM 0x031F0000
241 #define BUF_AUDIO_WMAV2 0x03200000
242 #define BUF_AUDIO_COOK 0x03210000
243 #define BUF_AUDIO_ATRK 0x03220000
244 #define BUF_AUDIO_14_4 0x03230000
245 #define BUF_AUDIO_28_8 0x03240000
246 #define BUF_AUDIO_SIPRO 0x03250000
247 #define BUF_AUDIO_WMAPRO 0x03260000
248 #define BUF_AUDIO_WMAV3 BUF_AUDIO_WMAPRO
249 #define BUF_AUDIO_INTERPLAY 0x03270000
250 #define BUF_AUDIO_XA_ADPCM 0x03280000
251 #define BUF_AUDIO_WESTWOOD 0x03290000
252 #define BUF_AUDIO_DIALOGIC_IMA 0x032A0000
253 #define BUF_AUDIO_NSF 0x032B0000
254 #define BUF_AUDIO_FLAC 0x032C0000
255 #define BUF_AUDIO_DV 0x032D0000
256 #define BUF_AUDIO_WMAV 0x032E0000
257 #define BUF_AUDIO_SPEEX 0x032F0000
258 #define BUF_AUDIO_RAWPCM 0x03300000
259 #define BUF_AUDIO_4X_ADPCM 0x03310000
260 #define BUF_AUDIO_VMD 0x03320000
261 #define BUF_AUDIO_XAN_DPCM 0x03330000
262 #define BUF_AUDIO_ALAC 0x03340000
263 #define BUF_AUDIO_MPC 0x03350000
264 #define BUF_AUDIO_SHORTEN 0x03360000
265 #define BUF_AUDIO_WESTWOOD_SND1 0x03370000
266 #define BUF_AUDIO_WMALL 0x03380000
267 #define BUF_AUDIO_TRUESPEECH 0x03390000
268 #define BUF_AUDIO_TTA 0x033A0000
269 #define BUF_AUDIO_SMACKER 0x033B0000
270 #define BUF_AUDIO_FLVADPCM 0x033C0000
271 #define BUF_AUDIO_WAVPACK 0x033D0000
272 #define BUF_AUDIO_MP3ADU 0x033E0000
273 #define BUF_AUDIO_AMR_NB 0x033F0000
274 #define BUF_AUDIO_AMR_WB 0x03400000
275 #define BUF_AUDIO_EAC3 0x03410000
276 #define BUF_AUDIO_AAC_LATM 0x03420000
277 #define BUF_AUDIO_ADPCM_G726 0x03430000
278 #define BUF_AUDIO_OPUS 0x03440000
279 #define BUF_AUDIO_TRUEHD 0x03450000
280 /*@}*/
281
282 /**
283 * @defgroup buffer_spu SPU buffer types
284 */
285 /*@{*/
286 #define BUF_SPU_BASE 0x04000000
287 #define BUF_SPU_DVD 0x04000000
288 #define BUF_SPU_TEXT 0x04010000
289 #define BUF_SPU_CC 0x04020000
290 #define BUF_SPU_DVB 0x04030000
291 #define BUF_SPU_SVCD 0x04040000
292 #define BUF_SPU_CVD 0x04050000
293 #define BUF_SPU_OGM 0x04060000
294 #define BUF_SPU_CMML 0x04070000
295 #define BUF_SPU_HDMV 0x04080000
296 #define BUF_SPU_HDMV_TEXT 0x04090000
297 /*@}*/
298
299 /**
300 * @defgroup buffer_demux Demuxer block types
301 */
302 /*@{*/
303 #define BUF_DEMUX_BLOCK 0x05000000
304 /*@}*/
305
306 /*@}*/
307
308 typedef struct extra_info_s extra_info_t;
309
310 /**
311 * @brief Structure to pass information from input or demuxer plugins
312 * to output frames (past decoder).
313 *
314 * New data must be added after the existing fields to not break ABI
315 * (backward compatibility).
316 */
317
318 struct extra_info_s {
319
320 int input_normpos; /**< remember where this buf came from in
321 * the input source (0..65535). can be
322 * either time or offset based. */
323 int input_time; /**< time offset in miliseconds from
324 * beginning of stream */
325 uint32_t frame_number; /**< number of current frame if known */
326
327 int seek_count; /**< internal engine use */
328 int64_t vpts; /**< set on output layers only */
329
330 int invalid; /**< do not use this extra info to update anything */
331 int total_time; /**< duration in miliseconds of the stream */
332 };
333
334
335 #define BUF_NUM_DEC_INFO 5
336
337 typedef struct buf_element_s buf_element_t;
338 struct buf_element_s {
339 buf_element_t *next;
340
341 unsigned char *mem;
342 unsigned char *content; /**< start of raw content in mem (without header etc) */
343
344 int32_t size ; /**< size of _content_ */
345 int32_t max_size; /**< size of pre-allocated memory pointed to by "mem" */
346 int64_t pts; /**< presentation time stamp, used for a/v sync */
347 int64_t disc_off; /**< discontinuity offset */
348
349 extra_info_t *extra_info; /**< extra info will be passed to frames */
350
351 uint32_t decoder_flags; /**< stuff like keyframe, is_header ... see below */
352
353 /** additional decoder flags and other dec-spec. stuff */
354 uint32_t decoder_info[BUF_NUM_DEC_INFO];
355 /** pointers to dec-spec. stuff */
356 void *decoder_info_ptr[BUF_NUM_DEC_INFO];
357
358 void (*free_buffer) (buf_element_t *buf);
359
360 void *source; /**< pointer to source of this buffer for
361 * free_buffer */
362
363 uint32_t type;
364 } ;
365
366 /** keyframe should be set whenever possible (that is, when demuxer
367 * knows about frames and keyframes). */
368 #define BUF_FLAG_KEYFRAME 0x0001
369
370 /** frame start/end. BUF_FLAG_FRAME_END is sent on last buf of a frame */
371 #define BUF_FLAG_FRAME_START 0x0002
372 #define BUF_FLAG_FRAME_END 0x0004
373
374 /** any out-of-band data needed to initialize decoder must have
375 * this flag set. */
376 #define BUF_FLAG_HEADER 0x0008
377
378 /** preview buffers are normal data buffers that must not produce any
379 * output in decoders (may be used to sneak details about the stream
380 * to come). */
381 #define BUF_FLAG_PREVIEW 0x0010
382
383 /** set when user stop the playback */
384 #define BUF_FLAG_END_USER 0x0020
385
386 /** set when stream finished naturaly */
387 #define BUF_FLAG_END_STREAM 0x0040
388
389 /** decoder_info[0] carries the frame step (1/90000). */
390 #define BUF_FLAG_FRAMERATE 0x0080
391
392 /** hint to metronom that seeking has occurred */
393 #define BUF_FLAG_SEEK 0x0100
394
395 /** special information inside, see below. */
396 #define BUF_FLAG_SPECIAL 0x0200
397
398 /** header use standard xine_bmiheader or xine_waveformatex structs.
399 * xine_waveformatex is actually optional since the most important
400 * information for audio init is available from decoder_info[].
401 * note: BUF_FLAG_HEADER must also be set. */
402 #define BUF_FLAG_STDHEADER 0x0400
403
404 /** decoder_info[1] carries numerator for display aspect ratio
405 * decoder_info[2] carries denominator for display aspect ratio */
406 #define BUF_FLAG_ASPECT 0x0800
407
408 /* represent the state of gapless_switch at the time buf was enqueued */
409 #define BUF_FLAG_GAPLESS_SW 0x1000
410
411 /* Amount of audio padding added by encoder (mp3, aac). These empty
412 * audio frames are causing a gap when switching between mp3 files.
413 * decoder_info[1] carries amount of audio frames padded at the
414 * beginning of the buffer
415 * decoder_info[2] carries amount of audio frames padded at the end of
416 * the buffer */
417 #define BUF_FLAG_AUDIO_PADDING 0x2000
418
419 /** decoder_info[4] has (mpeg_color_matrix << 1) | fullrange.
420 * Useful for raw YUV which cannot tell this otherwise.
421 * Valid until revoked or next stream. */
422 #define BUF_FLAG_COLOR_MATRIX 0x4000
423
424 /** Optimization: try to merge this buf with previous one still in fifo.
425 * This is for demuxers that dont know a frame's size before sending it
426 * (mpeg-ts). Decoders will never see this. */
427 #define BUF_FLAG_MERGE 0x8000
428
429 /**
430 * \defgroup buffer_special Special buffer types:
431 * Sometimes there is a need to relay special information from a demuxer
432 * to a video decoder. For example, some file types store palette data in
433 * the file header independant of the video data. The special buffer type
434 * offers a way to communicate this or any other custom, format-specific
435 * data to the decoder.
436 *
437 * The interface was designed in a way that did not require an API
438 * version bump. To send a special buffer type, set a buffer's flags field
439 * to BUF_FLAG_SPECIAL. Set the buffer's decoder_info[1] field to a
440 * number according to one of the special buffer subtypes defined below.
441 * The second and third decoder_info[] fields are defined according to
442 * your buffer type's requirements.
443 *
444 * Finally, remember to set the buffer's size to 0. This way, if a special
445 * buffer is sent to a decode that does not know how to handle it, the
446 * buffer will fall through to the case where the buffer's data content
447 * is accumulated and no harm will be done.
448 */
449 /*@{*/
450
451 /**
452 * In a BUF_SPECIAL_PALETTE buffer:
453 * decoder_info[1] = BUF_SPECIAL_PALETTE
454 * decoder_info[2] = number of entries in palette table
455 * decoder_info_ptr[2] = pointer to palette table
456 * This buffer type is used to provide a file- and decoder-independent
457 * facility to transport RGB color palettes from demuxers to decoders.
458 * A palette table is an array of palette_entry_t structures. A decoder
459 * should not count on this array to exist for the duration of the
460 * program's execution and should copy, manipulate, and store the palette
461 * data privately if it needs the palette information.
462 */
463 #define BUF_SPECIAL_PALETTE 1
464
465
466 /* special buffer type 2 used to be defined but is now available for use */
467
468
469 /**
470 * In a BUF_SPECIAL_ASPECT buffer:
471 * decoder_info[1] = BUF_SPECIAL_ASPECT
472 * decoder_info[2] = MPEG2 aspect ratio code
473 * decoder_info[3] = stream scale prohibitions
474 * This buffer is used to force mpeg decoders to use a certain aspect.
475 * Currently xine-dvdnav uses this, because it has more accurate information
476 * about the aspect from the dvd ifo-data.
477 * The stream scale prohibitions are also delivered, with bit 0 meaning
478 * "deny letterboxing" and bit 1 meaning "deny pan&scan"
479 */
480 #define BUF_SPECIAL_ASPECT 3
481
482 /**
483 * In a BUF_SPECIAL_DECODER_CONFIG buffer:
484 * decoder_info[1] = BUF_SPECIAL_DECODER_CONFIG
485 * decoder_info[2] = data size
486 * decoder_info_ptr[2] = pointer to data
487 * This buffer is used to pass config information from .mp4 files
488 * (atom esds) to decoders. both mpeg4 and aac streams use that.
489 */
490 #define BUF_SPECIAL_DECODER_CONFIG 4
491
492 /**
493 * In a BUF_SPECIAL_STSD_ATOM buffer:
494 * decoder_info[1] = BUF_SPECIAL_STSD_ATOM
495 * decoder_info[2] = size of the ImageDescription atom, minus the
496 * four length bytes at the beginning
497 * decoder_info_ptr[2] = pointer to ImageDescription atom, starting with
498 * the codec fourcc
499 * Some Quicktime decoders need information contained within the
500 * ImageDescription atom inside a Quicktime file's stsd atom. This
501 * special buffer carries the ImageDescription atom from the QT demuxer
502 * to an A/V decoder.
503 */
504 #define BUF_SPECIAL_STSD_ATOM 5
505
506 /**
507 * In a BUF_SPECIAL_LPCM_CONFIG buffer:
508 * decoder_info[1] = BUF_SPECIAL_LPCM_CONFIG
509 * decoder_info[2] = config data
510 * lpcm data encoded into mpeg2 streams have a format configuration
511 * byte in every frame. this is used to detect the sample rate,
512 * number of bits and channels.
513 */
514 #define BUF_SPECIAL_LPCM_CONFIG 6
515
516 /**
517 * In a BUF_SPECIAL_CHARSET_ENCODING buffer:
518 * decoder_info[1] = BUF_SPECIAL_CHARSET_ENCODING
519 * decoder_info[2] = size of charset encoding string
520 * decoder_info_ptr[2] = pointer to charset encoding string
521 * This is used mostly with subtitle buffers when encoding is
522 * known at demuxer level (take precedence over xine config
523 * settings such as subtitles.separate.src_encoding)
524 */
525 #define BUF_SPECIAL_CHARSET_ENCODING 7
526
527
528 /**
529 * In a BUF_SPECIAL_SPU_DVD_SUBTYPE:
530 * decoder_info[1] = BUF_SPECIAL_SPU_DVD_SUBTYPE
531 * decoder_info[2] = subtype
532 * decoder_info[3] =
533 * This buffer is pass SPU subtypes from DVDs
534 */
535 #define BUF_SPECIAL_SPU_DVD_SUBTYPE 8
536
537
538 #define SPU_DVD_SUBTYPE_CLUT 1
539 #define SPU_DVD_SUBTYPE_PACKAGE 2
540 #define SPU_DVD_SUBTYPE_VOBSUB_PACKAGE 3
541 #define SPU_DVD_SUBTYPE_NAV 4
542
543 /**
544 * In a BUF_SPECIAL_SPU_DVB_DESCRIPTOR
545 * decoder_info[1] = BUF_SPECIAL_SPU_DVB_DESCRIPTOR
546 * decoder_info[2] = size of spu_dvb_descriptor_t
547 * decoder_info_ptr[2] = pointer to spu_dvb_descriptor_t, or NULL
548 * decoder_info[3] =
549 *
550 * This buffer is used to tell a DVBSUB decoder when the stream
551 * changes. For more information on how to write a DVBSUB decoder,
552 * see the comment at the top of src/demuxers/demux_ts.c
553 **/
554 #define BUF_SPECIAL_SPU_DVB_DESCRIPTOR 9
555
556 /**
557 * In a BUF_SPECIAL_RV_CHUNK_TABLE:
558 * decoder_info[1] = BUF_SPECIAL_RV_CHUNK_TABLE
559 * decoder_info[2] = number of entries in chunk table
560 * decoder_info_ptr[2] = pointer to the chunk table
561 *
562 * This buffer transports the chunk table associated to each RealVideo frame.
563 */
564 #define BUF_SPECIAL_RV_CHUNK_TABLE 10
565 /*@}*/
566
567 typedef struct spu_dvb_descriptor_s spu_dvb_descriptor_t;
568 struct spu_dvb_descriptor_s
569 {
570 char lang[4];
571 long comp_page_id;
572 long aux_page_id;
573 } ;
574
575 typedef struct palette_entry_s palette_entry_t;
576 struct palette_entry_s
577 {
578 unsigned char r, g, b;
579 } ;
580
581 typedef struct fifo_buffer_s fifo_buffer_t;
582 struct fifo_buffer_s
583 {
584 buf_element_t *first, *last;
585
586 int fifo_size;
587 uint32_t fifo_data_size;
588 void *fifo_empty_cb_data;
589
590 pthread_mutex_t mutex;
591 pthread_cond_t not_empty;
592
593 /*
594 * functions to access this fifo:
595 */
596
597 void (*put) (fifo_buffer_t *fifo, buf_element_t *buf);
598
599 buf_element_t *(*get) (fifo_buffer_t *fifo);
600
601 void (*clear) (fifo_buffer_t *fifo) ;
602
603 int (*size) (fifo_buffer_t *fifo);
604
605 int (*num_free) (fifo_buffer_t *fifo);
606
607 uint32_t (*data_size) (fifo_buffer_t *fifo);
608
609 void (*dispose) (fifo_buffer_t *fifo);
610
611 /*
612 * alloc buffer for this fifo from global buf pool
613 * you don't have to use this function to allocate a buffer,
614 * an input plugin can decide to implement it's own
615 * buffer allocation functions
616 */
617
618 buf_element_t *(*buffer_pool_alloc) (fifo_buffer_t *self);
619
620
621 /*
622 * special functions, not used by demuxers
623 */
624
625 /* the same as buffer_pool_alloc but may fail if none is available */
626 buf_element_t *(*buffer_pool_try_alloc) (fifo_buffer_t *self);
627
628 /* the same as put but insert at the head of the fifo */
629 void (*insert) (fifo_buffer_t *fifo, buf_element_t *buf);
630
631 /* callbacks */
632 void (*register_alloc_cb) (fifo_buffer_t *fifo, void (*cb)(fifo_buffer_t *fifo, void *), void *cb_data);
633 void (*register_put_cb) (fifo_buffer_t *fifo, void (*cb)(fifo_buffer_t *fifo, buf_element_t *buf, void *), void *cb_data);
634 void (*register_get_cb) (fifo_buffer_t *fifo, void (*cb)(fifo_buffer_t *fifo, buf_element_t *buf, void *), void *cb_data);
635 void (*unregister_alloc_cb) (fifo_buffer_t *fifo, void (*cb)(fifo_buffer_t *fifo, void *));
636 void (*unregister_put_cb) (fifo_buffer_t *fifo, void (*cb)(fifo_buffer_t *fifo, buf_element_t *buf, void *));
637 void (*unregister_get_cb) (fifo_buffer_t *fifo, void (*cb)(fifo_buffer_t *fifo, buf_element_t *buf, void *));
638
639 /*
640 * private variables for buffer pool management
641 */
642 buf_element_t *buffer_pool_top; /* a heap actually */
643 pthread_mutex_t buffer_pool_mutex;
644 pthread_cond_t buffer_pool_cond_not_empty;
645 int buffer_pool_num_free;
646 int buffer_pool_capacity;
647 int buffer_pool_buf_size;
648 void *buffer_pool_base; /*used to free mem chunk */
649 void (*alloc_cb[BUF_MAX_CALLBACKS])(fifo_buffer_t *fifo, void *data_cb);
650 void (*put_cb[BUF_MAX_CALLBACKS])(fifo_buffer_t *fifo, buf_element_t *buf, void *data_cb);
651 void (*get_cb[BUF_MAX_CALLBACKS])(fifo_buffer_t *fifo, buf_element_t *buf, void *data_cb);
652 void *alloc_cb_data[BUF_MAX_CALLBACKS];
653 void *put_cb_data[BUF_MAX_CALLBACKS];
654 void *get_cb_data[BUF_MAX_CALLBACKS];
655
656 /* get a buffer large enough for given byte size.
657 * result may still be smaller, do check buf->max_size.
658 */
659 buf_element_t *(*buffer_pool_size_alloc) (fifo_buffer_t *self, size_t size);
660
661 /* private */
662 int buffer_pool_num_waiters;
663 int buffer_pool_large_wait;
664 int fifo_num_waiters;
665
666 /* Same as get but if ticket is not NULL
667 * - release it while waiting for a buf, or
668 * - renew it when revoked.
669 */
670 buf_element_t *(*tget) (fifo_buffer_t *fifo, xine_ticket_t *ticket);
671
672 /* Try to enlarge an allocated buf.
673 * There are 2 possible results:
674 * a) The buffer has been enlarged, and NULL is returned.
675 * b) The buffer cannot be enlarged due to internal memory fragmentation,
676 * and a new buffer for the extra data is returned.
677 * No need for an extra buffer_pool_size_alloc ().
678 * Any result may still be smaller, do check buf->max_size.
679 */
680 buf_element_t *(*buffer_pool_realloc) (buf_element_t *buf, size_t new_size);
681 } ;
682
683 /**
684 * @brief Allocate and initialise new (empty) FIFO buffers.
685 * @param num_buffer Number of buffers to allocate.
686 * @param buf_size Size of each buffer.
687 * @internal Only used by video and audio decoder loops.
688 */
689 fifo_buffer_t *_x_fifo_buffer_new (int num_buffers, uint32_t buf_size) XINE_PROTECTED;
690
691 /**
692 * @brief Allocate and initialise new dummy FIFO buffers.
693 * @param num_buffer Number of dummy buffers to allocate.
694 * @param buf_size Size of each buffer.
695 * @internal Only used by video and audio decoder loops.
696 */
697 fifo_buffer_t *_x_dummy_fifo_buffer_new (int num_buffers, uint32_t buf_size);
698
699 /**
700 * @brief Free chained list of buffer elements.
701 * @param head List to free. May be NULL.
702 */
703 void _x_free_buf_elements (buf_element_t *head) XINE_PROTECTED;
704
705
706 /**
707 * @brief Returns the \ref buffer_video "BUF_VIDEO_xxx" for the given fourcc.
708 * @param fourcc_int 32-bit FOURCC value in machine endianness
709 * @sa _x_formattag_to_buf_audio
710 *
711 * example: fourcc_int = *(uint32_t *)fourcc_char;
712 */
713 uint32_t _x_fourcc_to_buf_video( uint32_t fourcc_int ) XINE_PROTECTED;
714
715 /**
716 * @brief Returns video codec name given the buffer type.
717 * @param buf_type One of the \ref buffer_video "BUF_VIDEO_xxx" values.
718 * @sa _x_buf_audio_name
719 */
720 const char * _x_buf_video_name( uint32_t buf_type ) XINE_PROTECTED;
721
722 /**
723 * @brief Returns the \ref buffer_audio "BUF_AUDIO_xxx" for the given formattag.
724 * @param formattagg 32-bit format tag value in machine endianness
725 * @sa _x_fourcc_to_buf_video
726 */
727 uint32_t _x_formattag_to_buf_audio( uint32_t formattag ) XINE_PROTECTED;
728
729 /**
730 * @brief Returns audio codec name given the buffer type.
731 * @param buf_type One of the \ref buffer_audio "BUF_AUDIO_xxx" values.
732 * @sa _x_buf_video_name
733 */
734 const char * _x_buf_audio_name( uint32_t buf_type ) XINE_PROTECTED;
735
736
737 /**
738 * @brief xine version of BITMAPINFOHEADER.
739 * @note Should be safe to compile on 64bits machines.
740 * @note Will always use machine endian format, so demuxers reading
741 * stuff from win32 formats must use the function below.
742 */
743 typedef struct XINE_PACKED {
744 int32_t biSize;
745 int32_t biWidth;
746 int32_t biHeight;
747 int16_t biPlanes;
748 int16_t biBitCount;
749 uint32_t biCompression;
750 int32_t biSizeImage;
751 int32_t biXPelsPerMeter;
752 int32_t biYPelsPerMeter;
753 int32_t biClrUsed;
754 int32_t biClrImportant;
755 } xine_bmiheader;
756
757 /**
758 * @brief xine version of WAVEFORMATEX.
759 * @note The same comments from xine_bmiheader applies.
760 */
761 typedef struct XINE_PACKED {
762 int16_t wFormatTag;
763 int16_t nChannels;
764 int32_t nSamplesPerSec;
765 int32_t nAvgBytesPerSec;
766 int16_t nBlockAlign;
767 int16_t wBitsPerSample;
768 int16_t cbSize;
769 } xine_waveformatex;
770
771 /** Convert xine_bmiheader struct from little endian */
772 void _x_bmiheader_le2me( xine_bmiheader *bih ) XINE_PROTECTED;
773
774 /** Convert xine_waveformatex struct from little endian */
775 void _x_waveformatex_le2me( xine_waveformatex *wavex ) XINE_PROTECTED;
776
_x_is_fourcc(const void * ptr,const void * tag)777 static __inline int _x_is_fourcc(const void *ptr, const void *tag) {
778 return memcmp(ptr, tag, 4) == 0;
779 }
780
781 /**
782 * @brief Make string from machine endian 32bit tag, eg a fourcc or a chunk ID.
783 * @param s Pointer to string buffer of at least 20 bytes.
784 * @param tag The 32bit tag value in native byte order.
785 * @return The length of target string written to s, without the trailing \0.
786 */
787 size_t _x_tag32_me2str (char *s, uint32_t tag) XINE_PROTECTED;
788
789 #ifdef __cplusplus
790 }
791 #endif
792
793 #endif
794