Skip to content

Commit d19841d

Browse files
committed
Merge branch 'feature/add_media_lib_sal_component' into 'master'
feat(media_lib_sal): Add media_lib_sal component See merge request adf/esp-adf-libs!297
2 parents 692ae7d + 73d5198 commit d19841d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+1305
-1318
lines changed

.github/workflows/upload_component.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,6 @@ jobs:
2525
esp_libsrtp;
2626
esp_image_effects;
2727
esp_media_protocols;
28+
media_lib_sal;
2829
namespace: "espressif"
2930
api_token: ${{ secrets.IDF_COMPONENT_API_TOKEN }}

media_lib_sal/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Changelog
2+
3+
## v0.9.0
4+
5+
- Initial version of `media_lib_sal`

media_lib_sal/CMakeLists.txt

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,7 @@ set(COMPONENT_ADD_INCLUDEDIRS include include/port)
44

55
# Edit following two lines to set component requirements (see docs)
66

7-
set(COMPONENT_SRCS ./media_lib_common.c
8-
./media_lib_os.c ./port/media_lib_os_freertos.c
9-
./media_lib_adapter.c)
10-
11-
if (CONFIG_MEDIA_PROTOCOL_LIB_ENABLE)
12-
set(COMPONENT_REQUIRES mbedtls esp-tls)
13-
list(APPEND COMPONENT_SRCS ./media_lib_socket.c ./port/media_lib_socket_default.c
14-
./media_lib_crypt.c ./port/media_lib_crypt_default.c
15-
./media_lib_tls.c ./port/media_lib_tls_default.c
16-
./media_lib_netif.c ./port/media_lib_netif_default.c)
17-
if (idf_version VERSION_GREATER_EQUAL "5.0")
18-
list(APPEND COMPONENT_REQUIRES esp-tls mbedtls)
19-
endif()
20-
endif()
7+
list (APPEND COMPONENT_SRCDIRS ./ ./port ./mem_trace)
218

229
list(APPEND COMPONENT_REQUIRES esp-tls mbedtls esp_netif)
2310

media_lib_sal/Kconfig

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
menu "Media Library System Abstraction Layer Configuration"
2+
3+
config MEDIA_LIB_CRYPT_ENABLE
4+
bool "Enable media lib sal crypt library"
5+
default "y"
6+
7+
config MEDIA_LIB_SOCKET_ENABLE
8+
bool "Enable media lib sal socket library"
9+
default "y"
10+
11+
config MEDIA_LIB_TLS_ENABLE
12+
bool "Enable media lib sal tls library"
13+
default "y"
14+
15+
config MEDIA_LIB_NETIF_ENABLE
16+
bool "Enable media lib sal netif library"
17+
default "y"
18+
19+
config MEDIA_LIB_MEM_AUTO_TRACE
20+
bool "Support trace memory automatically after media_lib_sal init"
21+
default "n"
22+
23+
config MEDIA_LIB_MEM_TRACE_DEPTH
24+
int
25+
prompt "Memory trace stack depth" if MEDIA_LIB_MEM_AUTO_TRACE
26+
depends on MEDIA_LIB_MEM_AUTO_TRACE
27+
default 3
28+
help
29+
Set memory trace depth
30+
31+
config MEDIA_LIB_MEM_TRACE_NUM
32+
int
33+
prompt "Memory trace number" if MEDIA_LIB_MEM_AUTO_TRACE
34+
depends on MEDIA_LIB_MEM_AUTO_TRACE
35+
default 1024
36+
help
37+
Set memory trace number
38+
39+
config MEDIA_LIB_MEM_TRACE_MODULE
40+
bool "Trace for module memory usage"
41+
depends on MEDIA_LIB_MEM_AUTO_TRACE
42+
default y
43+
44+
config MEDIA_LIB_MEM_TRACE_LEAKAGE
45+
depends on MEDIA_LIB_MEM_AUTO_TRACE
46+
bool "Trace for memory leakage"
47+
default y
48+
49+
config MEDIA_LIB_MEM_TRACE_SAVE_HISTORY
50+
bool "Trace to save memory history"
51+
depends on MEDIA_LIB_MEM_AUTO_TRACE
52+
default n
53+
54+
config MEDIA_LIB_MEM_SAVE_CACHE_SIZE
55+
int
56+
prompt "Cache buffer size to store save history" if MEDIA_LIB_MEM_TRACE_SAVE_HISTORY
57+
depends on MEDIA_LIB_MEM_TRACE_SAVE_HISTORY
58+
default 32768
59+
help
60+
Set cache size for memory history
61+
62+
config MEDIA_LIB_MEM_TRACE_SAVE_PATH
63+
string "Memory trace save path" if MEDIA_LIB_MEM_TRACE_SAVE_HISTORY
64+
depends on MEDIA_LIB_MEM_TRACE_SAVE_HISTORY
65+
default "/sdcard/trace.log"
66+
help
67+
Set memory trace save path
68+
69+
endmenu

media_lib_sal/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

