Browse Source

rtmp: fix crash when publishing video-only tracks (#1819) (#1822)

this fixes a regression introduced in v0.23.0.
pull/1824/head
Alessandro Ros 3 years ago committed by GitHub
parent
commit
bbd8f006fe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      README.md
  2. 6
      internal/rtmp/tracks/read.go
  3. 65
      internal/rtmp/tracks/read_test.go

2
README.md

@ -1217,7 +1217,7 @@ For more advanced options, you can create and serve a custom web page by startin
* WebRTC * WebRTC
* [WebRTC: Real-Time Communication in Browsers](https://www.w3.org/TR/webrtc/) * [WebRTC: Real-Time Communication in Browsers](https://www.w3.org/TR/webrtc/)
* [WebRTC Ingestion Protocol (WHIP)](https://datatracker.ietf.org/doc/draft-ietf-wish-whip/) * [WebRTC HTTP Ingestion Protocol (WHIP)](https://datatracker.ietf.org/doc/draft-ietf-wish-whip/)
* [WebRTC HTTP Egress Protocol (WHEP)](https://datatracker.ietf.org/doc/draft-murillo-whep/) * [WebRTC HTTP Egress Protocol (WHEP)](https://datatracker.ietf.org/doc/draft-murillo-whep/)
* Video and audio codecs * Video and audio codecs

6
internal/rtmp/tracks/read.go

@ -44,7 +44,7 @@ func trackFromH264DecoderConfig(data []byte) (formats.Format, error) {
}, nil }, nil
} }
func trackFromAACDecoderConfig(data []byte) (*formats.MPEG4Audio, error) { func trackFromAACDecoderConfig(data []byte) (formats.Format, error) {
var mpegConf mpeg4audio.Config var mpegConf mpeg4audio.Config
err := mpegConf.Unmarshal(data) err := mpegConf.Unmarshal(data)
if err != nil { if err != nil {
@ -261,10 +261,10 @@ func readTracksFromMetadata(r *message.ReadWriter, payload []interface{}) (forma
} }
} }
func readTracksFromMessages(r *message.ReadWriter, msg message.Message) (formats.Format, *formats.MPEG4Audio, error) { func readTracksFromMessages(r *message.ReadWriter, msg message.Message) (formats.Format, formats.Format, error) {
var startTime *time.Duration var startTime *time.Duration
var videoTrack formats.Format var videoTrack formats.Format
var audioTrack *formats.MPEG4Audio var audioTrack formats.Format
// analyze 1 second of packets // analyze 1 second of packets
outer: outer:

65
internal/rtmp/tracks/read_test.go

@ -63,7 +63,7 @@ func TestRead(t *testing.T) {
nil, nil,
}, },
{ {
"metadata without codec id", "metadata without codec id, video+audio",
&formats.H264{ &formats.H264{
PayloadTyp: 96, PayloadTyp: 96,
SPS: sps, SPS: sps,
@ -82,6 +82,16 @@ func TestRead(t *testing.T) {
IndexDeltaLength: 3, IndexDeltaLength: 3,
}, },
}, },
{
"metadata without codec id, video only",
&formats.H264{
PayloadTyp: 96,
SPS: sps,
PPS: pps,
PacketizationMode: 1,
},
nil,
},
{ {
"missing metadata, video+audio", "missing metadata, video+audio",
&formats.H264{ &formats.H264{
@ -266,7 +276,7 @@ func TestRead(t *testing.T) {
}) })
require.NoError(t, err) require.NoError(t, err)
case "metadata without codec id": case "metadata without codec id, video+audio":
err := mrw.Write(&message.DataAMF0{ err := mrw.Write(&message.DataAMF0{
ChunkStreamID: 4, ChunkStreamID: 4,
MessageStreamID: 1, MessageStreamID: 1,
@ -325,6 +335,57 @@ func TestRead(t *testing.T) {
}) })
require.NoError(t, err) require.NoError(t, err)
case "metadata without codec id, video only":
err := mrw.Write(&message.DataAMF0{
ChunkStreamID: 4,
MessageStreamID: 1,
Payload: []interface{}{
"@setDataFrame",
"onMetaData",
flvio.AMFMap{
{
K: "width",
V: float64(2688),
},
{
K: "height",
V: float64(1520),
},
{
K: "framerate",
V: float64(0o25),
},
},
},
})
require.NoError(t, err)
buf, _ := h264conf.Conf{
SPS: sps,
PPS: pps,
}.Marshal()
err = mrw.Write(&message.Video{
ChunkStreamID: message.VideoChunkStreamID,
MessageStreamID: 0x1000000,
Codec: message.CodecH264,
IsKeyFrame: true,
Type: message.VideoTypeConfig,
Payload: buf,
})
require.NoError(t, err)
err = mrw.Write(&message.Video{
ChunkStreamID: message.VideoChunkStreamID,
MessageStreamID: 0x1000000,
Codec: message.CodecH264,
IsKeyFrame: true,
Type: message.VideoTypeAU,
Payload: []byte{0x01, 0x02, 0x03, 0x04},
DTS: 1 * time.Second,
})
require.NoError(t, err)
case "missing metadata, video+audio": case "missing metadata, video+audio":
buf, _ := h264conf.Conf{ buf, _ := h264conf.Conf{
SPS: sps, SPS: sps,

Loading…
Cancel
Save