From afec0cd86cd07375284cdac9c330743e2d58f667 Mon Sep 17 00:00:00 2001 From: Alessandro Ros Date: Mon, 1 Jul 2024 16:03:12 +0200 Subject: [PATCH] rtmp: fix publishing from DJI FlightHub Sync (#3301) (#3504) --- 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 846a9e01..b111780b 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 41d1d213..f5a2e9a5 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,