aboutsummaryrefslogtreecommitdiffstats
path: root/src/output
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2012-03-21 19:54:35 +0100
committerMax Kellermann <max@duempel.org>2012-03-21 21:16:50 +0100
commit170635e3a6fbbdb2274f6ecd164c2c363d4e80b4 (patch)
tree1065b6a3651ff07416835f1bdc42a32f9befe87a /src/output
parenta5d1444ef480952c73b429d43aadb943925e5aa1 (diff)
downloadmpd-170635e3a6fbbdb2274f6ecd164c2c363d4e80b4.tar.gz
mpd-170635e3a6fbbdb2274f6ecd164c2c363d4e80b4.tar.xz
mpd-170635e3a6fbbdb2274f6ecd164c2c363d4e80b4.zip
output/{alsa,oss}: move endian code to new library pcm_export
Diffstat (limited to 'src/output')
-rw-r--r--src/output/alsa_output_plugin.c41
-rw-r--r--src/output/oss_output_plugin.c43
2 files changed, 23 insertions, 61 deletions
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 <glib.h>
#include <alsa/asoundlib.h>
@@ -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;
diff --git a/src/output/oss_output_plugin.c b/src/output/oss_output_plugin.c
index ea15022d9..1b09c4b53 100644
--- a/src/output/oss_output_plugin.c
+++ b/src/output/oss_output_plugin.c
@@ -52,20 +52,14 @@
#endif
#ifdef AFMT_S24_PACKED
-#include "pcm_buffer.h"
-#include "pcm_byteswap.h"
+#include "pcm_export.h"
#endif
struct oss_data {
struct audio_output base;
#ifdef AFMT_S24_PACKED
- /**
- * The buffer used to reverse the byte order.
- *
- * @see #reverse_endian
- */
- struct pcm_buffer reverse_buffer;
+ struct pcm_export_state export;
#endif
int fd;
@@ -76,16 +70,6 @@ struct oss_data {
* the device after cancel().
*/
struct audio_format audio_format;
-
-#ifdef AFMT_S24_PACKED
- /**
- * Does OSS 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;
-#endif
};
/**
@@ -252,7 +236,7 @@ oss_output_enable(struct audio_output *ao, G_GNUC_UNUSED GError **error_r)
{
struct oss_data *od = (struct oss_data *)ao;
- pcm_buffer_init(&od->reverse_buffer);
+ pcm_export_init(&od->export);
return true;
}
@@ -261,7 +245,7 @@ oss_output_disable(struct audio_output *ao)
{
struct oss_data *od = (struct oss_data *)ao;
- pcm_buffer_deinit(&od->reverse_buffer);
+ pcm_export_deinit(&od->export);
}
#endif
@@ -517,7 +501,7 @@ sample_format_from_oss(int format)
static bool
oss_setup_sample_format(int fd, struct audio_format *audio_format,
#ifdef AFMT_S24_PACKED
- bool *reverse_endian_r,
+ struct pcm_export_state *export,
#endif
GError **error_r)
{
@@ -537,8 +521,9 @@ oss_setup_sample_format(int fd, struct audio_format *audio_format,
audio_format->format = mpd_format;
#ifdef AFMT_S24_PACKED
- *reverse_endian_r = oss_format == AFMT_S24_PACKED &&
- G_BYTE_ORDER != G_LITTLE_ENDIAN;
+ pcm_export_open(export, mpd_format,
+ oss_format == AFMT_S24_PACKED &&
+ G_BYTE_ORDER != G_LITTLE_ENDIAN);
#endif
return true;
@@ -583,8 +568,9 @@ oss_setup_sample_format(int fd, struct audio_format *audio_format,
audio_format->format = mpd_format;
#ifdef AFMT_S24_PACKED
- *reverse_endian_r = oss_format == AFMT_S24_PACKED &&
- G_BYTE_ORDER != G_LITTLE_ENDIAN;
+ pcm_export_open(export, mpd_format,
+ oss_format == AFMT_S24_PACKED &&
+ G_BYTE_ORDER != G_LITTLE_ENDIAN);
#endif
return true;
@@ -611,7 +597,7 @@ oss_setup(struct oss_data *od, struct audio_format *audio_format,
oss_setup_sample_rate(od->fd, audio_format, error_r) &&
oss_setup_sample_format(od->fd, audio_format,
#ifdef AFMT_S24_PACKED
- &od->reverse_endian,
+ &od->export,
#endif
error_r);
}
@@ -726,10 +712,7 @@ oss_output_play(struct audio_output *ao, const void *chunk, size_t size,
return 0;
#ifdef AFMT_S24_PACKED
- if (od->reverse_endian)
- chunk = pcm_byteswap(&od->reverse_buffer,
- od->audio_format.format,
- chunk, size);
+ chunk = pcm_export(&od->export, chunk, size, &size);
#endif
while (true) {