fix bad free
[oweals/gnunet.git] / src / include / gnunet_speaker_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 speaker; provides access to hardware speakers
26  *
27  * @defgroup speaker  Speaker service
28  * Access hardware audio speakers.
29  * @{
30  */
31 #ifndef GNUNET_SPEAKER_SERVICE_H
32 #define GNUNET_SPEAKER_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  * Function that enables a speaker.
46  *
47  * @param cls closure
48  * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
49  */
50 typedef int (*GNUNET_SPEAKER_EnableCallback)(void *cls);
51
52 /**
53  * Function that disables a speaker.
54  *
55  * @param cls closure
56  */
57 typedef void (*GNUNET_SPEAKER_DisableCallback)(void *cls);
58
59 /**
60  * Function to destroy a speaker.
61  *
62  * @param cls closure
63  */
64 typedef void (*GNUNET_SPEAKER_DestroyCallback)(void *cls);
65
66 /**
67  * Function to cause a speaker to play audio data.
68  *
69  * @param cls closure
70  * @param data_size number of bytes in @a data
71  * @param data audio data to play, format is
72  *        opaque to the API but should be OPUS.
73  */
74 typedef void (*GNUNET_SPEAKER_PlayCallback)(void *cls,
75                                             size_t data_size,
76                                             const void *data);
77
78
79 /**
80  * A speaker is a device that can play or record audio data.
81  */
82 struct GNUNET_SPEAKER_Handle
83 {
84
85   /**
86    * Turn on the speaker.
87    */
88   GNUNET_SPEAKER_EnableCallback enable_speaker;
89
90   /**
91    * Play audio.
92    */
93   GNUNET_SPEAKER_PlayCallback play;
94
95   /**
96    * Turn the speaker off.
97    */
98   GNUNET_SPEAKER_DisableCallback disable_speaker;
99
100   /**
101    * Destroy the speaker.  Called by #GNUNET_SPEAKER_destroy.
102    */
103   GNUNET_SPEAKER_DestroyCallback destroy_speaker;
104
105   /**
106    * Closure for the callbacks.
107    */
108   void *cls;
109
110 };
111
112
113 /**
114  * Create a speaker that corresponds to the speaker hardware
115  * of our system.
116  *
117  * @param cfg configuration to use
118  * @return NULL on error
119  */
120 struct GNUNET_SPEAKER_Handle *
121 GNUNET_SPEAKER_create_from_hardware (const struct GNUNET_CONFIGURATION_Handle *cfg);
122
123
124 /**
125  * Destroy a speaker.
126  *
127  * @param speaker speaker to destroy
128  */
129 void
130 GNUNET_SPEAKER_destroy (struct GNUNET_SPEAKER_Handle *speaker);
131
132
133 #if 0                           /* keep Emacsens' auto-indent happy */
134 {
135 #endif
136 #ifdef __cplusplus
137 }
138 #endif
139
140 #endif
141
142 /** @} */ /* end of group */
143
144 /* end of gnunet_speaker_lib.h */