Skip to content

Commit

Permalink
Merge pull request #33 from edgeware/remove-logrus-dep
Browse files Browse the repository at this point in the history
fix: remove non-standard log
  • Loading branch information
tobbee authored Nov 17, 2020
2 parents 9528d72 + bbd5924 commit ed549e0
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 52 deletions.
13 changes: 8 additions & 5 deletions avc/avcdecoderconfigurationrecord.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ package avc

import (
"encoding/binary"
"errors"
"io"
"io/ioutil"

log "github.com/sirupsen/logrus"
"log"
)

var ErrCannotParseAVCExtension = errors.New("Cannot parse SPS extensions")
var ErrLengthSize = errors.New("Can only handle 4byte NAL length size")

//AVCDecConfRec - AVCDecoderConfigurationRecord
type AVCDecConfRec struct {
AVCProfileIndication byte
Expand Down Expand Up @@ -56,7 +59,7 @@ func DecodeAVCDecConfRec(r io.Reader) (AVCDecConfRec, error) {
AVCLevelIndication := data[3]
LengthSizeMinus1 := data[4] & 0x03 // The first 5 bits are 1
if LengthSizeMinus1 != 0x3 {
panic("Can only handle 4byte NAL length size")
return AVCDecConfRec{}, ErrLengthSize
}
numSPS := data[5] & 0x1f // 5 bits following 3 reserved bits
pos := 6
Expand Down Expand Up @@ -88,7 +91,7 @@ func DecodeAVCDecConfRec(r io.Reader) (AVCDecConfRec, error) {
// No more bytes
default:
if pos == len(data) { // Not according to standard, but have been seen
log.Warningf("No ChromaFormat info for AVCProfileIndication=%d", AVCProfileIndication)
log.Printf("No ChromaFormat info for AVCProfileIndication %d", AVCProfileIndication)
adcr.NoTrailingInfo = true
return adcr, nil
}
Expand All @@ -97,7 +100,7 @@ func DecodeAVCDecConfRec(r io.Reader) (AVCDecConfRec, error) {
adcr.BitDepthChromaMinus1 = data[pos+2] & 0x07
adcr.NumSPSExt = data[pos+3]
if adcr.NumSPSExt != 0 {
panic("Cannot handle SPS extensions")
return adcr, ErrCannotParseAVCExtension
}
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/mp4ff-pslister/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ import (
"encoding/hex"
"flag"
"fmt"
"log"
"os"

"github.com/edgeware/mp4ff/avc"
"github.com/edgeware/mp4ff/mp4"
log "github.com/sirupsen/logrus"
)

func main() {
Expand Down
6 changes: 3 additions & 3 deletions examples/initcreator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package main
import (
"encoding/hex"
"errors"
"log"
"os"

"github.com/edgeware/mp4ff/mp4"
log "github.com/sirupsen/logrus"
)

const sps1nalu = "67640020accac05005bb0169e0000003002000000c9c4c000432380008647c12401cb1c31380"
Expand All @@ -16,11 +16,11 @@ func main() {

err := writeVideoAVCInitSegment()
if err != nil {
log.Fatal(err)
log.Fatalln(err)
}
err = writeAudioAACInitSegment()
if err != nil {
log.Fatal(err)
log.Fatalln(err)
}
}

Expand Down
5 changes: 4 additions & 1 deletion examples/resegmenter/resegment.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ func Resegment(in *mp4.File, chunkDur uint64) (*mp4.File, error) {

for _, iSeg := range in.Segments {
for _, iFrag := range iSeg.Fragments {
fSamples := iFrag.GetFullSamples(in.Init.Moov.Mvex.Trex)
fSamples, err := iFrag.GetFullSamples(in.Init.Moov.Mvex.Trex)
if err != nil {
return nil, err
}
iSamples = append(iSamples, fSamples...)
}
}
Expand Down
5 changes: 1 addition & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,4 @@ module github.com/edgeware/mp4ff

go 1.14

require (
github.com/go-test/deep v1.0.6
github.com/sirupsen/logrus v1.6.0
)
require github.com/go-test/deep v1.0.6
12 changes: 0 additions & 12 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,14 +1,2 @@
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/go-test/deep v1.0.6 h1:UHSEyLZUwX9Qoi99vVwvewiMC8mM2bf7XEM2nqvzEn8=
github.com/go-test/deep v1.0.6/go.mod h1:QV8Hv/iy04NyLBxAdO9njL0iVPN1S4d/A3NVv1V36o8=
github.com/konsorten/go-windows-terminal-sequences v1.0.3 h1:CE8S1cTafDpPvMhIxNJKvHsGVBgn1xWYf1NbHQhywc8=
github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sirupsen/logrus v1.6.0 h1:UBcNElsrwanuuMsnGSlYmtmgbb23qDR5dG+6X6Oo89I=
github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88=
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
golang.org/x/sys v0.0.0-20190422165155-953cdadca894 h1:Cz4ceDQGXuKRnVBDTS23GTn/pU5OE2C0WrNTOYK1Uuc=
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
7 changes: 1 addition & 6 deletions mp4/box.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import (
"errors"
"fmt"
"io"

log "github.com/sirupsen/logrus"
)

const (
Expand Down Expand Up @@ -136,7 +134,6 @@ func decodeHeader(r io.Reader) (*boxHeader, error) {
// EncodeHeader encodes a box header to a writer
func EncodeHeader(b Box, w io.Writer) error {
boxType, boxSize := b.Type(), b.Size()
log.Debugf("Writing %v size %d\n", boxType, boxSize)
buf := make([]byte, boxHeaderSize)
largeSize := false
if boxSize < 1<<32 {
Expand All @@ -145,7 +142,7 @@ func EncodeHeader(b Box, w io.Writer) error {
largeSize = true
binary.BigEndian.PutUint32(buf, 1)
}
strtobuf(buf[4:], b.Type(), 4)
strtobuf(buf[4:], boxType, 4)
if largeSize {
binary.BigEndian.PutUint64(buf, boxSize)
}
Expand Down Expand Up @@ -179,11 +176,9 @@ func DecodeBox(startPos uint64, r io.Reader) (Box, error) {
remainingLength := int64(h.size) - int64(h.hdrlen)

if !ok {
log.Debugf("Found unknown box type %v, size %v", h.name, h.size)
b, err = DecodeUnknown(h, startPos, io.LimitReader(r, remainingLength))

} else {
log.Debugf("Found supported box %v, size %v", h.name, h.size)
b, err = d(h, startPos, io.LimitReader(r, remainingLength))
}
if err != nil {
Expand Down
16 changes: 5 additions & 11 deletions mp4/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import (
"fmt"
"io"
"os"

log "github.com/sirupsen/logrus"
)

// File - an MPEG-4 file asset
Expand Down Expand Up @@ -51,31 +49,27 @@ func DecodeFile(r io.Reader) (*File, error) {

LoopBoxes:
for {
//f := r.(*os.File)
//p, err := f.Seek(0, os.SEEK_CUR)
//log.Printf("Byte position is %v", p)
box, err := DecodeBox(boxStartPos, r)
if err == io.EOF {
break LoopBoxes
}
if err != nil {
return nil, err
}
bType, bSize := box.Type(), box.Size()
log.Debugf("Box %v, size %v at pos %v", bType, bSize, boxStartPos)
boxType, boxSize := box.Type(), box.Size()
if err != nil {
return nil, err
}
if bType == "mdat" {
if boxType == "mdat" {
if f.isFragmented {
if lastBoxType != "moof" {
log.Fatalf("Does not support %v between moof and mdat", lastBoxType)
return nil, fmt.Errorf("Does not support %v between moof and mdat", lastBoxType)
}
}
}
f.AddChild(box, boxStartPos)
lastBoxType = bType
boxStartPos += bSize
lastBoxType = boxType
boxStartPos += boxSize
}
return f, nil
}
Expand Down
17 changes: 9 additions & 8 deletions mp4/fragment.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package mp4

import (
"errors"
"fmt"
"io"

log "github.com/sirupsen/logrus"
)

// Fragment - MP4 Fragment ([prft] + moof + mdat)
Expand Down Expand Up @@ -55,11 +54,10 @@ func (f *Fragment) AddChild(b Box) {
}

// GetFullSamples - Get full samples including media and accumulated time
func (f *Fragment) GetFullSamples(trex *TrexBox) []*FullSample {
func (f *Fragment) GetFullSamples(trex *TrexBox) ([]*FullSample, error) {
moof := f.Moof
mdat := f.Mdat
seqNr := moof.Mfhd.SequenceNumber
log.Debugf("Got samples for Segment %d\n", seqNr)
//seqNr := moof.Mfhd.SequenceNumber
tfhd := moof.Traf.Tfhd
baseTime := moof.Traf.Tfdt.BaseMediaDecodeTime
trun := moof.Traf.Trun
Expand All @@ -78,10 +76,10 @@ func (f *Fragment) GetFullSamples(trex *TrexBox) []*FullSample {
mdatDataLength := uint64(len(mdat.Data)) // TODO Make len take 64-bit number
offsetInMdat := baseOffset - mdatStartPos - headerLength(mdatDataLength)
if offsetInMdat > mdatDataLength {
log.Fatalf("Offset in mdata beyond size")
return nil, errors.New("Offset in mdata beyond size")
}
samples := trun.GetFullSamples(uint32(offsetInMdat), baseTime, f.Mdat)
return samples
return samples, nil
}

// AddFullSample - add a full sample to a fragment
Expand All @@ -98,7 +96,10 @@ func (f *Fragment) AddFullSample(s *FullSample) {

// DumpSampleData - Get Sample data and print out
func (f *Fragment) DumpSampleData(w io.Writer, trex *TrexBox) error {
samples := f.GetFullSamples(trex)
samples, err := f.GetFullSamples(trex)
if err != nil {
return err
}
for i, s := range samples {
if i < 9 {
fmt.Printf("%4d %8d %8d %6x %d %d\n", i, s.DecodeTime, s.PresentationTime(),
Expand Down
5 changes: 4 additions & 1 deletion mp4/mediasegment.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@ func (s *MediaSegment) Fragmentify(timescale uint64, trex *TrexBox, duration uin

for _, inFrag := range inFragments {

samples := inFrag.GetFullSamples(trex)
samples, err := inFrag.GetFullSamples(trex)
if err != nil {
return nil, err
}
for _, s := range samples {
if cumDur == 0 {
var err error
Expand Down

0 comments on commit ed549e0

Please sign in to comment.