Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Feb 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions internal/core/rtmp_conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,10 @@ func (c *rtmpConn) runPublish(ctx context.Context, u *url.URL) error {

switch tmsg := msg.(type) {
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 {
var conf h264conf.Conf
err = conf.Unmarshal(tmsg.Payload)
Expand All @@ -594,10 +598,6 @@ func (c *rtmpConn) runPublish(ctx context.Context, u *url.URL) error {
c.log(logger.Warn, "%v", err)
}
} 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)
if err != nil {
c.log(logger.Warn, "unable to decode AVCC: %v", err)
Expand All @@ -608,11 +608,11 @@ func (c *rtmpConn) runPublish(ctx context.Context, u *url.URL) error {
}

case *message.MsgAudio:
if tmsg.AACType == flvio.AAC_RAW {
if audioFormat == nil {
return fmt.Errorf("received an audio packet, but track is not set up")
}
if audioFormat == nil {
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{
PTS: tmsg.DTS,
AUs: [][]byte{tmsg.Payload},
Expand Down