1 #ifndef foopulsesinkinputhfoo
2 #define foopulsesinkinputhfoo
7 This file is part of PulseAudio.
9 Copyright 2004-2006 Lennart Poettering
10 Copyright 2006 Pierre Ossman <ossman@cendio.se> for Cendio AB
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.
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.
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
30 typedef struct pa_sink_input pa_sink_input
;
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>
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
;
49 static inline int 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
;
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_flags_t
;
59 struct pa_sink_input
{
65 /* Please note that this state should only be read with
66 * pa_sink_input_get_state(). That function will transparently
67 * merge the thread_info.drained value in. */
68 pa_sink_input_state_t state
;
69 pa_sink_input_flags_t flags
;
71 char *name
, *driver
; /* may be NULL */
72 pa_module
*module
; /* may be NULL */
73 pa_client
*client
; /* may be NULL */
77 pa_sample_spec sample_spec
;
78 pa_channel_map channel_map
;
80 pa_sink_input
*sync_prev
, *sync_next
;
85 /* Returns the chunk of audio data (but doesn't drop it
86 * yet!). Returns -1 on failure. Called from IO thread context. */
87 int (*peek
) (pa_sink_input
*i
, pa_memchunk
*chunk
);
89 /* Drops the specified number of bytes, usually called right after
90 * peek(), but not necessarily. Called from IO thread context. */
91 void (*drop
) (pa_sink_input
*i
, size_t length
);
93 /* If non-NULL this function is called when the input is first
94 * connected to a sink. Called from IO thread context */
95 void (*attach
) (pa_sink_input
*i
); /* may be NULL */
97 /* If non-NULL this function is called when the output is
98 * disconnected from its sink. Called from IO thread context */
99 void (*detach
) (pa_sink_input
*i
); /* may be NULL */
101 /* If non-NULL called whenever the the sink this input is attached
102 * to suspends or resumes. Called from main context */
103 void (*suspend
) (pa_sink_input
*i
, int b
); /* may be NULL */
105 /* Supposed to unlink and destroy this stream. Called from main
107 void (*kill
) (pa_sink_input
*i
); /* may be NULL */
109 /* Return the current latency (i.e. length of bufferd audio) of
110 this stream. Called from main context. If NULL a
111 PA_SINK_INPUT_MESSAGE_GET_LATENCY message is sent to the IO thread
113 pa_usec_t (*get_latency
) (pa_sink_input
*i
); /* may be NULL */
115 pa_resample_method_t resample_method
;
118 pa_sink_input_state_t state
;
121 pa_sample_spec sample_spec
;
123 pa_memchunk resampled_chunk
;
124 pa_resampler
*resampler
; /* may be NULL */
126 /* Some silence to play before the actual data. This is used to
127 * compensate for latency differences when moving a sink input
128 * "hot" between sinks. */
130 pa_memblock
*silence_memblock
; /* may be NULL */
132 pa_sink_input
*sync_prev
, *sync_next
;
141 PA_DECLARE_CLASS(pa_sink_input
);
142 #define PA_SINK_INPUT(o) pa_sink_input_cast(o)
145 PA_SINK_INPUT_MESSAGE_SET_VOLUME
,
146 PA_SINK_INPUT_MESSAGE_SET_MUTE
,
147 PA_SINK_INPUT_MESSAGE_GET_LATENCY
,
148 PA_SINK_INPUT_MESSAGE_SET_RATE
,
149 PA_SINK_INPUT_MESSAGE_SET_STATE
,
150 PA_SINK_INPUT_MESSAGE_MAX
153 typedef struct pa_sink_input_new_data
{
154 const char *name
, *driver
;
160 pa_sample_spec sample_spec
;
161 int sample_spec_is_set
;
162 pa_channel_map channel_map
;
163 int channel_map_is_set
;
170 pa_resample_method_t resample_method
;
172 pa_sink_input
*sync_base
;
173 } pa_sink_input_new_data
;
175 pa_sink_input_new_data
* pa_sink_input_new_data_init(pa_sink_input_new_data
*data
);
176 void pa_sink_input_new_data_set_sample_spec(pa_sink_input_new_data
*data
, const pa_sample_spec
*spec
);
177 void pa_sink_input_new_data_set_channel_map(pa_sink_input_new_data
*data
, const pa_channel_map
*map
);
178 void pa_sink_input_new_data_set_volume(pa_sink_input_new_data
*data
, const pa_cvolume
*volume
);
179 void pa_sink_input_new_data_set_muted(pa_sink_input_new_data
*data
, int mute
);
181 /* To be called by the implementing module only */
183 pa_sink_input
* pa_sink_input_new(
185 pa_sink_input_new_data
*data
,
186 pa_sink_input_flags_t flags
);
188 void pa_sink_input_put(pa_sink_input
*i
);
189 void pa_sink_input_unlink(pa_sink_input
* i
);
191 void pa_sink_input_set_name(pa_sink_input
*i
, const char *name
);
193 /* Callable by everyone */
195 /* External code may request disconnection with this function */
196 void pa_sink_input_kill(pa_sink_input
*i
);
198 pa_usec_t
pa_sink_input_get_latency(pa_sink_input
*i
);
200 void pa_sink_input_set_volume(pa_sink_input
*i
, const pa_cvolume
*volume
);
201 const pa_cvolume
*pa_sink_input_get_volume(pa_sink_input
*i
);
202 void pa_sink_input_set_mute(pa_sink_input
*i
, int mute
);
203 int pa_sink_input_get_mute(pa_sink_input
*i
);
205 void pa_sink_input_cork(pa_sink_input
*i
, int b
);
207 int pa_sink_input_set_rate(pa_sink_input
*i
, uint32_t rate
);
209 pa_resample_method_t
pa_sink_input_get_resample_method(pa_sink_input
*i
);
211 int pa_sink_input_move_to(pa_sink_input
*i
, pa_sink
*dest
, int immediately
);
213 pa_sink_input_state_t
pa_sink_input_get_state(pa_sink_input
*i
);
215 /* To be used exclusively by the sink driver thread */
217 int pa_sink_input_peek(pa_sink_input
*i
, pa_memchunk
*chunk
, pa_cvolume
*volume
);
218 void pa_sink_input_drop(pa_sink_input
*i
, size_t length
);
219 int pa_sink_input_process_msg(pa_msgobject
*o
, int code
, void *userdata
, int64_t offset
, pa_memchunk
*chunk
);
221 typedef struct pa_sink_input_move_info
{
222 pa_sink_input
*sink_input
;
223 pa_sink_input
*ghost_sink_input
;
224 pa_memblockq
*buffer
;
226 } pa_sink_input_move_info
;