Commit Graph

457 Commits

Author SHA1 Message Date
Dmytro Bogovych 03c58c4572 - G.722: decode as 16 kHz audio, keep the 8 kHz RTP clock separate
G722Codec::info() reported an 8 kHz sample rate for its 16 kHz output (640
bytes of PCM per 20 ms frame, read as 40 ms at 8 kHz). AudioReceiver therefore
fetched packets at half the rate they arrived, and the high-water trim
discarded about 44% of every G.722 stream: 109 of 250 packets per 5 s, with the
buffer at 360 ms instead of 100 ms.

The 8 kHz figure is right for one thing: RFC 3551 keeps G.722's RTP clock at
8000. Codec::Info already had mTimestampUnit for that. G.722 now reports
mSamplerate 16000 and mTimestampUnit 1/8000, and Codec::rtpClockRate() gives
the clock rate. The uses of samplerate() that mean RTP time now use it:
- the jitter statistics in AudioReceiver::add;
- the timestamp-gap-to-milliseconds conversion in AudioReceiver;
- AudioStream's transmit timestamp unit and increment (numerically unchanged
  for every codec, including G.722).
PCM uses stay on samplerate(), so AudioStream now also feeds the G.722
encoder 16 kHz audio instead of 8 kHz. The factory still advertises G722/8000
in SDP, as it must; only its backwards comment is fixed.

AudioReceiver::infoFor() also applied a "G729A silence" rule to payload type
9, which is G.722; G.729 is 18. It now applies to PT 18. Other fixed-frame
payloads are timed proportionally, as AudioReceiver::add already does, so a
10 ms G.722 packet (half a 160-byte frame) counts as 10 ms, not 20.

Measured in vq-core with 16 replayed calls (NISQA speech; G.722 from ffmpeg
and pjmedia, G.711 controls of the same speech; 3 runs each, all identical):
- G.722 packet drops: 44% -> 0; buffer 100 ms like G.711; no underruns;
- Sevana MOS of every G.722 call now equals its G.711 control, normal and loud
  (with the previous code three calls read 4.45 against 4.25);
- DeadAir-01 0.68-0.89 -> 0.01-0.27 (G.711: 0.00-0.14); SilentCall within 0.01
  of G.711 for the ffmpeg-encoded calls (was 0.15-0.17 higher);
- AmpClipping on loud calls 0.004/0.001, as G.711; the 0.02-0.03 seen after
  the codec swap alone came from the dropped packets;
- G.711 results, packet counts, loss, jitter and audio durations unchanged.
The transmit path (AudioStream) builds but was not exercised; vq-core only
receives.

Needs the vq_net change that computes jitter with rtpClockRate().

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-21 18:03:58 +02:00
Dmytro Bogovych c8d9bad845 - replace the LGPL G.722 codec with Asterisk's public-domain copy
The previous src/libs/g722 was spandsp's G.722 offered only under GPL-2 or
LGPL-2.1. That blocks shipping rtphone statically linked in a closed binary
(the freeware VQ for Asterisk engine) without a relink offer. Asterisk's
codecs/g722 is the same code: Steve Underwood placed his contributions in the
public domain there, and the CMU 1993 code under it is "completely
unrestricted" for any use. src/libs/g722/README.md records the provenance and
both statements.

It also fixes the decoded level. Asterisk's copy halves the encoder input and
doubles the decoder output, so streams from Asterisk and ffmpeg decode at
their original level. The old copy decoded them 6 dB too quiet (ITU-convention
streams from pjmedia 12 dB), and its encoder clipped input above -6 dBFS.

Local changes to Asterisk's files:
- the decoder saturates its output instead of casting. Asterisk's cast wraps:
  259 samples in 11 s of speech peaking at -0.2 dBFS came out with the
  opposite sign;
- g722.h includes <stdint.h> and maps __inline__ for MSVC (the removed
  g722_inttypes.h used to).
Dropped: g722_bitstream.*, g722codec.c and three helper headers, none used.
The API is unchanged (g722_encode_init / g722_decode, same options).

Measured in vq-core (16 simultaneous replayed calls, NISQA speech):
- G.711 control calls score identically;
- normal-level G.722: SilentCall -0.09..-0.14, DeadAir-01 -0.06..-0.09, MOS
  unchanged;
- loud G.722 with a clipped source now shows AmpClipping 0.02-0.03 and MOS
  3.89/4.28 instead of 4.45: the codec overshoots on the clipped peaks at the
  correct level, which the old -6 dB hid;
- results are identical across runs (the old decoder varied by up to 0.30 MOS).

