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
34
35 #define RTMPT_DEFAULT_PORT 80
36 #define RTMPTS_DEFAULT_PORT RTMPS_DEFAULT_PORT
37
38 /* protocol handler context */
42 char host[256];
///< hostname of the server
43 int port;
///< port to connect (default is 80)
44 char client_id[64];
///< client ID used for all requests except the first one
45 int seq;
///< sequence ID used for all requests
49 int initialized;
///< flag indicating when the http context is initialized
50 int finishing;
///< flag indicating when the client closes the connection
52 int tls;
///< use Transport Security Layer (RTMPTS)
54
56 {
58 char uri[2048];
61
64
67
68 /* send a new request to the server */
71
72 /* re-init output buffer */
74
75 /* read the first byte which contains the polling interval */
78
79 /* re-init the number of bytes read */
81
83 }
84
86 {
88
90 int err;
95 return err;
96 }
97 }
98
101
103 }
104
106 {
109
110 /* try to read at least 1 byte of data */
111 do {
115
118 /* Do not send new requests when the client wants to
119 * close the connection. */
121 }
122
123 /* When the client has reached end of file for the last request,
124 * we have to send a new request if we have buffered data.
125 * Otherwise, we have to send an idle POST. */
129 } else {
131 /* Wait 50ms before retrying to read a server reply in
132 * order to reduce the number of idle requets. */
134 }
135
138
141 }
142
144 /* no incoming data to handle in nonblocking mode */
146 }
147 } else {
151 }
152 } while (off <= 0);
153
154 return off;
155 }
156
158 {
162
164 /* client wants to close the connection */
166
167 do {
169 } while (ret > 0);
170
171 /* re-init output buffer before sending the close command */
173
176 }
177
180
182 }
183
185 {
187 char headers[1024], url[1024];
189
191 NULL, 0, uri);
192
193 /* This is the first request that is sent to the server in order to
194 * register a client on the server and start a new session. The server
195 * replies with a unique id (usually a number) that is used by the client
196 * for all future requests.
197 * Note: the reply doesn't contain a value for the polling interval.
198 * A successful connect resets the consecutive index that is used
199 * in the URLs. */
204 } else {
208 }
209
210 /* alloc the http context */
212 goto fail;
213
214 /* set options */
216 "Cache-Control: no-cache\r\n"
217 "Content-type: application/x-fcs\r\n"
218 "User-Agent: Shockwave Flash\r\n");
222
223 /* open the http context */
225 goto fail;
226
227 /* read the server reply which contains a unique ID */
228 for (;;) {
231 break;
232 if (ret < 0)
233 goto fail;
237 goto fail;
238 }
239 }
241 off--;
243
244 /* http context is now initialized */
246 return 0;
247
248 fail:
251 }
252
253 #define OFFSET(x) offsetof(RTMP_HTTPContext, x)
254 #define DEC AV_OPT_FLAG_DECODING_PARAM
255
257 {
"ffrtmphttp_tls",
"Use a HTTPS tunneling connection (RTMPTS).",
OFFSET(tls),
AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1,
DEC},
258 { NULL },
259 };
260
266 };
267
269 .
name =
"ffrtmphttp",
276 .priv_data_class= &ffrtmphttp_class,
277 };