1 /*
2 * RTMP network protocol
3 * Copyright (c) 2010 Howard Chu
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 protocol based on http://rtmpdump.mplayerhq.hu/ librtmp
25 */
26
32 #if CONFIG_NETWORK
34 #endif
36
37 #include <librtmp/rtmp.h>
38 #include <librtmp/log.h>
39
57
59 {
61 default:
68 }
69
72 }
73
75 {
78
81 return 0;
82 }
83
84 /**
85 * Open RTMP connection and verify that the stream can be played.
86 *
87 * URL syntax: rtmp://server[:port][/app][/playpath][ keyword=value]...
88 * where 'app' is first one or two directories in the path
89 * (e.g. /ondemand/, /flash/live/, etc.)
90 * and 'playpath' is a file name (the rest of the path,
91 * may be prefixed with "mp4:")
92 *
93 * Additional RTMP library options may be appended as
94 * space-separated key-value pairs.
95 */
97 {
101 /* This needs to stay allocated for as long as the RTMP context exists. */
103
105 default:
112 }
113 RTMP_LogSetLevel(
level);
115
128 char *sep, *p =
ctx->conn;
129 while (p) {
131 p += strspn(p, " ");
132 if (!*p)
133 break;
134 sep = strchr(p, ' ');
135 if (sep)
136 *sep = '0円';
138
139 if (sep)
140 p = sep + 1;
141 else
142 break;
143 }
144 }
151 if (
ctx->client_buffer_time)
153 if (
ctx->swfurl ||
ctx->swfverify) {
156 else
158 }
159
163 }
164
166 /* This will modify filename by null terminating the URL portion */
167 if (!RTMP_SetupURL(
r,
ctx->filename.str)) {
170 }
171
174
175 if (!RTMP_Connect(
r,
NULL) || !RTMP_ConnectStream(
r, 0)) {
178 }
179
180 #if CONFIG_NETWORK
182 int tmp =
ctx->buffer_size;
183 if (setsockopt(
r->m_sb.sb_socket, SOL_SOCKET, SO_SNDBUF, &
tmp,
sizeof(
tmp))) {
186 }
187 }
188 #endif
189
191 return 0;
193
194 if (rc)
197
198 return rc;
199 }
200
202 {
204 RTMP *
r = &
ctx->rtmp;
205
210 }
211
213 {
215 RTMP *
r = &
ctx->rtmp;
216
221 }
222
224 {
226 RTMP *
r = &
ctx->rtmp;
227
228 if (!RTMP_Pause(
r, pause))
230 return 0;
231 }
232
234 int64_t timestamp,
int flags)
235 {
237 RTMP *
r = &
ctx->rtmp;
238
241
242 /* seeks are in milliseconds */
243 if (stream_index < 0)
246
247 if (!RTMP_SendSeek(
r, timestamp))
249 return timestamp;
250 }
251
253 {
255 RTMP *
r = &
ctx->rtmp;
256
257 return RTMP_Socket(
r);
258 }
259
260 #define OFFSET(x) offsetof(LibRTMPContext, x)
261 #define DEC AV_OPT_FLAG_DECODING_PARAM
262 #define ENC AV_OPT_FLAG_ENCODING_PARAM
265 {
"rtmp_buffer",
"Set buffer time in milliseconds. The default is 3000.",
OFFSET(client_buffer_time),
AV_OPT_TYPE_STRING, {.str =
"3000"}, 0, 0,
DEC|
ENC},
268 {
"rtmp_live",
"Specify that the media is a live stream.",
OFFSET(live),
AV_OPT_TYPE_INT, {.i64 = 0}, INT_MIN, INT_MAX,
DEC,
"rtmp_live"},
272 {
"rtmp_pageurl",
"URL of the web page in which the media was embedded. By default no value will be sent.",
OFFSET(pageurl),
AV_OPT_TYPE_STRING, {.str =
NULL }, 0, 0,
DEC},
274 {
"rtmp_subscribe",
"Name of live stream to subscribe to. Defaults to rtmp_playpath.",
OFFSET(subscribe),
AV_OPT_TYPE_STRING, {.str =
NULL }, 0, 0,
DEC},
276 {
"rtmp_swfverify",
"URL to player swf file, compute hash/size automatically. (unimplemented)",
OFFSET(swfverify),
AV_OPT_TYPE_STRING, {.str =
NULL }, 0, 0,
DEC},
278 #if CONFIG_NETWORK
280 #endif
282 };
283
284 #define RTMP_CLASS(flavor)\
285 static const AVClass lib ## flavor ## _class = {\
286 .class_name = "lib" #flavor " protocol",\
287 .item_name = av_default_item_name,\
288 .option = options,\
289 .version = LIBAVUTIL_VERSION_INT,\
290 };
291
303 .priv_data_class = &librtmp_class,
305 };
306
318 .priv_data_class = &librtmpt_class,
320 };
321
333 .priv_data_class = &librtmpe_class,
335 };
336
348 .priv_data_class = &librtmpte_class,
350 };
351
363 .priv_data_class = &librtmps_class,
365 };