From d9268a50f166921402d434a21b173733c06e6118 Mon Sep 17 00:00:00 2001 From: Guillaume Desmottes Date: Mon, 21 Mar 2016 05:09:10 -0400 Subject: [PATCH] alsa: factor out alsa_detect_channels_mapping() This code was duplicated in alsasrc and alsasink. https://bugzilla.gnome.org/show_bug.cgi?id=763985 --- ext/alsa/gstalsa.c | 15 +++++++++++++++ ext/alsa/gstalsa.h | 6 ++++++ ext/alsa/gstalsasink.c | 12 ++---------- ext/alsa/gstalsasrc.c | 12 ++---------- 4 files changed, 25 insertions(+), 20 deletions(-) diff --git a/ext/alsa/gstalsa.c b/ext/alsa/gstalsa.c index 9d2a9733ab..ea4b74b158 100644 --- a/ext/alsa/gstalsa.c +++ b/ext/alsa/gstalsa.c @@ -761,4 +761,19 @@ alsa_chmap_to_channel_positions (const snd_pcm_chmap_t * chmap, } return TRUE; } + +void +alsa_detect_channels_mapping (GstObject * obj, snd_pcm_t * handle, + GstAudioRingBufferSpec * spec, guint channels, GstAudioRingBuffer * buf) +{ + if (spec->type == GST_AUDIO_RING_BUFFER_FORMAT_TYPE_RAW && channels < 9) { + snd_pcm_chmap_t *chmap = snd_pcm_get_chmap (handle); + if (chmap && chmap->channels == channels) { + GstAudioChannelPosition pos[8]; + if (alsa_chmap_to_channel_positions (chmap, pos)) + gst_audio_ring_buffer_set_channel_positions (buf, pos); + } + free (chmap); + } +} #endif /* SND_CHMAP_API_VERSION */ diff --git a/ext/alsa/gstalsa.h b/ext/alsa/gstalsa.h index 3c3d2d6561..56fa07526b 100644 --- a/ext/alsa/gstalsa.h +++ b/ext/alsa/gstalsa.h @@ -74,6 +74,12 @@ extern const GstAudioChannelPosition alsa_position[][8]; #ifdef SND_CHMAP_API_VERSION gboolean alsa_chmap_to_channel_positions (const snd_pcm_chmap_t *chmap, GstAudioChannelPosition *pos); + +void alsa_detect_channels_mapping (GstObject * obj, + snd_pcm_t * handle, + GstAudioRingBufferSpec * spec, + guint channels, + GstAudioRingBuffer * buf); #endif #endif /* __GST_ALSA_H__ */ diff --git a/ext/alsa/gstalsasink.c b/ext/alsa/gstalsasink.c index 2d81f52bf2..86606f7164 100644 --- a/ext/alsa/gstalsasink.c +++ b/ext/alsa/gstalsasink.c @@ -909,16 +909,8 @@ gst_alsasink_prepare (GstAudioSink * asink, GstAudioRingBufferSpec * spec) } #ifdef SND_CHMAP_API_VERSION - if (spec->type == GST_AUDIO_RING_BUFFER_FORMAT_TYPE_RAW && alsa->channels < 9) { - snd_pcm_chmap_t *chmap = snd_pcm_get_chmap (alsa->handle); - if (chmap && chmap->channels == alsa->channels) { - GstAudioChannelPosition pos[8]; - if (alsa_chmap_to_channel_positions (chmap, pos)) - gst_audio_ring_buffer_set_channel_positions (GST_AUDIO_BASE_SINK - (alsa)->ringbuffer, pos); - } - free (chmap); - } + alsa_detect_channels_mapping (GST_OBJECT (alsa), alsa->handle, spec, + alsa->channels, GST_AUDIO_BASE_SINK (alsa)->ringbuffer); #endif /* SND_CHMAP_API_VERSION */ return TRUE; diff --git a/ext/alsa/gstalsasrc.c b/ext/alsa/gstalsasrc.c index 8cf148e806..74b8bf9483 100644 --- a/ext/alsa/gstalsasrc.c +++ b/ext/alsa/gstalsasrc.c @@ -785,16 +785,8 @@ gst_alsasrc_prepare (GstAudioSrc * asrc, GstAudioRingBufferSpec * spec) } #ifdef SND_CHMAP_API_VERSION - if (spec->type == GST_AUDIO_RING_BUFFER_FORMAT_TYPE_RAW && alsa->channels < 9) { - snd_pcm_chmap_t *chmap = snd_pcm_get_chmap (alsa->handle); - if (chmap && chmap->channels == alsa->channels) { - GstAudioChannelPosition pos[8]; - if (alsa_chmap_to_channel_positions (chmap, pos)) - gst_audio_ring_buffer_set_channel_positions (GST_AUDIO_BASE_SRC - (alsa)->ringbuffer, pos); - } - free (chmap); - } + alsa_detect_channels_mapping (GST_OBJECT (alsa), alsa->handle, spec, + alsa->channels, GST_AUDIO_BASE_SRC (alsa)->ringbuffer); #endif /* SND_CHMAP_API_VERSION */ return TRUE;