From c463a3678f4ad0ae9329bd1cadc9c3e9a4d0e80b Mon Sep 17 00:00:00 2001 From: nareix Date: Sat, 18 Jun 2016 08:15:30 +0800 Subject: [PATCH] change float64->float32 --- atom/atom.go | 1 - atom/dumper.go | 1 - demuxer.go | 12 ++++++------ muxer.go | 8 ++++---- stream.go | 10 +++++----- 5 files changed, 15 insertions(+), 17 deletions(-) diff --git a/atom/atom.go b/atom/atom.go index f2551cd..70843fc 100644 --- a/atom/atom.go +++ b/atom/atom.go @@ -42,4 +42,3 @@ func WalkFile(w Walker, r io.Reader) (err error) { return } - diff --git a/atom/dumper.go b/atom/dumper.go index d77ea0a..262ed13 100644 --- a/atom/dumper.go +++ b/atom/dumper.go @@ -93,4 +93,3 @@ func (self Dumper) Bytes(val []byte) { func (self Dumper) TimeStamp(val TimeStamp) { self.Println(fmt.Sprintf("%s: %d", self.name, int(val))) } - diff --git a/demuxer.go b/demuxer.go index 72fd650..89c4c1d 100644 --- a/demuxer.go +++ b/demuxer.go @@ -4,10 +4,10 @@ import ( "bytes" "fmt" "github.com/nareix/av" - "github.com/nareix/mp4/atom" - "github.com/nareix/mp4/isom" "github.com/nareix/codec/aacparser" "github.com/nareix/codec/h264parser" + "github.com/nareix/mp4/atom" + "github.com/nareix/mp4/isom" "io" ) @@ -322,7 +322,7 @@ func (self *Demuxer) ReadPacket() (streamIndex int, pkt av.Packet, err error) { return } -func (self *Demuxer) CurrentTime() (time float64) { +func (self *Demuxer) CurrentTime() (time float32) { if len(self.streams) > 0 { stream := self.streams[0] time = stream.tsToTime(stream.dts) @@ -330,7 +330,7 @@ func (self *Demuxer) CurrentTime() (time float64) { return } -func (self *Demuxer) SeekToTime(time float64) (err error) { +func (self *Demuxer) SeekToTime(time float32) (err error) { for _, stream := range self.streams { if stream.IsVideo() { if err = stream.seekToTime(time); err != nil { @@ -395,7 +395,7 @@ func (self *Stream) readPacket() (pkt av.Packet, err error) { return } -func (self *Stream) seekToTime(time float64) (err error) { +func (self *Stream) seekToTime(time float32) (err error) { index := self.timeToSampleIndex(time) if err = self.setSampleIndex(index); err != nil { return @@ -406,7 +406,7 @@ func (self *Stream) seekToTime(time float64) (err error) { return } -func (self *Stream) timeToSampleIndex(time float64) int { +func (self *Stream) timeToSampleIndex(time float32) int { targetTs := self.timeToTs(time) targetIndex := 0 diff --git a/muxer.go b/muxer.go index 57a04e2..4493f1f 100644 --- a/muxer.go +++ b/muxer.go @@ -184,7 +184,7 @@ func (self *Muxer) WritePacket(streamIndex int, pkt av.Packet) (err error) { } newpkt := pkt newpkt.Data = payload - newpkt.Duration = float64(samples)/float64(sampleRate) + newpkt.Duration = float32(samples) / float32(sampleRate) if err = stream.writePacket(newpkt); err != nil { return } @@ -258,21 +258,21 @@ func (self *Muxer) WriteTrailer() (err error) { NextTrackId: 2, } - maxDur := float64(0) + maxDur := float32(0) timeScale := 10000 for _, stream := range self.streams { if err = stream.fillTrackAtom(); err != nil { return } dur := stream.tsToTime(stream.duration) - stream.trackAtom.Header.Duration = int(float64(timeScale) * dur) + stream.trackAtom.Header.Duration = int(float32(timeScale) * dur) if dur > maxDur { maxDur = dur } moov.Tracks = append(moov.Tracks, stream.trackAtom) } moov.Header.TimeScale = timeScale - moov.Header.Duration = int(float64(timeScale) * maxDur) + moov.Header.Duration = int(float32(timeScale) * maxDur) if err = self.mdatWriter.Close(); err != nil { return diff --git a/stream.go b/stream.go index 2e6cdf2..e2544dc 100644 --- a/stream.go +++ b/stream.go @@ -14,7 +14,7 @@ type Stream struct { idx int timeScale int64 - duration int64 + duration int64 muxer *Muxer @@ -39,10 +39,10 @@ type Stream struct { cttsEntry *atom.CompositionOffsetEntry } -func (self *Stream) timeToTs(time float64) int64 { - return int64(time * float64(self.timeScale)) +func (self *Stream) timeToTs(time float32) int64 { + return int64(time * float32(self.timeScale)) } -func (self *Stream) tsToTime(ts int64) float64 { - return float64(ts) / float64(self.timeScale) +func (self *Stream) tsToTime(ts int64) float32 { + return float32(ts) / float32(self.timeScale) }