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
24
* RTMP protocol based on http://rtmpdump.mplayerhq.hu/ librtmp
29
#include <librtmp/rtmp.h>
30
#include <librtmp/log.h>
32
static void rtmp_log(int level, const char *fmt, va_list args)
36
case RTMP_LOGCRIT: level = AV_LOG_FATAL; break;
37
case RTMP_LOGERROR: level = AV_LOG_ERROR; break;
38
case RTMP_LOGWARNING: level = AV_LOG_WARNING; break;
39
case RTMP_LOGINFO: level = AV_LOG_INFO; break;
40
case RTMP_LOGDEBUG: level = AV_LOG_VERBOSE; break;
41
case RTMP_LOGDEBUG2: level = AV_LOG_DEBUG; break;
44
av_vlog(NULL, level, fmt, args);
45
av_log(NULL, level, "\n");
48
static int rtmp_close(URLContext *s)
50
RTMP *r = s->priv_data;
58
* Opens RTMP connection and verifies that the stream can be played.
60
* URL syntax: rtmp://server[:port][/app][/playpath][ keyword=value]...
61
* where 'app' is first one or two directories in the path
62
* (e.g. /ondemand/, /flash/live/, etc.)
63
* and 'playpath' is a file name (the rest of the path,
64
* may be prefixed with "mp4:")
66
* Additional RTMP library options may be appended as
67
* space-separated key-value pairs.
69
static int rtmp_open(URLContext *s, const char *uri, int flags)
74
r = av_mallocz(sizeof(RTMP));
76
return AVERROR(ENOMEM);
78
switch (av_log_get_level()) {
80
case AV_LOG_FATAL: rc = RTMP_LOGCRIT; break;
81
case AV_LOG_ERROR: rc = RTMP_LOGERROR; break;
82
case AV_LOG_WARNING: rc = RTMP_LOGWARNING; break;
83
case AV_LOG_INFO: rc = RTMP_LOGINFO; break;
84
case AV_LOG_VERBOSE: rc = RTMP_LOGDEBUG; break;
85
case AV_LOG_DEBUG: rc = RTMP_LOGDEBUG2; break;
88
RTMP_LogSetCallback(rtmp_log);
91
if (!RTMP_SetupURL(r, s->filename)) {
96
if (flags & URL_WRONLY)
97
r->Link.protocol |= RTMP_FEATURE_WRITE;
99
if (!RTMP_Connect(r, NULL) || !RTMP_ConnectStream(r, 0)) {
112
static int rtmp_write(URLContext *s, uint8_t *buf, int size)
114
RTMP *r = s->priv_data;
116
return RTMP_Write(r, buf, size);
119
static int rtmp_read(URLContext *s, uint8_t *buf, int size)
121
RTMP *r = s->priv_data;
123
return RTMP_Read(r, buf, size);
126
static int rtmp_read_pause(URLContext *s, int pause)
128
RTMP *r = s->priv_data;
132
r->m_channelTimestamp[r->m_mediaChannel];
133
if (!RTMP_SendPause(r, pause, r->m_pauseStamp))
138
static int64_t rtmp_read_seek(URLContext *s, int stream_index,
139
int64_t timestamp, int flags)
141
RTMP *r = s->priv_data;
143
if (flags & AVSEEK_FLAG_BYTE)
144
return AVERROR(ENOSYS);
146
/* seeks are in milliseconds */
147
if (stream_index < 0)
148
timestamp = av_rescale_rnd(timestamp, 1000, AV_TIME_BASE,
149
flags & AVSEEK_FLAG_BACKWARD ? AV_ROUND_DOWN : AV_ROUND_UP);
151
if (!RTMP_SendSeek(r, timestamp))
156
static int rtmp_get_file_handle(URLContext *s)
158
RTMP *r = s->priv_data;
160
return r->m_sb.sb_socket;
163
URLProtocol rtmp_protocol = {
176
URLProtocol rtmpt_protocol = {
189
URLProtocol rtmpe_protocol = {
202
URLProtocol rtmpte_protocol = {
215
URLProtocol rtmps_protocol = {