[vlc-devel] [PATCH 3/4] access/http: Add ICY metadata handling
Marvin Scholz
epirat07 at gmail.com
Wed Nov 1 05:16:35 CET 2017
---
modules/access/http/access.c | 10 ++++++++++
modules/access/http/resource.c | 33 +++++++++++++++++++++++++++------
modules/access/http/resource.h | 12 ++++++++++++
3 files changed, 49 insertions(+), 6 deletions(-)
diff --git a/modules/access/http/access.c b/modules/access/http/access.c
index ab72107a04..b9390fdc27 100644
--- a/modules/access/http/access.c
+++ b/modules/access/http/access.c
@@ -227,6 +227,16 @@ static int Open(vlc_object_t *obj)
goto error;
}
+ /* ICY data */
+ int metaint;
+ const char *icy_name;
+ const char *icy_genre;
+
+ vlc_http_res_get_icy_data(sys->resource, &metaint, &icy_name, &icy_genre);
+ if (metaint > 0)
+ config_PutInt(access, "icy-metaint", metaint);
+
+
char *redir = vlc_http_res_get_redirect(sys->resource);
if (redir != NULL)
{
diff --git a/modules/access/http/resource.c b/modules/access/http/resource.c
index 4f49a4bff6..4f7d170ec6 100644
--- a/modules/access/http/resource.c
+++ b/modules/access/http/resource.c
@@ -57,6 +57,9 @@ vlc_http_res_req(const struct vlc_http_resource *res, void *opaque)
vlc_http_msg_add_header(req, "Accept-Language", "%s", lang);
}
+ /* ICY metadata */
+ vlc_http_msg_add_header(req, "Icy-MetaData", "1");
+
/* Authentication */
if (res->username != NULL && res->password != NULL)
vlc_http_msg_add_creds_basic(req, false, res->username, res->password);
@@ -245,6 +248,30 @@ error:
return -1;
}
+void vlc_http_res_get_icy_data(struct vlc_http_resource *restrict res,
+ int *metaint,
+ const char **icy_name,
+ const char **icy_genre)
+{
+ *metaint = -1;
+ *icy_name = NULL;
+ *icy_genre = NULL;
+
+ int status = vlc_http_res_get_status(res);
+ if (status < 0 || (status / 100) != 2)
+ return;
+
+ *icy_name = vlc_http_msg_get_header(res->response, "Icy-Name");
+ *icy_genre = vlc_http_msg_get_header(res->response, "Icy-Genre");
+
+ const char *metaint_str = vlc_http_msg_get_header(res->response, "Icy-MetaInt");
+ if (metaint_str != NULL) {
+ int metaint_tmp = atoi(metaint_str);
+ if (metaint_tmp > 0)
+ *metaint = metaint_tmp;
+ }
+}
+
char *vlc_http_res_get_redirect(struct vlc_http_resource *restrict res)
{
int status = vlc_http_res_get_status(res);
@@ -259,12 +286,6 @@ char *vlc_http_res_get_redirect(struct vlc_http_resource *restrict res)
if (vlc_http_msg_get_token(res->response, "Pragma", "features") != NULL
&& asprintf(&url, "mmsh://%s%s", res->authority, res->path) >= 0)
return url;
-
- /* HACK: Seems like an ICY server. Redirect to ICYX scheme. */
- if ((vlc_http_msg_get_header(res->response, "Icy-Name") != NULL
- || vlc_http_msg_get_header(res->response, "Icy-Genre") != NULL)
- && asprintf(&url, "icyx://%s%s", res->authority, res->path) >= 0)
- return url;
}
/* TODO: if (status == 426 Upgrade Required) */
diff --git a/modules/access/http/resource.h b/modules/access/http/resource.h
index 22b5abac64..e1f2934e8c 100644
--- a/modules/access/http/resource.h
+++ b/modules/access/http/resource.h
@@ -85,6 +85,18 @@ int vlc_http_res_get_status(struct vlc_http_resource *res);
char *vlc_http_res_get_redirect(struct vlc_http_resource *);
/**
+ * Gets ICY header data
+ *
+ * Extracts ICY info about the stream and the ICY metadata interval,
+ * if ICY metadata is going to be used.
+ *
+ */
+void vlc_http_res_get_icy_data(struct vlc_http_resource *restrict res,
+ int *metaint,
+ const char **icy_name,
+ const char **icy_genre);
+
+/**
* Gets MIME type.
*
* @return Heap-allocated MIME type string, or NULL if unknown.
--
2.13.5 (Apple Git-94)
More information about the vlc-devel
mailing list