]> code.delx.au - pulseaudio/blob - src/pulsecore/sink-input.h
- Check process name when dealing with PID files
[pulseaudio] / src / pulsecore / sink-input.h
1 #ifndef foopulsesinkinputhfoo
2 #define foopulsesinkinputhfoo
3
4 /* $Id$ */
5
6 /***
7 This file is part of PulseAudio.
8
9 Copyright 2004-2006 Lennart Poettering
10 Copyright 2006 Pierre Ossman <ossman@cendio.se> for Cendio AB
11
12 PulseAudio is free software; you can redistribute it and/or modify
13 it under the terms of the GNU Lesser General Public License as published
14 by the Free Software Foundation; either version 2 of the License,
15 or (at your option) any later version.
16
17 PulseAudio is distributed in the hope that it will be useful, but
18 WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 General Public License for more details.
21
22 You should have received a copy of the GNU Lesser General Public License
23 along with PulseAudio; if not, write to the Free Software
24 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
25 USA.
26 ***/
27
28 #include <inttypes.h>
29
30 typedef struct pa_sink_input pa_sink_input;
31
32 #include <pulse/sample.h>
33 #include <pulsecore/hook-list.h>
34 #include <pulsecore/memblockq.h>
35 #include <pulsecore/resampler.h>
36 #include <pulsecore/module.h>
37 #include <pulsecore/client.h>
38 #include <pulsecore/sink.h>
39 #include <pulsecore/core.h>
40
41 typedef enum pa_sink_input_state {
42 PA_SINK_INPUT_INIT, /*< The stream is not active yet, because pa_sink_put() has not been called yet */
43 PA_SINK_INPUT_DRAINED, /*< The stream stopped playing because there was no data to play */
44 PA_SINK_INPUT_RUNNING, /*< The stream is alive and kicking */
45 PA_SINK_INPUT_CORKED, /*< The stream was corked on user request */
46 PA_SINK_INPUT_UNLINKED /*< The stream is dead */
47 } pa_sink_input_state_t;
48
49 static inline pa_bool_t PA_SINK_INPUT_LINKED(pa_sink_input_state_t x) {
50 return x == PA_SINK_INPUT_DRAINED || x == PA_SINK_INPUT_RUNNING || x == PA_SINK_INPUT_CORKED;
51 }
52
53 typedef enum pa_sink_input_flags {
54 PA_SINK_INPUT_VARIABLE_RATE = 1,
55 PA_SINK_INPUT_DONT_MOVE = 2,
56 PA_SINK_INPUT_START_CORKED = 4,
57 PA_SINK_INPUT_NO_REMAP = 8,
58 PA_SINK_INPUT_NO_REMIX = 16,
59 PA_SINK_INPUT_FIX_FORMAT = 32,
60 PA_SINK_INPUT_FIX_RATE = 64,
61 PA_SINK_INPUT_FIX_CHANNELS = 128
62 } pa_sink_input_flags_t;
63
64 struct pa_sink_input {
65 pa_msgobject parent;
66
67 uint32_t index;
68 pa_core *core;
69
70 /* Please note that this state should only be read with
71 * pa_sink_input_get_state(). That function will transparently
72 * merge the thread_info.drained value in. */
73 pa_sink_input_state_t state;
74 pa_sink_input_flags_t flags;
75
76 char *name, *driver; /* may be NULL */
77 pa_module *module; /* may be NULL */
78 pa_client *client; /* may be NULL */
79
80 pa_sink *sink;
81
82 pa_sample_spec sample_spec;
83 pa_channel_map channel_map;
84
85 pa_sink_input *sync_prev, *sync_next;
86
87 pa_cvolume volume;
88 pa_bool_t muted;
89
90 /* Returns the chunk of audio data (but doesn't drop it
91 * yet!). Returns -1 on failure. Called from IO thread context. If
92 * data needs to be generated from scratch then please in the
93 * specified length. This is an optimization only. If less data is
94 * available, it's fine to return a smaller block. If more data is
95 * already ready, it is better to return the full block.*/
96 int (*peek) (pa_sink_input *i, size_t length, pa_memchunk *chunk);
97
98 /* Drops the specified number of bytes, usually called right after
99 * peek(), but not necessarily. Called from IO thread context. */
100 void (*drop) (pa_sink_input *i, size_t length);
101
102 /* If non-NULL this function is called when the input is first
103 * connected to a sink or when the rtpoll/asyncmsgq fields
104 * change. You usually don't need to implement this function
105 * unless you rewrite a sink that is piggy-backed onto
106 * another. Called from IO thread context */
107 void (*attach) (pa_sink_input *i); /* may be NULL */
108
109 /* If non-NULL this function is called when the output is
110 * disconnected from its sink. Called from IO thread context */
111 void (*detach) (pa_sink_input *i); /* may be NULL */
112
113 /* If non-NULL called whenever the the sink this input is attached
114 * to suspends or resumes. Called from main context */
115 void (*suspend) (pa_sink_input *i, pa_bool_t b); /* may be NULL */
116
117 /* If non-NULL called whenever the the sink this input is attached
118 * to changes. Called from main context */
119 void (*moved) (pa_sink_input *i); /* may be NULL */
120
121 /* Supposed to unlink and destroy this stream. Called from main
122 * context. */
123 void (*kill) (pa_sink_input *i); /* may be NULL */
124
125 /* Return the current latency (i.e. length of bufferd audio) of
126 this stream. Called from main context. If NULL a
127 PA_SINK_INPUT_MESSAGE_GET_LATENCY message is sent to the IO thread
128 instead. */
129 pa_usec_t (*get_latency) (pa_sink_input *i); /* may be NULL */
130
131 pa_resample_method_t resample_method;
132
133 struct {
134 pa_sink_input_state_t state;
135 pa_atomic_t drained;
136
137 pa_bool_t attached; /* True only between ->attach() and ->detach() calls */
138
139 pa_sample_spec sample_spec;
140
141 pa_memchunk resampled_chunk;
142 pa_resampler *resampler; /* may be NULL */
143
144 /* Some silence to play before the actual data. This is used to
145 * compensate for latency differences when moving a sink input
146 * "hot" between sinks. */
147 size_t move_silence;
148 pa_memblock *silence_memblock; /* may be NULL */
149
150 pa_sink_input *sync_prev, *sync_next;
151
152 pa_cvolume volume;
153 pa_bool_t muted;
154 } thread_info;
155
156 void *userdata;
157 };
158
159 PA_DECLARE_CLASS(pa_sink_input);
160 #define PA_SINK_INPUT(o) pa_sink_input_cast(o)
161
162 enum {
163 PA_SINK_INPUT_MESSAGE_SET_VOLUME,
164 PA_SINK_INPUT_MESSAGE_SET_MUTE,
165 PA_SINK_INPUT_MESSAGE_GET_LATENCY,
166 PA_SINK_INPUT_MESSAGE_SET_RATE,
167 PA_SINK_INPUT_MESSAGE_SET_STATE,
168 PA_SINK_INPUT_MESSAGE_MAX
169 };
170
171 typedef struct pa_sink_input_new_data {
172 const char *name, *driver;
173 pa_module *module;
174 pa_client *client;
175
176 pa_sink *sink;
177
178 pa_sample_spec sample_spec;
179 pa_bool_t sample_spec_is_set;
180 pa_channel_map channel_map;
181 pa_bool_t channel_map_is_set;
182
183 pa_cvolume volume;
184 pa_bool_t volume_is_set;
185 pa_bool_t muted;
186 pa_bool_t muted_is_set;
187
188 pa_resample_method_t resample_method;
189
190 pa_sink_input *sync_base;
191 } pa_sink_input_new_data;
192
193 typedef struct pa_sink_input_move_hook_data {
194 pa_sink_input *sink_input;
195 pa_sink *destination;
196 } pa_sink_input_move_hook_data;
197
198 pa_sink_input_new_data* pa_sink_input_new_data_init(pa_sink_input_new_data *data);
199 void pa_sink_input_new_data_set_sample_spec(pa_sink_input_new_data *data, const pa_sample_spec *spec);
200 void pa_sink_input_new_data_set_channel_map(pa_sink_input_new_data *data, const pa_channel_map *map);
201 void pa_sink_input_new_data_set_volume(pa_sink_input_new_data *data, const pa_cvolume *volume);
202 void pa_sink_input_new_data_set_muted(pa_sink_input_new_data *data, pa_bool_t mute);
203
204 /* To be called by the implementing module only */
205
206 pa_sink_input* pa_sink_input_new(
207 pa_core *core,
208 pa_sink_input_new_data *data,
209 pa_sink_input_flags_t flags);
210
211 void pa_sink_input_put(pa_sink_input *i);
212 void pa_sink_input_unlink(pa_sink_input* i);
213
214 void pa_sink_input_set_name(pa_sink_input *i, const char *name);
215
216 /* Callable by everyone */
217
218 /* External code may request disconnection with this function */
219 void pa_sink_input_kill(pa_sink_input*i);
220
221 pa_usec_t pa_sink_input_get_latency(pa_sink_input *i);
222
223 void pa_sink_input_set_volume(pa_sink_input *i, const pa_cvolume *volume);
224 const pa_cvolume *pa_sink_input_get_volume(pa_sink_input *i);
225 void pa_sink_input_set_mute(pa_sink_input *i, pa_bool_t mute);
226 int pa_sink_input_get_mute(pa_sink_input *i);
227
228 void pa_sink_input_cork(pa_sink_input *i, pa_bool_t b);
229
230 int pa_sink_input_set_rate(pa_sink_input *i, uint32_t rate);
231
232 pa_resample_method_t pa_sink_input_get_resample_method(pa_sink_input *i);
233
234 int pa_sink_input_move_to(pa_sink_input *i, pa_sink *dest, int immediately);
235
236 pa_sink_input_state_t pa_sink_input_get_state(pa_sink_input *i);
237
238 /* To be used exclusively by the sink driver thread */
239
240 int pa_sink_input_peek(pa_sink_input *i, size_t length, pa_memchunk *chunk, pa_cvolume *volume);
241 void pa_sink_input_drop(pa_sink_input *i, size_t length);
242 int pa_sink_input_process_msg(pa_msgobject *o, int code, void *userdata, int64_t offset, pa_memchunk *chunk);
243
244 typedef struct pa_sink_input_move_info {
245 pa_sink_input *sink_input;
246 pa_sink_input *ghost_sink_input;
247 pa_memblockq *buffer;
248 size_t buffer_bytes;
249 } pa_sink_input_move_info;
250
251 #endif