GNUnet 0.21.0
speaker.c
Go to the documentation of this file.
1/*
2 This file is part of GNUnet
3 Copyright (C) 2013 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your 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 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
28#include "platform.h"
29#include "gnunet_speaker_lib.h"
30#include "conversation.h"
31
32
36struct Speaker
37{
42
47};
48
49
56static int
57enable (void *cls)
58{
59 struct Speaker *spe = cls;
60 static char *playback_helper_argv[] = {
61 "gnunet-helper-audio-playback",
62 NULL
63 };
64
66 "gnunet-helper-audio-playback",
67 playback_helper_argv,
68 NULL,
69 NULL, spe);
70 if (NULL == spe->playback_helper)
71 {
73 _ ("Could not start playback audio helper.\n"));
74 return GNUNET_SYSERR;
75 }
76 return GNUNET_OK;
77}
78
79
85static void
86disable (void *cls)
87{
88 struct Speaker *spe = cls;
89
90 if (NULL == spe->playback_helper)
91 {
92 GNUNET_break (0);
93 return;
94 }
98 spe->playback_helper = NULL;
99}
100
101
107static void
108destroy (void *cls)
109{
110 struct Speaker *spe = cls;
111
112 if (NULL != spe->playback_helper)
113 disable (spe);
114}
115
116
125static void
126play (void *cls,
127 size_t data_size,
128 const void *data)
129{
130 struct Speaker *spe = cls;
131 char buf[sizeof(struct AudioMessage) + data_size];
132 struct AudioMessage *am;
133
134 if (NULL == spe->playback_helper)
135 {
136 GNUNET_break (0);
137 return;
138 }
139 am = (struct AudioMessage *) buf;
140 am->header.size = htons (sizeof(struct AudioMessage) + data_size);
142 GNUNET_memcpy (&am[1], data, data_size);
144 &am->header,
145 GNUNET_NO,
146 NULL, NULL);
147}
148
149
160{
162 struct Speaker *spe;
163
164 spe = GNUNET_new (struct Speaker);
165 spe->cfg = cfg;
167 speaker->cls = spe;
169 speaker->play = &play;
172 return speaker;
173}
174
175
181void
183{
186}
187
188
189/* end of speaker.c */
constants for network protocols
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:109
static struct GNUNET_SPEAKER_Handle * speaker
Handle to the speaker.
static char * data
The data to insert into the dht.
static size_t data_size
Number of bytes in data.
API to access an audio speaker; provides access to hardware speakers.
struct GNUNET_HELPER_Handle * GNUNET_HELPER_start(int with_control_pipe, const char *binary_name, char *const binary_argv[], GNUNET_MessageTokenizerCallback cb, GNUNET_HELPER_ExceptionCallback exp_cb, void *cb_cls)
Starts a helper and begins reading from it.
Definition: helper.c:460
struct GNUNET_HELPER_SendHandle * GNUNET_HELPER_send(struct GNUNET_HELPER_Handle *h, const struct GNUNET_MessageHeader *msg, int can_drop, GNUNET_HELPER_Continuation cont, void *cont_cls)
Send an message to the helper.
Definition: helper.c:613
enum GNUNET_GenericReturnValue GNUNET_HELPER_kill(struct GNUNET_HELPER_Handle *h, int soft_kill)
Sends termination signal to the helper process.
Definition: helper.c:166
void GNUNET_HELPER_destroy(struct GNUNET_HELPER_Handle *h)
Free's the resources occupied by the helper handle.
Definition: helper.c:499
#define GNUNET_log(kind,...)
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
@ GNUNET_OK
@ GNUNET_NO
@ GNUNET_SYSERR
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
@ GNUNET_ERROR_TYPE_ERROR
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
#define GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO
Message to transmit the audio between helper and speaker/microphone library.
struct GNUNET_SPEAKER_Handle * GNUNET_SPEAKER_create_from_hardware(const struct GNUNET_CONFIGURATION_Handle *cfg)
Create a speaker that corresponds to the speaker hardware of our system.
Definition: speaker.c:158
void GNUNET_SPEAKER_destroy(struct GNUNET_SPEAKER_Handle *speaker)
Destroy a speaker.
Definition: speaker.c:182
#define _(String)
GNU gettext support macro.
Definition: platform.h:178
static void disable(void *cls)
Function that disables a speaker.
Definition: speaker.c:86
static int enable(void *cls)
Function that enables a speaker.
Definition: speaker.c:57
static void destroy(void *cls)
Function to destroy a speaker.
Definition: speaker.c:108
static void play(void *cls, size_t data_size, const void *data)
Function to cause a speaker to play audio data.
Definition: speaker.c:126
Message to transmit the audio (between client and helpers).
Definition: conversation.h:59
struct GNUNET_MessageHeader header
Type is GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO.
Definition: conversation.h:63
The handle to a helper process.
Definition: helper.c:77
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
A speaker is a device that can play or record audio data.
GNUNET_SPEAKER_DestroyCallback destroy_speaker
Destroy the speaker.
void * cls
Closure for the callbacks.
GNUNET_SPEAKER_PlayCallback play
Play audio.
GNUNET_SPEAKER_EnableCallback enable_speaker
Turn on the speaker.
GNUNET_SPEAKER_DisableCallback disable_speaker
Turn the speaker off.
Internal data structures for the speaker.
Definition: speaker.c:37
const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: speaker.c:41
struct GNUNET_HELPER_Handle * playback_helper
Handle for the playback helper.
Definition: speaker.c:46