xine-lib  1.2.9
audio_out.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 #ifndef HAVE_AUDIO_OUT_H
21 #define HAVE_AUDIO_OUT_H
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 #include <xine/os_types.h>
28 #include <xine/metronom.h>
29 #include <xine/configfile.h>
30 #include <xine/xineutils.h>
31 
32 #ifdef XINE_COMPILE
33 # include <xine/plugin_catalog.h>
34 #endif
35 
36 #define AUDIO_OUT_IFACE_VERSION 9
37 
38 /*
39  * ao_driver_s contains the driver every audio output
40  * driver plugin has to implement.
41  */
42 
43 typedef struct ao_driver_s ao_driver_t;
44 
45 struct ao_driver_s {
46 
47  /*
48  *
49  * find out what output modes + capatilities are supported by
50  * this plugin (constants for the bit vector to return see above)
51  *
52  * See AO_CAP_* bellow.
53  */
54  uint32_t (*get_capabilities) (ao_driver_t *);
55 
56  /*
57  * open the driver and make it ready to receive audio data
58  * buffers may be flushed(!)
59  *
60  * return value: 0 : failure, >0 : output sample rate
61  */
62  int (*open)(ao_driver_t *, uint32_t bits, uint32_t rate, int mode);
63 
64  /* return the number of audio channels
65  */
66  int (*num_channels)(ao_driver_t *self_gen);
67 
68  /* return the number of bytes per frame.
69  * A frame is equivalent to one sample being output on every audio channel.
70  */
71  int (*bytes_per_frame)(ao_driver_t *self_gen);
72 
73  /* return the delay is frames measured by
74  * looking at pending samples in the audio output device
75  */
76  int (*delay)(ao_driver_t *self_gen);
77 
78  /*
79  * return gap tolerance (in pts) needed for this driver
80  */
81  int (*get_gap_tolerance) (ao_driver_t *self_gen);
82 
83  /*
84  * write audio data to audio output device
85  * return value:
86  * >0 => audio samples were processed ok
87  * 0 => audio samples were not yet processed,
88  * call write_audio_data with the _same_ samples again
89  */
90  int (*write)(ao_driver_t *,
91  int16_t* audio_data, uint32_t num_samples);
92 
93  /*
94  * this is called when the decoder no longer uses the audio
95  * output driver - the driver should get ready to get opened() again
96  */
97  void (*close)(ao_driver_t *);
98 
99  /*
100  * shut down this audio output driver plugin and
101  * free all resources allocated
102  */
103  void (*exit) (ao_driver_t *);
104 
105  /*
106  * Get, Set a property of audio driver.
107  *
108  * get_property() return 1 in success, 0 on failure.
109  * set_property() return value on success, ~value on failure.
110  *
111  * See AO_PROP_* below for available properties.
112  */
113  int (*get_property) (ao_driver_t *, int property);
114 
115  int (*set_property) (ao_driver_t *, int property, int value);
116 
117 
118  /*
119  * misc control operations on the audio device.
120  *
121  * See AO_CTRL_* below.
122  */
123  int (*control) (ao_driver_t *, int cmd, /* arg */ ...);
124 
131 #ifdef XINE_COMPILE
133 #else
134  void *node;
135 #endif
136 };
137 
138 typedef struct ao_format_s ao_format_t;
139 
140 struct ao_format_s {
141  uint32_t bits;
142  uint32_t rate;
143  int mode;
144 };
145 
146 typedef struct audio_fifo_s audio_fifo_t;
147 
149 
151 
153 
154  int16_t *mem;
155  int mem_size;
157 
158  int64_t vpts;
161 
162  /* extra info coming from input or demuxers */
164 
165  xine_stream_t *stream; /* stream that send that buffer */
166 
167  ao_format_t format; /* let each buffer carry it's own format info */
168 };
169 
170 /*
171  * xine_audio_port_s contains the port every audio decoder talks to
172  *
173  * Remember that adding new functions to this structure requires
174  * adaption of the post plugin decoration layer. Be sure to look into
175  * src/xine-engine/post.[ch].
176  */
177 
179  uint32_t (*get_capabilities) (xine_audio_port_t *); /* for constants see below */
180 
181  /* * Get/Set audio property
182  *
183  * See AO_PROP_* bellow
184  */
185  int (*get_property) (xine_audio_port_t *, int property);
186  int (*set_property) (xine_audio_port_t *, int property, int value);
187 
188  /* open audio driver for audio output
189  * return value: 0:failure, >0:output sample rate
190  */
191  /* when you are not a full-blown stream, but still need to open the port
192  * (e.g. you are a post plugin) it is legal to pass an anonymous stream */
194  uint32_t bits, uint32_t rate, int mode);
195 
196  /*
197  * get a piece of memory for audio data
198  */
199  audio_buffer_t * (*get_buffer) (xine_audio_port_t *);
200 
201  /*
202  * append a buffer filled with audio data to the audio fifo
203  * for output
204  */
205  /* when the frame does not originate from a stream, it is legal to pass an anonymous stream */
207 
208  /* audio driver is no longer used by decoder => close */
209  /* when you are not a full-blown stream, but still need to close the port
210  * (e.g. you are a post plugin) it is legal to pass an anonymous stream */
211  void (*close) (xine_audio_port_t *self, xine_stream_t *stream);
212 
213  /* called on xine exit */
214  void (*exit) (xine_audio_port_t *);
215 
216  /*
217  * misc control operations on the audio device.
218  *
219  * See AO_CTRL_* below.
220  */
221  int (*control) (xine_audio_port_t *, int cmd, /* arg */ ...);
222 
223  /*
224  * Flush audio_out fifo.
225  */
227 
228  /*
229  * Check if port is opened for this stream and get parameters.
230  * The stream can be anonymous.
231  */
233  uint32_t *bits, uint32_t *rate, int *mode);
234 
235 };
236 
238 
240 
241  /*
242  * open a new instance of this plugin class
243  */
244  ao_driver_t* (*open_plugin) (audio_driver_class_t *, const void *data);
245 
249  const char *identifier;
250 
256  const char *description;
257 
261  const char *text_domain;
262 
263  /*
264  * free all class-related resources
265  */
266 
268 };
269 
270 #define default_audio_driver_class_dispose (void (*) (audio_driver_class_t *this_gen))free
271 
277 xine_audio_port_t *_x_ao_new_port (xine_t *xine, ao_driver_t *driver, int grab_only) XINE_MALLOC;
278 
279 /*
280  * audio output modes + capabilities
281  */
282 
283 #define AO_CAP_NOCAP 0x00000000 /* driver has no capabilities */
284 #define AO_CAP_MODE_A52 0x00000001 /* driver supports A/52 output */
285 #define AO_CAP_MODE_AC5 0x00000002 /* driver supports AC5 output */
286 /* 1 sample == 2 bytes (C) */
287 #define AO_CAP_MODE_MONO 0x00000004 /* driver supports mono output */
288 /* 1 sample == 4 bytes (L,R) */
289 #define AO_CAP_MODE_STEREO 0x00000008 /* driver supports stereo output */
290 /* 1 sample == 8 bytes (L,R,LR,RR) */
291 #define AO_CAP_MODE_4CHANNEL 0x00000010 /* driver supports 4 channels */
292 /*
293  * Sound cards generally support, 1,2,4,6 channels, but rarely 5.
294  * So xine will take 4.1, 5 and 6 channel a52 streams and
295  * down or upmix it correctly to fill the 6 output channels.
296  * Are there any requests for 2.1 out there?
297  */
298 /* 1 sample == 12 bytes (L,R,LR,RR,Null,LFE) */
299 #define AO_CAP_MODE_4_1CHANNEL 0x00000020 /* driver supports 4.1 channels */
300 /* 1 sample == 12 bytes (L,R,LR,RR,C, Null) */
301 #define AO_CAP_MODE_5CHANNEL 0x00000040 /* driver supports 5 channels */
302 /* 1 sample == 12 bytes (L,R,LR,RR,C,LFE) */
303 #define AO_CAP_MODE_5_1CHANNEL 0x00000080 /* driver supports 5.1 channels */
304 
305 /*
306  * converts the audio output mode into the number of channels
307  */
309 /*
310  * converts the number of channels into the audio output mode
311  */
312 int _x_ao_channels2mode( int channels ) XINE_PROTECTED;
313 
314 #define AO_CAP_MIXER_VOL 0x00000100 /* driver supports mixer control */
315 #define AO_CAP_PCM_VOL 0x00000200 /* driver supports pcm control */
316 #define AO_CAP_MUTE_VOL 0x00000400 /* driver can mute volume */
317 #define AO_CAP_8BITS 0x00000800 /* driver support 8-bit samples */
318 #define AO_CAP_16BITS 0x00001000 /* driver support 16-bit samples */
319 #define AO_CAP_24BITS 0x00002000 /* driver support 24-bit samples */
320 #define AO_CAP_FLOAT32 0x00004000 /* driver support 32-bit samples. i.e. Floats */
321 
322 /* properties supported by get/set_property() */
323 #define AO_PROP_MIXER_VOL 0
324 #define AO_PROP_PCM_VOL 1
325 #define AO_PROP_MUTE_VOL 2
326 #define AO_PROP_COMPRESSOR 3
327 #define AO_PROP_DISCARD_BUFFERS 4
328 #define AO_PROP_BUFS_IN_FIFO 5 /* read-only */
329 #define AO_PROP_AMP 6 /* amplifier */
330 #define AO_PROP_EQ_30HZ 7 /* equalizer */
331 #define AO_PROP_EQ_60HZ 8 /* equalizer */
332 #define AO_PROP_EQ_125HZ 9 /* equalizer */
333 #define AO_PROP_EQ_250HZ 10 /* equalizer */
334 #define AO_PROP_EQ_500HZ 11 /* equalizer */
335 #define AO_PROP_EQ_1000HZ 12 /* equalizer */
336 #define AO_PROP_EQ_2000HZ 13 /* equalizer */
337 #define AO_PROP_EQ_4000HZ 14 /* equalizer */
338 #define AO_PROP_EQ_8000HZ 15 /* equalizer */
339 #define AO_PROP_EQ_16000HZ 16 /* equalizer */
340 #define AO_PROP_CLOSE_DEVICE 17 /* force closing audio device */
341 #define AO_PROP_AMP_MUTE 18 /* amplifier mute */
342 #define AO_PROP_NUM_STREAMS 19 /* read-only */
343 #define AO_PROP_CLOCK_SPEED 20 /* inform audio_out that speed has changed */
344 #define AO_PROP_BUFS_TOTAL 21 /* read-only */
345 #define AO_PROP_BUFS_FREE 22 /* read-only */
346 #define AO_PROP_DRIVER_DELAY 23 /* read-only */
347 #define AO_NUM_PROPERTIES 24
348 
349 /* audio device control ops */
350 #define AO_CTRL_PLAY_PAUSE 0
351 #define AO_CTRL_PLAY_RESUME 1
352 #define AO_CTRL_FLUSH_BUFFERS 2
353 
354 /* above that value audio frames are discarded */
355 #define AO_MAX_GAP 15000
356 
357 #ifdef __cplusplus
358 }
359 #endif
360 
361 #endif
int(* control)(xine_audio_port_t *, int cmd,...)
Definition: audio_out.h:221
xine_stream_t * stream
Definition: audio_out.h:165
enable disable number of frames of telecine pattern sync required before mode change make frames evenly spaced for film mode(24 fps)" ) PARAM_ITEM( POST_PARAM_TYPE_BOOL
#define XINE_MALLOC
Definition: attributes.h:119
int _x_ao_channels2mode(int channels)
Definition: audio_out.c:737
int mem_size
Definition: audio_out.h:155
int(* open)(xine_audio_port_t *, xine_stream_t *stream, uint32_t bits, uint32_t rate, int mode)
Definition: audio_out.h:193
int16_t * mem
Definition: audio_out.h:154
const char * text_domain
Optional non-standard catalog to use with dgettext() for description.
Definition: audio_out.h:261
void(* close)(xine_audio_port_t *self, xine_stream_t *stream)
Definition: audio_out.h:211
int(* get_gap_tolerance)(ao_driver_t *self_gen)
Definition: audio_out.h:81
const char * description
human readable (verbose = 1 line) description for this plugin class
Definition: audio_out.h:256
int num_frames
Definition: audio_out.h:156
int(* get_property)(xine_audio_port_t *, int property)
Definition: audio_out.h:185
void(* close)(ao_driver_t *)
Definition: audio_out.h:97
uint32_t(* get_capabilities)(ao_driver_t *)
Definition: audio_out.h:54
Definition: plugin_catalog.h:44
extra_info_t * extra_info
Definition: audio_out.h:163
void(* dispose)(audio_driver_class_t *)
Definition: audio_out.h:267
void(* put_buffer)(xine_audio_port_t *, audio_buffer_t *buf, xine_stream_t *stream)
Definition: audio_out.h:206
uint32_t first_access_unit
Definition: audio_out.h:160
ao_format_t format
Definition: audio_out.h:167
uint32_t rate
Definition: audio_out.h:142
int mode
Definition: audio_out.h:143
Definition: xine_internal.h:210
int64_t vpts
Definition: audio_out.h:158
Definition: audio_out.h:150
int(* delay)(ao_driver_t *self_gen)
Definition: audio_out.h:76
Definition: audio_out.h:45
xine_audio_port_t * _x_ao_new_port(xine_t *xine, ao_driver_t *driver, int grab_only)
Initialise the audio_out sync routines.
Definition: audio_out.c:2286
Definition: audio_out.c:195
#define XINE_PROTECTED
Definition: attributes.h:73
int(* status)(xine_audio_port_t *, xine_stream_t *stream, uint32_t *bits, uint32_t *rate, int *mode)
Definition: audio_out.h:232
int(* write)(ao_driver_t *, int16_t *audio_data, uint32_t num_samples)
Definition: audio_out.h:90
uint32_t frame_header_count
Definition: audio_out.h:159
Definition: xine_internal.h:81
void(* exit)(ao_driver_t *)
Definition: audio_out.h:103
void(* exit)(xine_audio_port_t *)
Definition: audio_out.h:214
uint32_t bits
Definition: audio_out.h:141
int _x_ao_mode2channels(int mode)
Definition: audio_out.c:721
int(* open)(ao_driver_t *, uint32_t bits, uint32_t rate, int mode)
Definition: audio_out.h:62
uint32_t(* get_capabilities)(xine_audio_port_t *)
Definition: audio_out.h:179
plugin_node_t * node
Pointer to the loaded plugin node.
Definition: audio_out.h:132
int(* set_property)(ao_driver_t *, int property, int value)
Definition: audio_out.h:115
int(* num_channels)(ao_driver_t *self_gen)
Definition: audio_out.h:66
audio_buffer_t * next
Definition: audio_out.h:152
#define bits
int(* set_property)(xine_audio_port_t *, int property, int value)
Definition: audio_out.h:186
Definition: audio_out.h:239
const char * identifier
short human readable identifier for this plugin class
Definition: audio_out.h:249
Structure to pass information from input or demuxer plugins to output frames (past decoder)...
Definition: buffer.h:314
Definition: audio_out.h:178
Definition: audio_out.h:140
int(* get_property)(ao_driver_t *, int property)
Definition: audio_out.h:113
int(* bytes_per_frame)(ao_driver_t *self_gen)
Definition: audio_out.h:71
int(* control)(ao_driver_t *, int cmd,...)
Definition: audio_out.h:123
void(* flush)(xine_audio_port_t *)
Definition: audio_out.h:226