diff --git a/samples/subsys/video/tcpserversink/README.rst b/samples/subsys/video/tcpserversink/README.rst index 6c7fc89afde4..83e9a62d9534 100644 --- a/samples/subsys/video/tcpserversink/README.rst +++ b/samples/subsys/video/tcpserversink/README.rst @@ -29,11 +29,13 @@ interface. Ethernet cable must be connected to RJ45 connector. Building and Running ******************** -For :ref:`mimxrt1064_evk`, build this sample application with the following commands: +For :ref:`mimxrt1064_evk`, the sample can be built with the following command. +If a mt9m114 camera shield is missing, video software generator will be used instead. .. zephyr-app-commands:: :zephyr-app: samples/subsys/video/tcpserversink :board: mimxrt1064_evk + :shield: [dvp_fpc24_mt9m114] :goals: build :compact: @@ -42,7 +44,7 @@ Sample Output .. code-block:: console - Video device detected, format: RGBP 640x480 + Video device detected, format: RGBP 480x272 TCP: Waiting for client... Then from a peer on the same network you can connect and grab frames. @@ -52,11 +54,12 @@ Example with gstreamer: .. code-block:: console gst-launch-1.0 tcpclientsrc host=192.0.2.1 port=5000 \ - ! videoparse format=rgb16 width=640 height=480 \ + ! videoparse format=rgb16 width=480 height=272 \ ! queue \ ! videoconvert \ ! fpsdisplaysink sync=false +For video software generator, the default resolution should be width=320 and height=160. References ********** diff --git a/samples/subsys/video/tcpserversink/sample.yaml b/samples/subsys/video/tcpserversink/sample.yaml index 6019ce0341ed..717923a6fa19 100644 --- a/samples/subsys/video/tcpserversink/sample.yaml +++ b/samples/subsys/video/tcpserversink/sample.yaml @@ -7,9 +7,12 @@ tests: - video - net - socket + - shield platform_allow: mimxrt1064_evk depends_on: - video - netif integration_platforms: - mimxrt1064_evk + extra_args: + - platform:mimxrt1064_evk:SHIELD=dvp_fpc24_mt9m114 diff --git a/samples/subsys/video/tcpserversink/src/main.c b/samples/subsys/video/tcpserversink/src/main.c index 3b4cf3ba223a..90946be44bd8 100644 --- a/samples/subsys/video/tcpserversink/src/main.c +++ b/samples/subsys/video/tcpserversink/src/main.c @@ -15,7 +15,8 @@ #include LOG_MODULE_REGISTER(main); -#define MY_PORT 5000 +#define VIDEO_DEV_SW "VIDEO_SW_GENERATOR" +#define MY_PORT 5000 #define MAX_CLIENT_QUEUE 1 static ssize_t sendall(int sock, const void *buf, size_t len) @@ -40,8 +41,21 @@ int main(void) struct video_buffer *buffers[2], *vbuf; int i, ret, sock, client; struct video_format fmt; - const struct device *const video = DEVICE_DT_GET_ANY(nxp_imx_csi); +#if DT_HAS_CHOSEN(zephyr_camera) + const struct device *const video = DEVICE_DT_GET(DT_CHOSEN(zephyr_camera)); + if (!device_is_ready(video)) { + LOG_ERR("%s: video device not ready.", video->name); + return 0; + } +#else + const struct device *const video = device_get_binding(VIDEO_DEV_SW); + + if (video == NULL) { + LOG_ERR("%s: video device not found or failed to initialized.", VIDEO_DEV_SW); + return 0; + } +#endif /* Prepare Network */ (void)memset(&addr, 0, sizeof(addr)); addr.sin_family = AF_INET; @@ -67,21 +81,15 @@ int main(void) return 0; } - if (!device_is_ready(video)) { - LOG_ERR("%s: device not ready.\n", video->name); - return 0; - } - /* Get default/native format */ if (video_get_format(video, VIDEO_EP_OUT, &fmt)) { LOG_ERR("Unable to retrieve video format"); return 0; } - printk("Video device detected, format: %c%c%c%c %ux%u\n", - (char)fmt.pixelformat, (char)(fmt.pixelformat >> 8), - (char)(fmt.pixelformat >> 16), (char)(fmt.pixelformat >> 24), - fmt.width, fmt.height); + printk("Video device detected, format: %c%c%c%c %ux%u\n", (char)fmt.pixelformat, + (char)(fmt.pixelformat >> 8), (char)(fmt.pixelformat >> 16), + (char)(fmt.pixelformat >> 24), fmt.width, fmt.height); /* Alloc Buffers */ for (i = 0; i < ARRAY_SIZE(buffers); i++) { @@ -96,8 +104,7 @@ int main(void) do { printk("TCP: Waiting for client...\n"); - client = accept(sock, (struct sockaddr *)&client_addr, - &client_addr_len); + client = accept(sock, (struct sockaddr *)&client_addr, &client_addr_len); if (client < 0) { printk("Failed to accept: %d\n", errno); return 0; @@ -121,14 +128,13 @@ int main(void) /* Capture loop */ i = 0; do { - ret = video_dequeue(video, VIDEO_EP_OUT, &vbuf, - K_FOREVER); + ret = video_dequeue(video, VIDEO_EP_OUT, &vbuf, K_FOREVER); if (ret) { LOG_ERR("Unable to dequeue video buf"); return 0; } - printk("\rSending frame %d", i++); + printk("\rSending frame %d\n", i++); /* Send video buffer to TCP client */ ret = sendall(client, vbuf->buffer, vbuf->bytesused); @@ -149,8 +155,7 @@ int main(void) /* Flush remaining buffers */ do { - ret = video_dequeue(video, VIDEO_EP_OUT, - &vbuf, K_NO_WAIT); + ret = video_dequeue(video, VIDEO_EP_OUT, &vbuf, K_NO_WAIT); } while (!ret); } while (1);