From 3a2594d610552120442b251f9befdcbe405e8987 Mon Sep 17 00:00:00 2001 From: Jacob Su Date: Tue, 11 Jun 2024 19:26:45 +0800 Subject: [PATCH] rtmp: fix error when publishing AAC audio tracks (#3414) * fix single aac file rtmp publish error. * add tests --------- Co-authored-by: aler9 <46489434+aler9@users.noreply.github.com> --- internal/protocols/rtmp/reader.go | 3 ++ internal/protocols/rtmp/reader_test.go | 71 ++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) diff --git a/internal/protocols/rtmp/reader.go b/internal/protocols/rtmp/reader.go index 64f8042f..846a9e01 100644 --- a/internal/protocols/rtmp/reader.go +++ b/internal/protocols/rtmp/reader.go @@ -327,6 +327,9 @@ func tracksFromMetadata(conn *Conn, payload []interface{}) (format.Format, forma } if audioTrack == nil { + if len(msg.Payload) == 0 { + continue + } switch { case msg.Codec == message.CodecMPEG4Audio && msg.AACType == message.AudioAACTypeConfig: diff --git a/internal/protocols/rtmp/reader_test.go b/internal/protocols/rtmp/reader_test.go index 052eeb19..41d1d213 100644 --- a/internal/protocols/rtmp/reader_test.go +++ b/internal/protocols/rtmp/reader_test.go @@ -332,6 +332,77 @@ func TestReadTracks(t *testing.T) { }, }, }, + { + "aac, issue mediamtx/3414 (empty audio payload)", + nil, + &format.MPEG4Audio{ + PayloadTyp: 96, + Config: &mpeg4audio.Config{ + Type: 2, + SampleRate: 44100, + ChannelCount: 2, + }, + SizeLength: 13, + IndexLength: 3, + IndexDeltaLength: 3, + }, + []message.Message{ + &message.DataAMF0{ + ChunkStreamID: 4, + MessageStreamID: 1, + Payload: []interface{}{ + "@setDataFrame", + "onMetaData", + amf0.Object{ + { + Key: "videodatarate", + Value: float64(0), + }, + { + Key: "videocodecid", + Value: float64(0), + }, + { + Key: "audiodatarate", + Value: float64(0), + }, + { + Key: "audiocodecid", + Value: float64(message.CodecMPEG4Audio), + }, + }, + }, + }, + &message.Audio{ + ChunkStreamID: message.AudioChunkStreamID, + MessageStreamID: 0x1000000, + Codec: message.CodecMPEG4Audio, + Rate: message.Rate44100, + Depth: message.Depth16, + IsStereo: true, + AACType: message.AudioAACTypeConfig, + Payload: nil, + }, + &message.Audio{ + ChunkStreamID: message.AudioChunkStreamID, + MessageStreamID: 0x1000000, + Codec: message.CodecMPEG4Audio, + Rate: message.Rate44100, + Depth: message.Depth16, + IsStereo: true, + AACType: message.AudioAACTypeConfig, + Payload: func() []byte { + enc, err2 := mpeg4audio.Config{ + Type: 2, + SampleRate: 44100, + ChannelCount: 2, + }.Marshal() + require.NoError(t, err2) + return enc + }(), + }, + }, + }, { "h265 + aac, obs studio pre 29.1 h265", &format.H265{