From 229d9cb4e10c6fc89304c37308ad5fd23fba7736 Mon Sep 17 00:00:00 2001 From: Seungha Yang Date: Tue, 20 Feb 2024 20:38:55 +0900 Subject: [PATCH] asiosink: Fix channel selection Fixing copy paste mistake Fixes: https://gitlab.freedesktop.org/gstreamer/gstreamer/-/issues/3321 Part-of: --- .../sys/asio/gstasioobject.cpp | 2 +- .../gst-plugins-bad/sys/asio/gstasiosink.cpp | 40 ++++++++----------- .../gst-plugins-bad/sys/asio/gstasiosrc.cpp | 30 ++++++-------- 3 files changed, 30 insertions(+), 42 deletions(-) diff --git a/subprojects/gst-plugins-bad/sys/asio/gstasioobject.cpp b/subprojects/gst-plugins-bad/sys/asio/gstasioobject.cpp index 675ffc89ad..c14b1dd73b 100644 --- a/subprojects/gst-plugins-bad/sys/asio/gstasioobject.cpp +++ b/subprojects/gst-plugins-bad/sys/asio/gstasioobject.cpp @@ -734,7 +734,7 @@ gst_asio_object_thread_func (GstAsioObject * self) } self->output_channel_requested = - g_new0 (gboolean, self->max_num_input_channels); + g_new0 (gboolean, self->max_num_output_channels); } asio_rst = asio_handle->getSampleRate (&self->sample_rate); diff --git a/subprojects/gst-plugins-bad/sys/asio/gstasiosink.cpp b/subprojects/gst-plugins-bad/sys/asio/gstasiosink.cpp index 492e8fbb47..46b805ff5c 100644 --- a/subprojects/gst-plugins-bad/sys/asio/gstasiosink.cpp +++ b/subprojects/gst-plugins-bad/sys/asio/gstasiosink.cpp @@ -27,6 +27,7 @@ #include #include #include +#include GST_DEBUG_CATEGORY_STATIC (gst_asio_sink_debug); #define GST_CAT_DEFAULT gst_asio_sink_debug @@ -234,9 +235,8 @@ gst_asio_sink_create_ringbuffer (GstAudioBaseSink * sink) GstAsioObject *asio_object = nullptr; glong max_input_ch = 0; glong max_output_ch = 0; - guint *channel_indices = nullptr; - guint num_capture_channels = 0; std::set < guint > channel_list; + std::vector < guint > channel_indices; guint i; gchar *ringbuffer_name; @@ -286,27 +286,27 @@ gst_asio_sink_create_ringbuffer (GstAudioBaseSink * sink) /* Configure channels to use */ if (!gst_asio_object_get_max_num_channels (asio_object, &max_input_ch, - &max_output_ch) || max_input_ch <= 0) { - GST_WARNING_OBJECT (self, "No available input channels"); + &max_output_ch) || max_output_ch <= 0) { + GST_WARNING_OBJECT (self, "No available output channels"); goto out; } - /* Check if user requested specific channle(s) */ + /* Check if user requested specific channel(s) */ if (self->output_channels) { gchar **ch; ch = g_strsplit (self->output_channels, ",", 0); - num_capture_channels = g_strv_length (ch); - if (num_capture_channels > max_input_ch) { + auto num_channels = g_strv_length (ch); + if (num_channels > max_output_ch) { GST_WARNING_OBJECT (self, "To many channels %d were requested", - num_capture_channels); + num_channels); } else { - for (i = 0; i < num_capture_channels; i++) { + for (i = 0; i < num_channels; i++) { guint64 c = g_ascii_strtoull (ch[i], nullptr, 0); - if (c >= (guint64) max_input_ch) { + if (c >= (guint64) max_output_ch) { GST_WARNING_OBJECT (self, "Invalid channel index"); - num_capture_channels = 0; + channel_list.clear (); break; } @@ -317,18 +317,12 @@ gst_asio_sink_create_ringbuffer (GstAudioBaseSink * sink) g_strfreev (ch); } - channel_indices = (guint *) g_alloca (sizeof (guint) * max_input_ch); if (channel_list.size () == 0) { - for (i = 0; i < max_input_ch; i++) - channel_indices[i] = i; - - num_capture_channels = max_input_ch; + for (i = 0; i < max_output_ch; i++) + channel_indices.push_back (i); } else { - num_capture_channels = (guint) channel_list.size (); - i = 0; - for (auto iter:channel_list) { - channel_indices[i++] = iter; - } + for (auto iter : channel_indices) + channel_indices.push_back (iter); } ringbuffer_name = g_strdup_printf ("%s-asioringbuffer", @@ -344,8 +338,8 @@ gst_asio_sink_create_ringbuffer (GstAudioBaseSink * sink) goto out; } - if (!gst_asio_ring_buffer_configure (ringbuffer, channel_indices, - num_capture_channels, self->buffer_size)) { + if (!gst_asio_ring_buffer_configure (ringbuffer, channel_indices.data (), + channel_indices.size (), self->buffer_size)) { GST_WARNING_OBJECT (self, "Failed to configure ringbuffer"); gst_clear_object (&ringbuffer); goto out; diff --git a/subprojects/gst-plugins-bad/sys/asio/gstasiosrc.cpp b/subprojects/gst-plugins-bad/sys/asio/gstasiosrc.cpp index 47bbad5f08..b0f8b159fc 100644 --- a/subprojects/gst-plugins-bad/sys/asio/gstasiosrc.cpp +++ b/subprojects/gst-plugins-bad/sys/asio/gstasiosrc.cpp @@ -27,6 +27,7 @@ #include #include #include +#include GST_DEBUG_CATEGORY_STATIC (gst_asio_src_debug); #define GST_CAT_DEFAULT gst_asio_src_debug @@ -247,9 +248,8 @@ gst_asio_src_create_ringbuffer (GstAudioBaseSrc * src) GstAsioObject *asio_object = nullptr; glong max_input_ch = 0; glong max_output_ch = 0; - guint *channel_indices = nullptr; - guint num_capture_channels = 0; std::set < guint > channel_list; + std::vector < guint > channel_indices; guint i; gchar *ringbuffer_name; @@ -310,16 +310,16 @@ gst_asio_src_create_ringbuffer (GstAudioBaseSrc * src) ch = g_strsplit (self->capture_channles, ",", 0); - num_capture_channels = g_strv_length (ch); - if (num_capture_channels > max_input_ch) { + auto num_channels = g_strv_length (ch); + if (num_channels > max_input_ch) { GST_WARNING_OBJECT (self, "To many channels %d were requested", - num_capture_channels); + num_channels); } else { - for (i = 0; i < num_capture_channels; i++) { + for (i = 0; i < num_channels; i++) { guint64 c = g_ascii_strtoull (ch[i], nullptr, 0); if (c >= (guint64) max_input_ch) { GST_WARNING_OBJECT (self, "Invalid channel index"); - num_capture_channels = 0; + channel_list.clear (); break; } @@ -330,18 +330,12 @@ gst_asio_src_create_ringbuffer (GstAudioBaseSrc * src) g_strfreev (ch); } - channel_indices = (guint *) g_alloca (sizeof (guint) * max_input_ch); if (channel_list.size () == 0) { for (i = 0; i < max_input_ch; i++) - channel_indices[i] = i; - - num_capture_channels = max_input_ch; + channel_indices.push_back (i); } else { - num_capture_channels = (guint) channel_list.size (); - i = 0; - for (auto iter:channel_list) { - channel_indices[i++] = iter; - } + for (auto iter : channel_indices) + channel_indices.push_back (iter); } ringbuffer_name = g_strdup_printf ("%s-asioringbuffer", @@ -358,8 +352,8 @@ gst_asio_src_create_ringbuffer (GstAudioBaseSrc * src) goto out; } - if (!gst_asio_ring_buffer_configure (ringbuffer, channel_indices, - num_capture_channels, self->buffer_size)) { + if (!gst_asio_ring_buffer_configure (ringbuffer, channel_indices.data (), + channel_indices.size (), self->buffer_size)) { GST_WARNING_OBJECT (self, "Failed to configure ringbuffer"); gst_clear_object (&ringbuffer); goto out;