-
Notifications
You must be signed in to change notification settings - Fork 177
/
vp9.go
104 lines (87 loc) · 2.08 KB
/
vp9.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
93
94
95
96
97
98
99
100
101
102
103
104
package format
import (
"fmt"
"strconv"
"github.com/pion/rtp"
"github.com/aler9/gortsplib/v2/pkg/formatdecenc/rtpvp9"
)
// VP9 is a format that uses the VP9 codec.
type VP9 struct {
PayloadTyp uint8
MaxFR *int
MaxFS *int
ProfileID *int
}
// String implements Format.
func (t *VP9) String() string {
return "VP9"
}
// ClockRate implements Format.
func (t *VP9) ClockRate() int {
return 90000
}
// PayloadType implements Format.
func (t *VP9) PayloadType() uint8 {
return t.PayloadTyp
}
func (t *VP9) unmarshal(payloadType uint8, clock string, codec string, rtpmap string, fmtp map[string]string) error {
t.PayloadTyp = payloadType
for key, val := range fmtp {
switch key {
case "max-fr":
n, err := strconv.ParseUint(val, 10, 64)
if err != nil {
return fmt.Errorf("invalid max-fr (%v)", val)
}
v2 := int(n)
t.MaxFR = &v2
case "max-fs":
n, err := strconv.ParseUint(val, 10, 64)
if err != nil {
return fmt.Errorf("invalid max-fs (%v)", val)
}
v2 := int(n)
t.MaxFS = &v2
case "profile-id":
n, err := strconv.ParseUint(val, 10, 64)
if err != nil {
return fmt.Errorf("invalid profile-id (%v)", val)
}
v2 := int(n)
t.ProfileID = &v2
}
}
return nil
}
// Marshal implements Format.
func (t *VP9) Marshal() (string, map[string]string) {
fmtp := make(map[string]string)
if t.MaxFR != nil {
fmtp["max-fr"] = strconv.FormatInt(int64(*t.MaxFR), 10)
}
if t.MaxFS != nil {
fmtp["max-fs"] = strconv.FormatInt(int64(*t.MaxFS), 10)
}
if t.ProfileID != nil {
fmtp["profile-id"] = strconv.FormatInt(int64(*t.ProfileID), 10)
}
return "VP9/90000", fmtp
}
// PTSEqualsDTS implements Format.
func (t *VP9) PTSEqualsDTS(*rtp.Packet) bool {
return true
}
// CreateDecoder creates a decoder able to decode the content of the format.
func (t *VP9) CreateDecoder() *rtpvp9.Decoder {
d := &rtpvp9.Decoder{}
d.Init()
return d
}
// CreateEncoder creates an encoder able to encode the content of the format.
func (t *VP9) CreateEncoder() *rtpvp9.Encoder {
e := &rtpvp9.Encoder{
PayloadType: t.PayloadTyp,
}
e.Init()
return e
}