Compare commits

...

6 Commits
v0.34 ... v0.37

Author SHA1 Message Date
Devaev Maxim
56df20fe84 Bump version: 0.36 → 0.37 2018-11-07 05:59:57 +03:00
Devaev Maxim
ed7dabbfcb /ping -> /state; some docs 2018-11-07 05:59:48 +03:00
Devaev Maxim
b1d40d1b3a Bump version: 0.35 → 0.36 2018-11-07 04:22:08 +03:00
Devaev Maxim
43939c7475 combined stream_client cookie 2018-11-07 04:20:57 +03:00
Devaev Maxim
8fa6db0be1 Bump version: 0.34 → 0.35 2018-11-07 03:08:10 +03:00
Devaev Maxim
d57e9864a4 stream key param 2018-11-07 03:07:58 +03:00
8 changed files with 40 additions and 14 deletions

View File

@@ -1,7 +1,7 @@
[bumpversion] [bumpversion]
commit = True commit = True
tag = True tag = True
current_version = 0.34 current_version = 0.37
parse = (?P<major>\d+)\.(?P<minor>\d+)(\.(?P<patch>\d+)(\-(?P<release>[a-z]+))?)? parse = (?P<major>\d+)\.(?P<minor>\d+)(\.(?P<patch>\d+)(\-(?P<release>[a-z]+))?)?
serialize = serialize =
{major}.{minor} {major}.{minor}

View File

@@ -3,7 +3,7 @@
pkgname=ustreamer pkgname=ustreamer
pkgver=0.34 pkgver=0.37
pkgrel=1 pkgrel=1
pkgdesc="Lightweight and fast MJPG-HTTP streamer" pkgdesc="Lightweight and fast MJPG-HTTP streamer"
url="https://github.com/pi-kvm/ustreamer" url="https://github.com/pi-kvm/ustreamer"

View File

@@ -21,4 +21,4 @@
#pragma once #pragma once
#define VERSION "0.34" #define VERSION "0.37"

View File

@@ -11,7 +11,7 @@
<hr> <hr>
<ul> <ul>
<li> <li>
<a href="/ping"><b><samp>/ping</samp></b></a><br> <a href="/state"><b><samp>/state</samp></b></a><br>
Get JSON structure with state of the server. Get JSON structure with state of the server.
</li> </li>
<br> <br>
@@ -25,6 +25,12 @@
Get a live stream. Query params:<br> Get a live stream. Query params:<br>
<br> <br>
<ul> <ul>
<li>
<b><samp>key=abc123</samp></b><br>
User-defined key, which is part of cookie <samp>stream_client</samp>, which allows<br>
the stream client to determine its identifier and view statistics using <a href="/state"><samp>/state</samp></a>.
</li>
<br>
<li> <li>
<b><samp>extra_headers=1</samp></b><br> <b><samp>extra_headers=1</samp></b><br>
Add <samp>X-UStreamer-*</samp> headers to /stream handle (like on <a href="/snapshot"><samp>/snapshot</samp></a>). Add <samp>X-UStreamer-*</samp> headers to /stream handle (like on <a href="/snapshot"><samp>/snapshot</samp></a>).
@@ -40,7 +46,7 @@
<b><samp>dual_final_frames=1</samp></b><br> <b><samp>dual_final_frames=1</samp></b><br>
Enable workaround for Safari/WebKit bug when using option <samp>--drop-same-frames</samp>.<br> Enable workaround for Safari/WebKit bug when using option <samp>--drop-same-frames</samp>.<br>
Without this option, when the frame series is completed, WebKit-based browsers<br> Without this option, when the frame series is completed, WebKit-based browsers<br>
renders the last one with a delay. renders the last frame with a delay.
</li> </li>
</ul> </ul>
</li> </li>

View File

