Skip to content

Commit

Permalink
rtmp: fix compatibility with DJI Osmo Action 4 (#3802)
Browse files Browse the repository at this point in the history
  • Loading branch information
aler9 committed Jan 6, 2025
1 parent 1342431 commit 475e93f
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 23 deletions.
26 changes: 10 additions & 16 deletions internal/protocols/rtmp/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,11 +381,7 @@ func (r *Reader) readTracks() (map[uint8]format.Format, map[uint8]format.Format,
}
curTime = msg.DTS

if msg.Type == message.VideoTypeConfig {
if videoTracks[0] != nil {
return nil, nil, fmt.Errorf("video track 0 already setupped")
}

if msg.Type == message.VideoTypeConfig && videoTracks[0] == nil {
videoTracks[0], err = h264TrackFromConfig(msg.Payload)
if err != nil {
return nil, nil, err
Expand Down Expand Up @@ -442,22 +438,20 @@ func (r *Reader) readTracks() (map[uint8]format.Format, map[uint8]format.Format,
}
curTime = msg.DTS

if msg.Codec == message.CodecMPEG4Audio {
if msg.AACType == message.AudioAACTypeConfig && len(msg.Payload) != 0 {
if audioTracks[0] != nil {
return nil, nil, fmt.Errorf("audio track 0 already setupped")
if audioTracks[0] == nil && len(msg.Payload) != 0 {
if msg.Codec == message.CodecMPEG4Audio {
if msg.AACType == message.AudioAACTypeConfig {
audioTracks[0], err = mpeg4AudioTrackFromConfig(msg.Payload)
if err != nil {
return nil, nil, err
}

Check warning on line 447 in internal/protocols/rtmp/reader.go

View check run for this annotation

Codecov / codecov/patch

internal/protocols/rtmp/reader.go#L446-L447

Added lines #L446 - L447 were not covered by tests
}

audioTracks[0], err = mpeg4AudioTrackFromConfig(msg.Payload)
} else {
audioTracks[0], err = audioTrackFromData(msg)
if err != nil {
return nil, nil, err
}
}
} else if audioTracks[0] == nil && len(msg.Payload) != 0 {
audioTracks[0], err = audioTrackFromData(msg)
if err != nil {
return nil, nil, err
}
}

case *message.AudioExSequenceStart:
Expand Down
89 changes: 82 additions & 7 deletions internal/protocols/rtmp/reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ func TestReadTracks(t *testing.T) {
},
},
{
"h264 + aac, issue mediamtx/386 (missing metadata)",
"issue mediamtx/386 (missing metadata)",
[]format.Format{
&format.H264{
PayloadTyp: 96,
Expand Down Expand Up @@ -278,7 +278,7 @@ func TestReadTracks(t *testing.T) {
},
},
{
"h264 + aac, issue mediamtx/3301 (metadata without tracks)",
"issue mediamtx/3301 (metadata without tracks)",
[]format.Format{
&format.H264{
PayloadTyp: 96,
Expand Down Expand Up @@ -353,7 +353,7 @@ func TestReadTracks(t *testing.T) {
},
},
{
"aac, issue mediamtx/386 (missing metadata)",
"issue mediamtx/386 (missing metadata)",
[]format.Format{
&format.MPEG4Audio{
PayloadTyp: 96,
Expand Down Expand Up @@ -399,7 +399,7 @@ func TestReadTracks(t *testing.T) {
},
},
{
"aac, issue mediamtx/3414 (empty audio payload)",
"issue mediamtx/3414 (empty audio payload)",
[]format.Format{
&format.MPEG4Audio{
PayloadTyp: 96,
Expand Down Expand Up @@ -481,7 +481,7 @@ func TestReadTracks(t *testing.T) {
},
},
{
"h265, issue mediamtx/2232 (xsplit broadcaster)",
"issue mediamtx/2232 (xsplit broadcaster)",
[]format.Format{
&format.H265{
PayloadTyp: 96,
Expand Down Expand Up @@ -669,7 +669,7 @@ func TestReadTracks(t *testing.T) {
},
},
{
"h264 + aac, issue mediamtx/2289 (missing videocodecid)",
"issue mediamtx/2289 (missing videocodecid)",
[]format.Format{
&format.H264{
PayloadTyp: 96,
Expand Down Expand Up @@ -758,7 +758,7 @@ func TestReadTracks(t *testing.T) {
},
},
{
"h264, issue mediamtx/2352",
"issue mediamtx/2352 (streamlabs)",
[]format.Format{
&format.H264{
PayloadTyp: 96,
Expand Down Expand Up @@ -1544,6 +1544,81 @@ func TestReadTracks(t *testing.T) {
},
},
},
{
"issue mediamtx/3802 (double video config)",
[]format.Format{
&format.H264{
PayloadTyp: 96,
SPS: test.FormatH264.SPS,
PPS: test.FormatH264.PPS,
PacketizationMode: 1,
},
},
[]message.Message{
&message.DataAMF0{
ChunkStreamID: 4,
MessageStreamID: 1,
Payload: []interface{}{
"@setDataFrame",
"onMetaData",
amf0.Object{
{
Key: "videodatarate",
Value: float64(0),
},
{
Key: "videocodecid",
Value: float64(message.CodecH264),
},
{
Key: "audiodatarate",
Value: float64(0),
},
{
Key: "audiocodecid",
Value: float64(0),
},
},
},
},
&message.Video{
ChunkStreamID: message.VideoChunkStreamID,
MessageStreamID: 0x1000000,
Codec: message.CodecH264,
IsKeyFrame: true,
Type: message.VideoTypeConfig,
Payload: func() []byte {
buf, _ := h264conf.Conf{
SPS: test.FormatH264.SPS,
PPS: test.FormatH264.PPS,
}.Marshal()
return buf
}(),
},
&message.Video{
ChunkStreamID: message.VideoChunkStreamID,
MessageStreamID: 0x1000000,
Codec: message.CodecH264,
IsKeyFrame: true,
Type: message.VideoTypeConfig,
Payload: func() []byte {
buf, _ := h264conf.Conf{
SPS: test.FormatH264.SPS,
PPS: test.FormatH264.PPS,
}.Marshal()
return buf
}(),
},
&message.Video{
ChunkStreamID: message.VideoChunkStreamID,
DTS: 2 * time.Second,
MessageStreamID: 0x1000000,
Codec: message.CodecH264,
IsKeyFrame: true,
Type: message.VideoTypeAU,
},
},
},
} {
t.Run(ca.name, func(t *testing.T) {
var buf bytes.Buffer
Expand Down

0 comments on commit 475e93f

Please sign in to comment.