2023-06-27 13:13:22 +02:00
|
|
|
From 8103e662a484c0887d29f11a1284f85ff34d0248 Mon Sep 17 00:00:00 2001
|
2022-12-15 13:54:39 +01:00
|
|
|
From: kgmt0 <kritphong@teknik.io>
|
2022-12-16 17:18:49 +01:00
|
|
|
Date: Thu, 1 Dec 2022 00:13:27 -0600
|
2022-12-15 13:54:39 +01:00
|
|
|
Subject: [PATCH] WIP: Support Pinephone Pro
|
|
|
|
|
|
|
|
Both cameras work now but the quality is very poor.
|
|
|
|
|
2023-06-27 13:13:22 +02:00
|
|
|
Tested with Linux 6.1.12-1 from Arch Linux ARM (linux-megi).
|
2022-12-15 13:54:39 +01:00
|
|
|
---
|
|
|
|
config/motorola,osprey.ini | 1 +
|
2022-12-16 17:18:49 +01:00
|
|
|
config/pine64,pinephone-pro.ini | 49 +++++++++
|
2022-12-15 13:54:39 +01:00
|
|
|
config/xiaomi,scorpio.ini | 1 +
|
|
|
|
meson.build | 1 +
|
2023-06-27 13:13:22 +02:00
|
|
|
src/camera.c | 8 +-
|
|
|
|
src/device.c | 118 ++++++++++++++++++++++
|
|
|
|
src/device.h | 15 +++
|
|
|
|
src/io_pipeline.c | 173 +++++++++++++++++++-------------
|
|
|
|
8 files changed, 296 insertions(+), 70 deletions(-)
|
2022-12-15 13:54:39 +01:00
|
|
|
create mode 100644 config/pine64,pinephone-pro.ini
|
|
|
|
|
|
|
|
diff --git a/config/motorola,osprey.ini b/config/motorola,osprey.ini
|
|
|
|
index ab8990d..5809a8e 100644
|
|
|
|
--- a/config/motorola,osprey.ini
|
|
|
|
+++ b/config/motorola,osprey.ini
|
|
|
|
@@ -15,3 +15,4 @@ preview-rate=30
|
|
|
|
preview-fmt=RGGB10P
|
|
|
|
rotate=270
|
|
|
|
media-links=msm_csiphy0:1->msm_csid0:0,msm_csid0:1->msm_ispif0:0,msm_ispif0:1->msm_vfe0_rdi0:0
|
|
|
|
+media-formats=msm_csiphy0:1:RGGB10P:4096:2304,msm_csid0:0:RGGB10P:4096:2304,msm_csid0:1:RGGB10P:4096:2304,msm_ispif0:0:RGGB10P:4096:2304,msm_ispif0:1:RGGB10P:4096:2304,msm_vfe0_rdi0:0:RGGB10P:4096:2304
|
|
|
|
diff --git a/config/pine64,pinephone-pro.ini b/config/pine64,pinephone-pro.ini
|
|
|
|
new file mode 100644
|
2023-06-27 13:13:22 +02:00
|
|
|
index 0000000..b7a2dcd
|
2022-12-15 13:54:39 +01:00
|
|
|
--- /dev/null
|
|
|
|
+++ b/config/pine64,pinephone-pro.ini
|
2022-12-16 17:18:49 +01:00
|
|
|
@@ -0,0 +1,49 @@
|
2022-12-15 13:54:39 +01:00
|
|
|
+[device]
|
|
|
|
+make=PINE64
|
|
|
|
+model=PinePhone
|
|
|
|
+
|
|
|
|
+[rear]
|
|
|
|
+driver=imx258 1-001a
|
|
|
|
+media-driver=rkisp1
|
|
|
|
+capture-width=1048
|
|
|
|
+capture-height=780
|
|
|
|
+capture-rate=30
|
|
|
|
+capture-fmt=RGGB8
|
|
|
|
+preview-width=1048
|
|
|
|
+preview-height=780
|
|
|
|
+preview-rate=30
|
|
|
|
+preview-fmt=RGGB8
|
|
|
|
+rotate=270
|
|
|
|
+mirrored=false
|
|
|
|
+blacklevel=3
|
|
|
|
+whitelevel=255
|
|
|
|
+focallength=2.35
|
|
|
|
+cropfactor=10.81
|
|
|
|
+fnumber=2.2
|
|
|
|
+iso-min=100
|
|
|
|
+iso-max=64000
|
|
|
|
+flash-path=/sys/class/leds/white:flash
|
|
|
|
+media-links=imx258 1-001a:0->rkisp1_csi:0,rkisp1_csi:1->rkisp1_isp:0,rkisp1_isp:2->rkisp1_resizer_mainpath:0
|
|
|
|
+media-formats=imx258 1-001a:0:RGGB10P:1048:780,rkisp1_csi:0:RGGB10P:1048:780,rkisp1_isp:0:RGGB10P:1048:780,rkisp1_isp:2:RGGB8:1048:780,rkisp1_resizer_mainpath:0:RGGB8:1048:780,rkisp1_resizer_mainpath:1:RGGB8:1048:780
|
|
|
|
+media-crops=rkisp1_isp:0:0:0:1048:780,rkisp1_isp:2:0:0:1048:780,rkisp1_resizer_mainpath:0:0:0:1048:768
|
|
|
|
+
|
|
|
|
+[front]
|
2023-06-27 13:13:22 +02:00
|
|
|
+driver=ov8858
|
2022-12-15 13:54:39 +01:00
|
|
|
+media-driver=rkisp1
|
|
|
|
+capture-width=3264
|
|
|
|
+capture-height=2448
|
|
|
|
+capture-rate=30
|
|
|
|
+capture-fmt=BGGR8
|
|
|
|
+preview-width=3264
|
|
|
|
+preview-height=2448
|
|
|
|
+preview-rate=30
|
|
|
|
+preview-fmt=BGGR8
|
|
|
|
+rotate=90
|
|
|
|
+mirrored=true
|
|
|
|
+focallength=2.94
|
|
|
|
+cropfactor=12.7
|
|
|
|
+fnumber=2.4
|
|
|
|
+flash-display=true
|
2023-06-27 13:13:22 +02:00
|
|
|
+media-links=ov8858:0->rkisp1_csi:0,rkisp1_csi:1->rkisp1_isp:0,rkisp1_isp:2->rkisp1_resizer_mainpath:0,rkisp1_resizer_mainpath:1->rkisp1_mainpath:0
|
|
|
|
+media-formats=ov8858:0:BGGR10P:3264:2448,rkisp1_csi:0:BGGR10P:3264:2448,rkisp1_isp:0:BGGR10P:3264:2448,rkisp1_isp:2:BGGR8:3264:2448,rkisp1_resizer_mainpath:0:BGGR8:3264:2448,rkisp1_resizer_mainpath:1:BGGR8:3264:2448
|
2022-12-15 13:54:39 +01:00
|
|
|
+media-crops=rkisp1_isp:0:0:0:3264:2448,rkisp1_isp:2:0:0:3264:2448,rkisp1_resizer_mainpath:0:0:0:3264:768
|
|
|
|
diff --git a/config/xiaomi,scorpio.ini b/config/xiaomi,scorpio.ini
|
|
|
|
index cce6d49..14b7f29 100644
|
|
|
|
--- a/config/xiaomi,scorpio.ini
|
|
|
|
+++ b/config/xiaomi,scorpio.ini
|
|
|
|
@@ -15,3 +15,4 @@ preview-rate=30
|
|
|
|
preview-fmt=RGGB10P
|
|
|
|
rotate=90
|
|
|
|
media-links=imx318 3-001a:0->msm_csiphy0:0,msm_csiphy0:1->msm_csid0:0,msm_csid0:1->msm_ispif0:0,msm_ispif0:1->msm_vfe0_rdi0:0
|
|
|
|
+media-formats=imx318 3-001a:0:RGGB10P:3840:2160,msm_csiphy0:0:RGGB10P:3840:2160,msm_csiphy0:1:RGGB10P:3840:2160,msm_csid0:0:RGGB10P:3840:2160,msm_csid0:1:RGGB10P:3840:2160,msm_ispif0:0:RGGB10P:3840:2160,msm_ispif0:1:RGGB10P:3840:2160,msm_vfe0_rdi0:0:RGGB10P:3840:2160
|
|
|
|
diff --git a/meson.build b/meson.build
|
2023-06-27 13:13:22 +02:00
|
|
|
index a9b9b4e..adc2359 100644
|
2022-12-15 13:54:39 +01:00
|
|
|
--- a/meson.build
|
|
|
|
+++ b/meson.build
|
|
|
|
@@ -72,6 +72,7 @@ install_data(
|
|
|
|
'config/pine64,pinephone-1.0.ini',
|
|
|
|
'config/pine64,pinephone-1.1.ini',
|
|
|
|
'config/pine64,pinephone-1.2.ini',
|
|
|
|
+ 'config/pine64,pinephone-pro.ini',
|
|
|
|
'config/pine64,pinetab.ini',
|
|
|
|
'config/xiaomi,scorpio.ini',
|
|
|
|
],
|
|
|
|
diff --git a/src/camera.c b/src/camera.c
|
2023-06-27 13:13:22 +02:00
|
|
|
index 5519bbd..588c164 100644
|
2022-12-15 13:54:39 +01:00
|
|
|
--- a/src/camera.c
|
|
|
|
+++ b/src/camera.c
|
2023-06-27 13:13:22 +02:00
|
|
|
@@ -327,8 +327,12 @@ mp_camera_set_mode(MPCamera *camera, MPMode *mode)
|
2022-12-15 13:54:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Update the mode
|
|
|
|
- mode->pixel_format =
|
|
|
|
- mp_pixel_format_from_v4l_bus_code(fmt.format.code);
|
2023-06-27 13:13:22 +02:00
|
|
|
+
|
|
|
|
+ // TODO: Some how the format gets changed to YUYV if this isn't
|
|
|
|
+ // commented out.
|
2022-12-15 13:54:39 +01:00
|
|
|
+ //mode->pixel_format =
|
|
|
|
+ // mp_pixel_format_from_v4l_bus_code(fmt.format.code);
|
2023-06-27 13:13:22 +02:00
|
|
|
+
|
|
|
|
mode->frame_interval = interval.interval;
|
|
|
|
mode->width = fmt.format.width;
|
|
|
|
mode->height = fmt.format.height;
|
2022-12-15 13:54:39 +01:00
|
|
|
diff --git a/src/device.c b/src/device.c
|
2023-06-27 13:13:22 +02:00
|
|
|
index 9e2db00..09e711b 100644
|
2022-12-15 13:54:39 +01:00
|
|
|
--- a/src/device.c
|
|
|
|
+++ b/src/device.c
|
|
|
|
@@ -8,6 +8,8 @@
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
+#include <linux/v4l2-subdev.h>
|
|
|
|
+#include <linux/media.h>
|
|
|
|
|
|
|
|
bool
|
|
|
|
mp_find_device_path(struct media_v2_intf_devnode devnode, char *path, int length)
|
2023-06-27 13:13:22 +02:00
|
|
|
@@ -73,6 +75,46 @@ xioctl(int fd, int request, void *arg)
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
+static int
|
|
|
|
+mp_device_get_fd_by_name(const MPDevice *device, const char *driver_name)
|
|
|
|
+{
|
|
|
|
+ struct media_entity_desc desc = {};
|
|
|
|
+
|
|
|
|
+ desc.id |= MEDIA_ENT_ID_FLAG_NEXT;
|
|
|
|
+
|
|
|
|
+ while(true) {
|
|
|
|
+ desc.id |= MEDIA_ENT_ID_FLAG_NEXT;
|
|
|
|
+ if(xioctl(device->fd, MEDIA_IOC_ENUM_ENTITIES, &desc) == -1) {
|
|
|
|
+ errno_printerr("MEDIA_IOC_ENUM_ENTITIES");
|
|
|
|
+ return -1;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if(strncmp(desc.name, driver_name, 32) == 0) {
|
|
|
|
+ const uint32_t major = desc.dev.major;
|
|
|
|
+ const uint32_t minor = desc.dev.minor;
|
|
|
|
+ char path[256];
|
|
|
|
+ int rc = snprintf(path, 256, "/dev/char/%u:%u", major, minor);
|
|
|
|
+
|
|
|
|
+ return rc > 0 ? open(path, O_RDWR) : -1;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return -1;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static bool
|
|
|
|
+mp_xioctl(const MPDevice *device, const char *driver_name, unsigned long request, void *argp)
|
|
|
|
+{
|
|
|
|
+ int fd = mp_device_get_fd_by_name(device, driver_name);
|
|
|
|
+
|
|
|
|
+ if(fd < 0)
|
|
|
|
+ {
|
|
|
|
+ printf("ERROR: device with driver name %s not found\n", driver_name);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return fd >= 0 && xioctl(fd, request, argp) != -1;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
MPDevice *
|
|
|
|
mp_device_find(const char *driver_name, const char *dev_name)
|
|
|
|
{
|
|
|
|
@@ -183,6 +225,42 @@ mp_device_setup_entity_link(MPDevice *device,
|
2022-12-16 17:18:49 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
+void
|
|
|
|
+mp_device_setup_media_link(MPDevice *device,
|
|
|
|
+ const struct mp_media_link_config *cfg,
|
|
|
|
+ bool enable)
|
|
|
|
+{
|
|
|
|
+ const struct media_v2_entity *source_entity =
|
|
|
|
+ mp_device_find_entity(device, cfg->source_name);
|
|
|
|
+
|
|
|
|
+ const struct media_v2_entity *target_entity =
|
|
|
|
+ mp_device_find_entity(device, cfg->target_name);
|
|
|
|
+
|
|
|
|
+ mp_device_setup_entity_link(device,
|
|
|
|
+ source_entity->id,
|
|
|
|
+ target_entity->id,
|
|
|
|
+ cfg->source_port,
|
|
|
|
+ cfg->target_port,
|
|
|
|
+ enable);
|
|
|
|
+}
|
2023-06-27 13:13:22 +02:00
|
|
|
+
|
|
|
|
+void
|
|
|
|
+mp_device_setup_media_link_pad_crop(MPDevice *device,
|
|
|
|
+ const struct mp_media_crop_config *crop)
|
|
|
|
+{
|
|
|
|
+ struct v4l2_subdev_crop v4l2_crop = {};
|
|
|
|
+ v4l2_crop.pad = crop->pad;
|
|
|
|
+ v4l2_crop.which = V4L2_SUBDEV_FORMAT_ACTIVE;
|
|
|
|
+ v4l2_crop.rect.top = crop->top;
|
|
|
|
+ v4l2_crop.rect.left = crop->left;
|
|
|
|
+ v4l2_crop.rect.width = crop->width;
|
|
|
|
+ v4l2_crop.rect.height = crop->height;
|
|
|
|
+
|
|
|
|
+ if(!mp_xioctl(device, crop->name, VIDIOC_SUBDEV_S_CROP, &v4l2_crop)) {
|
|
|
|
+ errno_printerr("VIDIOC_SUBDEV_S_CROP");
|
|
|
|
+ }
|
|
|
|
+}
|
2022-12-16 17:18:49 +01:00
|
|
|
+
|
|
|
|
bool
|
|
|
|
mp_device_setup_link(MPDevice *device,
|
|
|
|
uint32_t source_pad_id,
|
2023-06-27 13:13:22 +02:00
|
|
|
@@ -237,6 +315,46 @@ mp_entity_pad_set_format(MPDevice *device,
|
2022-12-15 13:54:39 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
+const struct media_v2_pad *
|
|
|
|
+mp_device_get_pad_at_index_from_entity(const MPDevice *device, uint32_t entity_id, uint32_t index)
|
|
|
|
+{
|
|
|
|
+ for (int i = 0; i < device->num_pads; ++i) {
|
|
|
|
+ if (device->pads[i].entity_id == entity_id && index-- == 0) {
|
|
|
|
+ return &device->pads[i];
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return NULL;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+bool
|
|
|
|
+mp_device_setup_link_by_name(MPDevice *device,
|
|
|
|
+ const char *source_entity_name,
|
|
|
|
+ uint32_t source_pad_index,
|
|
|
|
+ const char *sink_entity_name,
|
|
|
|
+ uint32_t sink_pad_index,
|
|
|
|
+ bool enabled)
|
|
|
|
+{
|
|
|
|
+ const struct media_v2_entity *source_entity =
|
|
|
|
+ mp_device_find_entity
|
|
|
|
+ (device, source_entity_name);
|
|
|
|
+ const struct media_v2_entity *sink_entity =
|
|
|
|
+ mp_device_find_entity
|
|
|
|
+ (device, sink_entity_name);
|
|
|
|
+
|
|
|
|
+ struct media_link_desc link = {};
|
|
|
|
+ link.flags = enabled ? MEDIA_LNK_FL_ENABLED : 0;
|
|
|
|
+ link.source.entity = source_entity->id;
|
|
|
|
+ link.source.index = source_pad_index;
|
|
|
|
+ link.sink.entity = sink_entity->id;
|
|
|
|
+ link.sink.index = sink_pad_index;
|
|
|
|
+ if (xioctl(device->fd, MEDIA_IOC_SETUP_LINK, &link) == -1) {
|
|
|
|
+ errno_printerr("MEDIA_IOC_SETUP_LINK");
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return true;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
const struct media_v2_entity *
|
|
|
|
mp_device_find_entity(const MPDevice *device, const char *driver_name)
|
|
|
|
{
|
|
|
|
diff --git a/src/device.h b/src/device.h
|
2023-06-27 13:13:22 +02:00
|
|
|
index 1894c67..c9b3477 100644
|
2022-12-15 13:54:39 +01:00
|
|
|
--- a/src/device.h
|
|
|
|
+++ b/src/device.h
|
2022-12-16 17:18:49 +01:00
|
|
|
@@ -1,6 +1,7 @@
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "mode.h"
|
|
|
|
+#include "camera_config.h"
|
|
|
|
|
|
|
|
#include <linux/media.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
@@ -26,6 +27,10 @@ bool mp_device_setup_entity_link(MPDevice *device,
|
|
|
|
uint32_t sink_index,
|
|
|
|
bool enabled);
|
|
|
|
|
|
|
|
+void mp_device_setup_media_link(MPDevice *device,
|
|
|
|
+ const struct mp_media_link_config *cfg,
|
|
|
|
+ bool enable);
|
|
|
|
+
|
|
|
|
bool mp_device_setup_link(MPDevice *device,
|
|
|
|
uint32_t source_pad_id,
|
|
|
|
uint32_t sink_pad_id,
|
2023-06-27 13:13:22 +02:00
|
|
|
@@ -36,6 +41,13 @@ bool mp_entity_pad_set_format(MPDevice *device,
|
2022-12-15 13:54:39 +01:00
|
|
|
uint32_t pad,
|
|
|
|
MPMode *mode);
|
|
|
|
|
|
|
|
+bool mp_device_setup_link_by_name(MPDevice *device,
|
|
|
|
+ const char *source_entity_name,
|
|
|
|
+ uint32_t source_pad_index,
|
|
|
|
+ const char *sink_entity_name,
|
|
|
|
+ uint32_t sink_pad_index,
|
|
|
|
+ bool enabled);
|
|
|
|
+
|
|
|
|
const struct media_device_info *mp_device_get_info(const MPDevice *device);
|
|
|
|
const struct media_v2_entity *mp_device_find_entity(const MPDevice *device,
|
|
|
|
const char *driver_name);
|
2023-06-27 13:13:22 +02:00
|
|
|
@@ -81,3 +93,6 @@ MPDevice *mp_device_list_remove(MPDeviceList **device_list);
|
|
|
|
MPDevice *mp_device_list_get(const MPDeviceList *device_list);
|
|
|
|
const char *mp_device_list_get_path(const MPDeviceList *device_list);
|
|
|
|
MPDeviceList *mp_device_list_next(const MPDeviceList *device_list);
|
|
|
|
+
|
|
|
|
+void mp_device_setup_media_link_pad_crop(MPDevice *device,
|
|
|
|
+ const struct mp_media_crop_config *crop);
|
2022-12-15 13:54:39 +01:00
|
|
|
diff --git a/src/io_pipeline.c b/src/io_pipeline.c
|
2023-06-27 13:13:22 +02:00
|
|
|
index e9f80c2..135b344 100644
|
2022-12-15 13:54:39 +01:00
|
|
|
--- a/src/io_pipeline.c
|
|
|
|
+++ b/src/io_pipeline.c
|
|
|
|
@@ -47,7 +47,8 @@ struct camera_info {
|
|
|
|
// int media_fd;
|
|
|
|
|
|
|
|
// struct mp_media_link media_links[MP_MAX_LINKS];
|
|
|
|
- // int num_media_links;
|
|
|
|
+ struct mp_media_link_config media_links[MP_MAX_LINKS];
|
|
|
|
+ int num_media_links;
|
|
|
|
|
|
|
|
// int gain_ctrl;
|
|
|
|
};
|
2023-06-27 13:13:22 +02:00
|
|
|
@@ -100,30 +101,41 @@ static bool want_focus = false;
|
2022-12-15 13:54:39 +01:00
|
|
|
static MPPipeline *pipeline;
|
|
|
|
static GSource *capture_source;
|
|
|
|
|
|
|
|
+static void
|
|
|
|
+mp_setup_media_link_pad_crops(struct device_info *dev_info,
|
|
|
|
+ const struct mp_media_crop_config media_crops[],
|
|
|
|
+ int num_media_crops)
|
|
|
|
+{
|
|
|
|
+ for(int i = 0; i < num_media_crops; i++) {
|
|
|
|
+ const struct mp_media_crop_config *crop = media_crops + i;
|
2023-06-27 13:13:22 +02:00
|
|
|
+ mp_device_setup_media_link_pad_crop(dev_info->device, crop);
|
2022-12-15 13:54:39 +01:00
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
static void
|
|
|
|
mp_setup_media_link_pad_formats(struct device_info *dev_info,
|
|
|
|
- const struct mp_media_link_config media_links[],
|
|
|
|
- int num_media_links,
|
|
|
|
- MPMode *mode)
|
|
|
|
+ const struct mp_media_format_config media_formats[],
|
|
|
|
+ int num_media_formats)
|
|
|
|
{
|
|
|
|
- const struct media_v2_entity *entities[2];
|
|
|
|
- int ports[2];
|
|
|
|
- for (int i = 0; i < num_media_links; i++) {
|
|
|
|
- entities[0] = mp_device_find_entity(
|
|
|
|
- dev_info->device, (const char *)media_links[i].source_name);
|
|
|
|
- entities[1] = mp_device_find_entity(
|
|
|
|
- dev_info->device, (const char *)media_links[i].target_name);
|
|
|
|
- ports[0] = media_links[i].source_port;
|
|
|
|
- ports[1] = media_links[i].target_port;
|
|
|
|
-
|
|
|
|
- for (int j = 0; j < 2; j++)
|
|
|
|
- if (!mp_entity_pad_set_format(
|
|
|
|
- dev_info->device, entities[j], ports[j], mode)) {
|
|
|
|
- g_printerr("Failed to set %s:%d format\n",
|
|
|
|
- entities[j]->name,
|
|
|
|
- ports[j]);
|
|
|
|
- exit(EXIT_FAILURE);
|
|
|
|
- }
|
|
|
|
+ for(int i = 0; i < num_media_formats; i++) {
|
|
|
|
+ const struct mp_media_format_config *format =
|
|
|
|
+ media_formats + i;
|
|
|
|
+ const struct media_v2_entity *entity =
|
|
|
|
+ mp_device_find_entity
|
|
|
|
+ (dev_info->device, format->name);
|
|
|
|
+ MPMode *mode =
|
|
|
|
+ (MPMode *)
|
|
|
|
+ &format->mode;
|
|
|
|
+ bool successful =
|
|
|
|
+ mp_entity_pad_set_format
|
|
|
|
+ (dev_info->device, entity, format->pad, mode);
|
|
|
|
+
|
|
|
|
+ if(!successful) {
|
|
|
|
+ g_printerr( "Failed to set %s:%d format\n",
|
|
|
|
+ entity->name,
|
|
|
|
+ format->pad );
|
|
|
|
+ exit(EXIT_FAILURE);
|
|
|
|
+ }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-27 13:13:22 +02:00
|
|
|
@@ -224,6 +236,9 @@ setup_camera(MPDeviceList **device_list, const struct mp_camera_config *config)
|
2022-12-15 13:54:39 +01:00
|
|
|
struct device_info *dev_info = &devices[device_index];
|
|
|
|
|
|
|
|
info->device_index = device_index;
|
|
|
|
+ info->num_media_links = config->num_media_links;
|
|
|
|
+
|
|
|
|
+ memcpy(info->media_links, config->media_links, MP_MAX_LINKS * sizeof(struct mp_media_link_config));
|
|
|
|
|
|
|
|
const struct media_v2_entity *entity =
|
|
|
|
mp_device_find_entity(dev_info->device, config->dev_name);
|
2023-06-27 13:13:22 +02:00
|
|
|
@@ -238,11 +253,33 @@ setup_camera(MPDeviceList **device_list, const struct mp_camera_config *config)
|
2022-12-15 13:54:39 +01:00
|
|
|
|
|
|
|
info->pad_id = pad->id;
|
|
|
|
|
2022-12-16 17:18:49 +01:00
|
|
|
- // Make sure the camera starts out as disabled
|
|
|
|
- mp_device_setup_link(dev_info->device,
|
|
|
|
- info->pad_id,
|
|
|
|
- dev_info->interface_pad_id,
|
|
|
|
- false);
|
|
|
|
+ // Only disable the camera here if no links are defined in the
|
|
|
|
+ // config file.
|
|
|
|
+ if(config->num_media_links == 0)
|
|
|
|
+ {
|
|
|
|
+ // Make sure the camera starts out as disabled
|
|
|
|
+ mp_device_setup_link(dev_info->device,
|
|
|
|
+ info->pad_id,
|
|
|
|
+ dev_info->interface_pad_id,
|
|
|
|
+ false);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // If links are defined, disable all of them.
|
2022-12-15 13:54:39 +01:00
|
|
|
+ const size_t num_links =
|
|
|
|
+ mp_device_get_num_links(dev_info->device);
|
|
|
|
+ const struct media_v2_link *links =
|
|
|
|
+ mp_device_get_links(dev_info->device);
|
|
|
|
+
|
|
|
|
+ for(int i = 0; i < num_links; i++) {
|
|
|
|
+ const struct media_v2_link *link = links + i;
|
|
|
|
+
|
|
|
|
+ if(!(link->flags & MEDIA_LNK_FL_IMMUTABLE)) {
|
|
|
|
+ mp_device_setup_link(dev_info->device,
|
|
|
|
+ link->source_id,
|
|
|
|
+ link->sink_id,
|
|
|
|
+ false);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
|
|
const struct media_v2_interface *interface =
|
|
|
|
mp_device_find_entity_interface(dev_info->device,
|
2023-06-27 13:13:22 +02:00
|
|
|
@@ -269,11 +306,14 @@ setup_camera(MPDeviceList **device_list, const struct mp_camera_config *config)
|
2022-12-15 13:54:39 +01:00
|
|
|
// the ov5640 driver where it won't allow setting the preview
|
|
|
|
// format initially.
|
|
|
|
MPMode mode = config->capture_mode;
|
|
|
|
- if (config->num_media_links)
|
|
|
|
+ if (config->num_media_formats)
|
|
|
|
mp_setup_media_link_pad_formats(dev_info,
|
|
|
|
- config->media_links,
|
|
|
|
- config->num_media_links,
|
|
|
|
- &mode);
|
|
|
|
+ config->media_formats,
|
|
|
|
+ config->num_media_formats);
|
|
|
|
+ if (config->num_media_crops)
|
|
|
|
+ mp_setup_media_link_pad_crops(dev_info,
|
|
|
|
+ config->media_crops,
|
|
|
|
+ config->num_media_crops);
|
|
|
|
mp_camera_set_mode(info->camera, &mode);
|
|
|
|
|
|
|
|
// Trigger continuous auto focus if the sensor supports it
|
2023-06-27 13:13:22 +02:00
|
|
|
@@ -435,9 +475,12 @@ capture(MPPipeline *pipeline, const void *data)
|
2022-12-15 13:54:39 +01:00
|
|
|
mode = camera->capture_mode;
|
|
|
|
if (camera->num_media_links)
|
|
|
|
mp_setup_media_link_pad_formats(dev_info,
|
|
|
|
- camera->media_links,
|
|
|
|
- camera->num_media_links,
|
|
|
|
- &mode);
|
|
|
|
+ camera->media_formats,
|
|
|
|
+ camera->num_media_formats);
|
|
|
|
+ if (camera->num_media_crops)
|
|
|
|
+ mp_setup_media_link_pad_crops(dev_info,
|
|
|
|
+ camera->media_crops,
|
|
|
|
+ camera->num_media_crops);
|
|
|
|
mp_camera_set_mode(info->camera, &mode);
|
|
|
|
just_switched_mode = true;
|
|
|
|
|
2023-06-27 13:13:22 +02:00
|
|
|
@@ -604,9 +647,13 @@ on_frame(MPBuffer buffer, void *_data)
|
2022-12-15 13:54:39 +01:00
|
|
|
if (camera->num_media_links)
|
|
|
|
mp_setup_media_link_pad_formats(
|
|
|
|
dev_info,
|
|
|
|
- camera->media_links,
|
|
|
|
- camera->num_media_links,
|
|
|
|
- &mode);
|
|
|
|
+ camera->media_formats,
|
|
|
|
+ camera->num_media_formats);
|
|
|
|
+ if (camera->num_media_crops)
|
|
|
|
+ mp_setup_media_link_pad_crops(
|
|
|
|
+ dev_info,
|
|
|
|
+ camera->media_crops,
|
|
|
|
+ camera->num_media_crops);
|
|
|
|
mp_camera_set_mode(info->camera, &mode);
|
|
|
|
just_switched_mode = true;
|
|
|
|
|
2023-06-27 13:13:22 +02:00
|
|
|
@@ -622,25 +669,6 @@ on_frame(MPBuffer buffer, void *_data)
|
2022-12-16 17:18:49 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
-static void
|
|
|
|
-mp_setup_media_link(struct device_info *dev_info,
|
|
|
|
- const struct mp_media_link_config *cfg,
|
|
|
|
- bool enable)
|
|
|
|
-{
|
|
|
|
- const struct media_v2_entity *source_entity =
|
|
|
|
- mp_device_find_entity(dev_info->device, cfg->source_name);
|
|
|
|
-
|
|
|
|
- const struct media_v2_entity *target_entity =
|
|
|
|
- mp_device_find_entity(dev_info->device, cfg->target_name);
|
|
|
|
-
|
|
|
|
- mp_device_setup_entity_link(dev_info->device,
|
|
|
|
- source_entity->id,
|
|
|
|
- target_entity->id,
|
|
|
|
- cfg->source_port,
|
|
|
|
- cfg->target_port,
|
|
|
|
- enable);
|
|
|
|
-}
|
|
|
|
-
|
2022-12-15 13:54:39 +01:00
|
|
|
static void
|
|
|
|
update_state(MPPipeline *pipeline, const struct mp_io_pipeline_state *state)
|
|
|
|
{
|
2023-06-27 13:13:22 +02:00
|
|
|
@@ -664,8 +692,8 @@ update_state(MPPipeline *pipeline, const struct mp_io_pipeline_state *state)
|
2022-12-15 13:54:39 +01:00
|
|
|
|
2022-12-16 17:18:49 +01:00
|
|
|
// Disable media links
|
|
|
|
for (int i = 0; i < camera->num_media_links; i++)
|
|
|
|
- mp_setup_media_link(
|
|
|
|
- dev_info, &camera->media_links[i], false);
|
|
|
|
+ mp_device_setup_media_link(
|
|
|
|
+ dev_info->device, &camera->media_links[i], false);
|
2022-12-15 13:54:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (capture_source) {
|
2023-06-27 13:13:22 +02:00
|
|
|
@@ -679,23 +707,32 @@ update_state(MPPipeline *pipeline, const struct mp_io_pipeline_state *state)
|
2022-12-15 13:54:39 +01:00
|
|
|
struct camera_info *info = &cameras[camera->index];
|
|
|
|
struct device_info *dev_info = &devices[info->device_index];
|
|
|
|
|
|
|
|
- mp_device_setup_link(dev_info->device,
|
|
|
|
- info->pad_id,
|
|
|
|
- dev_info->interface_pad_id,
|
|
|
|
- true);
|
2022-12-16 17:18:49 +01:00
|
|
|
+ // Only enable the camera here if no links are defined
|
|
|
|
+ // in the config file.
|
|
|
|
+ if(info->num_media_links == 0)
|
2022-12-15 13:54:39 +01:00
|
|
|
+ {
|
|
|
|
+ mp_device_setup_link(dev_info->device,
|
|
|
|
+ info->pad_id,
|
|
|
|
+ dev_info->interface_pad_id,
|
|
|
|
+ true);
|
|
|
|
+ }
|
|
|
|
|
2022-12-16 17:18:49 +01:00
|
|
|
- // Enable media links
|
|
|
|
+ // If links are defined, enable all of them.
|
2022-12-15 13:54:39 +01:00
|
|
|
for (int i = 0; i < camera->num_media_links; i++)
|
2022-12-16 17:18:49 +01:00
|
|
|
- mp_setup_media_link(
|
|
|
|
- dev_info, &camera->media_links[i], true);
|
|
|
|
+ mp_device_setup_media_link(
|
|
|
|
+ dev_info->device, &camera->media_links[i], true);
|
|
|
|
|
|
|
|
mode = camera->preview_mode;
|
2022-12-15 13:54:39 +01:00
|
|
|
if (camera->num_media_links)
|
|
|
|
mp_setup_media_link_pad_formats(
|
|
|
|
dev_info,
|
|
|
|
- camera->media_links,
|
|
|
|
- camera->num_media_links,
|
|
|
|
- &mode);
|
|
|
|
+ camera->media_formats,
|
|
|
|
+ camera->num_media_formats);
|
|
|
|
+ if (camera->num_media_crops)
|
|
|
|
+ mp_setup_media_link_pad_crops(
|
|
|
|
+ dev_info,
|
|
|
|
+ camera->media_crops,
|
|
|
|
+ camera->num_media_crops);
|
|
|
|
mp_camera_set_mode(info->camera, &mode);
|
|
|
|
|
|
|
|
mp_camera_start_capture(info->camera);
|