mirror of
https://github.com/aler9/gortsplib
synced 2025-09-27 03:25:52 +08:00
33 lines
625 B
Go
33 lines
625 B
Go
package rtplpcm
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/pion/rtp"
|
|
)
|
|
|
|
// Decoder is a RTP/LPCM decoder.
|
|
// Specification: https://datatracker.ietf.org/doc/html/rfc3190
|
|
type Decoder struct {
|
|
BitDepth int
|
|
ChannelCount int
|
|
|
|
sampleSize int
|
|
}
|
|
|
|
// Init initializes the decoder.
|
|
func (d *Decoder) Init() error {
|
|
d.sampleSize = d.BitDepth * d.ChannelCount / 8
|
|
return nil
|
|
}
|
|
|
|
// Decode decodes audio samples from a RTP packet.
|
|
func (d *Decoder) Decode(pkt *rtp.Packet) ([]byte, error) {
|
|
plen := len(pkt.Payload)
|
|
if (plen % d.sampleSize) != 0 {
|
|
return nil, fmt.Errorf("received payload of wrong size")
|
|
}
|
|
|
|
return pkt.Payload, nil
|
|
}
|