diff --git a/codec/h264/h264dec/cabacenc.go b/codec/h264/h264dec/cabacenc.go index 224fc529..f9b0cca5 100644 --- a/codec/h264/h264dec/cabacenc.go +++ b/codec/h264/h264dec/cabacenc.go @@ -28,6 +28,7 @@ package h264dec import ( "errors" + "fmt" "math" ) @@ -220,3 +221,23 @@ func subMbTypeBinString(v, slice int) ([]int, error) { return nil, errBadSubMbSliceType } } + +// codedBlockPatternBinString returns the binarization for the syntax element +// coded_block_pattern as defined by section 9.3.2.6 in specifications. +func codedBlockPatternBinString(luma, chroma, arrayType int) ([]int, error) { + p, err := fixedLenBinString(luma, 15) + if err != nil { + return nil, fmt.Errorf("fixed length binarization failed with error: %v", err) + } + + if arrayType == 0 || arrayType == 3 { + return p, nil + } + + s, err := truncUnaryBinString(chroma, 2) + if err != nil { + return nil, fmt.Errorf("truncated unary binarization failed with error: %v", err) + } + + return append(p, s...), nil +}