Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change: Rename and consolidate all bits readers and writers. #326

Merged
merged 1 commit into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

- InitSegment.TweakSingleTrakLive changes an init segment to fit live streaming
- Made bits.Mask() function public

### Changed

- All readers and writers in bits package now stop working at first error and provides the first error as AccError()
- Renamed bits.AccErrReader, bits.AccErrEBSPReader, bits.AccErrWriter to corresponiding names without AccErr
- Renamed bits.SliceWriterError to bits.ErrSliceWrite

## [0.42.0] - 2024-01-26

Expand Down
6 changes: 3 additions & 3 deletions aac/aac.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ var ReverseFrequencies = map[int]byte{

// DecodeAudioSpecificConfig -
func DecodeAudioSpecificConfig(r io.Reader) (*AudioSpecificConfig, error) {
br := bits.NewAccErrReader(r)
br := bits.NewReader(r)

asc := &AudioSpecificConfig{}
audioObjectType := byte(br.Read(5))
Expand Down Expand Up @@ -150,11 +150,11 @@ func (a *AudioSpecificConfig) Encode(w io.Writer) error {
}
bw.Write(0x00, 3) // GASpecificConfig
bw.Flush()
return bw.Error()
return bw.AccError()
}

// getFrequency - either from 4-bit index or 24-bit value
func getFrequency(br *bits.AccErrReader) (frequency int, ok bool) {
func getFrequency(br *bits.Reader) (frequency int, ok bool) {
frequencyIndex := br.Read(4)
if frequencyIndex == 0x0f {
f := br.Read(24)
Expand Down
2 changes: 1 addition & 1 deletion aac/adts.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (a ADTSHeader) Encode() []byte {

// DecodeADTSHeader by first looking for sync word
func DecodeADTSHeader(r io.Reader) (header *ADTSHeader, offset int, err error) {
br := bits.NewAccErrReader(r)
br := bits.NewReader(r)
tsPacketSize := 188 // Find sync 0xfff in first 188 bytes (MPEG-TS related)
syncFound := false
offset = 0
Expand Down
2 changes: 1 addition & 1 deletion avc/pps.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func ParsePPSNALUnit(data []byte, spsMap map[uint32]*SPS) (*PPS, error) {
pps := &PPS{}

rd := bytes.NewReader(data)
reader := bits.NewAccErrEBSPReader(rd)
reader := bits.NewEBSPReader(rd)
// Note! First byte is NAL Header

naluHdr := reader.Read(8)
Expand Down
15 changes: 5 additions & 10 deletions avc/slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,11 @@ func GetSliceTypeFromNALU(data []byte) (sliceType SliceType, err error) {
r := bits.NewEBSPReader(bytes.NewReader((data[1:])))

// first_mb_in_slice
if _, err = r.ReadExpGolomb(); err != nil {
return
}

// slice_type
var st uint
if st, err = r.ReadExpGolomb(); err != nil {
return
_ = r.ReadExpGolomb()
sliceType = SliceType(r.ReadExpGolomb())
if r.AccError() != nil {
err = r.AccError()
}
sliceType = SliceType(st)
if sliceType > 9 {
err = ErrInvalidSliceType
return
Expand Down Expand Up @@ -134,7 +129,7 @@ type SliceHeader struct {
func ParseSliceHeader(nalu []byte, spsMap map[uint32]*SPS, ppsMap map[uint32]*PPS) (*SliceHeader, error) {
sh := SliceHeader{}
buf := bytes.NewBuffer(nalu)
r := bits.NewAccErrEBSPReader(buf)
r := bits.NewEBSPReader(buf)
nalHdr := r.Read(8)
naluType := GetNaluType(byte(nalHdr))
switch naluType {
Expand Down
8 changes: 4 additions & 4 deletions avc/sps.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func ParseSPSNALUnit(data []byte, parseVUIBeyondAspectRatio bool) (*SPS, error)
sps := &SPS{}

rd := bytes.NewReader(data)
reader := bits.NewAccErrEBSPReader(rd)
reader := bits.NewEBSPReader(rd)
// Note! First byte is NAL Header

nalHdr := reader.Read(8)
Expand Down Expand Up @@ -271,7 +271,7 @@ func (s *SPS) ChromaArrayType() byte {

// parseVUI - parse VUI (Visual Usability Information)
// if parseVUIBeyondAspectRatio is false, stop after AspectRatio has been parsed
func parseVUI(reader *bits.AccErrEBSPReader, parseVUIBeyondAspectRatio bool) *VUIParameters {
func parseVUI(reader *bits.EBSPReader, parseVUIBeyondAspectRatio bool) *VUIParameters {
vui := &VUIParameters{}
var err error
aspectRatioInfoPresentFlag := reader.ReadFlag()
Expand Down Expand Up @@ -342,7 +342,7 @@ func parseVUI(reader *bits.AccErrEBSPReader, parseVUIBeyondAspectRatio bool) *VU
return vui
}

func parseHrdParameters(r *bits.AccErrEBSPReader) *HrdParameters {
func parseHrdParameters(r *bits.EBSPReader) *HrdParameters {
hp := &HrdParameters{}
hp.CpbCountMinus1 = r.ReadExpGolomb()

Expand Down Expand Up @@ -380,7 +380,7 @@ func GetSARfromIDC(index uint) (uint, uint, error) {
return aspectRatioTable[index-1][0], aspectRatioTable[index-1][1], nil
}

func readScalingList(reader *bits.AccErrEBSPReader, sizeOfScalingList int) ScalingList {
func readScalingList(reader *bits.EBSPReader, sizeOfScalingList int) ScalingList {
scalingList := make([]int, sizeOfScalingList)
lastScale := 8
nextScale := 8
Expand Down
53 changes: 0 additions & 53 deletions bits/aeebspreader_test.go

This file was deleted.

96 changes: 0 additions & 96 deletions bits/aereader_test.go

This file was deleted.

Loading
Loading