Add a codec module for Codec 2, using libcodec2 for decoding and
encoding.
There is no RFC payload format for Codec 2, so this follows the
convention Asterisk uses: encoding name "codec2" at 8000 Hz, mono, with
one or more complete frames per RTP packet, each padded to whole bytes.
The mode is selected with the format parameter "mode=" (3200, 2400,
1600, 1400, 1300, 1200 or 700C) and defaults to 2400, the only mode
Asterisk supports. With the transcode option it can also be given as
the bit rate, e.g. "codec2/8000/1/3200".
Different modes are different bit streams, so payload types only match
when they use the same mode. Modes 1600 and below use 40 ms frames, so
their ptime is rounded up to a multiple of 40 ms. Modes not known to
rtpengine (e.g. 450) are passed through unchanged when both sides
agree, but can't be transcoded.
libcodec2 is optional. It is detected with pkg-config (or from
/usr/include/codec2) by utils/gen-codec2-flags. Without it, Codec 2 is
still recognised for SDP handling and passthrough. In a Debian build
the dependency can be dropped with the pkg.ngcp-rtpengine.nocodec2
build profile.
test-transcode gains Codec 2 tests for both directions in modes 2400,
3200 and 1300, plus passthrough. check_encoder() is no longer limited
to the extended AMR tests, as these use it too.
Closes#2226
Change-Id: I2cad021f48e2043f36c30f5e6290cb7d6eba8c1f
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The decoder output frame was hard-coded to 960 samples, which is 20 ms
at 48 kHz. libopus refuses to decode a packet that does not fit the
given frame size, so every 40 ms and 60 ms packet (both ptimes accepted
by opus_init) failed with "buffer too small" and was dropped.
Size the buffer for 120 ms, the longest duration an Opus packet can
carry, at the decoder's clock rate.
Closes#2224
Change-Id: Ic2fcb32977ad0e262d42b74948103b0f68511d95
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
When the negotiated fmtp has a bitrate range (br=A-B), the encoder's
lower bound check compared the bitrate against max_br instead of
min_br. Any bitrate below the upper bound was therefore forced down
to the minimum, e.g. br=9.6-24.4 with the default 16.4 kbit/s ended
up encoding at 9.6 kbit/s instead of staying at 16.4.
Compare against min_br so the bitrate is only raised when it is
actually below the lower bound.
Closes#2223
Change-Id: I8bfaff332476e351e0b7a6a375a9c55bb3fa772f
stats->ext_seq has been the SRTP receive index since srtp_index moved into
shm (08c7f5853d). The transcode sequencer overwrote it after every
emitted packet with its own roc<<16|seq, which lags the received packets
and, whenever the sequencer emits a late or replayed packet with a lower
sequence number, carries a roc that was incremented without a real
wrap-around. packet_index() then estimated the wrong index, and once the
sender's real roc reached 1 none of the fallback guesses matched, so every
packet of the stream failed authentication until the call ended.
packet_index() already maintains the index for every received packet, so
drop the write. Also make the sequencer's own roc increment only on a
forward wrap-around, never on a backwards step.
Closes#2221
Change-Id: Ia38bf8cbc63dd3435717927f1adfd81ac94ea347
Treat a packet exactly one ring size ahead across the 65535->0
wrap-around as a seq reset, like the non-wrapped case, instead of
accepting it into the head slot.
Fixes#2220
Change-Id: I94e2fdd3d50d5c8241cfed5da06829097566356e
Ref #2211
cli_handle() takes a str, but most "set" handlers parsed their value
with strtol(), strtod() or atoi() on instr->s and printed it with "%s",
reading up to the next NUL. The ng "cli" command passes a slice of the
request: "set maxsessions 1000" set 10007, "set rediscmdtimeout 0" set
7 ms, and error messages quoted the rest of the request.
Parse with the str_to_X helpers, plus a new str_to_d for maxcpu and
maxload, and print with STR_FORMAT. As with the str_to_X family, a
value with trailing characters ("10x") is refused, and so is a
non-number in the seven handlers that read it as 0. "terminate" now
matches all, own and foreign exactly (str_cmp()), not as a prefix.
Tested by auto-daemon-tests-redis-errors.pl and the new t/test-str.c.
Change-Id: I92ed33a4229688aba513c3d0410b9d77a8bcd516
The fallback for `avcodec_get_supported_config()` reads
`dec->avc.codec->pix_fmts`, but the decoder struct has no `codec` member,
so the build fails on anything below libavcodec 61.19:
lib/avc.c:73:39: error: 'struct <anonymous>' has no member named 'codec'
The line above it uses the `codec` argument and so should this one. The
encoder path has a `codec` member of its own, which is where this looks to
have come from.
Closes#2169
Change-Id: Iebf130d19c5107a012c61b821460a5879a777d39