1 /*
2 * RTMP HTTP network protocol
3 * Copyright (c) 2012 Samuel Pitoiset
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 /**
23 * @file
24 * RTMP HTTP protocol
25 */
26
33
34 #define RTMPT_DEFAULT_PORT 80
35 #define RTMPTS_DEFAULT_PORT RTMPS_DEFAULT_PORT
36
37 /* protocol handler context */
41 char host[256];
///< hostname of the server
42 int port;
///< port to connect (default is 80)
43 char client_id[64];
///< client ID used for all requests except the first one
44 int seq;
///< sequence ID used for all requests
48 int initialized;
///< flag indicating when the http context is initialized
49 int finishing;
///< flag indicating when the client closes the connection
51 int tls;
///< use Transport Security Layer (RTMPTS)
53
55 {
57 char uri[2048];
60
63
66
67 /* send a new request to the server */
70
71 /* re-init output buffer */
73
74 /* read the first byte which contains the polling interval */
77
78 /* re-init the number of bytes read */
80
82 }
83
85 {
87
89 int err;
94 return err;
95 }
96 }
97
100
102 }
103
105 {
108
109 /* try to read at least 1 byte of data */
110 do {
114
117 /* Do not send new requests when the client wants to
118 * close the connection. */
120 }
121
122 /* When the client has reached end of file for the last request,
123 * we have to send a new request if we have buffered data.
124 * Otherwise, we have to send an idle POST. */
128 } else {
130 /* Wait 50ms before retrying to read a server reply in
131 * order to reduce the number of idle requests. */
133 }
134
137
140 }
141
143 /* no incoming data to handle in nonblocking mode */
145 }
146 } else {
150 }
151 } while (off <= 0);
152
153 return off;
154 }
155
157 {
159 uint8_t tmp_buf[2048];
161
163 /* client wants to close the connection */
165
166 do {
169
170 /* re-init output buffer before sending the close command */
172
175 }
176
179
181 }
182
184 {
188
191
192 /* This is the first request that is sent to the server in order to
193 * register a client on the server and start a new session. The server
194 * replies with a unique id (usually a number) that is used by the client
195 * for all future requests.
196 * Note: the reply doesn't contain a value for the polling interval.
197 * A successful connect resets the consecutive index that is used
198 * in the URLs. */
203 } else {
207 }
208
209 /* alloc the http context */
212
213 /* set options */
215 "Cache-Control: no-cache\r\n"
216 "Content-type: application/x-fcs\r\n"
217 "User-Agent: Shockwave Flash\r\n");
221
227 }
228 }
229
230 /* open the http context */
233
234 /* read the server reply which contains a unique ID */
235 for (;;) {
238 break;
245 }
246 }
248 off--;
250
251 /* http context is now initialized */
253 return 0;
254
258 }
259
260 #define OFFSET(x) offsetof(RTMP_HTTPContext, x)
261 #define DEC AV_OPT_FLAG_DECODING_PARAM
262
266 };
267
273 };
274
276 .
name =
"ffrtmphttp",
284 .default_whitelist = "https,http,tcp,tls",
285 };