[vlc-devel] [PATCH] vlc_stream/http: add GET_CONTENT_ENCODING
Francois Cartegnie
fcvlcdev at free.fr
Thu Jul 6 19:46:20 CEST 2017
Because there's no way to tell if the content
is a natively compressed file, or has been compressed
by http. (for conditional insertion of deflate filter)
---
include/vlc_stream.h | 1 +
modules/access/http/access.c | 8 ++++++++
modules/access/http/file.h | 1 +
modules/access/http/live.h | 1 +
modules/access/http/resource.c | 10 ++++++++++
modules/access/http/resource.h | 7 +++++++
modules/stream_filter/cache_block.c | 1 +
modules/stream_filter/cache_read.c | 1 +
modules/stream_filter/inflate.c | 1 +
modules/stream_filter/prefetch.c | 2 ++
src/input/stream_memory.c | 1 +
11 files changed, 34 insertions(+)
diff --git a/include/vlc_stream.h b/include/vlc_stream.h
index 182b633..bf31120 100644
--- a/include/vlc_stream.h
+++ b/include/vlc_stream.h
@@ -153,6 +153,7 @@ enum stream_query_e
STREAM_GET_META, /**< arg1= vlc_meta_t * res=can fail */
STREAM_GET_CONTENT_TYPE, /**< arg1= char ** res=can fail */
STREAM_GET_SIGNAL, /**< arg1=double *pf_quality, arg2=double *pf_strength res=can fail */
+ STREAM_GET_CONTENT_ENCODING,/**< arg1= char ** res=can fail */
STREAM_SET_PAUSE_STATE = 0x200, /**< arg1= bool res=can fail */
STREAM_SET_TITLE, /**< arg1= int res=can fail */
diff --git a/modules/access/http/access.c b/modules/access/http/access.c
index 4c772d5..93332a2 100644
--- a/modules/access/http/access.c
+++ b/modules/access/http/access.c
@@ -101,6 +101,10 @@ static int FileControl(access_t *access, int query, va_list args)
*va_arg(args, char **) = vlc_http_file_get_type(sys->resource);
break;
+ case STREAM_GET_CONTENT_ENCODING:
+ *va_arg(args, char **) = vlc_http_file_get_content_encoding(sys->resource);
+ break;
+
case STREAM_SET_PAUSE_STATE:
break;
@@ -149,6 +153,10 @@ static int LiveControl(access_t *access, int query, va_list args)
*va_arg(args, char **) = vlc_http_live_get_type(sys->resource);
break;
+ case STREAM_GET_CONTENT_ENCODING:
+ *va_arg(args, char **) = vlc_http_live_get_content_encoding(sys->resource);
+ break;
+
default:
return VLC_EGENERIC;
}
diff --git a/modules/access/http/file.h b/modules/access/http/file.h
index 802cf8f..003725a 100644
--- a/modules/access/http/file.h
+++ b/modules/access/http/file.h
@@ -82,6 +82,7 @@ struct block_t *vlc_http_file_read(struct vlc_http_resource *);
#define vlc_http_file_get_status vlc_http_res_get_status
#define vlc_http_file_get_redirect vlc_http_res_get_redirect
#define vlc_http_file_get_type vlc_http_res_get_type
+#define vlc_http_file_get_content_encoding vlc_http_res_get_content_encoding
#define vlc_http_file_destroy vlc_http_res_destroy
/** @} */
diff --git a/modules/access/http/live.h b/modules/access/http/live.h
index 552df6c..916e613 100644
--- a/modules/access/http/live.h
+++ b/modules/access/http/live.h
@@ -36,6 +36,7 @@ struct block_t *vlc_http_live_read(struct vlc_http_resource *);
#define vlc_http_live_get_status vlc_http_res_get_status
#define vlc_http_live_get_redirect vlc_http_res_get_redirect
#define vlc_http_live_get_type vlc_http_res_get_type
+#define vlc_http_live_get_content_encoding vlc_http_res_get_content_encoding
#define vlc_http_live_destroye vlc_http_res_destroy
/** @} */
diff --git a/modules/access/http/resource.c b/modules/access/http/resource.c
index ca55b49..84377aa 100644
--- a/modules/access/http/resource.c
+++ b/modules/access/http/resource.c
@@ -315,6 +315,16 @@ char *vlc_http_res_get_type(struct vlc_http_resource *res)
return (type != NULL) ? strdup(type) : NULL;
}
+char *vlc_http_res_get_content_encoding(struct vlc_http_resource *res)
+{
+ int status = vlc_http_res_get_status(res);
+ if (status < 200 || status >= 300)
+ return NULL;
+
+ const char *enc = vlc_http_msg_get_header(res->response, "Content-Encoding");
+ return (enc != NULL) ? strdup(enc) : NULL;
+}
+
struct block_t *vlc_http_res_read(struct vlc_http_resource *res)
{
int status = vlc_http_res_get_status(res);
diff --git a/modules/access/http/resource.h b/modules/access/http/resource.h
index 22b5aba..15972bd 100644
--- a/modules/access/http/resource.h
+++ b/modules/access/http/resource.h
@@ -92,6 +92,13 @@ char *vlc_http_res_get_redirect(struct vlc_http_resource *);
char *vlc_http_res_get_type(struct vlc_http_resource *);
/**
+ * Gets negociated Content Encoding.
+ *
+ * @return Heap-allocated MIME type string, or NULL if unknown.
+ */
+char *vlc_http_res_get_content_encoding(struct vlc_http_resource *);
+
+/**
* Reads data.
*/
struct block_t *vlc_http_res_read(struct vlc_http_resource *);
diff --git a/modules/stream_filter/cache_block.c b/modules/stream_filter/cache_block.c
index fc1187e..914a0b8 100644
--- a/modules/stream_filter/cache_block.c
+++ b/modules/stream_filter/cache_block.c
@@ -410,6 +410,7 @@ static int AStreamControl(stream_t *s, int i_query, va_list args)
case STREAM_GET_SEEKPOINT:
case STREAM_GET_META:
case STREAM_GET_CONTENT_TYPE:
+ case STREAM_GET_CONTENT_ENCODING:
case STREAM_GET_SIGNAL:
case STREAM_SET_PAUSE_STATE:
case STREAM_SET_PRIVATE_ID_STATE:
diff --git a/modules/stream_filter/cache_read.c b/modules/stream_filter/cache_read.c
index d9c33b5..ba0c07c 100644
--- a/modules/stream_filter/cache_read.c
+++ b/modules/stream_filter/cache_read.c
@@ -464,6 +464,7 @@ static int AStreamControl(stream_t *s, int i_query, va_list args)
case STREAM_GET_SEEKPOINT:
case STREAM_GET_META:
case STREAM_GET_CONTENT_TYPE:
+ case STREAM_GET_CONTENT_ENCODING:
case STREAM_GET_SIGNAL:
case STREAM_SET_PAUSE_STATE:
case STREAM_SET_PRIVATE_ID_STATE:
diff --git a/modules/stream_filter/inflate.c b/modules/stream_filter/inflate.c
index 05f3a5c..4f9bc21 100644
--- a/modules/stream_filter/inflate.c
+++ b/modules/stream_filter/inflate.c
@@ -125,6 +125,7 @@ static int Control(stream_t *stream, int query, va_list args)
case STREAM_IS_DIRECTORY:
case STREAM_GET_SIZE:
case STREAM_GET_TITLE_INFO:
+ case STREAM_GET_CONTENT_ENCODING:
case STREAM_GET_TITLE:
case STREAM_GET_SEEKPOINT:
case STREAM_SET_TITLE:
diff --git a/modules/stream_filter/prefetch.c b/modules/stream_filter/prefetch.c
index b1cb479..9e9b3b9 100644
--- a/modules/stream_filter/prefetch.c
+++ b/modules/stream_filter/prefetch.c
@@ -367,6 +367,8 @@ static int Control(stream_t *stream, int query, va_list args)
case STREAM_GET_PTS_DELAY:
*va_arg(args, int64_t *) = sys->pts_delay;
break;
+ case STREAM_GET_CONTENT_ENCODING:
+ return vlc_stream_vaControl(stream->p_source, query, args);
case STREAM_GET_TITLE_INFO:
case STREAM_GET_TITLE:
case STREAM_GET_SEEKPOINT:
diff --git a/src/input/stream_memory.c b/src/input/stream_memory.c
index f6b220c..0e9e7db 100644
--- a/src/input/stream_memory.c
+++ b/src/input/stream_memory.c
@@ -111,6 +111,7 @@ static int Control( stream_t *s, int i_query, va_list args )
case STREAM_GET_SEEKPOINT:
case STREAM_GET_META:
case STREAM_GET_CONTENT_TYPE:
+ case STREAM_GET_CONTENT_ENCODING:
case STREAM_GET_SIGNAL:
case STREAM_SET_TITLE:
case STREAM_SET_SEEKPOINT:
--
2.9.4
More information about the vlc-devel
mailing list