-
Notifications
You must be signed in to change notification settings - Fork 1
/
media_h265.go
62 lines (52 loc) · 1.07 KB
/
media_h265.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
package rtsp
import (
"encoding/base64"
"strconv"
"strings"
)
// RTP Payload Format for High Efficiency Video Coding (HEVC)
// https://datatracker.ietf.org/doc/html/rfc7798
type MediaH265 struct {
ClockRate int
LevelID int
VPS []byte
SPS []byte
PPS []byte
}
func NewMediaH265(clockRate int) *MediaH265 {
return &MediaH265{
ClockRate: clockRate,
}
}
func (m *MediaH265) ParseFMTP(line string) {
var (
pair, key, value string
ok bool
)
for line != "" {
pair, line, _ = strings.Cut(line, ";")
pair = strings.TrimSpace(pair)
key, value, ok = strings.Cut(pair, "=")
if !ok {
continue
}
switch key {
case "level-id":
if v, err := strconv.Atoi(value); err == nil {
m.LevelID = v
}
case "sprop-vps":
if v, err := base64.StdEncoding.DecodeString(value); err == nil {
m.VPS = v
}
case "sprop-sps":
if v, err := base64.StdEncoding.DecodeString(value); err == nil {
m.SPS = v
}
case "sprop-pps":
if v, err := base64.StdEncoding.DecodeString(value); err == nil {
m.PPS = v
}
}
}
}