From 170635e3a6fbbdb2274f6ecd164c2c363d4e80b4 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 21 Mar 2012 19:54:35 +0100 Subject: output/{alsa,oss}: move endian code to new library pcm_export --- src/output/alsa_output_plugin.c | 41 ++++++++++------------------------------- 1 file changed, 10 insertions(+), 31 deletions(-) (limited to 'src/output/alsa_output_plugin.c') diff --git a/src/output/alsa_output_plugin.c b/src/output/alsa_output_plugin.c index 00312c435..7714e8a66 100644 --- a/src/output/alsa_output_plugin.c +++ b/src/output/alsa_output_plugin.c @@ -21,8 +21,7 @@ #include "alsa_output_plugin.h" #include "output_api.h" #include "mixer_list.h" -#include "pcm_buffer.h" -#include "pcm_byteswap.h" +#include "pcm_export.h" #include #include @@ -47,12 +46,7 @@ typedef snd_pcm_sframes_t alsa_writei_t(snd_pcm_t * pcm, const void *buffer, struct alsa_data { struct audio_output base; - /** - * The buffer used to reverse the byte order. - * - * @see #reverse_endian - */ - struct pcm_buffer reverse_buffer; + struct pcm_export_state export; /** the configured name of the ALSA device; NULL for the default device */ @@ -61,21 +55,6 @@ struct alsa_data { /** use memory mapped I/O? */ bool use_mmap; - /** - * Does ALSA expect samples in reverse byte order? (i.e. not - * host byte order) - * - * This attribute is only valid while the device is open. - */ - bool reverse_endian; - - /** - * Which sample format is being sent to the play() method? - * - * This attribute is only valid while the device is open. - */ - enum sample_format sample_format; - /** libasound's buffer_time setting (in microseconds) */ unsigned int buffer_time; @@ -196,7 +175,7 @@ alsa_output_enable(struct audio_output *ao, G_GNUC_UNUSED GError **error_r) { struct alsa_data *ad = (struct alsa_data *)ao; - pcm_buffer_init(&ad->reverse_buffer); + pcm_export_init(&ad->export); return true; } @@ -205,7 +184,7 @@ alsa_output_disable(struct audio_output *ao) { struct alsa_data *ad = (struct alsa_data *)ao; - pcm_buffer_deinit(&ad->reverse_buffer); + pcm_export_deinit(&ad->export); } static bool @@ -434,8 +413,9 @@ configure_hw: ad->writei = snd_pcm_writei; } + bool reverse_endian; err = alsa_output_setup_format(ad->pcm, hwparams, audio_format, - &ad->reverse_endian); + &reverse_endian); if (err < 0) { g_set_error(error, alsa_output_quark(), err, "ALSA device \"%s\" does not support format %s: %s", @@ -445,8 +425,6 @@ configure_hw: return false; } - ad->sample_format = audio_format->format; - err = snd_pcm_hw_params_set_channels_near(ad->pcm, hwparams, &channels); if (err < 0) { @@ -579,6 +557,9 @@ configure_hw: ad->period_frames = alsa_period_size; ad->period_position = 0; + pcm_export_open(&ad->export, audio_format->format, + reverse_endian); + return true; error: @@ -710,9 +691,7 @@ alsa_play(struct audio_output *ao, const void *chunk, size_t size, { struct alsa_data *ad = (struct alsa_data *)ao; - if (ad->reverse_endian) - chunk = pcm_byteswap(&ad->reverse_buffer, ad->sample_format, - chunk, size); + chunk = pcm_export(&ad->export, chunk, size, &size); size /= ad->frame_size; -- cgit v1.2.3