Skip to content

Update tcpserversink sample #73665

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions samples/subsys/video/tcpserversink/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand All @@ -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.
Expand All @@ -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
**********
Expand Down
3 changes: 3 additions & 0 deletions samples/subsys/video/tcpserversink/sample.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
41 changes: 23 additions & 18 deletions samples/subsys/video/tcpserversink/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
#include <zephyr/logging/log.h>
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)
Expand All @@ -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;
Expand All @@ -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++) {
Expand All @@ -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;
Expand All @@ -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);
Expand All @@ -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);
Expand Down
Loading