forked from bluenviron/gortsplib
/
g726.go
73 lines (58 loc) · 1.25 KB
/
g726.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
package format
import (
"strconv"
"strings"
"github.com/pion/rtp"
)
// G726 is a RTP format for the G726 codec.
// Specification: https://datatracker.ietf.org/doc/html/rfc3551
type G726 struct {
PayloadTyp uint8
BitRate int
BigEndian bool
}
func (f *G726) unmarshal(ctx *unmarshalContext) error {
f.PayloadTyp = ctx.payloadType
if strings.HasPrefix(ctx.codec, "aal2-") {
f.BigEndian = true
}
switch {
case strings.HasSuffix(ctx.codec, "-16"):
f.BitRate = 16
case strings.HasSuffix(ctx.codec, "-24"):
f.BitRate = 24
case strings.HasSuffix(ctx.codec, "-32"):
f.BitRate = 32
default:
f.BitRate = 40
}
return nil
}
// Codec implements Format.
func (f *G726) Codec() string {
return "G726"
}
// ClockRate implements Format.
func (f *G726) ClockRate() int {
return 8000
}
// PayloadType implements Format.
func (f *G726) PayloadType() uint8 {
return f.PayloadTyp
}
// RTPMap implements Format.
func (f *G726) RTPMap() string {
codec := ""
if f.BigEndian {
codec += "AAL2-"
}
return codec + "G726-" + strconv.FormatInt(int64(f.BitRate), 10) + "/8000"
}
// FMTP implements Format.
func (f *G726) FMTP() map[string]string {
return nil
}
// PTSEqualsDTS implements Format.
func (f *G726) PTSEqualsDTS(*rtp.Packet) bool {
return true
}