Skip to content

Commit

Permalink
Merge pull request #233 from Eyevinn/fix-avc-slice-size
Browse files Browse the repository at this point in the history
Fix avc slice size
  • Loading branch information
tobbee authored Apr 5, 2023
2 parents 5026403 + 211a13b commit 9cde8b7
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 9 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

- stpp box handles optional empty lists properly (a single zero byte)
- `stpp` box handles optional empty lists properly (a single zero byte)
- AVC slice size value

## [0.34.1] - 2023-03-09

Expand Down
6 changes: 1 addition & 5 deletions avc/slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,11 +346,7 @@ func ParseSliceHeader(nalu []byte, spsMap map[uint32]*SPS, ppsMap map[uint32]*PP
sh.SliceGroupChangeCycle = uint32(r.Read(nrBits))
}

/* compute the size in bytes. Round up if not an integral number of bytes .*/
// compute the size in bytes. The last byte may not be fully read
sh.Size = uint32(r.NrBytesRead())
if r.NrBitsReadInCurrentByte() > 0 {
sh.Size++
}

return &sh, nil
}
2 changes: 1 addition & 1 deletion avc/slice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func TestParseSliceHeader(t *testing.T) {
SliceQPDelta: 6,
SliceAlphaC0OffsetDiv2: -3,
SliceBetaOffsetDiv2: -3,
Size: 8,
Size: 7,
}
data, err := ioutil.ReadFile("testdata/blackframe.264")
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions bits/aeebspreader.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ func (r *AccErrEBSPReader) ReadRbspTrailingBits() error {
return nil
}
if firstBit != 1 {
return fmt.Errorf("RbspTrailingBits don't start with 1")
return fmt.Errorf("rbspTrailingBits don't start with 1")
}
for {
b := r.Read(1)
Expand All @@ -236,7 +236,7 @@ func (r *AccErrEBSPReader) ReadRbspTrailingBits() error {
return nil
}
if b == 1 {
return fmt.Errorf("Another 1 in RbspTrailingBits")
return fmt.Errorf("another 1 in RbspTrailingBits")
}
}
}
Expand Down
49 changes: 49 additions & 0 deletions bits/aeebspreader_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package bits_test

import (
"bytes"
"encoding/hex"
"testing"

"github.com/Eyevinn/mp4ff/bits"
)

func TestAccErrEBSPReader(t *testing.T) {
testCases := []struct {
hexData string
readBits int
expectedValue uint
expectedNrBytesRead int
expectedNrBitsRead int
}{
{"00", 0, 0, 0, 8},
{"0001", 1, 0, 1, 1},
{"0001", 8, 0x00, 1, 8},
{"0010", 12, 0x001, 2, 4},
{"0102", 16, 0x0102, 2, 8},
{"00000304", 24, 0x000004, 4, 8},
}
for _, tc := range testCases {
t.Run("", func(t *testing.T) {
data, err := hex.DecodeString(tc.hexData)
if err != nil {
t.Error(err)
}
buf := bytes.NewBuffer(data)
r := bits.NewAccErrEBSPReader(buf)
if r.AccError() != nil {
t.Errorf("expected no error, got %v", r.AccError())
}
v := r.Read(tc.readBits)
if v != tc.expectedValue {
t.Errorf("expected value %d, got %d", tc.expectedValue, v)
}
if r.NrBytesRead() != tc.expectedNrBytesRead {
t.Errorf("expected %d bytes read, got %d", tc.expectedNrBytesRead, r.NrBytesRead())
}
if r.NrBitsReadInCurrentByte() != tc.expectedNrBitsRead {
t.Errorf("expected %d bits read, got %d", tc.expectedNrBitsRead, r.NrBitsReadInCurrentByte())
}
})
}
}

0 comments on commit 9cde8b7

Please sign in to comment.