MCPcopy Create free account
hub / github.com/FFmpeg/FFmpeg / rtmp_http_open

Function rtmp_http_open

libavformat/rtmphttp.c:183–258  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

181}
182
183static int rtmp_http_open(URLContext *h, const char *uri, int flags)
184{
185 RTMP_HTTPContext *rt = h->priv_data;
186 char headers[1024], url[1024];
187 int ret, off = 0;
188
189 av_url_split(NULL, 0, NULL, 0, rt->host, sizeof(rt->host), &rt->port,
190 NULL, 0, uri);
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. */
199 if (rt->tls) {
200 if (rt->port < 0)
201 rt->port = RTMPTS_DEFAULT_PORT;
202 ff_url_join(url, sizeof(url), "https", NULL, rt->host, rt->port, "/open/1");
203 } else {
204 if (rt->port < 0)
205 rt->port = RTMPT_DEFAULT_PORT;
206 ff_url_join(url, sizeof(url), "http", NULL, rt->host, rt->port, "/open/1");
207 }
208
209 /* alloc the http context */
210 if ((ret = ffurl_alloc(&rt->stream, url, AVIO_FLAG_READ_WRITE, &h->interrupt_callback)) < 0)
211 goto fail;
212
213 /* set options */
214 snprintf(headers, sizeof(headers),
215 "Cache-Control: no-cache\r\n"
216 "Content-type: application/x-fcs\r\n"
217 "User-Agent: Shockwave Flash\r\n");
218 av_opt_set(rt->stream->priv_data, "headers", headers, 0);
219 av_opt_set(rt->stream->priv_data, "multiple_requests", "1", 0);
220 av_opt_set_bin(rt->stream->priv_data, "post_data", "", 1, 0);
221
222 if (!rt->stream->protocol_whitelist && h->protocol_whitelist) {
223 rt->stream->protocol_whitelist = av_strdup(h->protocol_whitelist);
224 if (!rt->stream->protocol_whitelist) {
225 ret = AVERROR(ENOMEM);
226 goto fail;
227 }
228 }
229
230 /* open the http context */
231 if ((ret = ffurl_connect(rt->stream, NULL)) < 0)
232 goto fail;
233
234 /* read the server reply which contains a unique ID */
235 for (;;) {
236 ret = ffurl_read(rt->stream, rt->client_id + off, sizeof(rt->client_id) - off);
237 if (!ret || ret == AVERROR_EOF)
238 break;
239 if (ret < 0)
240 goto fail;

Callers

nothing calls this directly

Calls 10

av_url_splitFunction · 0.85
ff_url_joinFunction · 0.85
ffurl_allocFunction · 0.85
av_opt_setFunction · 0.85
av_opt_set_binFunction · 0.85
av_strdupFunction · 0.85
ffurl_connectFunction · 0.85
ffurl_readFunction · 0.85
av_isspaceFunction · 0.85
rtmp_http_closeFunction · 0.85

Tested by

no test coverage detected