对推流可能无法解析的情况进行报错

This commit is contained in:
dexter
2022-05-10 21:58:35 +08:00
parent 91e1726920
commit 76956b16d1
2 changed files with 10 additions and 4 deletions

View File

@@ -3,6 +3,8 @@ package rtsp
import (
"encoding/base64"
"encoding/hex"
"errors"
"fmt"
"strconv"
"strings"
@@ -18,14 +20,13 @@ type RTSPPublisher struct {
RTSPIO
}
func (p *RTSPPublisher) SetTracks() {
func (p *RTSPPublisher) SetTracks() error {
p.Tracks = make([]common.AVTrack, len(p.tracks))
for trackId, track := range p.tracks {
md := track.MediaDescription()
v, ok := md.Attribute("rtpmap")
if !ok {
p.Error("rtpmap attribute not found")
return
return errors.New("rtpmap attribute not found")
}
v = strings.TrimSpace(v)
vals := strings.Split(v, " ")
@@ -108,7 +109,10 @@ func (p *RTSPPublisher) SetTracks() {
} else {
plugin.Warn("aac no config")
}
default:
return fmt.Errorf("unsupport codec:%s", keyval[0])
}
}
}
return nil
}

View File

@@ -91,7 +91,9 @@ func (conf *RTSPConfig) OnAnnounce(ctx *gortsplib.ServerHandlerOnAnnounceCtx) (*
if err := plugin.Publish(ctx.Path, p); err == nil {
p.tracks = ctx.Tracks
p.stream = gortsplib.NewServerStream(ctx.Tracks)
p.SetTracks()
if err = p.SetTracks(); err != nil {
return nil, err
}
conf.Store(ctx.Conn, p)
conf.Store(ctx.Session, p)
} else {