]> code.delx.au - pulseaudio/blob - src/pulsecore/sink-input.h
use single array for storing pa_core hook lists, add sink state changed hook, drop...
[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_DRAINED, /*< The stream stopped playing because there was no data to play */
43 PA_SINK_INPUT_RUNNING, /*< The stream is alive and kicking */
44 PA_SINK_INPUT_CORKED, /*< The stream was corked on user request */
45 PA_SINK_INPUT_DISCONNECTED /*< The stream is dead */
46 } pa_sink_input_state_t;
47
48 typedef enum pa_sink_input_flags {
49 PA_SINK_INPUT_VARIABLE_RATE = 1,
50 } pa_sink_input_flags_t;
51
52 struct pa_sink_input {
53 pa_msgobject parent;
54
55 uint32_t index;
56 pa_core *core;
57
58 /* Please note that this state should only be read with
59 * pa_sink_input_get_state(). That function will transparently
60 * merge the thread_info.drained value in. */
61 pa_sink_input_state_t state;
62 pa_sink_input_flags_t flags;
63
64 char *name, *driver; /* may be NULL */
65 pa_module *module; /* may be NULL */
66 pa_client *client; /* may be NULL */
67
68 pa_sink *sink;
69
70 pa_sample_spec sample_spec;
71 pa_channel_map channel_map;
72
73 pa_sink_input *sync_prev, *sync_next;
74
75 pa_cvolume volume;
76 int muted;
77
78 int (*peek) (pa_sink_input *i, pa_memchunk *chunk);
79 void (*drop) (pa_sink_input *i, size_t length);
80 void (*kill) (pa_sink_input *i); /* may be NULL */
81 pa_usec_t (*get_latency) (pa_sink_input *i); /* may be NULL */
82 void (*underrun) (pa_sink_input *i); /* may be NULL */
83
84 pa_resample_method_t resample_method;
85
86 struct {
87 pa_sink_input_state_t state;
88 pa_atomic_t drained;
89
90 pa_sample_spec sample_spec;
91
92 pa_memchunk resampled_chunk;
93 pa_resampler *resampler; /* may be NULL */
94
95 /* Some silence to play before the actual data. This is used to
96 * compensate for latency differences when moving a sink input
97 * "hot" between sinks. */
98 /* size_t move_silence; */
99 pa_memblock *silence_memblock; /* may be NULL */
100
101 pa_sink_input *sync_prev, *sync_next;
102
103 pa_cvolume volume;
104 int muted;
105 } thread_info;
106
107 void *userdata;
108 };
109
110 PA_DECLARE_CLASS(pa_sink_input);
111 #define PA_SINK_INPUT(o) pa_sink_input_cast(o)
112
113 enum {
114 PA_SINK_INPUT_MESSAGE_SET_VOLUME,
115 PA_SINK_INPUT_MESSAGE_SET_MUTE,
116 PA_SINK_INPUT_MESSAGE_GET_LATENCY,
117 PA_SINK_INPUT_MESSAGE_SET_RATE,
118 PA_SINK_INPUT_MESSAGE_SET_STATE,
119 PA_SINK_INPUT_MESSAGE_MAX
120 };
121
122 typedef struct pa_sink_input_new_data {
123 const char *name, *driver;
124 pa_module *module;
125 pa_client *client;
126
127 pa_sink *sink;
128
129 pa_sample_spec sample_spec;
130 int sample_spec_is_set;
131 pa_channel_map channel_map;
132 int channel_map_is_set;
133
134 pa_cvolume volume;
135 int volume_is_set;
136 int muted;
137 int muted_is_set;
138
139 pa_resample_method_t resample_method;
140
141 int start_corked;
142 pa_sink_input *sync_base;
143 } pa_sink_input_new_data;
144
145 pa_sink_input_new_data* pa_sink_input_new_data_init(pa_sink_input_new_data *data);
146 void pa_sink_input_new_data_set_sample_spec(pa_sink_input_new_data *data, const pa_sample_spec *spec);
147 void pa_sink_input_new_data_set_channel_map(pa_sink_input_new_data *data, const pa_channel_map *map);
148 void pa_sink_input_new_data_set_volume(pa_sink_input_new_data *data, const pa_cvolume *volume);
149 void pa_sink_input_new_data_set_muted(pa_sink_input_new_data *data, int mute);
150
151 /* To be called by the implementing module only */
152
153 pa_sink_input* pa_sink_input_new(
154 pa_core *core,
155 pa_sink_input_new_data *data,
156 pa_sink_input_flags_t flags);
157
158 void pa_sink_input_put(pa_sink_input *i);
159 void pa_sink_input_disconnect(pa_sink_input* i);
160
161 void pa_sink_input_set_name(pa_sink_input *i, const char *name);
162
163 /* Callable by everyone */
164
165 /* External code may request disconnection with this function */
166 void pa_sink_input_kill(pa_sink_input*i);
167
168 pa_usec_t pa_sink_input_get_latency(pa_sink_input *i);
169
170 void pa_sink_input_set_volume(pa_sink_input *i, const pa_cvolume *volume);
171 const pa_cvolume *pa_sink_input_get_volume(pa_sink_input *i);
172 void pa_sink_input_set_mute(pa_sink_input *i, int mute);
173 int pa_sink_input_get_mute(pa_sink_input *i);
174
175 void pa_sink_input_cork(pa_sink_input *i, int b);
176
177 int pa_sink_input_set_rate(pa_sink_input *i, uint32_t rate);
178
179 pa_resample_method_t pa_sink_input_get_resample_method(pa_sink_input *i);
180
181 int pa_sink_input_move_to(pa_sink_input *i, pa_sink *dest, int immediately);
182
183 pa_sink_input_state_t pa_sink_input_get_state(pa_sink_input *i);
184
185 /* To be used exclusively by the sink driver thread */
186
187 int pa_sink_input_peek(pa_sink_input *i, pa_memchunk *chunk, pa_cvolume *volume);
188 void pa_sink_input_drop(pa_sink_input *i, size_t length);
189 int pa_sink_input_process_msg(pa_msgobject *o, int code, void *userdata, int64_t offset, pa_memchunk *chunk);
190
191 #endif