From 611dbd14be4fedbdc24a357a4b922ba20f6291ce Mon Sep 17 00:00:00 2001 From: Saxon Date: Sun, 23 Jun 2019 23:58:05 +0930 Subject: [PATCH] codec/h264: added decode folder, decode/parse.go and first function in parse.go. Added decode folder which will contain the h264 decoder and utilities. Added first file parse.go, which contains parsing processes for syntax elements. --- codec/h264/decode/parse.go | 53 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 codec/h264/decode/parse.go diff --git a/codec/h264/decode/parse.go b/codec/h264/decode/parse.go new file mode 100644 index 00000000..07087c7d --- /dev/null +++ b/codec/h264/decode/parse.go @@ -0,0 +1,53 @@ +/* +NAME + parse.go + +DESCRIPTION + parse.go provides parsing processes for syntax elements of different + descriptors specified in 7.2 of ITU-T H.264. + +AUTHOR + Saxon Nelson-Milton + +LICENSE + Copyright (C) 2017 the Australian Ocean Lab (AusOcean) + + It is free software: you can redistribute it and/or modify them + under the terms of the GNU General Public License as published by the + Free Software Foundation, either version 3 of the License, or (at your + option) any later version. + + It is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with revid in gpl.txt. If not, see http://www.gnu.org/licenses. +*/ + +package decode + +import ( + "math" + + "github.com/icza/bitio" +) + +// readUe parses a syntax element of ue(v) descriptor, i.e. an unsigned integer +// Exp-Golomb-coded element. This process is specified in 9.1. +func readUe(r bitio.Reader) (int, error) { + nZeros := -1 + var err error + for b := uint64(0); b == 0; nZeros++ { + b, err = r.ReadBits(1) + if err != nil { + return 0, err + } + } + rem, err := r.ReadBits(byte(nZeros)) + if err != nil { + return 0, err + } + return int(math.Pow(float64(2), float64(nZeros)) - 1 + float64(rem)), nil +}