forked from bluenviron/gortsplib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vorbis.go
92 lines (74 loc) · 1.79 KB
/
vorbis.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package format
import (
"encoding/base64"
"fmt"
"strconv"
"strings"
"github.com/pion/rtp"
)
// Vorbis is a RTP format for the Vorbis codec.
// Specification: https://datatracker.ietf.org/doc/html/rfc5215
type Vorbis struct {
PayloadTyp uint8
SampleRate int
ChannelCount int
Configuration []byte
}
func (f *Vorbis) unmarshal(ctx *unmarshalContext) error {
f.PayloadTyp = ctx.payloadType
tmp := strings.SplitN(ctx.clock, "/", 2)
if len(tmp) != 2 {
return fmt.Errorf("invalid clock (%v)", ctx.clock)
}
sampleRate, err := strconv.ParseUint(tmp[0], 10, 31)
if err != nil {
return err
}
f.SampleRate = int(sampleRate)
channelCount, err := strconv.ParseUint(tmp[1], 10, 31)
if err != nil {
return err
}
f.ChannelCount = int(channelCount)
for key, val := range ctx.fmtp {
if key == "configuration" {
conf, err := base64.StdEncoding.DecodeString(val)
if err != nil {
return fmt.Errorf("invalid config: %v", val)
}
f.Configuration = conf
}
}
if f.Configuration == nil {
return fmt.Errorf("config is missing")
}
return nil
}
// Codec implements Format.
func (f *Vorbis) Codec() string {
return "Vorbis"
}
// ClockRate implements Format.
func (f *Vorbis) ClockRate() int {
return f.SampleRate
}
// PayloadType implements Format.
func (f *Vorbis) PayloadType() uint8 {
return f.PayloadTyp
}
// RTPMap implements Format.
func (f *Vorbis) RTPMap() string {
return "VORBIS/" + strconv.FormatInt(int64(f.SampleRate), 10) +
"/" + strconv.FormatInt(int64(f.ChannelCount), 10)
}
// FMTP implements Format.
func (f *Vorbis) FMTP() map[string]string {
fmtp := map[string]string{
"configuration": base64.StdEncoding.EncodeToString(f.Configuration),
}
return fmtp
}
// PTSEqualsDTS implements Format.
func (f *Vorbis) PTSEqualsDTS(*rtp.Packet) bool {
return true
}