blob: ffec77da983dadf501f5a1c2c375be6ebeb3c775 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include "outputstream.h"
struct output_stream* output_stream_new(struct source *s, struct sample_spec *spec, const char *name) {
struct output_stream *o;
int r;
assert(s && spec);
o = malloc(sizeof(struct output_stream));
assert(o);
o->name = name ? strdup(name) : NULL;
o->source = s;
o->spec = *spec;
o->memblockq = memblockq_new(bytes_per_second(spec)*5, sample_size(spec));
assert(o->memblockq);
assert(s->core);
r = idxset_put(s->core->output_streams, o, &o->index);
assert(r == 0 && o->index != IDXSET_INVALID);
r = idxset_put(s->output_streams, o, NULL);
assert(r == 0);
return o;
}
void output_stream_free(struct output_stream* o) {
assert(o);
memblockq_free(o->memblockq);
assert(o->source && o->source->core);
idxset_remove_by_data(o->source->core->output_streams, o, NULL);
idxset_remove_by_data(o->source->output_streams, o, NULL);
free(o->name);
free(o);
}
|