2020-06-08 03:29:51 +03:00
|
|
|
package vpx
|
|
|
|
|
|
|
|
// https://tools.ietf.org/html/rfc6386
|
|
|
|
|
|
|
|
import (
|
2021-08-17 13:06:32 +03:00
|
|
|
"github.com/wader/fq/format"
|
|
|
|
"github.com/wader/fq/format/registry"
|
|
|
|
"github.com/wader/fq/pkg/decode"
|
2020-06-08 03:29:51 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
// TODO: vpx frame?
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
registry.MustRegister(&decode.Format{
|
|
|
|
Name: format.VP8_FRAME,
|
|
|
|
Description: "VP8 frame",
|
|
|
|
DecodeFn: vp8Decode,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func vp8Decode(d *decode.D, in interface{}) interface{} {
|
|
|
|
var isKeyFrame bool
|
|
|
|
|
|
|
|
versions := map[uint64]struct {
|
|
|
|
reconstruction string
|
|
|
|
loop string
|
|
|
|
}{
|
|
|
|
0: {"Bicubic", "Normal"},
|
|
|
|
1: {"Bilinear", "Simple"},
|
|
|
|
2: {"Bilinear", "None"},
|
|
|
|
3: {"None", "None"},
|
|
|
|
}
|
|
|
|
|
2021-11-05 17:04:26 +03:00
|
|
|
d.FieldStruct("tag", func(d *decode.D) {
|
2020-06-08 03:29:51 +03:00
|
|
|
// first_part_size is not contiguous bits
|
|
|
|
firstPartSize0 := d.FieldU3("first_part_size0")
|
|
|
|
d.FieldU1("show_frame")
|
|
|
|
version := d.FieldU3("version")
|
2021-11-05 17:04:26 +03:00
|
|
|
keyFrameV := d.FieldBool("frame_type", d.MapBoolToStr(decode.BoolToStr{true: "non_key_frame", false: "key_frame"}))
|
2020-06-08 03:29:51 +03:00
|
|
|
firstPartSize1 := d.FieldU16LE("first_part_size1")
|
|
|
|
|
|
|
|
firstPartSize := firstPartSize0 | firstPartSize1<<3
|
2021-11-05 17:04:26 +03:00
|
|
|
d.FieldValueU("first_part_size", firstPartSize)
|
2020-06-08 03:29:51 +03:00
|
|
|
|
|
|
|
isKeyFrame = !keyFrameV
|
|
|
|
if v, ok := versions[version]; ok {
|
2021-11-05 17:04:26 +03:00
|
|
|
d.FieldValueStr("reconstruction", v.reconstruction)
|
|
|
|
d.FieldValueStr("loop", v.loop)
|
2020-06-08 03:29:51 +03:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
if isKeyFrame {
|
2021-11-05 17:04:26 +03:00
|
|
|
d.FieldU24("start_code", d.ValidateU(0x9d012a), d.Hex)
|
2020-06-08 03:29:51 +03:00
|
|
|
|
|
|
|
// width and height are not contiguous bits
|
|
|
|
width0 := d.FieldU8("width0")
|
|
|
|
d.FieldU2("horizontal_scale")
|
|
|
|
width1 := d.FieldU6("width1")
|
2021-11-05 17:04:26 +03:00
|
|
|
d.FieldValueU("width", width0|width1<<8)
|
2020-06-08 03:29:51 +03:00
|
|
|
|
|
|
|
height0 := d.FieldU8("height0")
|
|
|
|
d.FieldU2("vertical_scale")
|
|
|
|
height1 := d.FieldU6("height1")
|
2021-11-05 17:04:26 +03:00
|
|
|
d.FieldValueU("height", height0|height1<<8)
|
2020-06-08 03:29:51 +03:00
|
|
|
}
|
|
|
|
|
2021-11-05 17:04:26 +03:00
|
|
|
d.FieldRawLen("data", d.BitsLeft())
|
2020-06-08 03:29:51 +03:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|