mirror of
https://github.com/aler9/gortsplib
synced 2025-10-06 15:46:51 +08:00
add RTP encoder/decoder for G722, PCMA, PCMU
This commit is contained in:
24
README.md
24
README.md
@@ -29,6 +29,7 @@ Features:
|
|||||||
* Switch transport protocol automatically
|
* Switch transport protocol automatically
|
||||||
* Pause without disconnecting from the server
|
* Pause without disconnecting from the server
|
||||||
* Generate RTCP sender reports
|
* Generate RTCP sender reports
|
||||||
|
|
||||||
* Server
|
* Server
|
||||||
* Handle requests from clients
|
* Handle requests from clients
|
||||||
* Sessions and connections are independent
|
* Sessions and connections are independent
|
||||||
@@ -42,13 +43,23 @@ Features:
|
|||||||
* Write TLS-encrypted streams
|
* Write TLS-encrypted streams
|
||||||
* Compute and provide SSRC, RTP-Info to clients
|
* Compute and provide SSRC, RTP-Info to clients
|
||||||
* Generate RTCP sender reports
|
* Generate RTCP sender reports
|
||||||
|
|
||||||
* Utilities
|
* Utilities
|
||||||
|
* Encode and decode codec-specific frames to/from RTP packets. The following codecs are supported:
|
||||||
|
* Video
|
||||||
|
* H264
|
||||||
|
* VP8
|
||||||
|
* VP9
|
||||||
|
* Audio
|
||||||
|
* G722
|
||||||
|
* LPCM
|
||||||
|
* MPEG4-Audio (AAC)
|
||||||
|
* Opus
|
||||||
|
* PCMA
|
||||||
|
* PCMU
|
||||||
* Parse RTSP elements: requests, responses, SDP
|
* Parse RTSP elements: requests, responses, SDP
|
||||||
* Parse H264 elements and formats: RTP/H264, Annex-B, AVCC, anti-competition, DTS
|
* Parse H264 elements and formats: Annex-B, AVCC, anti-competition, DTS
|
||||||
* Parse MPEG4-audio (AAC) elements and formats: RTP/MPEG4-audio, ADTS, MPEG4-audio configurations
|
* Parse MPEG4-audio (AAC) element and formats: ADTS, MPEG4-audio configurations
|
||||||
* Parse Opus elements: RTP/Opus
|
|
||||||
* Parse VP8 elements: RTP/VP8
|
|
||||||
* Parse VP9 elements: RTP/VP9
|
|
||||||
|
|
||||||
## Table of contents
|
## Table of contents
|
||||||
|
|
||||||
@@ -60,11 +71,14 @@ Features:
|
|||||||
|
|
||||||
* [client-query](examples/client-query/main.go)
|
* [client-query](examples/client-query/main.go)
|
||||||
* [client-read](examples/client-read/main.go)
|
* [client-read](examples/client-read/main.go)
|
||||||
|
* [client-read-codec-g722](examples/client-read-codec-g722/main.go)
|
||||||
* [client-read-codec-h264](examples/client-read-codec-h264/main.go)
|
* [client-read-codec-h264](examples/client-read-codec-h264/main.go)
|
||||||
* [client-read-codec-h264-convert-to-jpeg](examples/client-read-codec-h264-convert-to-jpeg/main.go)
|
* [client-read-codec-h264-convert-to-jpeg](examples/client-read-codec-h264-convert-to-jpeg/main.go)
|
||||||
* [client-read-codec-h264-save-to-disk](examples/client-read-codec-h264-save-to-disk/main.go)
|
* [client-read-codec-h264-save-to-disk](examples/client-read-codec-h264-save-to-disk/main.go)
|
||||||
* [client-read-codec-mpeg4audio](examples/client-read-codec-mpeg4audio/main.go)
|
* [client-read-codec-mpeg4audio](examples/client-read-codec-mpeg4audio/main.go)
|
||||||
* [client-read-codec-opus](examples/client-read-codec-opus/main.go)
|
* [client-read-codec-opus](examples/client-read-codec-opus/main.go)
|
||||||
|
* [client-read-codec-pcma](examples/client-read-codec-pcma/main.go)
|
||||||
|
* [client-read-codec-pcmu](examples/client-read-codec-pcmu/main.go)
|
||||||
* [client-read-codec-vp8](examples/client-read-codec-vp8/main.go)
|
* [client-read-codec-vp8](examples/client-read-codec-vp8/main.go)
|
||||||
* [client-read-codec-vp9](examples/client-read-codec-vp9/main.go)
|
* [client-read-codec-vp9](examples/client-read-codec-vp9/main.go)
|
||||||
* [client-read-partial](examples/client-read-partial/main.go)
|
* [client-read-partial](examples/client-read-partial/main.go)
|
||||||
|
73
examples/client-read-codec-g722/main.go
Normal file
73
examples/client-read-codec-g722/main.go
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log"
|
||||||
|
|
||||||
|
"github.com/aler9/gortsplib"
|
||||||
|
"github.com/aler9/gortsplib/pkg/url"
|
||||||
|
)
|
||||||
|
|
||||||
|
// This example shows how to
|
||||||
|
// 1. connect to a RTSP server and read all tracks on a path
|
||||||
|
// 2. check if there's a G722 track
|
||||||
|
// 3. get G722 frames of that track
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
c := gortsplib.Client{}
|
||||||
|
|
||||||
|
// parse URL
|
||||||
|
u, err := url.Parse("rtsp://localhost:8554/mystream")
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// connect to the server
|
||||||
|
err = c.Start(u.Scheme, u.Host)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
defer c.Close()
|
||||||
|
|
||||||
|
// find published tracks
|
||||||
|
tracks, baseURL, _, err := c.Describe(u)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// find the G722 track
|
||||||
|
track := func() *gortsplib.TrackG722 {
|
||||||
|
for _, track := range tracks {
|
||||||
|
if tt, ok := track.(*gortsplib.TrackG722); ok {
|
||||||
|
return tt
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}()
|
||||||
|
if track == nil {
|
||||||
|
panic("G722 track not found")
|
||||||
|
}
|
||||||
|
|
||||||
|
// setup decoder
|
||||||
|
dec := track.CreateDecoder()
|
||||||
|
|
||||||
|
// called when a RTP packet arrives
|
||||||
|
c.OnPacketRTP = func(ctx *gortsplib.ClientOnPacketRTPCtx) {
|
||||||
|
// decode an G722 packet from the RTP packet
|
||||||
|
op, _, err := dec.Decode(ctx.Packet)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// print
|
||||||
|
log.Printf("received G722 frame of size %d\n", len(op))
|
||||||
|
}
|
||||||
|
|
||||||
|
// setup and read the G722 track only
|
||||||
|
err = c.SetupAndPlay(gortsplib.Tracks{track}, baseURL)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// wait until a fatal error
|
||||||
|
panic(c.Wait())
|
||||||
|
}
|
73
examples/client-read-codec-pcma/main.go
Normal file
73
examples/client-read-codec-pcma/main.go
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log"
|
||||||
|
|
||||||
|
"github.com/aler9/gortsplib"
|
||||||
|
"github.com/aler9/gortsplib/pkg/url"
|
||||||
|
)
|
||||||
|
|
||||||
|
// This example shows how to
|
||||||
|
// 1. connect to a RTSP server and read all tracks on a path
|
||||||
|
// 2. check if there's a PCMA track
|
||||||
|
// 3. get PCMA frames of that track
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
c := gortsplib.Client{}
|
||||||
|
|
||||||
|
// parse URL
|
||||||
|
u, err := url.Parse("rtsp://localhost:8554/mystream")
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// connect to the server
|
||||||
|
err = c.Start(u.Scheme, u.Host)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
defer c.Close()
|
||||||
|
|
||||||
|
// find published tracks
|
||||||
|
tracks, baseURL, _, err := c.Describe(u)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// find the PCMA track
|
||||||
|
track := func() *gortsplib.TrackPCMA {
|
||||||
|
for _, track := range tracks {
|
||||||
|
if tt, ok := track.(*gortsplib.TrackPCMA); ok {
|
||||||
|
return tt
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}()
|
||||||
|
if track == nil {
|
||||||
|
panic("PCMA track not found")
|
||||||
|
}
|
||||||
|
|
||||||
|
// setup decoder
|
||||||
|
dec := track.CreateDecoder()
|
||||||
|
|
||||||
|
// called when a RTP packet arrives
|
||||||
|
c.OnPacketRTP = func(ctx *gortsplib.ClientOnPacketRTPCtx) {
|
||||||
|
// decode an PCMA packet from the RTP packet
|
||||||
|
op, _, err := dec.Decode(ctx.Packet)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// print
|
||||||
|
log.Printf("received PCMA frame of size %d\n", len(op))
|
||||||
|
}
|
||||||
|
|
||||||
|
// setup and read the PCMA track only
|
||||||
|
err = c.SetupAndPlay(gortsplib.Tracks{track}, baseURL)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// wait until a fatal error
|
||||||
|
panic(c.Wait())
|
||||||
|
}
|
73
examples/client-read-codec-pcmu/main.go
Normal file
73
examples/client-read-codec-pcmu/main.go
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log"
|
||||||
|
|
||||||
|
"github.com/aler9/gortsplib"
|
||||||
|
"github.com/aler9/gortsplib/pkg/url"
|
||||||
|
)
|
||||||
|
|
||||||
|
// This example shows how to
|
||||||
|
// 1. connect to a RTSP server and read all tracks on a path
|
||||||
|
// 2. check if there's a PCMU track
|
||||||
|
// 3. get PCMU frames of that track
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
c := gortsplib.Client{}
|
||||||
|
|
||||||
|
// parse URL
|
||||||
|
u, err := url.Parse("rtsp://localhost:8554/mystream")
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// connect to the server
|
||||||
|
err = c.Start(u.Scheme, u.Host)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
defer c.Close()
|
||||||
|
|
||||||
|
// find published tracks
|
||||||
|
tracks, baseURL, _, err := c.Describe(u)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// find the PCMU track
|
||||||
|
track := func() *gortsplib.TrackPCMU {
|
||||||
|
for _, track := range tracks {
|
||||||
|
if tt, ok := track.(*gortsplib.TrackPCMU); ok {
|
||||||
|
return tt
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}()
|
||||||
|
if track == nil {
|
||||||
|
panic("PCMU track not found")
|
||||||
|
}
|
||||||
|
|
||||||
|
// setup decoder
|
||||||
|
dec := track.CreateDecoder()
|
||||||
|
|
||||||
|
// called when a RTP packet arrives
|
||||||
|
c.OnPacketRTP = func(ctx *gortsplib.ClientOnPacketRTPCtx) {
|
||||||
|
// decode an PCMU packet from the RTP packet
|
||||||
|
op, _, err := dec.Decode(ctx.Packet)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// print
|
||||||
|
log.Printf("received PCMU frame of size %d\n", len(op))
|
||||||
|
}
|
||||||
|
|
||||||
|
// setup and read the PCMU track only
|
||||||
|
err = c.SetupAndPlay(gortsplib.Tracks{track}, baseURL)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// wait until a fatal error
|
||||||
|
panic(c.Wait())
|
||||||
|
}
|
@@ -1,2 +0,0 @@
|
|||||||
// Package rtpopus contains a RTP/Opus decoder and encoder.
|
|
||||||
package rtpopus
|
|
@@ -1,20 +1,17 @@
|
|||||||
package rtpopus
|
package rtpsimpleaudio
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/pion/rtp"
|
"github.com/pion/rtp"
|
||||||
"github.com/pion/rtp/codecs"
|
|
||||||
|
|
||||||
"github.com/aler9/gortsplib/pkg/rtptimedec"
|
"github.com/aler9/gortsplib/pkg/rtptimedec"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Decoder is a RTP/Opus decoder.
|
// Decoder is a RTP/simple audio decoder.
|
||||||
type Decoder struct {
|
type Decoder struct {
|
||||||
// sample rate of input packets.
|
|
||||||
SampleRate int
|
SampleRate int
|
||||||
|
|
||||||
cop codecs.OpusPacket
|
|
||||||
timeDecoder *rtptimedec.Decoder
|
timeDecoder *rtptimedec.Decoder
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -23,9 +20,7 @@ func (d *Decoder) Init() {
|
|||||||
d.timeDecoder = rtptimedec.New(d.SampleRate)
|
d.timeDecoder = rtptimedec.New(d.SampleRate)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Decode decodes a Opus packet from a RTP/Opus packet.
|
// Decode decodes an audio frame from a RTP packet.
|
||||||
// It returns the Opus packet and its PTS.
|
|
||||||
func (d *Decoder) Decode(pkt *rtp.Packet) ([]byte, time.Duration, error) {
|
func (d *Decoder) Decode(pkt *rtp.Packet) ([]byte, time.Duration, error) {
|
||||||
_, err := d.cop.Unmarshal(pkt.Payload)
|
return pkt.Payload, d.timeDecoder.Decode(pkt.Timestamp), nil
|
||||||
return d.cop.Payload, d.timeDecoder.Decode(pkt.Timestamp), err
|
|
||||||
}
|
}
|
@@ -1,4 +1,4 @@
|
|||||||
package rtpopus
|
package rtpsimpleaudio
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
@@ -9,22 +9,22 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var cases = []struct {
|
var cases = []struct {
|
||||||
name string
|
name string
|
||||||
op []byte
|
frame []byte
|
||||||
pts time.Duration
|
pts time.Duration
|
||||||
pkt *rtp.Packet
|
pkt *rtp.Packet
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
"a",
|
"single",
|
||||||
[]byte{0x01, 0x02, 0x03, 0x04},
|
[]byte{0x01, 0x02, 0x03, 0x04},
|
||||||
20 * time.Millisecond,
|
25 * time.Millisecond,
|
||||||
&rtp.Packet{
|
&rtp.Packet{
|
||||||
Header: rtp.Header{
|
Header: rtp.Header{
|
||||||
Version: 2,
|
Version: 2,
|
||||||
Marker: true,
|
Marker: false,
|
||||||
PayloadType: 96,
|
PayloadType: 0,
|
||||||
SequenceNumber: 17645,
|
SequenceNumber: 17645,
|
||||||
Timestamp: 2289527317,
|
Timestamp: 2289526557,
|
||||||
SSRC: 0x9dbb7812,
|
SSRC: 0x9dbb7812,
|
||||||
},
|
},
|
||||||
Payload: []byte{0x01, 0x02, 0x03, 0x04},
|
Payload: []byte{0x01, 0x02, 0x03, 0x04},
|
||||||
@@ -36,7 +36,7 @@ func TestDecode(t *testing.T) {
|
|||||||
for _, ca := range cases {
|
for _, ca := range cases {
|
||||||
t.Run(ca.name, func(t *testing.T) {
|
t.Run(ca.name, func(t *testing.T) {
|
||||||
d := &Decoder{
|
d := &Decoder{
|
||||||
SampleRate: 48000,
|
SampleRate: 8000,
|
||||||
}
|
}
|
||||||
d.Init()
|
d.Init()
|
||||||
|
|
||||||
@@ -46,22 +46,22 @@ func TestDecode(t *testing.T) {
|
|||||||
pkt := rtp.Packet{
|
pkt := rtp.Packet{
|
||||||
Header: rtp.Header{
|
Header: rtp.Header{
|
||||||
Version: 2,
|
Version: 2,
|
||||||
Marker: true,
|
Marker: false,
|
||||||
PayloadType: 96,
|
PayloadType: 0,
|
||||||
SequenceNumber: 17645,
|
SequenceNumber: 17645,
|
||||||
Timestamp: 2289526357,
|
Timestamp: 2289526357,
|
||||||
SSRC: 0x9dbb7812,
|
SSRC: 0x9dbb7812,
|
||||||
},
|
},
|
||||||
Payload: []byte{0x00},
|
Payload: []byte{0x01, 0x02, 0x03, 0x04},
|
||||||
}
|
}
|
||||||
|
|
||||||
_, _, err := d.Decode(&pkt)
|
_, _, err := d.Decode(&pkt)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
op, pts, err := d.Decode(ca.pkt)
|
frame, pts, err := d.Decode(ca.pkt)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, ca.op, op)
|
|
||||||
require.Equal(t, ca.pts, pts)
|
require.Equal(t, ca.pts, pts)
|
||||||
|
|
||||||
|
require.Equal(t, ca.frame, frame)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -1,4 +1,4 @@
|
|||||||
package rtpopus
|
package rtpsimpleaudio
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
@@ -6,7 +6,6 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/pion/rtp"
|
"github.com/pion/rtp"
|
||||||
"github.com/pion/rtp/codecs"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -19,7 +18,7 @@ func randUint32() uint32 {
|
|||||||
return uint32(b[0])<<24 | uint32(b[1])<<16 | uint32(b[2])<<8 | uint32(b[3])
|
return uint32(b[0])<<24 | uint32(b[1])<<16 | uint32(b[2])<<8 | uint32(b[3])
|
||||||
}
|
}
|
||||||
|
|
||||||
// Encoder is a RTP/Opus encoder.
|
// Encoder is a RTP/simple audio encoder.
|
||||||
type Encoder struct {
|
type Encoder struct {
|
||||||
// payload type of packets.
|
// payload type of packets.
|
||||||
PayloadType uint8
|
PayloadType uint8
|
||||||
@@ -40,11 +39,9 @@ type Encoder struct {
|
|||||||
// It defaults to 1460.
|
// It defaults to 1460.
|
||||||
PayloadMaxSize int
|
PayloadMaxSize int
|
||||||
|
|
||||||
// sample rate of packets.
|
|
||||||
SampleRate int
|
SampleRate int
|
||||||
|
|
||||||
sequenceNumber uint16
|
sequenceNumber uint16
|
||||||
op codecs.OpusPayloader
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Init initializes the encoder.
|
// Init initializes the encoder.
|
||||||
@@ -72,10 +69,10 @@ func (e *Encoder) encodeTimestamp(ts time.Duration) uint32 {
|
|||||||
return *e.InitialTimestamp + uint32(ts.Seconds()*float64(e.SampleRate))
|
return *e.InitialTimestamp + uint32(ts.Seconds()*float64(e.SampleRate))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Encode encodes an Opus packet into a RTP/Opus packet.
|
// Encode encodes an audio frame into a RTP packet.
|
||||||
func (e *Encoder) Encode(op []byte, pts time.Duration) (*rtp.Packet, error) {
|
func (e *Encoder) Encode(frame []byte, pts time.Duration) (*rtp.Packet, error) {
|
||||||
if len(op) > e.PayloadMaxSize {
|
if len(frame) > e.PayloadMaxSize {
|
||||||
return nil, fmt.Errorf("packet size exceeds maximum size")
|
return nil, fmt.Errorf("frame is too big")
|
||||||
}
|
}
|
||||||
|
|
||||||
pkt := &rtp.Packet{
|
pkt := &rtp.Packet{
|
||||||
@@ -85,9 +82,9 @@ func (e *Encoder) Encode(op []byte, pts time.Duration) (*rtp.Packet, error) {
|
|||||||
SequenceNumber: e.sequenceNumber,
|
SequenceNumber: e.sequenceNumber,
|
||||||
Timestamp: e.encodeTimestamp(pts),
|
Timestamp: e.encodeTimestamp(pts),
|
||||||
SSRC: *e.SSRC,
|
SSRC: *e.SSRC,
|
||||||
Marker: true,
|
Marker: false,
|
||||||
},
|
},
|
||||||
Payload: e.op.Payload(0, op)[0],
|
Payload: frame,
|
||||||
}
|
}
|
||||||
|
|
||||||
e.sequenceNumber++
|
e.sequenceNumber++
|
@@ -1,4 +1,4 @@
|
|||||||
package rtpopus
|
package rtpsimpleaudio
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
@@ -10,8 +10,8 @@ func TestEncode(t *testing.T) {
|
|||||||
for _, ca := range cases {
|
for _, ca := range cases {
|
||||||
t.Run(ca.name, func(t *testing.T) {
|
t.Run(ca.name, func(t *testing.T) {
|
||||||
e := &Encoder{
|
e := &Encoder{
|
||||||
PayloadType: 96,
|
PayloadType: 0,
|
||||||
SampleRate: 48000,
|
SampleRate: 8000,
|
||||||
SSRC: func() *uint32 {
|
SSRC: func() *uint32 {
|
||||||
v := uint32(0x9dbb7812)
|
v := uint32(0x9dbb7812)
|
||||||
return &v
|
return &v
|
||||||
@@ -27,7 +27,7 @@ func TestEncode(t *testing.T) {
|
|||||||
}
|
}
|
||||||
e.Init()
|
e.Init()
|
||||||
|
|
||||||
pkt, err := e.Encode(ca.op, ca.pts)
|
pkt, err := e.Encode(ca.frame, ca.pts)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, ca.pkt, pkt)
|
require.Equal(t, ca.pkt, pkt)
|
||||||
})
|
})
|
||||||
@@ -36,8 +36,8 @@ func TestEncode(t *testing.T) {
|
|||||||
|
|
||||||
func TestEncodeRandomInitialState(t *testing.T) {
|
func TestEncodeRandomInitialState(t *testing.T) {
|
||||||
e := &Encoder{
|
e := &Encoder{
|
||||||
PayloadType: 96,
|
PayloadType: 0,
|
||||||
SampleRate: 48000,
|
SampleRate: 8000,
|
||||||
}
|
}
|
||||||
e.Init()
|
e.Init()
|
||||||
require.NotEqual(t, nil, e.SSRC)
|
require.NotEqual(t, nil, e.SSRC)
|
2
pkg/rtpsimpleaudio/rtpsimpleaudio.go
Normal file
2
pkg/rtpsimpleaudio/rtpsimpleaudio.go
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
// Package rtpsimpleaudio contains a RTP decoder and encoder for audio codecs that fit in a single packet.
|
||||||
|
package rtpsimpleaudio
|
@@ -5,6 +5,8 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
psdp "github.com/pion/sdp/v3"
|
psdp "github.com/pion/sdp/v3"
|
||||||
|
|
||||||
|
"github.com/aler9/gortsplib/pkg/rtpsimpleaudio"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TrackG722 is a G722 track.
|
// TrackG722 is a G722 track.
|
||||||
@@ -60,3 +62,12 @@ func (t *TrackG722) clone() Track {
|
|||||||
trackBase: t.trackBase,
|
trackBase: t.trackBase,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CreateDecoder creates a decoder able to decode the content of the track.
|
||||||
|
func (t *TrackG722) CreateDecoder() *rtpsimpleaudio.Decoder {
|
||||||
|
d := &rtpsimpleaudio.Decoder{
|
||||||
|
SampleRate: 8000,
|
||||||
|
}
|
||||||
|
d.Init()
|
||||||
|
return d
|
||||||
|
}
|
||||||
|
@@ -7,7 +7,7 @@ import (
|
|||||||
|
|
||||||
psdp "github.com/pion/sdp/v3"
|
psdp "github.com/pion/sdp/v3"
|
||||||
|
|
||||||
"github.com/aler9/gortsplib/pkg/rtpopus"
|
"github.com/aler9/gortsplib/pkg/rtpsimpleaudio"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TrackOpus is a Opus track.
|
// TrackOpus is a Opus track.
|
||||||
@@ -97,8 +97,8 @@ func (t *TrackOpus) clone() Track {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// CreateDecoder creates a decoder able to decode the content of the track.
|
// CreateDecoder creates a decoder able to decode the content of the track.
|
||||||
func (t *TrackOpus) CreateDecoder() *rtpopus.Decoder {
|
func (t *TrackOpus) CreateDecoder() *rtpsimpleaudio.Decoder {
|
||||||
d := &rtpopus.Decoder{
|
d := &rtpsimpleaudio.Decoder{
|
||||||
SampleRate: t.SampleRate,
|
SampleRate: t.SampleRate,
|
||||||
}
|
}
|
||||||
d.Init()
|
d.Init()
|
||||||
|
@@ -5,6 +5,8 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
psdp "github.com/pion/sdp/v3"
|
psdp "github.com/pion/sdp/v3"
|
||||||
|
|
||||||
|
"github.com/aler9/gortsplib/pkg/rtpsimpleaudio"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TrackPCMA is a PCMA track.
|
// TrackPCMA is a PCMA track.
|
||||||
@@ -60,3 +62,12 @@ func (t *TrackPCMA) clone() Track {
|
|||||||
trackBase: t.trackBase,
|
trackBase: t.trackBase,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CreateDecoder creates a decoder able to decode the content of the track.
|
||||||
|
func (t *TrackPCMA) CreateDecoder() *rtpsimpleaudio.Decoder {
|
||||||
|
d := &rtpsimpleaudio.Decoder{
|
||||||
|
SampleRate: 8000,
|
||||||
|
}
|
||||||
|
d.Init()
|
||||||
|
return d
|
||||||
|
}
|
||||||
|
@@ -5,6 +5,8 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
psdp "github.com/pion/sdp/v3"
|
psdp "github.com/pion/sdp/v3"
|
||||||
|
|
||||||
|
"github.com/aler9/gortsplib/pkg/rtpsimpleaudio"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TrackPCMU is a PCMU track.
|
// TrackPCMU is a PCMU track.
|
||||||
@@ -60,3 +62,12 @@ func (t *TrackPCMU) clone() Track {
|
|||||||
trackBase: t.trackBase,
|
trackBase: t.trackBase,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CreateDecoder creates a decoder able to decode the content of the track.
|
||||||
|
func (t *TrackPCMU) CreateDecoder() *rtpsimpleaudio.Decoder {
|
||||||
|
d := &rtpsimpleaudio.Decoder{
|
||||||
|
SampleRate: 8000,
|
||||||
|
}
|
||||||
|
d.Init()
|
||||||
|
return d
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user