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;
133 break;
134 sep = strchr(
p,
' ');
135 if (sep)
136 *sep = '0円';
138
139 if (sep)
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 {
227 RTMP *
r = &
ctx->rtmp;
228
229 if (!RTMP_Pause(
r, pause))
231 return 0;
232 }
233
236 {
239 RTMP *
r = &
ctx->rtmp;
240
243
244 /* seeks are in milliseconds */
245 if (stream_index < 0)
248
249 if (!RTMP_SendSeek(
r, timestamp))
251 return timestamp;
252 }
253
255 {
257 RTMP *
r = &
ctx->rtmp;
258
259 return RTMP_Socket(
r);
260 }
261
262 #define OFFSET(x) offsetof(LibRTMPContext, x)
263 #define DEC AV_OPT_FLAG_DECODING_PARAM
264 #define ENC AV_OPT_FLAG_ENCODING_PARAM
267 {
"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},
270 {
"rtmp_live",
"Specify that the media is a live stream.",
OFFSET(live),
AV_OPT_TYPE_INT, {.i64 = 0}, INT_MIN, INT_MAX,
DEC, .unit =
"rtmp_live"},
273 {
"recorded",
"recorded stream", 0,
AV_OPT_TYPE_CONST, {.i64 = 0}, 0, 0,
DEC, .unit =
"rtmp_live"},
274 {
"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},
276 {
"rtmp_subscribe",
"Name of live stream to subscribe to. Defaults to rtmp_playpath.",
OFFSET(subscribe),
AV_OPT_TYPE_STRING, {.str =
NULL }, 0, 0,
DEC},
278 {
"rtmp_swfverify",
"URL to player swf file, compute hash/size automatically. (unimplemented)",
OFFSET(swfverify),
AV_OPT_TYPE_STRING, {.str =
NULL }, 0, 0,
DEC},
280 #if CONFIG_NETWORK
282 #endif
284 };
285
286 #define RTMP_CLASS(flavor)\
287 static const AVClass lib ## flavor ## _class = {\
288 .class_name = "lib" #flavor " protocol",\
289 .item_name = av_default_item_name,\
290 .option = options,\
291 .version = LIBAVUTIL_VERSION_INT,\
292 };
293
305 .priv_data_class = &librtmp_class,
307 };
308
320 .priv_data_class = &librtmpt_class,
322 };
323
335 .priv_data_class = &librtmpe_class,
337 };
338
350 .priv_data_class = &librtmpte_class,
352 };
353
365 .priv_data_class = &librtmps_class,
367 };