Skip to content

Commit

Permalink
Preparing to serve embedded HTML content
Browse files Browse the repository at this point in the history
  • Loading branch information
wberube committed Aug 8, 2024
1 parent 5709771 commit ac156c5
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 17 deletions.
Empty file added res/index.html
Empty file.
57 changes: 40 additions & 17 deletions src/server.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#include "server.h"

IMPORT_STR(.rodata, "../res/index.html", indexhtml);
extern const char indexhtml[];

char keepRunning = 1;

enum StreamType {
Expand Down Expand Up @@ -363,6 +366,20 @@ int send_file(const int client_fd, const char *path) {
return 0;
}

int send_html(const int client_fd, const char *data) {
char *buf;
int buf_len = asprintf(
&buf,
"HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nContent-Length: "
"%ld\r\nConnection: close\r\n\r\n%s",
strlen(data), data);
buf[buf_len++] = 0;
send_to_fd(client_fd, buf, buf_len);
free(buf);
close_socket_fd(client_fd);
return 1;
}

int send_mjpeg_html(const int client_fd) {
char html[] = "<html>\n"
" <head>\n"
Expand Down Expand Up @@ -593,6 +610,11 @@ void *server_thread(void *vargp) {
break;
}

if (equals(uri, "/index.html")) {
send_html(client_fd, indexhtml);
continue;
}

if (equals(uri, "/mjpeg.html") &&
app_config.mjpeg_enable) {
send_mjpeg_html(client_fd);
Expand Down Expand Up @@ -659,7 +681,7 @@ void *server_thread(void *vargp) {
continue;
}

if (equals(uri, "/video.mp4") && app_config.mp4_enable) {
if (app_config.mp4_enable && equals(uri, "/video.mp4")) {
request_idr();
int respLen = sprintf(
response, "HTTP/1.1 200 OK\r\nContent-Type: "
Expand Down Expand Up @@ -727,10 +749,11 @@ void *server_thread(void *vargp) {
if (remain != value)
task.qfactor = result;
}
else if (equals(key, "color2gray")) {
short result = strtol(value, &remain, 10);
if (remain != value)
task.color2Gray = result;
else if (equals(key, "color2gray") || equals(key, "gray")) {
if (equals_case(value, "true") || equals(value, "1"))
task.color2Gray = 1;
else if (equals_case(value, "false") || equals(value, "0"))
task.color2Gray = 0;
}
}
}
Expand Down Expand Up @@ -773,10 +796,10 @@ void *server_thread(void *vargp) {
app_config.audio_srate = result;
}
}
}

disable_audio();
enable_audio();
disable_audio();
enable_audio();
}

respLen = sprintf(response,
"HTTP/1.1 200 OK\r\n" \
Expand Down Expand Up @@ -824,10 +847,10 @@ void *server_thread(void *vargp) {
app_config.jpeg_qfactor = result;
}
}
}

jpeg_deinit();
jpeg_init();
jpeg_deinit();
jpeg_init();
}

respLen = sprintf(response,
"HTTP/1.1 200 OK\r\n" \
Expand Down Expand Up @@ -882,10 +905,10 @@ void *server_thread(void *vargp) {
app_config.mjpeg_mode = HAL_VIDMODE_QP;
}
}
}

disable_mjpeg();
enable_mjpeg();
disable_mjpeg();
enable_mjpeg();
}

char mode[5] = "\0";
switch (app_config.mjpeg_mode) {
Expand Down Expand Up @@ -967,10 +990,10 @@ void *server_thread(void *vargp) {
app_config.mp4_profile = HAL_VIDPROFILE_HIGH;
}
}
}

disable_mp4();
enable_mp4();
disable_mp4();
enable_mp4();
}

char h265[6] = "false";
char mode[5] = "\0";
Expand Down
21 changes: 21 additions & 0 deletions src/server.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,27 @@
#include "region.h"
#include "watchdog.h"

#define IMPORT_BIN(sect, file, sym) asm (\
".section " #sect "\n" /* Change section */\
".balign 4\n" /* Word alignment */\
".global " #sym "\n" /* Export the object address */\
#sym ":\n" /* Define the object label */\
".incbin \"" file "\"\n" /* Import the file */\
".global _sizeof_" #sym "\n" /* Export the object size */\
".set _sizeof_" #sym ", . - " #sym "\n" /* Define the object size */\
".balign 4\n" /* Word alignment */\
".section \".text\"\n") /* Restore section */

#define IMPORT_STR(sect, file, sym) asm (\
".section " #sect "\n" /* Change section */\
".balign 4\n" /* Word alignment */\
".global " #sym "\n" /* Export the object address */\
#sym ":\n" /* Define the object label */\
".incbin \"" file "\"\n" /* Import the file */\
".byte 0\n" /* Null-terminate the string */\
".balign 4\n" /* Word alignment */\
".section \".text\"\n") /* Restore section */

extern char keepRunning;

int start_server();
Expand Down

0 comments on commit ac156c5

Please sign in to comment.