* implement "hot" moving of playback streams between sinks (pa_sink_input_move_to()).
[platform/upstream/pulseaudio.git] / src / pulsecore / sink-input.h
1 #ifndef foosinkinputhfoo
2 #define foosinkinputhfoo
3
4 /* $Id$ */
5
6 /***
7   This file is part of PulseAudio.
8  
9   PulseAudio is free software; you can redistribute it and/or modify
10   it under the terms of the GNU Lesser General Public License as published
11   by the Free Software Foundation; either version 2 of the License,
12   or (at your option) any later version.
13  
14   PulseAudio is distributed in the hope that it will be useful, but
15   WITHOUT ANY WARRANTY; without even the implied warranty of
16   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17   General Public License for more details.
18  
19   You should have received a copy of the GNU Lesser General Public License
20   along with PulseAudio; if not, write to the Free Software
21   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
22   USA.
23 ***/
24
25 #include <inttypes.h>
26
27 typedef struct pa_sink_input pa_sink_input;
28
29 #include <pulse/sample.h>
30 #include <pulsecore/sink.h>
31 #include <pulsecore/memblockq.h>
32 #include <pulsecore/resampler.h>
33 #include <pulsecore/module.h>
34 #include <pulsecore/client.h>
35
36 typedef enum pa_sink_input_state {
37     PA_SINK_INPUT_RUNNING,      /*< The stream is alive and kicking */
38     PA_SINK_INPUT_DRAINED,      /*< The stream stopped playing because there was no data to play */
39     PA_SINK_INPUT_CORKED,       /*< The stream was corked on user request */
40     PA_SINK_INPUT_DISCONNECTED  /*< The stream is dead */
41 } pa_sink_input_state_t;
42
43 struct pa_sink_input {
44     int ref;
45     uint32_t index;
46     pa_sink_input_state_t state;
47     
48     char *name, *driver;
49     pa_module *owner;
50
51     pa_sink *sink;
52     pa_client *client;
53     
54     pa_sample_spec sample_spec;
55     pa_channel_map channel_map;
56
57     pa_cvolume volume;
58
59     /* Some silence to play before the actual data. This is used to
60      * compensate for latency differences when moving a sink input
61      * "hot" between sinks. */
62     size_t move_silence;
63     
64     int (*peek) (pa_sink_input *i, pa_memchunk *chunk);
65     void (*drop) (pa_sink_input *i, const pa_memchunk *chunk, size_t length);
66     void (*kill) (pa_sink_input *i);
67     pa_usec_t (*get_latency) (pa_sink_input *i);
68     void (*underrun) (pa_sink_input *i);
69
70     void *userdata;
71
72     pa_memchunk resampled_chunk;
73     pa_resampler *resampler;
74
75     int variable_rate;
76     pa_resample_method_t resample_method;
77
78     pa_memblock *silence_memblock;
79 };
80
81 pa_sink_input* pa_sink_input_new(
82     pa_sink *s,
83     const char *driver,
84     const char *name,
85     const pa_sample_spec *spec,
86     const pa_channel_map *map,
87     const pa_cvolume *volume,
88     int variable_rate,
89     pa_resample_method_t resample_method);
90
91 void pa_sink_input_unref(pa_sink_input* i);
92 pa_sink_input* pa_sink_input_ref(pa_sink_input* i);
93
94 /* To be called by the implementing module only */
95 void pa_sink_input_disconnect(pa_sink_input* i);
96
97 /* External code may request disconnection with this funcion */
98 void pa_sink_input_kill(pa_sink_input*i);
99
100 pa_usec_t pa_sink_input_get_latency(pa_sink_input *i);
101
102 int pa_sink_input_peek(pa_sink_input *i, pa_memchunk *chunk, pa_cvolume *volume);
103 void pa_sink_input_drop(pa_sink_input *i, const pa_memchunk *chunk, size_t length);
104
105 void pa_sink_input_set_volume(pa_sink_input *i, const pa_cvolume *volume);
106 const pa_cvolume * pa_sink_input_get_volume(pa_sink_input *i);
107
108 void pa_sink_input_cork(pa_sink_input *i, int b);
109
110 void pa_sink_input_set_rate(pa_sink_input *i, uint32_t rate);
111
112 void pa_sink_input_set_name(pa_sink_input *i, const char *name);
113
114 pa_resample_method_t pa_sink_input_get_resample_method(pa_sink_input *i);
115
116 int pa_sink_input_move_to(pa_sink_input *i, pa_sink *dest, int immediately);
117
118 #endif