mirror of
https://github.com/aler9/gortsplib
synced 2025-10-06 07:37:07 +08:00

* split tracks from medias * move tracks into dedicated package * move media into dedicated package * edit Medias.Marshal() in order to return SDP * add medias.Find() and simplify examples * improve coverage * fix rebase errors * replace TrackIDs with MediaIDs * implement media-specific and track-specific callbacks for reading RTCP and RTP packets * rename publish into record, read into play * add v2 tag * rename tracks into formats
27 lines
534 B
Go
27 lines
534 B
Go
package rtpsimpleaudio
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/pion/rtp"
|
|
|
|
"github.com/aler9/gortsplib/v2/pkg/rtptimedec"
|
|
)
|
|
|
|
// Decoder is a RTP/simple audio decoder.
|
|
type Decoder struct {
|
|
SampleRate int
|
|
|
|
timeDecoder *rtptimedec.Decoder
|
|
}
|
|
|
|
// Init initializes the decoder.
|
|
func (d *Decoder) Init() {
|
|
d.timeDecoder = rtptimedec.New(d.SampleRate)
|
|
}
|
|
|
|
// Decode decodes an audio frame from a RTP packet.
|
|
func (d *Decoder) Decode(pkt *rtp.Packet) ([]byte, time.Duration, error) {
|
|
return pkt.Payload, d.timeDecoder.Decode(pkt.Timestamp), nil
|
|
}
|