From 21888f54d77d5a039f68cbe6e7746a11b4b26832 Mon Sep 17 00:00:00 2001 From: nareix Date: Fri, 18 Mar 2016 20:11:54 +0800 Subject: [PATCH] add track.go --- demuxer.go | 34 ++++++++++++++++++++++++++++++++++ track.go | 7 +++++++ 2 files changed, 41 insertions(+) diff --git a/demuxer.go b/demuxer.go index c1d0984..bf4b5c6 100644 --- a/demuxer.go +++ b/demuxer.go @@ -109,6 +109,40 @@ func (self *Track) setSampleIndex(index int) (err error) { return } + start = 0 + found = false + self.ptsEntryIndex = 0 + for self.ptsEntryIndex < len(self.sample.TimeToSample.Entries) { + n := self.sample.TimeToSample.Entries[self.ptsEntryIndex].Count + if index >= start && index < start+n { + self.sampleIndexInPtsEntry = index-start + break + } + start += n + self.ptsEntryIndex++ + } + if !found { + err = io.EOF + return + } + + start = 0 + found = false + self.dtsEntryIndex = 0 + for self.dtsEntryIndex < len(self.sample.CompositionOffset.Entries) { + n := self.sample.CompositionOffset.Entries[self.dtsEntryIndex].Count + if index >= start && index < start+n { + self.sampleIndexInDtsEntry = index-start + break + } + start += n + self.dtsEntryIndex++ + } + if !found { + err = io.EOF + return + } + self.sampleIndex = index return } diff --git a/track.go b/track.go index e4bb9b9..b68e0e1 100644 --- a/track.go +++ b/track.go @@ -20,6 +20,13 @@ type Track struct { sample *atom.SampleTable sampleIndex int + + ptsEntryIndex int + sampleIndexInPtsEntry int + + dtsEntryIndex int + sampleIndexInDtsEntry int + chunkGroupIndex int chunkIndex int sampleIndexInChunk int