mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-02-17 03:35:21 +00:00
Proxy CAPS query from ajasrcdemux source pads to ajasrc
This commit is contained in:
parent
0df1d6dad9
commit
3dbbf20451
1 changed files with 132 additions and 2 deletions
|
@ -43,6 +43,12 @@ static GstFlowReturn gst_aja_src_demux_sink_chain(GstPad *pad,
|
|||
GstBuffer *buffer);
|
||||
static gboolean gst_aja_src_demux_sink_event(GstPad *pad, GstObject *parent,
|
||||
GstEvent *event);
|
||||
static gboolean gst_aja_src_demux_audio_src_query(GstPad *pad,
|
||||
GstObject *parent,
|
||||
GstQuery *query);
|
||||
static gboolean gst_aja_src_demux_video_src_query(GstPad *pad,
|
||||
GstObject *parent,
|
||||
GstQuery *query);
|
||||
|
||||
#define parent_class gst_aja_src_demux_parent_class
|
||||
G_DEFINE_TYPE(GstAjaSrcDemux, gst_aja_src_demux, GST_TYPE_ELEMENT);
|
||||
|
@ -73,12 +79,14 @@ static void gst_aja_src_demux_init(GstAjaSrcDemux *self) {
|
|||
|
||||
self->audio_src =
|
||||
gst_pad_new_from_static_template(&audio_src_template, "audio");
|
||||
gst_pad_use_fixed_caps(self->audio_src);
|
||||
gst_pad_set_query_function(
|
||||
self->audio_src, GST_DEBUG_FUNCPTR(gst_aja_src_demux_audio_src_query));
|
||||
gst_element_add_pad(GST_ELEMENT(self), self->audio_src);
|
||||
|
||||
self->video_src =
|
||||
gst_pad_new_from_static_template(&video_src_template, "video");
|
||||
gst_pad_use_fixed_caps(self->video_src);
|
||||
gst_pad_set_query_function(
|
||||
self->video_src, GST_DEBUG_FUNCPTR(gst_aja_src_demux_video_src_query));
|
||||
gst_element_add_pad(GST_ELEMENT(self), self->video_src);
|
||||
}
|
||||
|
||||
|
@ -160,3 +168,125 @@ static gboolean gst_aja_src_demux_sink_event(GstPad *pad, GstObject *parent,
|
|||
return gst_pad_event_default(pad, parent, event);
|
||||
}
|
||||
}
|
||||
|
||||
static gboolean gst_aja_src_demux_audio_src_query(GstPad *pad,
|
||||
GstObject *parent,
|
||||
GstQuery *query) {
|
||||
GstAjaSrcDemux *self = GST_AJA_SRC_DEMUX(parent);
|
||||
|
||||
switch (GST_QUERY_TYPE(query)) {
|
||||
case GST_QUERY_CAPS: {
|
||||
GstCaps *filter, *caps;
|
||||
|
||||
gst_query_parse_caps(query, &filter);
|
||||
if ((caps = gst_pad_get_current_caps(pad))) {
|
||||
GST_DEBUG_OBJECT(
|
||||
pad, "Returning currently negotiated caps %" GST_PTR_FORMAT, caps);
|
||||
} else if ((caps = gst_pad_peer_query_caps(self->sink, NULL))) {
|
||||
guint n;
|
||||
GstAudioInfo audio_info;
|
||||
gint audio_channels = 0;
|
||||
GstCaps *tmp;
|
||||
|
||||
GST_DEBUG_OBJECT(pad, "Got upstream caps %" GST_PTR_FORMAT, caps);
|
||||
|
||||
n = gst_caps_get_size(caps);
|
||||
for (guint i = 0; i < n; i++) {
|
||||
GstStructure *s = gst_caps_get_structure(caps, i);
|
||||
gint tmp;
|
||||
|
||||
if (!gst_structure_get_int(s, "audio-channels", &tmp)) {
|
||||
tmp = 0;
|
||||
}
|
||||
|
||||
// No audio channels in all caps
|
||||
if (tmp == 0 || (audio_channels != 0 && audio_channels != tmp)) {
|
||||
audio_channels = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
audio_channels = tmp;
|
||||
}
|
||||
|
||||
gst_audio_info_init(&audio_info);
|
||||
gst_audio_info_set_format(&audio_info, GST_AUDIO_FORMAT_S32LE, 48000,
|
||||
audio_channels ? audio_channels : 1, NULL);
|
||||
tmp = gst_audio_info_to_caps(&audio_info);
|
||||
gst_caps_unref(caps);
|
||||
caps = tmp;
|
||||
|
||||
if (!audio_channels) {
|
||||
gst_caps_set_simple(caps, "channels", GST_TYPE_INT_RANGE, 1, G_MAXINT,
|
||||
NULL);
|
||||
}
|
||||
|
||||
GST_DEBUG_OBJECT(pad, "Returning caps %" GST_PTR_FORMAT, caps);
|
||||
} else {
|
||||
caps = gst_pad_get_pad_template_caps(pad);
|
||||
|
||||
GST_DEBUG_OBJECT(pad, "Returning template caps %" GST_PTR_FORMAT, caps);
|
||||
}
|
||||
|
||||
if (filter) {
|
||||
GstCaps *tmp =
|
||||
gst_caps_intersect_full(filter, caps, GST_CAPS_INTERSECT_FIRST);
|
||||
gst_caps_unref(caps);
|
||||
caps = tmp;
|
||||
}
|
||||
|
||||
gst_query_set_caps_result(query, caps);
|
||||
gst_caps_unref(caps);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
default:
|
||||
return gst_pad_query_default(pad, parent, query);
|
||||
}
|
||||
}
|
||||
|
||||
static gboolean gst_aja_src_demux_video_src_query(GstPad *pad,
|
||||
GstObject *parent,
|
||||
GstQuery *query) {
|
||||
GstAjaSrcDemux *self = GST_AJA_SRC_DEMUX(parent);
|
||||
|
||||
switch (GST_QUERY_TYPE(query)) {
|
||||
case GST_QUERY_CAPS: {
|
||||
GstCaps *filter, *caps;
|
||||
|
||||
gst_query_parse_caps(query, &filter);
|
||||
if ((caps = gst_pad_get_current_caps(pad))) {
|
||||
GST_DEBUG_OBJECT(
|
||||
pad, "Returning currently negotiated caps %" GST_PTR_FORMAT, caps);
|
||||
} else if ((caps = gst_pad_peer_query_caps(self->sink, NULL))) {
|
||||
guint n;
|
||||
|
||||
GST_DEBUG_OBJECT(pad, "Returning upstream caps %" GST_PTR_FORMAT, caps);
|
||||
|
||||
caps = gst_caps_make_writable(caps);
|
||||
n = gst_caps_get_size(caps);
|
||||
for (guint i = 0; i < n; i++) {
|
||||
GstStructure *s = gst_caps_get_structure(caps, i);
|
||||
gst_structure_remove_field(s, "audio-channels");
|
||||
}
|
||||
} else {
|
||||
caps = gst_pad_get_pad_template_caps(pad);
|
||||
|
||||
GST_DEBUG_OBJECT(pad, "Returning template caps %" GST_PTR_FORMAT, caps);
|
||||
}
|
||||
|
||||
if (filter) {
|
||||
GstCaps *tmp =
|
||||
gst_caps_intersect_full(filter, caps, GST_CAPS_INTERSECT_FIRST);
|
||||
gst_caps_unref(caps);
|
||||
caps = tmp;
|
||||
}
|
||||
|
||||
gst_query_set_caps_result(query, caps);
|
||||
gst_caps_unref(caps);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
default:
|
||||
return gst_pad_query_default(pad, parent, query);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue