Documentation ¶
Overview ¶
Package bits - bit reading and writing including Golomb codes and EBSP.
Beyond plain bit reading and writing, reading of ebsp (Encapsulated Byte Sequence Packets) Golomb codes as used in the AVC/H.264 and HEVC video coding standards.
Index ¶
- Variables
- func EBSP2rbsp(ebsp []byte) []byte
- type AccErrByteWriter
- func (a *AccErrByteWriter) AccError() error
- func (a *AccErrByteWriter) WriteSlice(s []byte)
- func (a *AccErrByteWriter) WriteUint16(u uint16)
- func (a *AccErrByteWriter) WriteUint32(u uint32)
- func (a *AccErrByteWriter) WriteUint48(u uint64)
- func (a *AccErrByteWriter) WriteUint64(u uint64)
- func (a *AccErrByteWriter) WriteUint8(b byte)
- type AccErrEBSPReader
- func (r *AccErrEBSPReader) AccError() error
- func (r *AccErrEBSPReader) IsSeeker() bool
- func (r *AccErrEBSPReader) MoreRbspData() (bool, error)
- func (r *AccErrEBSPReader) NrBitsReadInCurrentByte() int
- func (r *AccErrEBSPReader) NrBytesRead() int
- func (r *AccErrEBSPReader) Read(n int) uint
- func (r *AccErrEBSPReader) ReadExpGolomb() uint
- func (r *AccErrEBSPReader) ReadFlag() bool
- func (r *AccErrEBSPReader) ReadRbspTrailingBits() error
- func (r *AccErrEBSPReader) ReadSignedGolomb() int
- type AccErrReader
- type EBSPReader
- func (r *EBSPReader) IsSeeker() bool
- func (r *EBSPReader) MoreRbspData() (bool, error)
- func (r *EBSPReader) MustRead(n int) uint
- func (r *EBSPReader) MustReadExpGolomb() uint
- func (r *EBSPReader) MustReadFlag() bool
- func (r *EBSPReader) MustReadSignedGolomb() int
- func (r *EBSPReader) NrBitsReadInCurrentByte() int
- func (r *EBSPReader) NrBytesRead() int
- func (r *EBSPReader) Read(n int) (uint, error)
- func (r *EBSPReader) ReadExpGolomb() (uint, error)
- func (r *EBSPReader) ReadFlag() (bool, error)
- func (r *EBSPReader) ReadRbspTrailingBits() error
- func (r *EBSPReader) ReadSignedGolomb() (int, error)
- type EBSPWriter
- type Reader
- type SliceReader
- func (s *SliceReader) AccError() error
- func (s *SliceReader) GetPos() int
- func (s *SliceReader) Length() int
- func (s *SliceReader) NrRemainingBytes() int
- func (s *SliceReader) ReadBytes(n int) []byte
- func (s *SliceReader) ReadFixedLengthString(n int) string
- func (s *SliceReader) ReadInt16() int16
- func (s *SliceReader) ReadInt32() int32
- func (s *SliceReader) ReadInt64() int64
- func (s *SliceReader) ReadUint16() uint16
- func (s *SliceReader) ReadUint32() uint32
- func (s *SliceReader) ReadUint64() uint64
- func (s *SliceReader) ReadUint8() byte
- func (s *SliceReader) ReadZeroTerminatedString() string
- func (s *SliceReader) RemainingBytes() []byte
- func (s *SliceReader) SetPos(pos int)
- func (s *SliceReader) SkipBytes(n int)
- type Writer
Constants ¶
This section is empty.
Variables ¶
var ErrNotReedSeeker = errors.New("Reader does not support Seek")
var SliceReadError = fmt.Errorf("Read too far in SliceReader")
Functions ¶
Types ¶
type AccErrByteWriter ¶ added in v0.17.0
type AccErrByteWriter struct {
// contains filtered or unexported fields
}
AccErrByteWriter - writer that wraps an io.Writer and accumulater error
func NewAccErrByteWriter ¶ added in v0.17.0
func NewAccErrByteWriter(w io.Writer) *AccErrByteWriter
NewAccErrByteWriter - create accumulated error writer around io.Writer
func (*AccErrByteWriter) AccError ¶ added in v0.17.0
func (a *AccErrByteWriter) AccError() error
AccError - return accumulated error
func (*AccErrByteWriter) WriteSlice ¶ added in v0.17.0
func (a *AccErrByteWriter) WriteSlice(s []byte)
func (*AccErrByteWriter) WriteUint16 ¶ added in v0.17.0
func (a *AccErrByteWriter) WriteUint16(u uint16)
func (*AccErrByteWriter) WriteUint32 ¶ added in v0.17.0
func (a *AccErrByteWriter) WriteUint32(u uint32)
func (*AccErrByteWriter) WriteUint48 ¶ added in v0.17.0
func (a *AccErrByteWriter) WriteUint48(u uint64)
func (*AccErrByteWriter) WriteUint64 ¶ added in v0.17.0
func (a *AccErrByteWriter) WriteUint64(u uint64)
func (*AccErrByteWriter) WriteUint8 ¶ added in v0.17.0
func (a *AccErrByteWriter) WriteUint8(b byte)
type AccErrEBSPReader ¶ added in v0.17.0
type AccErrEBSPReader struct {
// contains filtered or unexported fields
}
AccErrEBSPReader - Reader that drops start code emulation 0x03 after two bytes of 0x00
func NewAccErrEBSPReader ¶ added in v0.17.0
func NewAccErrEBSPReader(rd io.Reader) *AccErrEBSPReader
NewAccErrEBSPReader - return a new reader accumulating errors.
func (*AccErrEBSPReader) AccError ¶ added in v0.17.0
func (r *AccErrEBSPReader) AccError() error
AccError - accumulated error
func (*AccErrEBSPReader) IsSeeker ¶ added in v0.17.0
func (r *AccErrEBSPReader) IsSeeker() bool
IsSeeker - does reader support Seek
func (*AccErrEBSPReader) MoreRbspData ¶ added in v0.17.0
func (r *AccErrEBSPReader) MoreRbspData() (bool, error)
MoreRbspData - false if next bit is 1 and last 1 in fullSlice Underlying reader must support ReadSeeker interface to reset after check Return false, nil if underlying error
func (*AccErrEBSPReader) NrBitsReadInCurrentByte ¶ added in v0.17.0
func (r *AccErrEBSPReader) NrBitsReadInCurrentByte() int
NrBitsReadInCurrentByte - how many bits have been read
func (*AccErrEBSPReader) NrBytesRead ¶ added in v0.17.0
func (r *AccErrEBSPReader) NrBytesRead() int
NrBytesRead - how many bytes read into parser
func (*AccErrEBSPReader) Read ¶ added in v0.17.0
func (r *AccErrEBSPReader) Read(n int) uint
Read - read n bits and return 0 if (previous) error
func (*AccErrEBSPReader) ReadExpGolomb ¶ added in v0.17.0
func (r *AccErrEBSPReader) ReadExpGolomb() uint
ReadExpGolomb - Read one unsigned exponential golomb code. Return 0 if error
func (*AccErrEBSPReader) ReadFlag ¶ added in v0.17.0
func (r *AccErrEBSPReader) ReadFlag() bool
ReadFlag - read 1 bit into bool. Return false if not possible
func (*AccErrEBSPReader) ReadRbspTrailingBits ¶ added in v0.17.0
func (r *AccErrEBSPReader) ReadRbspTrailingBits() error
ReadRbspTrailingBits - read rbsp_traling_bits. Return error if wrong pattern If other error, return nil and let AccError provide that error
func (*AccErrEBSPReader) ReadSignedGolomb ¶ added in v0.17.0
func (r *AccErrEBSPReader) ReadSignedGolomb() int
ReadSignedGolomb - Read one signed exponential golomb code. Return 0 if error
type AccErrReader ¶ added in v0.16.0
type AccErrReader struct {
// contains filtered or unexported fields
}
AccErrReader - bit reader that accumulates error First error can be fetched as reader.AccError()
func NewAccErrReader ¶ added in v0.16.0
func NewAccErrReader(rd io.Reader) *AccErrReader
NewReader - return a new Reader
func (*AccErrReader) AccError ¶ added in v0.16.0
func (r *AccErrReader) AccError() error
func (*AccErrReader) Read ¶ added in v0.16.0
func (r *AccErrReader) Read(n int) uint
Read - read n bits. Return 0, if error now or previously
func (*AccErrReader) ReadFlag ¶ added in v0.16.0
func (r *AccErrReader) ReadFlag() bool
ReadFlag - read 1 bit into flag. Return false if error now or previously
type EBSPReader ¶
type EBSPReader struct {
// contains filtered or unexported fields
}
EBSPReader - Reader that drops start code emulation 0x03 after two bytes of 0x00
func NewEBSPReader ¶
func NewEBSPReader(rd io.Reader) *EBSPReader
NewEBSPReader - return a new Reader.
func (*EBSPReader) IsSeeker ¶ added in v0.12.0
func (r *EBSPReader) IsSeeker() bool
IsSeeker - does reader support Seek
func (*EBSPReader) MoreRbspData ¶ added in v0.12.0
func (r *EBSPReader) MoreRbspData() (bool, error)
MoreRbspData - false if next bit is 1 and last 1 in fullSlice Underlying reader must support ReadSeeker interface to reset after check
func (*EBSPReader) MustRead ¶
func (r *EBSPReader) MustRead(n int) uint
MustRead - read n bits and panic if not possible
func (*EBSPReader) MustReadExpGolomb ¶
func (r *EBSPReader) MustReadExpGolomb() uint
MustReadExpGolomb - Read one unsigned exponential golomb code. Panic if not possible
func (*EBSPReader) MustReadFlag ¶
func (r *EBSPReader) MustReadFlag() bool
MustReadFlag - read 1 bit into flag. Panic if not possible
func (*EBSPReader) MustReadSignedGolomb ¶
func (r *EBSPReader) MustReadSignedGolomb() int
MustReadSignedGolomb - Read one signed exponential golomb code. Panic if not possible
func (*EBSPReader) NrBitsReadInCurrentByte ¶ added in v0.12.0
func (r *EBSPReader) NrBitsReadInCurrentByte() int
NrBitsReadInCurrentByte - how many bits have been read
func (*EBSPReader) NrBytesRead ¶
func (r *EBSPReader) NrBytesRead() int
NrBytesRead - how many bytes read into parser
func (*EBSPReader) Read ¶
func (r *EBSPReader) Read(n int) (uint, error)
Read - read n bits and return error if not possible
func (*EBSPReader) ReadExpGolomb ¶
func (r *EBSPReader) ReadExpGolomb() (uint, error)
ReadExpGolomb - Read one unsigned exponential golomb code
func (*EBSPReader) ReadFlag ¶
func (r *EBSPReader) ReadFlag() (bool, error)
ReadFlag - read 1 bit into flag. Return error if not possible
func (*EBSPReader) ReadRbspTrailingBits ¶ added in v0.12.0
func (r *EBSPReader) ReadRbspTrailingBits() error
ReadRbspTrailingBits - read rbsp_traling_bits. Return false if wrong pattern
func (*EBSPReader) ReadSignedGolomb ¶
func (r *EBSPReader) ReadSignedGolomb() (int, error)
ReadSignedGolomb - Read one signed exponential golomb code
type EBSPWriter ¶ added in v0.15.0
type EBSPWriter struct {
// contains filtered or unexported fields
}
EbspWriter writes bits into underlying io.Writer and inserts start-code emulation prevention bytes as necessary Stops writing at first error. Errors that have occured can later be checked with Error().
func NewEBSPWriter ¶ added in v0.15.0
func NewEBSPWriter(w io.Writer) *EBSPWriter
NewWriter - returns a new Writer
func (*EBSPWriter) StuffByteWithZeros ¶ added in v0.15.0
func (w *EBSPWriter) StuffByteWithZeros()
StuffByteWithZeros - write zero bits until byte boundary (0-7bits)
func (*EBSPWriter) Write ¶ added in v0.15.0
func (w *EBSPWriter) Write(bits uint, n int)
Write - write n bits from bits and save error state
func (*EBSPWriter) WriteRbspTrailingBits ¶ added in v0.15.0
func (w *EBSPWriter) WriteRbspTrailingBits()
Write - write rbsp trailing bits (a 1 followed by zeros to a byte boundary)
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
Reader - read bits from the given io.Reader
func (*Reader) MustReadFlag ¶
MustReadFlag - read 1 bit into flag and panic if not possible
type SliceReader ¶ added in v0.17.0
type SliceReader struct {
// contains filtered or unexported fields
}
SliceReader - read integers and other data from a slice. Accumulates error, and the first error can be retrived. If err != nil, 0 or empty string is returned
func NewSliceReader ¶ added in v0.17.0
func NewSliceReader(data []byte) *SliceReader
NewSliceReader - create a new slice reader reading from data
func (*SliceReader) AccError ¶ added in v0.17.0
func (s *SliceReader) AccError() error
AccError - get accumulated error after read operations
func (*SliceReader) GetPos ¶ added in v0.17.0
func (s *SliceReader) GetPos() int
GetPos - get read position is slice
func (*SliceReader) Length ¶ added in v0.17.0
func (s *SliceReader) Length() int
Length - get length of slice
func (*SliceReader) NrRemainingBytes ¶ added in v0.17.0
func (s *SliceReader) NrRemainingBytes() int
NrRemaingingByts - return number of bytes remaining
func (*SliceReader) ReadBytes ¶ added in v0.17.0
func (s *SliceReader) ReadBytes(n int) []byte
ReadBytes - read a slice of n bytes Return empty slice if n bytes not available
func (*SliceReader) ReadFixedLengthString ¶ added in v0.17.0
func (s *SliceReader) ReadFixedLengthString(n int) string
ReadFixedLengthString - read string of specified length n. Sets err and returns empty string if full length not available
func (*SliceReader) ReadInt16 ¶ added in v0.17.0
func (s *SliceReader) ReadInt16() int16
ReadInt16 - read int16 from slice
func (*SliceReader) ReadInt32 ¶ added in v0.17.0
func (s *SliceReader) ReadInt32() int32
ReadInt32 - read int32 from slice
func (*SliceReader) ReadInt64 ¶ added in v0.17.0
func (s *SliceReader) ReadInt64() int64
ReadInt64 - read int64 from slice
func (*SliceReader) ReadUint16 ¶ added in v0.17.0
func (s *SliceReader) ReadUint16() uint16
ReadUint16 - read uint16 from slice
func (*SliceReader) ReadUint32 ¶ added in v0.17.0
func (s *SliceReader) ReadUint32() uint32
ReadUint32 - read uint32 from slice
func (*SliceReader) ReadUint64 ¶ added in v0.17.0
func (s *SliceReader) ReadUint64() uint64
ReadUint64 - read uint64 from slice
func (*SliceReader) ReadUint8 ¶ added in v0.17.0
func (s *SliceReader) ReadUint8() byte
ReadUint8 - read uint8 from slice
func (*SliceReader) ReadZeroTerminatedString ¶ added in v0.17.0
func (s *SliceReader) ReadZeroTerminatedString() string
ReadZeroTerminatedString - read string until zero byte Set err and return empty string if no zero byte found
func (*SliceReader) RemainingBytes ¶ added in v0.17.0
func (s *SliceReader) RemainingBytes() []byte
RemainingBytes - return remaining bytes of this slice
func (*SliceReader) SetPos ¶ added in v0.17.0
func (s *SliceReader) SetPos(pos int)
SetPos - set read position is slice
func (*SliceReader) SkipBytes ¶ added in v0.17.0
func (s *SliceReader) SkipBytes(n int)
SkipBytes - skip passed n bytes
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
Writer writes bits into underlying io.Writer. Stops writing at first error. Errors that have occured can later be checked with Error().