aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2013-10-02 19:48:12 +0000
committerChristian Grothoff <christian@grothoff.org>2013-10-02 19:48:12 +0000
commite4d1ce975f6bbb5c89904ad9c174f1e29b49a76b (patch)
tree70d3e98b1386acc4c218c973b44d62691fd49f1f /src
parente4eafbbef9d494182ca863f7ee03095a235bdf71 (diff)
downloadgnunet-e4d1ce975f6bbb5c89904ad9c174f1e29b49a76b.tar.gz
gnunet-e4d1ce975f6bbb5c89904ad9c174f1e29b49a76b.zip
-implement speaker library
Diffstat (limited to 'src')
-rw-r--r--src/conversation/Makefile.am10
-rw-r--r--src/conversation/microphone.c3
-rw-r--r--src/conversation/speaker.c190
-rw-r--r--src/include/gnunet_speaker_lib.h10
4 files changed, 208 insertions, 5 deletions
diff --git a/src/conversation/Makefile.am b/src/conversation/Makefile.am
index ac2f47612..10fd26014 100644
--- a/src/conversation/Makefile.am
+++ b/src/conversation/Makefile.am
@@ -16,6 +16,7 @@ AM_CPPFLAGS = \
16 16
17lib_LTLIBRARIES = \ 17lib_LTLIBRARIES = \
18 libgnunetmicrophone.la \ 18 libgnunetmicrophone.la \
19 libgnunetspeaker.la \
19 libgnunetconversation.la 20 libgnunetconversation.la
20 21
21pkgcfgdir= $(prefix)/share/gnunet/config.d/ 22pkgcfgdir= $(prefix)/share/gnunet/config.d/
@@ -30,12 +31,21 @@ libgnunetmicrophone_la_LDFLAGS = \
30 $(GNUNET_LDFLAGS) $(WINFLAGS) \ 31 $(GNUNET_LDFLAGS) $(WINFLAGS) \
31 -version-info 0:0:0 32 -version-info 0:0:0
32 33
34libgnunetspeaker_la_SOURCES = \
35 speaker.c
36libgnunetspeaker_la_LIBADD = \
37 -lgnunetutil
38libgnunetspeaker_la_LDFLAGS = \
39 $(GNUNET_LDFLAGS) $(WINFLAGS) \
40 -version-info 0:0:0
41
33 42
34libgnunetconversation_la_SOURCES = \ 43libgnunetconversation_la_SOURCES = \
35 conversation_api.c \ 44 conversation_api.c \
36 conversation_api2.c 45 conversation_api2.c
37libgnunetconversation_la_LIBADD = \ 46libgnunetconversation_la_LIBADD = \
38 libgnunetmicrophone.la \ 47 libgnunetmicrophone.la \
48 libgnunetspeaker.la \
39 $(top_builddir)/src/gns/libgnunetgns.la \ 49 $(top_builddir)/src/gns/libgnunetgns.la \
40 $(top_builddir)/src/namestore/libgnunetnamestore.la \ 50 $(top_builddir)/src/namestore/libgnunetnamestore.la \
41 $(top_builddir)/src/util/libgnunetutil.la 51 $(top_builddir)/src/util/libgnunetutil.la
diff --git a/src/conversation/microphone.c b/src/conversation/microphone.c
index 8e9b9e241..53ac5cb86 100644
--- a/src/conversation/microphone.c
+++ b/src/conversation/microphone.c
@@ -101,11 +101,12 @@ enable (void *cls,
101 void *rdc_cls) 101 void *rdc_cls)
102{ 102{
103 struct Microphone *mic = cls; 103 struct Microphone *mic = cls;
104 char * const record_helper_argv[] = 104 static char * const record_helper_argv[] =
105 { 105 {
106 "gnunet-helper-audio-record", 106 "gnunet-helper-audio-record",
107 NULL 107 NULL
108 }; 108 };
109
109 mic->rdc = rdc; 110 mic->rdc = rdc;
110 mic->rdc_cls = rdc_cls; 111 mic->rdc_cls = rdc_cls;
111 mic->record_helper = GNUNET_HELPER_start (GNUNET_NO, 112 mic->record_helper = GNUNET_HELPER_start (GNUNET_NO,
diff --git a/src/conversation/speaker.c b/src/conversation/speaker.c
new file mode 100644
index 000000000..255b79ee3
--- /dev/null
+++ b/src/conversation/speaker.c
@@ -0,0 +1,190 @@
1/*
2 This file is part of GNUnet
3 (C) 2013 Christian Grothoff (and other contributing authors)
4
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19 */
20
21/**
22 * @file conversation/speaker.c
23 * @brief API to access an audio speaker; provides access to hardware speakers
24 * @author Simon Dieterle
25 * @author Andreas Fuchs
26 * @author Christian Grothoff
27 */
28#include "platform.h"
29#include "gnunet_speaker_lib.h"
30#include "conversation.h"
31
32
33/**
34 * Internal data structures for the speaker.
35 */
36struct Speaker
37{
38 /**
39 * Our configuration.
40 */
41 const struct GNUNET_CONFIGURATION_Handle *cfg;
42
43 /**
44 * Handle for the playback helper
45 */
46 struct GNUNET_HELPER_Handle *playback_helper;
47
48};
49
50
51/**
52 * Function that enables a speaker.
53 *
54 * @param cls closure with the `struct Speaker`
55 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
56 */
57static int
58enable (void *cls)
59{
60 struct Speaker *spe = cls;
61 static char *playback_helper_argv[] =
62 {
63 "gnunet-helper-audio-playback",
64 NULL
65 };
66
67 spe->playback_helper = GNUNET_HELPER_start (GNUNET_NO,
68 "gnunet-helper-audio-playback",
69 playback_helper_argv,
70 NULL,
71 NULL, spe);
72 if (NULL == spe->playback_helper)
73 {
74 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
75 _("Could not start playback audio helper.\n"));
76 return GNUNET_SYSERR;
77 }
78 return GNUNET_OK;
79}
80
81
82/**
83 * Function that disables a speaker.
84 *
85 * @param cls closure with the `struct Speaker`
86 */
87static void
88disable (void *cls)
89{
90 struct Speaker *spe = cls;
91
92 if (NULL == spe->playback_helper)
93 {
94 GNUNET_break (0);
95 return;
96 }
97 GNUNET_break (GNUNET_OK ==
98 GNUNET_HELPER_kill (spe->playback_helper, GNUNET_NO));
99 GNUNET_HELPER_destroy (spe->playback_helper);
100 spe->playback_helper = NULL;
101}
102
103
104/**
105 * Function to destroy a speaker.
106 *
107 * @param cls closure with the `struct Speaker`
108 */
109static void
110destroy (void *cls)
111{
112 struct Speaker *spe = cls;
113
114 if (NULL != spe->playback_helper)
115 disable (spe);
116}
117
118
119/**
120 * Function to cause a speaker to play audio data.
121 *
122 * @param cls clsoure with the `struct Speaker`
123 * @param data_size number of bytes in @a data
124 * @param data audio data to play, format is
125 * opaque to the API but should be OPUS.
126 */
127static void
128play (void *cls,
129 size_t data_size,
130 const void *data)
131{
132 struct Speaker *spe = cls;
133 const struct AudioMessage *am;
134
135 if (NULL == spe->playback_helper)
136 {
137 GNUNET_break (0);
138 return;
139 }
140 if (sizeof (struct AudioMessage) != data_size)
141 {
142 GNUNET_break (0);
143 return;
144 }
145 am = (const struct AudioMessage *) data;
146 (void) GNUNET_HELPER_send (spe->playback_helper,
147 &am->header,
148 GNUNET_YES,
149 NULL, NULL);
150}
151
152
153/**
154 * Create a speaker that corresponds to the speaker hardware
155 * of our system.
156 *
157 * @param cfg configuration to use
158 * @return NULL on error
159 */
160struct GNUNET_SPEAKER_Handle *
161GNUNET_SPEAKER_create_from_hardware (const struct GNUNET_CONFIGURATION_Handle *cfg)
162{
163 struct GNUNET_SPEAKER_Handle *speaker;
164 struct Speaker *spe;
165
166 spe = GNUNET_new (struct Speaker);
167 spe->cfg = cfg;
168 speaker = GNUNET_new (struct GNUNET_SPEAKER_Handle);
169 speaker->cls = spe;
170 speaker->enable_speaker = &enable;
171 speaker->play = &play;
172 speaker->disable_speaker = &disable;
173 speaker->destroy_speaker = &destroy;
174 return speaker;
175}
176
177
178/**
179 * Destroy a speaker.
180 *
181 * @param speaker speaker to destroy
182 */
183void
184GNUNET_SPEAKER_destroy (struct GNUNET_SPEAKER_Handle *speaker)
185{
186 speaker->destroy_speaker (speaker->cls);
187 GNUNET_free (speaker);
188}
189
190/* end of speaker.c */
diff --git a/src/include/gnunet_speaker_lib.h b/src/include/gnunet_speaker_lib.h
index 7a6eb028b..bdb91d6a1 100644
--- a/src/include/gnunet_speaker_lib.h
+++ b/src/include/gnunet_speaker_lib.h
@@ -36,10 +36,12 @@ extern "C"
36#endif 36#endif
37#endif 37#endif
38 38
39#include "gnunet_util_lib.h"
40
39/** 41/**
40 * Function that enables a speaker. 42 * Function that enables a speaker.
41 * 43 *
42 * @param cls clsoure 44 * @param cls closure
43 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 45 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
44 */ 46 */
45typedef int (*GNUNET_SPEAKER_EnableCallback)(void *cls); 47typedef int (*GNUNET_SPEAKER_EnableCallback)(void *cls);
@@ -47,21 +49,21 @@ typedef int (*GNUNET_SPEAKER_EnableCallback)(void *cls);
47/** 49/**
48 * Function that disables a speaker. 50 * Function that disables a speaker.
49 * 51 *
50 * @param cls clsoure 52 * @param cls closure
51 */ 53 */
52typedef void (*GNUNET_SPEAKER_DisableCallback)(void *cls); 54typedef void (*GNUNET_SPEAKER_DisableCallback)(void *cls);
53 55
54/** 56/**
55 * Function to destroy a speaker. 57 * Function to destroy a speaker.
56 * 58 *
57 * @param cls clsoure 59 * @param cls closure
58 */ 60 */
59typedef void (*GNUNET_SPEAKER_DestroyCallback)(void *cls); 61typedef void (*GNUNET_SPEAKER_DestroyCallback)(void *cls);
60 62
61/** 63/**
62 * Function to cause a speaker to play audio data. 64 * Function to cause a speaker to play audio data.
63 * 65 *
64 * @param cls clsoure 66 * @param cls closure
65 * @param data_size number of bytes in @a data 67 * @param data_size number of bytes in @a data
66 * @param data audio data to play, format is 68 * @param data audio data to play, format is
67 * opaque to the API but should be OPUS. 69 * opaque to the API but should be OPUS.