Add Af-Trigger

This commit is contained in:
Kamil Trzcinski 2022-07-05 12:05:17 +02:00
parent 26d94709e3
commit 4eaa42f1ea
7 changed files with 49 additions and 9 deletions

View File

@ -14,6 +14,22 @@ extern unsigned int html_video_html_len;
extern unsigned char html_jmuxer_min_js[]; extern unsigned char html_jmuxer_min_js[];
extern unsigned int html_jmuxer_min_js_len; 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[] = { http_method_t http_methods[] = {
{ "GET /snapshot?", http_snapshot }, { "GET /snapshot?", http_snapshot },
{ "GET /stream?", http_stream }, { "GET /stream?", http_stream },
@ -23,6 +39,7 @@ http_method_t http_methods[] = {
{ "GET /video.h264?", http_h264_video }, { "GET /video.h264?", http_h264_video },
{ "GET /video.mkv?", http_mkv_video }, { "GET /video.mkv?", http_mkv_video },
{ "GET /video.mp4?", http_mp4_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 /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 }, { "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) { while (true) {
camera_t *camera = camera_open(&camera_options); camera = camera_open(&camera_options);
if (camera) { if (camera) {
ret = camera_run(camera); ret = camera_run(camera);
camera_close(camera); camera_close(&camera);
} }
if (camera_options.auto_reconnect > 0) { if (camera_options.auto_reconnect > 0) {

View File

@ -25,15 +25,18 @@ camera_t *camera_open(camera_options_t *options)
return camera; return camera;
error: error:
camera_close(camera); camera_close(&camera);
return NULL; return NULL;
} }
void camera_close(camera_t *camera) void camera_close(camera_t **camerap)
{ {
if (!camera) if (!camerap || !*camerap)
return; return;
camera_t *camera = *camerap;
*camerap = NULL;
for (int i = MAX_DEVICES; i-- > 0; ) { for (int i = MAX_DEVICES; i-- > 0; ) {
if (camera->devices[i]) { if (camera->devices[i]) {
device_close(camera->devices[i]); device_close(camera->devices[i]);

View File

@ -64,7 +64,7 @@ typedef struct camera_s {
camera_t *camera_open(camera_options_t *camera); camera_t *camera_open(camera_options_t *camera);
int camera_set_params(camera_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); int camera_run(camera_t *camera);
link_t *camera_ensure_capture(camera_t *camera, buffer_list_t *capture); link_t *camera_ensure_capture(camera_t *camera, buffer_list_t *capture);

View File

@ -7,9 +7,14 @@ std::string libcamera_device_option_normalize(std::string key)
return 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) int libcamera_device_open(device_t *dev)

View File

@ -50,6 +50,14 @@
<li><a href="video?res=low">/video?res=low</a> get a low resolution stream (if -camera-low_res_factor=X is configured).</li> <li><a href="video?res=low">/video?res=low</a> get a low resolution stream (if -camera-low_res_factor=X is configured).</li>
</ul> </ul>
</li> </li>
<br>
<li>
The commands available on some cameras:<br>
<br>
<ul>
<li><a href="option?autofocus">/option?autofocus</a> trigger auto focus.</li>
</ul>
</li>
</ul> </ul>
<br> <br>
<hr> <hr>

View File

@ -45,6 +45,7 @@ typedef struct http_server_options_s {
int http_server(http_server_options_t *options, http_method_t *methods); int http_server(http_server_options_t *options, http_method_t *methods);
void http_content(http_worker_t *worker, FILE *stream); 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_404(FILE *stream, const char *data);
void http_500(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_capture(struct buffer_s *buf);
void http_jpeg_lowres_capture(struct buffer_s *buf); void http_jpeg_lowres_capture(struct buffer_s *buf);
bool http_jpeg_needs_buffer(); bool http_jpeg_needs_buffer();
void http_option(http_worker_t *worker, FILE *stream);
// H264 // H264
bool http_h264_needs_buffer(); bool http_h264_needs_buffer();

View File

@ -16,7 +16,7 @@ static void http_write_response(
fprintf(stream, "HTTP/1.1 %s\r\n", status ? status : "200 OK"); 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"); fprintf(stream, "Content-Type: %s\r\n", content_type ? content_type : "text/plain");
if (content_length > 0) 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"); fprintf(stream, "\r\n");
if (body) { if (body) {
fwrite(body, 1, content_length, stream); 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) void http_404(FILE *stream, const char *data)
{ {
http_write_response(stream, "404 Not Found", NULL, data ? data : "Nothing here.\n", 0); http_write_response(stream, "404 Not Found", NULL, data ? data : "Nothing here.\n", 0);