Skip to content

Commit eabbe06

Browse files
committed
samples: subsys: Add libMP video examples
Add video examples for libMP which includes two pipelines: - camera source and display sink - camera source, video transform and display sink Signed-off-by: Phi Bang Nguyen <[email protected]> Signed-off-by: Trung Hieu Le <[email protected]>
1 parent 3a92b4d commit eabbe06

File tree

11 files changed

+430
-0
lines changed

11 files changed

+430
-0
lines changed

samples/subsys/libmp/libmp.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.. zephyr:code-sample-category:: LibMP
2+
:name: LibMP
3+
:show-listing:
4+
:glob: **/*
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CMAKE_MINIMUM_REQUIRED (VERSION 3.20.0)
2+
3+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
4+
5+
project(video_example)
6+
7+
target_sources(app PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/camera_display.c)
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
.. zephyr:code-sample:: libmp_camera_display
2+
:name: Camera Display Example
3+
4+
A sample pipeline composed of 3 elements: a camera source, a capsfilter and a display sink.
5+
6+
Description
7+
***********
8+
9+
::
10+
11+
+-----------------+ +--------------+ +----------------+
12+
| Camera Source | --> | Capsfilter | --> | Display Sink |
13+
+-----------------+ +--------------+ +----------------+
14+
15+
This example demonstrates a pipeline consisting of 3 elements. The camera source element generates
16+
video frames. The capsfilter is used to enforce a video format and/or resolution and/or framerate.
17+
This element is optional, without it, the pipeline is still working but with the default negotiated
18+
format. The display sink then renders the video frames on the screen.
19+
20+
Requirements
21+
************
22+
23+
* A board with input camera support
24+
* A board with output display support
25+
* Sufficient RAM for video buffering
26+
27+
This sample has been tested on the following boards:
28+
29+
- :zephyr:board:`native_sim`
30+
31+
- :zephyr:board:`mimxrt1170_evk`
32+
33+
Building and Running
34+
********************
35+
36+
For :zephyr:board:`native_sim`, build the sample with the following command:
37+
38+
.. zephyr-app-commands::
39+
:zephyr-app: samples/subsys/libmp/video_examples/camera_display
40+
:board: native_sim/native/64
41+
:goals: build
42+
:snippets: video-sw-generator
43+
:compact:
44+
45+
For :zephyr:board:`mimxrt1170_evk`, build the sample with the following command:
46+
47+
.. zephyr-app-commands::
48+
:zephyr-app: samples/subsys/libmp/video_examples/camera_display
49+
:board: mimxrt1170_evk@B/mimxrt1176/cm7
50+
:shield: nxp_btb44_ov5640,rk055hdmipi4ma0
51+
:goals: build
52+
:compact:
53+
54+
Wiring
55+
******
56+
57+
On :zephyr:board:`native_sim`, no wiring is needed since it uses a software video generator
58+
as source, however for the display output you need to ensure that your host system supports
59+
SDL2 to emulate the display.
60+
61+
62+
On :zephyr:board:`mimxrt1170_evk`, the OV5640 camera module should be plugged into the J2
63+
camera connector, the display module RK055HDMIPI4MA0 should be plugged into the J48 MIPI LCD connector.
64+
An additional USB cable is needed to connect USB debug port (J11) on the board to the host PC.
65+
66+
67+
Sample Output
68+
*************
69+
70+
The application will start the video pipeline and display the camera frames on the screen.
71+
Check for any error messages during initialization:
72+
73+
.. code-block:: console
74+
75+
*** Booting Zephyr OS build ***
76+
[00:00:00.321,000] <inf> mp_zdisp_sink: Display device: display-controller@40804000
77+
[00:00:00.373,000] <inf> mp_zvid_buffer_pool: Started streaming
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CONFIG_VIDEO_BUFFER_POOL_SZ_MAX=3686800
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
/*
2+
* Copyright 2025 NXP
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <zephyr/drivers/video-controls.h>
8+
#include <zephyr/kernel.h>
9+
#include <zephyr/logging/log.h>
10+
11+
#include <mp.h>
12+
13+
LOG_MODULE_REGISTER(main);
14+
15+
#define LOG_LEVEL LOG_LEVEL_DBG
16+
17+
int main(void)
18+
{
19+
int ret;
20+
21+
/* Create elements */
22+
struct mp_element *source = mp_element_factory_create("zvid_src", "camsrc");
23+
24+
if (source == NULL) {
25+
goto err;
26+
}
27+
28+
struct mp_element *caps_filter = mp_element_factory_create("capsfilter", "capsfilter");
29+
30+
if (caps_filter == NULL) {
31+
goto err;
32+
}
33+
34+
struct mp_element *sink = mp_element_factory_create("zdisp_sink", "dispsink");
35+
36+
if (sink == NULL) {
37+
goto err;
38+
}
39+
40+
/* Set elements' properties */
41+
ret = mp_object_set_properties(MP_OBJECT(source), PROP_NUM_BUFS, 3, VIDEO_CID_HFLIP, 1,
42+
PROP_LIST_END);
43+
if (ret < 0) {
44+
goto err;
45+
}
46+
47+
struct mp_caps *filtered_caps =
48+
mp_caps_new("video/x-raw", "width", MP_TYPE_UINT, 320, "height", MP_TYPE_UINT, 240,
49+
"framerate", MP_TYPE_UINT_FRACTION, 30, 1, NULL);
50+
51+
if (filtered_caps == NULL) {
52+
goto err;
53+
}
54+
55+
ret = mp_object_set_properties(MP_OBJECT(caps_filter), PROP_CAPS, filtered_caps,
56+
PROP_LIST_END);
57+
mp_caps_unref(filtered_caps);
58+
if (ret < 0) {
59+
goto err;
60+
}
61+
62+
/* Create a new pipeline */
63+
struct mp_element *pipeline = mp_pipeline_new("cam_disp");
64+
65+
if (pipeline == NULL) {
66+
goto err;
67+
}
68+
69+
/* Add elements to the pipeline - order does not matter */
70+
if (mp_bin_add(MP_BIN(pipeline), source, caps_filter, sink, NULL) == false) {
71+
LOG_ERR("Failed to add elements");
72+
goto err;
73+
}
74+
75+
/* Link elements together - order does matter */
76+
if (mp_element_link(source, caps_filter, sink, NULL) == false) {
77+
LOG_ERR("Failed to link elements");
78+
goto err;
79+
}
80+
81+
/* Start playing */
82+
if (mp_element_set_state(pipeline, MP_STATE_PLAYING) != MP_STATE_CHANGE_SUCCESS) {
83+
LOG_ERR("Failed to start pipeline");
84+
goto err;
85+
}
86+
87+
/* Handle message from the pipeline */
88+
struct mp_bus *bus = mp_element_get_bus(pipeline);
89+
/* Wait until an Error or an EOS - blocking */
90+
struct mp_message *msg = mp_bus_pop_msg(bus, MP_MESSAGE_ERROR | MP_MESSAGE_EOS);
91+
92+
if (msg != NULL) {
93+
switch (MP_MESSAGE_TYPE(msg)) {
94+
case MP_MESSAGE_ERROR:
95+
LOG_INF("Received ERROR from %s", msg->src->name);
96+
break;
97+
case MP_MESSAGE_EOS:
98+
LOG_INF("Received EOS from %s", msg->src->name);
99+
break;
100+
default:
101+
LOG_ERR("Unexpected message received from %s", msg->src->name);
102+
break;
103+
}
104+
}
105+
106+
/* TODO: Stop pipeline and free allocated resources */
107+
108+
return 0;
109+
110+
err:
111+
LOG_ERR("Aborting sample");
112+
return 0;
113+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
CONFIG_LOG=y
2+
3+
CONFIG_MP=y
4+
CONFIG_MP_CAPSFILTER=y
5+
CONFIG_MP_PLUGIN_ZVID=y
6+
CONFIG_MP_PLUGIN_ZDISP=y
7+
8+
CONFIG_VIDEO=y
9+
CONFIG_DISPLAY=y
10+
11+
CONFIG_SHELL=y
12+
CONFIG_DEVICE_SHELL=y
13+
14+
CONFIG_HEAP_MEM_POOL_SIZE=10000
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CMAKE_MINIMUM_REQUIRED (VERSION 3.20.0)
2+
3+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
4+
5+
project(video_example)
6+
7+
target_sources(app PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/camera_transform_display.c)
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
.. zephyr:code-sample:: libmp_camera_transform_display
2+
:name: Camera Transform Display Example
3+
4+
A sample pipeline composed of 4 elements: a camera source, a capsfilter,
5+
a video transform and a display sink.
6+
7+
Description
8+
***********
9+
10+
::
11+
12+
+-----------------+ +--------------+ +-------------------+ +----------------+
13+
| Camera Source | --> | Capsfilter | --> | Video Transform | --> | Display Sink |
14+
+-----------------+ +--------------+ +-------------------+ +----------------+
15+
16+
This example demonstrates a pipeline consisting of 4 elements. The camera source element generates
17+
video frames. The capsfilter is used to enforce a video format and/or resolution and/or framerate.
18+
This element is optional, without it, the pipeline is still working but with the default negotiated
19+
format. The video transformer then processes the video frames and forwards them to the display sink
20+
to render them on the screen.
21+
22+
Requirements
23+
************
24+
25+
* A board with input camera support
26+
* A board with output display support
27+
* Sufficient RAM for video buffering
28+
29+
This sample has been tested on the following boards:
30+
31+
- :zephyr:board:`mimxrt1170_evk`
32+
33+
Building and Running
34+
********************
35+
36+
For :zephyr:board:`mimxrt1170_evk`, build this sample application with the following commands:
37+
38+
.. zephyr-app-commands::
39+
:zephyr-app: samples/subsys/libmp/video_examples/camera_transform_display
40+
:board: mimxrt1170_evk@B/mimxrt1176/cm7
41+
:shield: nxp_btb44_ov5640,rk055hdmipi4ma0
42+
:goals: build flash
43+
:compact:
44+
45+
Wiring
46+
******
47+
On :zephyr:board:`mimxrt1170_evk`, the OV5640 camera module should be plugged into the J2
48+
camera connector, the display module RK055HDMIPI4MA0 should be plugged into the J48 MIPI LCD connector.
49+
An additional USB cable is needed to connect USB debug port (J11) on the board to the host PC.
50+
51+
52+
Sample Output
53+
*************
54+
55+
.. code-block:: console
56+
57+
*** Booting Zephyr OS build ***
58+
[00:00:00.321,000] <inf> mp_zdisp_sink: Display device: display-controller@40804000
59+
[00:00:00.373,000] <inf> mp_zvid_buffer_pool: Started streaming
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
CONFIG_VIDEO_BUFFER_POOL_SZ_MAX=3686800
2+
CONFIG_VIDEO_BUFFER_POOL_NUM_MAX=3

0 commit comments

Comments
 (0)