update
[netyack.git] / src / netyack.c
blobe89b277b97fb61625b40078a6d153bc26b6003d0
1 /*
2 * netyack
3 * By Daniel Borkmann <daniel@netyack.org>
4 * Copyright 2011 Daniel Borkmann.
5 * Subject to the GPL.
6 */
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <unistd.h>
11 #include <stdlib.h>
12 #include <string.h>
13 #include <jack/jack.h>
14 #include <celt/celt.h>
15 #include <speex/speex_jitter.h>
17 #include "netyack.h"
18 #include "error_and_die.h"
20 static jack_port_t *input;
21 static jack_port_t *output;
23 static jack_client_t *client;
25 int jack_process_new_frames(jack_nframes_t nframes, void *arg)
27 jack_default_audio_sample_t *in, *out;
29 in = jack_port_get_buffer(input, nframes);
30 out = jack_port_get_buffer(output, nframes);
32 memcpy(out, in, sizeof(*in) * nframes);
34 return 0;
37 void jack_shutdown(void *arg)
39 die();
42 void jack_setup(char *name)
44 int ret;
45 const char **ports;
47 jack_options_t options = JackNoStartServer;
48 jack_status_t status;
50 client = jack_client_open(name, options, &status, NULL);
51 if (!client) {
52 whine("Opening JACK client failed (0x%2.0x)\n", status);
53 if (status & JackServerFailed)
54 whine("JACK server not running?\n");
55 die();
58 jack_set_process_callback(client, jack_process_new_frames, 0);
59 jack_on_shutdown(client, jack_shutdown, 0);
61 input = jack_port_register(client, "input", JACK_DEFAULT_AUDIO_TYPE,
62 JackPortIsInput, 0);
63 output = jack_port_register(client, "output", JACK_DEFAULT_AUDIO_TYPE,
64 JackPortIsOutput, 0);
65 if (!input || !output)
66 panic("No more JACK ports available!\n");
68 ret = jack_activate(client);
69 if (ret)
70 panic("Cannot activate JACK client!\n");
72 ports = jack_get_ports(client, NULL, NULL,
73 JackPortIsPhysical | JackPortIsOutput);
74 if (!ports)
75 panic("No physical capture ports available!\n");
77 ret = jack_connect(client, ports[0], jack_port_name(input));
78 free(ports);
79 if (ret)
80 panic("Cannot connect input ports!\n");
82 ports = jack_get_ports(client, NULL, NULL,
83 JackPortIsPhysical | JackPortIsInput);
84 if (!ports)
85 panic("No physical playback ports available!\n");
87 ret = jack_connect(client, jack_port_name(output), ports[0]);
88 free(ports);
89 if (ret)
90 panic("Cannot connect output ports!\n");
92 info("plugged to jack\n");
95 int main(int argc, char **argv)
97 jack_setup(argv[0]);
98 info("netyack up and running\n");
100 /* Keep running until stopped by the user. */
101 sleep(-1);
104 * This is never reached but if the program had some other way to exit
105 * besides being killed, they would be important to call.
108 jack_client_close(client);
110 return 0;