mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-04-26 04:46:13 +00:00
rtmp2: Add single-value AMF0 parsing and serializing
https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/merge_requests/878
This commit is contained in:
parent
f5b068b26c
commit
8f1ae04ac5
2 changed files with 70 additions and 0 deletions
|
@ -886,6 +886,47 @@ parse_value (AmfParser * parser)
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GstAmfNode *
|
||||||
|
gst_amf_node_parse (const guint8 * data, gsize size, guint8 ** endptr)
|
||||||
|
{
|
||||||
|
AmfParser parser = {
|
||||||
|
.data = data,
|
||||||
|
.size = size,
|
||||||
|
};
|
||||||
|
GstAmfNode *node;
|
||||||
|
|
||||||
|
g_return_val_if_fail (data, NULL);
|
||||||
|
g_return_val_if_fail (size, NULL);
|
||||||
|
|
||||||
|
init_static ();
|
||||||
|
|
||||||
|
GST_TRACE ("Starting parse with %" G_GSIZE_FORMAT " bytes", parser.size);
|
||||||
|
|
||||||
|
node = parse_value (&parser);
|
||||||
|
if (gst_amf_node_get_type (node) == GST_AMF_TYPE_INVALID) {
|
||||||
|
GST_ERROR ("invalid value");
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (G_UNLIKELY (GST_LEVEL_LOG <= _gst_debug_min) &&
|
||||||
|
GST_LEVEL_LOG <= gst_debug_category_get_threshold (GST_CAT_DEFAULT)) {
|
||||||
|
GString *string = g_string_new (NULL);
|
||||||
|
gst_amf_node_dump (node, -1, string);
|
||||||
|
GST_LOG ("Parsed value: %s", string->str);
|
||||||
|
g_string_free (string, TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
GST_TRACE ("Done parsing; consumed %" G_GSIZE_FORMAT " bytes and left %"
|
||||||
|
G_GSIZE_FORMAT " bytes", parser.offset, parser.size - parser.offset);
|
||||||
|
|
||||||
|
out:
|
||||||
|
if (endptr) {
|
||||||
|
*endptr = (guint8 *) parser.data + parser.offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
|
||||||
GPtrArray *
|
GPtrArray *
|
||||||
gst_amf_parse_command (const guint8 * data, gsize size,
|
gst_amf_parse_command (const guint8 * data, gsize size,
|
||||||
gdouble * transaction_id, gchar ** command_name)
|
gdouble * transaction_id, gchar ** command_name)
|
||||||
|
@ -1093,6 +1134,30 @@ serialize_value (GByteArray * array, const GstAmfNode * node)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GBytes *
|
||||||
|
gst_amf_node_serialize (const GstAmfNode * node)
|
||||||
|
{
|
||||||
|
GByteArray *array = g_byte_array_new ();
|
||||||
|
|
||||||
|
g_return_val_if_fail (node, NULL);
|
||||||
|
|
||||||
|
init_static ();
|
||||||
|
|
||||||
|
if (G_UNLIKELY (GST_LEVEL_LOG <= _gst_debug_min) &&
|
||||||
|
GST_LEVEL_LOG <= gst_debug_category_get_threshold (GST_CAT_DEFAULT)) {
|
||||||
|
GString *string = g_string_new (NULL);
|
||||||
|
gst_amf_node_dump (node, -1, string);
|
||||||
|
GST_LOG ("Serializing value: %s", string->str);
|
||||||
|
g_string_free (string, TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
serialize_value (array, node);
|
||||||
|
|
||||||
|
GST_TRACE ("Done serializing; produced %u bytes", array->len);
|
||||||
|
|
||||||
|
return g_byte_array_free_to_bytes (array);
|
||||||
|
}
|
||||||
|
|
||||||
GBytes *
|
GBytes *
|
||||||
gst_amf_serialize_command (gdouble transaction_id, const gchar * command_name,
|
gst_amf_serialize_command (gdouble transaction_id, const gchar * command_name,
|
||||||
const GstAmfNode * argument, ...)
|
const GstAmfNode * argument, ...)
|
||||||
|
|
|
@ -100,9 +100,14 @@ void gst_amf_node_append_field_take_string (GstAmfNode * node,
|
||||||
void gst_amf_node_dump (const GstAmfNode * node, gint indent,
|
void gst_amf_node_dump (const GstAmfNode * node, gint indent,
|
||||||
GString * string);
|
GString * string);
|
||||||
|
|
||||||
|
GstAmfNode * gst_amf_node_parse (const guint8 * data, gsize size,
|
||||||
|
guint8 ** endptr);
|
||||||
|
|
||||||
GPtrArray * gst_amf_parse_command (const guint8 * data, gsize size,
|
GPtrArray * gst_amf_parse_command (const guint8 * data, gsize size,
|
||||||
gdouble * transaction_id, gchar ** command_name);
|
gdouble * transaction_id, gchar ** command_name);
|
||||||
|
|
||||||
|
GBytes * gst_amf_node_serialize (const GstAmfNode * node);
|
||||||
|
|
||||||
GBytes * gst_amf_serialize_command (gdouble transaction_id,
|
GBytes * gst_amf_serialize_command (gdouble transaction_id,
|
||||||
const gchar * command_name, const GstAmfNode * argument, ...) G_GNUC_NULL_TERMINATED;
|
const gchar * command_name, const GstAmfNode * argument, ...) G_GNUC_NULL_TERMINATED;
|
||||||
GBytes * gst_amf_serialize_command_valist (gdouble transaction_id,
|
GBytes * gst_amf_serialize_command_valist (gdouble transaction_id,
|
||||||
|
|
Loading…
Reference in a new issue