alsa: factor out alsa_detect_channels_mapping()

This code was duplicated in alsasrc and alsasink.

https://bugzilla.gnome.org/show_bug.cgi?id=763985
This commit is contained in:
Guillaume Desmottes 2016-03-21 05:09:10 -04:00 committed by Nicolas Dufresne
parent 592b87a463
commit d9268a50f1
4 changed files with 25 additions and 20 deletions

View file

@ -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 */

View file

@ -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__ */

View file

@ -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;

View file

@ -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;