diff options
author | Jan Alexander Steffens (heftig) <jsteffens@make.tv> | 2019-11-27 15:38:39 +0100 |
---|---|---|
committer | Jan Alexander Steffens (heftig) <jsteffens@make.tv> | 2019-12-03 14:11:47 +0100 |
commit | 042e4398294bc1c567cb20c0fe295f77b094bc49 (patch) | |
tree | 96ff2b22ccf52ef672ab4ad5aa8a5eabffddc8ef /gst/rtmp2 | |
parent | e07a1bb48f88e662d1aeda3631e4720952cf13d7 (diff) | |
download | gstreamer-plugins-bad-042e4398294bc1c567cb20c0fe295f77b094bc49.tar.gz |
rtmp2: Add gst_rtmp_message_is_metadata
https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/merge_requests/878
Diffstat (limited to 'gst/rtmp2')
-rw-r--r-- | gst/rtmp2/rtmp/rtmpmessage.c | 45 | ||||
-rw-r--r-- | gst/rtmp2/rtmp/rtmpmessage.h | 2 |
2 files changed, 47 insertions, 0 deletions
diff --git a/gst/rtmp2/rtmp/rtmpmessage.c b/gst/rtmp2/rtmp/rtmpmessage.c index cf93eb34d..9a7d1bcca 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 92f3fdc95..9761d5815 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 |