From 5f9ace4b782bcb43ba11ccbf0e427a1c51195a71 Mon Sep 17 00:00:00 2001 From: Benjamin Drung Date: Thu, 19 Aug 2010 18:32:17 +0200 Subject: Imported Upstream version 2.4~rc2 --- src/alsa/Makefile | 4 +- src/alsa/alsa.c | 122 +++++++++++++++++++++++++----------------------- src/alsa/alsa.h | 5 +- src/alsa/config.c | 2 - src/gtkui/ui_gtk.c | 4 ++ src/gtkui/ui_infoarea.c | 4 ++ src/hotkey/plugin.c | 1 + src/resample/plugin.c | 4 ++ 8 files changed, 79 insertions(+), 67 deletions(-) (limited to 'src') diff --git a/src/alsa/Makefile b/src/alsa/Makefile index 10485dc..2a97887 100644 --- a/src/alsa/Makefile +++ b/src/alsa/Makefile @@ -9,6 +9,6 @@ include ../../extra.mk plugindir := ${plugindir}/${OUTPUT_PLUGIN_DIR} -CFLAGS += ${PLUGIN_CFLAGS} ${GLIB_CFLAGS} ${GTK_CFLAGS} ${ALSA_CFLAGS} +CFLAGS += -std=gnu99 ${PLUGIN_CFLAGS} ${GTK_CFLAGS} ${ALSA_CFLAGS} CPPFLAGS += -I../.. -LIBS += ${GLIB_LIBS} ${GTK_LIBS} ${ALSA_LIBS} +LIBS += ${GTK_LIBS} ${ALSA_LIBS} diff --git a/src/alsa/alsa.c b/src/alsa/alsa.c index b407a9e..867ad8c 100755 --- a/src/alsa/alsa.c +++ b/src/alsa/alsa.c @@ -40,6 +40,7 @@ #include #include #include +#include #include #include #include @@ -69,8 +70,8 @@ do { \ static snd_pcm_t * alsa_handle; static char alsa_initted; -pthread_mutex_t alsa_mutex = PTHREAD_MUTEX_INITIALIZER; -pthread_cond_t alsa_cond = PTHREAD_COND_INITIALIZER; +static pthread_mutex_t alsa_mutex = PTHREAD_MUTEX_INITIALIZER; +static pthread_cond_t alsa_cond = PTHREAD_COND_INITIALIZER; static snd_pcm_format_t alsa_format; static int alsa_channels, alsa_rate; @@ -78,9 +79,9 @@ static int alsa_channels, alsa_rate; static void * alsa_buffer; static int alsa_buffer_length, alsa_buffer_data_start, alsa_buffer_data_length; -static int64_t alsa_time; /* microseconds */ +static int64_t alsa_written; /* frames */ static char alsa_prebuffer, alsa_paused; -static int alsa_paused_time; +static int alsa_paused_time; /* milliseconds */ static int poll_pipe[2]; static int poll_count; @@ -120,12 +121,15 @@ static char poll_setup (void) static void poll_sleep (void) { - char c; - - poll (poll_handles, poll_count, -1); + if (poll (poll_handles, poll_count, -1) < 0) + { + ERROR ("Failed to poll: %s.\n", strerror (errno)); + return; + } if (poll_handles[0].revents & POLLIN) { + char c; while (read (poll_pipe[0], & c, 1) == 1) ; } @@ -134,7 +138,6 @@ static void poll_sleep (void) static void poll_wake (void) { const char c = 0; - write (poll_pipe[1], & c, 1); } @@ -147,8 +150,6 @@ static void poll_cleanup (void) static void * pump (void * unused) { - int length, written; - pthread_mutex_lock (& alsa_mutex); pthread_cond_broadcast (& alsa_cond); /* signal thread started */ @@ -160,6 +161,7 @@ static void * pump (void * unused) continue; } + int length; CHECK_VAL_RECOVER (length, snd_pcm_avail_update, alsa_handle); if (! length) @@ -170,8 +172,10 @@ static void * pump (void * unused) length = MIN (length, alsa_buffer_length - alsa_buffer_data_start); length = snd_pcm_bytes_to_frames (alsa_handle, length); + int written; CHECK_VAL_RECOVER (written, snd_pcm_writei, alsa_handle, (char *) alsa_buffer + alsa_buffer_data_start, length); + written = snd_pcm_frames_to_bytes (alsa_handle, written); alsa_buffer_data_start += written; alsa_buffer_data_length -= written; @@ -236,20 +240,21 @@ FAILED: static int get_output_time (void) { - return (alsa_time - (int64_t) (snd_pcm_bytes_to_frames (alsa_handle, - alsa_buffer_data_length) + get_delay ()) * 1000000 / alsa_rate) / 1000; + return (int64_t) (alsa_written - snd_pcm_bytes_to_frames (alsa_handle, + alsa_buffer_data_length) - get_delay ()) * 1000 / alsa_rate; } OutputPluginInitStatus alsa_init (void) { alsa_handle = NULL; alsa_initted = 0; - return OUTPUT_PLUGIN_INIT_FOUND_DEVICES; } void alsa_soft_init (void) { + pthread_mutex_lock (& alsa_mutex); + if (! alsa_initted) { AUDDBG ("Initialize.\n"); @@ -257,6 +262,8 @@ void alsa_soft_init (void) alsa_open_mixer (); alsa_initted = 1; } + + pthread_mutex_unlock (& alsa_mutex); } void alsa_cleanup (void) @@ -294,57 +301,62 @@ static int convert_aud_format (int aud_format) {FMT_U32_BE, SND_PCM_FORMAT_U32_BE}, }; - int count; - - for (count = 0; count < G_N_ELEMENTS (table); count ++) + for (int count = 0; count < G_N_ELEMENTS (table); count ++) { - if (table[count].aud_format == aud_format) - return table[count].format; + if (table[count].aud_format == aud_format) + return table[count].format; } return SND_PCM_FORMAT_UNKNOWN; } -int alsa_open_audio (gint aud_format, int rate, int channels) +int alsa_open_audio (int aud_format, int rate, int channels) { - int format = convert_aud_format (aud_format); - snd_pcm_hw_params_t * params; - unsigned int useconds; - int direction; - snd_pcm_uframes_t frames, period; - int hard_buffer, soft_buffer; - - pthread_mutex_lock (& alsa_mutex); alsa_soft_init (); + pthread_mutex_lock (& alsa_mutex); + + assert (alsa_handle == NULL); + int format = convert_aud_format (aud_format); AUDDBG ("Opening PCM device %s for %s, %d channels, %d Hz.\n", alsa_config_pcm, snd_pcm_format_name (format), channels, rate); CHECK_NOISY (snd_pcm_open, & alsa_handle, alsa_config_pcm, SND_PCM_STREAM_PLAYBACK, 0); + snd_pcm_hw_params_t * params; snd_pcm_hw_params_alloca (& params); CHECK_NOISY (snd_pcm_hw_params_any, alsa_handle, params); CHECK_NOISY (snd_pcm_hw_params_set_access, alsa_handle, params, SND_PCM_ACCESS_RW_INTERLEAVED); + CHECK_NOISY (snd_pcm_hw_params_set_format, alsa_handle, params, format); CHECK_NOISY (snd_pcm_hw_params_set_channels, alsa_handle, params, channels); CHECK_NOISY (snd_pcm_hw_params_set_rate, alsa_handle, params, rate, 0); - useconds = 1000 * aud_cfg->output_buffer_size / 2; - direction = 0; - CHECK_NOISY (snd_pcm_hw_params_set_buffer_time_max, alsa_handle, params, - & useconds, & direction); - CHECK_NOISY (snd_pcm_hw_params, alsa_handle, params); alsa_format = format; alsa_channels = channels; alsa_rate = rate; - CHECK_NOISY (snd_pcm_get_params, alsa_handle, & frames, & period); - hard_buffer = (int64_t) frames * 1000 / rate; - soft_buffer = MAX (aud_cfg->output_buffer_size / 2, + unsigned int useconds = 1000 * MIN (1000, aud_cfg->output_buffer_size / 2); + int direction = 0; + CHECK_NOISY (snd_pcm_hw_params_set_buffer_time_near, alsa_handle, params, + & useconds, & direction); + int hard_buffer = useconds / 1000; + + useconds = 1000 * (hard_buffer / 4); + direction = 0; + CHECK_NOISY (snd_pcm_hw_params_set_period_time_near, alsa_handle, params, + & useconds, & direction); +#ifdef DEBUG + int period = useconds / 1000; +#endif + + CHECK_NOISY (snd_pcm_hw_params, alsa_handle, params); + + int soft_buffer = MAX (aud_cfg->output_buffer_size / 2, aud_cfg->output_buffer_size - hard_buffer); - AUDDBG ("Hardware buffer %d ms, software buffer %d ms.\n", hard_buffer, - soft_buffer); + AUDDBG ("Buffer: hardware %d ms, software %d ms, period %d ms.\n", + hard_buffer, soft_buffer, period); alsa_buffer_length = snd_pcm_frames_to_bytes (alsa_handle, (int64_t) soft_buffer * rate / 1000); @@ -352,7 +364,7 @@ int alsa_open_audio (gint aud_format, int rate, int channels) alsa_buffer_data_start = 0; alsa_buffer_data_length = 0; - alsa_time = 0; + alsa_written = 0; alsa_prebuffer = 1; alsa_paused = 0; alsa_paused_time = 0; @@ -381,6 +393,8 @@ void alsa_close_audio (void) AUDDBG ("Closing audio.\n"); pthread_mutex_lock (& alsa_mutex); + assert (alsa_handle != NULL); + pump_stop (); CHECK (snd_pcm_drop, alsa_handle); @@ -421,8 +435,7 @@ void alsa_write_audio (void * data, int length) memcpy ((char *) alsa_buffer + start, data, length); alsa_buffer_data_length += length; - alsa_time += (int64_t) snd_pcm_bytes_to_frames (alsa_handle, length) * - 1000000 / alsa_rate; + alsa_written += snd_pcm_bytes_to_frames (alsa_handle, length); pthread_mutex_unlock (& alsa_mutex); } @@ -449,8 +462,6 @@ void alsa_period_wait (void) void alsa_drain (void) { - int state; - AUDDBG ("Drain.\n"); pthread_mutex_lock (& alsa_mutex); @@ -478,6 +489,7 @@ void alsa_drain (void) { while (1) { + int state; CHECK_VAL (state, snd_pcm_state, alsa_handle); if (state != SND_PCM_STATE_RUNNING && state != @@ -501,31 +513,23 @@ void alsa_set_written_time (int time) { AUDDBG ("Setting time counter to %d.\n", time); pthread_mutex_lock (& alsa_mutex); - alsa_time = 1000 * (int64_t) time; + alsa_written = (int64_t) time * alsa_rate / 1000; pthread_mutex_unlock (& alsa_mutex); } int alsa_written_time (void) { - int time; - pthread_mutex_lock (& alsa_mutex); - time = alsa_time / 1000; + int time = (int64_t) alsa_written * 1000 / alsa_rate; pthread_mutex_unlock (& alsa_mutex); return time; } int alsa_output_time (void) { - int time = 0; - pthread_mutex_lock (& alsa_mutex); - - if (alsa_prebuffer || alsa_paused) - time = alsa_paused_time; - else - time = get_output_time (); - + int time = (alsa_prebuffer || alsa_paused) ? alsa_paused_time : + get_output_time (); pthread_mutex_unlock (& alsa_mutex); return time; } @@ -542,7 +546,7 @@ FAILED: alsa_buffer_data_start = 0; alsa_buffer_data_length = 0; - alsa_time = (int64_t) time * 1000; + alsa_written = (int64_t) time * alsa_rate / 1000; alsa_prebuffer = 1; alsa_paused_time = time; @@ -617,10 +621,10 @@ void alsa_close_mixer (void) void alsa_get_volume (int * left, int * right) { - long left_l = 0, right_l = 0; - - pthread_mutex_lock (& alsa_mutex); alsa_soft_init (); + pthread_mutex_lock (& alsa_mutex); + + long left_l = 0, right_l = 0; if (alsa_mixer == NULL) goto FAILED; @@ -650,8 +654,8 @@ FAILED: void alsa_set_volume (int left, int right) { - pthread_mutex_lock (& alsa_mutex); alsa_soft_init (); + pthread_mutex_lock (& alsa_mutex); if (alsa_mixer == NULL) goto FAILED; diff --git a/src/alsa/alsa.h b/src/alsa/alsa.h index b522b3a..890a98f 100644 --- a/src/alsa/alsa.h +++ b/src/alsa/alsa.h @@ -1,6 +1,6 @@ /* * ALSA Output Plugin for Audacious - * Copyright 2009 John Lindgren + * Copyright 2009-2010 John Lindgren * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: @@ -22,7 +22,6 @@ #include "../../config.h" -#include #include #include @@ -55,8 +54,6 @@ do { \ } while (0) /* alsa.c */ -extern pthread_mutex_t alsa_mutex; - OutputPluginInitStatus alsa_init (void); void alsa_soft_init (void); void alsa_cleanup (void); diff --git a/src/alsa/config.c b/src/alsa/config.c index a5c2231..20af5c1 100644 --- a/src/alsa/config.c +++ b/src/alsa/config.c @@ -536,9 +536,7 @@ static void connect_callbacks (void) void alsa_configure (void) { - pthread_mutex_lock (& alsa_mutex); alsa_soft_init (); - pthread_mutex_unlock (& alsa_mutex); if (window != NULL) { diff --git a/src/gtkui/ui_gtk.c b/src/gtkui/ui_gtk.c index fd1a625..bc44471 100644 --- a/src/gtkui/ui_gtk.c +++ b/src/gtkui/ui_gtk.c @@ -41,6 +41,10 @@ #include "actions-mainwin.h" #include "actions-playlist.h" +#if ! GTK_CHECK_VERSION (2, 18, 0) +#define gtk_widget_set_can_focus(w, t) do {if (t) GTK_WIDGET_SET_FLAGS ((w), GTK_CAN_FOCUS); else GTK_WIDGET_UNSET_FLAGS ((w), GTK_CAN_FOCUS);} while (0) +#endif + gboolean multi_column_view; static GtkWidget *label_time; diff --git a/src/gtkui/ui_infoarea.c b/src/gtkui/ui_infoarea.c index 5d7527c..64b6368 100644 --- a/src/gtkui/ui_infoarea.c +++ b/src/gtkui/ui_infoarea.c @@ -44,6 +44,10 @@ #define SPECT_BANDS 12 #define VIS_OFFSET (10 + 12 * SPECT_BANDS + 7) +#if ! GTK_CHECK_VERSION (2, 18, 0) +#define gtk_widget_get_allocation(w, ap) (* (ap) = (w)->allocation) +#endif + typedef struct { GtkWidget *parent; diff --git a/src/hotkey/plugin.c b/src/hotkey/plugin.c index c2c1bfb..1b42cfe 100644 --- a/src/hotkey/plugin.c +++ b/src/hotkey/plugin.c @@ -38,6 +38,7 @@ #include #include +#include #include #include diff --git a/src/resample/plugin.c b/src/resample/plugin.c index 8017f69..e2772b4 100644 --- a/src/resample/plugin.c +++ b/src/resample/plugin.c @@ -188,7 +188,11 @@ static void resample_configure (void) button = gtk_button_new_from_stock (GTK_STOCK_CLOSE); gtk_box_pack_end ((GtkBox *) hbox, button, FALSE, FALSE, 0); +#if GTK_CHECK_VERSION (2, 18, 0) gtk_widget_set_can_default (button, TRUE); +#else + GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT); +#endif gtk_widget_grab_default (button); g_signal_connect_swapped (button, "clicked", (GCallback) gtk_widget_destroy, window); -- cgit v1.2.3