1 /* GStreamer RTMP Library
2 * Copyright (C) 2017 Make.TV, Inc. <info@make.tv>
3 * Contact: Jan Alexander Steffens (heftig) <jsteffens@make.tv>
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
14 *
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19 */
20
21 #ifndef _GST_RTMP_MESSAGE_H_
22 #define _GST_RTMP_MESSAGE_H_
23
24 #include <gst/gst.h>
25
26 G_BEGIN_DECLS
27
28 #define GST_RTMP_MAXIMUM_MESSAGE_SIZE 0xFFFFFF
29
30 typedef enum {
31 GST_RTMP_MESSAGE_TYPE_INVALID = 0,
32 GST_RTMP_MESSAGE_TYPE_SET_CHUNK_SIZE = 1,
33 GST_RTMP_MESSAGE_TYPE_ABORT_MESSAGE = 2,
34 GST_RTMP_MESSAGE_TYPE_ACKNOWLEDGEMENT = 3,
35 GST_RTMP_MESSAGE_TYPE_USER_CONTROL = 4,
36 GST_RTMP_MESSAGE_TYPE_WINDOW_ACK_SIZE = 5,
37 GST_RTMP_MESSAGE_TYPE_SET_PEER_BANDWIDTH = 6,
38 GST_RTMP_MESSAGE_TYPE_AUDIO = 8,
39 GST_RTMP_MESSAGE_TYPE_VIDEO = 9,
40 GST_RTMP_MESSAGE_TYPE_DATA_AMF3 = 15,
41 GST_RTMP_MESSAGE_TYPE_SHARED_OBJECT_AMF3 = 16,
42 GST_RTMP_MESSAGE_TYPE_COMMAND_AMF3 = 17,
43 GST_RTMP_MESSAGE_TYPE_DATA_AMF0 = 18,
44 GST_RTMP_MESSAGE_TYPE_SHARED_OBJECT_AMF0 = 19,
45 GST_RTMP_MESSAGE_TYPE_COMMAND_AMF0 = 20,
46 GST_RTMP_MESSAGE_TYPE_AGGREGATE = 22,
47 } GstRtmpMessageType;
48
49 gboolean gst_rtmp_message_type_is_valid (GstRtmpMessageType type);
50 gboolean gst_rtmp_message_type_is_protocol_control (GstRtmpMessageType type);
51 const gchar * gst_rtmp_message_type_get_nick (GstRtmpMessageType type);
52
53 typedef enum
54 {
55 GST_RTMP_USER_CONTROL_TYPE_STREAM_BEGIN = 0,
56 GST_RTMP_USER_CONTROL_TYPE_STREAM_EOF = 1,
57 GST_RTMP_USER_CONTROL_TYPE_STREAM_DRY = 2,
58 GST_RTMP_USER_CONTROL_TYPE_SET_BUFFER_LENGTH = 3,
59 GST_RTMP_USER_CONTROL_TYPE_STREAM_IS_RECORDED = 4,
60 GST_RTMP_USER_CONTROL_TYPE_PING_REQUEST = 6,
61 GST_RTMP_USER_CONTROL_TYPE_PING_RESPONSE = 7,
62
63 /* undocumented */
64 GST_RTMP_USER_CONTROL_TYPE_SWF_VERIFICATION_REQUEST = 26,
65 GST_RTMP_USER_CONTROL_TYPE_SWF_VERIFICATION_RESPONSE = 27,
66 GST_RTMP_USER_CONTROL_TYPE_BUFFER_EMPTY = 31,
67 GST_RTMP_USER_CONTROL_TYPE_BUFFER_READY = 32,
68 } GstRtmpUserControlType;
69
70 const gchar * gst_rtmp_user_control_type_get_nick (
71 GstRtmpUserControlType type);
72
73 #define GST_RTMP_META_API_TYPE (gst_rtmp_meta_api_get_type())
74 #define GST_RTMP_META_INFO (gst_rtmp_meta_get_info())
75 typedef struct _GstRtmpMeta GstRtmpMeta;
76
77 struct _GstRtmpMeta {
78 GstMeta meta;
79 guint32 cstream;
80 guint32 ts_delta;
81 guint32 size;
82 GstRtmpMessageType type;
83 guint32 mstream;
84 };
85
86 GType gst_rtmp_meta_api_get_type (void);
87 const GstMetaInfo * gst_rtmp_meta_get_info (void);
88
89 GstRtmpMeta * gst_buffer_add_rtmp_meta (GstBuffer * buffer);
90
91 static inline GstRtmpMeta *
gst_buffer_get_rtmp_meta(GstBuffer * buffer)92 gst_buffer_get_rtmp_meta (GstBuffer * buffer)
93 {
94 return (GstRtmpMeta *) gst_buffer_get_meta (buffer, GST_RTMP_META_API_TYPE);
95 }
96
97 GstBuffer * gst_rtmp_message_new (GstRtmpMessageType type, guint32 cstream,
98 guint32 mstream);
99 GstBuffer * gst_rtmp_message_new_wrapped (GstRtmpMessageType type, guint32 cstream,
100 guint32 mstream, guint8 * data, gsize size);
101
102 void gst_rtmp_buffer_dump (GstBuffer * buffer, const gchar * prefix);
103
104 GstRtmpMessageType gst_rtmp_message_get_type (GstBuffer * buffer);
105 gboolean gst_rtmp_message_is_protocol_control (GstBuffer * buffer);
106 gboolean gst_rtmp_message_is_user_control (GstBuffer * buffer);
107
108 typedef struct {
109 GstRtmpMessageType type;
110
111 /* for SET_CHUNK_SIZE: chunk size */
112 /* for ABORT_MESSAGE: chunk stream ID */
113 /* for ACKNOWLEDGEMENT: acknowledged byte count */
114 /* for WINDOW_ACK_SIZE and SET_PEER_BANDWIDTH: acknowledgement window size */
115 guint32 param;
116
117 /* for SET_PEER_BANDWIDTH: limit type */
118 guint8 param2;
119 } GstRtmpProtocolControl;
120
121 gboolean gst_rtmp_message_parse_protocol_control (GstBuffer * buffer,
122 GstRtmpProtocolControl * out);
123
124 GstBuffer * gst_rtmp_message_new_protocol_control (GstRtmpProtocolControl * pc);
125
126 typedef struct {
127 GstRtmpUserControlType type;
128
129 /* for STREAM_BEGIN to STREAM_IS_RECORDED: message stream ID */
130 /* for PING_REQUEST and PING_RESPONSE: timestamp of request */
131 guint32 param;
132
133 /* for SET_BUFFER_LENGTH: buffer length in ms */
134 guint32 param2;
135 } GstRtmpUserControl;
136
137 gboolean gst_rtmp_message_parse_user_control (GstBuffer * buffer,
138 GstRtmpUserControl * out);
139
140 GstBuffer * gst_rtmp_message_new_user_control (GstRtmpUserControl * uc);
141
142 gboolean gst_rtmp_message_is_metadata (GstBuffer * buffer);
143
144 G_END_DECLS
145
146 #endif
147