[FFmpeg-devel] [PATCH] libavformat/icecast.c Add Icecast protocol

Clément Bœsch u at pkh.me
Sun Aug 3 00:00:22 CEST 2014


On Mon, Jul 28, 2014 at 10:36:19AM +0200, epirat07 at gmail.com wrote:
> From: ePirat <epirat07 at gmail.com>
> 

> Fix header.

Note: you should put that under the --- below so it doesn't end up in the
commit description.

> ---
> Add Icecast protocol, a convenience wrapper for the HTTP protocol
> ---
>  Changelog                |   3 +
>  configure                |   1 +
>  doc/general.texi         |   1 +
>  doc/protocols.texi       |  42 ++++++++++
>  libavformat/Makefile     |   1 +
>  libavformat/allformats.c |   1 +
>  libavformat/icecast.c    | 209 +++++++++++++++++++++++++++++++++++++++++++++++
>  libavformat/version.h    |   4 +-
>  8 files changed, 260 insertions(+), 2 deletions(-)
>  create mode 100644 libavformat/icecast.c
> 
[...]
> diff --git a/libavformat/icecast.c b/libavformat/icecast.c
> new file mode 100644
> index 0000000..77781b2
> --- /dev/null
> +++ b/libavformat/icecast.c
> @@ -0,0 +1,209 @@
> +/*

> + * Icecast protocol for Libav

Here it's for FFmpeg

> + * Copyright (c) 2014 Marvin Scholz
> + *
> + * 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
> + */
> +
> +
[...]
> +static int icecast_open(URLContext *h, const char *uri, int flags)
> +{
> +    IcecastContext *s = h->priv_data;
> +
> +    // Dict to set options that we pass to the HTTP protocol
> +    AVDictionary *opt_dict = NULL;
> +
> +    // URI part variables
> +    char h_url[1024], host[1024], auth[1024], path[1024];
> +    char *user = NULL, *headers = NULL;
> +    int port, ret;

> +    struct AVBPrint bp;

You can remove "struct"

> +
> +    av_bprint_init(&bp, 0, 1);
> +
> +    // Build header strings
> +    cat_header(&bp, "Ice-Name", s->name);
> +    cat_header(&bp, "Ice-Description", s->description);
> +    cat_header(&bp, "Ice-URL", s->url);
> +    cat_header(&bp, "Ice-Genre", s->genre);
> +    cat_header(&bp, "Ice-Public", s->public ? "1" : "0");
> +    if (!av_bprint_is_complete(&bp)) {
> +        ret = AVERROR(ENOMEM);
> +        goto cleanup;
> +    }
> +    av_bprint_finalize(&bp, &headers);
> +
> +    // Set options
> +    av_dict_set(&opt_dict, "method", s->legacy_icecast ? "SOURCE" : "PUT", 0);
> +    av_dict_set(&opt_dict, "auth_type", "basic", 0);
> +    av_dict_set(&opt_dict, "headers", headers, 0);
> +    if (NOT_EMPTY(s->content_type))
> +        av_dict_set(&opt_dict, "content_type", s->content_type, 0);
> +    if (NOT_EMPTY(s->user_agent))
> +        av_dict_set(&opt_dict, "user_agent", s->user_agent, 0);
> +
> +    // Parse URI
> +    av_url_split(NULL, 0, auth, sizeof(auth), host, sizeof(host),
> +                 &port, path, sizeof(path), uri);
> +
> +    // Check for auth data in URI
> +    if (auth[0]) {

> +        char *sep = strchr(auth,':');

nitstyle: space after ,

> +        if (sep) {
> +            *sep = 0;
> +            sep++;
> +            if (s->pass) {
> +                av_free(s->pass);
> +                av_log(h, AV_LOG_WARNING, "Overwriting -password <pass> with URI password!\n");
> +            }
> +            s->pass = av_strdup(sep);
> +        }
> +        user = av_strdup(auth);
> +    }
> +
> +    // Build new authstring
> +    snprintf(auth, sizeof(auth),
> +             "%s:%s",
> +             user ? user : DEFAULT_ICE_USER,
> +             s->pass ? s->pass : "");
> +
> +    // Check for mountpoint (path)
> +    if (!path[0] || strcmp(path, "/") == 0) {
> +        av_log(h, AV_LOG_ERROR, "No mountpoint (path) specified!\n");
> +        ret = AVERROR(EIO);
> +        goto cleanup;
> +    }
> +
> +    // Build new URI for passing to http protocol
> +    ff_url_join(h_url, sizeof(h_url), "http", auth, host, port, "%s", path);
> +    // Finally open http proto handler
> +    ret = ffurl_open(&s->hd, h_url, AVIO_FLAG_READ_WRITE, NULL, &opt_dict);
> +
> +cleanup:

> +    // Free variables

pointless comment

> +    if (user)
> +        av_freep(&user);
> +    if (headers)
> +        av_freep(&headers);

pointless ifs

[...]

Rest LGTM. Please send a rebased patch and I'll apply.

-- 
Clément B.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 473 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20140803/a4f258b8/attachment.asc>


More information about the ffmpeg-devel mailing list