aboutsummaryrefslogtreecommitdiff
path: root/src/conversation/gnunet-helper-audio-record.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2013-10-02 19:29:22 +0000
committerChristian Grothoff <christian@grothoff.org>2013-10-02 19:29:22 +0000
commit0834bf4d6fdf19ab410c01c02e65fcda8a5e5ebc (patch)
tree2410199dfb90c0ef4d12fc749f30f88e9bfda9b8 /src/conversation/gnunet-helper-audio-record.c
parentec9740ca2ca84525842e6743b45ceb9cb2a3ea95 (diff)
downloadgnunet-0834bf4d6fdf19ab410c01c02e65fcda8a5e5ebc.tar.gz
gnunet-0834bf4d6fdf19ab410c01c02e65fcda8a5e5ebc.zip
-implement microphone library
Diffstat (limited to 'src/conversation/gnunet-helper-audio-record.c')
-rw-r--r--src/conversation/gnunet-helper-audio-record.c110
1 files changed, 53 insertions, 57 deletions
diff --git a/src/conversation/gnunet-helper-audio-record.c b/src/conversation/gnunet-helper-audio-record.c
index a6b97278b..5d4c0399a 100644
--- a/src/conversation/gnunet-helper-audio-record.c
+++ b/src/conversation/gnunet-helper-audio-record.c
@@ -38,9 +38,10 @@
38#include <opus/opus.h> 38#include <opus/opus.h>
39#include <opus/opus_types.h> 39#include <opus/opus_types.h>
40 40
41
41/** 42/**
42* Specification for recording. May change in the future to spec negotiation. 43 * Specification for recording. May change in the future to spec negotiation.
43*/ 44 */
44static pa_sample_spec sample_spec = { 45static pa_sample_spec sample_spec = {
45 .format = PA_SAMPLE_FLOAT32LE, 46 .format = PA_SAMPLE_FLOAT32LE,
46 .rate = 48000, 47 .rate = 48000,
@@ -48,90 +49,89 @@ static pa_sample_spec sample_spec = {
48}; 49};
49 50
50/** 51/**
51* Pulseaudio mainloop api 52 * Pulseaudio mainloop api
52*/ 53 */
53static pa_mainloop_api *mainloop_api = NULL; 54static pa_mainloop_api *mainloop_api;
54 55
55/** 56/**
56* Pulseaudio mainloop 57 * Pulseaudio mainloop
57*/ 58 */
58static pa_mainloop *m = NULL; 59static pa_mainloop *m;
59 60
60/** 61/**
61* Pulseaudio context 62 * Pulseaudio context
62*/ 63 */
63static pa_context *context = NULL; 64static pa_context *context;
64 65
65/** 66/**
66* Pulseaudio recording stream 67 * Pulseaudio recording stream
67*/ 68 */
68static pa_stream *stream_in = NULL; 69static pa_stream *stream_in;
69 70
70/** 71/**
71* Pulseaudio io events 72 * Pulseaudio io events
72*/ 73 */
73static pa_io_event *stdio_event = NULL; 74static pa_io_event *stdio_event;
74 75
75/** 76/**
76* Message tokenizer 77 * Message tokenizer
77*/ 78 */
78struct MessageStreamTokenizer *stdin_mst; 79static struct MessageStreamTokenizer *stdin_mst;
79 80
80/** 81/**
81* OPUS encoder 82 * OPUS encoder
82*/ 83 */
83OpusEncoder *enc = NULL; 84static OpusEncoder *enc;
84 85
85/** 86/**
86* 87 *
87*/ 88 */
88unsigned char *opus_data; 89static unsigned char *opus_data;
89 90
90/** 91/**
91* PCM data buffer for one OPUS frame 92 * PCM data buffer for one OPUS frame
92*/ 93 */
93float *pcm_buffer; 94static float *pcm_buffer;
94 95
95/** 96/**
96 * Length of the pcm data needed for one OPUS frame 97 * Length of the pcm data needed for one OPUS frame
97 */ 98 */
98int pcm_length; 99static int pcm_length;
99 100
100/** 101/**
101* Number of samples for one frame 102 * Number of samples for one frame
102*/ 103 */
103int frame_size; 104static int frame_size;
104 105
105/** 106/**
106* Maximum length of opus payload 107* Maximum length of opus payload
107*/ 108*/
108int max_payload_bytes = 1500; 109static int max_payload_bytes = 1500;
109 110
110/** 111/**
111* Audio buffer 112 * Audio buffer
112*/ 113 */
113static void *transmit_buffer = NULL; 114static void *transmit_buffer;
114 115
115/** 116/**
116* Length of audio buffer 117 * Length of audio buffer
117*/ 118 */
118static size_t transmit_buffer_length = 0; 119static size_t transmit_buffer_length;
119 120
120/** 121/**
121* Read index for transmit buffer 122 * Read index for transmit buffer
122*/ 123 */
123static size_t transmit_buffer_index = 0; 124static size_t transmit_buffer_index;
124 125
125/** 126/**
126* Audio message skeleton 127 * Audio message skeleton
127*/ 128 */
128struct AudioMessage *audio_message; 129static struct AudioMessage *audio_message;
129
130 130
131 131
132/** 132/**
133* Pulseaudio shutdown task 133 * Pulseaudio shutdown task
134*/ 134 */
135static void 135static void
136quit (int ret) 136quit (int ret)
137{ 137{
@@ -140,18 +140,14 @@ quit (int ret)
140} 140}
141 141
142 142
143
144/** 143/**
145* Creates OPUS packets from PCM data 144 * Creates OPUS packets from PCM data
146*/ 145 */
147static void 146static void
148packetizer () 147packetizer ()
149{ 148{
150
151
152 while (transmit_buffer_length >= transmit_buffer_index + pcm_length) 149 while (transmit_buffer_length >= transmit_buffer_index + pcm_length)
153 { 150 {
154
155 int ret; 151 int ret;
156 int len; 152 int len;
157 153
@@ -450,11 +446,11 @@ opus_init ()
450 opus_data = (unsigned char *) calloc (max_payload_bytes, sizeof (char)); 446 opus_data = (unsigned char *) calloc (max_payload_bytes, sizeof (char));
451 447
452 audio_message = pa_xmalloc (sizeof (struct AudioMessage)); 448 audio_message = pa_xmalloc (sizeof (struct AudioMessage));
453
454 audio_message->header.size = htons (sizeof (struct AudioMessage)); 449 audio_message->header.size = htons (sizeof (struct AudioMessage));
455 audio_message->header.type = htons (GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO); 450 audio_message->header.type = htons (GNUNET_MESSAGE_TYPE_CONVERSATION_AUDIO);
456} 451}
457 452
453
458/** 454/**
459 * The main function for the record helper. 455 * The main function for the record helper.
460 * 456 *