Initialized graphpin fields
[aftubes.git] / playsink.c
blob1bee6b9c7c8d187e906f59ed49c50c4b0b675050
1 #include "graph.h"
2 #include "errors.h"
3 #include "soundout.h"
5 struct playsink {
6 struct buffer *buf;
7 bool is_open;
8 struct soundout so;
9 };
11 static bool is_acceptable_input_format(struct graphnode *node, struct graphpin *pin, const struct aformat *af)
13 return af->media == MT_AUDIO_16I;
16 static err_t set_buffer(struct graphnode *node, struct graphpin *pin, struct buffer *buf)
18 struct playsink *ps = node->extra;
19 ps->buf = buf;
20 if (!ps->is_open){
21 if (soundout_open(&ps->so, &buf->format) != 0){
22 return make_error(-1, node, "cannot open soundout");
24 ps->is_open = true;
26 return EOK;
29 static err_t run(struct graphnode *node)
31 struct playsink *ps = node->extra;
33 if (soundout_write(&ps->so, ps->buf->data, ps->buf->n_samples * aformat_get_sample_size(&ps->buf->format)) != 0){
34 return make_error(-1, node, "cannot write to soundout");
36 return EOK;
39 static const struct graphnode_functab functab = {
40 is_acceptable_input_format,
41 NULL, // get_output_format
42 set_buffer,
43 run,
46 err_t playsink_create(struct graphnode **node_out)
48 struct graphnode *node;
49 struct graphpin *pin;
50 struct playsink *ps;
51 err_t err;
53 err = graphnode_create(&node, &functab, sizeof *ps);
54 if (err != EOK){
55 return err;
58 err = graphnode_add_pin(node, &pin);
59 if (err != EOK){
60 return err;
62 pin->dir = DIR_IN;
63 pin->name = "in";
65 ps = node->extra;
66 ps->is_open = false;
68 *node_out = node;
69 return EOK;