mirror of https://bitbucket.org/ausocean/av.git
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.
This commit is contained in:
parent
2640b1b615
commit
611dbd14be
|
@ -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 <saxon@ausocean.org>
|
||||
|
||||
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
|
||||
}
|
Loading…
Reference in New Issue