forked from pion/mediadevices
-
Notifications
You must be signed in to change notification settings - Fork 0
/
params.go
123 lines (110 loc) · 3.6 KB
/
params.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
package vaapi
import (
"github.com/carbonrobotics/mediadevices/pkg/codec"
"github.com/carbonrobotics/mediadevices/pkg/io/video"
"github.com/carbonrobotics/mediadevices/pkg/prop"
)
// ParamsVP8 stores VP8 encoding parameters.
type ParamsVP8 struct {
codec.BaseParams
Sequence SequenceParamVP8
RateControlMode RateControlMode
RateControl RateControlParam
}
// SequenceParamVP8 represents VAEncSequenceParameterBufferVP8 and other parameter buffers.
type SequenceParamVP8 struct {
ErrorResilient bool
ClampQindexHigh uint
ClampQindexLow uint
}
// NewVP8Params returns default parameters of VP8 codec.
func NewVP8Params() (ParamsVP8, error) {
return ParamsVP8{
BaseParams: codec.BaseParams{
BitRate: 320000,
KeyFrameInterval: 30,
},
Sequence: SequenceParamVP8{
ClampQindexLow: 9,
ClampQindexHigh: 127,
},
RateControlMode: RateControlVBR,
RateControl: RateControlParam{
TargetPercentage: 80,
WindowSize: 1500,
InitialQP: 60,
MinQP: 9,
MaxQP: 127,
},
}, nil
}
// RTPCodec represents the codec metadata
func (p *ParamsVP8) RTPCodec() *codec.RTPCodec {
return codec.NewRTPVP8Codec(90000)
}
// BuildVideoEncoder builds VP8 encoder with given params
func (p *ParamsVP8) BuildVideoEncoder(r video.Reader, property prop.Media) (codec.ReadCloser, error) {
return newVP8Encoder(r, property, *p)
}
// ParamsVP9 represents VAEncSequenceParameterBufferVP9 and other parameter buffers.
type ParamsVP9 struct {
codec.BaseParams
RateControlMode RateControlMode
RateControl RateControlParam
}
// RateControlParam represents VAEncMiscParameterRateControl.
type RateControlParam struct {
// bitsPerSecond is a maximum bit-rate.
// This parameter is calculated from BaseParams.BitRate.
bitsPerSecond uint
// TargetPercentage is a target bit-rate relative to the maximum bit-rate.
// BaseParams.BitRate / (TargetPercentage * 0.01) will be the maximum bit-rate.
TargetPercentage uint
// WindowSize is a rate control window size in milliseconds.
WindowSize uint
InitialQP uint
MinQP uint
MaxQP uint
}
// RateControlMode represents rate control mode.
// Note that supported mode depends on the codec and acceleration hardware.
type RateControlMode uint
// List of the RateControlMode.
const (
RateControlCBR RateControlMode = 0x00000002
RateControlVBR RateControlMode = 0x00000004
RateControlVCM RateControlMode = 0x00000008
RateControlCQP RateControlMode = 0x00000010
RateControlVBRConstrained RateControlMode = 0x00000020
RateControlICQ RateControlMode = 0x00000040
RateControlMB RateControlMode = 0x00000080
RateControlCFS RateControlMode = 0x00000100
RateControlParallel RateControlMode = 0x00000200
RateControlQVBR RateControlMode = 0x00000400
RateControlAVBR RateControlMode = 0x00000800
)
// NewVP9Params returns default parameters of VP9 codec.
func NewVP9Params() (ParamsVP9, error) {
return ParamsVP9{
BaseParams: codec.BaseParams{
BitRate: 320000,
KeyFrameInterval: 30,
},
RateControlMode: RateControlVBR,
RateControl: RateControlParam{
TargetPercentage: 80,
WindowSize: 1500,
InitialQP: 60,
MinQP: 9,
MaxQP: 127,
},
}, nil
}
// RTPCodec represents the codec metadata
func (p *ParamsVP9) RTPCodec() *codec.RTPCodec {
return codec.NewRTPVP9Codec(90000)
}
// BuildVideoEncoder builds VP9 encoder with given params
func (p *ParamsVP9) BuildVideoEncoder(r video.Reader, property prop.Media) (codec.ReadCloser, error) {
return newVP9Encoder(r, property, *p)
}