Move all into device/
This commit is contained in:
137
cmd/camera.c
137
cmd/camera.c
@ -1,137 +0,0 @@
|
||||
#include "camera.h"
|
||||
|
||||
#include "hw/device.h"
|
||||
#include "hw/buffer_list.h"
|
||||
#include "hw/links.h"
|
||||
#include "hw/v4l2.h"
|
||||
|
||||
void camera_init(camera_t *camera)
|
||||
{
|
||||
memset(camera, 0, sizeof(*camera));
|
||||
camera->name = "CAMERA";
|
||||
}
|
||||
|
||||
void camera_close(camera_t *camera)
|
||||
{
|
||||
if (!camera)
|
||||
return;
|
||||
|
||||
for (int i = MAX_DEVICES; i-- > 0; ) {
|
||||
if (camera->devices[i]) {
|
||||
device_close(camera->devices[i]);
|
||||
camera->devices[i] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = MAX_DEVICES; i-- > 0; ) {
|
||||
if (camera->links[i].callbacks.on_buffer) {
|
||||
camera->links[i].callbacks.on_buffer = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
memset(camera->links, 0, sizeof(camera->links));
|
||||
free(camera);
|
||||
}
|
||||
|
||||
camera_t *camera_open(camera_options_t *options)
|
||||
{
|
||||
camera_t *camera = calloc(1, sizeof(camera_t));
|
||||
camera->name = "CAMERA";
|
||||
camera->options = *options;
|
||||
|
||||
camera->camera = device_open(camera->name, camera->options.path);
|
||||
if (!camera->camera) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
camera->camera->allow_dma = camera->options.allow_dma;
|
||||
|
||||
if (strstr(camera->camera->v4l2_cap.bus_info, "usb")) {
|
||||
E_LOG_INFO(camera, "Disabling DMA since device uses USB (which is likely not working properly).");
|
||||
camera->camera->allow_dma = false;
|
||||
}
|
||||
|
||||
device_set_pad_format(camera->camera, camera->options.width, camera->options.height, 0);
|
||||
|
||||
if (device_open_buffer_list(camera->camera, true, camera->options.width, camera->options.height, camera->options.format, 0, camera->options.nbufs, true) < 0) {
|
||||
goto error;
|
||||
}
|
||||
camera->camera->capture_list->do_timestamps = true;
|
||||
|
||||
if (camera->options.fps > 0) {
|
||||
camera->camera->capture_list->fmt_interval_us = 1000 * 1000 / camera->options.fps;
|
||||
}
|
||||
|
||||
switch (camera->camera->capture_list->fmt_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, camera->options.high_res_factor, camera->options.low_res_factor) < 0) {
|
||||
goto error;
|
||||
}
|
||||
#else
|
||||
if (camera_configure_legacy_isp(camera, camera->options.high_res_factor) < 0) {
|
||||
goto error;
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
|
||||
default:
|
||||
E_LOG_ERROR(camera, "Unsupported camera format=%s", fourcc_to_string(camera->options.format).buf);
|
||||
break;
|
||||
}
|
||||
|
||||
if (camera_set_params(camera) < 0) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
return camera;
|
||||
|
||||
error:
|
||||
camera_close(camera);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int camera_set_params(camera_t *camera)
|
||||
{
|
||||
device_set_fps(camera->camera, camera->options.fps);
|
||||
device_set_option_list(camera->camera, camera->options.options);
|
||||
|
||||
// DEVICE_SET_OPTION(camera->camera, EXPOSURE, 2684);
|
||||
// DEVICE_SET_OPTION(camera->camera, ANALOGUE_GAIN, 938);
|
||||
// DEVICE_SET_OPTION(camera->camera, DIGITAL_GAIN, 512);
|
||||
// DEVICE_SET_OPTION(camera->camera, VBLANK, 1636);
|
||||
// DEVICE_SET_OPTION(camera->camera, HBLANK, 6906);
|
||||
|
||||
// DEVICE_SET_OPTION(camera->isp_srgb, RED_BALANCE, 2120);
|
||||
// DEVICE_SET_OPTION(camera->isp_srgb, BLUE_BALANCE, 1472);
|
||||
// DEVICE_SET_OPTION(camera->isp_srgb, DIGITAL_GAIN, 1007);
|
||||
|
||||
DEVICE_SET_OPTION2(camera->codec_jpeg, JPEG, COMPRESSION_QUALITY, 80);
|
||||
|
||||
DEVICE_SET_OPTION2(camera->codec_h264, MPEG_VIDEO, BITRATE, 5000 * 1000);
|
||||
DEVICE_SET_OPTION2(camera->codec_h264, MPEG_VIDEO, H264_I_PERIOD, 30);
|
||||
DEVICE_SET_OPTION2(camera->codec_h264, MPEG_VIDEO, H264_LEVEL, V4L2_MPEG_VIDEO_H264_LEVEL_4_0);
|
||||
DEVICE_SET_OPTION2(camera->codec_h264, MPEG_VIDEO, REPEAT_SEQ_HEADER, 1);
|
||||
DEVICE_SET_OPTION2(camera->codec_h264, MPEG_VIDEO, H264_MIN_QP, 16);
|
||||
DEVICE_SET_OPTION2(camera->codec_h264, MPEG_VIDEO, H264_MIN_QP, 32);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int camera_run(camera_t *camera)
|
||||
{
|
||||
bool running = false;
|
||||
return links_loop(camera->links, &running);
|
||||
}
|
57
cmd/camera.h
57
cmd/camera.h
@ -1,57 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "hw/links.h"
|
||||
#include "hw/device.h"
|
||||
|
||||
#define MAX_DEVICES 20
|
||||
#define MAX_HTTP_METHODS 20
|
||||
|
||||
#define CAMERA_DEVICE_CAMERA 0
|
||||
|
||||
typedef struct camera_options_s {
|
||||
char path[256];
|
||||
unsigned width, height, format;
|
||||
unsigned nbufs, fps;
|
||||
bool allow_dma;
|
||||
float high_res_factor;
|
||||
float low_res_factor;
|
||||
|
||||
char options[4096];
|
||||
} camera_options_t;
|
||||
|
||||
typedef struct camera_s {
|
||||
const char *name;
|
||||
|
||||
camera_options_t options;
|
||||
|
||||
union {
|
||||
device_t *devices[MAX_DEVICES];
|
||||
struct {
|
||||
device_t *camera;
|
||||
device_t *decoder; // decode JPEG/H264 into YUVU
|
||||
device_t *legacy_isp; // convert pRAA/YUVU into YUVU
|
||||
device_t *isp_srgb;
|
||||
device_t *isp_yuuv;
|
||||
device_t *isp_yuuv_lowres;
|
||||
device_t *codec_jpeg; // encode YUVU into JPEG
|
||||
device_t *codec_h264; // encode YUVU into H264
|
||||
device_t *codec_jpeg_lowres; // encode YUVU into JPEG
|
||||
device_t *codec_h264_lowres; // encode YUVU into H264
|
||||
};
|
||||
};
|
||||
|
||||
link_t links[MAX_DEVICES];
|
||||
int nlinks;
|
||||
} camera_t;
|
||||
|
||||
#define CAMERA(DEVICE) camera->devices[DEVICE]
|
||||
|
||||
camera_t *camera_open(camera_options_t *camera);
|
||||
int camera_set_params(camera_t *camera);
|
||||
void camera_close(camera_t *camera);
|
||||
int camera_run(camera_t *camera);
|
||||
|
||||
int camera_configure_isp(camera_t *camera, float high_div, float low_div);
|
||||
int camera_configure_legacy_isp(camera_t *camera, float div);
|
||||
int camera_configure_direct(camera_t *camera);
|
||||
int camera_configure_decoder(camera_t *camera);
|
@ -1,68 +0,0 @@
|
||||
#include "camera.h"
|
||||
|
||||
#include "hw/buffer.h"
|
||||
#include "hw/buffer_list.h"
|
||||
#include "hw/device.h"
|
||||
#include "hw/links.h"
|
||||
#include "hw/v4l2.h"
|
||||
#include "hw/buffer_list.h"
|
||||
#include "http/http.h"
|
||||
|
||||
int camera_configure_decoder(camera_t *camera)
|
||||
{
|
||||
buffer_list_t *camera_src = camera->camera->capture_list;
|
||||
buffer_list_t *src = camera_src;
|
||||
device_video_force_key(camera->camera);
|
||||
|
||||
camera->decoder = device_open("DECODER", "/dev/video10");
|
||||
|
||||
if (device_open_buffer_list_output(camera->decoder, src) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (device_open_buffer_list_capture(camera->decoder, NULL, 1.0, 0, true) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (device_set_decoder_start(camera->decoder, true) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
src = camera->decoder->capture_list;
|
||||
|
||||
if (camera_src->fmt_format != V4L2_PIX_FMT_MJPEG && camera_src->fmt_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 (camera_src->fmt_format != V4L2_PIX_FMT_H264) {
|
||||
camera->codec_h264 = device_open("H264", "/dev/video11");
|
||||
|
||||
if (device_open_buffer_list_output(camera->codec_h264, src) < 0 ||
|
||||
device_open_buffer_list_capture(camera->codec_h264, src, 1.0, V4L2_PIX_FMT_H264, true) < 0) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
link_t *links = camera->links;
|
||||
|
||||
if (camera_src->fmt_format == V4L2_PIX_FMT_MJPEG || camera_src->fmt_format == V4L2_PIX_FMT_JPEG) {
|
||||
*links++ = (link_t){ camera->camera->capture_list, { camera->decoder->output_list }, { http_jpeg_capture, http_jpeg_needs_buffer } };
|
||||
*links++ = (link_t){ camera->decoder->capture_list, { camera->codec_h264->output_list } };
|
||||
*links++ = (link_t){ camera->codec_h264->capture_list, { }, { http_h264_capture, http_h264_needs_buffer } };
|
||||
} else if (camera_src->fmt_format == V4L2_PIX_FMT_H264) {
|
||||
*links++ = (link_t){ camera->camera->capture_list, { camera->decoder->output_list }, { http_h264_capture, http_h264_needs_buffer }};
|
||||
*links++ = (link_t){ camera->decoder->capture_list, { camera->codec_jpeg->output_list } };
|
||||
*links++ = (link_t){ camera->codec_jpeg->capture_list, { }, { http_jpeg_capture, http_jpeg_needs_buffer } };
|
||||
} else {
|
||||
*links++ = (link_t){ camera->camera->capture_list, { camera->decoder->output_list } };
|
||||
*links++ = (link_t){ camera->decoder->capture_list, { camera->codec_jpeg->output_list, camera->codec_h264->output_list } };
|
||||
*links++ = (link_t){ camera->codec_jpeg->capture_list, { }, { http_jpeg_capture, http_jpeg_needs_buffer } };
|
||||
*links++ = (link_t){ camera->codec_h264->capture_list, { }, { http_h264_capture, http_h264_needs_buffer } };
|
||||
}
|
||||
return 0;
|
||||
}
|
@ -1,34 +0,0 @@
|
||||
#include "camera.h"
|
||||
|
||||
#include "hw/buffer.h"
|
||||
#include "hw/buffer_list.h"
|
||||
#include "hw/device.h"
|
||||
#include "hw/links.h"
|
||||
#include "hw/v4l2.h"
|
||||
#include "hw/buffer_list.h"
|
||||
#include "http/http.h"
|
||||
|
||||
int camera_configure_direct(camera_t *camera)
|
||||
{
|
||||
buffer_list_t *src = camera->camera->capture_list;
|
||||
|
||||
camera->codec_jpeg = device_open("JPEG", "/dev/video31");
|
||||
camera->codec_h264 = device_open("H264", "/dev/video11");
|
||||
|
||||
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 ||
|
||||
device_open_buffer_list_capture(camera->codec_h264, src, 1.0, V4L2_PIX_FMT_H264, true) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
link_t *links = camera->links;
|
||||
|
||||
*links++ = (link_t){ camera->camera->capture_list, { camera->codec_jpeg->output_list, camera->codec_h264->output_list } };
|
||||
*links++ = (link_t){ camera->codec_jpeg->capture_list, { }, { http_jpeg_capture, http_jpeg_needs_buffer } };
|
||||
*links++ = (link_t){ camera->codec_h264->capture_list, { }, { http_h264_capture, http_h264_needs_buffer } };
|
||||
return 0;
|
||||
}
|
@ -1,76 +0,0 @@
|
||||
#include "camera.h"
|
||||
|
||||
#include "hw/buffer.h"
|
||||
#include "hw/buffer_list.h"
|
||||
#include "hw/device.h"
|
||||
#include "hw/links.h"
|
||||
#include "hw/v4l2.h"
|
||||
#include "hw/buffer_list.h"
|
||||
#include "http/http.h"
|
||||
|
||||
void write_yuvu(buffer_t *buffer);
|
||||
|
||||
int camera_configure_isp(camera_t *camera, float high_div, float low_div)
|
||||
{
|
||||
camera->isp_srgb = device_open("ISP", "/dev/video13");
|
||||
camera->isp_yuuv = device_open("ISP-YUUV", "/dev/video14");
|
||||
camera->codec_jpeg = device_open("JPEG", "/dev/video31");
|
||||
camera->codec_h264 = device_open("H264", "/dev/video11");
|
||||
|
||||
if (device_open_buffer_list_output(camera->isp_srgb, camera->camera->capture_list) < 0 ||
|
||||
device_open_buffer_list_capture(camera->isp_yuuv, camera->camera->capture_list, high_div, V4L2_PIX_FMT_YUYV, true) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
camera->isp_yuuv->output_device = camera->isp_srgb;
|
||||
|
||||
link_t *links = camera->links;
|
||||
*links++ = (link_t){ camera->camera->capture_list, { camera->isp_srgb->output_list } };
|
||||
|
||||
buffer_list_t *src = camera->isp_yuuv->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 (device_open_buffer_list_output(camera->codec_h264, src) < 0 ||
|
||||
device_open_buffer_list_capture(camera->codec_h264, src, 1.0, V4L2_PIX_FMT_H264, true) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
*links++ = (link_t){ camera->isp_yuuv->capture_list, { camera->codec_jpeg->output_list, camera->codec_h264->output_list }, { write_yuvu } };
|
||||
*links++ = (link_t){ camera->codec_jpeg->capture_list, { }, { http_jpeg_capture, http_jpeg_needs_buffer } };
|
||||
*links++ = (link_t){ camera->codec_h264->capture_list, { }, { http_h264_capture, http_h264_needs_buffer } };
|
||||
|
||||
// all done
|
||||
if (low_div < 1) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
camera->isp_yuuv_lowres = device_open("ISP-YUUV-LOW", "/dev/video15");
|
||||
camera->codec_jpeg_lowres = device_open("JPEG-LOW", "/dev/video31");
|
||||
camera->codec_h264_lowres = device_open("H264-LOW", "/dev/video11");
|
||||
|
||||
if (device_open_buffer_list_capture(camera->isp_yuuv_lowres, camera->camera->capture_list, low_div, V4L2_PIX_FMT_YUYV, true) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
camera->isp_yuuv_lowres->output_device = camera->isp_srgb;
|
||||
src = camera->isp_yuuv_lowres->capture_list;
|
||||
|
||||
if (device_open_buffer_list_output(camera->codec_jpeg_lowres, src) < 0 ||
|
||||
device_open_buffer_list_capture(camera->codec_jpeg_lowres, src, 1.0, V4L2_PIX_FMT_JPEG, true) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (device_open_buffer_list_output(camera->codec_h264_lowres, src) < 0 ||
|
||||
device_open_buffer_list_capture(camera->codec_h264_lowres, src, 1.0, V4L2_PIX_FMT_H264, true) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
*links++ = (link_t){ camera->isp_yuuv_lowres->capture_list, { camera->codec_jpeg_lowres->output_list, camera->codec_h264_lowres->output_list }, { write_yuvu } };
|
||||
*links++ = (link_t){ camera->codec_jpeg_lowres->capture_list, { }, { http_jpeg_lowres_capture, http_jpeg_needs_buffer } };
|
||||
*links++ = (link_t){ camera->codec_h264_lowres->capture_list, { }, { http_h264_lowres_capture, http_h264_needs_buffer } };
|
||||
return 0;
|
||||
}
|
@ -1,55 +0,0 @@
|
||||
#include "camera.h"
|
||||
|
||||
#include "hw/buffer.h"
|
||||
#include "hw/buffer_list.h"
|
||||
#include "hw/device.h"
|
||||
#include "hw/links.h"
|
||||
#include "hw/v4l2.h"
|
||||
#include "hw/buffer_list.h"
|
||||
#include "http/http.h"
|
||||
|
||||
void write_yuvu(buffer_t *buffer)
|
||||
{
|
||||
#if 0
|
||||
FILE *fp = fopen("/tmp/capture-yuyv.raw.tmp", "wb");
|
||||
if (fp) {
|
||||
fwrite(buffer->start, 1, buffer->used, fp);
|
||||
fclose(fp);
|
||||
}
|
||||
rename("/tmp/capture-yuyv.raw.tmp", "/tmp/capture-yuyv.raw");
|
||||
#endif
|
||||
}
|
||||
|
||||
int camera_configure_legacy_isp(camera_t *camera, float div)
|
||||
{
|
||||
buffer_list_t *src = camera->camera->capture_list;
|
||||
|
||||
camera->legacy_isp = device_open("ISP", "/dev/video12");
|
||||
camera->codec_jpeg = device_open("JPEG", "/dev/video31");
|
||||
camera->codec_h264 = device_open("H264", "/dev/video11");
|
||||
|
||||
if (device_open_buffer_list_output(camera->legacy_isp, src) < 0 ||
|
||||
device_open_buffer_list_capture(camera->legacy_isp, src, div, V4L2_PIX_FMT_YUYV, true) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
src = camera->legacy_isp->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 (device_open_buffer_list_output(camera->codec_h264, src) < 0 ||
|
||||
device_open_buffer_list_capture(camera->codec_h264, src, 1.0, V4L2_PIX_FMT_H264, true) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
link_t *links = camera->links;
|
||||
|
||||
*links++ = (link_t){ camera->camera->capture_list, { camera->legacy_isp->output_list } };
|
||||
*links++ = (link_t){ camera->legacy_isp->capture_list, { camera->codec_jpeg->output_list, camera->codec_h264->output_list }, { write_yuvu, NULL } };
|
||||
*links++ = (link_t){ camera->codec_jpeg->capture_list, { }, { http_jpeg_capture, http_jpeg_needs_buffer } };
|
||||
*links++ = (link_t){ camera->codec_h264->capture_list, { }, { http_h264_capture, http_h264_needs_buffer } };
|
||||
return 0;
|
||||
}
|
@ -1,11 +1,11 @@
|
||||
#include "hw/buffer.h"
|
||||
#include "hw/buffer_list.h"
|
||||
#include "hw/device.h"
|
||||
#include "hw/links.h"
|
||||
#include "hw/v4l2.h"
|
||||
#include "device/hw/buffer.h"
|
||||
#include "device/hw/buffer_list.h"
|
||||
#include "device/hw/device.h"
|
||||
#include "device/hw/links.h"
|
||||
#include "device/hw/v4l2.h"
|
||||
#include "http/http.h"
|
||||
#include "opts/opts.h"
|
||||
#include "camera.h"
|
||||
#include "device/camera.h"
|
||||
|
||||
#include <signal.h>
|
||||
|
Reference in New Issue
Block a user