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:
parent
f1966ab2b9
commit
8d0c04ccd5
@ -46,6 +46,7 @@ camera_options_t camera_options = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
http_server_options_t http_options = {
|
http_server_options_t http_options = {
|
||||||
|
.listen = "127.0.0.1",
|
||||||
.port = 8080,
|
.port = 8080,
|
||||||
.maxcons = 10
|
.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_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, port, uint, "Set the HTTP web-server port."),
|
||||||
DEFINE_OPTION(http, maxcons, uint, "Set maximum number of concurrent HTTP connections."),
|
DEFINE_OPTION(http, maxcons, uint, "Set maximum number of concurrent HTTP connections."),
|
||||||
|
|
||||||
|
@ -23,6 +23,8 @@ ExecStart=/usr/local/bin/camera-streamer \
|
|||||||
-camera-options=brightness=0.1 \
|
-camera-options=brightness=0.1 \
|
||||||
; disable auto-focus
|
; disable auto-focus
|
||||||
-camera-auto_focus=1 \
|
-camera-auto_focus=1 \
|
||||||
|
--http-listen=0.0.0.0 \
|
||||||
|
--http-port=8080 \
|
||||||
-rtsp-port
|
-rtsp-port
|
||||||
|
|
||||||
DynamicUser=yes
|
DynamicUser=yes
|
||||||
|
@ -25,6 +25,8 @@ ExecStart=/usr/local/bin/camera-streamer \
|
|||||||
-camera-options=brightness=0.1 \
|
-camera-options=brightness=0.1 \
|
||||||
; disable auto-focus
|
; disable auto-focus
|
||||||
-camera-auto_focus=0 \
|
-camera-auto_focus=0 \
|
||||||
|
--http-listen=0.0.0.0 \
|
||||||
|
--http-port=8080 \
|
||||||
-rtsp-port
|
-rtsp-port
|
||||||
|
|
||||||
DynamicUser=yes
|
DynamicUser=yes
|
||||||
|
@ -11,6 +11,8 @@ ExecStart=/usr/local/bin/camera-streamer \
|
|||||||
-camera-fps=30 \
|
-camera-fps=30 \
|
||||||
; use two memory buffers to optimise usage
|
; use two memory buffers to optimise usage
|
||||||
-camera-nbufs=3 \
|
-camera-nbufs=3 \
|
||||||
|
--http-listen=0.0.0.0 \
|
||||||
|
--http-port=8080 \
|
||||||
; disable video streaming (WebRTC, RTSP, H264)
|
; disable video streaming (WebRTC, RTSP, H264)
|
||||||
; on non-supported platforms
|
; on non-supported platforms
|
||||||
-camera-video.disabled
|
-camera-video.disabled
|
||||||
|
@ -17,6 +17,8 @@ ExecStart=/usr/local/bin/camera-streamer \
|
|||||||
-camera-video.height=720 \
|
-camera-video.height=720 \
|
||||||
; the stream is 853x480
|
; the stream is 853x480
|
||||||
-camera-stream.height=480 \
|
-camera-stream.height=480 \
|
||||||
|
--http-listen=0.0.0.0 \
|
||||||
|
--http-port=8080 \
|
||||||
-rtsp-port
|
-rtsp-port
|
||||||
|
|
||||||
DynamicUser=yes
|
DynamicUser=yes
|
||||||
|
@ -24,6 +24,8 @@ ExecStart=/usr/local/bin/camera-streamer \
|
|||||||
-camera-stream.height=480 \
|
-camera-stream.height=480 \
|
||||||
; bump brightness slightly
|
; bump brightness slightly
|
||||||
-camera-options=brightness=0.1 \
|
-camera-options=brightness=0.1 \
|
||||||
|
--http-listen=0.0.0.0 \
|
||||||
|
--http-port=8080 \
|
||||||
-rtsp-port
|
-rtsp-port
|
||||||
|
|
||||||
DynamicUser=yes
|
DynamicUser=yes
|
||||||
|
@ -25,6 +25,8 @@ ExecStart=/usr/local/bin/camera-streamer \
|
|||||||
; enable continuous autofocus
|
; enable continuous autofocus
|
||||||
-camera-options=AfMode=2 \
|
-camera-options=AfMode=2 \
|
||||||
-camera-options=AfRange=2 \
|
-camera-options=AfRange=2 \
|
||||||
|
--http-listen=0.0.0.0 \
|
||||||
|
--http-port=8080 \
|
||||||
-rtsp-port
|
-rtsp-port
|
||||||
|
|
||||||
DynamicUser=yes
|
DynamicUser=yes
|
||||||
|
@ -22,6 +22,7 @@ fi
|
|||||||
set -xeo pipefail
|
set -xeo pipefail
|
||||||
make -j$(nproc)
|
make -j$(nproc)
|
||||||
$GDB ./camera-streamer -camera-path="${CAMERA_PATH[0]}" \
|
$GDB ./camera-streamer -camera-path="${CAMERA_PATH[0]}" \
|
||||||
|
--http-listen=0.0.0.0 \
|
||||||
-camera-options=vertical_blanking=728 \
|
-camera-options=vertical_blanking=728 \
|
||||||
-camera-options=exposure=2444 \
|
-camera-options=exposure=2444 \
|
||||||
-camera-options=analogue_gain=600 \
|
-camera-options=analogue_gain=600 \
|
||||||
|
@ -6,6 +6,7 @@ cd "$SCRIPT_DIR/.."
|
|||||||
set -xeo pipefail
|
set -xeo pipefail
|
||||||
make -j$(nproc)
|
make -j$(nproc)
|
||||||
$GDB ./camera-streamer \
|
$GDB ./camera-streamer \
|
||||||
|
--http-listen=0.0.0.0 \
|
||||||
-camera-type=libcamera \
|
-camera-type=libcamera \
|
||||||
-camera-format=YUYV \
|
-camera-format=YUYV \
|
||||||
"$@"
|
"$@"
|
||||||
|
@ -7,4 +7,7 @@ CAMERA_PATH=( $(echo /dev/v4l/by-id/usb-*-video-index0) )
|
|||||||
|
|
||||||
set -xeo pipefail
|
set -xeo pipefail
|
||||||
make -j$(nproc)
|
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 \
|
||||||
|
"$@"
|
||||||
|
@ -19,19 +19,23 @@
|
|||||||
#define HEADER_USER_AGENT "User-Agent:"
|
#define HEADER_USER_AGENT "User-Agent:"
|
||||||
#define HEADER_HOST "Host:"
|
#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};
|
struct sockaddr_in server = {0};
|
||||||
int listenfd = -1;
|
int listenfd = -1;
|
||||||
|
char listen_addr[INET_ADDRSTRLEN];
|
||||||
|
|
||||||
// getaddrinfo for host
|
// getaddrinfo for host
|
||||||
server.sin_family = AF_INET;
|
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);
|
server.sin_port = htons(port);
|
||||||
|
|
||||||
listenfd = socket(AF_INET, SOCK_STREAM, 0);
|
listenfd = socket(server.sin_family, SOCK_STREAM, 0);
|
||||||
if (listenfd < 0) {
|
if (listenfd < 0) {
|
||||||
perror("socket");
|
LOG_INFO(NULL, "Invalid HTTP listen address: %s", addr4);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,6 +52,13 @@ static int http_listen(int port, int maxcons)
|
|||||||
goto error;
|
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;
|
return listenfd;
|
||||||
error:
|
error:
|
||||||
if (listenfd >= 0)
|
if (listenfd >= 0)
|
||||||
@ -240,7 +251,7 @@ error:
|
|||||||
|
|
||||||
int http_server(http_server_options_t *options, http_method_t *methods)
|
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) {
|
if (listen_fd < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,7 @@ typedef struct http_method_s {
|
|||||||
} http_method_t;
|
} http_method_t;
|
||||||
|
|
||||||
typedef struct http_server_options_s {
|
typedef struct http_server_options_s {
|
||||||
|
char listen[512];
|
||||||
unsigned port;
|
unsigned port;
|
||||||
unsigned maxcons;
|
unsigned maxcons;
|
||||||
} http_server_options_t;
|
} http_server_options_t;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user