simplify example

This commit is contained in:
aler9
2022-04-15 13:00:33 +02:00
parent 49e13c6c7b
commit 6781d4a92b

View File

@@ -36,38 +36,30 @@ func main() {
} }
// find the AAC track // find the AAC track
var clockRate int aacTrack, aacTrackID := func() (*gortsplib.TrackAAC, int) {
var sizeLength int
var indexLength int
var indexDeltaLength int
aacTrack := func() int {
for i, track := range tracks { for i, track := range tracks {
if tt, ok := track.(*gortsplib.TrackAAC); ok { if tt, ok := track.(*gortsplib.TrackAAC); ok {
clockRate = track.ClockRate() return tt, i
sizeLength = tt.SizeLength()
indexLength = tt.IndexLength()
indexDeltaLength = tt.IndexDeltaLength()
return i
} }
} }
return -1 return nil, -1
}() }()
if aacTrack < 0 { if aacTrack == nil {
panic("AAC track not found") panic("AAC track not found")
} }
// setup decoder // setup decoder
dec := &rtpaac.Decoder{ dec := &rtpaac.Decoder{
SampleRate: clockRate, SampleRate: aacTrack.ClockRate(),
SizeLength: sizeLength, SizeLength: aacTrack.SizeLength(),
IndexLength: indexLength, IndexLength: aacTrack.IndexLength(),
IndexDeltaLength: indexDeltaLength, IndexDeltaLength: aacTrack.IndexDeltaLength(),
} }
dec.Init() dec.Init()
// called when a RTP packet arrives // called when a RTP packet arrives
c.OnPacketRTP = func(ctx *gortsplib.ClientOnPacketRTPCtx) { c.OnPacketRTP = func(ctx *gortsplib.ClientOnPacketRTPCtx) {
if ctx.TrackID != aacTrack { if ctx.TrackID != aacTrackID {
return return
} }