GNUnet 0.22.2
microphone.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
29#include "platform.h"
30
32#include "conversation.h"
33
34
39{
44
49
54
58 void *rdc_cls;
59};
60
61
71static int
73 const struct GNUNET_MessageHeader *msg)
74{
75 struct Microphone *mic = cls;
76 const struct AudioMessage *am;
77
79 {
80 GNUNET_break (0);
81 return GNUNET_SYSERR;
82 }
83 am = (const struct AudioMessage *) msg;
84 mic->rdc (mic->rdc_cls,
85 ntohs (msg->size) - sizeof(struct AudioMessage),
86 &am[1]);
87 return GNUNET_OK;
88}
89
90
98static int
99enable (void *cls,
101 void *rdc_cls)
102{
103 struct Microphone *mic = cls;
104 static char *const record_helper_argv[] = {
105 (char*) "gnunet-helper-audio-record",
106 NULL
107 };
108
109 mic->rdc = rdc;
110 mic->rdc_cls = rdc_cls;
112 GNUNET_NO,
113 "gnunet-helper-audio-record",
114 record_helper_argv,
116 NULL, mic);
117 if (NULL == mic->record_helper)
118 {
120 _ ("Could not start record audio helper\n"));
121 return GNUNET_SYSERR;
122 }
123 return GNUNET_OK;
124}
125
126
132static void
133disable (void *cls)
134{
135 struct Microphone *mic = cls;
136
137 if (NULL == mic->record_helper)
138 {
139 GNUNET_break (0);
140 return;
141 }
143 GNUNET_HELPER_kill (mic->record_helper, GNUNET_NO));
144 GNUNET_HELPER_destroy (mic->record_helper);
145 mic->record_helper = NULL;
146}
147
148
154static void
155destroy (void *cls)
156{
157 struct Microphone *mic = cls;
158
159 if (NULL != mic->record_helper)
160 disable (mic);
161}
162
163
174{
176 struct Microphone *mic;
177
178 mic = GNUNET_new (struct Microphone);
179 mic->cfg = cfg;
181 microphone->cls = mic;
185 return microphone;
186}
187
188
194void
196{
199}
200
201
202/* end of microphone.c */
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
constants for network protocols
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:108
static struct GNUNET_MICROPHONE_Handle * microphone
Handle to the microphone.
static struct GNUNET_MICROPHONE_Handle * mic
Our microphone.
API to access an audio microphone; provides access to hardware microphones.
struct GNUNET_HELPER_Handle * GNUNET_HELPER_start(const struct GNUNET_OS_ProjectData *pd, 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
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:501
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
#define GNUNET_log(kind,...)
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
@ 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.
void GNUNET_MICROPHONE_destroy(struct GNUNET_MICROPHONE_Handle *microphone)
Destroy a microphone.
Definition: microphone.c:195
struct GNUNET_MICROPHONE_Handle * GNUNET_MICROPHONE_create_from_hardware(const struct GNUNET_CONFIGURATION_Handle *cfg)
Create a microphone that corresponds to the microphone hardware of our system.
Definition: microphone.c:172
void(* GNUNET_MICROPHONE_RecordedDataCallback)(void *cls, size_t data_size, const void *data)
Process recorded audio data.
const struct GNUNET_OS_ProjectData * GNUNET_OS_project_data_gnunet(void)
Return default project data used by 'libgnunetutil' for GNUnet.
#define GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO
Message to transmit the audio between helper and speaker/microphone library.
static int process_record_messages(void *cls, const struct GNUNET_MessageHeader *msg)
Function to process the audio from the record helper.
Definition: microphone.c:72
static void disable(void *cls)
Function that disables a microphone.
Definition: microphone.c:133
static int enable(void *cls, GNUNET_MICROPHONE_RecordedDataCallback rdc, void *rdc_cls)
Enable a microphone.
Definition: microphone.c:99
static void destroy(void *cls)
Function to destroy a microphone.
Definition: microphone.c:155
#define _(String)
GNU gettext support macro.
Definition: platform.h:179
Message to transmit the audio (between client and helpers).
Definition: conversation.h:59
The handle to a helper process.
Definition: helper.c:77
A microphone is a device that can capture or otherwise produce audio data.
void * cls
Closure for the callbacks.
GNUNET_MICROPHONE_DisableCallback disable_microphone
Turn the microphone off.
GNUNET_MICROPHONE_DestroyCallback destroy_microphone
Destroy the microphone.
GNUNET_MICROPHONE_EnableCallback enable_microphone
Turn on the microphone.
Header for all communications.
Internal data structures for the microphone.
Definition: microphone.c:39
struct GNUNET_HELPER_Handle * record_helper
Handle for the record helper.
Definition: microphone.c:48
void * rdc_cls
Closure for rdc.
Definition: microphone.c:58
const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: microphone.c:43
GNUNET_MICROPHONE_RecordedDataCallback rdc
Function to call with audio data (if we are enabled).
Definition: microphone.c:53