avutil: add better documentation for AVSampleFormat
[libav.git] / libavformat / rtmpproto.c
CommitLineData
9fd6b843
KS
1/*
2 * RTMP network protocol
3 * Copyright (c) 2009 Kostya Shishkov
4 *
2912e87a 5 * This file is part of Libav.
9fd6b843 6 *
2912e87a 7 * Libav is free software; you can redistribute it and/or
9fd6b843
KS
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 *
2912e87a 12 * Libav is distributed in the hope that it will be useful,
9fd6b843
KS
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
2912e87a 18 * License along with Libav; if not, write to the Free Software
9fd6b843
KS
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22/**
ba87f080 23 * @file
9fd6b843
KS
24 * RTMP protocol
25 */
26
27#include "libavcodec/bytestream.h"
28#include "libavutil/avstring.h"
3383a53e 29#include "libavutil/intfloat.h"
9fd6b843
KS
30#include "libavutil/lfg.h"
31#include "libavutil/sha.h"
32#include "avformat.h"
e4a9e3cc 33#include "internal.h"
9fd6b843
KS
34
35#include "network.h"
36
37#include "flv.h"
38#include "rtmp.h"
39#include "rtmppkt.h"
0589da0a 40#include "url.h"
9fd6b843 41
cfac91fe
KS
42//#define DEBUG
43
9fd6b843
KS
44/** RTMP protocol handler state */
45typedef enum {
46 STATE_START, ///< client has not done anything yet
47 STATE_HANDSHAKED, ///< client has performed handshake
6bf22e18
S
48 STATE_RELEASING, ///< client releasing stream before publish it (for output)
49 STATE_FCPUBLISH, ///< client FCPublishing stream (for output)
9fd6b843
KS
50 STATE_CONNECTING, ///< client connected to server successfully
51 STATE_READY, ///< client has sent all needed commands and waits for server reply
52 STATE_PLAYING, ///< client has started receiving multimedia data from server
6bf22e18 53 STATE_PUBLISHING, ///< client has started sending multimedia data to server (for output)
72b870b9 54 STATE_STOPPED, ///< the broadcast has been stopped
9fd6b843
KS
55} ClientState;
56
57/** protocol handler context */
58typedef struct RTMPContext {
59 URLContext* stream; ///< TCP stream used in interactions with RTMP server
60 RTMPPacket prev_pkt[2][RTMP_CHANNELS]; ///< packet history used when reading and sending packets
61 int chunk_size; ///< size of the chunks RTMP packets are divided into
b316991b 62 int is_input; ///< input/output flag
9fd6b843 63 char playpath[256]; ///< path to filename to play (with possible "mp4:" prefix)
5e9ad759 64 char app[128]; ///< application
9fd6b843
KS
65 ClientState state; ///< current state
66 int main_channel_id; ///< an additional channel ID which is used for some invocations
67 uint8_t* flv_data; ///< buffer with data for demuxer
68 int flv_size; ///< current buffer size
69 int flv_off; ///< number of bytes read from current buffer
6bf22e18 70 RTMPPacket out_pkt; ///< rtmp packet, created from flv a/v or metadata (for output)
bf7c1719
KS
71 uint32_t client_report_size; ///< number of bytes after which client should report to server
72 uint32_t bytes_read; ///< number of bytes read from server
73 uint32_t last_bytes_read; ///< number of bytes read last reported to server
3ffe32eb 74 int skip_bytes; ///< number of bytes to skip from the input FLV stream in the next write call
b14629e5
MS
75 uint8_t flv_header[11]; ///< partial incoming flv packet header
76 int flv_header_bytes; ///< number of initialized bytes in flv_header
704af3e2 77 int nb_invokes; ///< keeps track of invoke messages
1eef08f9 78 int create_stream_invoke; ///< invoke id for the create stream command
9fd6b843
KS
79} RTMPContext;
80
81#define PLAYER_KEY_OPEN_PART_LEN 30 ///< length of partial key used for first client digest signing
82/** Client key used for digest signing */
83static const uint8_t rtmp_player_key[] = {
84 'G', 'e', 'n', 'u', 'i', 'n', 'e', ' ', 'A', 'd', 'o', 'b', 'e', ' ',
85 'F', 'l', 'a', 's', 'h', ' ', 'P', 'l', 'a', 'y', 'e', 'r', ' ', '0', '0', '1',
86
87 0xF0, 0xEE, 0xC2, 0x4A, 0x80, 0x68, 0xBE, 0xE8, 0x2E, 0x00, 0xD0, 0xD1, 0x02,
88 0x9E, 0x7E, 0x57, 0x6E, 0xEC, 0x5D, 0x2D, 0x29, 0x80, 0x6F, 0xAB, 0x93, 0xB8,
89 0xE6, 0x36, 0xCF, 0xEB, 0x31, 0xAE
90};
91
92#define SERVER_KEY_OPEN_PART_LEN 36 ///< length of partial key used for first server digest signing
93/** Key used for RTMP server digest signing */
94static const uint8_t rtmp_server_key[] = {
95 'G', 'e', 'n', 'u', 'i', 'n', 'e', ' ', 'A', 'd', 'o', 'b', 'e', ' ',
96 'F', 'l', 'a', 's', 'h', ' ', 'M', 'e', 'd', 'i', 'a', ' ',
97 'S', 'e', 'r', 'v', 'e', 'r', ' ', '0', '0', '1',
98
99 0xF0, 0xEE, 0xC2, 0x4A, 0x80, 0x68, 0xBE, 0xE8, 0x2E, 0x00, 0xD0, 0xD1, 0x02,
100 0x9E, 0x7E, 0x57, 0x6E, 0xEC, 0x5D, 0x2D, 0x29, 0x80, 0x6F, 0xAB, 0x93, 0xB8,
101 0xE6, 0x36, 0xCF, 0xEB, 0x31, 0xAE
102};
103
104/**
49bd8e4b 105 * Generate 'connect' call and send it to the server.
9fd6b843
KS
106 */
107static void gen_connect(URLContext *s, RTMPContext *rt, const char *proto,
5e9ad759 108 const char *host, int port)
9fd6b843
KS
109{
110 RTMPPacket pkt;
6bf22e18 111 uint8_t ver[64], *p;
9fd6b843
KS
112 char tcurl[512];
113
31da5966 114 ff_rtmp_packet_create(&pkt, RTMP_SYSTEM_CHANNEL, RTMP_PT_INVOKE, 0, 4096);
9fd6b843
KS
115 p = pkt.data;
116
57b5555c 117 ff_url_join(tcurl, sizeof(tcurl), proto, NULL, host, port, "/%s", rt->app);
9fd6b843 118 ff_amf_write_string(&p, "connect");
1eef08f9 119 ff_amf_write_number(&p, ++rt->nb_invokes);
9fd6b843
KS
120 ff_amf_write_object_start(&p);
121 ff_amf_write_field_name(&p, "app");
5e9ad759 122 ff_amf_write_string(&p, rt->app);
9fd6b843 123
6bf22e18 124 if (rt->is_input) {
c7240611
KS
125 snprintf(ver, sizeof(ver), "%s %d,%d,%d,%d", RTMP_CLIENT_PLATFORM, RTMP_CLIENT_VER1,
126 RTMP_CLIENT_VER2, RTMP_CLIENT_VER3, RTMP_CLIENT_VER4);
6bf22e18
S
127 } else {
128 snprintf(ver, sizeof(ver), "FMLE/3.0 (compatible; %s)", LIBAVFORMAT_IDENT);
129 ff_amf_write_field_name(&p, "type");
130 ff_amf_write_string(&p, "nonprivate");
131 }
9fd6b843
KS
132 ff_amf_write_field_name(&p, "flashVer");
133 ff_amf_write_string(&p, ver);
134 ff_amf_write_field_name(&p, "tcUrl");
135 ff_amf_write_string(&p, tcurl);
6bf22e18 136 if (rt->is_input) {
c7240611
KS
137 ff_amf_write_field_name(&p, "fpad");
138 ff_amf_write_bool(&p, 0);
139 ff_amf_write_field_name(&p, "capabilities");
140 ff_amf_write_number(&p, 15.0);
faba4a9b
SP
141
142 /* Tell the server we support all the audio codecs except
143 * SUPPORT_SND_INTEL (0x0008) and SUPPORT_SND_UNUSED (0x0010)
144 * which are unused in the RTMP protocol implementation. */
c7240611 145 ff_amf_write_field_name(&p, "audioCodecs");
faba4a9b 146 ff_amf_write_number(&p, 4071.0);
c7240611
KS
147 ff_amf_write_field_name(&p, "videoCodecs");
148 ff_amf_write_number(&p, 252.0);
149 ff_amf_write_field_name(&p, "videoFunction");
150 ff_amf_write_number(&p, 1.0);
6bf22e18 151 }
9fd6b843
KS
152 ff_amf_write_object_end(&p);
153
154 pkt.data_size = p - pkt.data;
155
156 ff_rtmp_packet_write(rt->stream, &pkt, rt->chunk_size, rt->prev_pkt[1]);
f8caa544 157 ff_rtmp_packet_destroy(&pkt);
9fd6b843
KS
158}
159
160/**
49bd8e4b 161 * Generate 'releaseStream' call and send it to the server. It should make
6bf22e18
S
162 * the server release some channel for media streams.
163 */
164static void gen_release_stream(URLContext *s, RTMPContext *rt)
165{
166 RTMPPacket pkt;
167 uint8_t *p;
168
169 ff_rtmp_packet_create(&pkt, RTMP_SYSTEM_CHANNEL, RTMP_PT_INVOKE, 0,
170 29 + strlen(rt->playpath));
171
7f804085 172 av_log(s, AV_LOG_DEBUG, "Releasing stream...\n");
6bf22e18
S
173 p = pkt.data;
174 ff_amf_write_string(&p, "releaseStream");
704af3e2 175 ff_amf_write_number(&p, ++rt->nb_invokes);
6bf22e18
S
176 ff_amf_write_null(&p);
177 ff_amf_write_string(&p, rt->playpath);
178
179 ff_rtmp_packet_write(rt->stream, &pkt, rt->chunk_size, rt->prev_pkt[1]);
180 ff_rtmp_packet_destroy(&pkt);
181}
182
183/**
49bd8e4b 184 * Generate 'FCPublish' call and send it to the server. It should make
6bf22e18
S
185 * the server preapare for receiving media streams.
186 */
187static void gen_fcpublish_stream(URLContext *s, RTMPContext *rt)
188{
189 RTMPPacket pkt;
190 uint8_t *p;
191
192 ff_rtmp_packet_create(&pkt, RTMP_SYSTEM_CHANNEL, RTMP_PT_INVOKE, 0,
193 25 + strlen(rt->playpath));
194
7f804085 195 av_log(s, AV_LOG_DEBUG, "FCPublish stream...\n");
6bf22e18
S
196 p = pkt.data;
197 ff_amf_write_string(&p, "FCPublish");
704af3e2 198 ff_amf_write_number(&p, ++rt->nb_invokes);
6bf22e18
S
199 ff_amf_write_null(&p);
200 ff_amf_write_string(&p, rt->playpath);
201
202 ff_rtmp_packet_write(rt->stream, &pkt, rt->chunk_size, rt->prev_pkt[1]);
203 ff_rtmp_packet_destroy(&pkt);
204}
205
206/**
49bd8e4b 207 * Generate 'FCUnpublish' call and send it to the server. It should make
6bf22e18
S
208 * the server destroy stream.
209 */
210static void gen_fcunpublish_stream(URLContext *s, RTMPContext *rt)
211{
212 RTMPPacket pkt;
213 uint8_t *p;
214
215 ff_rtmp_packet_create(&pkt, RTMP_SYSTEM_CHANNEL, RTMP_PT_INVOKE, 0,
216 27 + strlen(rt->playpath));
217
7f804085 218 av_log(s, AV_LOG_DEBUG, "UnPublishing stream...\n");
6bf22e18
S
219 p = pkt.data;
220 ff_amf_write_string(&p, "FCUnpublish");
704af3e2 221 ff_amf_write_number(&p, ++rt->nb_invokes);
6bf22e18
S
222 ff_amf_write_null(&p);
223 ff_amf_write_string(&p, rt->playpath);
224
225 ff_rtmp_packet_write(rt->stream, &pkt, rt->chunk_size, rt->prev_pkt[1]);
226 ff_rtmp_packet_destroy(&pkt);
227}
228
229/**
49bd8e4b 230 * Generate 'createStream' call and send it to the server. It should make
9fd6b843
KS
231 * the server allocate some channel for media streams.
232 */
233static void gen_create_stream(URLContext *s, RTMPContext *rt)
234{
235 RTMPPacket pkt;
236 uint8_t *p;
237
7f804085 238 av_log(s, AV_LOG_DEBUG, "Creating stream...\n");
31da5966 239 ff_rtmp_packet_create(&pkt, RTMP_SYSTEM_CHANNEL, RTMP_PT_INVOKE, 0, 25);
9fd6b843
KS
240
241 p = pkt.data;
242 ff_amf_write_string(&p, "createStream");
704af3e2 243 ff_amf_write_number(&p, ++rt->nb_invokes);
6bf22e18 244 ff_amf_write_null(&p);
1eef08f9 245 rt->create_stream_invoke = rt->nb_invokes;
6bf22e18
S
246
247 ff_rtmp_packet_write(rt->stream, &pkt, rt->chunk_size, rt->prev_pkt[1]);
248 ff_rtmp_packet_destroy(&pkt);
249}
250
251
252/**
49bd8e4b 253 * Generate 'deleteStream' call and send it to the server. It should make
6bf22e18
S
254 * the server remove some channel for media streams.
255 */
256static void gen_delete_stream(URLContext *s, RTMPContext *rt)
257{
258 RTMPPacket pkt;
259 uint8_t *p;
260
7f804085 261 av_log(s, AV_LOG_DEBUG, "Deleting stream...\n");
6bf22e18
S
262 ff_rtmp_packet_create(&pkt, RTMP_SYSTEM_CHANNEL, RTMP_PT_INVOKE, 0, 34);
263
264 p = pkt.data;
265 ff_amf_write_string(&p, "deleteStream");
1eef08f9 266 ff_amf_write_number(&p, ++rt->nb_invokes);
9fd6b843 267 ff_amf_write_null(&p);
6bf22e18 268 ff_amf_write_number(&p, rt->main_channel_id);
9fd6b843
KS
269
270 ff_rtmp_packet_write(rt->stream, &pkt, rt->chunk_size, rt->prev_pkt[1]);
271 ff_rtmp_packet_destroy(&pkt);
272}
273
274/**
49bd8e4b 275 * Generate 'play' call and send it to the server, then ping the server
9fd6b843
KS
276 * to start actual playing.
277 */
278static void gen_play(URLContext *s, RTMPContext *rt)
279{
280 RTMPPacket pkt;
281 uint8_t *p;
282
7f804085 283 av_log(s, AV_LOG_DEBUG, "Sending play command for '%s'\n", rt->playpath);
9fd6b843 284 ff_rtmp_packet_create(&pkt, RTMP_VIDEO_CHANNEL, RTMP_PT_INVOKE, 0,
f836fa17 285 20 + strlen(rt->playpath));
9fd6b843
KS
286 pkt.extra = rt->main_channel_id;
287
288 p = pkt.data;
289 ff_amf_write_string(&p, "play");
1eef08f9 290 ff_amf_write_number(&p, ++rt->nb_invokes);
9fd6b843
KS
291 ff_amf_write_null(&p);
292 ff_amf_write_string(&p, rt->playpath);
9fd6b843
KS
293
294 ff_rtmp_packet_write(rt->stream, &pkt, rt->chunk_size, rt->prev_pkt[1]);
295 ff_rtmp_packet_destroy(&pkt);
296
297 // set client buffer time disguised in ping packet
298 ff_rtmp_packet_create(&pkt, RTMP_NETWORK_CHANNEL, RTMP_PT_PING, 1, 10);
299
300 p = pkt.data;
301 bytestream_put_be16(&p, 3);
302 bytestream_put_be32(&p, 1);
303 bytestream_put_be32(&p, 256); //TODO: what is a good value here?
304
305 ff_rtmp_packet_write(rt->stream, &pkt, rt->chunk_size, rt->prev_pkt[1]);
306 ff_rtmp_packet_destroy(&pkt);
307}
308
309/**
49bd8e4b 310 * Generate 'publish' call and send it to the server.
6bf22e18
S
311 */
312static void gen_publish(URLContext *s, RTMPContext *rt)
313{
314 RTMPPacket pkt;
315 uint8_t *p;
316
7f804085 317 av_log(s, AV_LOG_DEBUG, "Sending publish command for '%s'\n", rt->playpath);
6bf22e18
S
318 ff_rtmp_packet_create(&pkt, RTMP_SOURCE_CHANNEL, RTMP_PT_INVOKE, 0,
319 30 + strlen(rt->playpath));
320 pkt.extra = rt->main_channel_id;
321
322 p = pkt.data;
323 ff_amf_write_string(&p, "publish");
1eef08f9 324 ff_amf_write_number(&p, ++rt->nb_invokes);
6bf22e18
S
325 ff_amf_write_null(&p);
326 ff_amf_write_string(&p, rt->playpath);
327 ff_amf_write_string(&p, "live");
328
329 ff_rtmp_packet_write(rt->stream, &pkt, rt->chunk_size, rt->prev_pkt[1]);
330 ff_rtmp_packet_destroy(&pkt);
331}
332
333/**
49bd8e4b 334 * Generate ping reply and send it to the server.
9fd6b843
KS
335 */
336static void gen_pong(URLContext *s, RTMPContext *rt, RTMPPacket *ppkt)
337{
338 RTMPPacket pkt;
339 uint8_t *p;
340
341 ff_rtmp_packet_create(&pkt, RTMP_NETWORK_CHANNEL, RTMP_PT_PING, ppkt->timestamp + 1, 6);
342 p = pkt.data;
343 bytestream_put_be16(&p, 7);
4aaebf78 344 bytestream_put_be32(&p, AV_RB32(ppkt->data+2));
9fd6b843
KS
345 ff_rtmp_packet_write(rt->stream, &pkt, rt->chunk_size, rt->prev_pkt[1]);
346 ff_rtmp_packet_destroy(&pkt);
347}
348
bf7c1719 349/**
34d908c0
RS
350 * Generate server bandwidth message and send it to the server.
351 */
352static void gen_server_bw(URLContext *s, RTMPContext *rt)
353{
354 RTMPPacket pkt;
355 uint8_t *p;
356
357 ff_rtmp_packet_create(&pkt, RTMP_NETWORK_CHANNEL, RTMP_PT_SERVER_BW, 0, 4);
358 p = pkt.data;
359 bytestream_put_be32(&p, 2500000);
360 ff_rtmp_packet_write(rt->stream, &pkt, rt->chunk_size, rt->prev_pkt[1]);
361 ff_rtmp_packet_destroy(&pkt);
362}
363
364/**
49bd8e4b 365 * Generate report on bytes read so far and send it to the server.
bf7c1719
KS
366 */
367static void gen_bytes_read(URLContext *s, RTMPContext *rt, uint32_t ts)
368{
369 RTMPPacket pkt;
370 uint8_t *p;
371
372 ff_rtmp_packet_create(&pkt, RTMP_NETWORK_CHANNEL, RTMP_PT_BYTES_READ, ts, 4);
373 p = pkt.data;
374 bytestream_put_be32(&p, rt->bytes_read);
375 ff_rtmp_packet_write(rt->stream, &pkt, rt->chunk_size, rt->prev_pkt[1]);
376 ff_rtmp_packet_destroy(&pkt);
377}
378
9fd6b843
KS
379//TODO: Move HMAC code somewhere. Eventually.
380#define HMAC_IPAD_VAL 0x36
381#define HMAC_OPAD_VAL 0x5C
382
383/**
49bd8e4b 384 * Calculate HMAC-SHA2 digest for RTMP handshake packets.
9fd6b843
KS
385 *
386 * @param src input buffer
387 * @param len input buffer length (should be 1536)
388 * @param gap offset in buffer where 32 bytes should not be taken into account
389 * when calculating digest (since it will be used to store that digest)
390 * @param key digest key
391 * @param keylen digest key length
392 * @param dst buffer where calculated digest will be stored (32 bytes)
393 */
394static void rtmp_calc_digest(const uint8_t *src, int len, int gap,
395 const uint8_t *key, int keylen, uint8_t *dst)
396{
397 struct AVSHA *sha;
398 uint8_t hmac_buf[64+32] = {0};
399 int i;
400
401 sha = av_mallocz(av_sha_size);
402
403 if (keylen < 64) {
404 memcpy(hmac_buf, key, keylen);
405 } else {
406 av_sha_init(sha, 256);
407 av_sha_update(sha,key, keylen);
408 av_sha_final(sha, hmac_buf);
409 }
410 for (i = 0; i < 64; i++)
411 hmac_buf[i] ^= HMAC_IPAD_VAL;
412
413 av_sha_init(sha, 256);
414 av_sha_update(sha, hmac_buf, 64);
415 if (gap <= 0) {
416 av_sha_update(sha, src, len);
417 } else { //skip 32 bytes used for storing digest
418 av_sha_update(sha, src, gap);
419 av_sha_update(sha, src + gap + 32, len - gap - 32);
420 }
421 av_sha_final(sha, hmac_buf + 64);
422
423 for (i = 0; i < 64; i++)
424 hmac_buf[i] ^= HMAC_IPAD_VAL ^ HMAC_OPAD_VAL; //reuse XORed key for opad
425 av_sha_init(sha, 256);
426 av_sha_update(sha, hmac_buf, 64+32);
427 av_sha_final(sha, dst);
428
429 av_free(sha);
430}
431
432/**
49bd8e4b 433 * Put HMAC-SHA2 digest of packet data (except for the bytes where this digest
9fd6b843
KS
434 * will be stored) into that packet.
435 *
436 * @param buf handshake data (1536 bytes)
437 * @return offset to the digest inside input data
438 */
439static int rtmp_handshake_imprint_with_digest(uint8_t *buf)
440{
441 int i, digest_pos = 0;
442
443 for (i = 8; i < 12; i++)
444 digest_pos += buf[i];
445 digest_pos = (digest_pos % 728) + 12;
446
447 rtmp_calc_digest(buf, RTMP_HANDSHAKE_PACKET_SIZE, digest_pos,
448 rtmp_player_key, PLAYER_KEY_OPEN_PART_LEN,
449 buf + digest_pos);
450 return digest_pos;
451}
452
453/**
49bd8e4b 454 * Verify that the received server response has the expected digest value.
9fd6b843
KS
455 *
456 * @param buf handshake data received from the server (1536 bytes)
457 * @param off position to search digest offset from
458 * @return 0 if digest is valid, digest position otherwise
459 */
460static int rtmp_validate_digest(uint8_t *buf, int off)
461{
462 int i, digest_pos = 0;
463 uint8_t digest[32];
464
465 for (i = 0; i < 4; i++)
466 digest_pos += buf[i + off];
467 digest_pos = (digest_pos % 728) + off + 4;
468
469 rtmp_calc_digest(buf, RTMP_HANDSHAKE_PACKET_SIZE, digest_pos,
470 rtmp_server_key, SERVER_KEY_OPEN_PART_LEN,
471 digest);
472 if (!memcmp(digest, buf + digest_pos, 32))
473 return digest_pos;
474 return 0;
475}
476
477/**
49bd8e4b 478 * Perform handshake with the server by means of exchanging pseudorandom data
9fd6b843
KS
479 * signed with HMAC-SHA2 digest.
480 *
481 * @return 0 if handshake succeeds, negative value otherwise
482 */
483static int rtmp_handshake(URLContext *s, RTMPContext *rt)
484{
485 AVLFG rnd;
486 uint8_t tosend [RTMP_HANDSHAKE_PACKET_SIZE+1] = {
487 3, // unencrypted data
488 0, 0, 0, 0, // client uptime
489 RTMP_CLIENT_VER1,
490 RTMP_CLIENT_VER2,
491 RTMP_CLIENT_VER3,
492 RTMP_CLIENT_VER4,
493 };
494 uint8_t clientdata[RTMP_HANDSHAKE_PACKET_SIZE];
495 uint8_t serverdata[RTMP_HANDSHAKE_PACKET_SIZE+1];
496 int i;
497 int server_pos, client_pos;
498 uint8_t digest[32];
499
7f804085 500 av_log(s, AV_LOG_DEBUG, "Handshaking...\n");
9fd6b843
KS
501
502 av_lfg_init(&rnd, 0xDEADC0DE);
503 // generate handshake packet - 1536 bytes of pseudorandom data
504 for (i = 9; i <= RTMP_HANDSHAKE_PACKET_SIZE; i++)
505 tosend[i] = av_lfg_get(&rnd) >> 24;
506 client_pos = rtmp_handshake_imprint_with_digest(tosend + 1);
507
925e908b 508 ffurl_write(rt->stream, tosend, RTMP_HANDSHAKE_PACKET_SIZE + 1);
dce37564 509 i = ffurl_read_complete(rt->stream, serverdata, RTMP_HANDSHAKE_PACKET_SIZE + 1);
9fd6b843 510 if (i != RTMP_HANDSHAKE_PACKET_SIZE + 1) {
7f804085 511 av_log(s, AV_LOG_ERROR, "Cannot read RTMP handshake response\n");
9fd6b843
KS
512 return -1;
513 }
dce37564 514 i = ffurl_read_complete(rt->stream, clientdata, RTMP_HANDSHAKE_PACKET_SIZE);
9fd6b843 515 if (i != RTMP_HANDSHAKE_PACKET_SIZE) {
7f804085 516 av_log(s, AV_LOG_ERROR, "Cannot read RTMP handshake response\n");
9fd6b843
KS
517 return -1;
518 }
519
7f804085 520 av_log(s, AV_LOG_DEBUG, "Server version %d.%d.%d.%d\n",
9fd6b843
KS
521 serverdata[5], serverdata[6], serverdata[7], serverdata[8]);
522
e2ee11e8 523 if (rt->is_input && serverdata[5] >= 3) {
c7240611 524 server_pos = rtmp_validate_digest(serverdata + 1, 772);
9fd6b843 525 if (!server_pos) {
c7240611
KS
526 server_pos = rtmp_validate_digest(serverdata + 1, 8);
527 if (!server_pos) {
7f804085 528 av_log(s, AV_LOG_ERROR, "Server response validating failed\n");
c7240611
KS
529 return -1;
530 }
9fd6b843 531 }
9fd6b843 532
c7240611
KS
533 rtmp_calc_digest(tosend + 1 + client_pos, 32, 0,
534 rtmp_server_key, sizeof(rtmp_server_key),
535 digest);
536 rtmp_calc_digest(clientdata, RTMP_HANDSHAKE_PACKET_SIZE-32, 0,
537 digest, 32,
538 digest);
539 if (memcmp(digest, clientdata + RTMP_HANDSHAKE_PACKET_SIZE - 32, 32)) {
7f804085 540 av_log(s, AV_LOG_ERROR, "Signature mismatch\n");
c7240611
KS
541 return -1;
542 }
9fd6b843 543
c7240611
KS
544 for (i = 0; i < RTMP_HANDSHAKE_PACKET_SIZE; i++)
545 tosend[i] = av_lfg_get(&rnd) >> 24;
546 rtmp_calc_digest(serverdata + 1 + server_pos, 32, 0,
547 rtmp_player_key, sizeof(rtmp_player_key),
548 digest);
549 rtmp_calc_digest(tosend, RTMP_HANDSHAKE_PACKET_SIZE - 32, 0,
550 digest, 32,
551 tosend + RTMP_HANDSHAKE_PACKET_SIZE - 32);
552
553 // write reply back to the server
925e908b 554 ffurl_write(rt->stream, tosend, RTMP_HANDSHAKE_PACKET_SIZE);
6bf22e18 555 } else {
925e908b 556 ffurl_write(rt->stream, serverdata+1, RTMP_HANDSHAKE_PACKET_SIZE);
6bf22e18
S
557 }
558
9fd6b843
KS
559 return 0;
560}
561
562/**
49bd8e4b 563 * Parse received packet and possibly perform some action depending on
9fd6b843
KS
564 * the packet contents.
565 * @return 0 for no errors, negative values for serious errors which prevent
566 * further communications, positive values for uncritical errors
567 */
568static int rtmp_parse_result(URLContext *s, RTMPContext *rt, RTMPPacket *pkt)
569{
570 int i, t;
571 const uint8_t *data_end = pkt->data + pkt->data_size;
572
cfac91fe 573#ifdef DEBUG
7f804085 574 ff_rtmp_packet_dump(s, pkt);
cfac91fe
KS
575#endif
576
9fd6b843
KS
577 switch (pkt->type) {
578 case RTMP_PT_CHUNK_SIZE:
579 if (pkt->data_size != 4) {
7f804085 580 av_log(s, AV_LOG_ERROR,
9fd6b843
KS
581 "Chunk size change packet is not 4 bytes long (%d)\n", pkt->data_size);
582 return -1;
583 }
6bf22e18
S
584 if (!rt->is_input)
585 ff_rtmp_packet_write(rt->stream, pkt, rt->chunk_size, rt->prev_pkt[1]);
9fd6b843
KS
586 rt->chunk_size = AV_RB32(pkt->data);
587 if (rt->chunk_size <= 0) {
7f804085 588 av_log(s, AV_LOG_ERROR, "Incorrect chunk size %d\n", rt->chunk_size);
9fd6b843
KS
589 return -1;
590 }
7f804085 591 av_log(s, AV_LOG_DEBUG, "New chunk size = %d\n", rt->chunk_size);
9fd6b843
KS
592 break;
593 case RTMP_PT_PING:
594 t = AV_RB16(pkt->data);
595 if (t == 6)
596 gen_pong(s, rt, pkt);
597 break;
bf7c1719
KS
598 case RTMP_PT_CLIENT_BW:
599 if (pkt->data_size < 4) {
7f804085 600 av_log(s, AV_LOG_ERROR,
bf7c1719
KS
601 "Client bandwidth report packet is less than 4 bytes long (%d)\n",
602 pkt->data_size);
603 return -1;
604 }
7f804085 605 av_log(s, AV_LOG_DEBUG, "Client bandwidth = %d\n", AV_RB32(pkt->data));
bf7c1719
KS
606 rt->client_report_size = AV_RB32(pkt->data) >> 1;
607 break;
9fd6b843
KS
608 case RTMP_PT_INVOKE:
609 //TODO: check for the messages sent for wrong state?
610 if (!memcmp(pkt->data, "\002\000\006_error", 9)) {
611 uint8_t tmpstr[256];
612
613 if (!ff_amf_get_field_value(pkt->data + 9, data_end,
614 "description", tmpstr, sizeof(tmpstr)))
7f804085 615 av_log(s, AV_LOG_ERROR, "Server error: %s\n",tmpstr);
9fd6b843
KS
616 return -1;
617 } else if (!memcmp(pkt->data, "\002\000\007_result", 10)) {
618 switch (rt->state) {
619 case STATE_HANDSHAKED:
6bf22e18
S
620 if (!rt->is_input) {
621 gen_release_stream(s, rt);
622 gen_fcpublish_stream(s, rt);
623 rt->state = STATE_RELEASING;
624 } else {
34d908c0 625 gen_server_bw(s, rt);
6bf22e18
S
626 rt->state = STATE_CONNECTING;
627 }
9fd6b843 628 gen_create_stream(s, rt);
6bf22e18
S
629 break;
630 case STATE_FCPUBLISH:
9fd6b843
KS
631 rt->state = STATE_CONNECTING;
632 break;
6bf22e18
S
633 case STATE_RELEASING:
634 rt->state = STATE_FCPUBLISH;
635 /* hack for Wowza Media Server, it does not send result for
636 * releaseStream and FCPublish calls */
637 if (!pkt->data[10]) {
3383a53e 638 int pkt_id = av_int2double(AV_RB64(pkt->data + 11));
1eef08f9 639 if (pkt_id == rt->create_stream_invoke)
6bf22e18
S
640 rt->state = STATE_CONNECTING;
641 }
e07c92e4 642 if (rt->state != STATE_CONNECTING)
6bf22e18 643 break;
9fd6b843
KS
644 case STATE_CONNECTING:
645 //extract a number from the result
646 if (pkt->data[10] || pkt->data[19] != 5 || pkt->data[20]) {
7f804085 647 av_log(s, AV_LOG_WARNING, "Unexpected reply on connect()\n");
9fd6b843 648 } else {
3383a53e 649 rt->main_channel_id = av_int2double(AV_RB64(pkt->data + 21));
9fd6b843 650 }
6bf22e18 651 if (rt->is_input) {
c7240611 652 gen_play(s, rt);
6bf22e18
S
653 } else {
654 gen_publish(s, rt);
655 }
9fd6b843
KS
656 rt->state = STATE_READY;
657 break;
658 }
659 } else if (!memcmp(pkt->data, "\002\000\010onStatus", 11)) {
660 const uint8_t* ptr = pkt->data + 11;
661 uint8_t tmpstr[256];
9fd6b843
KS
662
663 for (i = 0; i < 2; i++) {
664 t = ff_amf_tag_size(ptr, data_end);
665 if (t < 0)
666 return 1;
667 ptr += t;
668 }
669 t = ff_amf_get_field_value(ptr, data_end,
670 "level", tmpstr, sizeof(tmpstr));
671 if (!t && !strcmp(tmpstr, "error")) {
672 if (!ff_amf_get_field_value(ptr, data_end,
673 "description", tmpstr, sizeof(tmpstr)))
7f804085 674 av_log(s, AV_LOG_ERROR, "Server error: %s\n",tmpstr);
9fd6b843
KS
675 return -1;
676 }
677 t = ff_amf_get_field_value(ptr, data_end,
678 "code", tmpstr, sizeof(tmpstr));
6bf22e18 679 if (!t && !strcmp(tmpstr, "NetStream.Play.Start")) rt->state = STATE_PLAYING;
72b870b9
MS
680 if (!t && !strcmp(tmpstr, "NetStream.Play.Stop")) rt->state = STATE_STOPPED;
681 if (!t && !strcmp(tmpstr, "NetStream.Play.UnpublishNotify")) rt->state = STATE_STOPPED;
6bf22e18 682 if (!t && !strcmp(tmpstr, "NetStream.Publish.Start")) rt->state = STATE_PUBLISHING;
9fd6b843
KS
683 }
684 break;
685 }
686 return 0;
687}
688
689/**
49bd8e4b 690 * Interact with the server by receiving and sending RTMP packets until
9fd6b843
KS
691 * there is some significant data (media data or expected status notification).
692 *
693 * @param s reading context
1d8041b3
SS
694 * @param for_header non-zero value tells function to work until it
695 * gets notification from the server that playing has been started,
696 * otherwise function will work until some media data is received (or
697 * an error happens)
9fd6b843
KS
698 * @return 0 for successful operation, negative value in case of error
699 */
700static int get_packet(URLContext *s, int for_header)
701{
702 RTMPContext *rt = s->priv_data;
703 int ret;
56e29bf2
S
704 uint8_t *p;
705 const uint8_t *next;
706 uint32_t data_size;
707 uint32_t ts, cts, pts=0;
9fd6b843 708
72b870b9
MS
709 if (rt->state == STATE_STOPPED)
710 return AVERROR_EOF;
711
e07c92e4 712 for (;;) {
271c869c 713 RTMPPacket rpkt = { 0 };
9fd6b843 714 if ((ret = ff_rtmp_packet_read(rt->stream, &rpkt,
adb54961 715 rt->chunk_size, rt->prev_pkt[0])) <= 0) {
b381a823 716 if (ret == 0) {
9fd6b843
KS
717 return AVERROR(EAGAIN);
718 } else {
719 return AVERROR(EIO);
720 }
721 }
bf7c1719
KS
722 rt->bytes_read += ret;
723 if (rt->bytes_read > rt->last_bytes_read + rt->client_report_size) {
7f804085 724 av_log(s, AV_LOG_DEBUG, "Sending bytes read report\n");
bf7c1719
KS
725 gen_bytes_read(s, rt, rpkt.timestamp + 1);
726 rt->last_bytes_read = rt->bytes_read;
727 }
9fd6b843
KS
728
729 ret = rtmp_parse_result(s, rt, &rpkt);
730 if (ret < 0) {//serious error in current packet
731 ff_rtmp_packet_destroy(&rpkt);
732 return -1;
733 }
72b870b9
MS
734 if (rt->state == STATE_STOPPED) {
735 ff_rtmp_packet_destroy(&rpkt);
736 return AVERROR_EOF;
737 }
6bf22e18 738 if (for_header && (rt->state == STATE_PLAYING || rt->state == STATE_PUBLISHING)) {
9fd6b843
KS
739 ff_rtmp_packet_destroy(&rpkt);
740 return 0;
741 }
6bf22e18 742 if (!rpkt.data_size || !rt->is_input) {
9fd6b843
KS
743 ff_rtmp_packet_destroy(&rpkt);
744 continue;
745 }
746 if (rpkt.type == RTMP_PT_VIDEO || rpkt.type == RTMP_PT_AUDIO ||
afbacb93 747 (rpkt.type == RTMP_PT_NOTIFY && !memcmp("\002\000\012onMetaData", rpkt.data, 13))) {
56e29bf2 748 ts = rpkt.timestamp;
9fd6b843 749
9fd6b843
KS
750 // generate packet header and put data into buffer for FLV demuxer
751 rt->flv_off = 0;
752 rt->flv_size = rpkt.data_size + 15;
753 rt->flv_data = p = av_realloc(rt->flv_data, rt->flv_size);
754 bytestream_put_byte(&p, rpkt.type);
755 bytestream_put_be24(&p, rpkt.data_size);
756 bytestream_put_be24(&p, ts);
757 bytestream_put_byte(&p, ts >> 24);
758 bytestream_put_be24(&p, 0);
759 bytestream_put_buffer(&p, rpkt.data, rpkt.data_size);
760 bytestream_put_be32(&p, 0);
761 ff_rtmp_packet_destroy(&rpkt);
762 return 0;
763 } else if (rpkt.type == RTMP_PT_METADATA) {
764 // we got raw FLV data, make it available for FLV demuxer
765 rt->flv_off = 0;
766 rt->flv_size = rpkt.data_size;
767 rt->flv_data = av_realloc(rt->flv_data, rt->flv_size);
56e29bf2
S
768 /* rewrite timestamps */
769 next = rpkt.data;
770 ts = rpkt.timestamp;
771 while (next - rpkt.data < rpkt.data_size - 11) {
772 next++;
773 data_size = bytestream_get_be24(&next);
774 p=next;
775 cts = bytestream_get_be24(&next);
aae9a093 776 cts |= bytestream_get_byte(&next) << 24;
56e29bf2
S
777 if (pts==0)
778 pts=cts;
779 ts += cts - pts;
780 pts = cts;
781 bytestream_put_be24(&p, ts);
782 bytestream_put_byte(&p, ts >> 24);
783 next += data_size + 3 + 4;
784 }
9fd6b843
KS
785 memcpy(rt->flv_data, rpkt.data, rpkt.data_size);
786 ff_rtmp_packet_destroy(&rpkt);
787 return 0;
788 }
789 ff_rtmp_packet_destroy(&rpkt);
790 }
9fd6b843
KS
791}
792
793static int rtmp_close(URLContext *h)
794{
795 RTMPContext *rt = h->priv_data;
796
e07c92e4 797 if (!rt->is_input) {
6bf22e18
S
798 rt->flv_data = NULL;
799 if (rt->out_pkt.data_size)
800 ff_rtmp_packet_destroy(&rt->out_pkt);
615c2879
S
801 if (rt->state > STATE_FCPUBLISH)
802 gen_fcunpublish_stream(h, rt);
6bf22e18 803 }
615c2879
S
804 if (rt->state > STATE_HANDSHAKED)
805 gen_delete_stream(h, rt);
6bf22e18 806
9fd6b843 807 av_freep(&rt->flv_data);
e52a9145 808 ffurl_close(rt->stream);
9fd6b843
KS
809 return 0;
810}
811
812/**
49bd8e4b 813 * Open RTMP connection and verify that the stream can be played.
9fd6b843
KS
814 *
815 * URL syntax: rtmp://server[:port][/app][/playpath]
816 * where 'app' is first one or two directories in the path
817 * (e.g. /ondemand/, /flash/live/, etc.)
818 * and 'playpath' is a file name (the rest of the path,
819 * may be prefixed with "mp4:")
820 */
821static int rtmp_open(URLContext *s, const char *uri, int flags)
822{
7e580505 823 RTMPContext *rt = s->priv_data;
5e9ad759 824 char proto[8], hostname[256], path[1024], *fname;
9fd6b843 825 uint8_t buf[2048];
b316991b 826 int port;
9fd6b843
KS
827 int ret;
828
59d96941 829 rt->is_input = !(flags & AVIO_FLAG_WRITE);
9fd6b843 830
f3bfe388 831 av_url_split(proto, sizeof(proto), NULL, 0, hostname, sizeof(hostname), &port,
f984dcf6 832 path, sizeof(path), s->filename);
9fd6b843
KS
833
834 if (port < 0)
835 port = RTMP_DEFAULT_PORT;
57b5555c 836 ff_url_join(buf, sizeof(buf), "tcp", NULL, hostname, port, NULL);
9fd6b843 837
6f1b7b39 838 if (ffurl_open(&rt->stream, buf, AVIO_FLAG_READ_WRITE,
ddffc2fd 839 &s->interrupt_callback, NULL) < 0) {
59d96941 840 av_log(s , AV_LOG_ERROR, "Cannot open connection %s\n", buf);
9fd6b843 841 goto fail;
fe523958 842 }
9fd6b843 843
c7240611
KS
844 rt->state = STATE_START;
845 if (rtmp_handshake(s, rt))
02490bf3 846 goto fail;
9fd6b843 847
c7240611
KS
848 rt->chunk_size = 128;
849 rt->state = STATE_HANDSHAKED;
850 //extract "app" part from path
851 if (!strncmp(path, "/ondemand/", 10)) {
852 fname = path + 10;
853 memcpy(rt->app, "ondemand", 9);
854 } else {
855 char *p = strchr(path + 1, '/');
856 if (!p) {
857 fname = path + 1;
858 rt->app[0] = '\0';
9fd6b843 859 } else {
c7240611
KS
860 char *c = strchr(p + 1, ':');
861 fname = strchr(p + 1, '/');
862 if (!fname || c < fname) {
863 fname = p + 1;
864 av_strlcpy(rt->app, path + 1, p - path);
9fd6b843 865 } else {
c7240611
KS
866 fname++;
867 av_strlcpy(rt->app, path + 1, fname - path - 1);
9fd6b843
KS
868 }
869 }
c7240611
KS
870 }
871 if (!strchr(fname, ':') &&
872 (!strcmp(fname + strlen(fname) - 4, ".f4v") ||
873 !strcmp(fname + strlen(fname) - 4, ".mp4"))) {
874 memcpy(rt->playpath, "mp4:", 5);
875 } else {
876 rt->playpath[0] = 0;
877 }
878 strncat(rt->playpath, fname, sizeof(rt->playpath) - 5);
9fd6b843 879
bf7c1719
KS
880 rt->client_report_size = 1048576;
881 rt->bytes_read = 0;
882 rt->last_bytes_read = 0;
883
7f804085 884 av_log(s, AV_LOG_DEBUG, "Proto = %s, path = %s, app = %s, fname = %s\n",
c7240611
KS
885 proto, path, rt->app, rt->playpath);
886 gen_connect(s, rt, proto, hostname, port);
9fd6b843 887
c7240611
KS
888 do {
889 ret = get_packet(s, 1);
890 } while (ret == EAGAIN);
891 if (ret < 0)
892 goto fail;
6bf22e18
S
893
894 if (rt->is_input) {
9fd6b843
KS
895 // generate FLV header for demuxer
896 rt->flv_size = 13;
897 rt->flv_data = av_realloc(rt->flv_data, rt->flv_size);
898 rt->flv_off = 0;
899 memcpy(rt->flv_data, "FLV\1\5\0\0\0\011\0\0\0\0", rt->flv_size);
6bf22e18
S
900 } else {
901 rt->flv_size = 0;
902 rt->flv_data = NULL;
903 rt->flv_off = 0;
b14629e5 904 rt->skip_bytes = 13;
9fd6b843
KS
905 }
906
5958df34 907 s->max_packet_size = rt->stream->max_packet_size;
9fd6b843
KS
908 s->is_streamed = 1;
909 return 0;
910
911fail:
912 rtmp_close(s);
913 return AVERROR(EIO);
914}
915
916static int rtmp_read(URLContext *s, uint8_t *buf, int size)
917{
918 RTMPContext *rt = s->priv_data;
919 int orig_size = size;
920 int ret;
921
922 while (size > 0) {
923 int data_left = rt->flv_size - rt->flv_off;
924
925 if (data_left >= size) {
926 memcpy(buf, rt->flv_data + rt->flv_off, size);
927 rt->flv_off += size;
928 return orig_size;
929 }
930 if (data_left > 0) {
931 memcpy(buf, rt->flv_data + rt->flv_off, data_left);
932 buf += data_left;
933 size -= data_left;
934 rt->flv_off = rt->flv_size;
e8ccf245 935 return data_left;
9fd6b843
KS
936 }
937 if ((ret = get_packet(s, 0)) < 0)
938 return ret;
939 }
940 return orig_size;
941}
942
9ad4c65f 943static int rtmp_write(URLContext *s, const uint8_t *buf, int size)
9fd6b843 944{
9ad4c65f 945 RTMPContext *rt = s->priv_data;
6bf22e18
S
946 int size_temp = size;
947 int pktsize, pkttype;
948 uint32_t ts;
949 const uint8_t *buf_temp = buf;
950
6bf22e18 951 do {
b14629e5
MS
952 if (rt->skip_bytes) {
953 int skip = FFMIN(rt->skip_bytes, size_temp);
954 buf_temp += skip;
955 size_temp -= skip;
956 rt->skip_bytes -= skip;
957 continue;
958 }
959
960 if (rt->flv_header_bytes < 11) {
961 const uint8_t *header = rt->flv_header;
962 int copy = FFMIN(11 - rt->flv_header_bytes, size_temp);
963 bytestream_get_buffer(&buf_temp, rt->flv_header + rt->flv_header_bytes, copy);
964 rt->flv_header_bytes += copy;
965 size_temp -= copy;
966 if (rt->flv_header_bytes < 11)
967 break;
6bf22e18 968
b14629e5
MS
969 pkttype = bytestream_get_byte(&header);
970 pktsize = bytestream_get_be24(&header);
971 ts = bytestream_get_be24(&header);
972 ts |= bytestream_get_byte(&header) << 24;
973 bytestream_get_be24(&header);
6bf22e18
S
974 rt->flv_size = pktsize;
975
976 //force 12bytes header
977 if (((pkttype == RTMP_PT_VIDEO || pkttype == RTMP_PT_AUDIO) && ts == 0) ||
978 pkttype == RTMP_PT_NOTIFY) {
979 if (pkttype == RTMP_PT_NOTIFY)
980 pktsize += 16;
981 rt->prev_pkt[1][RTMP_SOURCE_CHANNEL].channel_id = 0;
982 }
983
984 //this can be a big packet, it's better to send it right here
985 ff_rtmp_packet_create(&rt->out_pkt, RTMP_SOURCE_CHANNEL, pkttype, ts, pktsize);
986 rt->out_pkt.extra = rt->main_channel_id;
987 rt->flv_data = rt->out_pkt.data;
988
989 if (pkttype == RTMP_PT_NOTIFY)
990 ff_amf_write_string(&rt->flv_data, "@setDataFrame");
991 }
992
993 if (rt->flv_size - rt->flv_off > size_temp) {
994 bytestream_get_buffer(&buf_temp, rt->flv_data + rt->flv_off, size_temp);
995 rt->flv_off += size_temp;
a14c7842 996 size_temp = 0;
6bf22e18
S
997 } else {
998 bytestream_get_buffer(&buf_temp, rt->flv_data + rt->flv_off, rt->flv_size - rt->flv_off);
a14c7842 999 size_temp -= rt->flv_size - rt->flv_off;
6bf22e18
S
1000 rt->flv_off += rt->flv_size - rt->flv_off;
1001 }
1002
1003 if (rt->flv_off == rt->flv_size) {
b14629e5
MS
1004 rt->skip_bytes = 4;
1005
6bf22e18
S
1006 ff_rtmp_packet_write(rt->stream, &rt->out_pkt, rt->chunk_size, rt->prev_pkt[1]);
1007 ff_rtmp_packet_destroy(&rt->out_pkt);
1008 rt->flv_size = 0;
1009 rt->flv_off = 0;
b14629e5 1010 rt->flv_header_bytes = 0;
6bf22e18 1011 }
a14c7842 1012 } while (buf_temp - buf < size);
6bf22e18 1013 return size;
9fd6b843
KS
1014}
1015
c6610a21 1016URLProtocol ff_rtmp_protocol = {
c3b05d21
MS
1017 .name = "rtmp",
1018 .url_open = rtmp_open,
1019 .url_read = rtmp_read,
1020 .url_write = rtmp_write,
1021 .url_close = rtmp_close,
7e580505 1022 .priv_data_size = sizeof(RTMPContext),
32b83aee 1023 .flags = URL_PROTOCOL_FLAG_NETWORK,
9fd6b843 1024};