Mercurial > audlegacy-plugins
changeset 1686:2e8adf61c54f
remove realtime craq from the code
author | William Pitcock <nenolod@atheme.org> |
---|---|
date | Tue, 11 Sep 2007 06:52:53 -0500 |
parents | 8c93d207a4d9 |
children | 6f939852584b |
files | src/OSS/audio.c src/OSS4/audio.c src/esd/audio.c src/filewriter/filewriter.c src/sun/audio.c |
diffstat | 5 files changed, 142 insertions(+), 315 deletions(-) [+] |
line wrap: on
line diff
--- a/src/OSS/audio.c Tue Sep 11 06:04:15 2007 -0500 +++ b/src/OSS/audio.c Tue Sep 11 06:52:53 2007 -0500 @@ -47,7 +47,7 @@ static gint fragsize, device_buffer_size; static gchar *device_name; static GThread *buffer_thread; -static gboolean realtime, select_works; +static gboolean select_works; static int (*oss_convert_func) (void **data, int length); static int (*oss_stereo_convert_func) (void **data, int length, int fmt); @@ -197,8 +197,6 @@ if (!fd || !going) return 0; - if (realtime) - oss_calc_device_buffer_used(); bytes = output_bytes < device_buffer_used ? 0 : output_bytes - device_buffer_used; @@ -208,13 +206,10 @@ static int oss_used(void) { - if (realtime) - return 0; - else { - if (wr_index >= rd_index) - return wr_index - rd_index; - return buffer_size - (rd_index - wr_index); - } + if (wr_index >= rd_index) + return wr_index - rd_index; + + return buffer_size - (rd_index - wr_index); } gint @@ -222,8 +217,6 @@ { if (!going) return 0; - if (realtime) - oss_calc_device_buffer_used(); if (!oss_used() && (device_buffer_used - (3 * blk_size)) <= 0) return FALSE; @@ -233,22 +226,18 @@ gint oss_free(void) { - if (!realtime) { - if (remove_prebuffer && prebuffer) { - prebuffer = FALSE; - remove_prebuffer = FALSE; - } - if (prebuffer) - remove_prebuffer = TRUE; + if (remove_prebuffer && prebuffer) { + prebuffer = FALSE; + remove_prebuffer = FALSE; + } - if (rd_index > wr_index) - return (rd_index - wr_index) - device_buffer_size - 1; - return (buffer_size - (wr_index - rd_index)) - device_buffer_size - 1; - } - else if (paused) - return 0; - else - return 1000000; + if (prebuffer) + remove_prebuffer = TRUE; + + if (rd_index > wr_index) + return (rd_index - wr_index) - device_buffer_size - 1; + + return (buffer_size - (wr_index - rd_index)) - device_buffer_size - 1; } static inline ssize_t @@ -275,14 +264,6 @@ audio_buf_info abuf_info; - if (realtime && !ioctl(fd, SNDCTL_DSP_GETOSPACE, &abuf_info)) { - while (abuf_info.bytes < length) { - g_usleep(10000); - if (ioctl(fd, SNDCTL_DSP_GETOSPACE, &abuf_info)) - break; - } - } - if (oss_convert_func != NULL) length = oss_convert_func(&data, length); @@ -437,23 +418,15 @@ { int cnt, off = 0; - if (!realtime) { - remove_prebuffer = FALSE; + remove_prebuffer = FALSE; - written += length; - while (length > 0) { - cnt = MIN(length, buffer_size - wr_index); - memcpy(buffer + wr_index, (char *) ptr + off, cnt); - wr_index = (wr_index + cnt) % buffer_size; - length -= cnt; - off += cnt; - } - } - else { - if (paused) - return; - oss_write_audio(ptr, length); - written += length; + written += length; + while (length > 0) { + cnt = MIN(length, buffer_size - wr_index); + memcpy(buffer + wr_index, (char *) ptr + off, cnt); + wr_index = (wr_index + cnt) % buffer_size; + length -= cnt; + off += cnt; } } @@ -463,12 +436,9 @@ if (!going) return; going = 0; - if (!realtime) - g_thread_join(buffer_thread); - else { - ioctl(fd, SNDCTL_DSP_RESET, 0); - close(fd); - } + + g_thread_join(buffer_thread); + g_free(device_name); oss_free_convert_buffer(); wr_index = 0; @@ -480,34 +450,18 @@ void oss_flush(gint time) { - if (!realtime) { - flush = time; - while (flush != -1) - g_usleep(10000); - } - else { - ioctl(fd, SNDCTL_DSP_RESET, 0); - close(fd); - fd = open(device_name, O_WRONLY); - oss_set_audio_params(); - output_time_offset = time; - written = ((guint64) time * input.bps) / 1000; - output_bytes = 0; - } + flush = time; + while (flush != -1) + g_usleep(10000); } void oss_pause(short p) { - if (!realtime) { - if (p == TRUE) - do_pause = TRUE; - else - unpause = TRUE; - } + if (p == TRUE) + do_pause = TRUE; else - paused = p; - + unpause = TRUE; } gpointer @@ -666,19 +620,18 @@ oss_setup_format(fmt, rate, nch); - realtime = xmms_check_realtime_priority(); + buffer_size = (oss_cfg.buffer_size * input.bps) / 1000; + + if (buffer_size < 8192) + buffer_size = 8192; - if (!realtime) { - buffer_size = (oss_cfg.buffer_size * input.bps) / 1000; - if (buffer_size < 8192) - buffer_size = 8192; - prebuffer_size = (buffer_size * oss_cfg.prebuffer) / 100; - if (buffer_size - prebuffer_size < 4096) - prebuffer_size = buffer_size - 4096; + prebuffer_size = (buffer_size * oss_cfg.prebuffer) / 100; + if (buffer_size - prebuffer_size < 4096) + prebuffer_size = buffer_size - 4096; - buffer_size += device_buffer_size; - buffer = g_malloc0(buffer_size); - } + buffer_size += device_buffer_size; + buffer = g_malloc0(buffer_size); + flush = -1; prebuffer = TRUE; wr_index = rd_index = output_time_offset = written = output_bytes = 0; @@ -688,8 +641,9 @@ remove_prebuffer = FALSE; going = 1; - if (!realtime) - buffer_thread = g_thread_create(oss_loop, NULL, TRUE, NULL); + + buffer_thread = g_thread_create(oss_loop, NULL, TRUE, NULL); + return 1; }
--- a/src/OSS4/audio.c Tue Sep 11 06:04:15 2007 -0500 +++ b/src/OSS4/audio.c Tue Sep 11 06:52:53 2007 -0500 @@ -47,7 +47,7 @@ static gint fragsize, device_buffer_size; static gchar *device_name; static GThread *buffer_thread; -static gboolean realtime, select_works; +static gboolean select_works; static int (*oss_convert_func) (void **data, int length); static int (*oss_stereo_convert_func) (void **data, int length, int fmt); @@ -197,8 +197,6 @@ if (!fd || !going) return 0; - if (realtime) - oss_calc_device_buffer_used(); bytes = output_bytes < device_buffer_used ? 0 : output_bytes - device_buffer_used; @@ -208,13 +206,10 @@ static int oss_used(void) { - if (realtime) - return 0; - else { - if (wr_index >= rd_index) - return wr_index - rd_index; - return buffer_size - (rd_index - wr_index); - } + if (wr_index >= rd_index) + return wr_index - rd_index; + + return buffer_size - (rd_index - wr_index); } gint @@ -222,8 +217,6 @@ { if (!going) return 0; - if (realtime) - oss_calc_device_buffer_used(); if (!oss_used() && (device_buffer_used - (3 * blk_size)) <= 0) return FALSE; @@ -233,22 +226,18 @@ gint oss_free(void) { - if (!realtime) { - if (remove_prebuffer && prebuffer) { - prebuffer = FALSE; - remove_prebuffer = FALSE; - } - if (prebuffer) - remove_prebuffer = TRUE; + if (remove_prebuffer && prebuffer) { + prebuffer = FALSE; + remove_prebuffer = FALSE; + } - if (rd_index > wr_index) - return (rd_index - wr_index) - device_buffer_size - 1; - return (buffer_size - (wr_index - rd_index)) - device_buffer_size - 1; - } - else if (paused) - return 0; - else - return 1000000; + if (prebuffer) + remove_prebuffer = TRUE; + + if (rd_index > wr_index) + return (rd_index - wr_index) - device_buffer_size - 1; + + return (buffer_size - (wr_index - rd_index)) - device_buffer_size - 1; } static inline ssize_t @@ -275,14 +264,6 @@ audio_buf_info abuf_info; - if (realtime && !ioctl(fd, SNDCTL_DSP_GETOSPACE, &abuf_info)) { - while (abuf_info.bytes < length) { - g_usleep(10000); - if (ioctl(fd, SNDCTL_DSP_GETOSPACE, &abuf_info)) - break; - } - } - if (oss_convert_func != NULL) length = oss_convert_func(&data, length); @@ -437,23 +418,15 @@ { int cnt, off = 0; - if (!realtime) { - remove_prebuffer = FALSE; + remove_prebuffer = FALSE; - written += length; - while (length > 0) { - cnt = MIN(length, buffer_size - wr_index); - memcpy(buffer + wr_index, (char *) ptr + off, cnt); - wr_index = (wr_index + cnt) % buffer_size; - length -= cnt; - off += cnt; - } - } - else { - if (paused) - return; - oss_write_audio(ptr, length); - written += length; + written += length; + while (length > 0) { + cnt = MIN(length, buffer_size - wr_index); + memcpy(buffer + wr_index, (char *) ptr + off, cnt); + wr_index = (wr_index + cnt) % buffer_size; + length -= cnt; + off += cnt; } } @@ -463,12 +436,9 @@ if (!going) return; going = 0; - if (!realtime) - g_thread_join(buffer_thread); - else { - ioctl(fd, SNDCTL_DSP_RESET, 0); - close(fd); - } + + g_thread_join(buffer_thread); + g_free(device_name); oss_free_convert_buffer(); wr_index = 0; @@ -480,34 +450,18 @@ void oss_flush(gint time) { - if (!realtime) { - flush = time; - while (flush != -1) - g_usleep(10000); - } - else { - ioctl(fd, SNDCTL_DSP_RESET, 0); - close(fd); - fd = open(device_name, O_WRONLY); - oss_set_audio_params(); - output_time_offset = time; - written = ((guint64) time * input.bps) / 1000; - output_bytes = 0; - } + flush = time; + while (flush != -1) + g_usleep(10000); } void oss_pause(short p) { - if (!realtime) { - if (p == TRUE) - do_pause = TRUE; - else - unpause = TRUE; - } + if (p == TRUE) + do_pause = TRUE; else - paused = p; - + unpause = TRUE; } gpointer @@ -666,19 +620,18 @@ oss_setup_format(fmt, rate, nch); - realtime = xmms_check_realtime_priority(); + buffer_size = (oss_cfg.buffer_size * input.bps) / 1000; + + if (buffer_size < 8192) + buffer_size = 8192; - if (!realtime) { - buffer_size = (oss_cfg.buffer_size * input.bps) / 1000; - if (buffer_size < 8192) - buffer_size = 8192; - prebuffer_size = (buffer_size * oss_cfg.prebuffer) / 100; - if (buffer_size - prebuffer_size < 4096) - prebuffer_size = buffer_size - 4096; + prebuffer_size = (buffer_size * oss_cfg.prebuffer) / 100; + if (buffer_size - prebuffer_size < 4096) + prebuffer_size = buffer_size - 4096; - buffer_size += device_buffer_size; - buffer = g_malloc0(buffer_size); - } + buffer_size += device_buffer_size; + buffer = g_malloc0(buffer_size); + flush = -1; prebuffer = TRUE; wr_index = rd_index = output_time_offset = written = output_bytes = 0; @@ -688,8 +641,9 @@ remove_prebuffer = FALSE; going = 1; - if (!realtime) - buffer_thread = g_thread_create(oss_loop, NULL, TRUE, NULL); + + buffer_thread = g_thread_create(oss_loop, NULL, TRUE, NULL); + return 1; }
--- a/src/esd/audio.c Tue Sep 11 06:04:15 2007 -0500 +++ b/src/esd/audio.c Tue Sep 11 06:52:53 2007 -0500 @@ -43,7 +43,6 @@ static esd_format_t esd_format; static gint input_bps, input_format, input_frequency, input_channels; static GThread *buffer_thread; -static gboolean realtime = FALSE; static void *(*esd_translate) (void *, gint); static int player_id_unique = 0; @@ -227,13 +226,10 @@ gint esdout_used(void) { - if (realtime) - return 0; - else { - if (wr_index >= rd_index) - return wr_index - rd_index; - return buffer_size - (rd_index - wr_index); - } + if (wr_index >= rd_index) + return wr_index - rd_index; + + return buffer_size - (rd_index - wr_index); } gint @@ -250,24 +246,18 @@ gint esdout_free(void) { - if (!realtime) { - if (remove_prebuffer && prebuffer) { - prebuffer = FALSE; - remove_prebuffer = FALSE; - } - if (prebuffer) - remove_prebuffer = TRUE; + if (remove_prebuffer && prebuffer) { + prebuffer = FALSE; + remove_prebuffer = FALSE; + } - if (rd_index > wr_index) - return (rd_index - wr_index) - 1; - return (buffer_size - (wr_index - rd_index)) - 1; - } - else { - if (paused) - return 0; - else - return 1000000; - } + if (prebuffer) + remove_prebuffer = TRUE; + + if (rd_index > wr_index) + return (rd_index - wr_index) - 1; + + return (buffer_size - (wr_index - rd_index)) - 1; } static void @@ -293,27 +283,16 @@ { gint cnt, off = 0; - if (!realtime) { - remove_prebuffer = FALSE; - - written += length; - while (length > 0) { - cnt = MIN(length, buffer_size - wr_index); - memcpy((gchar *) buffer + wr_index, (gchar *) ptr + off, cnt); - wr_index = (wr_index + cnt) % buffer_size; - length -= cnt; - off += cnt; + remove_prebuffer = FALSE; - } + written += length; + while (length > 0) { + cnt = MIN(length, buffer_size - wr_index); + memcpy((gchar *) buffer + wr_index, (gchar *) ptr + off, cnt); + wr_index = (wr_index + cnt) % buffer_size; + length -= cnt; + off += cnt; } - else { - if (paused) - return; - esdout_write_audio(ptr, length); - written += length; - - } - } void @@ -324,10 +303,7 @@ going = 0; - if (!realtime) - g_thread_join(buffer_thread); - else - esd_close(fd); + g_thread_join(buffer_thread); wr_index = 0; rd_index = 0; @@ -338,16 +314,10 @@ void esdout_flush(gint time) { - if (!realtime) { - flush = time; - while (flush != -1) - g_usleep(10000); - } - else { - output_time_offset = time; - written = (guint64) (time / 10) * (guint64) (input_bps / 100); - output_bytes = 0; - } + flush = time; + + while (flush != -1) + g_usleep(10000); } void @@ -417,18 +387,15 @@ input_frequency = frequency; input_bps = bps; - realtime = xmms_check_realtime_priority(); + buffer_size = (esd_cfg.buffer_size * input_bps) / 1000; + if (buffer_size < 8192) + buffer_size = 8192; + prebuffer_size = (buffer_size * esd_cfg.prebuffer) / 100; + if (buffer_size - prebuffer_size < 4096) + prebuffer_size = buffer_size - 4096; - if (!realtime) { - buffer_size = (esd_cfg.buffer_size * input_bps) / 1000; - if (buffer_size < 8192) - buffer_size = 8192; - prebuffer_size = (buffer_size * esd_cfg.prebuffer) / 100; - if (buffer_size - prebuffer_size < 4096) - prebuffer_size = buffer_size - 4096; + buffer = g_malloc0(buffer_size); - buffer = g_malloc0(buffer_size); - } flush = -1; prebuffer = 1; wr_index = rd_index = output_time_offset = written = output_bytes = 0; @@ -454,8 +421,8 @@ } going = 1; - if (!realtime) - buffer_thread = g_thread_create(esdout_loop, NULL, TRUE, NULL); + buffer_thread = g_thread_create(esdout_loop, NULL, TRUE, NULL); + return 1; }
--- a/src/filewriter/filewriter.c Tue Sep 11 06:04:15 2007 -0500 +++ b/src/filewriter/filewriter.c Tue Sep 11 06:52:53 2007 -0500 @@ -187,15 +187,6 @@ gint rv; Playlist *playlist; - if (xmms_check_realtime_priority()) - { - audacious_info_dialog(_("Error"), - _("You cannot use the FileWriter plugin\n" - "when you're running in realtime mode."), - _("OK"), FALSE, NULL, NULL); - return 0; - } - input.format = fmt; input.frequency = rate; input.channels = nch;
--- a/src/sun/audio.c Tue Sep 11 06:04:15 2007 -0500 +++ b/src/sun/audio.c Tue Sep 11 06:52:53 2007 -0500 @@ -35,7 +35,6 @@ static gboolean prebuffer, remove_prebuffer; static pthread_t buffer_thread; static int (*sun_convert)(void **, int); -static int realtime; static int rd_index, wr_index; static int buffer_size; static int prebuffer_size; @@ -233,9 +232,6 @@ if (!audio.fd || !audio.going) return 0; - if (realtime) - sun_bufused(); - bytes = output_bytes < device_buffer_used ? 0 : output_bytes - device_buffer_used; return (output_time_offset + ((bytes * 1000) / output.bps)); @@ -243,9 +239,6 @@ static inline int sun_used(void) { - if (realtime) - return 0; - if (wr_index >= rd_index) return (wr_index - rd_index); @@ -257,9 +250,6 @@ if (!audio.going) return 0; - if (realtime) - sun_bufused(); - if (!sun_used() && (device_buffer_used - (3 * blocksize)) <= 0) return (FALSE); @@ -268,9 +258,6 @@ int sun_free(void) { - if (realtime) - return (audio.paused ? 0 : 1000000); - if (remove_prebuffer && prebuffer) { prebuffer = FALSE; @@ -372,15 +359,6 @@ { int cnt, off = 0; - if (realtime) - { - if (audio.paused) - return; - sun_write_audio(ptr, length); - written += length; - return; - } - remove_prebuffer = FALSE; written += length; while (length > 0) @@ -400,15 +378,7 @@ audio.going = 0; - if (realtime) - { - ioctl(audio.fd, AUDIO_FLUSH, NULL); - close(audio.fd); - } - else - { - pthread_join(buffer_thread, NULL); - } + pthread_join(buffer_thread, NULL); sun_get_convert_buffer(0); wr_index = 0; @@ -426,15 +396,10 @@ void sun_pause(short p) { - if (!realtime) - { - if (p == TRUE) - audio.do_pause = TRUE; - else - audio.unpause = TRUE; - } + if (p == TRUE) + audio.do_pause = TRUE; else - audio.paused = p; + audio.unpause = TRUE; } static void* sun_loop(void *arg) @@ -519,25 +484,21 @@ input.bps = sun_bps(sun_format(fmt), rate, nch); sun_setformat(fmt, rate, nch); - realtime = xmms_check_realtime_priority(); - if (ioctl(audio.fd, AUDIO_GETINFO, &info) != 0) blocksize = SUN_DEFAULT_BLOCKSIZE; else blocksize = info.blocksize; - if (!realtime) - { - buffer_size = audio.req_buffer_size; + buffer_size = audio.req_buffer_size; + + if (buffer_size < SUN_MIN_BUFFER_SIZE) + buffer_size = SUN_MIN_BUFFER_SIZE; - if (buffer_size < SUN_MIN_BUFFER_SIZE) - buffer_size = SUN_MIN_BUFFER_SIZE; + prebuffer_size = (buffer_size * audio.req_prebuffer_size) / 100; - prebuffer_size = (buffer_size * audio.req_prebuffer_size) / 100; + buffer_size += blocksize; + buffer = g_malloc0(buffer_size); - buffer_size += blocksize; - buffer = g_malloc0(buffer_size); - } prebuffer = TRUE; wr_index = 0; rd_index = 0; @@ -551,8 +512,8 @@ remove_prebuffer = FALSE; audio.going++; - if (!realtime) - pthread_create(&buffer_thread, NULL, sun_loop, NULL); + + pthread_create(&buffer_thread, NULL, sun_loop, NULL); return 1; }