|
| 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. |
0 commit comments