G.722 still loses about 44% of its packets in AudioReceiver because
G722Codec::info() reports an 8 kHz sample rate for 16 kHz audio. That is fixed
separately.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-21 17:54:18 +02:00
dmytro.bogovych 405483a00d - add clang-format settings 2026-09-03 10:30:22 +03:00
dmytro.bogovych e166bae1ea - clang format + naming improved 2026-09-03 10:03:42 +03:00
dmytro.bogovych 249e614def - find total number of received RTP (not RTCP) bytes 2026-08-14 11:32:35 +03:00
dmytro.bogovych f29ab8aa13 - memory optimization for vq-core project 2026-08-14 11:32:17 +03:00
dmytro.bogovych 23a28c293b - audio decoding chain improving 2026-07-22 17:28:37 +03:00
dmytro.bogovych d22b8fe1ab - statistics for pool allocator 2026-07-22 17:28:13 +03:00
dmytro.bogovych a19697f501 - statistics for Android Oboe backend 2026-07-22 17:28:00 +03:00
dmytro.bogovych 9f246e0d92 - rename README 2026-07-17 14:44:27 +03:00
dmytro.bogovych bbad9d27b4 - fix bad audio quality 2026-07-17 14:42:36 +03:00
dmytro.bogovych 7f638a5aef - optimize memory usage 2026-07-06 12:33:45 +03:00
dmytro.bogovych 25e30a6ba7 - stop properly on bad AMR packets 2026-07-06 12:33:37 +03:00
dmytro.bogovych 3d455732ea - fix few audio processing bugs 2026-07-06 12:33:16 +03:00
dmytro.bogovych 0e48bed9c1 - set User-Agent via agent interface 2026-07-06 12:32:27 +03:00
dmytro.bogovych dc8cf6a12c - performance optimization 2026-06-30 20:43:08 +03:00
dmytro.bogovych 60d3470873 - run RNG seed once per app lifetime 2026-06-25 14:12:01 +03:00
dmytro.bogovych e8a71d5b03 - optimize memory usage 2026-06-21 14:02:40 +03:00
dmytro.bogovych 1e020a7b5f - better internal statistics + memory performance optimization 2026-06-18 12:28:19 +03:00
dmytro.bogovych 2cb2a93d59 - performance optimizations 2026-06-17 14:18:31 +03:00
dmytro.bogovych 40f3b34b16 - fixes after review 2026-06-16 18:05:51 +03:00
dmytro.bogovych 2c89b80dcd - fix crash in VPN networks + fix build for softphone clients 2026-06-10 09:46:28 +03:00
dmytro.bogovych c1ab8778bc - fix static builds 2026-05-30 18:11:58 +03:00
dmytro.bogovych ee96f1144d - fix logging issues 2026-05-30 18:11:23 +03:00
dmytro.bogovych 27eefb34fe - fix DTX decoding 2026-05-30 18:11:03 +03:00
dmytro.bogovych e7757fa08b - use size_t in Audio::DataWindow and be more strict in memory management 2026-05-30 18:10:37 +03:00
dmytro.bogovych b779a9f00f - fix audio decoding chain (extra silence could be generated in case of big network losses) 2026-05-23 15:51:46 +03:00
dmytro.bogovych dd21bc8c35 - fix packet time calculation for Opus codec 2026-05-22 13:36:28 +03:00
dmytro.bogovych 97c4c3aef0 - statistics improved + allow to use virtual microphone AND/OR speaker + minor cleanups 2026-05-18 10:46:21 +03:00
dmytro.bogovych 7cb3b4334f - expose AudioManager::setAudioInput() to inject custom input device
Lets a host inject e.g. NullInputDevice before start() so the default
platform microphone is not constructed, avoiding the RECORD_AUDIO
permission on Android while leaving the real speaker output in place.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-17 07:20:47 +03:00
dmytro.bogovych fd4f664164 - patches for RTT / jitter / Network MOS calculation 2026-05-17 05:42:35 +03:00
dmytro.bogovych cfdf1a0c77 - cleanup old non-used code + migration to std::chrono 2026-04-20 22:09:58 +03:00
dmytro.bogovych 6caabf285c - remove commented MSVC runtime library related code 2026-04-07 18:18:57 +03:00
dmytro.bogovych 4f9ac22358 - cleanup CMakeLists.txt 2026-03-24 22:12:17 +03:00
dmytro.bogovych affcfd4fe6 - fix subprojects build locations 2026-03-16 14:23:19 +03:00
dmytro.bogovych d9b3d8e914 - fix logging formatting for callbacks 2026-03-12 13:57:04 +03:00
dmytro.bogovych 06e8bf0b5d - fix logging - too much different subsystem names were used 2026-03-09 15:27:55 +03:00
dmytro.bogovych e07654e2bc - use AMR decoders built from source code; this eliminates the problem with build environments + ensures latest 0.1.6 version is used 2026-02-28 07:32:23 +03:00
dmytro.bogovych 226bbe9b0b - fix logger - use template method finally 2026-02-28 06:36:31 +03:00
dmytro.bogovych ece1847796 - fix macOS build 2026-02-27 17:28:17 +03:00
dmytro.bogovych fb3b34f496 - disable OpenCore AMR libraries usage on Android; vcpkg doesn't include them. 2026-02-26 19:33:30 +03:00
dmytro.bogovych 549eb93db7 - fix Windows build issues 2026-02-26 13:33:29 +03:00
dmytro.bogovych 8eb6447164 - silence deprecation warnings 2026-02-25 14:10:11 +03:00
dmytro.bogovych 273c72498e Merge branch 'dev' 2026-02-25 13:55:45 +03:00
dmytro.bogovych 34fd9121ed - adopt RFC2833 decoder for pcap analyzer 2026-02-25 13:54:37 +03:00
dmytro.bogovych 06b39dd629 - improve packet loss reporting + initial DTMF RFC 2833 event reporting 2026-02-25 10:16:24 +03:00
dmytro.bogovych 03f662e5ce - fix packet loss reporting 2026-02-24 12:49:39 +03:00
dmytro.bogovych 72a7042ab9 - allow AMR-NB/WB BWE profiles in rtp_decode 2026-02-24 10:48:03 +03:00
dmytro.bogovych b5fe9e59c4 - fix AMR-WB decoder 2026-02-24 10:47:38 +03:00
dmytro.bogovych bdc4858bcc - initial work to fix RTPdump decoder + more fixes 2026-02-24 09:50:44 +03:00