On Wed,  4 Jun 2014 14:33:02 -0400
Andrew Stone <and...@clovar.com> wrote:

> ---
>  libavformat/http.c | 29 +++++++++++++++++++++++++++++
>  1 file changed, 29 insertions(+)
> 
> diff --git a/libavformat/http.c b/libavformat/http.c
> index 948930a..f269675 100644
> --- a/libavformat/http.c
> +++ b/libavformat/http.c
> @@ -78,6 +78,7 @@ typedef struct {
>      int icy_metaint;
>      char *icy_metadata_headers;
>      char *icy_metadata_packet;
> +    AVDictionary *metadata;
>  #if CONFIG_ZLIB
>      int compressed;
>      z_stream inflate_stream;
> @@ -103,6 +104,7 @@ static const AVOption options[] = {
>  {"icy", "request ICY metadata", OFFSET(icy), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 
> 1, D },
>  {"icy_metadata_headers", "return ICY metadata headers", 
> OFFSET(icy_metadata_headers), AV_OPT_TYPE_STRING, {0}, 0, 0, 
> AV_OPT_FLAG_EXPORT },
>  {"icy_metadata_packet", "return current ICY metadata packet", 
> OFFSET(icy_metadata_packet), AV_OPT_TYPE_STRING, {0}, 0, 0, 
> AV_OPT_FLAG_EXPORT },
> +{"metadata", "metadata read from the bitstream", OFFSET(metadata), 
> AV_OPT_TYPE_DICT, {0}, 0, 0, AV_OPT_FLAG_EXPORT },
>  {"auth_type", "HTTP authentication type", OFFSET(auth_state.auth_type), 
> AV_OPT_TYPE_INT, {.i64 = HTTP_AUTH_NONE}, HTTP_AUTH_NONE, HTTP_AUTH_BASIC, 
> D|E, "auth_type" },
>  {"none", "No auth method set, autodetect", 0, AV_OPT_TYPE_CONST, {.i64 = 
> HTTP_AUTH_NONE}, 0, 0, D|E, "auth_type" },
>  {"basic", "HTTP basic authentication", 0, AV_OPT_TYPE_CONST, {.i64 = 
> HTTP_AUTH_BASIC}, 0, 0, D|E, "auth_type" },
> @@ -784,6 +786,32 @@ static int http_read_stream_all(URLContext *h, uint8_t 
> *buf, int size)
>      return pos;
>  }
>  
> +static void update_metadata(HTTPContext *s, char *data)
> +{
> +    char *key;
> +    char *val;
> +    char *end;
> +    char *next = data;
> +
> +    while (*next) {
> +        key = next;
> +        val = strstr(key, "='");
> +        if (!val)
> +            break;
> +        end = strstr(val, "';");
> +        if (!end)
> +            break;
> +
> +        *val = '\0';
> +        *end = '\0';
> +        val += 2;
> +
> +        av_dict_set(&s->metadata, key, val, 0);
> +
> +        next = end + 2;
> +    }
> +}

I'm not sure if this way to parse it always works (I've found ICY
metadata can be quite inconsistent), but I guess we can give it a try.
Or did you find anything definitive about the format of this data?

Also, your patch is ignoring icy_metadata_headers, which is basically
per-connection metadata.

> +
>  static int store_icy(URLContext *h, int size)
>  {
>      HTTPContext *s = h->priv_data;
> @@ -812,6 +840,7 @@ static int store_icy(URLContext *h, int size)
>              data[len + 1] = 0;
>              if ((ret = av_opt_set(s, "icy_metadata_packet", data, 0)) < 0)
>                  return ret;
> +            update_metadata(s, data);
>          }
>          s->icy_data_read = 0;
>          remaining = s->icy_metaint;

_______________________________________________
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to