add RTP/VP9 encoder and decoder (#152)

This commit is contained in:
Alessandro Ros
2022-11-14 18:46:26 +01:00
committed by GitHub
parent 34545becc3
commit e264304710
13 changed files with 537 additions and 27 deletions

View File

@@ -36,30 +36,26 @@ func main() {
}
// find the Opus track
opusTrack, opusTrackID := func() (*gortsplib.TrackOpus, int) {
for i, track := range tracks {
track := func() *gortsplib.TrackOpus {
for _, track := range tracks {
if tt, ok := track.(*gortsplib.TrackOpus); ok {
return tt, i
return tt
}
}
return nil, -1
return nil
}()
if opusTrack == nil {
if track == nil {
panic("Opus track not found")
}
// setup decoder
dec := &rtpopus.Decoder{
SampleRate: opusTrack.SampleRate,
SampleRate: track.SampleRate,
}
dec.Init()
// called when a RTP packet arrives
c.OnPacketRTP = func(ctx *gortsplib.ClientOnPacketRTPCtx) {
if ctx.TrackID != opusTrackID {
return
}
// decode an Opus packet from the RTP packet
op, _, err := dec.Decode(ctx.Packet)
if err != nil {
@@ -70,8 +66,8 @@ func main() {
log.Printf("received Opus packet of size %d\n", len(op))
}
// setup and read all tracks
err = c.SetupAndPlay(tracks, baseURL)
// setup and read the Opus track only
err = c.SetupAndPlay(gortsplib.Tracks{track}, baseURL)
if err != nil {
panic(err)
}