From 89af163b1fcbed7709e747325ad717da1b2a3d4e Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Thu, 12 Jan 2023 12:53:19 -0500 Subject: [PATCH] MT#55283 add minimum_ptime codec attribute Prevent a wrongly advertised (too small) a=ptime from producing too small buffers to hold encoded packets by flagging codecs with a fixed or minimum frame size as such. This is relevant to libavcodec only as the code determines the expected frame size from the clock rate and the ptime. closes #1591 Change-Id: I9f5c56d45f2aad56951b19d846ddbfa4b7bd7e7d (cherry picked from commit 38b0351d03cde3e830bd917311826d69c21bb6a0) --- lib/codeclib.c | 13 +++++++++++++ lib/codeclib.h | 1 + 2 files changed, 14 insertions(+) diff --git a/lib/codeclib.c b/lib/codeclib.c index c7f4126f5..d29093815 100644 --- a/lib/codeclib.c +++ b/lib/codeclib.c @@ -193,6 +193,7 @@ static codec_def_t __codec_defs[] = { .default_clockrate = 8000, .default_channels = 1, .default_ptime = 30, + .minimum_ptime = 30, .default_bitrate = 6300, .packetizer = packetizer_passthrough, .media_type = MT_AUDIO, @@ -224,6 +225,7 @@ static codec_def_t __codec_defs[] = { .avcodec_id = AV_CODEC_ID_QCELP, .clockrate_mult = 1, .default_ptime = 20, + .minimum_ptime = 20, .packetizer = packetizer_passthrough, .media_type = MT_AUDIO, .codec_type = &codec_type_avcodec, @@ -240,6 +242,7 @@ static codec_def_t __codec_defs[] = { .default_clockrate = 8000, .default_channels = 1, .default_ptime = 20, + .minimum_ptime = 20, .packetizer = packetizer_passthrough, .media_type = MT_AUDIO, .codec_type = &codec_type_avcodec, @@ -255,6 +258,7 @@ static codec_def_t __codec_defs[] = { .default_clockrate = 8000, .default_channels = 1, .default_ptime = 20, + .minimum_ptime = 20, .packetizer = packetizer_passthrough, .media_type = MT_AUDIO, .codec_type = &codec_type_avcodec, @@ -271,6 +275,7 @@ static codec_def_t __codec_defs[] = { .default_clockrate = 8000, .default_channels = 1, .default_ptime = 20, + .minimum_ptime = 20, .default_fmtp = "annexb=no", .packetizer = packetizer_g729, .bits_per_sample = 1, // 10 ms frame has 80 samples and encodes as (max) 10 bytes = 80 bits @@ -288,6 +293,7 @@ static codec_def_t __codec_defs[] = { .default_clockrate = 8000, .default_channels = 1, .default_ptime = 20, + .minimum_ptime = 20, .packetizer = packetizer_g729, .bits_per_sample = 1, // 10 ms frame has 80 samples and encodes as (max) 10 bytes = 80 bits .media_type = MT_AUDIO, @@ -305,6 +311,7 @@ static codec_def_t __codec_defs[] = { .default_channels = 1, .default_bitrate = 11000, .default_ptime = 20, + .minimum_ptime = 20, .packetizer = packetizer_passthrough, .media_type = MT_AUDIO, .codec_type = &codec_type_avcodec, @@ -320,6 +327,7 @@ static codec_def_t __codec_defs[] = { .default_channels = 1, //.default_bitrate = 13200, .default_ptime = 20, + .minimum_ptime = 20, .packetizer = packetizer_passthrough, .media_type = MT_AUDIO, .codec_type = &codec_type_avcodec, @@ -351,6 +359,7 @@ static codec_def_t __codec_defs[] = { .default_channels = 2, .default_bitrate = 32000, .default_ptime = 20, + .minimum_ptime = 5, .packetizer = packetizer_passthrough, .media_type = MT_AUDIO, .codec_type = &codec_type_avcodec, @@ -473,6 +482,7 @@ static codec_def_t __codec_defs[] = { .default_channels = 1, .default_bitrate = 6700, .default_ptime = 20, + .minimum_ptime = 20, .default_fmtp = "octet-align=1;mode-change-capability=2", .packetizer = packetizer_amr, .bits_per_sample = 2, // max is 12200 / 8000 = 1.525 bits per sample, rounded up @@ -496,6 +506,7 @@ static codec_def_t __codec_defs[] = { .default_channels = 1, .default_bitrate = 14250, .default_ptime = 20, + .minimum_ptime = 20, .default_fmtp = "octet-align=1;mode-change-capability=2", .packetizer = packetizer_amr, .bits_per_sample = 2, // max is 23850 / 16000 = 1.490625 bits per sample, rounded up @@ -1315,6 +1326,8 @@ int encoder_config_fmtp(encoder_t *enc, const codec_def_t *def, int bitrate, int if (ptime <= 0) ptime = 20; + if (def->minimum_ptime && ptime < def->minimum_ptime) + ptime = def->minimum_ptime; enc->requested_format = *requested_format; enc->def = def; diff --git a/lib/codeclib.h b/lib/codeclib.h index e2f98614a..a9cbf63b2 100644 --- a/lib/codeclib.h +++ b/lib/codeclib.h @@ -137,6 +137,7 @@ struct codec_def_s { int default_channels; const int default_bitrate; int default_ptime; + int minimum_ptime; const char *default_fmtp; format_cmp_f * const format_cmp; packetizer_f * const packetizer;