diff --git a/cmd/camera.c b/cmd/camera.c index 82dad42..1901b96 100644 --- a/cmd/camera.c +++ b/cmd/camera.c @@ -7,6 +7,8 @@ void camera_init(camera_t *camera) { memset(camera, 0, sizeof(*camera)); + camera->name = "CAMERA"; + strcpy(camera->path, "/dev/video0"); camera->width = 1280; camera->height = 720; camera->nbufs = 4; @@ -27,16 +29,50 @@ void camera_close(camera_t *camera) memset(camera->links, 0, sizeof(camera->links)); } -int camera_open(camera_t *camera, const char *path) +int camera_open(camera_t *camera) { - camera->camera = device_open("CAMERA", path); + camera->camera = device_open("CAMERA", camera->path); if (!camera->camera) { return -1; } camera->camera->allow_dma = camera->allow_dma; - return 0;; + switch (camera->format) { + case V4L2_PIX_FMT_YUYV: + if (camera_configure_direct(camera) < 0) { + goto error; + } + break; + + case V4L2_PIX_FMT_MJPEG: + case V4L2_PIX_FMT_H264: + if (camera_configure_decoder(camera) < 0) { + goto error; + } + break; + + case V4L2_PIX_FMT_SRGGB10P: +#if 1 + if (camera_configure_isp(camera, 1, 0) < 0) { + goto error; + } +#else + if (camera_configure_legacy_isp(&camera, 1.3) < 0) { + goto error; + } +#endif + break; + + default: + E_LOG_ERROR(camera, "Unsupported camera format=%s", fourcc_to_string(camera->format).buf); + break; + } + + return 0; + +error: + return -1; } int camera_set_params(camera_t *camera) diff --git a/cmd/camera.h b/cmd/camera.h index 49d732a..c9ad81b 100644 --- a/cmd/camera.h +++ b/cmd/camera.h @@ -9,6 +9,8 @@ #define CAMERA_DEVICE_CAMERA 0 typedef struct camera_s { + const char *name; + union { device_t *devices[MAX_DEVICES]; struct { @@ -38,6 +40,7 @@ typedef struct camera_s { }; link_t links[MAX_DEVICES]; + char path[256]; unsigned width, height, format; unsigned nbufs, fps; bool allow_dma; @@ -47,7 +50,7 @@ typedef struct camera_s { void camera_init(camera_t *camera); void camera_close(camera_t *camera); -int camera_open(camera_t *camera, const char *path); +int camera_open(camera_t *camera); int camera_set_params(camera_t *camera); int camera_run(camera_t *camera); diff --git a/cmd/camera_decoder.c b/cmd/camera_decoder.c index 7324a21..2874c46 100644 --- a/cmd/camera_decoder.c +++ b/cmd/camera_decoder.c @@ -17,7 +17,6 @@ int camera_configure_decoder(camera_t *camera) buffer_list_t *src = camera->camera->capture_list; camera->decoder.decoder = device_open("DECODER", "/dev/video10"); - camera->codec_jpeg = device_open("JPEG", "/dev/video31"); camera->codec_h264 = device_open("H264", "/dev/video11"); if (device_open_buffer_list_output(camera->decoder.decoder, src) < 0 || @@ -27,9 +26,13 @@ int camera_configure_decoder(camera_t *camera) src = camera->decoder.decoder->capture_list; - if (device_open_buffer_list_output(camera->codec_jpeg, src) < 0 || - device_open_buffer_list_capture(camera->codec_jpeg, src, 1.0, V4L2_PIX_FMT_JPEG, true) < 0) { - return -1; + if (camera->format != V4L2_PIX_FMT_MJPEG && camera->format != V4L2_PIX_FMT_JPEG) { + camera->codec_jpeg = device_open("JPEG", "/dev/video31"); + + if (device_open_buffer_list_output(camera->codec_jpeg, src) < 0 || + device_open_buffer_list_capture(camera->codec_jpeg, src, 1.0, V4L2_PIX_FMT_JPEG, true) < 0) { + return -1; + } } if (device_open_buffer_list_output(camera->codec_h264, src) < 0 || @@ -39,9 +42,15 @@ int camera_configure_decoder(camera_t *camera) link_t *links = camera->links; - *links++ = (link_t){ camera->camera, { camera->decoder.decoder } }; - *links++ = (link_t){ camera->decoder.decoder, { camera->codec_jpeg, camera->codec_h264 } }; - *links++ = (link_t){ camera->codec_jpeg, { }, { http_jpeg_capture, http_jpeg_needs_buffer } }; - *links++ = (link_t){ camera->codec_h264, { }, { http_h264_capture, http_h264_needs_buffer } }; + if (camera->format == V4L2_PIX_FMT_MJPEG || camera->format == V4L2_PIX_FMT_JPEG) { + *links++ = (link_t){ camera->camera, { camera->decoder.decoder }, { http_jpeg_capture, http_jpeg_needs_buffer } }; + *links++ = (link_t){ camera->decoder.decoder, { camera->codec_h264 } }; + *links++ = (link_t){ camera->codec_h264, { }, { http_h264_capture, http_h264_needs_buffer } }; + } else { + *links++ = (link_t){ camera->camera, { camera->decoder.decoder } }; + *links++ = (link_t){ camera->decoder.decoder, { camera->codec_jpeg, camera->codec_h264 } }; + *links++ = (link_t){ camera->codec_jpeg, { }, { http_jpeg_capture, http_jpeg_needs_buffer } }; + *links++ = (link_t){ camera->codec_h264, { }, { http_h264_capture, http_h264_needs_buffer } }; + } return 0; } diff --git a/cmd/main.c b/cmd/main.c index 14a3ec0..a0278a5 100644 --- a/cmd/main.c +++ b/cmd/main.c @@ -34,47 +34,16 @@ int main(int argc, char *argv[]) camera_init(&camera); //camera.width = 1920; camera.height = 1080; - camera.width = 2328; camera.height = 1748; // 1164x874 + strcpy(camera.path, "/dev/video2"); camera.width = 2328; camera.height = 1748; camera.format = V4L2_PIX_FMT_SRGGB10P; // 1164x874 //camera.width = 4656; camera.height = 3496; //camera.width = 3840; camera.height = 2160; //camera.width = 1280; camera.height = 720; + strcpy(camera.path, "/dev/video0"); camera.width = 1920; camera.height = 1080; camera.format = V4L2_PIX_FMT_YUYV; camera.format = V4L2_PIX_FMT_MJPEG; camera.allow_dma = false; camera.nbufs = 1; - -#if 1 - camera.format = V4L2_PIX_FMT_SRGGB10P; - if (camera_open(&camera, "/dev/video2") < 0) { + if (camera_open(&camera) < 0) { goto error; } -#else - //camera.width = 1920; camera.height = 1080; - camera.width = 1280; camera.height = 720; - // camera.format = V4L2_PIX_FMT_YUYV; - camera.format = V4L2_PIX_FMT_MJPEG; - camera.allow_dma = false; - - if (camera_open(&camera, "/dev/video0") < 0) { - goto error; - } -#endif - -#if 0 - if (camera_configure_decoder(&camera) < 0) { - goto error; - } -#elif 0 - if (camera_configure_direct(&camera) < 0) { - goto error; - } -#elif 1 - if (camera_configure_isp(&camera, 3, 0) < 0) { - goto error; - } -#else - if (camera_configure_legacy_isp(&camera, 1.3) < 0) { - goto error; - } -#endif if (camera_set_params(&camera) < 0) { goto error; diff --git a/hw/buffer_list.c b/hw/buffer_list.c index 9415fbb..c8e52dd 100644 --- a/hw/buffer_list.c +++ b/hw/buffer_list.c @@ -82,7 +82,7 @@ retry: if (strstr(buf_list->name, "JPEG") || strstr(buf_list->name, "H264") || buf_list->do_capture && strstr(buf_list->name, "ISP")) { width = shrink_to_block(width, 32); height = shrink_to_block(height, 32); - E_LOG_INFO(buf_list, "Adapting size to 32x32 block: %dx%d vs %dx%d", orig_width, orig_height, width, height); + E_LOG_VERBOSE(buf_list, "Adapting size to 32x32 block: %dx%d vs %dx%d", orig_width, orig_height, width, height); } if (format == V4L2_PIX_FMT_H264) { diff --git a/hw/buffer_lock.c b/hw/buffer_lock.c index 182b293..a100c03 100644 --- a/hw/buffer_lock.c +++ b/hw/buffer_lock.c @@ -46,7 +46,7 @@ void buffer_lock_capture(buffer_lock_t *buf_lock, buffer_t *buf) buf_lock->buf = buf; buf_lock->counter++; gettimeofday(&buf_lock->buf_time, NULL); - E_LOG_DEBUG(buf_lock, "Captured buffer: %d", buf_lock->counter); + E_LOG_DEBUG(buf_lock, "Captured buffer %s, frame=%d", dev_name(buf), buf_lock->counter); pthread_cond_broadcast(&buf_lock->cond_wait); pthread_mutex_unlock(&buf_lock->lock); }