mirror of
https://github.com/pikvm/ustreamer.git
synced 2026-02-18 02:55:46 +00:00
blank picture
This commit is contained in:
parent
c9c843d236
commit
1339307099
27
make-blank-h.py
Executable file
27
make-blank-h.py
Executable file
@ -0,0 +1,27 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
|
||||
# =====
|
||||
def main():
|
||||
with open("blank.jpg", "rb") as jpg_file:
|
||||
jpg_data = jpg_file.read()
|
||||
|
||||
rows = [[]]
|
||||
for ch in jpg_data:
|
||||
if len(rows[-1]) > 20:
|
||||
rows.append([])
|
||||
rows[-1].append(hex(ch))
|
||||
|
||||
text = ",\n\t".join(", ".join(row) for row in rows)
|
||||
text = "const unsigned char BLANK_JPG_DATA[] = {\n\t" + text + "\n};"
|
||||
text = "const unsigned long BLANK_JPG_SIZE = %d;\n\n" % (len(jpg_data)) + text
|
||||
text = "const unsigned BLANK_JPG_HEIGHT = 480;\n\n" + text
|
||||
text = "const unsigned BLANK_JPG_WIDTH = 640;\n" + text
|
||||
|
||||
with open("src/blank.h", "w") as h_file:
|
||||
h_file.write(text)
|
||||
|
||||
|
||||
# =====
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
7557
src/blank.h
Normal file
7557
src/blank.h
Normal file
File diff suppressed because it is too large
Load Diff
55
src/http.c
55
src/http.c
@ -18,6 +18,8 @@
|
||||
#include "stream.h"
|
||||
#include "http.h"
|
||||
|
||||
#include "blank.h"
|
||||
|
||||
|
||||
#define BOUNDARY "boundarydonotcross"
|
||||
#define RN "\r\n"
|
||||
@ -31,8 +33,9 @@ static void _http_callback_stream(struct evhttp_request *request, void *v_server
|
||||
static void _http_callback_stream_write(struct bufferevent *buf_event, 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_exposed_refresh(int fd, short event, void *v_server);
|
||||
static void _http_queue_send_stream(struct http_server_t *server);
|
||||
static void _expose_blank_picture(struct http_server_t *server);
|
||||
|
||||
|
||||
struct http_server_t *http_server_init(struct stream_t *stream) {
|
||||
@ -54,6 +57,8 @@ struct http_server_t *http_server_init(struct stream_t *stream) {
|
||||
server->timeout = 10;
|
||||
server->run = run;
|
||||
|
||||
_expose_blank_picture(server);
|
||||
|
||||
assert(!evthread_use_pthreads());
|
||||
assert((run->base = event_base_new()));
|
||||
assert((run->http = evhttp_new(run->base)));
|
||||
@ -271,7 +276,7 @@ static void _http_callback_stream_error(UNUSED struct bufferevent *buf_event, UN
|
||||
free(client);
|
||||
}
|
||||
|
||||
static void _http_send_stream(struct http_server_t *server) {
|
||||
static void _http_queue_send_stream(struct http_server_t *server) {
|
||||
struct stream_client_t *client;
|
||||
struct evhttp_connection *conn;
|
||||
struct bufferevent *buf_event;
|
||||
@ -294,8 +299,8 @@ static void _http_exposed_refresh(UNUSED int fd, UNUSED short what, void *v_serv
|
||||
|
||||
A_PTHREAD_M_LOCK(&server->run->stream->mutex);
|
||||
|
||||
if (server->run->stream->picture.size > 0) {
|
||||
if (server->run->stream->picture.allocated > server->run->exposed->picture.allocated) {
|
||||
if (server->run->stream->picture.size > 0) { // If online
|
||||
if (server->run->exposed->picture.allocated < server->run->stream->picture.allocated) {
|
||||
A_REALLOC(server->run->exposed->picture.data, server->run->stream->picture.allocated);
|
||||
server->run->exposed->picture.allocated = server->run->stream->picture.allocated;
|
||||
}
|
||||
@ -304,16 +309,42 @@ static void _http_exposed_refresh(UNUSED int fd, UNUSED short what, void *v_serv
|
||||
server->run->stream->picture.data,
|
||||
server->run->stream->picture.size * sizeof(*server->run->exposed->picture.data)
|
||||
);
|
||||
server->run->exposed->picture.size = server->run->stream->picture.size;
|
||||
server->run->exposed->width = server->run->stream->width;
|
||||
server->run->exposed->height = server->run->stream->height;
|
||||
server->run->exposed->online = true;
|
||||
|
||||
server->run->stream->updated = false;
|
||||
A_PTHREAD_M_UNLOCK(&server->run->stream->mutex);
|
||||
|
||||
} else {
|
||||
server->run->stream->updated = false;
|
||||
A_PTHREAD_M_UNLOCK(&server->run->stream->mutex);
|
||||
|
||||
_expose_blank_picture(server);
|
||||
}
|
||||
|
||||
server->run->exposed->picture.size = server->run->stream->picture.size;
|
||||
server->run->exposed->width = server->run->stream->width;
|
||||
server->run->exposed->height = server->run->stream->height;
|
||||
server->run->exposed->online = server->run->stream->online;
|
||||
server->run->stream->updated = false;
|
||||
_http_queue_send_stream(server);
|
||||
|
||||
A_PTHREAD_M_UNLOCK(&server->run->stream->mutex);
|
||||
|
||||
_http_send_stream(server);
|
||||
} else if (!server->run->exposed->online) {
|
||||
_http_queue_send_stream(server);
|
||||
}
|
||||
}
|
||||
|
||||
void _expose_blank_picture(struct http_server_t *server) {
|
||||
if (server->run->exposed->online || server->run->exposed->picture.size == 0) {
|
||||
if (server->run->exposed->picture.allocated < BLANK_JPG_SIZE) {
|
||||
A_REALLOC(server->run->exposed->picture.data, BLANK_JPG_SIZE);
|
||||
server->run->exposed->picture.allocated = BLANK_JPG_SIZE;
|
||||
}
|
||||
memcpy(
|
||||
server->run->exposed->picture.data,
|
||||
BLANK_JPG_DATA,
|
||||
BLANK_JPG_SIZE * sizeof(*server->run->exposed->picture.data)
|
||||
);
|
||||
server->run->exposed->picture.size = BLANK_JPG_SIZE;
|
||||
server->run->exposed->width = BLANK_JPG_WIDTH;
|
||||
server->run->exposed->height = BLANK_JPG_HEIGHT;
|
||||
server->run->exposed->online = false;
|
||||
}
|
||||
}
|
||||
|
||||
14
src/stream.c
14
src/stream.c
@ -90,12 +90,6 @@ void stream_loop(struct stream_t *stream) {
|
||||
LOG_DEBUG("Allocation memory for stream picture ...");
|
||||
A_CALLOC(stream->picture.data, stream->dev->run->max_picture_size);
|
||||
|
||||
A_PTHREAD_M_LOCK(&stream->mutex);
|
||||
stream->width = stream->dev->run->width;
|
||||
stream->height = stream->dev->run->height;
|
||||
stream->online = true;
|
||||
A_PTHREAD_M_UNLOCK(&stream->mutex);
|
||||
|
||||
while (!stream->dev->stop) {
|
||||
SEP_DEBUG('-');
|
||||
|
||||
@ -106,6 +100,7 @@ void stream_loop(struct stream_t *stream) {
|
||||
|
||||
if (oldest_worker && !oldest_worker->has_job && stream->dev->run->pictures[oldest_worker->ctx.index].data) {
|
||||
A_PTHREAD_M_LOCK(&stream->mutex);
|
||||
|
||||
stream->picture.size = stream->dev->run->pictures[oldest_worker->ctx.index].size;
|
||||
stream->picture.allocated = stream->dev->run->pictures[oldest_worker->ctx.index].allocated;
|
||||
memcpy(
|
||||
@ -113,7 +108,11 @@ void stream_loop(struct stream_t *stream) {
|
||||
stream->dev->run->pictures[oldest_worker->ctx.index].data,
|
||||
stream->picture.size * sizeof(*stream->picture.data)
|
||||
);
|
||||
|
||||
stream->width = stream->dev->run->width;
|
||||
stream->height = stream->dev->run->height;
|
||||
stream->updated = true;
|
||||
|
||||
A_PTHREAD_M_UNLOCK(&stream->mutex);
|
||||
|
||||
oldest_worker = oldest_worker->order_next;
|
||||
@ -248,11 +247,10 @@ void stream_loop(struct stream_t *stream) {
|
||||
}
|
||||
|
||||
A_PTHREAD_M_LOCK(&stream->mutex);
|
||||
stream->picture.size = 0;
|
||||
stream->picture.size = 0; // On stream offline
|
||||
free(stream->picture.data);
|
||||
stream->width = 0;
|
||||
stream->height = 0;
|
||||
stream->online = false;
|
||||
stream->updated = true;
|
||||
A_PTHREAD_M_UNLOCK(&stream->mutex);
|
||||
}
|
||||
|
||||
@ -53,7 +53,6 @@ struct stream_t {
|
||||
struct picture_t picture;
|
||||
unsigned width;
|
||||
unsigned height;
|
||||
bool online;
|
||||
bool updated;
|
||||
pthread_mutex_t mutex;
|
||||
struct device_t *dev;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user