[FFmpeg-devel] [PATCH] RTMPE support
Stefano Sabatini
stefano.sabatini-lala
Sun Mar 28 00:44:49 CET 2010
On date Saturday 2010-03-27 00:13:26 -0700, Howard Chu encoded:
> Howard Chu wrote:
> >Kostya wrote:
> >>On Thu, Mar 25, 2010 at 09:06:51PM -0700, Howard Chu wrote:
> >>>+fail:
> >>>+ av_free(host);
> >>>+ av_free(playpath.av_val);
> >>
> >>Where are those allocated? And have you tested this path?
> >
> >In RTMP_ParseURL. Yes, this part is ugly, could be done differently. And yes,
> >it works here.
>
> I've moved the option parsing into librtmp, so none of these values
> are exposed now. This is better in the long run since RTMP is still
> a moving target and we're still revving new stuff into librtmp
> pretty frequently.
[...]
So if I understood correctly the various "swfurl", "pageurl", etc
parameters are directly specified in the filename?
Can you say how they need to be specified?
> Index: libavformat/librtmp.c
> ===================================================================
> --- libavformat/librtmp.c (revision 0)
> +++ libavformat/librtmp.c (revision 0)
> @@ -0,0 +1,198 @@
> +/*
> + * RTMP network protocol
> + * Copyright (c) 2010 Howard Chu
> + *
> + * This file is part of FFmpeg.
> + *
> + * FFmpeg is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation; either
> + * version 2.1 of the License, or (at your option) any later version.
> + *
> + * FFmpeg is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with FFmpeg; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
> + */
> +
> +/**
> + * @file libavformat/librtmp.c
> + * RTMP protocol based on http://rtmpdump.mplayerhq.hu librtmp
> + */
> +
> +#include "avformat.h"
> +#include "libavcodec/opt.h"
Not anymore required.
> +#include <librtmp/rtmp.h>
> +#include <librtmp/log.h>
> +
> +static int rtmp_close(URLContext *s)
> +{
> + RTMP *r = s->priv_data;
> +
> + RTMP_Close(r);
> + av_free(r);
> + return 0;
> +}
> +
> +/**
> + * Opens RTMP connection and verifies that the stream can be played.
> + *
> + * URL syntax: rtmp://server[:port][/app][/playpath]
> + * where 'app' is first one or two directories in the path
> + * (e.g. /ondemand/, /flash/live/, etc.)
> + * and 'playpath' is a file name (the rest of the path,
> + * may be prefixed with "mp4:")
> + */
> +static int rtmp_open(URLContext *s, const char *uri, int flags)
> +{
> + RTMP *r;
> + int rc;
> +
> + r = av_mallocz(sizeof(RTMP));
> + if (!r)
> + return AVERROR(ENOMEM);
> +
> + switch(av_log_get_level()) {
> + default:
> + case AV_LOG_FATAL:
> + rc = RTMP_LOGCRIT; break;
> + case AV_LOG_ERROR:
> + rc = RTMP_LOGERROR; break;
> + case AV_LOG_WARNING:
> + rc = RTMP_LOGWARNING; break;
> + case AV_LOG_INFO:
> + rc = RTMP_LOGINFO; break;
> + case AV_LOG_VERBOSE:
> + rc = RTMP_LOGDEBUG; break;
> + case AV_LOG_DEBUG:
> + rc = RTMP_LOGDEBUG2; break;
These can be put on one line and vertically aligned, should help
readability.
> + }
> + RTMP_LogSetLevel(rc);
> +
> + RTMP_Init(r);
> + if (!RTMP_SetupURL(r, s->filename)) {
> + rc = -1;
> + goto fail;
> + }
> +
> + if (flags & URL_WRONLY)
> + r->Link.protocol |= RTMP_FEATURE_WRITE;
> +
> + if (!RTMP_Connect(r, NULL) || !RTMP_ConnectStream(r, 0)) {
> + rc = -1;
> + goto fail;
> + }
> +
> + s->priv_data = r;
> + s->is_streamed = 1;
> + return 0;
> +fail:
> + av_free(r);
> + return rc;
> +}
> +
> +static int rtmp_write(URLContext *s, uint8_t *buf, int size)
> +{
> + RTMP *r = s->priv_data;
> +
> + return RTMP_Write(r, buf, size);
> +}
> +
> +static int rtmp_read(URLContext * s, uint8_t * buf, int size)
Nit: please use consistently TYPE *VAR rather than TYPE * VAR, here
and below.
> +{
> + RTMP *r = s->priv_data;
> +
> + return RTMP_Read(r, buf, size);
> +}
> +
> +static int rtmp_pause(URLContext * s, int pause)
> +{
> + RTMP *r = s->priv_data;
> +
> + if (pause)
> + r->m_pauseStamp =
> + r->m_channelTimestamp[r->m_mediaChannel];
> + if (!RTMP_SendPause(r, pause, r->m_pauseStamp))
> + return -1;
> + return 0;
> +}
> +
> +static int64_t rtmp_seek(URLContext * s, int stream_index,
> + int64_t timestamp, int flags)
> +{
> + RTMP *r = s->priv_data;
> +
> + if (flags & AVSEEK_FLAG_BYTE)
> + return AVERROR(ENOTSUP);
As I'm now an expert of error codes, I can say this is not very
correct:
http://www.opengroup.org/onlinepubs/000095399/functions/xsh_chap02_03.html
[ENOTSUP]
Not supported. The implementation does not support this feature of the Realtime Option Group.
Please use AVERROR_NOTSUPP instead (but there is still discussion
about the real meaning of that error code).
> + /* seeks are in milliseconds */
> + timestamp = av_rescale(timestamp, AV_TIME_BASE, 1000);
> + if (!RTMP_SendSeek(r, timestamp))
> + return -1;
> + return timestamp;
> +}
> +
> +URLProtocol rtmp_protocol = {
> + "rtmp",
> + rtmp_open,
> + rtmp_read,
> + rtmp_write, /* write */
> + NULL, /* seek */
> + rtmp_close,
> + NULL, /* next */
> + rtmp_pause,
> + rtmp_seek
> +};
The " /* write */" here and below is slightly confusing, as it is
indeed implemented, while the "/* seek */" and "/* next */" are
evidently useful for indicating which are the not
implemented/implementable features.
Thanks for your work, regards.
--
FFmpeg = Formidable and Fundamental Meaningless Proud Elitist Gargoyle
More information about the ffmpeg-devel
mailing list