Add WebRTC support using libdatachannel
The WebRTC is exposed via `/video.html` endpoint and enabled by default as long as h264 stream is available.
This commit is contained in:
@ -14,6 +14,9 @@
|
||||
#include "http.h"
|
||||
#include "util/opts/log.h"
|
||||
|
||||
#define HEADER_RANGE "Range:"
|
||||
#define HEADER_CONTENT_LENGTH "Content-Length:"
|
||||
|
||||
static int http_listen(int port, int maxcons)
|
||||
{
|
||||
struct sockaddr_in server = {0};
|
||||
@ -92,6 +95,7 @@ static void http_process(http_worker_t *worker, FILE *stream)
|
||||
}
|
||||
|
||||
worker->range_header[0] = 0;
|
||||
worker->content_length = -1;
|
||||
|
||||
// Consume headers
|
||||
for(int i = 0; i < 50; i++) {
|
||||
@ -101,9 +105,12 @@ static void http_process(http_worker_t *worker, FILE *stream)
|
||||
if (line[0] == '\r' && line[1] == '\n')
|
||||
break;
|
||||
|
||||
if (strcasestr(line, "Range:") == line) {
|
||||
if (strcasestr(line, HEADER_RANGE) == line) {
|
||||
strcpy(worker->range_header, line);
|
||||
}
|
||||
if (strcasestr(line, HEADER_CONTENT_LENGTH) == line) {
|
||||
worker->content_length = atoi(line + strlen(HEADER_CONTENT_LENGTH));
|
||||
}
|
||||
}
|
||||
|
||||
worker->current_method = NULL;
|
||||
|
@ -31,6 +31,7 @@ typedef struct http_worker_s {
|
||||
pthread_t thread;
|
||||
|
||||
int client_fd;
|
||||
int content_length;
|
||||
struct sockaddr_in client_addr;
|
||||
char *client_host;
|
||||
char client_method[BUFSIZE];
|
||||
@ -46,7 +47,9 @@ typedef struct http_server_options_s {
|
||||
|
||||
int http_server(http_server_options_t *options, http_method_t *methods);
|
||||
void http_content(http_worker_t *worker, FILE *stream);
|
||||
void http_write_response(FILE *stream, const char *status, const char *content_type, const char *body, unsigned content_length);
|
||||
void http_200(FILE *stream, const char *data);
|
||||
void http_400(FILE *stream, const char *data);
|
||||
void http_404(FILE *stream, const char *data);
|
||||
void http_500(FILE *stream, const char *data);
|
||||
void *http_enum_params(http_worker_t *worker, FILE *stream, http_param_fn fn, void *opaque);
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
#include "http.h"
|
||||
|
||||
static void http_write_response(
|
||||
void http_write_response(
|
||||
FILE *stream,
|
||||
const char *status,
|
||||
const char *content_type,
|
||||
@ -46,6 +46,11 @@ void http_200(FILE *stream, const char *data)
|
||||
http_write_response(stream, "200 OK", NULL, data ? data : "Nothing here.\n", 0);
|
||||
}
|
||||
|
||||
void http_400(FILE *stream, const char *data)
|
||||
{
|
||||
http_write_response(stream, "400 Bad Request", NULL, data ? data : "Nothing here.\n", 0);
|
||||
}
|
||||
|
||||
void http_404(FILE *stream, const char *data)
|
||||
{
|
||||
http_write_response(stream, "404 Not Found", NULL, data ? data : "Nothing here.\n", 0);
|
||||
|
Reference in New Issue
Block a user