From 3df26cf2d060b531546cd51f040779b1aeda4047 Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Thu, 5 Jun 2025 08:55:23 -0400 Subject: [PATCH] MT#55283 improve G.729 format matching RFC says that annex B is the default in the absence of the annexb=no format string. Consider the alias "G729a" as annex A. Closes #1951 Change-Id: I9a8483ee5520bf4688601123f1ebec4f1f480642 --- lib/codeclib.c | 28 +++++++++++++++------------- t/auto-daemon-tests.pl | 15 ++++++--------- 2 files changed, 21 insertions(+), 22 deletions(-) diff --git a/lib/codeclib.c b/lib/codeclib.c index f9bcb2069..cde0d69a0 100644 --- a/lib/codeclib.c +++ b/lib/codeclib.c @@ -460,7 +460,7 @@ static struct codec_def_s __codec_defs[] = { .default_channels = 1, .default_ptime = 20, .minimum_ptime = 20, - .default_fmtp = "annexb=no", + .default_fmtp = "annexb=yes", .format_cmp = format_cmp_g729, .packetizer = packetizer_g729, .bits_per_sample = 1, // 10 ms frame has 80 samples and encodes as (max) 10 bytes = 80 bits @@ -479,6 +479,7 @@ static struct codec_def_s __codec_defs[] = { .default_channels = 1, .default_ptime = 20, .minimum_ptime = 20, + .default_fmtp = "annexb=no", .format_cmp = format_cmp_g729, .packetizer = packetizer_g729, .bits_per_sample = 1, // 10 ms frame has 80 samples and encodes as (max) 10 bytes = 80 bits @@ -3607,19 +3608,20 @@ static int packetizer_g729(AVPacket *pkt, GString *buf, str *input_output, encod return buf->len >= 2 ? 1 : 0; } +static bool g729_is_annex_b(const struct rtp_payload_type *p) { + // defaults based on codec name (G729 vs G729a) + bool annex_b = p->encoding.len && !((p->encoding.s[p->encoding.len - 1] & 0xdf) == 'A'); + // override per fmtp + if (str_str(&p->format_parameters, "annexb=no") != -1) + annex_b = false; + else if (str_str(&p->format_parameters, "annexb=yes") != -1) + annex_b = true; + return annex_b; +} static int format_cmp_g729(const struct rtp_payload_type *a, const struct rtp_payload_type *b) { - // shortcut the most common case: - if (!str_cmp_str(&a->format_parameters, &b->format_parameters)) - return 0; - // incompatible is if one side uses annex B but the other one doesn't - if (str_str(&a->format_parameters, "annexb=yes") != -1 - && str_str(&b->format_parameters, "annexb=yes") == -1) - return -1; - if (str_str(&a->format_parameters, "annexb=yes") == -1 - && str_str(&b->format_parameters, "annexb=yes") != -1) - return -1; - // everything else is compatible - return 0; + bool a_b = g729_is_annex_b(a); + bool b_b = g729_is_annex_b(b); + return a_b == b_b ? 0 : -1; } #endif diff --git a/t/auto-daemon-tests.pl b/t/auto-daemon-tests.pl index 974391e98..a6da22eae 100755 --- a/t/auto-daemon-tests.pl +++ b/t/auto-daemon-tests.pl @@ -1016,7 +1016,7 @@ m=audio 49696 RTP/AVP 8 0 18 100 a=rtpmap:8 PCMA/8000 a=rtpmap:0 PCMU/8000 a=rtpmap:18 G729/8000 -a=fmtp:18 annexb=no +a=fmtp:18 annexb=yes a=rtpmap:100 telephone-event/8000 a=fmtp:100 0-11 a=ptime:20 @@ -1032,7 +1032,7 @@ c=IN IP4 203.0.113.1 a=rtpmap:8 PCMA/8000 a=rtpmap:0 PCMU/8000 a=rtpmap:18 G729/8000 -a=fmtp:18 annexb=no +a=fmtp:18 annexb=yes a=rtpmap:100 telephone-event/8000 a=fmtp:100 0-11 a=sendrecv @@ -1079,7 +1079,7 @@ m=audio 49696 RTP/AVP 8 0 18 100 a=rtpmap:8 PCMA/8000 a=rtpmap:0 PCMU/8000 a=rtpmap:18 G729/8000 -a=fmtp:18 annexb=yes +a=fmtp:18 annexb=no a=rtpmap:100 telephone-event/8000 a=fmtp:100 0-11 a=ptime:20 @@ -1151,11 +1151,10 @@ v=0 o=- 1737116508926565 1737116508926565 IN IP4 5.6.7.7 s=SIP call t=0 0 -m=audio PORT RTP/AVP 8 0 18 100 +m=audio PORT RTP/AVP 8 0 100 c=IN IP4 203.0.113.1 a=rtpmap:8 PCMA/8000 a=rtpmap:0 PCMU/8000 -a=rtpmap:18 G729a/8000 a=rtpmap:100 telephone-event/8000 a=fmtp:100 0-11 a=sendrecv @@ -1213,12 +1212,10 @@ v=0 o=- 1737116508926565 1737116508926565 IN IP4 5.6.7.7 s=SIP call t=0 0 -m=audio PORT RTP/AVP 8 0 18 100 +m=audio PORT RTP/AVP 8 0 100 c=IN IP4 203.0.113.1 a=rtpmap:8 PCMA/8000 a=rtpmap:0 PCMU/8000 -a=rtpmap:18 G729a/8000 -a=fmtp:18 annexb=no a=rtpmap:100 telephone-event/8000 a=fmtp:100 0-11 a=sendrecv @@ -1265,7 +1262,7 @@ m=audio 49696 RTP/AVP 8 0 18 100 a=rtpmap:8 PCMA/8000 a=rtpmap:0 PCMU/8000 a=rtpmap:18 G729a/8000 -a=fmtp:18 annexb=yes +a=fmtp:18 annexb=no a=rtpmap:100 telephone-event/8000 a=fmtp:100 0-11 a=ptime:20