|
1 | 1 | # AV_Render
|
2 | 2 |
|
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**: |
4 | 5 |
|
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 |
6 | 51 |
|
7 | 52 | ### Render Implementations
|
8 | 53 |
|
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 | +--- |
10 | 121 |
|
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 |
13 | 123 |
|
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. |
15 | 127 |
|
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` |
17 | 132 |
|
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) |
24 | 136 |
|
25 |
| -### Resetting the Playback |
| 137 | +--- |
26 | 138 |
|
27 |
| -If you want to clear the current stream and start a new one, call `av_render_reset`. |
| 139 | +## 📬 Contact & Support |
28 | 140 |
|
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 |
30 | 146 |
|
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) |
32 | 149 |
|
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! |
34 | 151 |
|
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. |
|
0 commit comments