UltraGrid
UltraGrid Low-Latency High-Resolution Transmission System
Loading...
Searching...
No Matches
export.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void audio_export (struct audio_export *state, const struct audio_frame *frame)
 
bool audio_export_configure_raw (struct audio_export *s, int bps, int sample_rate, int ch_count)
 
void audio_export_destroy (struct audio_export *state)
 
struct audio_export * audio_export_init (const char *filename)
 
void audio_export_raw (struct audio_export *s, void *data, unsigned len)
 
void audio_export_raw_ch (struct audio_export *s, const void **channels_data, unsigned sample_count)
 

Detailed Description

Author
Martin Pulec pulec.nosp@m.@ces.nosp@m.net.c.nosp@m.z

Definition in file export.h.

Function Documentation

◆ audio_export()

void audio_export ( struct audio_export * state,
const struct audio_frame * frame )

Definition at line 221 of file export.c.

222{
223 if(!s) {
224 return;
225 }
226
227 if(s->saved_format.ch_count == 0) {
228 bool res;
230 if(!res) {
231 fprintf(stderr, "[Audio export] Configuration failed.\n");
232 return;
233 }
234 pthread_create(&s->thread_id, NULL, audio_export_thread, s);
235 } else {
236 if(!audio_desc_eq(s->saved_format,
238 return;
239 }
240 }
241
242 audio_export_raw(s, frame->data, frame->data_len);
243}
struct video_frame * frame
void audio_export_raw(struct audio_export *s, void *data, unsigned len)
Definition export.c:209
static bool configure(struct audio_export *s, struct audio_desc fmt)
Definition export.c:122
static void * audio_export_thread(void *arg)
Definition export.c:82
struct audio_desc audio_desc_from_frame(const struct audio_frame *frame)
Definition utils.cpp:196
bool audio_desc_eq(struct audio_desc a1, struct audio_desc a2)
Definition utils.cpp:189

References audio_desc_eq(), audio_desc_from_frame(), audio_export_raw(), audio_export_thread(), audio_desc::ch_count, configure(), frame, audio_export::saved_format, and audio_export::thread_id.

Referenced by audio_play_dump_put_frame(), and export_audio().

Here is the call graph for this function:

◆ audio_export_configure_raw()

bool audio_export_configure_raw ( struct audio_export * s,
int bps,
int sample_rate,
int ch_count )

Configure audio export for exporting samples directly from a sample buffer. Cannot be called when export is already configured by a previous call to this function, or by audio_export().

Definition at line 136 of file export.c.

138{
139
140 assert(s->saved_format.ch_count == 0 && "Audio export already configured");
141 struct audio_desc fmt;
142
143 fmt.codec = AC_PCM;
144 fmt.bps = bps;
145 fmt.sample_rate = sample_rate;
146 fmt.ch_count = ch_count;
147
148 bool res = configure(s, fmt);
149
150 if(!res) {
151 fprintf(stderr, "[Audio export] Configuration failed.\n");
152 return false;
153 }
154 pthread_create(&s->thread_id, NULL, audio_export_thread, s);
155
156 return true;
157}
int int int sample_rate
const char * fmt
@ AC_PCM
Definition types.h:53
int ch_count
Definition types.h:79
int bps
Definition types.h:77
audio_codec_t codec
Definition types.h:80
struct audio_desc saved_format
Definition export.c:69
pthread_t thread_id
Definition export.c:73

References AC_PCM, audio_export_thread(), audio_desc::bps, audio_desc::ch_count, audio_desc::codec, configure(), fmt, sample_rate, audio_export::saved_format, and audio_export::thread_id.

Referenced by reconfigure_echo().

Here is the call graph for this function:

◆ audio_export_destroy()

void audio_export_destroy ( struct audio_export * state)

Definition at line 182 of file export.c.

183{
184 if(s) {
185 if(s->thread_id) {
186 pthread_mutex_lock(&s->lock);
187 s->should_exit_worker = true;
188 s->new_work_ready = true;
189 if(s->worker_waiting) {
190 pthread_cond_signal(&s->worker_cv);
191 }
192 pthread_mutex_unlock(&s->lock);
193 pthread_join(s->thread_id, NULL);
194 }
195
196 if (s->wav != NULL) {
197 wav_writer_close(s->wav);
198 }
199 if (s->ring != NULL) {
200 ring_buffer_destroy(s->ring);
201 }
202 pthread_cond_destroy(&s->worker_cv);
203 pthread_mutex_destroy(&s->lock);
204 free(s->filename);
205 free(s);
206 }
207}
void ring_buffer_destroy(struct ring_buffer *ring)
bool wav_writer_close(struct wav_writer_file *wav)
Definition wav_writer.c:169

References audio_export::filename, audio_export::lock, audio_export::new_work_ready, audio_export::ring, ring_buffer_destroy(), audio_export::should_exit_worker, audio_export::thread_id, audio_export::wav, wav_writer_close(), audio_export::worker_cv, and audio_export::worker_waiting.

Referenced by disable_export().

Here is the call graph for this function:

◆ audio_export_init()

struct audio_export * audio_export_init ( const char * filename)

Definition at line 159 of file export.c.

160{
161 struct audio_export *s = calloc(1, sizeof(struct audio_export));
162 if(!s) {
163 return NULL;
164 }
165
166 unlink(filename);
167 s->filename = strdup(filename);
168 s->thread_id = 0;
169 s->ring = NULL;
170
171 pthread_mutex_init(&s->lock, NULL);
172 pthread_cond_init(&s->worker_cv, NULL);
173 s->new_work_ready = false;
174 s->worker_waiting = false;
175 s->should_exit_worker = false;
176
177 s->saved_format = (struct audio_desc) { 0, 0, 0, 0 };
178
179 return s;
180}
ring_buffer_t * ring
Definition export.c:71
pthread_cond_t worker_cv
Definition export.c:75
volatile bool should_exit_worker
Definition export.c:79
pthread_mutex_t lock
Definition export.c:74
char * filename
Definition export.c:66
volatile bool new_work_ready
Definition export.c:76
volatile bool worker_waiting
Definition export.c:77

References audio_export::filename, audio_export::lock, audio_export::new_work_ready, audio_export::ring, audio_export::saved_format, audio_export::should_exit_worker, audio_export::thread_id, audio_export::worker_cv, and audio_export::worker_waiting.

Referenced by audio_play_dump_reconfigure(), enable_export(), and reconfigure_echo().

◆ audio_export_raw()

void audio_export_raw ( struct audio_export * s,
void * data,
unsigned len )

For exporting audio directly from a sample buffer. Before using this, the audio_export needs to be configured with audio_export_configure_raw()

Parameters
lensize of data in bytes

Definition at line 209 of file export.c.

209 {
210 assert(s->saved_format.ch_count != 0 && "Export not configured");
211 pthread_mutex_lock(&s->lock);
212 ring_buffer_write(s->ring, data, len);
213 s->new_work_ready = true;
214
215 if(s->worker_waiting) {
216 pthread_cond_signal(&s->worker_cv);
217 }
218 pthread_mutex_unlock(&s->lock);
219}
int void size_t * len
void ring_buffer_write(struct ring_buffer *ring, const char *in, int len)

References audio_desc::ch_count, len, audio_export::lock, audio_export::new_work_ready, audio_export::ring, ring_buffer_write(), audio_export::saved_format, audio_export::worker_cv, and audio_export::worker_waiting.

Referenced by audio_export().

Here is the call graph for this function:

◆ audio_export_raw_ch()

void audio_export_raw_ch ( struct audio_export * s,
const void ** channels_data,
unsigned sample_count )

Export audio from separate sample buffers for each channel.

Parameters
channels_dataarray of pointers to sample buffers
sample_countnumber of samples to export

Definition at line 262 of file export.c.

264{
265 const int ch_count = s->saved_format.ch_count;
266 const int bps = s->saved_format.bps;
267 assert(ch_count != 0 && "Export not configured");
268
269 int len = s->saved_format.ch_count * s->saved_format.bps * sample_count;
270
271 pthread_mutex_lock(&s->lock);
272 void *ptr1;
273 int size1;
274 void *ptr2;
275 int size2;
276 int avail = ring_get_write_regions(s->ring, len, &ptr1, &size1, &ptr2, &size2);
277
278 assert((size1 % (bps * ch_count)) == 0);
279 assert(!ptr2 || (size2 % (bps * ch_count)) == 0);
280
281 int written = write_samples(ptr1, channels_data, bps, ch_count, size1, 0);
282 if(ptr2){
283 write_samples(ptr2, channels_data, bps, ch_count, size2, written);
284 }
285
286 ring_advance_write_idx(s->ring, avail);
287
288 s->new_work_ready = true;
289 if(s->worker_waiting) {
290 pthread_cond_signal(&s->worker_cv);
291 }
292 pthread_mutex_unlock(&s->lock);
293}
static int write_samples(char *out, const void **channels_data, int bps, int ch_count, int size, int start_sample)
Definition export.c:245
bool ring_advance_write_idx(struct ring_buffer *ring, int amount)
int ring_get_write_regions(struct ring_buffer *ring, int requested_len, void **ptr1, int *size1, void **ptr2, int *size2)

References audio_desc::bps, audio_desc::ch_count, len, audio_export::lock, audio_export::new_work_ready, audio_export::ring, ring_advance_write_idx(), ring_get_write_regions(), audio_export::saved_format, audio_export::worker_cv, audio_export::worker_waiting, and write_samples().

Referenced by echo_cancel().

Here is the call graph for this function: