]> code.delx.au - pulseaudio/blob - src/modules/dbus/iface-stream.c
dbus: Three entangled changes:
[pulseaudio] / src / modules / dbus / iface-stream.c
1 /***
2 This file is part of PulseAudio.
3
4 Copyright 2009 Tanu Kaskinen
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.1 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 <pulsecore/core-util.h>
27 #include <pulsecore/protocol-dbus.h>
28
29 #include "iface-stream.h"
30
31 #define PLAYBACK_OBJECT_NAME "playback_stream"
32 #define RECORD_OBJECT_NAME "record_stream"
33
34 enum stream_type {
35 STREAM_TYPE_PLAYBACK,
36 STREAM_TYPE_RECORD
37 };
38
39 struct pa_dbusiface_stream {
40 union {
41 pa_sink_input *sink_input;
42 pa_source_output *source_output;
43 };
44 enum stream_type type;
45 char *path;
46 };
47
48 pa_dbusiface_stream *pa_dbusiface_stream_new_playback(pa_dbusiface_core *core, pa_sink_input *sink_input) {
49 pa_dbusiface_stream *s;
50
51 pa_assert(core);
52 pa_assert(sink_input);
53
54 s = pa_xnew(pa_dbusiface_stream, 1);
55 s->sink_input = pa_sink_input_ref(sink_input);
56 s->type = STREAM_TYPE_PLAYBACK;
57 s->path = pa_sprintf_malloc("%s/%s%u", PA_DBUS_CORE_OBJECT_PATH, PLAYBACK_OBJECT_NAME, sink_input->index);
58
59 return s;
60 }
61
62 pa_dbusiface_stream *pa_dbusiface_stream_new_record(pa_dbusiface_core *core, pa_source_output *source_output) {
63 pa_dbusiface_stream *s;
64
65 pa_assert(core);
66 pa_assert(source_output);
67
68 s = pa_xnew(pa_dbusiface_stream, 1);
69 s->source_output = pa_source_output_ref(source_output);
70 s->type = STREAM_TYPE_RECORD;
71 s->path = pa_sprintf_malloc("%s/%s%u", PA_DBUS_CORE_OBJECT_PATH, RECORD_OBJECT_NAME, source_output->index);
72
73 return s;
74 }
75
76 void pa_dbusiface_stream_free(pa_dbusiface_stream *s) {
77 pa_assert(s);
78
79 if (s->type == STREAM_TYPE_PLAYBACK)
80 pa_sink_input_unref(s->sink_input);
81 else
82 pa_source_output_unref(s->source_output);
83
84 pa_xfree(s->path);
85 pa_xfree(s);
86 }
87
88 const char *pa_dbusiface_stream_get_path(pa_dbusiface_stream *s) {
89 pa_assert(s);
90
91 return s->path;
92 }