-
Notifications
You must be signed in to change notification settings - Fork 227
/
vp8_frame.go
72 lines (58 loc) · 1.68 KB
/
vp8_frame.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
package vpx
// https://tools.ietf.org/html/rfc6386
import (
"github.com/wader/fq/format"
"github.com/wader/fq/pkg/decode"
"github.com/wader/fq/pkg/interp"
"github.com/wader/fq/pkg/scalar"
)
// TODO: vpx frame?
func init() {
interp.RegisterFormat(
format.VP8_Frame,
&decode.Format{
Description: "VP8 frame",
DecodeFn: vp8Decode,
})
}
func vp8Decode(d *decode.D) any {
var isKeyFrame bool
versions := map[uint64]struct {
reconstruction string
loop string
}{
0: {"Bicubic", "Normal"},
1: {"Bilinear", "Simple"},
2: {"Bilinear", "None"},
3: {"None", "None"},
}
d.FieldStruct("tag", func(d *decode.D) {
// first_part_size is not contiguous bits
firstPartSize0 := d.FieldU3("first_part_size0")
d.FieldU1("show_frame")
version := d.FieldU3("version")
keyFrameV := d.FieldBool("frame_type", scalar.BoolMapSymStr{true: "non_key_frame", false: "key_frame"})
firstPartSize1 := d.FieldU16LE("first_part_size1")
firstPartSize := firstPartSize0 | firstPartSize1<<3
d.FieldValueUint("first_part_size", firstPartSize)
isKeyFrame = !keyFrameV
if v, ok := versions[version]; ok {
d.FieldValueStr("reconstruction", v.reconstruction)
d.FieldValueStr("loop", v.loop)
}
})
if isKeyFrame {
d.FieldU24("start_code", d.UintValidate(0x9d012a), scalar.UintHex)
// width and height are not contiguous bits
width0 := d.FieldU8("width0")
d.FieldU2("horizontal_scale")
width1 := d.FieldU6("width1")
d.FieldValueUint("width", width0|width1<<8)
height0 := d.FieldU8("height0")
d.FieldU2("vertical_scale")
height1 := d.FieldU6("height1")
d.FieldValueUint("height", height0|height1<<8)
}
d.FieldRawLen("data", d.BitsLeft())
return nil
}