diff options
author | Christian Grothoff <christian@grothoff.org> | 2013-10-02 19:29:22 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2013-10-02 19:29:22 +0000 |
commit | 0834bf4d6fdf19ab410c01c02e65fcda8a5e5ebc (patch) | |
tree | 2410199dfb90c0ef4d12fc749f30f88e9bfda9b8 /src/conversation/gnunet-helper-audio-record.c | |
parent | ec9740ca2ca84525842e6743b45ceb9cb2a3ea95 (diff) | |
download | gnunet-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.c | 110 |
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 | */ |
44 | static pa_sample_spec sample_spec = { | 45 | static 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 | */ |
53 | static pa_mainloop_api *mainloop_api = NULL; | 54 | static pa_mainloop_api *mainloop_api; |
54 | 55 | ||
55 | /** | 56 | /** |
56 | * Pulseaudio mainloop | 57 | * Pulseaudio mainloop |
57 | */ | 58 | */ |
58 | static pa_mainloop *m = NULL; | 59 | static pa_mainloop *m; |
59 | 60 | ||
60 | /** | 61 | /** |
61 | * Pulseaudio context | 62 | * Pulseaudio context |
62 | */ | 63 | */ |
63 | static pa_context *context = NULL; | 64 | static pa_context *context; |
64 | 65 | ||
65 | /** | 66 | /** |
66 | * Pulseaudio recording stream | 67 | * Pulseaudio recording stream |
67 | */ | 68 | */ |
68 | static pa_stream *stream_in = NULL; | 69 | static pa_stream *stream_in; |
69 | 70 | ||
70 | /** | 71 | /** |
71 | * Pulseaudio io events | 72 | * Pulseaudio io events |
72 | */ | 73 | */ |
73 | static pa_io_event *stdio_event = NULL; | 74 | static pa_io_event *stdio_event; |
74 | 75 | ||
75 | /** | 76 | /** |
76 | * Message tokenizer | 77 | * Message tokenizer |
77 | */ | 78 | */ |
78 | struct MessageStreamTokenizer *stdin_mst; | 79 | static struct MessageStreamTokenizer *stdin_mst; |
79 | 80 | ||
80 | /** | 81 | /** |
81 | * OPUS encoder | 82 | * OPUS encoder |
82 | */ | 83 | */ |
83 | OpusEncoder *enc = NULL; | 84 | static OpusEncoder *enc; |
84 | 85 | ||
85 | /** | 86 | /** |
86 | * | 87 | * |
87 | */ | 88 | */ |
88 | unsigned char *opus_data; | 89 | static 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 | */ |
93 | float *pcm_buffer; | 94 | static 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 | */ |
98 | int pcm_length; | 99 | static int pcm_length; |
99 | 100 | ||
100 | /** | 101 | /** |
101 | * Number of samples for one frame | 102 | * Number of samples for one frame |
102 | */ | 103 | */ |
103 | int frame_size; | 104 | static int frame_size; |
104 | 105 | ||
105 | /** | 106 | /** |
106 | * Maximum length of opus payload | 107 | * Maximum length of opus payload |
107 | */ | 108 | */ |
108 | int max_payload_bytes = 1500; | 109 | static int max_payload_bytes = 1500; |
109 | 110 | ||
110 | /** | 111 | /** |
111 | * Audio buffer | 112 | * Audio buffer |
112 | */ | 113 | */ |
113 | static void *transmit_buffer = NULL; | 114 | static void *transmit_buffer; |
114 | 115 | ||
115 | /** | 116 | /** |
116 | * Length of audio buffer | 117 | * Length of audio buffer |
117 | */ | 118 | */ |
118 | static size_t transmit_buffer_length = 0; | 119 | static size_t transmit_buffer_length; |
119 | 120 | ||
120 | /** | 121 | /** |
121 | * Read index for transmit buffer | 122 | * Read index for transmit buffer |
122 | */ | 123 | */ |
123 | static size_t transmit_buffer_index = 0; | 124 | static size_t transmit_buffer_index; |
124 | 125 | ||
125 | /** | 126 | /** |
126 | * Audio message skeleton | 127 | * Audio message skeleton |
127 | */ | 128 | */ |
128 | struct AudioMessage *audio_message; | 129 | static struct AudioMessage *audio_message; |
129 | |||
130 | 130 | ||
131 | 131 | ||
132 | /** | 132 | /** |
133 | * Pulseaudio shutdown task | 133 | * Pulseaudio shutdown task |
134 | */ | 134 | */ |
135 | static void | 135 | static void |
136 | quit (int ret) | 136 | quit (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 | */ |
147 | static void | 146 | static void |
148 | packetizer () | 147 | packetizer () |
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 | * |