-
Notifications
You must be signed in to change notification settings - Fork 89
/
Copy pathsei1_hevc.go
103 lines (93 loc) · 4.04 KB
/
sei1_hevc.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
package sei
import (
"bytes"
"fmt"
"github.com/Eyevinn/mp4ff/bits"
)
// PicTimingHevcSEI carries the data of an SEI 1 PicTiming message for HEVC.
// The corresponding SEI 1 for AVC is very different. Time code is in SEI 136 for HEVC.
// Defined in ISO/IEC 23008-2 Ed 5. Section D.2.3 (page 372) and D.3.2.3 (page 405)
type PicTimingHevcSEI struct {
ExternalParams HEVCPicTimingParams `json:"-"`
FrameFieldInfo *HEVCFrameFieldInfo `json:"FrameFieldInfo,omitempty"`
AuCpbRemovalDelayMinus1 uint32 `json:"AuCpbRemovalDelayMinus1,omitempty"`
PicDpbOutputDelay uint32 `json:"PicDpbOutputDelay,omitempty"`
PicDpbOutputDuDelay uint32 `json:"PicDpbOutputDuDelay,omitempty"`
NumDecodingUnitsMinus1 uint32 `json:"NumDecodingUnitsMinus1,omitempty"`
DuCommonCpbRemovalDelayFlag bool `json:"DuCommonCpbRemovalDelayFlag,omitempty"`
DuCommonCpbRemovalDelayIncrementMinus1 uint32 `json:"DuCommonCpbRemovalDelayIncrementMinus1,omitempty"`
NumNalusInDuMinus1 []uint32 `json:"NumNalusInDuMinus1,omitempty"`
DuCpbRemovalDelayIncrementMinus1 []uint32 `json:"DuCpbRemovalDelayIncrementMinus1,omitempty"`
payload []byte `json:"-"`
}
type HEVCPicTimingParams struct {
FrameFieldInfoPresentFlag bool
CpbDpbDelaysPresentFlag bool
SubPicHrdParamsPresentFlag bool
SubPicCpbParamsInPicTimingSeiFlag bool
AuCbpRemovalDelayLengthMinus1 uint8
DpbOutputDelayLengthMinus1 uint8
DpbOutputDelayDuLengthMinus1 uint8
DuCpbRemovalDelayIncrementLengthMinus1 uint8
}
type HEVCFrameFieldInfo struct {
PicStruct uint8 // 4 bits
SourceScanType uint8 // 2 bits
DuplicateFlag bool `json:"DuplicateFlag,omitempty"` // 1bit
}
func DecodePicTimingHevcSEI(sd *SEIData, exPar HEVCPicTimingParams) (SEIMessage, error) {
buf := bytes.NewBuffer(sd.Payload())
br := bits.NewEBSPReader(buf)
pt := PicTimingHevcSEI{
payload: sd.Payload(),
}
if exPar.FrameFieldInfoPresentFlag {
frameFieldInfo := &HEVCFrameFieldInfo{}
frameFieldInfo.PicStruct = uint8(br.Read(4))
frameFieldInfo.SourceScanType = uint8(br.Read(2))
frameFieldInfo.DuplicateFlag = br.ReadFlag()
pt.FrameFieldInfo = frameFieldInfo
}
if exPar.CpbDpbDelaysPresentFlag {
pt.AuCpbRemovalDelayMinus1 = uint32(br.Read(int(exPar.AuCbpRemovalDelayLengthMinus1) + 1))
pt.PicDpbOutputDelay = uint32(br.Read(int(exPar.DpbOutputDelayLengthMinus1) + 1))
if exPar.SubPicHrdParamsPresentFlag {
pt.PicDpbOutputDuDelay = uint32(br.Read(int(exPar.DpbOutputDelayDuLengthMinus1) + 1))
if exPar.SubPicCpbParamsInPicTimingSeiFlag {
pt.NumDecodingUnitsMinus1 = uint32(br.ReadExpGolomb())
pt.DuCommonCpbRemovalDelayFlag = br.ReadFlag()
if pt.DuCommonCpbRemovalDelayFlag {
pt.DuCommonCpbRemovalDelayIncrementMinus1 = uint32(br.Read(int(exPar.DuCpbRemovalDelayIncrementLengthMinus1) + 1))
}
for i := uint32(0); i <= pt.NumDecodingUnitsMinus1; i++ {
pt.NumNalusInDuMinus1[i] = uint32(br.ReadExpGolomb())
if !pt.DuCommonCpbRemovalDelayFlag && i < pt.NumDecodingUnitsMinus1 {
pt.DuCpbRemovalDelayIncrementMinus1[i] = uint32(br.Read(int(exPar.DuCpbRemovalDelayIncrementLengthMinus1) + 1))
}
}
}
}
}
return &pt, br.AccError()
}
// Type returns the SEI payload type.
func (s *PicTimingHevcSEI) Type() uint {
return SEIPicTimingType
}
// Payload returns the SEI raw rbsp payload.
func (s *PicTimingHevcSEI) Payload() []byte {
return s.payload
}
// String returns string representation of PicTiming SEI1.
func (s *PicTimingHevcSEI) String() string {
msgType := SEIType(s.Type())
msg := fmt.Sprintf("%s: ", msgType)
if s.FrameFieldInfo != nil {
msg += fmt.Sprintf("FrameFieldInfo: %+v, ", s.FrameFieldInfo)
}
return msg
}
// Size is size in bytes of raw SEI message rbsp payload.
func (s *PicTimingHevcSEI) Size() uint {
return uint(len(s.payload))
}