Skip to content

Commit

Permalink
Merge pull request #136 from abema/sample-size-type
Browse files Browse the repository at this point in the history
Additional changes for #135: Update test code and revert type of Sample.Size
  • Loading branch information
sunfish-shogi authored Jul 27, 2023
2 parents 43d6fbf + efe42e7 commit a1a707d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
16 changes: 8 additions & 8 deletions probe.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ type EditListEntry struct {
type Samples []*Sample

type Sample struct {
Size uint64
Size uint32
TimeDelta uint32
CompositionTimeOffset int64
}
Expand Down Expand Up @@ -360,7 +360,7 @@ func probeTrak(r io.ReadSeeker, bi *BoxInfo) (*Track, error) {

if stsz != nil {
for i := 0; i < len(stsz.EntrySize) && i < len(track.Samples); i++ {
track.Samples[i].Size = uint64(stsz.EntrySize[i])
track.Samples[i].Size = stsz.EntrySize[i]
}
}

Expand Down Expand Up @@ -570,7 +570,7 @@ func FindIDRFrames(r io.ReadSeeker, trackInfo *TrackInfo) ([]int, error) {
if trackInfo.AVC == nil {
return nil, nil
}
lengthSize := uint64(trackInfo.AVC.LengthSize)
lengthSize := uint32(trackInfo.AVC.LengthSize)

var si int
idxs := make([]int, 0, 8)
Expand All @@ -582,17 +582,17 @@ func FindIDRFrames(r io.ReadSeeker, trackInfo *TrackInfo) ([]int, error) {
if sample.Size == 0 {
continue
}
for nalOffset := uint64(0); nalOffset+lengthSize+1 <= sample.Size; {
if _, err := r.Seek(int64(dataOffset+nalOffset), io.SeekStart); err != nil {
for nalOffset := uint32(0); nalOffset+lengthSize+1 <= sample.Size; {
if _, err := r.Seek(int64(dataOffset+uint64(nalOffset)), io.SeekStart); err != nil {
return nil, err
}
data := make([]byte, lengthSize+1)
if _, err := io.ReadFull(r, data); err != nil {
return nil, err
}
var length uint64
var length uint32
for i := 0; i < int(lengthSize); i++ {
length = (length << 8) + uint64(data[i])
length = (length << 8) + uint32(data[i])
}
nalHeader := data[lengthSize]
nalType := nalHeader & 0x1f
Expand All @@ -602,7 +602,7 @@ func FindIDRFrames(r io.ReadSeeker, trackInfo *TrackInfo) ([]int, error) {
}
nalOffset += lengthSize + length
}
dataOffset += sample.Size
dataOffset += uint64(sample.Size)
}
}
return idxs, nil
Expand Down
4 changes: 2 additions & 2 deletions probe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ func TestProbe(t *testing.T) {
assert.Equal(t, int64(2048), info.Tracks[0].Samples[0].CompositionTimeOffset)
assert.Equal(t, int64(1024), info.Tracks[0].Samples[9].CompositionTimeOffset)
require.Len(t, info.Tracks[0].Chunks, 9)
assert.Equal(t, uint32(48), info.Tracks[0].Chunks[0].DataOffset)
assert.Equal(t, uint32(6038), info.Tracks[0].Chunks[8].DataOffset)
assert.Equal(t, uint64(48), info.Tracks[0].Chunks[0].DataOffset)
assert.Equal(t, uint64(6038), info.Tracks[0].Chunks[8].DataOffset)
assert.Equal(t, uint32(2), info.Tracks[0].Chunks[0].SamplesPerChunk)
assert.Equal(t, uint32(1), info.Tracks[0].Chunks[8].SamplesPerChunk)

Expand Down

0 comments on commit a1a707d

Please sign in to comment.