mirror of
https://github.com/aler9/gortsplib
synced 2025-10-30 18:16:29 +08:00
previous formula was: uint32(a + uint32(b)) this formula overflows two times, while it should overflow once. new formula is: uint32(uint64(a) + uint64(b))
27 lines
532 B
Go
27 lines
532 B
Go
package rtpsimpleaudio
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/pion/rtp"
|
|
|
|
"github.com/aler9/gortsplib/v2/pkg/rtptime"
|
|
)
|
|
|
|
// Decoder is a RTP/simple audio decoder.
|
|
type Decoder struct {
|
|
SampleRate int
|
|
|
|
timeDecoder *rtptime.Decoder
|
|
}
|
|
|
|
// Init initializes the decoder.
|
|
func (d *Decoder) Init() {
|
|
d.timeDecoder = rtptime.NewDecoder(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
|
|
}
|