1 /*
2 * RTMP packet utilities
3 * Copyright (c) 2009 Konstantin Shishkov
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 #ifndef AVFORMAT_RTMPPKT_H
23 #define AVFORMAT_RTMPPKT_H
24
28
29 /** maximum possible number of different RTMP channels */
30 #define RTMP_CHANNELS 65599
31
32 /**
33 * channels used to for RTMP packets with different purposes (i.e. data, network
34 * control, remote procedure calls, etc.)
35 */
42 };
43
44 /**
45 * known RTMP packet types
46 */
63
64 /**
65 * possible RTMP packet header sizes
66 */
72 };
73
74 /**
75 * structure for holding RTMP packets
76 */
78 int channel_id;
///< RTMP channel ID (nothing to do with audio/video channels though)
81 uint32_t
ts_delta;
///< timestamp increment to the previous one in milliseconds (latter only for media packets)
82 uint32_t
extra;
///< probably an additional channel ID used during streaming data
84 int size;
///< packet payload size
85 int offset;
///< amount of data read so far
86 int read;
///< amount read, including headers
88
89 /**
90 * Create new RTMP packet with given attributes.
91 *
92 * @param pkt packet
93 * @param channel_id packet channel ID
94 * @param type packet type
95 * @param timestamp packet timestamp
96 * @param size packet size
97 * @return zero on success, negative value otherwise
98 */
100 int timestamp,
int size);
101
102 /**
103 * Free RTMP packet.
104 *
105 * @param pkt packet
106 */
108
109 /**
110 * Read RTMP packet sent by the server.
111 *
112 * @param h reader context
113 * @param p packet
114 * @param chunk_size current chunk size
115 * @param prev_pkt previously read packet headers for all channels
116 * (may be needed for restoring incomplete packet header)
117 * @param nb_prev_pkt number of allocated elements in prev_pkt
118 * @return number of bytes read on success, negative value otherwise
119 */
122 int *nb_prev_pkt);
123 /**
124 * Read internal RTMP packet sent by the server.
125 *
126 * @param h reader context
127 * @param p packet
128 * @param chunk_size current chunk size
129 * @param prev_pkt previously read packet headers for all channels
130 * (may be needed for restoring incomplete packet header)
131 * @param nb_prev_pkt number of allocated elements in prev_pkt
132 * @param c the first byte already read
133 * @return number of bytes read on success, negative value otherwise
134 */
138
139 /**
140 * Send RTMP packet to the server.
141 *
142 * @param h reader context
143 * @param p packet to send
144 * @param chunk_size current chunk size
145 * @param prev_pkt previously sent packet headers for all channels
146 * (may be used for packet header compressing)
147 * @param nb_prev_pkt number of allocated elements in prev_pkt
148 * @return number of bytes written on success, negative value otherwise
149 */
152 int *nb_prev_pkt);
153
154 /**
155 * Print information and contents of RTMP packet.
156 *
157 * @param ctx output context
158 * @param p packet to dump
159 */
161
162 /**
163 * Enlarge the prev_pkt array to fit the given channel
164 *
165 * @param prev_pkt array with previously sent packet headers
166 * @param nb_prev_pkt number of allocated elements in prev_pkt
167 * @param channel the channel number that needs to be allocated
168 */
170 int channel);
171
172 /**
173 * @name Functions used to work with the AMF format (which is also used in .flv)
174 * @see amf_* funcs in libavformat/flvdec.c
175 * @{
176 */
177
178 /**
179 * Calculate number of bytes taken by first AMF entry in data.
180 *
181 * @param data input data
182 * @param data_end input buffer end
183 * @return number of bytes used by first AMF entry
184 */
186
187 /**
188 * Retrieve value of given AMF object field in string form.
189 *
190 * @param data AMF object data
191 * @param data_end input buffer end
192 * @param name name of field to retrieve
193 * @param dst buffer for storing result
194 * @param dst_size output buffer size
195 * @return 0 if search and retrieval succeeded, negative value otherwise
196 */
199
200 /**
201 * Write boolean value in AMF format to buffer.
202 *
203 * @param dst pointer to the input buffer (will be modified)
204 * @param val value to write
205 */
207
208 /**
209 * Write number in AMF format to buffer.
210 *
211 * @param dst pointer to the input buffer (will be modified)
212 * @param num value to write
213 */
215
216 /**
217 * Write string in AMF format to buffer.
218 *
219 * @param dst pointer to the input buffer (will be modified)
220 * @param str string to write
221 */
223
224 /**
225 * Write a string consisting of two parts in AMF format to a buffer.
226 *
227 * @param dst pointer to the input buffer (will be modified)
228 * @param str1 first string to write, may be null
229 * @param str2 second string to write, may be null
230 */
232
233 /**
234 * Write AMF NULL value to buffer.
235 *
236 * @param dst pointer to the input buffer (will be modified)
237 */
239
240 /**
241 * Write marker for AMF object to buffer.
242 *
243 * @param dst pointer to the input buffer (will be modified)
244 */
246
247 /**
248 * Write string used as field name in AMF object to buffer.
249 *
250 * @param dst pointer to the input buffer (will be modified)
251 * @param str string to write
252 */
254
255 /**
256 * Write marker for end of AMF object to buffer.
257 *
258 * @param dst pointer to the input buffer (will be modified)
259 */
261
262 /**
263 * Read AMF boolean value.
264 *
265 *@param[in,out] gbc GetByteContext initialized with AMF-formatted data
266 *@param[out] val 0 or 1
267 *@return 0 on success or an AVERROR code on failure
268 */
270
271 /**
272 * Read AMF number value.
273 *
274 *@param[in,out] gbc GetByteContext initialized with AMF-formatted data
275 *@param[out] val read value
276 *@return 0 on success or an AVERROR code on failure
277 */
279
280 /**
281 * Read AMF string value.
282 *
283 * Appends a trailing null byte to output string in order to
284 * ease later parsing.
285 *
286 *@param[in,out] gbc GetByteContext initialized with AMF-formatted data
287 *@param[out] str read string
288 *@param[in] strsize buffer size available to store the read string
289 *@param[out] length read string length
290 *@return 0 on success or an AVERROR code on failure
291 */
293 int strsize,
int *
length);
294
295 /**
296 * Read AMF NULL value.
297 *
298 *@param[in,out] gbc GetByteContext initialized with AMF-formatted data
299 *@return 0 on success or an AVERROR code on failure
300 */
302
303 /**
304 * Match AMF string with a NULL-terminated string.
305 *
306 * @return 0 if the strings do not match.
307 */
308
310
311 /** @} */ // AMF funcs
312
313 #endif /* AVFORMAT_RTMPPKT_H */