Turns a Reolink video doorbell into a SIP extension on your PBX:
- someone calls the extension → the bridge answers and connects them to the doorbell's microphone and speaker;
- someone presses the button → the bridge dials
RING_TARGETand connects the same two-way audio once it is answered.
Developed and tested against FreePBX/Asterisk, but nothing in it is FreePBX-specific: any PBX that accepts a registering SIP endpoint will do.
- A Linux host on the same routable network as both the PBX and the doorbell, with no NAT between any of the three. SIP and RTP put real addresses in their headers, so anything that rewrites them breaks audio.
ffmpegon that host (already included in the Docker image).- Python 3.12+ if you are running it outside Docker.
The SIP stack is native code and the deployment target is Linux.
With Docker, which is the intended way:
cp .env.example .env # then fill in hosts, credentials, extensions
docker compose up -d --build
docker compose logs -f
Or directly:
python -m venv .venv && . .venv/bin/activate
pip install -r requirements.txt
cp .env.example .env # then edit
python -m rsb
Host networking is required for the container, for the reason above: a bridge
network would put unroutable addresses in the SIP and SDP headers.
SIP_BIND_IP is the address of the host running the container, not the
PBX — get it wrong and registration still succeeds while audio goes nowhere.
docker-compose.yml can carry the whole configuration, with the passwords
interpolated from .env so they never reach an image layer.
To run a second doorbell, add a service with its own SIP_USERNAME,
SIP_BIND_PORT, SIP_RTP_PORT_LOW/HIGH, REOLINK_HOST and RING_TARGET;
host networking means those must not collide.
Everything lives in .env (see .env.example). Most of it is addresses and
credentials. These are the ones worth understanding:
| Key | Default | What it does |
|---|---|---|
MIC_GAIN_DB |
0 |
Gain on the doorbell microphone, in dB. 0 leaves the stream untouched; raise it only if visitors come through quietly. |
AUDIO_TARGET_MS |
60 |
How much audio the bridge will hold in each direction. This is delay you hear; lower is snappier, too low turns a hiccup into a dropout. |
AUDIO_QUIET_PEAK |
600 |
Absolute floor on what counts as a pause, in raw sample units (0–32767; 600 ≈ −35 dBFS). See Pauses. |
AUDIO_QUIET_OVER_FLOOR |
1.8 |
The other half of the same threshold: this far above the tracked noise floor is somebody talking. 1.8 ≈ 5 dB. See Pauses. |
MIC_QUIET_* / SPEAKER_QUIET_* |
(unset) | Per-direction overrides of the two above. See Pauses. |
SIP_VAD |
false |
PJSIP's own silence suppression towards the caller. Off here, unlike stock pjsua; true restores it. See Pauses. |
SPEAKER_DRAIN_MS |
1600 |
How much of the camera's own playout cushion to reclaim. Do not raise to 2000 — a camera that runs dry stops playing until the stream is rebuilt. |
BUTTON_CHIME_MS |
3000 |
How long the doorbell's own chime lasts. The speaker is opened only after this. |
If your PBX is FreePBX, note that the chan_sip driver listens on udp/5160
and chan_pjsip on udp/5060; SIP_PORT must match whichever one is actually
answering.
rsb/__main__.py entry point: python -m rsb
rsb/bridge.py wires a call to the doorbell and watches it
rsb/config.py .env-backed configuration
rsb/log.py logging setup
rsb/audio/pcm.py the internal audio bus format + helpers
rsb/audio/buffer.py thread-safe buffer between a producer and PJSIP
rsb/audio/g711.py mu-law/A-law conversion (backchannel only)
rsb/audio/hold.py the "door not ready yet" hold tone
rsb/audio/wav.py WAV read/write, for the diagnostic tools
rsb/audio/testsignal.py tones the diagnostic tools play and measure
rsb/sip/phone.py PJSIP endpoint: register, answer, dial
rsb/doorbell/mic.py microphone: ffmpeg pulls RTSP audio into the bus
rsb/doorbell/speaker.py speaker: RTP up the ONVIF backchannel
rsb/doorbell/events.py button detection via Baichuan TCP push
rsb/doorbell/rtsp.py minimal RTSP client (DESCRIBE + backchannel)
rsb/doorbell/api.py Reolink HTTP CGI API client
Everything internal is 16-bit linear PCM, 8 kHz, mono — PJSIP's native format once G.711 is decoded, so the SIP leg needs no conversion at all and the media stack never resamples. Conversion happens only at the two doorbell edges:
doorbell mic AAC 16 kHz --ffmpeg--> PCM 8 kHz --> caller
caller PCM 8 kHz --g711.py--> mu-law --> doorbell speaker
Transcoding is unavoidable in one direction and absent in the other: the camera
offers its microphone only as MPEG4-GENERIC/16000 and SIP has no AAC, while
the backchannel speaks PCMU/8000 natively. Neither costs meaningful time —
decoding takes microseconds, buffering takes milliseconds.
Audio is carried by PJSIP's media thread and nothing else: it asks the
microphone buffer for a frame every 20 ms and hands the caller's frames
straight to the speaker (CallSession.bridge). One buffer per direction:
ffmpeg --> [mic buffer] --> PJSIP --> RTP door to caller
RTP --> PJSIP --> [speaker buffer] --> RTSP caller to door
That structure is the point, because a reader taking one 20 ms frame every 20 ms can never work off a backlog. It runs at exactly the right average rate, so whatever depth a burst leaves behind is kept forever — and depth is delay. Every extra hop is another clock and another backlog that never drains.
So each buffer sheds excess deliberately (FrameBuffer._trim), dropping 20 ms
of pause at a time: inaudible, and conversation is mostly pauses. How much
cushion to keep is not knowable in advance, so the buffer finds it — starting
at AUDIO_TARGET_MS, growing when it runs dry while someone is speaking, and
giving it back once the trouble stops.
A frame is a pause when its loudest sample is at or below
max(AUDIO_QUIET_PEAK, noise floor x AUDIO_QUIET_OVER_FLOOR)
Speech is judged against a tracked noise floor rather than a fixed threshold, since mic gain and a noisy doorway both lift ordinary room tone above any constant you might pick. The same threshold governs both directions, and it is the only level test in the bridge — nothing is muted or gated by loudness; audio under it is merely the first thing thrown away when there is delay to shed.
Two places act on it. FrameBuffer._trim deletes pauses when a direction is
holding more than AUDIO_TARGET_MS, and the speaker drops half its packets
during pauses until SPEAKER_DRAIN_MS of the camera's cushion is reclaimed.
So a talker quiet enough to sit under the threshold can be thinned — lower
both values if that happens.
Turning it off takes AUDIO_QUIET_PEAK=0 and AUDIO_QUIET_OVER_FLOOR=0;
they are combined with max(), so zeroing one leaves the other in charge, and
the adaptive half dominates in any real room. With both at zero only digital
silence is a pause, which means nothing is ever cut — and also that _trim
has nothing to drop. Delay then settles wherever a burst leaves it and is
released only when the direction hits its hard 200 ms cap, which drops the
oldest audio mid-word. SPEAKER_DRAIN_MS=0 disables just the camera-cushion
reclaim, at the cost of keeping the camera's full ~2 s of delay.
Per direction. MIC_QUIET_PEAK / MIC_QUIET_OVER_FLOOR override the pair
for doorbell → caller, and SPEAKER_QUIET_PEAK / SPEAKER_QUIET_OVER_FLOOR
for caller → doorbell; unset, each falls back to the AUDIO_QUIET_* value.
The split is worth having because the two paths fail differently. ffmpeg hands
over the microphone in 64 ms bursts, sometimes three at once, so that
direction really does accumulate backlog and trimming is what holds it at
AUDIO_TARGET_MS — it is also where a visitor standing back from a noisy door
is most likely to be clipped. The speaker side is fed one frame per 20 ms by
PJSIP and rarely builds a backlog at all.
Whether a direction needs it is measurable rather than a guess: every call
ends with a FrameBuffer.stats() line per direction, and its Nms trimmed
figure is exactly how much audio that threshold removed. If doorbell-mic
reports 0ms trimmed across a few real calls, switching that direction off
costs nothing.
A third gate lives below all of this. PJSIP does its own silence
detection on the leg to the caller and simply stops sending RTP underneath it,
which clips the start of a word and can swallow a quiet visitor. pjsua
enables it by default (MediaConfig.noVad is false out of the box, verified
against pjsua2 2.15.1); this bridge sets SIP_VAD=false and disables it,
since the bandwidth it saves is meaningless for one G.711 call on a LAN. It is
the least visible of the three — nothing is logged when it fires — so it is
worth ruling out before chasing the two above. SIP_VAD=true restores stock
pjsua behaviour.
The camera adds a cushion of its own, which is the larger half of the caller-to-door delay; see Gotchas.
Answering instantly would be worse than it sounds: draining the camera's
cushion needs several seconds of silence, and a conversation will not provide
them. So the bridge sends 180 Ringing, gets the doorbell ready while the
caller hears ringback, and only then picks up — up to DRAIN_TIMEOUT.
The camera plays its own chime on the same speaker we are about to stream to, and audio sent during it is discarded rather than played. The three things therefore run in parallel rather than in sequence:
- the phone rings immediately — a visitor who pressed a button expects something to happen;
- after
BUTTON_CHIME_MSthe camera's audio opens, primes and drains; - anyone who answers before that finishes hears a short pip, quickly
repeated (425 Hz, 150 ms on / 450 ms off), until both ends are ready. A
ringing-tone cadence leaves seconds of silence between beeps, which over a
wait this short sounds like a dead line; adjust it in
rsb/audio/hold.py.
To try this without going to the door, send the bridge SIGUSR1:
docker compose kill -s USR1 doorbell # or: kill -USR1 <pid>
It runs the same path as a real press, ringing, hold tone and doorbell audio
included, so whoever is at the door can hear and be heard. Two differences:
the camera plays no chime (the bridge still waits BUTTON_CHIME_MS, so the
timing is the same), and RING_DEBOUNCE does not apply.
Findings are from a Reolink Video Doorbell WiFi on fw v3.0.0.4662_2503122270.
Other Reolink models with the talk ability should behave the same way.
The unit exposes tcp/80 (API), 554 (RTSP), 8000 (ONVIF) and 9000 (Baichuan push).
- Speaker: ONVIF backchannel,
PCMU/8000, payload type 0,track3. - Microphone: carried inside the RTSP stream as 16 kHz AAC
(
MPEG4-GENERIC/16000); ffmpeg decodes and resamples it. The camera exposes no microphone gain of its own —GetAudioCfghas only speakervolume— so any levelling happens on our side viaMIC_GAIN_DBandMIC_AGC, both off by default.tools/mic_tune.pyrecords once and renders every candidate chain from that one take, so you can pick by listening.
If the microphone stays inaudible no matter what — the same on main and sub, TCP and UDP, audio-only and audio+video, with no gain or filter chain making a difference — stop tuning and suspect the hardware. A faulty capsule looks exactly like a configuration problem from this end, and one unit tested here turned out to be defective after a long detour through filter chains.
Things that cost real time to discover, in rough order of how much:
- The camera holds a fixed ~2 s cushion before it plays anything, and that
cushion is the caller-to-door delay.
tools/latency.py speakermeasures it: the doorbell plays a rising tone while the console prints the step it is sending, and the gap between the two is the delay in seconds. - It plays out on its own clock, but it must never run dry. Stop sending
and two seconds come out, so the cushion does drain — but once empty the
camera plays nothing again until the stream is rebuilt. Silence suppression
is therefore not an option. Thinning is: during silences send slightly
fewer packets than real time, so the cushion shrinks with the stream
unbroken.
SPEAKER_DRAIN_MS=1600takes 2.0 s down to ~0.4 s, and stops short of 2000 because the remaining depth is not observable and the failure mode is unrecoverable. - Do not thin the moment speech stops. The camera still holds the tail of that sentence, and the dropped packets are the ones that would have pushed it out, so the last half-second gets clipped. Wait out the cushion minus what has already been reclaimed.
- Audio sent while the camera plays its chime is discarded. Draining during it reclaims nothing while reporting success.
- The doorbell mutes its microphone while its speaker plays. Any self-test that plays a sound on the camera and listens for it on the same camera fails no matter what. It also means echo cancellation is unnecessary — the camera gives us half-duplex suppression for free.
- Early media is a different media session. A PBX sends ringback before the
callee answers, so
onCallMediaStatefires twice; bind to the first and ignore the second, and audio arrives at PJSIP but never reaches the application. Rewire on every media state change. - Dial with an explicit port. A URI like
sip:101@pbx.examplemeans port 5060; if your PBX answers on 5160 instead, the INVITE vanishes with no error at all. - A fixed-rate reader never catches up. Any stage consuming 20 ms every 20 ms holds a backlog indefinitely. Chaining two of them is the easy way to build an intercom with a second of delay in it.
- ffmpeg is not a source of delay. It delivers the microphone in a steady
trickle of 64 ms AAC frames;
-flush_packets,-avioflags direct,-probesizeand-max_delaychange nothing measurable (tools/latency.py pipe). - Asterisk may advertise the site's public IP in Contact and SDP even for
purely internal calls, if
localnetdoes not cover the subnet the bridge lives on. Harmless here — we loose-route via the PBX rather than following Contact — but it is the first suspect for any one-way audio.
Diagnostics, each run from the project root on the host that can reach the
doorbell (python tools/<name>.py, or docker compose exec doorbell python tools/<name>.py). Pass --help for options.
| Tool | For |
|---|---|
probe.py |
What the doorbell and PBX offer: ports, codecs, abilities. |
pjsip_check.py |
Does the native SIP stack work in this environment? |
watch_button.py |
Log doorbell button presses. |
sip_test.py |
Register, answer, or dial, with a test tone. |
mic_test.py |
Record the doorbell microphone, or stream it into a call. |
mic_diag.py |
Which RTSP/RTMP variant actually carries microphone audio. |
mic_tune.py |
One recording, every candidate filter chain, for A/B listening. |
speaker_test.py |
Tone, WAV, or a caller's voice out of the doorbell. |
latency.py |
Where the delay is: sdp, pipe, mic, speaker. |
pyVoIP can register, but FreePBX qualifies endpoints with OPTIONS every 60 s
and pyVoIP cannot parse them — OPTIONS is absent from SIPCompatibleMethods
on both the current release and master — so the extension is eventually marked
unreachable. Alongside that: no CANCEL, RTP underruns padded with 0x80
(full scale in mu-law, not silence), encode_packet labelling mu-law as A-law,
and a blocking recv() inside invite(). Fixing that list means writing a SIP
stack. PJSIP 2.15.1 via the pjsua2-python wheels handles OPTIONS, CANCEL,
retransmissions and jitter buffering itself.
Copyright (C) 2026 Wouter Gritter.
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. See LICENSE for the full text.
It is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.