Merge pull request #61 from sprucehealth/master

Fix panic in ReadPanic when no streams
This commit is contained in:
Eric Tang 2018-08-14 18:15:33 -04:00 committed by GitHub
commit 7d93fa5e2a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,13 +1,15 @@
package mp4
import (
"time"
"errors"
"fmt"
"io"
"time"
"github.com/nareix/joy4/av"
"github.com/nareix/joy4/codec/aacparser"
"github.com/nareix/joy4/codec/h264parser"
"github.com/nareix/joy4/format/mp4/mp4io"
"io"
)
type Demuxer struct {
@ -124,7 +126,7 @@ func (self *Stream) setSampleIndex(index int) (err error) {
}
if self.sample.SampleSize.SampleSize != 0 {
self.sampleOffsetInChunk = int64(self.sampleIndexInChunk)*int64(self.sample.SampleSize.SampleSize)
self.sampleOffsetInChunk = int64(self.sampleIndexInChunk) * int64(self.sample.SampleSize.SampleSize)
} else {
if index >= len(self.sample.SampleSize.Entries) {
err = fmt.Errorf("mp4: stream[%d]: sample index out of range", self.idx)
@ -145,12 +147,12 @@ func (self *Stream) setSampleIndex(index int) (err error) {
n := int(entry.Count)
if index >= start && index < start+n {
self.sampleIndexInSttsEntry = index - start
self.dts += int64(index-start)*int64(entry.Duration)
self.dts += int64(index-start) * int64(entry.Duration)
found = true
break
}
start += n
self.dts += int64(n)*int64(entry.Duration)
self.dts += int64(n) * int64(entry.Duration)
self.sttsEntryIndex++
}
if !found {
@ -299,6 +301,10 @@ func (self *Demuxer) ReadPacket() (pkt av.Packet, err error) {
if err = self.probe(); err != nil {
return
}
if len(self.streams) == 0 {
err = errors.New("mp4: no streams available while trying to read a packet")
return
}
var chosen *Stream
var chosenidx int
@ -430,7 +436,7 @@ func (self *Stream) timeToSampleIndex(tm time.Duration) int {
entries := self.sample.SyncSample.Entries
for i := len(entries) - 1; i >= 0; i-- {
if entries[i]-1 < uint32(targetIndex) {
targetIndex = int(entries[i]-1)
targetIndex = int(entries[i] - 1)
break
}
}