From e8e531ee12efc687f427a9596c824d63a219eb52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Tue, 3 Jan 2017 17:30:07 +0200 Subject: [PATCH] decklinkaudiosrc: Add support for 8/16 channels via property These are unpositioned channel layouts. --- sys/decklink/gstdecklink.cpp | 20 ++++++++++++++++ sys/decklink/gstdecklink.h | 8 +++++++ sys/decklink/gstdecklinkaudiosrc.cpp | 35 ++++++++++++++++++++++++---- sys/decklink/gstdecklinkaudiosrc.h | 1 + 4 files changed, 60 insertions(+), 4 deletions(-) diff --git a/sys/decklink/gstdecklink.cpp b/sys/decklink/gstdecklink.cpp index 1fe9005022..a795567e99 100644 --- a/sys/decklink/gstdecklink.cpp +++ b/sys/decklink/gstdecklink.cpp @@ -192,6 +192,26 @@ gst_decklink_audio_connection_get_type (void) return (GType) id; } +GType +gst_decklink_audio_channels_get_type (void) +{ + static gsize id = 0; + static const GEnumValue connections[] = { + {GST_DECKLINK_AUDIO_CHANNELS_2, "2 Channels", "2"}, + {GST_DECKLINK_AUDIO_CHANNELS_8, "8 Channels", "8"}, + {GST_DECKLINK_AUDIO_CHANNELS_16, "16 Channels", "16"}, + {0, NULL, NULL} + }; + + if (g_once_init_enter (&id)) { + GType tmp = + g_enum_register_static ("GstDecklinkAudioChannels", connections); + g_once_init_leave (&id, tmp); + } + + return (GType) id; +} + #define NTSC 10, 11, false, "bt601" #define PAL 12, 11, true, "bt601" #define HD 1, 1, true, "bt709" diff --git a/sys/decklink/gstdecklink.h b/sys/decklink/gstdecklink.h index 5ae38b2815..5b940334d4 100644 --- a/sys/decklink/gstdecklink.h +++ b/sys/decklink/gstdecklink.h @@ -110,6 +110,14 @@ typedef enum { #define GST_TYPE_DECKLINK_AUDIO_CONNECTION (gst_decklink_audio_connection_get_type ()) GType gst_decklink_audio_connection_get_type (void); +typedef enum { + GST_DECKLINK_AUDIO_CHANNELS_2 = 2, + GST_DECKLINK_AUDIO_CHANNELS_8 = 8, + GST_DECKLINK_AUDIO_CHANNELS_16 = 16 +} GstDecklinkAudioChannelsEnum; +#define GST_TYPE_DECKLINK_AUDIO_CHANNELS (gst_decklink_audio_channels_get_type ()) +GType gst_decklink_audio_channels_get_type (void); + typedef enum { GST_DECKLINK_VIDEO_FORMAT_AUTO, GST_DECKLINK_VIDEO_FORMAT_8BIT_YUV, /* bmdFormat8BitYUV */ diff --git a/sys/decklink/gstdecklinkaudiosrc.cpp b/sys/decklink/gstdecklinkaudiosrc.cpp index 04dc2f715d..4b9a353015 100644 --- a/sys/decklink/gstdecklinkaudiosrc.cpp +++ b/sys/decklink/gstdecklinkaudiosrc.cpp @@ -34,6 +34,7 @@ GST_DEBUG_CATEGORY_STATIC (gst_decklink_audio_src_debug); #define DEFAULT_ALIGNMENT_THRESHOLD (40 * GST_MSECOND) #define DEFAULT_DISCONT_WAIT (1 * GST_SECOND) +#define DEFAULT_CHANNELS (GST_DECKLINK_AUDIO_CHANNELS_2) enum { @@ -42,7 +43,8 @@ enum PROP_DEVICE_NUMBER, PROP_ALIGNMENT_THRESHOLD, PROP_DISCONT_WAIT, - PROP_BUFFER_SIZE + PROP_BUFFER_SIZE, + PROP_CHANNELS, }; static GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE ("src", @@ -50,6 +52,8 @@ static GstStaticPadTemplate sink_template = GST_STATIC_PAD_TEMPLATE ("src", GST_PAD_ALWAYS, GST_STATIC_CAPS ("audio/x-raw, format={S16LE,S32LE}, channels=2, rate=48000, " + "layout=interleaved;" + "audio/x-raw, format={S16LE,S32LE}, channels={8,16}, channel-mask=(bitmask)0, rate=48000, " "layout=interleaved") ); @@ -171,6 +175,13 @@ gst_decklink_audio_src_class_init (GstDecklinkAudioSrcClass * klass) G_MAXINT, DEFAULT_BUFFER_SIZE, (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); + g_object_class_install_property (gobject_class, PROP_CHANNELS, + g_param_spec_enum ("channels", "Channels", + "Audio channels", + GST_TYPE_DECKLINK_AUDIO_CHANNELS, DEFAULT_CHANNELS, + (GParamFlags) (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | + G_PARAM_CONSTRUCT))); + gst_element_class_add_static_pad_template (element_class, &sink_template); gst_element_class_set_static_metadata (element_class, "Decklink Audio Source", @@ -188,6 +199,7 @@ gst_decklink_audio_src_init (GstDecklinkAudioSrc * self) self->alignment_threshold = DEFAULT_ALIGNMENT_THRESHOLD; self->discont_wait = DEFAULT_DISCONT_WAIT; self->buffer_size = DEFAULT_BUFFER_SIZE; + self->channels = DEFAULT_CHANNELS; gst_base_src_set_live (GST_BASE_SRC (self), TRUE); gst_base_src_set_format (GST_BASE_SRC (self), GST_FORMAT_TIME); @@ -221,6 +233,9 @@ gst_decklink_audio_src_set_property (GObject * object, guint property_id, case PROP_BUFFER_SIZE: self->buffer_size = g_value_get_uint (value); break; + case PROP_CHANNELS: + self->channels = (GstDecklinkAudioChannelsEnum) g_value_get_enum (value); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; @@ -249,6 +264,9 @@ gst_decklink_audio_src_get_property (GObject * object, guint property_id, case PROP_BUFFER_SIZE: g_value_set_uint (value, self->buffer_size); break; + case PROP_CHANNELS: + g_value_set_enum (value, self->channels); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; @@ -383,7 +401,7 @@ gst_decklink_audio_src_set_caps (GstBaseSrc * bsrc, GstCaps * caps) } ret = self->input->input->EnableAudioInput (bmdAudioSampleRate48kHz, - sample_depth, 2); + sample_depth, self->info.channels); if (ret != S_OK) { GST_WARNING_OBJECT (self, "Failed to enable audio input: 0x%08x", ret); return FALSE; @@ -401,13 +419,22 @@ gst_decklink_audio_src_set_caps (GstBaseSrc * bsrc, GstCaps * caps) static GstCaps * gst_decklink_audio_src_get_caps (GstBaseSrc * bsrc, GstCaps * filter) { + GstDecklinkAudioSrc *self = GST_DECKLINK_AUDIO_SRC_CAST (bsrc); GstCaps *caps; // We don't support renegotiation caps = gst_pad_get_current_caps (GST_BASE_SRC_PAD (bsrc)); - if (!caps) - caps = gst_pad_get_pad_template_caps (GST_BASE_SRC_PAD (bsrc)); + if (!caps) { + GstCaps *channel_filter, *templ; + templ = gst_pad_get_pad_template_caps (GST_BASE_SRC_PAD (bsrc)); + channel_filter = + gst_caps_new_simple ("audio/x-raw", "channels", G_TYPE_INT, + self->channels, NULL); + caps = gst_caps_intersect (channel_filter, templ); + gst_caps_unref (channel_filter); + gst_caps_unref (templ); + } if (filter) { GstCaps *tmp = diff --git a/sys/decklink/gstdecklinkaudiosrc.h b/sys/decklink/gstdecklinkaudiosrc.h index 9d0af77d23..d6e2e079b6 100644 --- a/sys/decklink/gstdecklinkaudiosrc.h +++ b/sys/decklink/gstdecklinkaudiosrc.h @@ -52,6 +52,7 @@ struct _GstDecklinkAudioSrc GstDecklinkModeEnum mode; GstDecklinkAudioConnectionEnum connection; gint device_number; + GstDecklinkAudioChannelsEnum channels; GstAudioInfo info;