dfad5f56a531ed195d560f06461179c973545fd6
[oweals/gnunet.git] / src / include / gnunet_microphone_lib.h
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
19 /**
20  * @author Simon Dieterle
21  * @author Andreas Fuchs
22  * @author Christian Grothoff
23  *
24  * @file
25  * API to access an audio microphone; provides access to hardware microphones
26  *
27  * @defgroup microphone  Microphone library
28  * Provides access to hardware microphones.
29  * @{
30  */
31 #ifndef GNUNET_MICROPHONE_SERVICE_H
32 #define GNUNET_MICROPHONE_SERVICE_H
33
34 #ifdef __cplusplus
35 extern "C"
36 {
37 #if 0                           /* keep Emacsens' auto-indent happy */
38 }
39 #endif
40 #endif
41
42 #include "gnunet_util_lib.h"
43
44 /**
45  * Process recorded audio data.
46  *
47  * @param cls clsoure
48  * @param data_size number of bytes in @a data
49  * @param data audio data to play
50  */
51 typedef void (*GNUNET_MICROPHONE_RecordedDataCallback)(void *cls,
52                                                        size_t data_size,
53                                                        const void *data);
54
55 /**
56  * Enable a microphone.
57  *
58  * @param cls clsoure
59  * @param rdc function to call with recorded data
60  * @param rdc_cls closure for @a dc
61  * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
62  */
63 typedef int (*GNUNET_MICROPHONE_EnableCallback)(void *cls,
64                                                 GNUNET_MICROPHONE_RecordedDataCallback rdc,
65                                                 void *rdc_cls);
66
67 /**
68  * Function that disables a microphone.
69  *
70  * @param cls clsoure
71  */
72 typedef void (*GNUNET_MICROPHONE_DisableCallback)(void *cls);
73
74 /**
75  * Function to destroy a microphone.
76  *
77  * @param cls clsoure
78  */
79 typedef void (*GNUNET_MICROPHONE_DestroyCallback)(void *cls);
80
81
82 /**
83  * A microphone is a device that can capture or otherwise produce audio data.
84  */
85 struct GNUNET_MICROPHONE_Handle
86 {
87
88   /**
89    * Turn on the microphone.
90    */
91   GNUNET_MICROPHONE_EnableCallback enable_microphone;
92
93   /**
94    * Turn the microphone off.
95    */
96   GNUNET_MICROPHONE_DisableCallback disable_microphone;
97
98   /**
99    * Destroy the microphone.  Called by #GNUNET_MICROPHONE_destroy.
100    */
101   GNUNET_MICROPHONE_DestroyCallback destroy_microphone;
102
103   /**
104    * Closure for the callbacks.
105    */
106   void *cls;
107
108 };
109
110
111 /**
112  * Create a microphone that corresponds to the microphone hardware
113  * of our system.
114  *
115  * @param cfg configuration to use
116  * @return NULL on error
117  */
118 struct GNUNET_MICROPHONE_Handle *
119 GNUNET_MICROPHONE_create_from_hardware (const struct GNUNET_CONFIGURATION_Handle *cfg);
120
121
122 /**
123  * Destroy a microphone.
124  *
125  * @param microphone microphone to destroy
126  */
127 void
128 GNUNET_MICROPHONE_destroy (struct GNUNET_MICROPHONE_Handle *microphone);
129
130
131 #if 0                           /* keep Emacsens' auto-indent happy */
132 {
133 #endif
134 #ifdef __cplusplus
135 }
136 #endif
137
138 #endif
139
140 /** @} */  /* end of group */
141
142 /* end of gnunet_microphone_lib.h */