func (r *BitReader) ReadSignedGolomb() (val int32, err error) {
	uval, err := r.ReadUnsignedGolomb()
	if err != nil {
		return 0, err
	}
	if (uval & 1) == 0 {
		return -int32(uval / 2), nil
	}
	return int32((uval + 1) / 2), nil
}
ReadSignedGolomb reads and decodes exponential golomb encoded value from a bit stream. and interprets it as signed value.
Returns an error if running into end of stream prematurely.
package h264
import (
	"errors"
	"io"
)
var (
	errMissingTrailingBits = errors.New("RBSP is missing trailing stop and align bits")
)
type BitReader struct {
	buffer []byte
	count  uint
	byten  uint
	bitn   uint
}
func NewBitReader(buf []byte) *BitReader {
	return &BitReader{buffer: buf, count: uint(len(buf)), byten: 0, bitn: 0}
}
func (r *BitReader) Available() uint {
	return (r.count-r.byten)*8 - r.bitn
}
func (r *BitReader) ReadBits(n uint) (val uint32, err error) {
	if n > 32 || n > r.Available() {
		return 0, io.ErrUnexpectedEOF
	}
	val = uint32(r.buffer[r.byten])
	bits := 8 - r.bitn
	for n > bits {
		r.byten++
		val = (val << 8) | uint32(r.buffer[r.byten])
		bits += 8
	}
	val = (val >> (bits - n)) & ((1 << n) - 1)
	r.bitn = 8 - (bits - n)
	return
}
func (r *BitReader) ReadByteBits(n uint) (val byte, err error) {
	if n > 8 {
		n = 8
	}
	v, err := r.ReadBits(n)
	return byte(v), err
}
func (r *BitReader) ReadFlag() (val bool, err error) {
	v, err := r.ReadBits(1)
	return v != 0, err
}
func (r *BitReader) ReadUnsignedGolomb() (val uint32, err error) {
	var zeroes uint
	for val, err = r.ReadBits(1); val == 0; val, err = r.ReadBits(1) {
		if err != nil {
			return
		}
		zeroes++
	}
	val, err = r.ReadBits(zeroes)
	if err != nil {
		return
	}
	return val + (1 << zeroes) - 1, nil
}