适配引擎升级

This commit is contained in:
dexter
2023-02-01 11:00:36 +08:00
parent b44efd9749
commit f32f44db40
2 changed files with 16 additions and 13 deletions

View File

@@ -25,6 +25,10 @@ func (p *RTSPPublisher) SetTracks() error {
p.Tracks = make([]common.AVTrack, len(p.tracks))
defer func() {
for i, track := range p.Tracks {
if track == nil {
p.Info("unknown track", zap.String("codec", p.tracks[i].String()))
continue
}
p.Info("set track", zap.Int("trackId", i), zap.String("name", track.GetBase().Name))
}
}()
@@ -65,7 +69,7 @@ func (p *RTSPPublisher) SetTracks() error {
case "h264":
vt := NewH264(p.Stream)
if payloadType, err := strconv.Atoi(vals[0]); err == nil {
vt.DecoderConfiguration.PayloadType = byte(payloadType)
vt.PayloadType = byte(payloadType)
}
p.Tracks[trackId] = vt
t := track.(*gortsplib.TrackH264)
@@ -78,7 +82,7 @@ func (p *RTSPPublisher) SetTracks() error {
case "h265", "hevc":
vt := NewH265(p.Stream)
if payloadType, err := strconv.Atoi(vals[0]); err == nil {
vt.DecoderConfiguration.PayloadType = byte(payloadType)
vt.PayloadType = byte(payloadType)
}
p.Tracks[trackId] = vt
if v, ok := fmtp["sprop-vps"]; ok {
@@ -96,7 +100,7 @@ func (p *RTSPPublisher) SetTracks() error {
case "pcma":
at := NewG711(p.Stream, true)
if payloadType, err := strconv.Atoi(vals[0]); err == nil {
at.DecoderConfiguration.PayloadType = byte(payloadType)
at.PayloadType = byte(payloadType)
}
p.Tracks[trackId] = at
at.SampleRate = uint32(timeScale)
@@ -110,7 +114,7 @@ func (p *RTSPPublisher) SetTracks() error {
case "pcmu":
at := NewG711(p.Stream, false)
if payloadType, err := strconv.Atoi(vals[0]); err == nil {
at.DecoderConfiguration.PayloadType = byte(payloadType)
at.PayloadType = byte(payloadType)
}
p.Tracks[trackId] = at
at.SampleRate = uint32(timeScale)
@@ -124,13 +128,13 @@ func (p *RTSPPublisher) SetTracks() error {
case "mpeg4-generic":
at := NewAAC(p.Stream)
if payloadType, err := strconv.Atoi(vals[0]); err == nil {
at.DecoderConfiguration.PayloadType = byte(payloadType)
at.PayloadType = byte(payloadType)
}
p.Tracks[trackId] = at
if config, ok := fmtp["config"]; ok {
asc, _ := hex.DecodeString(config)
// 复用AVCC写入逻辑解析出AAC的配置信息
at.WriteAVCC(0, append([]byte{0xAF, 0}, asc...))
at.WriteAVCCSequenceHead(asc)
} else {
RTSPPlugin.Warn("aac no config")
}

View File

@@ -16,35 +16,34 @@ type RTSPSubscriber struct {
func (s *RTSPSubscriber) OnEvent(event any) {
switch v := event.(type) {
case *track.Video:
if s.Video.Track != nil {
if s.Video != nil {
return
}
switch v.CodecID {
case codec.CodecID_H264:
extra := v.DecoderConfiguration.Raw
vtrack := &gortsplib.TrackH264{
PayloadType: v.DecoderConfiguration.PayloadType, SPS: extra[0], PPS: extra[1],
PayloadType: v.PayloadType, SPS: v.ParamaterSets[0], PPS: v.ParamaterSets[1],
}
s.videoTrackId = len(s.tracks)
s.tracks = append(s.tracks, vtrack)
case codec.CodecID_H265:
vtrack := &gortsplib.TrackH265{
PayloadType: v.DecoderConfiguration.PayloadType, VPS: v.DecoderConfiguration.Raw[0], SPS: v.DecoderConfiguration.Raw[1], PPS: v.DecoderConfiguration.Raw[2],
PayloadType: v.PayloadType, VPS: v.ParamaterSets[0], SPS: v.ParamaterSets[1], PPS: v.ParamaterSets[2],
}
s.videoTrackId = len(s.tracks)
s.tracks = append(s.tracks, vtrack)
}
s.AddTrack(v)
case *track.Audio:
if s.Audio.Track != nil {
if s.Audio != nil {
return
}
switch v.CodecID {
case codec.CodecID_AAC:
var mpegConf mpeg4audio.Config
mpegConf.Unmarshal(v.DecoderConfiguration.Raw)
mpegConf.Unmarshal(v.SequenceHead[2:])
atrack := &gortsplib.TrackMPEG4Audio{
PayloadType: v.DecoderConfiguration.PayloadType, Config: &mpegConf, SizeLength: 13, IndexLength: 3, IndexDeltaLength: 3,
PayloadType: v.PayloadType, Config: &mpegConf, SizeLength: 13, IndexLength: 3, IndexDeltaLength: 3,
}
s.audioTrackId = len(s.tracks)
s.tracks = append(s.tracks, atrack)