scons --> make
[aftubes.git] / modules / playsink.c
blob937b7a22557b9607129fd9dec7f93242f3dea9b6
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 get_ideal_input_format(struct graphnode *node, struct graphpin *pin, struct aformat *af)
18 af->media = MT_AUDIO_16I;
19 af->srate = 44100;
20 af->channels = 2;
21 return EOK;
24 static err_t set_buffer(struct graphnode *node, struct graphpin *pin, struct buffer *buf)
26 struct playsink *ps = node->extra;
27 ps->buf = buf;
28 if (!ps->is_open){
29 if (soundout_open(&ps->so, &buf->format) != 0){
30 return make_error(-1, node, "cannot open soundout");
32 ps->is_open = true;
34 return EOK;
37 static err_t run(struct graphnode *node)
39 struct playsink *ps = node->extra;
41 if (soundout_write(&ps->so, ps->buf->data, ps->buf->n_samples * aformat_get_sample_size(&ps->buf->format)) != 0){
42 return make_error(-1, node, "cannot write to soundout");
44 return EOK;
47 static const struct graphnode_functab functab = {
48 is_acceptable_input_format,
49 get_ideal_input_format,
50 NULL, // get_output_format
51 set_buffer,
52 run,
55 err_t playsink_create(struct graphnode **node_out)
57 struct graphnode *node;
58 struct graphpin *pin;
59 struct playsink *ps;
60 err_t err;
62 err = graphnode_create(&node, &functab, sizeof *ps);
63 if (err != EOK){
64 return err;
67 err = graphnode_add_pin(node, &pin);
68 if (err != EOK){
69 return err;
71 pin->dir = DIR_IN;
72 pin->name = "in";
74 ps = node->extra;
75 ps->is_open = false;
77 *node_out = node;
78 return EOK;