Updated patches
This commit is contained in:
		@@ -0,0 +1,23 @@
 | 
			
		||||
From 06230f3a02cffdf8b683f85cb32fc256d73615d9 Mon Sep 17 00:00:00 2001
 | 
			
		||||
From: kgmt0 <kritphong@teknik.io>
 | 
			
		||||
Date: Sat, 2 Jul 2022 12:15:22 +0700
 | 
			
		||||
Subject: [PATCH] device: Make mp_device_setup_link() support non-zero pad
 | 
			
		||||
 indices
 | 
			
		||||
 | 
			
		||||
---
 | 
			
		||||
 src/device.c | 2 +-
 | 
			
		||||
 1 file changed, 1 insertion(+), 1 deletion(-)
 | 
			
		||||
 | 
			
		||||
diff --git a/src/device.c b/src/device.c
 | 
			
		||||
index b4d5f80..9e2db00 100644
 | 
			
		||||
--- a/src/device.c
 | 
			
		||||
+++ b/src/device.c
 | 
			
		||||
@@ -197,7 +197,7 @@ mp_device_setup_link(MPDevice *device,
 | 
			
		||||
         g_return_val_if_fail(sink_pad, false);
 | 
			
		||||
 
 | 
			
		||||
         return mp_device_setup_entity_link(
 | 
			
		||||
-                device, source_pad->entity_id, sink_pad->entity_id, 0, 0, enabled);
 | 
			
		||||
+                device, source_pad->entity_id, sink_pad->entity_id, source_pad->index, sink_pad->index, enabled);
 | 
			
		||||
 }
 | 
			
		||||
 
 | 
			
		||||
 bool
 | 
			
		||||
@@ -0,0 +1,130 @@
 | 
			
		||||
From 27a1e606d680295e0b4caceadf74ff5857ac16b2 Mon Sep 17 00:00:00 2001
 | 
			
		||||
From: kgmt0 <kritphong@teknik.io>
 | 
			
		||||
Date: Thu, 1 Dec 2022 00:09:27 -0600
 | 
			
		||||
Subject: [PATCH] Add media-formats and media-crops to the config file format
 | 
			
		||||
 | 
			
		||||
---
 | 
			
		||||
 src/camera_config.c | 61 +++++++++++++++++++++++++++++++++++++++++++++
 | 
			
		||||
 src/camera_config.h | 23 +++++++++++++++++
 | 
			
		||||
 2 files changed, 84 insertions(+)
 | 
			
		||||
 | 
			
		||||
diff --git a/src/camera_config.c b/src/camera_config.c
 | 
			
		||||
index 6ff74d1..1102354 100644
 | 
			
		||||
--- a/src/camera_config.c
 | 
			
		||||
+++ b/src/camera_config.c
 | 
			
		||||
@@ -184,6 +184,67 @@ config_ini_handler(void *user,
 | 
			
		||||
                                 ++cc->num_media_links;
 | 
			
		||||
                         }
 | 
			
		||||
                         g_strfreev(linkdefs);
 | 
			
		||||
