From 679b2b95324ee5a7b4bd801ec5b27490836249e1 Mon Sep 17 00:00:00 2001 From: Alessandro Ros Date: Sat, 15 Aug 2026 19:08:49 +0200 Subject: [PATCH] impose a minimum value to clock rate of always-available tracks (#6086) Clock rates below 10 caused the emission of empty samples. Fix the issue by imposing a minimum value of 8khz, that rises to 22khz in case of AAC. --- internal/conf/always_available_track.go | 16 +++++++++++++++- internal/conf/conf_test.go | 22 ++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/internal/conf/always_available_track.go b/internal/conf/always_available_track.go index ce04ffbd..c959d896 100644 --- a/internal/conf/always_available_track.go +++ b/internal/conf/always_available_track.go @@ -31,10 +31,24 @@ func (t *AlwaysAvailableTrack) UnmarshalJSON(b []byte) error { return fmt.Errorf("channelCount must not be specified for codec '%s'", t.Codec) } - case CodecMPEG4Audio, CodecG711, CodecLPCM: + case CodecMPEG4Audio: if t.SampleRate == 0 { return fmt.Errorf("sampleRate is mandatory for codec '%s'", t.Codec) } + if t.SampleRate < 22050 { + return fmt.Errorf("sampleRate must be greater than or equal to 22050 for codec '%s'", t.Codec) + } + if t.ChannelCount == 0 { + return fmt.Errorf("channelCount is mandatory for codec '%s'", t.Codec) + } + + case CodecG711, CodecLPCM: + if t.SampleRate == 0 { + return fmt.Errorf("sampleRate is mandatory for codec '%s'", t.Codec) + } + if t.SampleRate < 8000 { + return fmt.Errorf("sampleRate must be greater than or equal to 8000 for codec '%s'", t.Codec) + } if t.ChannelCount == 0 { return fmt.Errorf("channelCount is mandatory for codec '%s'", t.Codec) } diff --git a/internal/conf/conf_test.go b/internal/conf/conf_test.go index 14b7f31f..62bb66bf 100644 --- a/internal/conf/conf_test.go +++ b/internal/conf/conf_test.go @@ -841,6 +841,28 @@ func TestConfErrors(t *testing.T) { " alwaysAvailableFile: /path/to/file.mp4\n", "'alwaysAvailableFile' and 'alwaysAvailableTracks' cannot be used together", }, + { + "alwaysAvailableTracks g711 sampleRate too low", + "paths:\n" + + " mypath:\n" + + " alwaysAvailable: yes\n" + + " alwaysAvailableTracks:\n" + + " - codec: G711\n" + + " sampleRate: 7999\n" + + " channelCount: 1\n", + "sampleRate must be greater than or equal to 8000 for codec 'G711'", + }, + { + "alwaysAvailableTracks mpeg4audio sampleRate too low", + "paths:\n" + + " mypath:\n" + + " alwaysAvailable: yes\n" + + " alwaysAvailableTracks:\n" + + " - codec: MPEG4Audio\n" + + " sampleRate: 22049\n" + + " channelCount: 1\n", + "sampleRate must be greater than or equal to 22050 for codec 'MPEG4Audio'", + }, { "missing udp port", "paths:\n" +