From 0a7a44a1762e66b7fd6ec1ffd18040702f5c69a3 Mon Sep 17 00:00:00 2001 From: aler9 <46489434+aler9@users.noreply.github.com> Date: Sat, 22 Jun 2024 22:27:03 +0200 Subject: [PATCH] rtmp: fix publishing from DJI FlightHub Sync (#3301) --- internal/protocols/rtmp/reader.go | 6 ++- internal/protocols/rtmp/reader_test.go | 58 ++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 2 deletions(-) diff --git a/internal/protocols/rtmp/reader.go b/internal/protocols/rtmp/reader.go index 846a9e01c03..b111780b805 100644 --- a/internal/protocols/rtmp/reader.go +++ b/internal/protocols/rtmp/reader.go @@ -182,7 +182,7 @@ func tracksFromMetadata(conn *Conn, payload []interface{}) (format.Format, forma } if !hasVideo && !hasAudio { - return nil, nil, fmt.Errorf("metadata doesn't contain any track") + return nil, nil, nil } firstReceived := false @@ -523,7 +523,9 @@ func (r *Reader) readTracks() (format.Format, format.Format, error) { return nil, nil, err } - return videoTrack, audioTrack, nil + if videoTrack != nil || audioTrack != nil { + return videoTrack, audioTrack, nil + } } } } diff --git a/internal/protocols/rtmp/reader_test.go b/internal/protocols/rtmp/reader_test.go index 41d1d213df4..f5a2e9a5c5d 100644 --- a/internal/protocols/rtmp/reader_test.go +++ b/internal/protocols/rtmp/reader_test.go @@ -244,6 +244,64 @@ func TestReadTracks(t *testing.T) { return buf }(), }, + &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 + }(), + }, + }, + }, + { + "h264 + aac, issue mediamtx/3301 (metadata without tracks)", + &format.H264{ + PayloadTyp: 96, + SPS: test.FormatH264.SPS, + PPS: test.FormatH264.PPS, + PacketizationMode: 1, + }, + &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: "metadatacreator", + Value: "Agora.io SDK", + }, + { + Key: "encoder", + Value: "Agora.io Encoder", + }, + }, + }, + }, &message.Video{ ChunkStreamID: message.VideoChunkStreamID, MessageStreamID: 0x1000000,