diff options
author | David Schleef <ds@schleef.org> | 2014-09-01 19:07:41 -0700 |
---|---|---|
committer | David Schleef <ds@schleef.org> | 2014-09-01 19:07:41 -0700 |
commit | d5b4e3cd5a19fcb86cbbe2125be48bd24e4faba3 (patch) | |
tree | 9906ac6615de0678216dd477dd28687db23d2506 | |
parent | c61055beacf664e072ca763525d110756da98862 (diff) |
refactor dump_chunk
-rw-r--r-- | plugins/gstrtmp2sink.c | 42 | ||||
-rw-r--r-- | plugins/gstrtmp2src.c | 38 | ||||
-rw-r--r-- | rtmp/rtmputils.c | 41 | ||||
-rw-r--r-- | rtmp/rtmputils.h | 3 | ||||
-rw-r--r-- | tools/client-test.c | 41 | ||||
-rw-r--r-- | tools/proxy-server.c | 43 |
6 files changed, 51 insertions, 157 deletions
diff --git a/plugins/gstrtmp2sink.c b/plugins/gstrtmp2sink.c index b16ec74..dccdaa9 100644 --- a/plugins/gstrtmp2sink.c +++ b/plugins/gstrtmp2sink.c @@ -100,8 +100,6 @@ static void publish_done (GstRtmpConnection * connection, gpointer user_data); static void got_chunk (GstRtmpConnection * connection, GstRtmpChunk * chunk, gpointer user_data); -static void dump_command (GstRtmpChunk * chunk); -static void dump_chunk (GstRtmpChunk * chunk, gboolean dir); static void send_secure_token_response (GstRtmp2Sink * rtmp2sink, const char *challenge); @@ -506,7 +504,7 @@ gst_rtmp2_sink_render (GstBaseSink * sink, GstBuffer * buffer) } if (rtmp2sink->dump) { - dump_chunk (chunk, TRUE); + gst_rtmp_dump_chunk (chunk, TRUE, TRUE, TRUE); } gst_rtmp_connection_queue_chunk (rtmp2sink->connection, chunk); @@ -820,47 +818,11 @@ got_chunk (GstRtmpConnection * connection, GstRtmpChunk * chunk, GstRtmp2Sink *rtmp2sink = GST_RTMP2_SINK (user_data); if (rtmp2sink->dump) { - dump_chunk (chunk, FALSE); + gst_rtmp_dump_chunk (chunk, FALSE, TRUE, TRUE); } } static void -dump_command (GstRtmpChunk * chunk) -{ - GstAmfNode *amf; - gsize size; - const guint8 *data; - gsize n_parsed; - int offset; - - offset = 0; - data = g_bytes_get_data (chunk->payload, &size); - while (offset < size) { - amf = gst_amf_node_new_parse (data + offset, size - offset, &n_parsed); - gst_amf_node_dump (amf); - gst_amf_node_free (amf); - offset += n_parsed; - } -} - -static void -dump_chunk (GstRtmpChunk * chunk, gboolean dir) -{ - g_print ("%s chunk_stream_id:%-4d ts:%-8d len:%-6" G_GSIZE_FORMAT - " type_id:%-4d stream_id:%08x\n", dir ? ">>>" : "<<<", - chunk->chunk_stream_id, - chunk->timestamp, - chunk->message_length, chunk->message_type_id, chunk->stream_id); - if (chunk->message_type_id == 20) { - dump_command (chunk); - } - if (chunk->message_type_id == 18) { - dump_command (chunk); - } - gst_rtmp_dump_data (gst_rtmp_chunk_get_payload (chunk)); -} - -static void send_secure_token_response (GstRtmp2Sink * rtmp2sink, const char *challenge) { GstAmfNode *node1; diff --git a/plugins/gstrtmp2src.c b/plugins/gstrtmp2src.c index 156a6b4..7648097 100644 --- a/plugins/gstrtmp2src.c +++ b/plugins/gstrtmp2src.c @@ -409,49 +409,13 @@ connect_done (GObject * source, GAsyncResult * result, gpointer user_data) } static void -dump_command (GstRtmpChunk * chunk) -{ - GstAmfNode *amf; - gsize size; - const guint8 *data; - gsize n_parsed; - int offset; - - offset = 0; - data = g_bytes_get_data (chunk->payload, &size); - while (offset < size) { - amf = gst_amf_node_new_parse (data + offset, size - offset, &n_parsed); - gst_amf_node_dump (amf); - gst_amf_node_free (amf); - offset += n_parsed; - } -} - -static void -dump_chunk (GstRtmpChunk * chunk, gboolean dir) -{ - g_print ("%s chunk_stream_id:%-4d ts:%-8d len:%-6" G_GSIZE_FORMAT - " type_id:%-4d stream_id:%08x\n", dir ? ">>>" : "<<<", - chunk->chunk_stream_id, - chunk->timestamp, - chunk->message_length, chunk->message_type_id, chunk->stream_id); - if (chunk->message_type_id == 20) { - dump_command (chunk); - } - if (chunk->message_type_id == 18) { - dump_command (chunk); - } - gst_rtmp_dump_data (gst_rtmp_chunk_get_payload (chunk)); -} - -static void got_chunk (GstRtmpConnection * connection, GstRtmpChunk * chunk, gpointer user_data) { GstRtmp2Src *rtmp2src = GST_RTMP2_SRC (user_data); if (rtmp2src->dump) { - dump_chunk (chunk, FALSE); + gst_rtmp_dump_chunk (chunk, FALSE, TRUE, TRUE); } if ((chunk->chunk_stream_id == 7 && chunk->message_type_id == 9) || diff --git a/rtmp/rtmputils.c b/rtmp/rtmputils.c index c479680..3472f35 100644 --- a/rtmp/rtmputils.c +++ b/rtmp/rtmputils.c @@ -180,3 +180,44 @@ gst_rtmp_tea_decode (const gchar * key, const gchar * text) return (gchar *) out; } + +static void +dump_command (GstRtmpChunk * chunk) +{ + GstAmfNode *amf; + gsize size; + const guint8 *data; + gsize n_parsed; + int offset; + + offset = 0; + data = g_bytes_get_data (chunk->payload, &size); + while (offset < size) { + amf = gst_amf_node_new_parse (data + offset, size - offset, &n_parsed); + gst_amf_node_dump (amf); + gst_amf_node_free (amf); + offset += n_parsed; + } +} + +void +gst_rtmp_dump_chunk (GstRtmpChunk * chunk, gboolean dir, gboolean dump_message, + gboolean dump_data) +{ + g_print ("%s chunk_stream_id:%-4d ts:%-8d len:%-6" G_GSIZE_FORMAT + " type_id:%-4d stream_id:%08x\n", dir ? ">>>" : "<<<", + chunk->chunk_stream_id, + chunk->timestamp, + chunk->message_length, chunk->message_type_id, chunk->stream_id); + if (dump_message) { + if (chunk->message_type_id == 20) { + dump_command (chunk); + } + if (chunk->message_type_id == 18) { + dump_command (chunk); + } + } + if (dump_data) { + gst_rtmp_dump_data (gst_rtmp_chunk_get_payload (chunk)); + } +} diff --git a/rtmp/rtmputils.h b/rtmp/rtmputils.h index b020367..7751c76 100644 --- a/rtmp/rtmputils.h +++ b/rtmp/rtmputils.h @@ -21,6 +21,7 @@ #define _GST_RTMP_UTILS_H_ #include <glib.h> +#include "rtmpchunk.h" G_BEGIN_DECLS @@ -30,6 +31,8 @@ GBytes *gst_rtmp_bytes_remove (GBytes *bytes, gsize size); gchar * gst_rtmp_hexify (const guint8 *src, gsize size); guint8 * gst_rtmp_unhexify (const char *src, gsize *size); gchar * gst_rtmp_tea_decode (const gchar *key, const gchar *text); +void gst_rtmp_dump_chunk (GstRtmpChunk * chunk, gboolean dir, + gboolean dump_message, gboolean dump_data); G_END_DECLS diff --git a/tools/client-test.c b/tools/client-test.c index c158c05..b23dcd7 100644 --- a/tools/client-test.c +++ b/tools/client-test.c @@ -115,49 +115,10 @@ connect_done (GObject * source, GAsyncResult * result, gpointer user_data) } static void -dump_command (GstRtmpChunk * chunk) -{ - GstAmfNode *amf; - gsize size; - const guint8 *data; - gsize n_parsed; - int offset; - - offset = 0; - data = g_bytes_get_data (chunk->payload, &size); - while (offset < size) { - amf = gst_amf_node_new_parse (data + offset, size - offset, &n_parsed); - gst_amf_node_dump (amf); - gst_amf_node_free (amf); - offset += n_parsed; - } -} - -static void -dump_chunk (GstRtmpChunk * chunk, gboolean dir) -{ - if (!dump) - return; - - g_print ("%s chunk_stream_id:%-4d ts:%-8d len:%-6" G_GSIZE_FORMAT - " type_id:%-4d stream_id:%08x\n", dir ? ">>>" : "<<<", - chunk->chunk_stream_id, - chunk->timestamp, - chunk->message_length, chunk->message_type_id, chunk->stream_id); - if (chunk->message_type_id == 20) { - dump_command (chunk); - } - if (chunk->message_type_id == 18) { - dump_command (chunk); - } - gst_rtmp_dump_data (gst_rtmp_chunk_get_payload (chunk)); -} - -static void got_chunk (GstRtmpConnection * connection, GstRtmpChunk * chunk, gpointer user_data) { - dump_chunk (chunk, FALSE); + gst_rtmp_dump_chunk (chunk, FALSE, TRUE, TRUE); } static void diff --git a/tools/proxy-server.c b/tools/proxy-server.c index eb0fcba..6151fcb 100644 --- a/tools/proxy-server.c +++ b/tools/proxy-server.c @@ -42,7 +42,6 @@ connect_done (GObject * source, GAsyncResult * result, gpointer user_data); static void got_chunk_proxy (GstRtmpConnection * connection, GstRtmpChunk * chunk, gpointer user_data); -static void dump_chunk (GstRtmpChunk * chunk, gboolean dir); static gboolean periodic (gpointer user_data); GstRtmpServer *server; @@ -122,7 +121,7 @@ got_chunk (GstRtmpConnection * connection, GstRtmpChunk * chunk, g_object_ref (chunk); if (proxy_conn) { - dump_chunk (chunk, TRUE); + gst_rtmp_dump_chunk (chunk, TRUE, TRUE, TRUE); gst_rtmp_connection_queue_chunk (proxy_conn, chunk); } else { if (verbose) @@ -152,7 +151,7 @@ connect_done (GObject * source, GAsyncResult * result, gpointer user_data) proxy_conn = gst_rtmp_client_get_connection (client); server_connection = proxy_conn; - dump_chunk (proxy_chunk, TRUE); + gst_rtmp_dump_chunk (proxy_chunk, TRUE, TRUE, TRUE); gst_rtmp_connection_queue_chunk (proxy_conn, proxy_chunk); proxy_chunk = NULL; } @@ -168,7 +167,7 @@ got_chunk_proxy (GstRtmpConnection * connection, GstRtmpChunk * chunk, { GST_INFO ("got chunk"); - dump_chunk (chunk, FALSE); + gst_rtmp_dump_chunk (chunk, FALSE, TRUE, TRUE); g_object_ref (chunk); gst_rtmp_connection_queue_chunk (client_connection, chunk); @@ -188,39 +187,3 @@ periodic (gpointer user_data) } return G_SOURCE_CONTINUE; } - -static void -dump_command (GstRtmpChunk * chunk) -{ - GstAmfNode *amf; - gsize size; - const guint8 *data; - gsize n_parsed; - int offset; - - offset = 0; - data = g_bytes_get_data (chunk->payload, &size); - while (offset < size) { - amf = gst_amf_node_new_parse (data + offset, size - offset, &n_parsed); - gst_amf_node_dump (amf); - gst_amf_node_free (amf); - offset += n_parsed; - } -} - -static void -dump_chunk (GstRtmpChunk * chunk, gboolean dir) -{ - if (!dump) - return; - - g_print ("%s chunk_stream_id:%-4d ts:%-8d len:%-6" G_GSIZE_FORMAT - " type_id:%-4d stream_id:%08x\n", dir ? ">>>" : "<<<", - chunk->chunk_stream_id, - chunk->timestamp, - chunk->message_length, chunk->message_type_id, chunk->stream_id); - if (chunk->message_type_id == 0x14 || chunk->message_type_id == 0x12) { - dump_command (chunk); - } - gst_rtmp_dump_data (gst_rtmp_chunk_get_payload (chunk)); -} |