ao_jack: uncrustify

This commit is contained in:
wm4 2013-06-07 15:38:08 +02:00
parent 6cc60710e4
commit 5dec12f525
1 changed files with 233 additions and 208 deletions

View File

@ -80,9 +80,11 @@ static AVFifoBuffer *buffer;
*
* If there is not enough room, the buffer is filled up
*/
static int write_buffer(unsigned char* data, int len) {
static int write_buffer(unsigned char *data, int len)
{
int free = av_fifo_space(buffer);
if (len > free) len = free;
if (len > free)
len = free;
return av_fifo_generic_write(buffer, data, len, NULL);
}
@ -95,7 +97,8 @@ struct deinterleave {
int pos;
};
static void deinterleave(void *info, void *src, int len) {
static void deinterleave(void *info, void *src, int len)
{
struct deinterleave *di = info;
float *s = src;
int i;
@ -122,20 +125,25 @@ static void deinterleave(void *info, void *src, int len) {
* If there is not enough data in the buffer remaining parts will be filled
* with silence.
*/
static int read_buffer(float **bufs, int cnt, int num_bufs) {
struct deinterleave di = {bufs, num_bufs, 0, 0};
static int read_buffer(float **bufs, int cnt, int num_bufs)
{
struct deinterleave di = {
bufs, num_bufs, 0, 0
};
int buffered = av_fifo_size(buffer);
if (cnt * sizeof(float) * num_bufs > buffered) {
silence(bufs, cnt, num_bufs);
cnt = buffered / sizeof(float) / num_bufs;
}
av_fifo_generic_read(buffer, &di, cnt * num_bufs * sizeof(float), deinterleave);
av_fifo_generic_read(buffer, &di, cnt * num_bufs * sizeof(float),
deinterleave);
return cnt;
}
// end ring buffer stuff
static int control(int cmd, void *arg) {
static int control(int cmd, void *arg)
{
return CONTROL_UNKNOWN;
}
@ -145,7 +153,8 @@ static int control(int cmd, void *arg) {
* \param cnt number of samples in each buffer
* \param num_bufs number of buffers
*/
static void silence(float **bufs, int cnt, int num_bufs) {
static void silence(float **bufs, int cnt, int num_bufs)
{
int i;
for (i = 0; i < num_bufs; i++)
memset(bufs[i], 0, cnt * sizeof(float));
@ -159,15 +168,15 @@ static void silence(float **bufs, int cnt, int num_bufs) {
*
* Write silence into buffers if paused or an underrun occured
*/
static int outputaudio(jack_nframes_t nframes, void *arg) {
static int outputaudio(jack_nframes_t nframes, void *arg)
{
float *bufs[MAX_CHANS];
int i;
for (i = 0; i < num_ports; i++)
bufs[i] = jack_port_get_buffer(ports[i], nframes);
if (paused || underrun)
silence(bufs, nframes, num_ports);
else
if (read_buffer(bufs, nframes, num_ports) < nframes)
else if (read_buffer(bufs, nframes, num_ports) < nframes)
underrun = 1;
if (estimate) {
float now = mp_time_us() / 1000000.0;
@ -186,7 +195,8 @@ static int outputaudio(jack_nframes_t nframes, void *arg) {
*/
static void print_help(void)
{
mp_msg (MSGT_AO, MSGL_FATAL,
mp_msg(
MSGT_AO, MSGL_FATAL,
"\n-ao jack commandline help:\n"
"Example: mpv -ao jack:port=myout\n"
" connects mpv to the jack ports named myout\n"
@ -204,7 +214,8 @@ static void print_help (void)
);
}
static int init(int rate, const struct mp_chmap *channels, int format, int flags)
static int init(int rate, const struct mp_chmap *channels, int format,
int flags)
{
const char **matching_ports = NULL;
char *port_name = NULL;
@ -258,15 +269,20 @@ static int init(int rate, const struct mp_chmap *channels, int format, int flags
}
i = 1;
num_ports = ao_data.channels.num;
while (matching_ports[i]) i++;
if (num_ports > i) num_ports = i;
while (matching_ports[i])
i++;
if (num_ports > i)
num_ports = i;
}
// create out output ports
for (i = 0; i < num_ports; i++) {
char pname[30];
snprintf(pname, 30, "out_%d", i);
ports[i] = jack_port_register(client, pname, JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0);
ports[i] =
jack_port_register(client, pname, JACK_DEFAULT_AUDIO_TYPE,
JackPortIsOutput,
0);
if (!ports[i]) {
mp_msg(MSGT_AO, MSGL_FATAL, "[JACK] not enough ports available\n");
goto err_out;
@ -277,7 +293,8 @@ static int init(int rate, const struct mp_chmap *channels, int format, int flags
goto err_out;
}
for (i = 0; i < num_ports; i++) {
if (jack_connect(client, jack_port_name(ports[i]), matching_ports[i])) {
if (jack_connect(client, jack_port_name(ports[i]),
matching_ports[i])) {
mp_msg(MSGT_AO, MSGL_FATAL, "[JACK] connecting failed\n");
goto err_out;
}
@ -315,7 +332,8 @@ err_out:
}
// close audio device
static void uninit(int immed) {
static void uninit(int immed)
{
if (!immed)
mp_sleep_us(get_delay() * 1000 * 1000);
// HACK, make sure jack doesn't loop-output dirty buffers
@ -329,7 +347,8 @@ static void uninit(int immed) {
/**
* \brief stop playing and empty buffers (for seeking/pause)
*/
static void reset(void) {
static void reset(void)
{
paused = 1;
av_fifo_reset(buffer);
paused = 0;
@ -338,38 +357,44 @@ static void reset(void) {
/**
* \brief stop playing, keep buffers (for pause)
*/
static void audio_pause(void) {
static void audio_pause(void)
{
paused = 1;
}
/**
* \brief resume playing, after audio_pause()
*/
static void audio_resume(void) {
static void audio_resume(void)
{
paused = 0;
}
static int get_space(void) {
static int get_space(void)
{
return av_fifo_space(buffer);
}
/**
* \brief write data into buffer and reset underrun flag
*/
static int play(void *data, int len, int flags) {
static int play(void *data, int len, int flags)
{
if (!(flags & AOPLAY_FINAL_CHUNK))
len -= len % ao_data.outburst;
underrun = 0;
return write_buffer(data, len);
}
static float get_delay(void) {
static float get_delay(void)
{
int buffered = av_fifo_size(buffer); // could be less
float in_jack = jack_latency;
if (estimate && callback_interval > 0) {
float elapsed = mp_time_us() / 1000000.0 - callback_time;
in_jack += callback_interval - elapsed;
if (in_jack < 0) in_jack = 0;
if (in_jack < 0)
in_jack = 0;
}
return (float)buffered / (float)ao_data.bps + in_jack;
}