]> code.delx.au - pulseaudio/blob - polyp/polyplib-scache.c
Make the whole stuff LGPL only
[pulseaudio] / polyp / polyplib-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 "polyplib-scache.h"
32 #include "polyplib-internal.h"
33 #include "pstream-util.h"
34
35 void pa_stream_connect_upload(struct pa_stream *s, size_t length) {
36 struct pa_tagstruct *t;
37 uint32_t tag;
38
39 assert(s && length);
40
41 pa_stream_ref(s);
42
43 s->state = PA_STREAM_CREATING;
44 s->direction = PA_STREAM_UPLOAD;
45
46 t = pa_tagstruct_new(NULL, 0);
47 pa_tagstruct_putu32(t, PA_COMMAND_CREATE_UPLOAD_STREAM);
48 pa_tagstruct_putu32(t, tag = s->context->ctag++);
49 pa_tagstruct_puts(t, s->name);
50 pa_tagstruct_put_sample_spec(t, &s->sample_spec);
51 pa_tagstruct_putu32(t, length);
52 pa_pstream_send_tagstruct(s->context->pstream, t);
53 pa_pdispatch_register_reply(s->context->pdispatch, tag, DEFAULT_TIMEOUT, pa_create_stream_callback, s);
54
55 pa_stream_unref(s);
56 }
57
58 void pa_stream_finish_upload(struct pa_stream *s) {
59 struct pa_tagstruct *t;
60 uint32_t tag;
61 assert(s);
62
63 if (!s->channel_valid || !s->context->state == PA_CONTEXT_READY)
64 return;
65
66 pa_stream_ref(s);
67
68 t = pa_tagstruct_new(NULL, 0);
69 assert(t);
70
71 pa_tagstruct_putu32(t, PA_COMMAND_FINISH_UPLOAD_STREAM);
72 pa_tagstruct_putu32(t, tag = s->context->ctag++);
73 pa_tagstruct_putu32(t, s->channel);
74 pa_pstream_send_tagstruct(s->context->pstream, t);
75 pa_pdispatch_register_reply(s->context->pdispatch, tag, DEFAULT_TIMEOUT, pa_stream_disconnect_callback, s);
76
77 pa_stream_unref(s);
78 }
79
80 struct pa_operation * pa_context_play_sample(struct pa_context *c, const char *name, const char *dev, uint32_t volume, void (*cb)(struct pa_context *c, int success, void *userdata), void *userdata) {
81 struct pa_operation *o;
82 struct pa_tagstruct *t;
83 uint32_t tag;
84 assert(c && name && *name && (!dev || *dev));
85
86 o = pa_operation_new(c, NULL);
87 o->callback = cb;
88 o->userdata = userdata;
89
90 if (!dev)
91 dev = c->conf->default_sink;
92
93 t = pa_tagstruct_new(NULL, 0);
94 assert(t);
95 pa_tagstruct_putu32(t, PA_COMMAND_PLAY_SAMPLE);
96 pa_tagstruct_putu32(t, tag = c->ctag++);
97 pa_tagstruct_putu32(t, (uint32_t) -1);
98 pa_tagstruct_puts(t, dev);
99 pa_tagstruct_putu32(t, volume);
100 pa_tagstruct_puts(t, name);
101 pa_pstream_send_tagstruct(c->pstream, t);
102 pa_pdispatch_register_reply(c->pdispatch, tag, DEFAULT_TIMEOUT, pa_context_simple_ack_callback, o);
103
104 return pa_operation_ref(o);
105 }
106
107 struct pa_operation* pa_context_remove_sample(struct pa_context *c, const char *name, void (*cb)(struct pa_context *c, int success, void *userdata), void *userdata) {
108 struct pa_operation *o;
109 struct pa_tagstruct *t;
110 uint32_t tag;
111 assert(c && name);
112
113 o = pa_operation_new(c, NULL);
114 o->callback = cb;
115 o->userdata = userdata;
116
117 t = pa_tagstruct_new(NULL, 0);
118 assert(t);
119 pa_tagstruct_putu32(t, PA_COMMAND_REMOVE_SAMPLE);
120 pa_tagstruct_putu32(t, tag = c->ctag++);
121 pa_tagstruct_puts(t, name);
122 pa_pstream_send_tagstruct(c->pstream, t);
123 pa_pdispatch_register_reply(c->pdispatch, tag, DEFAULT_TIMEOUT, pa_context_simple_ack_callback, o);
124
125 return pa_operation_ref(o);
126 }
127