Skip to content

Commit 65d1342

Browse files
committed
Refine code to make av_render media_lib_sal as component
2 parents 527a6ca + 20dea70 commit 65d1342

36 files changed

+980
-91
lines changed

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44

55
This repository provides everything needed to build a WebRTC application.
66
It includes the `esp_webrtc` core code along with its dependent components, such as:
7-
- **`esp_capture`**: For capturing media data
7+
- **`esp_peer`**: WebRTC PeerConnection realization
8+
- **`esp_capture`**: For capturing media data (moved to [esp_capture](https://components.espressif.com/components/espressif/esp_capture/))
89
- **`av_render`**: For playing media data
910

10-
Additionally, the repository contains three several demo applications that demonstrate how to use `esp_webrtc`.
11+
Additionally, the repository contains several demo applications that demonstrate how to use `esp_webrtc`.
1112

1213
## Solutions
1314

@@ -31,4 +32,6 @@ This demo show how to use `esp_webrtc` to publish streaming data to WHIP server.
3132

3233
### 6. Doorbell Local Demo
3334
This demo sets up a local doorbell application that operates without external signaling servers.
34-
An ESP32 series board acts as the signaling server, allowing users to connect directly for WebRTC testing.
35+
An ESP32 series board acts as the signaling server, allowing users to connect directly for WebRTC testing.
36+
Meanwhile provide AI pedestrian detect capability in realtime.
37+

components/av_render/CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Changelog
2+
3+
## v0.9.1
4+
5+
- Fixed dependency missing
6+
- Added example code
7+
8+
## v0.9.0
9+
10+
- Initial version of `av_render`
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11

2-
list (APPEND COMPONENT_SRCDIRS ./src)
2+
list (APPEND COMPONENT_SRCDIRS ./src ./render_impl)
33

44
set(COMPONENT_ADD_INCLUDEDIRS ./include)
55

6-
set(COMPONENT_PRIV_REQUIRES media_lib_sal esp_timer esp_audio_codec esp_video_codec)
6+
set(COMPONENT_PRIV_REQUIRES esp_timer esp_lcd driver)
77

88
register_component()
99

1010
# Add color convert ASM optimized lib
11-
IF (${IDF_TARGET} STREQUAL "esp32p4")
11+
IF (${IDF_TARGET} STREQUAL "esp32p4")
1212
set(TARGET_LIB_NAME "${CMAKE_CURRENT_SOURCE_DIR}/libs/${IDF_TARGET}/libesp_image_i420_2_rgb565le.a")
1313
target_link_libraries(${COMPONENT_TARGET} "-Wl,--start-group" ${TARGET_LIB_NAME} "-Wl,--end-group")
1414
ENDIF ()

components/av_render/LICENSE

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Espressif Modified MIT License
2+
3+
Copyright (c) 2025 Espressif Systems (Shanghai) CO., LTD
4+
5+
Permission is hereby granted for use EXCLUSIVELY with Espressif Systems products.
6+
This includes the right to use, copy, modify, merge, publish, distribute, and sublicense
7+
the Software, subject to the following conditions:
8+
9+
1. This Software MUST BE USED IN CONJUNCTION WITH ESPRESSIF SYSTEMS PRODUCTS.
10+
2. The above copyright notice and this permission notice shall be included in all copies
11+
or substantial portions of the Software.
12+
3. Redistribution of the Software in source or binary form FOR USE WITH NON-ESPRESSIF PRODUCTS
13+
is strictly prohibited.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
16+
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
17+
PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
18+
FOR ANY CLAIM, DAMAGES, OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19+
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20+
DEALINGS IN THE SOFTWARE.
21+
22+
SPDX-License-Identifier: LicenseRef-Espressif-Modified-MIT

components/av_render/README.md

Lines changed: 135 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,151 @@
11
# AV_Render
22

3-
`AV_Render` is a simple player designed for video and audio playback. It primarily supports "push" playback model, where the user first provides stream information and then pushes the stream data to `av_render`. The player checks the input stream's codec and uses appropriate audio and video decoders for processing. The decoded output frame data is sent to the corresponding renderer for final output (e.g., audio playback via codec, video playback on LCD).
3+
`AV_Render` is a lightweight player designed for **audio and video playback**.
4+
It primarily follows a **push-based playback model**:
45

5-
## Abstraction
6+
- The user provides stream information.
7+
- The user pushes encoded stream data into `av_render`.
8+
- The player selects the appropriate codec and decodes the stream.
9+
- The decoded output is synchronized (if enabled) and then rendered (e.g., audio via I2S, video via LCD).
10+
11+
---
12+
13+
## 🔹 Architecture
14+
15+
`av_render` processes audio and video in **parallel pipelines** with separate decode and render threads.
16+
A synchronization module ensures correct playback alignment based on the selected `sync_mode`.
17+
18+
```mermaid
19+
flowchart TD
20+
A[Audio Data] --> AD[Audio Decoder]
21+
V[Video Data] --> VD[Video Decoder]
22+
AD --> AR[Audio Render]
23+
VD --> VR[Video Render]
24+
AR --> S[Sync]
25+
VR --> S[Sync]
26+
27+
subgraph Audio Decode Thread
28+
AD
29+
end
30+
subgraph Video Decode Thread
31+
VD
32+
end
33+
subgraph Audio Render Thread
34+
AR
35+
end
36+
subgraph Video Render Thread
37+
VR
38+
end
39+
```
40+
- **Decode Thread**: Handles audio and video decoding.
41+
- **Render Thread**: Fetches decoded frames, applies sync control, and renders them.
42+
43+
### Sync Modes
44+
- **None** → Audio and video run independently.
45+
- **Audio** → Video is synced to the audio clock.
46+
- **Time** → Both streams follow system time or timestamps.
47+
48+
---
49+
50+
## 🔹 Abstraction
651

752
### Render Implementations
853

9-
Users can select the appropriate renderer based on their specific use case. We also provide default implementations for common scenarios, such as:
54+
`av_render` provides abstraction for audio and video rendering.
55+
Users can choose from the default implementations or develop their own:
56+
57+
- **Audio Rendering**`av_render_alloc_i2s_render` (outputs audio through I2S)
58+
- **Video Rendering**`av_render_alloc_lcd_render` (renders video through `esp_lcd`)
59+
60+
---
61+
62+
## 🔹 Usage Guide
63+
64+
A typical playback sequence looks like this:
65+
66+
1. `av_render_open`
67+
2. `av_render_add_audio_stream`
68+
3. `av_render_add_video_stream`
69+
4. `av_render_add_audio_data`
70+
5. `av_render_add_video_data`
71+
6. `av_render_close`
72+
73+
### Resetting Playback
74+
To clear the current stream and start fresh, call:
75+
```c
76+
av_render_reset();
77+
```
78+
79+
---
80+
81+
## 🔹 Resource Configuration
82+
83+
`av_render` offers flexible resource management, including:
84+
- Decoder render threading options (if fifo not set no threading)
85+
- Buffer sizes for both audio and video(decode fifo, render fifo etc)
86+
87+
With this design user can achive trade off between resource consume and performance.
88+
Configuration is done via `av_render_cfg_t` or through specific APIs:
89+
90+
- `av_render_config_audio_fifo` — Configure audio buffer size
91+
- `av_render_config_video_fifo` — Configure video buffer size
92+
93+
---
94+
95+
## 🔹 Decoder Registration
96+
97+
Decoding in `av_render` is powered by `esp_audio_codec` and `esp_video_codec`.
98+
Only registered decoders are included, ensuring a smaller final image size.
99+
100+
You can register decoders in two ways:
101+
102+
### 1. Manual Registration
103+
```c
104+
#include "esp_aac_dec.h"
105+
#include "esp_video_dec_h264.h"
106+
107+
esp_aac_dec_register();
108+
esp_video_dec_register_sw_h264();
109+
```
110+
111+
### 2. Register All Defaults (and disable unused ones in `menuconfig`)
112+
```c
113+
#include "esp_audio_dec_default.h"
114+
#include "esp_video_dec_default.h"
115+
116+
esp_audio_dec_register_default();
117+
esp_video_dec_register_default();
118+
```
119+
120+
---
10121

11-
- **Audio Rendering:** `av_render_alloc_i2s_render` — outputs audio through I2S.
12-
- **Video Rendering:** `av_render_alloc_lcd_render` — renders video through `esp_lcd`.
122+
## 🔹 Customization
13123

14-
## Simple Usage
124+
### Custom Decoders
125+
Users may replace existing decoders or add new ones.
126+
See the `esp_audio_codec` and `esp_video_codec` documentation for details.
15127

16-
The overall flow for audio and video playback is as follows:
128+
### Custom Renderers
129+
Both audio and video renderers are abstracted as:
130+
- `audio_render_ops_t`
131+
- `video_render_ops_t`
17132

18-
1. `av_render_open`
19-
2. `av_render_add_audio_stream`
20-
3. `av_render_add_video_stream`
21-
4. `av_render_add_audio_data`
22-
5. `av_render_add_video_data`
23-
6. `av_render_close`
133+
To implement custom renderers, use the existing implementations as references:
134+
- [i2s_render](render_impl/i2s_render.c)
135+
- [lcd_render](render_impl/lcd_render.c)
24136

25-
### Resetting the Playback
137+
---
26138

27-
If you want to clear the current stream and start a new one, call `av_render_reset`.
139+
## 📬 Contact & Support
28140

29-
### Resource usage
141+
This component is part of the [esp-webrtc-solution](https://github.com/espressif/esp-webrtc-solution), which provides:
142+
- Complete WebRTC functionality
143+
- Media handling (`esp_capture`, `av_render`)
144+
- Multiple signaling methods (OpenAI, WHIP, AppRTC, etc.)
145+
- Practical examples for real applications
30146

31-
Users can configure resource usage more precisely to meet their specific needs. This includes options such as whether an additional thread is required for decoding, as well as how much data can be buffered by the decoder and renderer.
147+
🔧 **Bug reports or feature requests?**
148+
Please open an issue here: [esp-webrtc-solution/issues](https://github.com/espressif/esp-webrtc-solution/issues)
32149

33-
To customize these settings, you can use the `av_render_cfg_t` configuration structure or the following API functions:
150+
We’re happy to help!
34151

35-
- `av_render_config_audio_fifo` — Configure the audio buffer size for the decoder and renderer.
36-
- `av_render_config_video_fifo` — Configure the video buffer size for the decoder and renderer.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# The following lines of boilerplate have to be in your project's CMakeLists
2+
# in this exact order for cmake to work correctly
3+
cmake_minimum_required(VERSION 3.5)
4+
5+
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
6+
7+
project(render_test)

0 commit comments

Comments
 (0)