-
Notifications
You must be signed in to change notification settings - Fork 177
/
vp9.go
147 lines (118 loc) · 2.91 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
package formats //nolint:dupl
import (
"fmt"
"strconv"
"github.com/pion/rtp"
"github.com/bluenviron/gortsplib/v3/pkg/formats/rtpvp9"
)
// VP9 is a RTP format for the VP9 codec.
// Specification: https://datatracker.ietf.org/doc/html/draft-ietf-payload-vp9-16
type VP9 struct {
PayloadTyp uint8
MaxFR *int
MaxFS *int
ProfileID *int
}
func (f *VP9) unmarshal(ctx *unmarshalContext) error {
f.PayloadTyp = ctx.payloadType
for key, val := range ctx.fmtp {
switch key {
case "max-fr":
n, err := strconv.ParseUint(val, 10, 31)
if err != nil {
return fmt.Errorf("invalid max-fr: %v", val)
}
v2 := int(n)
f.MaxFR = &v2
case "max-fs":
n, err := strconv.ParseUint(val, 10, 31)
if err != nil {
return fmt.Errorf("invalid max-fs: %v", val)
}
v2 := int(n)
f.MaxFS = &v2
case "profile-id":
n, err := strconv.ParseUint(val, 10, 31)
if err != nil {
return fmt.Errorf("invalid profile-id: %v", val)
}
v2 := int(n)
f.ProfileID = &v2
}
}
return nil
}
// Codec implements Format.
func (f *VP9) Codec() string {
return "VP9"
}
// String implements Format.
//
// Deprecated: replaced by Codec().
func (f *VP9) String() string {
return f.Codec()
}
// ClockRate implements Format.
func (f *VP9) ClockRate() int {
return 90000
}
// PayloadType implements Format.
func (f *VP9) PayloadType() uint8 {
return f.PayloadTyp
}
// RTPMap implements Format.
func (f *VP9) RTPMap() string {
return "VP9/90000"
}
// FMTP implements Format.
func (f *VP9) FMTP() map[string]string {
fmtp := make(map[string]string)
if f.MaxFR != nil {
fmtp["max-fr"] = strconv.FormatInt(int64(*f.MaxFR), 10)
}
if f.MaxFS != nil {
fmtp["max-fs"] = strconv.FormatInt(int64(*f.MaxFS), 10)
}
if f.ProfileID != nil {
fmtp["profile-id"] = strconv.FormatInt(int64(*f.ProfileID), 10)
}
return fmtp
}
// PTSEqualsDTS implements Format.
func (f *VP9) PTSEqualsDTS(*rtp.Packet) bool {
return true
}
// CreateDecoder creates a decoder able to decode the content of the format.
//
// Deprecated: this has been replaced by CreateDecoder2() that can also return an error.
func (f *VP9) CreateDecoder() *rtpvp9.Decoder {
d, _ := f.CreateDecoder2()
return d
}
// CreateDecoder2 creates a decoder able to decode the content of the format.
func (f *VP9) CreateDecoder2() (*rtpvp9.Decoder, error) {
d := &rtpvp9.Decoder{}
err := d.Init()
if err != nil {
return nil, err
}
return d, nil
}
// CreateEncoder creates an encoder able to encode the content of the format.
//
// Deprecated: this has been replaced by CreateEncoder2() that can also return an error.
func (f *VP9) CreateEncoder() *rtpvp9.Encoder {
e, _ := f.CreateEncoder2()
return e
}
// CreateEncoder2 creates an encoder able to encode the content of the format.
func (f *VP9) CreateEncoder2() (*rtpvp9.Encoder, error) {
e := &rtpvp9.Encoder{
PayloadType: f.PayloadTyp,
}
err := e.Init()
if err != nil {
return nil, err
}
return e, nil
}