http: add --http-listen=<ip4>, and listen by default on 127.0.0.1 (#81)

Co-authored-by: AndrolGenhald <AndrolGenhald@gmail.com>
This commit is contained in:
Kamil Trzciński 2023-07-01 16:38:36 +02:00 committed by GitHub
parent f1966ab2b9
commit 8d0c04ccd5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 37 additions and 6 deletions

View File

@ -46,6 +46,7 @@ camera_options_t camera_options = {
};
http_server_options_t http_options = {
.listen = "127.0.0.1",
.port = 8080,
.maxcons = 10
};
@ -126,6 +127,7 @@ option_t all_options[] = {
DEFINE_OPTION_DEFAULT(camera, list_options, bool, "1", "List all available options and exit."),
DEFINE_OPTION_PTR(http, listen, string, "Set the IP address the HTTP web-server will bind to. Set to 0.0.0.0 to listen on all interfaces."),
DEFINE_OPTION(http, port, uint, "Set the HTTP web-server port."),
DEFINE_OPTION(http, maxcons, uint, "Set maximum number of concurrent HTTP connections."),

View File

@ -23,6 +23,8 @@ ExecStart=/usr/local/bin/camera-streamer \
-camera-options=brightness=0.1 \
; disable auto-focus
-camera-auto_focus=1 \
--http-listen=0.0.0.0 \
--http-port=8080 \
-rtsp-port
DynamicUser=yes

View File

@ -25,6 +25,8 @@ ExecStart=/usr/local/bin/camera-streamer \
-camera-options=brightness=0.1 \
; disable auto-focus
-camera-auto_focus=0 \
--http-listen=0.0.0.0 \
--http-port=8080 \
-rtsp-port
DynamicUser=yes

View File

@ -11,6 +11,8 @@ ExecStart=/usr/local/bin/camera-streamer \
-camera-fps=30 \
; use two memory buffers to optimise usage
-camera-nbufs=3 \
--http-listen=0.0.0.0 \
--http-port=8080 \
; disable video streaming (WebRTC, RTSP, H264)
; on non-supported platforms
-camera-video.disabled

View File

@ -17,6 +17,8 @@ ExecStart=/usr/local/bin/camera-streamer \
-camera-video.height=720 \
; the stream is 853x480
-camera-stream.height=480 \
--http-listen=0.0.0.0 \
--http-port=8080 \
-rtsp-port
DynamicUser=yes

View File

@ -24,6 +24,8 @@ ExecStart=/usr/local/bin/camera-streamer \
-camera-stream.height=480 \
; bump brightness slightly
-camera-options=brightness=0.1 \
--http-listen=0.0.0.0 \
--http-port=8080 \
-rtsp-port
DynamicUser=yes

View File

@ -25,6 +25,8 @@ ExecStart=/usr/local/bin/camera-streamer \
; enable continuous autofocus
-camera-options=AfMode=2 \
-camera-options=AfRange=2 \
--http-listen=0.0.0.0 \
--http-port=8080 \
-rtsp-port
DynamicUser=yes

View File

@ -22,6 +22,7 @@ fi
set -xeo pipefail
make -j$(nproc)
$GDB ./camera-streamer -camera-path="${CAMERA_PATH[0]}" \
--http-listen=0.0.0.0 \
-camera-options=vertical_blanking=728 \
-camera-options=exposure=2444 \
-camera-options=analogue_gain=600 \

View File

@ -6,6 +6,7 @@ cd "$SCRIPT_DIR/.."
set -xeo pipefail
make -j$(nproc)
$GDB ./camera-streamer \
--http-listen=0.0.0.0 \
-camera-type=libcamera \
-camera-format=YUYV \
"$@"

View File

@ -7,4 +7,7 @@ CAMERA_PATH=( $(echo /dev/v4l/by-id/usb-*-video-index0) )
set -xeo pipefail
make -j$(nproc)
$GDB ./camera-streamer -camera-path="${CAMERA_PATH[${CAMERA_INDEX:-0}]}" "$@"
$GDB ./camera-streamer \
-camera-path="${CAMERA_PATH[${CAMERA_INDEX:-0}]}"
--http-listen=0.0.0.0 \
"$@"

View File

@ -19,19 +19,23 @@
#define HEADER_USER_AGENT "User-Agent:"
#define HEADER_HOST "Host:"
static int http_listen(int port, int maxcons)
static int http_listen(char *addr4, int port, int maxcons)
{
struct sockaddr_in server = {0};
int listenfd = -1;
char listen_addr[INET_ADDRSTRLEN];
// getaddrinfo for host
server.sin_family = AF_INET;
server.sin_addr.s_addr = INADDR_ANY;
if (inet_pton(server.sin_family, addr4, &server.sin_addr) != 1) {
perror("inet_pton");
return -1;
}
server.sin_port = htons(port);
listenfd = socket(AF_INET, SOCK_STREAM, 0);
listenfd = socket(server.sin_family, SOCK_STREAM, 0);
if (listenfd < 0) {
perror("socket");
LOG_INFO(NULL, "Invalid HTTP listen address: %s", addr4);
return -1;
}
@ -48,6 +52,13 @@ static int http_listen(int port, int maxcons)
goto error;
}
if (inet_ntop(server.sin_family, &server.sin_addr, listen_addr, sizeof(listen_addr)) == NULL) {
perror("inet_ntop");
goto error;
}
LOG_INFO(NULL, "HTTP listening on %s:%d.", listen_addr, port);
return listenfd;
error:
if (listenfd >= 0)
@ -240,7 +251,7 @@ error:
int http_server(http_server_options_t *options, http_method_t *methods)
{
int listen_fd = http_listen(options->port, options->maxcons);
int listen_fd = http_listen(options->listen, options->port, options->maxcons);
if (listen_fd < 0) {
return -1;
}

View File

@ -26,6 +26,7 @@ typedef struct http_method_s {
} http_method_t;
typedef struct http_server_options_s {
char listen[512];
unsigned port;
unsigned maxcons;
} http_server_options_t;