12 KiB
RTPhone Platform - Agent Guide
Project Overview
RTPhone is a comprehensive real-time communication (RTC) platform developed by VoIP Objects (Sevana) that provides a complete software stack for building VoIP/SIP-based communication applications. It delivers production-ready voice communication capabilities with extensive codec support and cross-platform compatibility.
The project produces a static library (librtphone.a) that can be integrated into larger telephony and communication systems. It provides a JSON-based command interface for easy integration and control.
Technology Stack
- Language: C++20
- Build System: CMake 3.20+
- License: Mozilla Public License Version 2.0 (see LICENSE_MPL.txt)
- Primary Platforms: Linux (x64, ARM/Raspberry Pi), Windows (32/64-bit), macOS, Android, iOS
Project Structure
/home/anand/works/sevana/platform/rtphone/
├── src/ # Main source code
│ ├── CMakeLists.txt # Main CMake configuration
│ ├── engine/ # Core engine modules
│ │ ├── agent/ # JSON-based command interface
│ │ ├── audio/ # Cross-platform audio I/O handling
│ │ ├── endpoint/ # SIP user agent implementation
│ │ ├── helper/ # Utility functions (networking, logging, threading)
│ │ ├── media/ # Audio codec management and processing
│ │ └── engine_config.h # Compile-time configuration
│ └── libs/ # Third-party libraries
│ ├── resiprocate/ # SIP stack (git submodule)
│ ├── libsrtp/ # SRTP library (git submodule)
│ ├── libraries/ # Prebuilt platform libraries (git submodule)
│ ├── ice/ # ICE (Interactive Connectivity Establishment)
│ ├── jrtplib/ # RTP library
│ ├── opus/ # Opus codec
│ ├── webrtc/ # WebRTC components
│ ├── libg729/ # G.729 codec
│ ├── libgsm/ # GSM codec
│ ├── gsmhr/ # GSM HR codec
│ ├── g722/ # G.722 codec
│ ├── speexdsp/ # Speex DSP
│ ├── libevs/ # EVS codec (optional)
│ ├── opencore-amr/ # AMR codec (optional)
│ ├── oboe/ # Android low-latency audio
│ └── fmt/ # Format library
├── build_linux.py # Linux build script
├── build_android.py # Android build script
├── build_android.sh # Android build script (shell)
├── run_ci.sh # CI build script
└── README.txt # Human-readable README
Build Instructions
Prerequisites
- CMake 3.20+
- C++20 compatible compiler (GCC, Clang, MSVC)
- Python 3 (for build scripts)
- Ninja (recommended, used by build scripts)
- OpenSSL 1.1+ development libraries
- Platform-specific audio libraries
Linux Build
python3 build_linux.py
This creates a build_linux/ directory and outputs librtphone.a.
Android Build
# Ensure ANDROID_NDK_HOME environment variable is set
export ANDROID_NDK_HOME=/path/to/android-ndk
python3 build_android.py
Or use the shell script:
./build_android.sh
This creates a build_android/ directory with ARM64 libraries by default.
Manual CMake Build
mkdir build && cd build
cmake ../src -G Ninja
cmake --build . -j$(nproc)
Build Options
The following CMake options are available (defined in src/CMakeLists.txt):
USE_AMR_CODEC(ON/OFF): Include AMR-NB/AMR-WB codec support. Default: ONUSE_EVS_CODEC(ON/OFF): Include EVS codec support. Default: ONUSE_MUSL(ON/OFF): Build with MUSL library. Default: OFF
Module Architecture
1. Agent Module (src/engine/agent/)
Provides a JSON-based command interface for controlling the engine.
Key Classes:
AgentImpl: Main agent implementation, processes JSON commandsAgent_AudioManager: Manages audio devices and streams
Interface Pattern: Commands are sent as JSON strings and responses are returned as JSON.
2. Endpoint Module (src/engine/endpoint/)
SIP user agent implementation based on reSIProcate.
Key Classes:
UserAgent(in EP_Engine.h): Main SIP stack wrapper, handles registration, sessions, presenceAccount(EP_Account): SIP account managementSession(EP_Session): Call/session managementEP_AudioProvider: Audio data provider for sessionsEP_DataProvider: Generic data provider interface
Key Concepts:
- Implements resiprocate handlers:
ClientRegistrationHandler,InviteSessionHandler, etc. - Supports multiple transport types: UDP, TCP, TLS
- ICE integration for NAT traversal
3. Media Module (src/engine/media/)
Audio codec management, RTP/RTCP handling, and media processing.
Key Classes:
MT::AudioCodec: Codec managementMT::AudioStream: Audio streamingMT::AudioReceiver: RTP packet receivingMT::CodecList: Codec negotiationMT::SrtpHelper: SRTP encryptionMT::Dtmf: DTMF tone handlingMT::AmrCodec: AMR codec wrapperMT::EvsCodec: EVS codec wrapper
4. Audio Module (src/engine/audio/)
Cross-platform audio I/O abstraction.
Key Classes:
Audio::Interface: Audio interface abstractionAudio::DevicePair: Input/output device pairAudio::Resampler: Audio resamplingAudio::Mixer: Multi-channel audio mixingAudio::CoreAudio: macOS/iOS implementationAudio::DirectSound: Windows DirectSound implementationAudio::AndroidOboe: Android Oboe implementationAudio::Null: Null/no-op implementation for testing
5. Helper Module (src/engine/helper/)
Utility classes and platform abstractions.
Key Classes:
HL::Types: Type definitions and BiMap templateHL::Sync: Threading primitives (Mutex, Event, etc.)HL::ByteBuffer: Binary data bufferHL::VariantMap: Key-value configuration storageHL::Rtp: RTP packet utilitiesHL::IuUP: Iu User Plane protocol (3G)HL::NetworkSocket: Network socket abstractionHL::ThreadPool: Thread pool implementation
Code Style Guidelines
Naming Conventions
-
Classes: PascalCase with module prefix
AgentImpl,UserAgent,MT::AudioCodec,HL::Sync
-
Files: Prefix indicates module
Agent_*.cpp/h- Agent moduleEP_*.cpp/h- Endpoint moduleMT_*.cpp/h- Media moduleAudio_*.cpp/h- Audio moduleHL_*.cpp/h- Helper module
-
Member Variables: Hungarian notation with
mprefixmAgentMutex,mSessionMap,mShutdown
-
Type Aliases:
Pprefix for smart pointersPAccount,PSession,PVariantMap
File Header Template
All source files must include the MPL license header:
/* Copyright(C) 2007-YYYY VoIP objects (voipobjects.com)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
Include Order
- Corresponding header file (for .cpp files)
- Project headers (using
"...") - Third-party library headers
- Standard library headers
- System headers
Platform Abstraction
Use preprocessor defines for platform-specific code:
TARGET_WIN- WindowsTARGET_LINUX- LinuxTARGET_OSX- macOSTARGET_ANDROID- AndroidTARGET_MUSL- MUSL libc
Configuration
Compile-Time Configuration (src/engine/engine_config.h)
Key configuration constants:
// Audio settings
#define AUDIO_SAMPLE_WIDTH 16
#define AUDIO_CHANNELS 1
#define AUDIO_SAMPLERATE 48000
#define AUDIO_RESAMPLER_QUALITY 1
// SIP settings
#define UA_REGISTRATION_TIME 3600
#define UA_MEDIA_PORT_START 20000
#define UA_MEDIA_PORT_FINISH 30000
// Codec payload types
#define MT_AMRNB_PAYLOADTYPE 112
#define MT_AMRWB_PAYLOADTYPE 96
#define MT_EVS_PAYLOADTYPE 127
#define MT_OPUS_CODEC_PT 106
Runtime Configuration
Configuration is passed via VariantMap objects to the UserAgent:
enum
{
CONFIG_IPV4 = 0, // Use IP4
CONFIG_IPV6, // Use IP6
CONFIG_USERNAME, // Username
CONFIG_DOMAIN, // Domain
CONFIG_PASSWORD, // Password
CONFIG_STUNSERVER_NAME, // STUN server hostname
CONFIG_STUNSERVER_PORT, // STUN server port
CONFIG_TRANSPORT, // 0=all, 1=UDP, 2=TCP, 3=TLS
// ... see EP_Engine.h for full list
};
Dependencies
Git Submodules
The project uses Git submodules for some dependencies:
src/libs/resiprocate- SIP stack (sevana branch)src/libs/libsrtp- SRTP librarysrc/libs/libraries- Prebuilt platform libraries
To initialize:
git submodule update --init --recursive
Third-Party Libraries
Prebuilt libraries are provided in src/libs/libraries/:
- OpenSSL 1.1 (crypto, SSL)
- Opus codec
- Opencore AMR (NB/WB)
- Boost (headers)
- PortAudio
- libevent2
Testing
There is no dedicated test suite in the main project. Testing is typically done through:
- Integration with the final application
- The
run_ci.shscript for build verification - Unit tests in individual library submodules (e.g., oboe)
CI Build
./run_ci.sh
This configures with CMake and builds with make (2 parallel jobs).
Security Considerations
- OpenSSL Integration: Uses OpenSSL 1.1+ for TLS and certificate handling
- SRTP Support: Media encryption via libsrtp
- Certificate Management: Root certificates can be added at runtime via
addRootCert() - AMR/EVS Patents: The project does NOT include patent licenses for AMR and EVS codecs. Users must acquire these independently.
Integration Guide
Basic Usage Pattern
- Create
AgentImplinstance - Send JSON commands via
command()method - Poll for events via
waitForData()andread() - Process JSON event responses
Example Commands
config- Configure the enginestart- Start the enginecreateAccount- Create SIP accountstartAccount- Register accountcreateSession- Create call sessionstartSession- Make/accept callwaitForEvent- Poll for events
Development Workflow
- Making Changes: Edit files in appropriate
src/engine/<module>/directory - Building: Use
build_linux.pyfor quick Linux builds - Testing: Integrate with test application or use existing CI
- Commits: Follow existing commit message style (visible in git log)
Common Tasks
Adding a New Codec
- Create
MT_<Codec>Codec.cpp/hinsrc/engine/media/ - Derive from
MT::Codecbase class - Register in
MT_CodecList.cpp - Add to
src/CMakeLists.txtif external library needed
Adding Platform Audio Support
- Create
Audio_<Platform>.cpp/hinsrc/engine/audio/ - Implement
Audio::Interfacemethods - Add platform detection in
src/CMakeLists.txt - Include in build conditionally
Modifying Build Configuration
- Edit
src/CMakeLists.txtfor main build changes - Edit
src/libs/libraries/platform_libs.cmakefor platform library paths - Edit
src/engine/engine_config.hfor compile-time constants
Notes
- The codebase uses C++20 features - ensure compiler compatibility
- Thread safety: Use
std::recursive_mutex(e.g.,mAgentMutex) for thread-safe access - Memory management: Uses smart pointers (
std::shared_ptr) extensively - The JSON library is embedded in
src/libs/json/