]> code.delx.au - pulseaudio/blob - src/polyp/scache.c
Cleaned up the includes after the restructuring. Indicate which headers are
[pulseaudio] / src / polyp / scache.c
1 /* $Id$ */
2
3 /***
4 This file is part of polypaudio.
5
6 polypaudio is free software; you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as published
8 by the Free Software Foundation; either version 2 of the License,
9 or (at your option) any later version.
10
11 polypaudio is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public License
17 along with polypaudio; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19 USA.
20 ***/
21
22 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
25
26 #include <assert.h>
27 #include <stdlib.h>
28 #include <stdio.h>
29 #include <string.h>
30
31 #include <polypcore/pstream-util.h>
32
33 #include "internal.h"
34
35 #include "scache.h"
36
37 void pa_stream_connect_upload(pa_stream *s, size_t length) {
38 pa_tagstruct *t;
39 uint32_t tag;
40
41 assert(s && length);
42
43 pa_stream_ref(s);
44
45 s->state = PA_STREAM_CREATING;
46 s->direction = PA_STREAM_UPLOAD;
47
48 t = pa_tagstruct_new(NULL, 0);
49 pa_tagstruct_putu32(t, PA_COMMAND_CREATE_UPLOAD_STREAM);
50 pa_tagstruct_putu32(t, tag = s->context->ctag++);
51 pa_tagstruct_puts(t, s->name);
52 pa_tagstruct_put_sample_spec(t, &s->sample_spec);
53 pa_tagstruct_putu32(t, length);
54 pa_pstream_send_tagstruct(s->context->pstream, t);
55 pa_pdispatch_register_reply(s->context->pdispatch, tag, DEFAULT_TIMEOUT, pa_create_stream_callback, s);
56
57 pa_stream_unref(s);
58 }
59
60 void pa_stream_finish_upload(pa_stream *s) {
61 pa_tagstruct *t;
62 uint32_t tag;
63 assert(s);
64
65 if (!s->channel_valid || !s->context->state == PA_CONTEXT_READY)
66 return;
67
68 pa_stream_ref(s);
69
70 t = pa_tagstruct_new(NULL, 0);
71 assert(t);
72
73 pa_tagstruct_putu32(t, PA_COMMAND_FINISH_UPLOAD_STREAM);
74 pa_tagstruct_putu32(t, tag = s->context->ctag++);
75 pa_tagstruct_putu32(t, s->channel);
76 pa_pstream_send_tagstruct(s->context->pstream, t);
77 pa_pdispatch_register_reply(s->context->pdispatch, tag, DEFAULT_TIMEOUT, pa_stream_disconnect_callback, s);
78
79 pa_stream_unref(s);
80 }
81
82 pa_operation * pa_context_play_sample(pa_context *c, const char *name, const char *dev, uint32_t volume, void (*cb)(pa_context *c, int success, void *userdata), void *userdata) {
83 pa_operation *o;
84 pa_tagstruct *t;
85 uint32_t tag;
86 assert(c && name && *name && (!dev || *dev));
87
88 o = pa_operation_new(c, NULL);
89 o->callback = (pa_operation_callback) cb;
90 o->userdata = userdata;
91
92 if (!dev)
93 dev = c->conf->default_sink;
94
95 t = pa_tagstruct_new(NULL, 0);
96 assert(t);
97 pa_tagstruct_putu32(t, PA_COMMAND_PLAY_SAMPLE);
98 pa_tagstruct_putu32(t, tag = c->ctag++);
99 pa_tagstruct_putu32(t, (uint32_t) -1);
100 pa_tagstruct_puts(t, dev);
101 pa_tagstruct_putu32(t, volume);
102 pa_tagstruct_puts(t, name);
103 pa_pstream_send_tagstruct(c->pstream, t);
104 pa_pdispatch_register_reply(c->pdispatch, tag, DEFAULT_TIMEOUT, pa_context_simple_ack_callback, o);
105
106 return pa_operation_ref(o);
107 }
108
109 pa_operation* pa_context_remove_sample(pa_context *c, const char *name, void (*cb)(pa_context *c, int success, void *userdata), void *userdata) {
110 pa_operation *o;
111 pa_tagstruct *t;
112 uint32_t tag;
113 assert(c && name);
114
115 o = pa_operation_new(c, NULL);
116 o->callback = (pa_operation_callback) cb;
117 o->userdata = userdata;
118
119 t = pa_tagstruct_new(NULL, 0);
120 assert(t);
121 pa_tagstruct_putu32(t, PA_COMMAND_REMOVE_SAMPLE);
122 pa_tagstruct_putu32(t, tag = c->ctag++);
123 pa_tagstruct_puts(t, name);
124 pa_pstream_send_tagstruct(c->pstream, t);
125 pa_pdispatch_register_reply(c->pdispatch, tag, DEFAULT_TIMEOUT, pa_context_simple_ack_callback, o);
126
127 return pa_operation_ref(o);
128 }
129