From 042e4398294bc1c567cb20c0fe295f77b094bc49 Mon Sep 17 00:00:00 2001 From: "Jan Alexander Steffens (heftig)" Date: Wed, 27 Nov 2019 15:38:39 +0100 Subject: [PATCH] rtmp2: Add gst_rtmp_message_is_metadata https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/merge_requests/878 --- gst/rtmp2/rtmp/rtmpmessage.c | 45 ++++++++++++++++++++++++++++++++++++ gst/rtmp2/rtmp/rtmpmessage.h | 2 ++ 2 files changed, 47 insertions(+) diff --git a/gst/rtmp2/rtmp/rtmpmessage.c b/gst/rtmp2/rtmp/rtmpmessage.c index cf93eb34d6..9a7d1bcca5 100644 --- a/gst/rtmp2/rtmp/rtmpmessage.c +++ b/gst/rtmp2/rtmp/rtmpmessage.c @@ -22,6 +22,7 @@ #include "config.h" #endif +#include "amf.h" #include "rtmpmessage.h" #include "rtmpchunkstream.h" @@ -493,3 +494,47 @@ gst_rtmp_message_new_user_control (GstRtmpUserControl * uc) return gst_rtmp_message_new_wrapped (GST_RTMP_MESSAGE_TYPE_USER_CONTROL, GST_RTMP_CHUNK_STREAM_PROTOCOL, 0, data, size); } + +gboolean +gst_rtmp_message_is_metadata (GstBuffer * buffer) +{ + GstRtmpMeta *meta = gst_buffer_get_rtmp_meta (buffer); + GstMapInfo map; + GstAmfNode *node; + gboolean ret = FALSE; + + g_return_val_if_fail (meta, FALSE); + + if (meta->type != GST_RTMP_MESSAGE_TYPE_DATA_AMF0) { + return FALSE; + } + + if (!gst_buffer_map (buffer, &map, GST_MAP_READ)) { + GST_ERROR ("can't map metadata message"); + return FALSE; + } + + node = gst_amf_node_parse (map.data, map.size, NULL); + if (!node) { + GST_ERROR ("can't read metadata name"); + goto err; + } + + switch (gst_amf_node_get_type (node)) { + case GST_AMF_TYPE_STRING: + case GST_AMF_TYPE_LONG_STRING:{ + const gchar *name = gst_amf_node_peek_string (node, NULL); + ret = (strcmp (name, "onMetaData") == 0); + break; + } + + default: + break; + } + + gst_amf_node_free (node); + +err: + gst_buffer_unmap (buffer, &map); + return ret; +} diff --git a/gst/rtmp2/rtmp/rtmpmessage.h b/gst/rtmp2/rtmp/rtmpmessage.h index 92f3fdc95c..9761d58159 100644 --- a/gst/rtmp2/rtmp/rtmpmessage.h +++ b/gst/rtmp2/rtmp/rtmpmessage.h @@ -137,6 +137,8 @@ gboolean gst_rtmp_message_parse_user_control (GstBuffer * buffer, GstBuffer * gst_rtmp_message_new_user_control (GstRtmpUserControl * uc); +gboolean gst_rtmp_message_is_metadata (GstBuffer * buffer); + G_END_DECLS #endif