summaryrefslogtreecommitdiff
path: root/src/apps
diff options
context:
space:
mode:
Diffstat (limited to 'src/apps')
-rw-r--r--src/apps/c_apps/c_main.c130
-rw-r--r--src/apps/c_apps/meson.build8
-rw-r--r--src/apps/meson.build2
3 files changed, 140 insertions, 0 deletions
diff --git a/src/apps/c_apps/c_main.c b/src/apps/c_apps/c_main.c
new file mode 100644
index 00000000..a44c3d50
--- /dev/null
+++ b/src/apps/c_apps/c_main.c
@@ -0,0 +1,130 @@
+#include "camera_c.h"
+#include "camera_manager_c.h"
+#include "request_c.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+[[maybe_unused]]
+static void list_camera_cbk(camera_t camera)
+{
+ printf("Camera name: %s\n", camera_id(camera));
+}
+
+static void managed_camera_cleanup(managed_camera_t **cameras)
+{
+ if (!*cameras)
+ return;
+
+ camera_manager_camera_list_drop(*cameras, 2);
+ free(*cameras);
+}
+
+int main([[maybe_unused]] int argc, [[maybe_unused]] char *argv[])
+{
+ camera_manager_t *mngr = camera_manager_create();
+ camera_manager_start(mngr);
+
+ printf(" === Unwrap the camera list with callbacks === \n");
+
+ /*
+ * Inspect the camera list with callbacks.
+
+ * No memory transfer, the callback has access to members one by one
+ */
+ camera_manager_list_cameras_with_cbk(mngr, list_camera_cbk);
+ printf("\n");
+
+ printf(" === View the camera list memory (doesn't work) === \n");
+ /*
+ * View the libcamera::CameraManager::cameras() memory.
+ *
+ * This doesn't work and segfaults as CameraManager::cameras() return a new vector instance
+ * instead of refrencing to its owned copy.
+ */
+ {
+ const managed_camera_t *cameras;
+ size_t num_cameras = camera_manager_list_cameras_view(mngr,
+ &cameras);
+
+ for (size_t i = 0; i < num_cameras; ++i) {
+ printf("Camera name: %s\n", " nope.. ");//shared_ptr_camera_id(cameras[i]));
+ }
+ }
+ printf("\n");
+
+ printf(" === Get a list of cameras increasing the ref count (grab) === \n");
+ /*
+ * Borrow the shared_ptr into memory owned by application and increase the reference count
+ *
+ * We need to explicitly drop references and release memory
+ */
+ char camera_name[100];
+ {
+ size_t num_cameras = camera_manager_num_cameras(mngr);
+
+ __attribute__((cleanup(managed_camera_cleanup)))
+ managed_camera_t *cameras = (managed_camera_t *)calloc(num_cameras,
+ sizeof(*cameras));
+
+ camera_manager_camera_list_grab(mngr, cameras);
+
+ for (size_t i = 0; i < num_cameras; ++i) {
+ printf("Camera name: %s\n", shared_ptr_camera_id(&cameras[i]));
+ }
+
+ const char *name = shared_ptr_camera_id(&cameras[0]);
+ memcpy(camera_name, name, strlen(name));
+ }
+ printf("\n");
+
+ printf(" === Get a list of raw camera references (borrow) === \n");
+ /*
+ * Copy the raw Camera pointers in application's memory.
+ *
+ * No reference handling needed, but memory has to be released
+ */
+ {
+ size_t num_cameras = camera_manager_num_cameras(mngr);
+ camera_t *cameras = (camera_t *)calloc(num_cameras,
+ sizeof(*cameras));
+
+ camera_manager_camera_list_borrow(mngr, cameras);
+ for (size_t i = 0; i < num_cameras; ++i) {
+ printf("Camera name: %s\n", camera_id(cameras[i]));
+ }
+
+ free(cameras);
+
+ }
+
+ managed_camera_t camera = {};
+ printf("Camera name: %s\n", camera_name);
+ camera_manager_get_camera(mngr, camera_name, &camera);
+
+ camera_configuration_t config = {};
+ enum stream_roles roles[] = { VIEWFINDER };
+ camera_generate_configuration(&camera, roles, 1, &config);
+
+ camera_acquire(&camera);
+ camera_configure(&camera, &config);
+
+ request_t requests[8] = {};
+
+ for (size_t i = 0; i < 8; ++i) {
+ camera_create_request(&camera, &requests[i]);
+ }
+
+ /* Cleanup */
+ for (size_t i = 0; i < 8; ++i)
+ request_drop(&requests[i]);
+ camera_drop_configuration(&config);
+ camera_release(&camera);
+ camera_put(&camera);
+
+ camera_manager_stop(mngr);
+ camera_manager_delete(mngr);
+
+ return 0;
+} \ No newline at end of file
diff --git a/src/apps/c_apps/meson.build b/src/apps/c_apps/meson.build
new file mode 100644
index 00000000..c5b0b3b9
--- /dev/null
+++ b/src/apps/c_apps/meson.build
@@ -0,0 +1,8 @@
+
+c_cam_sources = files([
+ 'c_main.c',
+])
+
+c_cam = executable('c_cam', c_cam_sources,
+ link_with : libcamera_c_abi,
+ dependencies : libcamera_c)
diff --git a/src/apps/meson.build b/src/apps/meson.build
index af632b9a..4b0b1598 100644
--- a/src/apps/meson.build
+++ b/src/apps/meson.build
@@ -12,6 +12,8 @@ endif
libtiff = dependency('libtiff-4', required : false)
+subdir('c_apps')
+
subdir('common')
subdir('lc-compliance')