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