Browse Source

rtmp: fix crash when receiving unexpected video packets (#1459) (#1504)

pull/1506/head
Alessandro Ros 3 years ago committed by GitHub
parent
commit
2cffea6d51
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 10
      internal/core/rtmp_conn.go

10
internal/core/rtmp_conn.go

@ -573,6 +573,10 @@ func (c *rtmpConn) runPublish(ctx context.Context, u *url.URL) error {
switch tmsg := msg.(type) { switch tmsg := msg.(type) {
case *message.MsgVideo: case *message.MsgVideo:
if videoFormat == nil {
return fmt.Errorf("received a video packet, but track is not set up")
}
if tmsg.H264Type == flvio.AVC_SEQHDR { if tmsg.H264Type == flvio.AVC_SEQHDR {
var conf h264conf.Conf var conf h264conf.Conf
err = conf.Unmarshal(tmsg.Payload) err = conf.Unmarshal(tmsg.Payload)
@ -594,10 +598,6 @@ func (c *rtmpConn) runPublish(ctx context.Context, u *url.URL) error {
c.log(logger.Warn, "%v", err) c.log(logger.Warn, "%v", err)
} }
} else if tmsg.H264Type == flvio.AVC_NALU { } else if tmsg.H264Type == flvio.AVC_NALU {
if videoFormat == nil {
return fmt.Errorf("received a video packet, but track is not set up")
}
au, err := h264.AVCCUnmarshal(tmsg.Payload) au, err := h264.AVCCUnmarshal(tmsg.Payload)
if err != nil { if err != nil {
c.log(logger.Warn, "unable to decode AVCC: %v", err) c.log(logger.Warn, "unable to decode AVCC: %v", err)
@ -608,11 +608,11 @@ func (c *rtmpConn) runPublish(ctx context.Context, u *url.URL) error {
} }
case *message.MsgAudio: case *message.MsgAudio:
if tmsg.AACType == flvio.AAC_RAW {
if audioFormat == nil { if audioFormat == nil {
return fmt.Errorf("received an audio packet, but track is not set up") return fmt.Errorf("received an audio packet, but track is not set up")
} }
if tmsg.AACType == flvio.AAC_RAW {
err := rres.stream.writeData(audioMedia, audioFormat, &formatprocessor.DataMPEG4Audio{ err := rres.stream.writeData(audioMedia, audioFormat, &formatprocessor.DataMPEG4Audio{
PTS: tmsg.DTS, PTS: tmsg.DTS,
AUs: [][]byte{tmsg.Payload}, AUs: [][]byte{tmsg.Payload},

Loading…
Cancel
Save