]> git.sesse.net Git - ffmpeg/commitdiff
Merge commit '3a6bb9735053c453f806ceab1d91124648d90aca'
authorMichael Niedermayer <michaelni@gmx.at>
Sat, 15 Nov 2014 10:28:06 +0000 (11:28 +0100)
committerMichael Niedermayer <michaelni@gmx.at>
Sat, 15 Nov 2014 10:30:42 +0000 (11:30 +0100)
* commit '3a6bb9735053c453f806ceab1d91124648d90aca':
  Icecast: Send 100-continue header if possible

See: 17dc39e76baf8a481fc8b1d24ee4cf7a6ffe1c1d
Merged-by: Michael Niedermayer <michaelni@gmx.at>
1  2 
libavformat/icecast.c

diff --combined libavformat/icecast.c
index 973c0c26a245a73fae69e9ccc5d6dde22f0cc344,1dc08ab3656410f228f3f9e159df0714d386b1f8..a7c7001f03a5772bcdcf71908c726dfc222f950f
@@@ -1,27 -1,26 +1,27 @@@
  /*
 - * Icecast protocol for Libav
 + * Icecast protocol for FFmpeg
   * Copyright (c) 2014 Marvin Scholz
   *
 - * This file is part of Libav.
 + * This file is part of FFmpeg.
   *
 - * Libav is free software; you can redistribute it and/or
 + * 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.
   *
 - * Libav is distributed in the hope that it will be useful,
 + * 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 Libav; if not, write to the Free Software
 + * License along with FFmpeg; if not, write to the Free Software
   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
   */
  
  
  #include "libavutil/avstring.h"
 +#include "libavutil/bprint.h"
  #include "libavutil/opt.h"
  
  #include "avformat.h"
@@@ -66,10 -65,27 +66,10 @@@ static const AVOption options[] = 
  };
  
  
 -static char *cat_header(char buf[], const char key[], const char value[])
 +static void cat_header(AVBPrint *bp, const char key[], const char value[])
  {
 -    if (NOT_EMPTY(value)) {
 -        int len = strlen(key) + strlen(value) + 5;
 -        int is_first = !buf;
 -        char *tmp = NULL;
 -
 -        if (buf)
 -            len += strlen(buf);
 -        if (!(tmp = av_realloc(buf, len))) {
 -            av_freep(&buf);
 -            return NULL;
 -        } else {
 -            buf = tmp;
 -        }
 -        if (is_first)
 -            *buf = '\0';
 -
 -        av_strlcatf(buf, len, "%s: %s\r\n", key, value);
 -    }
 -    return buf;
 +    if (NOT_EMPTY(value))
 +        av_bprintf(bp, "%s: %s\r\n", key, value);
  }
  
  static int icecast_close(URLContext *h)
@@@ -91,35 -107,29 +91,35 @@@ static int icecast_open(URLContext *h, 
      char h_url[1024], host[1024], auth[1024], path[1024];
      char *headers = NULL, *user = NULL;
      int port, ret;
 +    AVBPrint bp;
  
      if (flags & AVIO_FLAG_READ)
          return AVERROR(ENOSYS);
  
 +    av_bprint_init(&bp, 0, 1);
 +
      // Build header strings
 -    headers = cat_header(headers, "Ice-Name", s->name);
 -    headers = cat_header(headers, "Ice-Description", s->description);
 -    headers = cat_header(headers, "Ice-URL", s->url);
 -    headers = cat_header(headers, "Ice-Genre", s->genre);
 -    headers = cat_header(headers, "Ice-Public", s->public ? "1" : "0");
 -    if (!headers) {
 +    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);
      av_dict_set(&opt_dict, "chunked_post", "0", 0);
+     av_dict_set(&opt_dict, "send_expect_100", s->legacy_icecast ? "0" : "1", 0);
      if (NOT_EMPTY(s->content_type))
          av_dict_set(&opt_dict, "content_type", s->content_type, 0);
-     av_dict_set(&opt_dict, "send_expect_100", s->legacy_icecast ? "0" : "1", 0);
 +    else
 +        av_dict_set(&opt_dict, "content_type", "audio/mpeg", 0);
      if (NOT_EMPTY(s->user_agent))
          av_dict_set(&opt_dict, "user_agent", s->user_agent, 0);
  
  
      // Check for auth data in URI
      if (auth[0]) {
 -        char *sep = strchr(auth,':');
 +        char *sep = strchr(auth, ':');
          if (sep) {
              *sep = 0;
              sep++;
      ret = ffurl_open(&s->hd, h_url, AVIO_FLAG_READ_WRITE, NULL, &opt_dict);
  
  cleanup:
 -    // Free variables
      av_freep(&user);
      av_freep(&headers);
      av_dict_free(&opt_dict);