main: Allow to pass different devices and height/width 10/29110/1
authorMarius Vlad <marius.vlad@collabora.com>
Wed, 9 Aug 2023 09:58:17 +0000 (12:58 +0300)
committerMarius Vlad <marius.vlad@collabora.com>
Wed, 9 Aug 2023 11:04:45 +0000 (14:04 +0300)
Bug-AGL: SPEC-4877
Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
Change-Id: Ic35267e93a95589be6af0b3d2e0bb9839303b519

README.md
app/main.cpp

index a7f64b7..bb1db89 100644 (file)
--- a/README.md
+++ b/README.md
@@ -3,3 +3,5 @@ camera-gstreamer
 
 Assumes that /dev/video0 is present and is set as a capture device.  Use
 DEFAULT_V4L2_DEVICE environmental variable to change it.
+DEFAULT_V4L2_DEVICE_WIDTH and DEFAULT_V4L2_DEVICE_HEIGHT to specify the
+dimensions.
index 1acb70f..d4c0671 100644 (file)
@@ -652,6 +652,12 @@ int main(int argc, char *argv[])
        struct receiver_data receiver_data = {};
        struct display *display;
        struct window *window;
+       const char *camera_device = NULL;
+       const char *width_str = NULL;
+       const char *height_str = NULL;
+       int width;
+       int height;
+
        char pipeline_str[1024];
        GError *error = NULL;
        const char *app_id = "camera-gstreamer";
@@ -667,9 +673,24 @@ int main(int argc, char *argv[])
        gargv[0] = strdup(argv[0]);
        gargv[1] = strdup("--gst-debug-level=2");
 
+       camera_device = getenv("DEFAULT_V4L2_DEVICE");
+       if (!camera_device)
+               camera_device = get_first_camera_device();
+       width_str = getenv("DEFAULT_V4L2_DEVICE_WIDTH");
+       if (!width_str)
+               width = WINDOW_WIDTH_SIZE;
+       else
+               width = atoi(width_str);
+
+       height_str = getenv("DEFAULT_V4L2_DEVICE_HEIGHT");
+       if (!height_str)
+               height = WINDOW_HEIGHT_SIZE;
+       else
+               height = atoi(height_str);
+
        memset(pipeline_str, 0, sizeof(pipeline_str));
        snprintf(pipeline_str, sizeof(pipeline_str), "v4l2src device=%s ! video/x-raw,width=%d,height=%d ! waylandsink", 
-               get_first_camera_device(), WINDOW_WIDTH_SIZE, WINDOW_HEIGHT_SIZE);
+               camera_device, width, height);
        gst_init(&gargc, &gargv);
 
        setbuf(stdout, NULL);