diff --git a/cmd/camera-streamer.c b/cmd/camera-streamer.c index b16925d..2a108e1 100644 --- a/cmd/camera-streamer.c +++ b/cmd/camera-streamer.c @@ -14,6 +14,22 @@ extern unsigned int html_video_html_len; extern unsigned char html_jmuxer_min_js[]; extern unsigned int html_jmuxer_min_js_len; +camera_t *camera; + +void camera_http_option(http_worker_t *worker, FILE *stream) +{ + if (strstr(worker->client_method, "autofocus")) { + if (camera && !device_set_option_string(camera->camera, "AfTrigger", "1")) { + http_200(stream, "Auto-focus triggered.\r\n"); + } else { + http_500(stream, "Cannot set auto-focus.\r\n"); + } + return; + } + + http_404(stream, "No option found.\r\n"); +} + http_method_t http_methods[] = { { "GET /snapshot?", http_snapshot }, { "GET /stream?", http_stream }, @@ -23,6 +39,7 @@ http_method_t http_methods[] = { { "GET /video.h264?", http_h264_video }, { "GET /video.mkv?", http_mkv_video }, { "GET /video.mp4?", http_mp4_video }, + { "GET /option?", camera_http_option }, { "GET /jmuxer.min.js?", http_content, "text/javascript", html_jmuxer_min_js, 0, &html_jmuxer_min_js_len }, { "GET /?", http_content, "text/html", html_index_html, 0, &html_index_html_len }, { } @@ -130,10 +147,10 @@ int main(int argc, char *argv[]) } while (true) { - camera_t *camera = camera_open(&camera_options); + camera = camera_open(&camera_options); if (camera) { ret = camera_run(camera); - camera_close(camera); + camera_close(&camera); } if (camera_options.auto_reconnect > 0) { diff --git a/device/camera/camera.c b/device/camera/camera.c index a780023..087b901 100644 --- a/device/camera/camera.c +++ b/device/camera/camera.c @@ -25,15 +25,18 @@ camera_t *camera_open(camera_options_t *options) return camera; error: - camera_close(camera); + camera_close(&camera); return NULL; } -void camera_close(camera_t *camera) +void camera_close(camera_t **camerap) { - if (!camera) + if (!camerap || !*camerap) return; + camera_t *camera = *camerap; + *camerap = NULL; + for (int i = MAX_DEVICES; i-- > 0; ) { if (camera->devices[i]) { device_close(camera->devices[i]); diff --git a/device/camera/camera.h b/device/camera/camera.h index d1ab85c..db429de 100644 --- a/device/camera/camera.h +++ b/device/camera/camera.h @@ -64,7 +64,7 @@ typedef struct camera_s { camera_t *camera_open(camera_options_t *camera); int camera_set_params(camera_t *camera); -void camera_close(camera_t *camera); +void camera_close(camera_t **camera); int camera_run(camera_t *camera); link_t *camera_ensure_capture(camera_t *camera, buffer_list_t *capture); diff --git a/device/libcamera/device.cc b/device/libcamera/device.cc index 667f38d..867dc7b 100644 --- a/device/libcamera/device.cc +++ b/device/libcamera/device.cc @@ -7,9 +7,14 @@ std::string libcamera_device_option_normalize(std::string key) return key; } -libcamera::ControlInfoMap libcamera_control_list(device_t *dev) +libcamera::ControlInfoMap::Map libcamera_control_list(device_t *dev) { - return dev->libcamera->camera->controls(); + libcamera::ControlInfoMap::Map controls_map; + for (auto const &control : dev->libcamera->camera->controls()) { + controls_map[control.first] = control.second; + } + controls_map[&libcamera::controls::draft::AfTrigger] = libcamera::ControlInfo(); + return controls_map; } int libcamera_device_open(device_t *dev) diff --git a/html/index.html b/html/index.html index 3536669..2b28031 100644 --- a/html/index.html +++ b/html/index.html @@ -50,6 +50,14 @@
  • /video?res=low get a low resolution stream (if -camera-low_res_factor=X is configured).
  • +
    +
  • + The commands available on some cameras:
    +
    + +


  • diff --git a/http/http.h b/http/http.h index f4a0b76..e36d639 100644 --- a/http/http.h +++ b/http/http.h @@ -45,6 +45,7 @@ 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_200(FILE *stream, const char *data); void http_404(FILE *stream, const char *data); void http_500(FILE *stream, const char *data); @@ -54,6 +55,7 @@ void http_stream(http_worker_t *worker, FILE *stream); void http_jpeg_capture(struct buffer_s *buf); void http_jpeg_lowres_capture(struct buffer_s *buf); bool http_jpeg_needs_buffer(); +void http_option(http_worker_t *worker, FILE *stream); // H264 bool http_h264_needs_buffer(); diff --git a/http/http_methods.c b/http/http_methods.c index a3d037f..0004d54 100644 --- a/http/http_methods.c +++ b/http/http_methods.c @@ -16,7 +16,7 @@ static void http_write_response( fprintf(stream, "HTTP/1.1 %s\r\n", status ? status : "200 OK"); fprintf(stream, "Content-Type: %s\r\n", content_type ? content_type : "text/plain"); if (content_length > 0) - fprintf(stream, "Content-Type: %d\r\n", content_length); + fprintf(stream, "Content-Length: %d\r\n", content_length); fprintf(stream, "\r\n"); if (body) { fwrite(body, 1, content_length, stream); @@ -41,6 +41,11 @@ void http_content(http_worker_t *worker, FILE *stream) } } +void http_200(FILE *stream, const char *data) +{ + http_write_response(stream, "200 OK", 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);