mirror of
https://github.com/pikvm/ustreamer.git
synced 2026-05-26 23:36:16 +00:00
testing chunks
This commit is contained in:
33
src/http.c
33
src/http.c
@@ -32,6 +32,7 @@ static void _http_callback_stream_write(struct bufferevent *buf_event, void *v_c
|
|||||||
static void _http_callback_stream_error(struct bufferevent *buf_event, short what, void *v_ctx);
|
static void _http_callback_stream_error(struct bufferevent *buf_event, short what, void *v_ctx);
|
||||||
|
|
||||||
static void _http_send_stream(struct http_server_t *server);
|
static void _http_send_stream(struct http_server_t *server);
|
||||||
|
static bool _http_check_clients_done(struct http_server_t *server);
|
||||||
static void _http_exposed_refresh(int fd, short event, void *v_server);
|
static void _http_exposed_refresh(int fd, short event, void *v_server);
|
||||||
|
|
||||||
|
|
||||||
@@ -214,6 +215,7 @@ static void _http_callback_stream_write(struct bufferevent *buf_event, void *v_c
|
|||||||
assert((buf = evbuffer_new()));
|
assert((buf = evbuffer_new()));
|
||||||
assert(!clock_gettime(CLOCK_REALTIME, &x_timestamp_spec));
|
assert(!clock_gettime(CLOCK_REALTIME, &x_timestamp_spec));
|
||||||
|
|
||||||
|
if (client->offset == 0) {
|
||||||
if (client->need_initial) {
|
if (client->need_initial) {
|
||||||
assert(evbuffer_add_printf(buf,
|
assert(evbuffer_add_printf(buf,
|
||||||
"HTTP/1.0 200 OK" RN
|
"HTTP/1.0 200 OK" RN
|
||||||
@@ -238,17 +240,33 @@ static void _http_callback_stream_write(struct bufferevent *buf_event, void *v_c
|
|||||||
(unsigned)x_timestamp_spec.tv_sec,
|
(unsigned)x_timestamp_spec.tv_sec,
|
||||||
(unsigned)(x_timestamp_spec.tv_nsec / 1000) // TODO: round?
|
(unsigned)(x_timestamp_spec.tv_nsec / 1000) // TODO: round?
|
||||||
));
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned long chunk = (client->server->run->exposed->picture.size - client->offset < 4096 ? client->server->run->exposed->picture.size - client->offset : 4096);
|
||||||
assert(!evbuffer_add(buf,
|
assert(!evbuffer_add(buf,
|
||||||
|
(void *)(client->server->run->exposed->picture.data + client->offset),
|
||||||
|
chunk * sizeof(*client->server->run->exposed->picture.data)
|
||||||
|
));
|
||||||
|
client->offset += chunk;
|
||||||
|
LOG_INFO("%lu", client->offset);
|
||||||
|
|
||||||
|
/* assert(!evbuffer_add(buf,
|
||||||
(void *)client->server->run->exposed->picture.data,
|
(void *)client->server->run->exposed->picture.data,
|
||||||
client->server->run->exposed->picture.size * sizeof(*client->server->run->exposed->picture.data)
|
client->server->run->exposed->picture.size * sizeof(*client->server->run->exposed->picture.data)
|
||||||
));
|
));*/
|
||||||
|
|
||||||
|
if (client->offset >= client->server->run->exposed->picture.size) {
|
||||||
assert(evbuffer_add_printf(buf, RN "--" BOUNDARY RN));
|
assert(evbuffer_add_printf(buf, RN "--" BOUNDARY RN));
|
||||||
|
}
|
||||||
|
|
||||||
assert(!bufferevent_write_buffer(buf_event, buf)); // FIXME
|
assert(!bufferevent_write_buffer(buf_event, buf)); // FIXME
|
||||||
evbuffer_free(buf);
|
evbuffer_free(buf);
|
||||||
|
|
||||||
|
if (client->offset >= client->server->run->exposed->picture.size) {
|
||||||
bufferevent_setcb(buf_event, NULL, NULL, _http_callback_stream_error, (void *)client);
|
bufferevent_setcb(buf_event, NULL, NULL, _http_callback_stream_error, (void *)client);
|
||||||
bufferevent_enable(buf_event, EV_READ);
|
bufferevent_enable(buf_event, EV_READ);
|
||||||
|
client->offset = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _http_callback_stream_error(UNUSED struct bufferevent *buf_event, UNUSED short what, void *v_client) {
|
static void _http_callback_stream_error(UNUSED struct bufferevent *buf_event, UNUSED short what, void *v_client) {
|
||||||
@@ -286,10 +304,21 @@ static void _http_send_stream(struct http_server_t *server) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool _http_check_clients_done(struct http_server_t *server) {
|
||||||
|
struct stream_client_t *client;
|
||||||
|
|
||||||
|
for (client = server->run->stream_clients; client != NULL; client = client->next) {
|
||||||
|
if (client->offset != 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
static void _http_exposed_refresh(UNUSED int fd, UNUSED short what, void *v_server) {
|
static void _http_exposed_refresh(UNUSED int fd, UNUSED short what, 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;
|
||||||
|
|
||||||
if (server->run->stream->updated) {
|
if (server->run->stream->updated && _http_check_clients_done(server)) {
|
||||||
LOG_DEBUG("Refreshing HTTP exposed ...");
|
LOG_DEBUG("Refreshing HTTP exposed ...");
|
||||||
|
|
||||||
A_PTHREAD_M_LOCK(&server->run->stream->mutex);
|
A_PTHREAD_M_LOCK(&server->run->stream->mutex);
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ struct stream_client_t {
|
|||||||
struct http_server_t *server;
|
struct http_server_t *server;
|
||||||
struct evhttp_request *request;
|
struct evhttp_request *request;
|
||||||
bool need_initial;
|
bool need_initial;
|
||||||
|
unsigned long offset;
|
||||||
|
|
||||||
struct stream_client_t *prev;
|
struct stream_client_t *prev;
|
||||||
struct stream_client_t *next;
|
struct stream_client_t *next;
|
||||||
|
|||||||
Reference in New Issue
Block a user