]> code.delx.au - pulseaudio/blob - src/pulse/scache.c
Huge trailing whitespace cleanup. Let's keep the tree pure from here on,
[pulseaudio] / src / pulse / scache.c
1 /* $Id$ */
2
3 /***
4 This file is part of PulseAudio.
5
6 PulseAudio 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 PulseAudio 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 PulseAudio; 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 <pulsecore/pstream-util.h>
32
33 #include "internal.h"
34
35 #include "scache.h"
36
37 int pa_stream_connect_upload(pa_stream *s, size_t length) {
38 pa_tagstruct *t;
39 uint32_t tag;
40
41 assert(s);
42
43 PA_CHECK_VALIDITY(s->context, s->state == PA_STREAM_UNCONNECTED, PA_ERR_BADSTATE);
44 PA_CHECK_VALIDITY(s->context, length > 0, PA_ERR_INVALID);
45
46 pa_stream_ref(s);
47
48 s->direction = PA_STREAM_UPLOAD;
49
50 t = pa_tagstruct_command(s->context, PA_COMMAND_CREATE_UPLOAD_STREAM, &tag);
51 pa_tagstruct_puts(t, s->name);
52 pa_tagstruct_put_sample_spec(t, &s->sample_spec);
53 pa_tagstruct_put_channel_map(t, &s->channel_map);
54 pa_tagstruct_putu32(t, length);
55 pa_pstream_send_tagstruct(s->context->pstream, t);
56 pa_pdispatch_register_reply(s->context->pdispatch, tag, DEFAULT_TIMEOUT, pa_create_stream_callback, s, NULL);
57
58 pa_stream_set_state(s, PA_STREAM_CREATING);
59
60 pa_stream_unref(s);
61 return 0;
62 }
63
64 int pa_stream_finish_upload(pa_stream *s) {
65 pa_tagstruct *t;
66 uint32_t tag;
67 assert(s);
68
69 PA_CHECK_VALIDITY(s->context, s->channel_valid, PA_ERR_BADSTATE);
70 PA_CHECK_VALIDITY(s->context, s->context->state == PA_CONTEXT_READY, PA_ERR_BADSTATE);
71
72 pa_stream_ref(s);
73
74 t = pa_tagstruct_command(s->context, PA_COMMAND_FINISH_UPLOAD_STREAM, &tag);
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, NULL);
78
79 pa_stream_unref(s);
80 return 0;
81 }
82
83 pa_operation *pa_context_play_sample(pa_context *c, const char *name, const char *dev, pa_volume_t volume, pa_context_success_cb_t cb, void *userdata) {
84 pa_operation *o;
85 pa_tagstruct *t;
86 uint32_t tag;
87
88 assert(c);
89 assert(c->ref >= 1);
90
91 PA_CHECK_VALIDITY_RETURN_NULL(c, c->state == PA_CONTEXT_READY, PA_ERR_BADSTATE);
92 PA_CHECK_VALIDITY_RETURN_NULL(c, name && *name, PA_ERR_INVALID);
93 PA_CHECK_VALIDITY_RETURN_NULL(c, !dev || *dev, PA_ERR_INVALID);
94
95 o = pa_operation_new(c, NULL, (pa_operation_cb_t) cb, userdata);
96
97 if (!dev)
98 dev = c->conf->default_sink;
99
100 t = pa_tagstruct_command(c, PA_COMMAND_PLAY_SAMPLE, &tag);
101 pa_tagstruct_putu32(t, PA_INVALID_INDEX);
102 pa_tagstruct_puts(t, dev);
103 pa_tagstruct_putu32(t, volume);
104 pa_tagstruct_puts(t, name);
105 pa_pstream_send_tagstruct(c->pstream, t);
106 pa_pdispatch_register_reply(c->pdispatch, tag, DEFAULT_TIMEOUT, pa_context_simple_ack_callback, pa_operation_ref(o), (pa_free_cb_t) pa_operation_unref);
107
108 return o;
109 }
110
111 pa_operation* pa_context_remove_sample(pa_context *c, const char *name, pa_context_success_cb_t cb, void *userdata) {
112 pa_operation *o;
113 pa_tagstruct *t;
114 uint32_t tag;
115
116 assert(c);
117 assert(c->ref >= 1);
118
119 PA_CHECK_VALIDITY_RETURN_NULL(c, c->state == PA_CONTEXT_READY, PA_ERR_BADSTATE);
120 PA_CHECK_VALIDITY_RETURN_NULL(c, name && *name, PA_ERR_INVALID);
121
122 o = pa_operation_new(c, NULL, (pa_operation_cb_t) cb, userdata);
123
124 t = pa_tagstruct_command(c, PA_COMMAND_REMOVE_SAMPLE, &tag);
125 pa_tagstruct_puts(t, name);
126 pa_pstream_send_tagstruct(c->pstream, t);
127 pa_pdispatch_register_reply(c->pdispatch, tag, DEFAULT_TIMEOUT, pa_context_simple_ack_callback, pa_operation_ref(o), (pa_free_cb_t) pa_operation_unref);
128
129 return o;
130 }
131