@@ -38,7 +38,7 @@ const char *HTML_INDEX_PAGE = " \
<hr> \ <hr> \
<ul> \ <ul> \
<li> \ <li> \
<a href=\"/ping\"><b><samp>/ping</samp></b></a><br> \ <a href=\"/state\"><b><samp>/state</samp></b></a><br> \
Get JSON structure with state of the server. \ Get JSON structure with state of the server. \
</li> \ </li> \
<br> \ <br> \
@@ -52,6 +52,12 @@ const char *HTML_INDEX_PAGE = " \
Get a live stream. Query params:<br> \ Get a live stream. Query params:<br> \
<br> \ <br> \
<ul> \ <ul> \
<li> \
<b><samp>key=abc123</samp></b><br> \
User-defined key, which is part of cookie <samp>stream_client</samp>, which allows<br> \
the stream client to determine its identifier and view statistics using <a href=\"/state\"><samp>/state</samp></a>. \
</li> \
<br> \
<li> \ <li> \
<b><samp>extra_headers=1</samp></b><br> \ <b><samp>extra_headers=1</samp></b><br> \
Add <samp>X-UStreamer-*</samp> headers to /stream handle (like on <a href=\"/snapshot\"><samp>/snapshot</samp></a>). \ Add <samp>X-UStreamer-*</samp> headers to /stream handle (like on <a href=\"/snapshot\"><samp>/snapshot</samp></a>). \
@@ -67,7 +73,7 @@ const char *HTML_INDEX_PAGE = " \
<b><samp>dual_final_frames=1</samp></b><br> \ <b><samp>dual_final_frames=1</samp></b><br> \
Enable workaround for Safari/WebKit bug when using option <samp>--drop-same-frames</samp>.<br> \ Enable workaround for Safari/WebKit bug when using option <samp>--drop-same-frames</samp>.<br> \
Without this option, when the frame series is completed, WebKit-based browsers<br> \ Without this option, when the frame series is completed, WebKit-based browsers<br> \
renders the last one with a delay. \ renders the last frame with a delay. \
</li> \ </li> \
</ul> \ </ul> \
</li> \ </li> \

View File