+                } else if (strcmp(name, "media-formats") == 0) {
 | 
			
		||||
+                        struct mp_camera_config *cc = &cameras[index];
 | 
			
		||||
+                        char **formatdefs = g_strsplit(value, ",", 0);
 | 
			
		||||
+
 | 
			
		||||
+                        for (int i = 0; i < MP_MAX_FORMATS && formatdefs[i] != NULL;
 | 
			
		||||
+                             ++i) {
 | 
			
		||||
+                                char **entry = g_strsplit(formatdefs[i], ":", 5);
 | 
			
		||||
+                                char *name = entry[0];
 | 
			
		||||
+                                int pad = strtoint(entry[1], NULL, 10);
 | 
			
		||||
+                                char *format = entry[2];
 | 
			
		||||
+                                char *width = entry[3];
 | 
			
		||||
+                                char *height = entry[4];
 | 
			
		||||
+
 | 
			
		||||
+                                const size_t name_size =
 | 
			
		||||
+                                        sizeof(cc->media_formats[i].name);
 | 
			
		||||
+                                strncpy(cc->media_formats[i].name,
 | 
			
		||||
+                                        name,
 | 
			
		||||
+                                        name_size );
 | 
			
		||||
+
 | 
			
		||||
+                                cc->media_formats[i].pad = pad;
 | 
			
		||||
+
 | 
			
		||||
+                                cc->media_formats[i].mode.pixel_format =
 | 
			
		||||
+                                        mp_pixel_format_from_str(format);
 | 
			
		||||
+                                cc->media_formats[i].mode.width =
 | 
			
		||||
+                                        strtoint(width, NULL, 10);
 | 
			
		||||
+                                cc->media_formats[i].mode.height =
 | 
			
		||||
+                                        strtoint(height, NULL, 10);
 | 
			
		||||
+
 | 
			
		||||
+                                cc->num_media_formats++;
 | 
			
		||||
+
 | 
			
		||||
+                                g_strfreev(entry);
 | 
			
		||||
+                        }
 | 
			
		||||
+                } else if (strcmp(name, "media-crops") == 0) {
 | 
			
		||||
+                        char **formatdefs = g_strsplit(value, ",", 0);
 | 
			
		||||
+
 | 
			
		||||
+                        for (int i = 0; i < MP_MAX_CROPS && formatdefs[i] != NULL;
 | 
			
		||||
+                             ++i) {
 | 
			
		||||
+                                char **entry = g_strsplit(formatdefs[i], ":", 6);
 | 
			
		||||
+                                char *name = entry[0];
 | 
			
		||||
+                                int pad = strtoint(entry[1], NULL, 10);
 | 
			
		||||
+                                int top = strtoint(entry[2], NULL, 10);
 | 
			
		||||
+                                int left = strtoint(entry[3], NULL, 10);
 | 
			
		||||
+                                int width = strtoint(entry[4], NULL, 10);
 | 
			
		||||
+                                int height = strtoint(entry[5], NULL, 10);
 | 
			
		||||
+
 | 
			
		||||
+                                const size_t name_size =
 | 
			
		||||
+                                        sizeof(cc->media_crops[i].name);
 | 
			
		||||
+                                strncpy(cc->media_crops[i].name,
 | 
			
		||||
+                                        name,
 | 
			
		||||
+                                        name_size );
 | 
			
		||||
+
 | 
			
		||||
+                                cc->media_crops[i].pad = pad;
 | 
			
		||||
+                                cc->media_crops[i].top = top;
 | 
			
		||||
+                                cc->media_crops[i].left = left;
 | 
			
		||||
+                                cc->media_crops[i].width = width;
 | 
			
		||||
+                                cc->media_crops[i].height = height;
 | 
			
		||||
+
 | 
			
		||||
+                                cc->num_media_crops++;
 | 
			
		||||
+
 | 
			
		||||
+                                g_strfreev(entry);
 | 
			
		||||
+                        }
 | 
			
		||||
                 } else if (strcmp(name, "colormatrix") == 0) {
 | 
			
		||||
                         sscanf(value,
 | 
			
		||||
                                "%f,%f,%f,%f,%f,%f,%f,%f,%f",
 | 
			
		||||
diff --git a/src/camera_config.h b/src/camera_config.h
 | 
			
		||||
index d53d36f..b1bd5a5 100644
 | 
			
		||||
--- a/src/camera_config.h
 | 
			
		||||
+++ b/src/camera_config.h
 | 
			
		||||
@@ -7,6 +7,8 @@
 | 
			
		||||
 
 | 
			
		||||
 #define MP_MAX_CAMERAS 5
 | 
			
		||||
 #define MP_MAX_LINKS 10
 | 
			
		||||
+#define MP_MAX_FORMATS 10
 | 
			
		||||
+#define MP_MAX_CROPS 10
 | 
			
		||||
 
 | 
			
		||||
 struct mp_media_link_config {
 | 
			
		||||
         char source_name[100];
 | 
			
		||||
@@ -15,6 +17,21 @@ struct mp_media_link_config {
 | 
			
		||||
         int target_port;
 | 
			
		||||
 };
 | 
			
		||||
 
 | 
			
		||||
+struct mp_media_format_config {
 | 
			
		||||
+        char name[100];
 | 
			
		||||
+        int pad;
 | 
			
		||||
+        MPMode mode;
 | 
			
		||||
+};
 | 
			
		||||
+
 | 
			
		||||
+struct mp_media_crop_config {
 | 
			
		||||
+        char name[100];
 | 
			
		||||
+        int pad;
 | 
			
		||||
+        int left;
 | 
			
		||||
+        int top;
 | 
			
		||||
+        int width;
 | 
			
		||||
+        int height;
 | 
			
		||||
+};
 | 
			
		||||
+
 | 
			
		||||
 struct mp_camera_config {
 | 
			
		||||
         size_t index;
 | 
			
		||||
 
 | 
			
		||||
@@ -30,6 +47,12 @@ struct mp_camera_config {
 | 
			
		||||
         struct mp_media_link_config media_links[MP_MAX_LINKS];
 | 
			
		||||
         int num_media_links;
 | 
			
		||||
 
 | 
			
		||||
+        struct mp_media_format_config media_formats[MP_MAX_FORMATS];
 | 
			
		||||
+        int num_media_formats;
 | 
			
		||||
+
 | 
			
		||||
+        struct mp_media_crop_config media_crops[MP_MAX_CROPS];
 | 
			
		||||
+        int num_media_crops;
 | 
			
		||||
+
 | 
			
		||||
         float colormatrix[9];
 | 
			
		||||
         float forwardmatrix[9];
 | 
			
		||||
         float previewmatrix[9];
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
From 8721f29e27f21111c439ee45f4ea76b56017d016 Mon Sep 17 00:00:00 2001
 | 
			
		||||
From d8b35bc223989cb165ba1b0716ab9f0ca9c43e53 Mon Sep 17 00:00:00 2001
 | 
			
		||||
From: kgmt0 <kritphong@teknik.io>
 | 
			
		||||
Date: Fri, 17 Jun 2022 02:08:44 +0700
 | 
			
		||||
Date: Thu, 1 Dec 2022 00:13:27 -0600
 | 
			
		||||
Subject: [PATCH] WIP: Support Pinephone Pro
 | 
			
		||||
 | 
			
		||||
Both cameras work now but the quality is very poor.
 | 
			
		||||
@@ -13,16 +13,14 @@ media controller.
 | 
			
		||||
Tested with Linux 6.0.8-1 from Arch Linux ARM (linux-megi).
 | 
			
		||||
---
 | 
			
		||||
 config/motorola,osprey.ini      |   1 +
 | 
			
		||||
 config/pine64,pinephone-pro.ini |  51 ++++++++
 | 
			
		||||
 config/pine64,pinephone-pro.ini |  49 +++++++++
 | 
			
		||||
 config/xiaomi,scorpio.ini       |   1 +
 | 
			
		||||
 meson.build                     |   1 +
 | 
			
		||||
 src/camera.c                    |  10 +-
 | 
			
		||||
 src/camera_config.c             |  61 ++++++++++
 | 
			
		||||
 src/camera_config.h             |  23 ++++
 | 
			
		||||
 src/device.c                    |  82 +++++++++++++
 | 
			
		||||
 src/device.h                    |   9 ++
 | 
			
		||||
 src/io_pipeline.c               | 201 +++++++++++++++++++++++++-------
 | 
			
		||||
 10 files changed, 392 insertions(+), 48 deletions(-)
 | 
			
		||||
 src/device.c                    | 101 ++++++++++++++++++
 | 
			
		||||
 src/device.h                    |  14 +++
 | 
			
		||||
 src/io_pipeline.c               | 184 ++++++++++++++++++++------------
 | 
			
		||||
 8 files changed, 288 insertions(+), 73 deletions(-)
 | 
			
		||||
 create mode 100644 config/pine64,pinephone-pro.ini
 | 
			
		||||
 | 
			
		||||
diff --git a/config/motorola,osprey.ini b/config/motorola,osprey.ini
 | 
			
		||||
@@ -36,10 +34,10 @@ index ab8990d..5809a8e 100644
 | 
			
		||||
+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
 | 
			
		||||
index 0000000..3416ca0
 | 
			
		||||
index 0000000..bd5cfcd
 | 
			
		||||
--- /dev/null
 | 
			
		||||
+++ b/config/pine64,pinephone-pro.ini
 | 
			
		||||
@@ -0,0 +1,51 @@
 | 
			
		||||
@@ -0,0 +1,49 @@
 | 
			
		||||
+[device]
 | 
			
		||||
+make=PINE64
 | 
			
		||||
+model=PinePhone
 | 
			
		||||
@@ -75,12 +73,10 @@ index 0000000..3416ca0
 | 
			
		||||
+capture-width=3264
 | 
			
		||||
+capture-height=2448
 | 
			
		||||
+capture-rate=30
 | 
			
		||||
+;capture-fmt=BGGR10P
 | 
			
		||||
+capture-fmt=BGGR8
 | 
			
		||||
+preview-width=3264
 | 
			
		||||
+preview-height=2448
 | 
			
		||||
+preview-rate=30
 | 
			
		||||
+;preview-fmt=BGGR10P
 | 
			
		||||
+preview-fmt=BGGR8
 | 
			
		||||
+rotate=90
 | 
			
		||||
+mirrored=true
 | 
			
		||||
@@ -133,128 +129,8 @@ index 9a08f56..7368189 100644
 | 
			
		||||
         }
 | 
			
		||||
 
 | 
			
		||||
         // Set the mode for the video device
 | 
			
		||||
diff --git a/src/camera_config.c b/src/camera_config.c
 | 
			
		||||
index 6ff74d1..1102354 100644
 | 
			
		||||
--- a/src/camera_config.c
 | 
			
		||||
+++ b/src/camera_config.c
 | 
			
		||||
@@ -184,6 +184,67 @@ config_ini_handler(void *user,
 | 
			
		||||
                                 ++cc->num_media_links;
 | 
			
		||||
                         }
 | 
			
		||||
                         g_strfreev(linkdefs);
 | 
			
		||||
+                } else if (strcmp(name, "media-formats") == 0) {
 | 
			
		||||
+                        struct mp_camera_config *cc = &cameras[index];
 | 
			
		||||
+                        char **formatdefs = g_strsplit(value, ",", 0);
 | 
			
		||||
+
 | 
			
		||||
+                        for (int i = 0; i < MP_MAX_FORMATS && formatdefs[i] != NULL;
 | 
			
		||||
+                             ++i) {
 | 
			
		||||
+                                char **entry = g_strsplit(formatdefs[i], ":", 5);
 | 
			
		||||
+                                char *name = entry[0];
 | 
			
		||||
+                                int pad = strtoint(entry[1], NULL, 10);
 | 
			
		||||
+                                char *format = entry[2];
 | 
			
		||||
+                                char *width = entry[3];
 | 
			
		||||
+                                char *height = entry[4];
 | 
			
		||||
+
 | 
			
		||||
+                                const size_t name_size =
 | 
			
		||||
+                                        sizeof(cc->media_formats[i].name);
 | 
			
		||||
+                                strncpy(cc->media_formats[i].name,
 | 
			
		||||
+                                        name,
 | 
			
		||||
+                                        name_size );
 | 
			
		||||
+
 | 
			
		||||
+                                cc->media_formats[i].pad = pad;
 | 
			
		||||
+
 | 
			
		||||
+                                cc->media_formats[i].mode.pixel_format =
 | 
			
		||||
+                                        mp_pixel_format_from_str(format);
 | 
			
		||||
+                                cc->media_formats[i].mode.width =
 | 
			
		||||
+                                        strtoint(width, NULL, 10);
 | 
			
		||||
+                                cc->media_formats[i].mode.height =
 | 
			
		||||
+                                        strtoint(height, NULL, 10);
 | 
			
		||||
+
 | 
			
		||||
+                                cc->num_media_formats++;
 | 
			
		||||
+
 | 
			
		||||
+                                g_strfreev(entry);
 | 
			
		||||
+                        }
 | 
			
		||||
+                } else if (strcmp(name, "media-crops") == 0) {
 | 
			
		||||
+                        char **formatdefs = g_strsplit(value, ",", 0);
 | 
			
		||||
+
 | 
			
		||||
+                        for (int i = 0; i < MP_MAX_CROPS && formatdefs[i] != NULL;
 | 
			
		||||
+                             ++i) {
 | 
			
		||||
+                                char **entry = g_strsplit(formatdefs[i], ":", 6);
 | 
			
		||||
+                                char *name = entry[0];
 | 
			
		||||
+                                int pad = strtoint(entry[1], NULL, 10);
 | 
			
		||||
+                                int top = strtoint(entry[2], NULL, 10);
 | 
			
		||||
+                                int left = strtoint(entry[3], NULL, 10);
 | 
			
		||||
+                                int width = strtoint(entry[4], NULL, 10);
 | 
			
		||||
+                                int height = strtoint(entry[5], NULL, 10);
 | 
			
		||||
+
 | 
			
		||||
+                                const size_t name_size =
 | 
			
		||||
+                                        sizeof(cc->media_crops[i].name);
 | 
			
		||||
+                                strncpy(cc->media_crops[i].name,
 | 
			
		||||
+                                        name,
 | 
			
		||||
+                                        name_size );
 | 
			
		||||
+
 | 
			
		||||
+                                cc->media_crops[i].pad = pad;
 | 
			
		||||
+                                cc->media_crops[i].top = top;
 | 
			
		||||
+                                cc->media_crops[i].left = left;
 | 
			
		||||
+                                cc->media_crops[i].width = width;
 | 
			
		||||
+                                cc->media_crops[i].height = height;
 | 
			
		||||
+
 | 
			
		||||
+                                cc->num_media_crops++;
 | 
			
		||||
+
 | 
			
		||||
+                                g_strfreev(entry);
 | 
			
		||||
+                        }
 | 
			
		||||
                 } else if (strcmp(name, "colormatrix") == 0) {
 | 
			
		||||
                         sscanf(value,
 | 
			
		||||
                                "%f,%f,%f,%f,%f,%f,%f,%f,%f",
 | 
			
		||||
diff --git a/src/camera_config.h b/src/camera_config.h
 | 
			
		||||
index d53d36f..b1bd5a5 100644
 | 
			
		||||
--- a/src/camera_config.h
 | 
			
		||||
+++ b/src/camera_config.h
 | 
			
		||||
@@ -7,6 +7,8 @@
 | 
			
		||||
 
 | 
			
		||||
 #define MP_MAX_CAMERAS 5
 | 
			
		||||
 #define MP_MAX_LINKS 10
 | 
			
		||||
+#define MP_MAX_FORMATS 10
 | 
			
		||||
+#define MP_MAX_CROPS 10
 | 
			
		||||
 
 | 
			
		||||
 struct mp_media_link_config {
 | 
			
		||||
         char source_name[100];
 | 
			
		||||
@@ -15,6 +17,21 @@ struct mp_media_link_config {
 | 
			
		||||
         int target_port;
 | 
			
		||||
 };
 | 
			
		||||
 
 | 
			
		||||
+struct mp_media_format_config {
 | 
			
		||||
+        char name[100];
 | 
			
		||||
+        int pad;
 | 
			
		||||
+        MPMode mode;
 | 
			
		||||
+};
 | 
			
		||||
+
 | 
			
		||||
+struct mp_media_crop_config {
 | 
			
		||||
+        char name[100];
 | 
			
		||||
+        int pad;
 | 
			
		||||
+        int left;
 | 
			
		||||
+        int top;
 | 
			
		||||
+        int width;
 | 
			
		||||
+        int height;
 | 
			
		||||
+};
 | 
			
		||||
+
 | 
			
		||||
 struct mp_camera_config {
 | 
			
		||||
         size_t index;
 | 
			
		||||
 
 | 
			
		||||
@@ -30,6 +47,12 @@ struct mp_camera_config {
 | 
			
		||||
         struct mp_media_link_config media_links[MP_MAX_LINKS];
 | 
			
		||||
         int num_media_links;
 | 
			
		||||
 
 | 
			
		||||
+        struct mp_media_format_config media_formats[MP_MAX_FORMATS];
 | 
			
		||||
+        int num_media_formats;
 | 
			
		||||
+
 | 
			
		||||
+        struct mp_media_crop_config media_crops[MP_MAX_CROPS];
 | 
			
		||||
+        int num_media_crops;
 | 
			
		||||
+
 | 
			
		||||
         float colormatrix[9];
 | 
			
		||||
         float forwardmatrix[9];
 | 
			
		||||
         float previewmatrix[9];
 | 
			
		||||
diff --git a/src/device.c b/src/device.c
 | 
			
		||||
index 9e2db00..0defccb 100644
 | 
			
		||||
index 9e2db00..1161861 100644
 | 
			
		||||
--- a/src/device.c
 | 
			
		||||
+++ b/src/device.c
 | 
			
		||||
@@ -8,6 +8,8 @@
 | 
			
		||||
@@ -266,7 +142,33 @@ index 9e2db00..0defccb 100644
 | 
			
		||||
 
 | 
			
		||||
 bool
 | 
			
		||||
 mp_find_device_path(struct media_v2_intf_devnode devnode, char *path, int length)
 | 
			
		||||
@@ -237,6 +239,73 @@ mp_entity_pad_set_format(MPDevice *device,
 | 
			
		||||
@@ -183,6 +185,25 @@ mp_device_setup_entity_link(MPDevice *device,
 | 
			
		||||
         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);
 | 
			
		||||
+}
 | 
			
		||||
+
 | 
			
		||||
 bool
 | 
			
		||||
 mp_device_setup_link(MPDevice *device,
 | 
			
		||||
                      uint32_t source_pad_id,
 | 
			
		||||
@@ -237,6 +258,73 @@ mp_entity_pad_set_format(MPDevice *device,
 | 
			
		||||
         return true;
 | 
			
		||||
 }
 | 
			
		||||
 
 | 
			
		||||
@@ -340,7 +242,7 @@ index 9e2db00..0defccb 100644
 | 
			
		||||
 const struct media_v2_entity *
 | 
			
		||||
 mp_device_find_entity(const MPDevice *device, const char *driver_name)
 | 
			
		||||
 {
 | 
			
		||||
@@ -263,6 +332,19 @@ mp_device_find_entity_type(const MPDevice *device, const uint32_t type)
 | 
			
		||||
@@ -263,6 +351,19 @@ mp_device_find_entity_type(const MPDevice *device, const uint32_t type)
 | 
			
		||||
         return NULL;
 | 
			
		||||
 }
 | 
			
		||||
 
 | 
			
		||||
@@ -361,10 +263,29 @@ index 9e2db00..0defccb 100644
 | 
			
		||||
 mp_device_get_info(const MPDevice *device)
 | 
			
		||||
 {
 | 
			
		||||
diff --git a/src/device.h b/src/device.h
 | 
			
		||||
index 1894c67..a9e1b59 100644
 | 
			
		||||
index 1894c67..b324e1a 100644
 | 
			
		||||
--- a/src/device.h
 | 
			
		||||
+++ b/src/device.h
 | 
			
		||||
@@ -36,6 +36,15 @@ bool mp_entity_pad_set_format(MPDevice *device,
 | 
			
		||||
@@ -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,
 | 
			
		||||
@@ -36,6 +41,15 @@ bool mp_entity_pad_set_format(MPDevice *device,
 | 
			
		||||
                               uint32_t pad,
 | 
			
		||||
                               MPMode *mode);
 | 
			
		||||
 
 | 
			
		||||
@@ -381,7 +302,7 @@ index 1894c67..a9e1b59 100644
 | 
			
		||||
 const struct media_v2_entity *mp_device_find_entity(const MPDevice *device,
 | 
			
		||||
                                                     const char *driver_name);
 | 
			
		||||
diff --git a/src/io_pipeline.c b/src/io_pipeline.c
 | 
			
		||||
index 8434420..da95678 100644
 | 
			
		||||
index 8434420..598118f 100644
 | 
			
		||||
--- a/src/io_pipeline.c
 | 
			
		||||
+++ b/src/io_pipeline.c
 | 
			
		||||
@@ -47,7 +47,8 @@ struct camera_info {
 | 
			
		||||
@@ -394,7 +315,7 @@ index 8434420..da95678 100644
 | 
			
		||||
 
 | 
			
		||||
         // int gain_ctrl;
 | 
			
		||||
 };
 | 
			
		||||
@@ -100,36 +101,68 @@ static bool want_focus = false;
 | 
			
		||||
@@ -100,30 +101,52 @@ static bool want_focus = false;
 | 
			
		||||
 static MPPipeline *pipeline;
 | 
			
		||||
 static GSource *capture_source;
 | 
			
		||||
 
 | 
			
		||||
@@ -468,40 +389,7 @@ index 8434420..da95678 100644
 | 
			
		||||
         }
 | 
			
		||||
 }
 | 
			
		||||
 
 | 
			
		||||
 static void
 | 
			
		||||
 setup_camera(MPDeviceList **device_list, const struct mp_camera_config *config)
 | 
			
		||||
 {
 | 
			
		||||
+        char compat[512];
 | 
			
		||||
+        FILE *fp = fopen("/proc/device-tree/compatible", "r");
 | 
			
		||||
+        fgets(compat, 512, fp);
 | 
			
		||||
+        fclose(fp);
 | 
			
		||||
+
 | 
			
		||||
+        printf("setup_camera()\n");
 | 
			
		||||
+        printf("compatible: %s\n", compat);
 | 
			
		||||
+        printf("media_dev: %s\n", config->media_dev_name);
 | 
			
		||||
+        printf("dev: %s\n", config->dev_name);
 | 
			
		||||
+
 | 
			
		||||
         // Find device info
 | 
			
		||||
         size_t device_index = 0;
 | 
			
		||||
         for (; device_index < num_devices; ++device_index) {
 | 
			
		||||
@@ -144,6 +177,7 @@ setup_camera(MPDeviceList **device_list, const struct mp_camera_config *config)
 | 
			
		||||
         if (device_index == num_devices) {
 | 
			
		||||
                 device_index = num_devices;
 | 
			
		||||
 
 | 
			
		||||
+                printf("initializing new device\n");
 | 
			
		||||
                 // Initialize new device
 | 
			
		||||
                 struct device_info *info = &devices[device_index];
 | 
			
		||||
                 info->media_dev_name = config->media_dev_name;
 | 
			
		||||
@@ -175,6 +209,8 @@ setup_camera(MPDeviceList **device_list, const struct mp_camera_config *config)
 | 
			
		||||
                         exit(EXIT_FAILURE);
 | 
			
		||||
                 }
 | 
			
		||||
 
 | 
			
		||||
+                printf("video path: %s\n", dev_name);
 | 
			
		||||
+
 | 
			
		||||
                 info->video_fd = open(dev_name, O_RDWR);
 | 
			
		||||
                 if (info->video_fd == -1) {
 | 
			
		||||
                         g_printerr("Could not open %s: %s\n",
 | 
			
		||||
@@ -191,6 +227,9 @@ setup_camera(MPDeviceList **device_list, const struct mp_camera_config *config)
 | 
			
		||||
@@ -191,6 +214,9 @@ setup_camera(MPDeviceList **device_list, const struct mp_camera_config *config)
 | 
			
		||||
                 struct device_info *dev_info = &devices[device_index];
 | 
			
		||||
 
 | 
			
		||||
                 info->device_index = device_index;
 | 
			
		||||
@@ -511,11 +399,27 @@ index 8434420..da95678 100644
 | 
			
		||||
 
 | 
			
		||||
                 const struct media_v2_entity *entity =
 | 
			
		||||
                         mp_device_find_entity(dev_info->device, config->dev_name);
 | 
			
		||||
@@ -205,11 +244,48 @@ setup_camera(MPDeviceList **device_list, const struct mp_camera_config *config)
 | 
			
		||||
@@ -205,11 +231,33 @@ setup_camera(MPDeviceList **device_list, const struct mp_camera_config *config)
 | 
			
		||||
 
 | 
			
		||||
                 info->pad_id = pad->id;
 | 
			
		||||
 
 | 
			
		||||
+                // Disable all links
 | 
			
		||||
-                // 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.
 | 
			
		||||
+                const size_t num_links =
 | 
			
		||||
+                        mp_device_get_num_links(dev_info->device);
 | 
			
		||||
+                const struct media_v2_link *links =
 | 
			
		||||
@@ -530,49 +434,11 @@ index 8434420..da95678 100644
 | 
			
		||||
+                                                     link->sink_id,
 | 
			
		||||
+                                                     false);
 | 
			
		||||
+                        }
 | 
			
		||||
+                }
 | 
			
		||||
+
 | 
			
		||||
                 // Make sure the camera starts out as disabled
 | 
			
		||||
-                mp_device_setup_link(dev_info->device,
 | 
			
		||||
-                                     info->pad_id,
 | 
			
		||||
-                                     dev_info->interface_pad_id,
 | 
			
		||||
-                                     false);
 | 
			
		||||
+                printf("making sure camera starts out disabled\n");
 | 
			
		||||
+                if(config->num_media_links > 0)
 | 
			
		||||
+                {
 | 
			
		||||
+                        const struct media_v2_entity *entity =
 | 
			
		||||
+                                mp_device_find_entity(dev_info->device, config->media_links[0].source_name);
 | 
			
		||||
+
 | 
			
		||||
+                        // This gets the first pad for this entity, which is
 | 
			
		||||
+                        // fine for Pinephone Pro, but does it really work for
 | 
			
		||||
+                        // all devices?
 | 
			
		||||
+                        const struct media_v2_pad* pad =
 | 
			
		||||
+                                mp_device_get_pad_from_entity(dev_info->device, entity->id);
 | 
			
		||||
+
 | 
			
		||||
+                        mp_device_setup_link(dev_info->device,
 | 
			
		||||
+                                             info->pad_id,
 | 
			
		||||
+                                             pad->id,
 | 
			
		||||
+                                             false);
 | 
			
		||||
+                }
 | 
			
		||||
+                else
 | 
			
		||||
+                {
 | 
			
		||||
+                        mp_device_setup_link(dev_info->device,
 | 
			
		||||
+                                             info->pad_id,
 | 
			
		||||
+                                             dev_info->interface_pad_id,
 | 
			
		||||
+                                             false);
 | 
			
		||||
+                }
 | 
			
		||||
 
 | 
			
		||||
                 const struct media_v2_interface *interface =
 | 
			
		||||
                         mp_device_find_entity_interface(dev_info->device,
 | 
			
		||||
@@ -220,6 +296,7 @@ setup_camera(MPDeviceList **device_list, const struct mp_camera_config *config)
 | 
			
		||||
                         exit(EXIT_FAILURE);
 | 
			
		||||
                 }
 | 
			
		||||
 
 | 
			
		||||
+                printf("camera device path: %s\n", info->dev_fname);
 | 
			
		||||
                 info->fd = open(info->dev_fname, O_RDWR);
 | 
			
		||||
                 if (info->fd == -1) {
 | 
			
		||||
                         g_printerr("Could not open %s: %s\n",
 | 
			
		||||
@@ -234,11 +311,14 @@ setup_camera(MPDeviceList **device_list, const struct mp_camera_config *config)
 | 
			
		||||
@@ -234,11 +282,14 @@ setup_camera(MPDeviceList **device_list, const struct mp_camera_config *config)
 | 
			
		||||
                 // the ov5640 driver where it won't allow setting the preview
 | 
			
		||||
                 // format initially.
 | 
			
		||||
                 MPMode mode = config->capture_mode;
 | 
			
		||||
@@ -591,7 +457,7 @@ index 8434420..da95678 100644
 | 
			
		||||
                 mp_camera_set_mode(info->camera, &mode);
 | 
			
		||||
 
 | 
			
		||||
                 // Trigger continuous auto focus if the sensor supports it
 | 
			
		||||
@@ -400,9 +480,12 @@ capture(MPPipeline *pipeline, const void *data)
 | 
			
		||||
@@ -400,9 +451,12 @@ capture(MPPipeline *pipeline, const void *data)
 | 
			
		||||
         mode = camera->capture_mode;
 | 
			
		||||
         if (camera->num_media_links)
 | 
			
		||||
                 mp_setup_media_link_pad_formats(dev_info,
 | 
			
		||||
@@ -607,7 +473,7 @@ index 8434420..da95678 100644
 | 
			
		||||
         mp_camera_set_mode(info->camera, &mode);
 | 
			
		||||
         just_switched_mode = true;
 | 
			
		||||
 
 | 
			
		||||
@@ -569,9 +652,13 @@ on_frame(MPBuffer buffer, void *_data)
 | 
			
		||||
@@ -569,9 +623,13 @@ on_frame(MPBuffer buffer, void *_data)
 | 
			
		||||
                         if (camera->num_media_links)
 | 
			
		||||
                                 mp_setup_media_link_pad_formats(
 | 
			
		||||
                                         dev_info,
 | 
			
		||||
@@ -624,36 +490,44 @@ index 8434420..da95678 100644
 | 
			
		||||
                         mp_camera_set_mode(info->camera, &mode);
 | 
			
		||||
                         just_switched_mode = true;
 | 
			
		||||
 
 | 
			
		||||
@@ -609,6 +696,8 @@ mp_setup_media_link(struct device_info *dev_info,
 | 
			
		||||
@@ -587,25 +645,6 @@ on_frame(MPBuffer buffer, void *_data)
 | 
			
		||||
         }
 | 
			
		||||
 }
 | 
			
		||||
 
 | 
			
		||||
-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);
 | 
			
		||||
-}
 | 
			
		||||
-
 | 
			
		||||
 static void
 | 
			
		||||
 update_state(MPPipeline *pipeline, const struct mp_io_pipeline_state *state)
 | 
			
		||||
 {
 | 
			
		||||
+        printf("update_state()\n");
 | 
			
		||||
+
 | 
			
		||||
         // Make sure the state isn't updated more than it needs to be by checking
 | 
			
		||||
         // whether this state change actually changes anything.
 | 
			
		||||
         bool has_changed = false;
 | 
			
		||||
@@ -617,6 +706,7 @@ update_state(MPPipeline *pipeline, const struct mp_io_pipeline_state *state)
 | 
			
		||||
                 has_changed = true;
 | 
			
		||||
@@ -629,8 +668,8 @@ update_state(MPPipeline *pipeline, const struct mp_io_pipeline_state *state)
 | 
			
		||||
 
 | 
			
		||||
                 if (camera) {
 | 
			
		||||
+                        printf("uninitializing current camera\n");
 | 
			
		||||
                         struct camera_info *info = &cameras[camera->index];
 | 
			
		||||
                         struct device_info *dev_info = &devices[info->device_index];
 | 
			
		||||
 
 | 
			
		||||
@@ -634,6 +724,7 @@ update_state(MPPipeline *pipeline, const struct mp_io_pipeline_state *state)
 | 
			
		||||
                         // 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);
 | 
			
		||||
                 }
 | 
			
		||||
 
 | 
			
		||||
                 if (capture_source) {
 | 
			
		||||
+                        printf("uninitializing current capture source\n");
 | 
			
		||||
                         g_source_destroy(capture_source);
 | 
			
		||||
                         capture_source = NULL;
 | 
			
		||||
                 }
 | 
			
		||||
@@ -641,13 +732,33 @@ update_state(MPPipeline *pipeline, const struct mp_io_pipeline_state *state)
 | 
			
		||||
                 camera = state->camera;
 | 
			
		||||
 
 | 
			
		||||
                 if (camera) {
 | 
			
		||||
+                        printf("initializing camera\n");
 | 
			
		||||
@@ -644,23 +683,32 @@ update_state(MPPipeline *pipeline, const struct mp_io_pipeline_state *state)
 | 
			
		||||
                         struct camera_info *info = &cameras[camera->index];
 | 
			
		||||
                         struct device_info *dev_info = &devices[info->device_index];
 | 
			
		||||
 
 | 
			
		||||
@@ -661,23 +535,9 @@ index 8434420..da95678 100644
 | 
			
		||||
-                                             info->pad_id,
 | 
			
		||||
-                                             dev_info->interface_pad_id,
 | 
			
		||||
-                                             true);
 | 
			
		||||
+                        if(info->num_media_links > 0)
 | 
			
		||||
+                        {
 | 
			
		||||
+                                const struct media_v2_entity *entity =
 | 
			
		||||
+                                        mp_device_find_entity(dev_info->device, info->media_links[0].source_name);
 | 
			
		||||
+
 | 
			
		||||
+                                // This gets the first pad for this entity, which is
 | 
			
		||||
+                                // fine for Pinephone Pro, but does it really work for
 | 
			
		||||
+                                // all devices?
 | 
			
		||||
+                                const struct media_v2_pad* pad =
 | 
			
		||||
+                                        mp_device_get_pad_from_entity(dev_info->device, entity->id);
 | 
			
		||||
+
 | 
			
		||||
+                                mp_device_setup_link(dev_info->device,
 | 
			
		||||
+                                                     info->pad_id,
 | 
			
		||||
+                                                     pad->id,
 | 
			
		||||
+                                                     true);
 | 
			
		||||
+                        }
 | 
			
		||||
+                        else
 | 
			
		||||
+                        // Only enable the camera here if no links are defined
 | 
			
		||||
+                        // in the config file.
 | 
			
		||||
+                        if(info->num_media_links == 0)
 | 
			
		||||
+                        {
 | 
			
		||||
+                                mp_device_setup_link(dev_info->device,
 | 
			
		||||
+                                                     info->pad_id,
 | 
			
		||||
@@ -685,9 +545,15 @@ index 8434420..da95678 100644
 | 
			
		||||
+                                                     true);
 | 
			
		||||
+                        }
 | 
			
		||||
 
 | 
			
		||||
                         // Enable media links
 | 
			
		||||
-                        // Enable media links
 | 
			
		||||
+                        // If links are defined, enable all of them.
 | 
			
		||||
                         for (int i = 0; i < camera->num_media_links; i++)
 | 
			
		||||
@@ -658,9 +769,13 @@ update_state(MPPipeline *pipeline, const struct mp_io_pipeline_state *state)
 | 
			
		||||
-                                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;
 | 
			
		||||
                         if (camera->num_media_links)
 | 
			
		||||
                                 mp_setup_media_link_pad_formats(
 | 
			
		||||
                                         dev_info,
 | 
			
		||||
@@ -28,7 +28,9 @@ RDEPEND="${DEPEND}"
 | 
			
		||||
BDEPEND=""
 | 
			
		||||
 | 
			
		||||
PATCHES=(
 | 
			
		||||
	"${FILESDIR}"/8721f29e27f21111c439ee45f4ea76b56017d016.patch
 | 
			
		||||
	"${FILESDIR}"/06230f3a02cffdf8b683f85cb32fc256d73615d9.patch
 | 
			
		||||
        "${FILESDIR}"/27a1e606d680295e0b4caceadf74ff5857ac16b2.patch
 | 
			
		||||
        "${FILESDIR}"/d8b35bc223989cb165ba1b0716ab9f0ca9c43e53.patch
 | 
			
		||||
)	
 | 
			
		||||
 | 
			
		||||
pkg_postinst() {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user