media_lib_sal/README.md

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
# MEDIA_LIB_SAL (Media Library System Abstraction Layer)
2+
3+
## Overview
4+
5+
The `media_lib_sal` provides a cross-platform abstraction for media libraries and applications.
6+
It enables developers to build media applications in a platform-independent way and even debug on a PC without changing application logic.
7+
8+
The `media_lib_sal` offers a unified interface to interact with:
9+
- Operating system primitives (threads, memory, sync objects)
10+
- Cryptographic operations (MD5, SHA256, AES)
11+
- Networking (sockets, netif)
12+
- TLS/SSL for secure communication
13+
14+
Through its registration mechanism, platform-specific implementations can be plugged in, while applications always use the same wrapper APIs.
15+
16+
## Architecture
17+
18+
The `media_lib_sal` follows a two-layer architecture:
19+
20+
1. **Wrapper Layer** – Public APIs that applications call
21+
2. **Registration Layer** – Interfaces to bind platform-specific implementations
22+
23+
Applications only see the wrapper layer, while hardware or OS vendors provide implementations via the registration layer.
24+
25+
### Architecture Diagram
26+
27+
```mermaid
28+
flowchart TB
29+
subgraph Application_Layer["Application Layer"]
30+
APP["Media Applications"]
31+
end
32+
subgraph SAL["System Abstraction Layer"]
33+
W["Wrapper Layer<br/>(media_lib_xxx.h)"]
34+
R["Registration Layer<br/>(media_lib_adapter.h)"]
35+
end
36+
subgraph Platform["Platform Implementations"]
37+
OS["OS Functions"]
38+
CRYPT["Crypto Functions"]
39+
SOCK["Socket Functions"]
40+
TLS["TLS Functions"]
41+
NETIF["Netif Functions"]
42+
end
43+
APP --> W
44+
W --> R
45+
R --> OS & CRYPT & SOCK & TLS & NETIF
46+
```
47+
48+
## Core Components
49+
50+
### 1. Operating System Abstraction (`media_lib_os.h`)
51+
52+
Cross-platform access to OS services:
53+
- Memory management (`malloc`, `calloc`, `realloc`, `free`)
54+
- Thread management (`create`, `destroy`, `sleep`)
55+
- Synchronization primitives (mutex, semaphore, event groups)
56+
57+
### 2. Cryptography (`media_lib_crypt.h`)
58+
59+
Standard crypto wrappers:
60+
- **MD5** – init, update, finish
61+
- **SHA256** – init, update, finish
62+
- **AES** – key setup, CBC encrypt/decrypt
63+
64+
### 3. Socket API (`media_lib_socket.h`)
65+
66+
Unified networking interface:
67+
- **Connection management** – open, bind, connect, listen, accept
68+
- **Data transfer** – send/recv, sendto/recvfrom
69+
- **Socket control** – select, setsockopt, getsockopt
70+
71+
### 4. TLS/SSL (`media_lib_tls.h`)
72+
73+
Abstraction for secure communication:
74+
- Create client/server TLS sessions
75+
- Read/Write encrypted data
76+
- Session management (delete/cleanup)
77+
78+
### 5. Network Interface (`media_lib_netif.h`)
79+
80+
Query and utility functions:
81+
- Get IPv4 information
82+
- Address conversion (`ntoa`)
83+
84+
## Utilities
85+
86+
### Memory Tracing (`media_lib_mem_trace.h`)
87+
88+
Advanced debugging utilities:
89+
- Track memory usage by module
90+
- Detect leaks with stack traces
91+
- Allocation history logging
92+
93+
## Registration Interface (Port Layer)
94+
95+
Platform-specific functions are registered via adapters:
96+
97+
- `media_lib_add_default_adapter()` – Register all defaults
98+
- `media_lib_os_register(...)` – Register custom OS functions
99+
- `media_lib_crypt_register(...)` – Register custom crypto functions
100+
- `media_lib_socket_register(...)` – Register custom socket functions
101+
- `media_lib_tls_register(...)` – Register custom TLS functions
102+
- `media_lib_netif_register(...)` – Register custom netif functions
103+
104+
Users can manually register each component or register all and select the used one by menuconfig, this allows flexible default or custom implementation selection.
105+
106+
## Platform Support
107+
108+
- **ESP32 family (primary target)**
109+
- Easily portable to other platforms by providing new registration functions.
110+
111+
## License
112+
113+
This component is licensed under the Modified MIT License - see the [LICENSE](./LICENSE) file for details.

media_lib_sal/component.mk

Lines changed: 0 additions & 8 deletions
This file was deleted.

media_lib_sal/idf_component.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
version: 0.9.0
2+
description: Media Library System Abstract layer
3+
url: https://github.com/espressif/esp-adf-libs/tree/master/media_lib_sal
4+
repository: https://github.com/espressif/esp-adf-libs.git
5+
issues: https://github.com/espressif/esp-adf/issues
6+
7+
dependencies:
8+
idf:
9+
version: '>=5.1'
10+
11+
tags:
12+
- Multimedia
13+
- OSLibrary
14+
- System
15+
- Network

0 commit comments

Comments
 (0)