@@ -48,9 +48,10 @@
static bool _http_get_param_true(struct evkeyvalq *params, const char *key); static bool _http_get_param_true(struct evkeyvalq *params, const char *key);
static char *_http_get_param_uri(struct evkeyvalq *params, const char *key);
static void _http_callback_root(struct evhttp_request *request, void *arg); static void _http_callback_root(struct evhttp_request *request, void *arg);
static void _http_callback_ping(struct evhttp_request *request, void *v_server); static void _http_callback_state(struct evhttp_request *request, void *v_server);
static void _http_callback_snapshot(struct evhttp_request *request, void *v_server); static void _http_callback_snapshot(struct evhttp_request *request, void *v_server);
static void _http_callback_stream(struct evhttp_request *request, void *v_server); static void _http_callback_stream(struct evhttp_request *request, void *v_server);
@@ -90,7 +91,7 @@ struct http_server_t *http_server_init(struct stream_t *stream) {
evhttp_set_allowed_methods(run->http, EVHTTP_REQ_GET|EVHTTP_REQ_HEAD); evhttp_set_allowed_methods(run->http, EVHTTP_REQ_GET|EVHTTP_REQ_HEAD);
assert(!evhttp_set_cb(run->http, "/", _http_callback_root, NULL)); assert(!evhttp_set_cb(run->http, "/", _http_callback_root, NULL));
assert(!evhttp_set_cb(run->http, "/ping", _http_callback_ping, (void *)server)); assert(!evhttp_set_cb(run->http, "/state", _http_callback_state, (void *)server));
assert(!evhttp_set_cb(run->http, "/snapshot", _http_callback_snapshot, (void *)server)); assert(!evhttp_set_cb(run->http, "/snapshot", _http_callback_snapshot, (void *)server));
assert(!evhttp_set_cb(run->http, "/stream", _http_callback_stream, (void *)server)); assert(!evhttp_set_cb(run->http, "/stream", _http_callback_stream, (void *)server));
@@ -157,6 +158,15 @@ static bool _http_get_param_true(struct evkeyvalq *params, const char *key) {
return false; return false;
} }
static char *_http_get_param_uri(struct evkeyvalq *params, const char *key) {
const char *value_str;
if ((value_str = evhttp_find_header(params, key)) != NULL) {
return evhttp_encode_uri(value_str);
}
return NULL;
}
#define ADD_HEADER(_key, _value) \ #define ADD_HEADER(_key, _value) \
assert(!evhttp_add_header(evhttp_request_get_output_headers(request), _key, _value)) assert(!evhttp_add_header(evhttp_request_get_output_headers(request), _key, _value))
@@ -179,7 +189,7 @@ static void _http_callback_root(struct evhttp_request *request, UNUSED void *arg
evbuffer_free(buf); evbuffer_free(buf);
} }
static void _http_callback_ping(struct evhttp_request *request, void *v_server) { static void _http_callback_state(struct evhttp_request *request, void *v_server) {
struct http_server_t *server = (struct http_server_t *)v_server; struct http_server_t *server = (struct http_server_t *)v_server;
struct evbuffer *buf; struct evbuffer *buf;
@@ -189,7 +199,7 @@ static void _http_callback_ping(struct evhttp_request *request, void *v_server)
assert(evbuffer_add_printf(buf, assert(evbuffer_add_printf(buf,
"{\"source\": {\"resolution\": {\"width\": %u, \"height\": %u}," "{\"source\": {\"resolution\": {\"width\": %u, \"height\": %u},"
" \"online\": %s, \"quality\": %u, \"soft_fps\": %u, \"captured_fps\": %u}," " \"online\": %s, \"quality\": %u, \"soft_fps\": %u, \"captured_fps\": %u},"
" \"stream\": {\"queued_fps\": %u, \"clients\": %u, \"clients_stat\": {", " \"stream\": {\"queued_fps\": %u, \"clients\": %u, \"clients_stat\": {",
(server->fake_width ? server->fake_width : server->run->exposed->width), (server->fake_width ? server->fake_width : server->run->exposed->width),
(server->fake_height ? server->fake_height : server->run->exposed->height), (server->fake_height ? server->fake_height : server->run->exposed->height),
bool_to_string(server->run->exposed->online), bool_to_string(server->run->exposed->online),
@@ -292,6 +302,7 @@ static void _http_callback_stream(struct evhttp_request *request, void *v_server
client->need_first_frame = true; client->need_first_frame = true;
evhttp_parse_query(evhttp_request_get_uri(request), &params); evhttp_parse_query(evhttp_request_get_uri(request), &params);
client->key = _http_get_param_uri(&params, "key");
client->extra_headers = _http_get_param_true(&params, "extra_headers"); client->extra_headers = _http_get_param_true(&params, "extra_headers");
client->advance_headers = _http_get_param_true(&params, "advance_headers"); client->advance_headers = _http_get_param_true(&params, "advance_headers");
client->dual_final_frames = _http_get_param_true(&params, "dual_final_frames"); client->dual_final_frames = _http_get_param_true(&params, "dual_final_frames");
@@ -381,10 +392,11 @@ static void _http_callback_stream_write(struct bufferevent *buf_event, void *v_c
"Cache-Control: no-store, no-cache, must-revalidate, pre-check=0, post-check=0, max-age=0" RN "Cache-Control: no-store, no-cache, must-revalidate, pre-check=0, post-check=0, max-age=0" RN
"Pragma: no-cache" RN "Pragma: no-cache" RN
"Expires: Mon, 3 Jan 2000 12:34:56 GMT" RN "Expires: Mon, 3 Jan 2000 12:34:56 GMT" RN
"Set-Cookie: stream_client_id=%s; path=/; max-age=30" RN "Set-Cookie: stream_client=%s/%s; path=/; max-age=30" RN
"Content-Type: multipart/x-mixed-replace;boundary=" BOUNDARY RN "Content-Type: multipart/x-mixed-replace;boundary=" BOUNDARY RN
RN RN
"--" BOUNDARY RN, "--" BOUNDARY RN,
(client->key != NULL ? client->key : "0"),
client->id client->id
)); ));
@@ -486,6 +498,7 @@ static void _http_callback_stream_error(UNUSED struct bufferevent *buf_event, UN
if (client->next != NULL) { if (client->next != NULL) {
client->next->prev = client->prev; client->next->prev = client->prev;
} }
free(client->key);
free(client); free(client);
} }

View File

@@ -32,6 +32,7 @@ struct stream_client_t {
struct http_server_t *server; struct http_server_t *server;
struct evhttp_request *request; struct evhttp_request *request;
char *key;
bool extra_headers; bool extra_headers;
bool advance_headers; bool advance_headers;
bool dual_final_frames; bool dual_final_frames;

View File

@@ -135,8 +135,8 @@ static void _help(struct device_t *dev, struct encoder_t *encoder, struct http_s
printf(" It can significantly reduce the outgoing traffic, but will increase\n"); printf(" It can significantly reduce the outgoing traffic, but will increase\n");
printf(" the CPU loading. Don't use this option with analog signal sources\n"); printf(" the CPU loading. Don't use this option with analog signal sources\n");
printf(" or webcams, it's useless. Default: disabled.\n\n"); printf(" or webcams, it's useless. Default: disabled.\n\n");
printf(" --fake-width <N> -- Override image width for /ping. Default: disabled\n\n"); printf(" --fake-width <N> -- Override image width for /state. Default: disabled\n\n");
printf(" --fake-height <N> -- Override image height for /ping. Default: disabled.\n\n"); printf(" --fake-height <N> -- Override image height for /state. Default: disabled.\n\n");
printf(" --server-timeout <seconds> -- Timeout for client connections. Default: %d\n\n", server->timeout); printf(" --server-timeout <seconds> -- Timeout for client connections. Default: %d\n\n", server->timeout);
printf("Misc options:\n"); printf("Misc options:\n");
printf("-------------\n"); printf("-------------\n");