Hue/saturation controls, qtmultimedia viewfinder works
This commit is contained in:
78
utility.c
78
utility.c
@@ -1,3 +1,7 @@
|
||||
/* insert copyright here *
|
||||
* THE manual: https://www.kernel.org/doc/html/v5.7/media/uapi/mediactl/media-ioc-g-topology.html
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <stdio.h>
|
||||
@@ -82,13 +86,14 @@ struct camera_data {
|
||||
int subdev_fd;
|
||||
const struct media_v2_entity *entity;
|
||||
const struct media_v2_interface *interface;
|
||||
const struct media_v2_pad *pad;
|
||||
int gain_ctrl;
|
||||
int gain_max;
|
||||
char devnode_path[261];
|
||||
};
|
||||
struct camera_config configurations[] = {
|
||||
{"front", "gc2145", 320, 240, MEDIA_BUS_FMT_YUYV8_2X8, MEDIA_BUS_FMT_SBGGR8_1X8, {1, 15}},
|
||||
{"rear", "ov5640", 320, 240, MEDIA_BUS_FMT_YUYV8_2X8, MEDIA_BUS_FMT_SBGGR8_1X8, {1, 15}},
|
||||
{"front", "gc2145", 320, 240, MEDIA_BUS_FMT_UYVY8_2X8, MEDIA_BUS_FMT_SBGGR8_1X8, {1, 15}},
|
||||
{"rear", "ov5640", 1280, 720, MEDIA_BUS_FMT_UYVY8_2X8, MEDIA_BUS_FMT_SBGGR8_1X8, {1, 30}},
|
||||
};
|
||||
struct camera_data cam_store[] = {
|
||||
{},
|
||||
@@ -216,48 +221,6 @@ static void disable_all_links(struct device_data *dev)
|
||||
setup_link(dev, source_pad->id, sink_pad->id, FALSE);
|
||||
}
|
||||
}
|
||||
#if 0
|
||||
const struct media_v2_link *plink =
|
||||
gst_pinesrcbin_get_link_from_entity(dev,
|
||||
dev->entities[i].id);
|
||||
if (plink) {
|
||||
g_print("link %d %08x %08x: %08x\n", plink->id, plink->source_id, plink->sink_id, plink->flags);
|
||||
if (plink->flags & MEDIA_LNK_FL_ENABLED) {
|
||||
uint32_t link_type = plink->flags & MEDIA_LNK_FL_LINK_TYPE;
|
||||
if (link_type == MEDIA_LNK_FL_DATA_LINK) {
|
||||
g_print("data link %d\n", plink->id);
|
||||
setup_link(dev, plink->source_id, plink->sink_id, FALSE);
|
||||
} else if (link_type == MEDIA_LNK_FL_INTERFACE_LINK) {
|
||||
struct media_v2_interface *iface = st_pinesrcbin_get_interface_by_id(dev, plink->source_id);
|
||||
g_print("interface link %d entity: %d\n", plink->id, iface->);
|
||||
continue;
|
||||
}
|
||||
const struct media_v2_pad *source_pad, *sink_pad;
|
||||
g_print("link %d is active\n", plink->id);
|
||||
source_pad = gst_pinesrcbin_get_pad_from_entity(dev, plink->source_id);
|
||||
sink_pad = gst_pinesrcbin_get_pad_from_entity(dev, plink->sink_id);
|
||||
g_assert(source_pad);
|
||||
g_assert(sink_pad);
|
||||
setup_link(dev, source_pad->id, sink_pad->id, FALSE);
|
||||
#if 0
|
||||
struct media_link_desc link = {};
|
||||
link.flags = 0;
|
||||
link.source.entity = plink->source_id;
|
||||
link.source.index = 0;
|
||||
link.sink.entity = plink->sink_id;
|
||||
link.sink.index = 0;
|
||||
if (xioctl(dev->fd, MEDIA_IOC_SETUP_LINK, &link) == -1)
|
||||
g_printerr("MEDIA_IOC_SETUP_LINK: %d %s", errno, strerror(errno));
|
||||
#endif
|
||||
#if 0
|
||||
/* TODO: maintain own links structure */
|
||||
else
|
||||
plink->flags = 0;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
static struct device_data *
|
||||
@@ -342,6 +305,7 @@ setup_gain(int fd, int *gain_ctrl, int *gain_max)
|
||||
*gain_max = ctrl.maximum;
|
||||
return;
|
||||
}
|
||||
camera_control(fd, *gain_ctrl, VIDIOC_S_EXT_CTRLS, gain_max);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
@@ -517,6 +481,20 @@ get_camera_data(const char *conf_name)
|
||||
return &cam_store[conf];
|
||||
}
|
||||
}
|
||||
void set_camera_control(const char * conf_name, int control, int value)
|
||||
{
|
||||
struct camera_data *cam_data = get_camera_data(conf_name);
|
||||
switch(control) {
|
||||
case CONTROL_HUE:
|
||||
g_print("configuring hue = %d\n", value);
|
||||
camera_control (cam_data->subdev_fd, V4L2_CID_HUE, VIDIOC_S_EXT_CTRLS, &value);
|
||||
break;
|
||||
case CONTROL_SATURATION:
|
||||
g_print("configuring saturation = %d\n", value);
|
||||
camera_control (cam_data->subdev_fd, V4L2_CID_SATURATION, VIDIOC_S_EXT_CTRLS, &value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
void gst_pinesrcbin_configure_device(GstPineSrcBin * self, const char *conf_name)
|
||||
{
|
||||
struct camera_config *conf;
|
||||
@@ -565,7 +543,7 @@ void gst_pinesrcbin_configure_device(GstPineSrcBin * self, const char *conf_name
|
||||
if (!self->v4l2entity)
|
||||
g_error ("can't find entity sun6i-csi\n");
|
||||
GST_DEBUG_OBJECT (self, "sink entity: %d %s\n", self->v4l2entity->id, self->v4l2entity->name);
|
||||
/* This is sink pad (for host controller) */
|
||||
/* This is sink pad (for media controller) */
|
||||
self->v4l2pad =
|
||||
gst_pinesrcbin_get_pad_from_entity (self->media_if, self->v4l2entity->id);
|
||||
GST_DEBUG_OBJECT (self, "sink pad: %d\n", self->v4l2pad->id);
|
||||
@@ -591,6 +569,8 @@ void gst_pinesrcbin_configure_device(GstPineSrcBin * self, const char *conf_name
|
||||
disable_all_links(self->media_if);
|
||||
cam_data->entity = gst_pinesrcbin_find_media_entity(self->media_if, conf->camera_name);
|
||||
GST_DEBUG_OBJECT (self, "camera: %s: source interface entity %d\n", conf->camera_name, cam_data->entity->id);
|
||||
cam_data->pad =
|
||||
gst_pinesrcbin_get_pad_from_entity (self->media_if, cam_data->entity->id);
|
||||
|
||||
cam_data->interface =
|
||||
gst_pinesrcbin_get_entity_interface (self->media_if,
|
||||
@@ -612,10 +592,18 @@ void gst_pinesrcbin_configure_device(GstPineSrcBin * self, const char *conf_name
|
||||
camera_control (cam_data->subdev_fd, V4L2_CID_FOCUS_AUTO, VIDIOC_S_EXT_CTRLS, &enable);
|
||||
}
|
||||
setup_gain (cam_data->subdev_fd, &cam_data->gain_ctrl, &cam_data->gain_max);
|
||||
camera_control (cam_data->subdev_fd, V4L2_CID_TEST_PATTERN, VIDIOC_S_EXT_CTRLS, &self->test_pattern);
|
||||
{
|
||||
int auto_gain = 1;
|
||||
camera_control (cam_data->subdev_fd, V4L2_CID_AUTOGAIN, VIDIOC_S_EXT_CTRLS, &auto_gain);
|
||||
}
|
||||
set_camera_control(conf_name, CONTROL_HUE, self->hue);
|
||||
/* now configuring camera modes */
|
||||
GST_DEBUG_OBJECT (self, "configuring camera modes\n");
|
||||
subdev_set_mode(cam_data->subdev_fd, conf->width,
|
||||
conf->height, conf->bus_code_video,
|
||||
conf->frame_interval);
|
||||
GST_DEBUG_OBJECT (self, "enabling link for %s\n", conf->camera_name);
|
||||
setup_link(self->media_if, cam_data->pad->id, self->v4l2pad->id, TRUE);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user