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