Skip to content

Commit af66cbd

Browse files
fix android udp h264 video record (#10611)
Co-authored-by: Luiz Kressin <luiz.kressin@gmail.com>
1 parent d1c850c commit af66cbd

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

src/VideoReceiver/GstVideoReceiver.cc

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,58 @@ GstVideoReceiver::_handleEOS(void)
683683
}
684684
}
685685

686+
gboolean
687+
GstVideoReceiver::_filterParserCaps(GstElement* bin, GstPad* pad, GstElement* element, GstQuery* query, gpointer data)
688+
{
689+
Q_UNUSED(bin)
690+
Q_UNUSED(pad)
691+
Q_UNUSED(element)
692+
Q_UNUSED(data)
693+
694+
if (GST_QUERY_TYPE(query) != GST_QUERY_CAPS) {
695+
return FALSE;
696+
}
697+
698+
GstCaps* srcCaps;
699+
700+
gst_query_parse_caps(query, &srcCaps);
701+
702+
if (srcCaps == nullptr || gst_caps_is_any(srcCaps)) {
703+
return FALSE;
704+
}
705+
706+
GstCaps* sinkCaps = nullptr;
707+
708+
GstCaps* filter;
709+
710+
if ((filter = gst_caps_from_string("video/x-h264")) != nullptr) {
711+
if (gst_caps_can_intersect(srcCaps, filter)) {
712+
sinkCaps = gst_caps_from_string("video/x-h264,stream-format=avc");
713+
}
714+
715+
gst_caps_unref(filter);
716+
filter = nullptr;
717+
} else if ((filter = gst_caps_from_string("video/x-h265")) != nullptr) {
718+
if (gst_caps_can_intersect(srcCaps, filter)) {
719+
sinkCaps = gst_caps_from_string("video/x-h265,stream-format=hvc1");
720+
}
721+
722+
gst_caps_unref(filter);
723+
filter = nullptr;
724+
}
725+
726+
if (sinkCaps == nullptr) {
727+
return FALSE;
728+
}
729+
730+
gst_query_set_caps_result(query, sinkCaps);
731+
732+
gst_caps_unref(sinkCaps);
733+
sinkCaps = nullptr;
734+
735+
return TRUE;
736+
}
737+
686738
GstElement*
687739
GstVideoReceiver::_makeSource(const QString& uri)
688740
{
@@ -759,6 +811,8 @@ GstVideoReceiver::_makeSource(const QString& uri)
759811
break;
760812
}
761813

814+
g_signal_connect(parser, "autoplug-query", G_CALLBACK(_filterParserCaps), nullptr);
815+
762816
gst_bin_add_many(GST_BIN(bin), source, parser, nullptr);
763817

764818
// FIXME: AV: Android does not determine MPEG2-TS via parsebin - have to explicitly state which demux to use

src/VideoReceiver/GstVideoReceiver.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ protected slots:
125125
static void _wrapWithGhostPad(GstElement* element, GstPad* pad, gpointer data);
126126
static void _linkPad(GstElement* element, GstPad* pad, gpointer data);
127127
static gboolean _padProbe(GstElement* element, GstPad* pad, gpointer user_data);
128+
static gboolean _filterParserCaps(GstElement* bin, GstPad* pad, GstElement* element, GstQuery* query, gpointer data);
128129
static GstPadProbeReturn _teeProbe(GstPad* pad, GstPadProbeInfo* info, gpointer user_data);
129130
static GstPadProbeReturn _videoSinkProbe(GstPad* pad, GstPadProbeInfo* info, gpointer user_data);
130131
static GstPadProbeReturn _eosProbe(GstPad* pad, GstPadProbeInfo* info, gpointer user_data);

0 commit comments

Comments
 (0)