Skip to content

Commit 3075797

Browse files
authored
Create README.md
1 parent 5a772e9 commit 3075797

1 file changed

Lines changed: 222 additions & 0 deletions

File tree

README.md

Lines changed: 222 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,222 @@
1+
# RRAS Audio Broadcast API
2+
3+
A lightweight REST API for managing **GStreamer-based audio broadcasts**.
4+
Provides `/start`, `/stop`, and `/status` endpoints to control multicast or direct-stream audio pipelines.
5+
6+
---
7+
8+
## 🚀 Features
9+
10+
- RESTful API for starting and stopping GStreamer audio pipelines
11+
- PID-based process control (safe, avoids global `pkill`)
12+
- Logging with timestamps to `/var/log/gstreamer_api.log`
13+
- JSON responses for all endpoints
14+
- Compatible with systemd or Docker deployment
15+
16+
---
17+
18+
## ⚙️ Requirements
19+
20+
### System Packages
21+
22+
```bash
23+
sudo apt update
24+
sudo apt install -y python3 python3-pip \
25+
gstreamer1.0-tools \
26+
gstreamer1.0-plugins-base \
27+
gstreamer1.0-plugins-good \
28+
gstreamer1.0-plugins-bad \
29+
gstreamer1.0-plugins-ugly
30+
````
31+
32+
### Python Dependencies
33+
34+
```bash
35+
pip install -r requirements.txt
36+
```
37+
38+
---
39+
40+
## 🧠 API Endpoints
41+
42+
### `POST /start`
43+
44+
Starts a new audio stream.
45+
46+
**Request Body (JSON):**
47+
48+
```json
49+
{
50+
"source": "http://192.168.1.100:9000/train-automation/audios/alert.mp3",
51+
"multicast_iface": "eno1",
52+
"multicast_host": "239.193.0.52",
53+
"multicast_port": 2100,
54+
"volume": 10.0
55+
}
56+
```
57+
58+
**Response:**
59+
60+
```json
61+
{
62+
"status": "started",
63+
"urlAddress": "http://192.168.1.100:9000/train-automation/audios/alert.mp3"
64+
}
65+
```
66+
67+
---
68+
69+
### `POST /stop`
70+
71+
Stops the currently active stream.
72+
73+
**Response:**
74+
75+
```json
76+
{
77+
"status": "stopped",
78+
"urlAddress": "http://192.168.1.100:9000/train-automation/audios/alert.mp3"
79+
}
80+
```
81+
82+
If there’s no active stream:
83+
84+
```json
85+
{
86+
"status": "no-active-stream",
87+
"urlAddress": null
88+
}
89+
```
90+
91+
---
92+
93+
### `GET /status`
94+
95+
Checks if a stream is currently active.
96+
97+
**Response (playing):**
98+
99+
```json
100+
{
101+
"status": "playing",
102+
"urlAddress": "http://192.168.1.100:9000/train-automation/audios/alert.mp3"
103+
}
104+
```
105+
106+
**Response (idle):**
107+
108+
```json
109+
{
110+
"status": "idle",
111+
"urlAddress": null
112+
}
113+
```
114+
115+
---
116+
117+
## 🧾 Example Usage (via curl)
118+
119+
```bash
120+
# Start a stream
121+
curl -X POST http://localhost:8081/start \
122+
-H "Content-Type: application/json" \
123+
-d '{"source":"http://192.168.1.100:9000/train-automation/audios/test.mp3"}'
124+
125+
# Check status
126+
curl http://localhost:8081/status
127+
128+
# Stop the stream
129+
curl -X POST http://localhost:8081/stop
130+
```
131+
132+
---
133+
134+
## 🪵 Logs
135+
136+
All activity is logged at:
137+
138+
```
139+
/var/log/gstreamer_api.log
140+
```
141+
142+
Typical entries:
143+
144+
```
145+
2025-10-13 14:10:21 [INFO] Starting stream: gst-launch-1.0 souphttpsrc ...
146+
2025-10-13 14:10:22 [INFO] GStreamer process started (PID=1810)
147+
2025-10-13 14:12:08 [INFO] Stopped GStreamer process (PID=1810)
148+
```
149+
150+
---
151+
152+
## 🧰 Run Manually
153+
154+
```bash
155+
156+
python3 app.py
157+
158+
```
159+
160+
Then open:
161+
162+
➡️ `http://localhost:8081/status`
163+
164+
---
165+
166+
## ⚙️ Optional: Run as a Systemd Service
167+
168+
Create a service file at `/etc/systemd/system/audio-broadcast.service`:
169+
170+
```ini
171+
[Unit]
172+
Description=RRAS Audio Broadcast API
173+
After=network.target
174+
175+
[Service]
176+
ExecStart=/usr/bin/python3 /opt/audio-broadcast-api/app.py
177+
WorkingDirectory=/opt/audio-broadcast-api
178+
Restart=always
179+
User=root
180+
StandardOutput=file:/var/log/gstreamer_api.log
181+
StandardError=file:/var/log/gstreamer_api.log
182+
183+
[Install]
184+
WantedBy=multi-user.target
185+
```
186+
187+
Then enable and start it:
188+
189+
```bash
190+
sudo systemctl daemon-reload
191+
sudo systemctl enable audio-broadcast.service
192+
sudo systemctl start audio-broadcast.service
193+
```
194+
195+
---
196+
197+
## ✅ Health Check
198+
199+
```bash
200+
curl http://localhost:8081/
201+
```
202+
203+
**Response:**
204+
205+
```json
206+
{
207+
"service": "RRAS Audio Broadcast API",
208+
"version": "1.2"
209+
}
210+
```
211+
212+
---
213+
214+
## 📜 License
215+
216+
This project is licensed under the [MIT License](LICENSE). See the license file for details.
217+
218+
---
219+
220+
## 🙌 Issues, Feature Requests or Support
221+
222+
Please use the Issue > New Issue button to submit issues, feature requests or support issues directly to me. You can also send an e-mail to akin.bicer@outlook.com.tr.

0 commit comments

Comments
 (0)