2 * RTMP network protocol
3 * Copyright (c) 2010 Howard Chu
5 * This file is part of FFmpeg.
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.
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.
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
23 * @file libavformat/librtmp.c
24 * RTMP protocol based on http://rtmpdump.mplayerhq.hu/ librtmp
29 #include <librtmp/rtmp.h>
30 #include <librtmp/log.h>
32 static int rtmp_close(URLContext *s)
34 RTMP *r = s->priv_data;
42 * Opens RTMP connection and verifies that the stream can be played.
44 * URL syntax: rtmp://server[:port][/app][/playpath][ keyword=value]...
45 * where 'app' is first one or two directories in the path
46 * (e.g. /ondemand/, /flash/live/, etc.)
47 * and 'playpath' is a file name (the rest of the path,
48 * may be prefixed with "mp4:")
50 * Additional RTMP library options may be appended as
51 * space-separated key-value pairs.
53 static int rtmp_open(URLContext *s, const char *uri, int flags)
58 r = av_mallocz(sizeof(RTMP));
60 return AVERROR(ENOMEM);
62 switch (av_log_get_level()) {
64 case AV_LOG_FATAL: rc = RTMP_LOGCRIT; break;
65 case AV_LOG_ERROR: rc = RTMP_LOGERROR; break;
66 case AV_LOG_WARNING: rc = RTMP_LOGWARNING; break;
67 case AV_LOG_INFO: rc = RTMP_LOGINFO; break;
68 case AV_LOG_VERBOSE: rc = RTMP_LOGDEBUG; break;
69 case AV_LOG_DEBUG: rc = RTMP_LOGDEBUG2; break;
74 if (!RTMP_SetupURL(r, s->filename)) {
79 if (flags & URL_WRONLY)
80 r->Link.protocol |= RTMP_FEATURE_WRITE;
82 if (!RTMP_Connect(r, NULL) || !RTMP_ConnectStream(r, 0)) {
95 static int rtmp_write(URLContext *s, uint8_t *buf, int size)
97 RTMP *r = s->priv_data;
99 return RTMP_Write(r, buf, size);
102 static int rtmp_read(URLContext *s, uint8_t *buf, int size)
104 RTMP *r = s->priv_data;
106 return RTMP_Read(r, buf, size);
109 static int rtmp_read_pause(URLContext *s, int pause)
111 RTMP *r = s->priv_data;
115 r->m_channelTimestamp[r->m_mediaChannel];
116 if (!RTMP_SendPause(r, pause, r->m_pauseStamp))
121 static int64_t rtmp_read_seek(URLContext *s, int stream_index,
122 int64_t timestamp, int flags)
124 RTMP *r = s->priv_data;
126 if (flags & AVSEEK_FLAG_BYTE)
127 return AVERROR_NOTSUPP;
129 /* seeks are in milliseconds */
130 timestamp = av_rescale(timestamp, AV_TIME_BASE, 1000);
131 if (!RTMP_SendSeek(r, timestamp))
136 static int rtmp_get_file_handle(URLContext *s)
138 RTMP *r = s->priv_data;
140 return r->m_sb.sb_socket;
143 URLProtocol rtmp_protocol = {
156 URLProtocol rtmpt_protocol = {
169 URLProtocol rtmpe_protocol = {
182 URLProtocol rtmpte_protocol = {
195 URLProtocol rtmps_protocol = {