diff --git a/astits/main.go b/astits/main.go index 274943c..8c7781b 100644 --- a/astits/main.go +++ b/astits/main.go @@ -3,9 +3,11 @@ package main import ( "context" "encoding/json" + "errors" "flag" "fmt" "io" + "log" "net" "net/url" "os" @@ -14,9 +16,7 @@ import ( "syscall" "github.com/asticode/go-astikit" - "github.com/asticode/go-astilog" "github.com/asticode/go-astits" - "github.com/pkg/errors" "github.com/pkg/profile" ) @@ -38,9 +38,7 @@ func main() { } flag.Var(dataTypes, "d", "the datatypes whitelist (all, pat, pmt, pes, eit, nit, sdt, tot)") cmd := astikit.FlagCmd() - astilog.SetHandyFlags() flag.Parse() - astilog.FlagInit() // Handle signals handleSignals() @@ -56,8 +54,7 @@ func main() { var r io.Reader var err error if r, err = buildReader(ctx); err != nil { - astilog.Error(errors.Wrap(err, "astits: parsing input failed")) - return + log.Fatal(fmt.Errorf("astits: parsing input failed: %w", err)) } // Make sure the reader is closed properly @@ -73,21 +70,18 @@ func main() { case "data": // Fetch data if err = data(dmx); err != nil { - astilog.Error(errors.Wrap(err, "astits: fetching data failed")) - return + log.Fatal(fmt.Errorf("astits: fetching data failed: %w", err)) } case "packets": // Fetch packets if err = packets(dmx); err != nil { - astilog.Error(errors.Wrap(err, "astits: fetching packets failed")) - return + log.Fatal(fmt.Errorf("astits: fetching packets failed: %w", err)) } default: // Fetch the programs var pgms []*Program if pgms, err = programs(dmx); err != nil { - astilog.Error(errors.Wrap(err, "astits: fetching programs failed")) - return + log.Fatal(fmt.Errorf("astits: fetching programs failed: %w", err)) } // Print @@ -96,13 +90,12 @@ func main() { var e = json.NewEncoder(os.Stdout) e.SetIndent("", " ") if err = e.Encode(pgms); err != nil { - astilog.Error(errors.Wrap(err, "astits: json encoding to stdout failed")) - return + log.Fatal(fmt.Errorf("astits: json encoding to stdout failed: %w", err)) } default: fmt.Println("Programs are:") for _, pgm := range pgms { - fmt.Printf("* %s\n", pgm) + log.Printf("* %s\n", pgm) } } } @@ -113,7 +106,7 @@ func handleSignals() { signal.Notify(ch) go func() { for s := range ch { - astilog.Debugf("Received signal %s", s) + log.Printf("Received signal %s\n", s) switch s { case syscall.SIGABRT, syscall.SIGINT, syscall.SIGQUIT, syscall.SIGTERM: cancel() @@ -126,14 +119,14 @@ func handleSignals() { func buildReader(ctx context.Context) (r io.Reader, err error) { // Validate input if len(*inputPath) <= 0 { - err = errors.New("Use -i to indicate an input path") + err = errors.New("use -i to indicate an input path") return } // Parse input var u *url.URL if u, err = url.Parse(*inputPath); err != nil { - err = errors.Wrap(err, "astits: parsing input path failed") + err = fmt.Errorf("astits: parsing input path failed: %w", err) return } @@ -143,14 +136,14 @@ func buildReader(ctx context.Context) (r io.Reader, err error) { // Resolve addr var addr *net.UDPAddr if addr, err = net.ResolveUDPAddr("udp", u.Host); err != nil { - err = errors.Wrapf(err, "astits: resolving udp addr %s failed", u.Host) + err = fmt.Errorf("astits: resolving udp addr %s failed: %w", u.Host, err) return } // Listen to multicast UDP var c *net.UDPConn if c, err = net.ListenMulticastUDP("udp", nil, addr); err != nil { - err = errors.Wrapf(err, "astits: listening on multicast udp addr %s failed", u.Host) + err = fmt.Errorf("astits: listening on multicast udp addr %s failed: %w", u.Host, err) return } c.SetReadBuffer(4096) @@ -159,7 +152,7 @@ func buildReader(ctx context.Context) (r io.Reader, err error) { // Open file var f *os.File if f, err = os.Open(*inputPath); err != nil { - err = errors.Wrapf(err, "astits: opening %s failed", *inputPath) + err = fmt.Errorf("astits: opening %s failed: %w", *inputPath, err) return } r = f @@ -170,28 +163,28 @@ func buildReader(ctx context.Context) (r io.Reader, err error) { func packets(dmx *astits.Demuxer) (err error) { // Loop through packets var p *astits.Packet - astilog.Debug("Fetching packets...") + log.Println("Fetching packets...") for { // Get next packet if p, err = dmx.NextPacket(); err != nil { if err == astits.ErrNoMorePackets { break } - err = errors.Wrap(err, "astits: getting next packet failed") + err = fmt.Errorf("astits: getting next packet failed: %w", err) return } // Log packet - astilog.Infof("PKT: %d", p.Header.PID) - astilog.Infof(" Continuity Counter: %v", p.Header.ContinuityCounter) - astilog.Infof(" Payload Unit Start Indicator: %v", p.Header.PayloadUnitStartIndicator) - astilog.Infof(" Has Payload: %v", p.Header.HasPayload) - astilog.Infof(" Has Adaptation Field: %v", p.Header.HasAdaptationField) - astilog.Infof(" Transport Error Indicator: %v", p.Header.TransportErrorIndicator) - astilog.Infof(" Transport Priority: %v", p.Header.TransportPriority) - astilog.Infof(" Transport Scrambling Control: %v", p.Header.TransportScramblingControl) + log.Printf("PKT: %d\n", p.Header.PID) + log.Printf(" Continuity Counter: %v\n", p.Header.ContinuityCounter) + log.Printf(" Payload Unit Start Indicator: %v\n", p.Header.PayloadUnitStartIndicator) + log.Printf(" Has Payload: %v\n", p.Header.HasPayload) + log.Printf(" Has Adaptation Field: %v\n", p.Header.HasAdaptationField) + log.Printf(" Transport Error Indicator: %v\n", p.Header.TransportErrorIndicator) + log.Printf(" Transport Priority: %v\n", p.Header.TransportPriority) + log.Printf(" Transport Scrambling Control: %v\n", p.Header.TransportScramblingControl) if p.Header.HasAdaptationField { - astilog.Infof(" Adaptation Field: %+v", p.AdaptationField) + log.Printf(" Adaptation Field: %+v\n", p.AdaptationField) } } return nil @@ -227,51 +220,51 @@ func data(dmx *astits.Demuxer) (err error) { // Loop through data var d *astits.Data - astilog.Debug("Fetching data...") + log.Println("Fetching data...") for { // Get next data if d, err = dmx.NextData(); err != nil { if err == astits.ErrNoMorePackets { break } - err = errors.Wrap(err, "astits: getting next data failed") + err = fmt.Errorf("astits: getting next data failed: %w", err) return } // Log data if d.EIT != nil && (logAll || logEIT) { - astilog.Infof("EIT: %d", d.PID) - astilog.Info(eventsToString(d.EIT.Events)) + log.Printf("EIT: %d\n", d.PID) + log.Println(eventsToString(d.EIT.Events)) } else if d.NIT != nil && (logAll || logNIT) { - astilog.Infof("NIT: %d", d.PID) + log.Printf("NIT: %d\n", d.PID) } else if d.PAT != nil && (logAll || logPAT) { - astilog.Infof("PAT: %d", d.PID) - astilog.Infof(" Transport Stream ID: %v", d.PAT.TransportStreamID) - astilog.Infof(" Programs:") + log.Printf("PAT: %d\n", d.PID) + log.Printf(" Transport Stream ID: %v\n", d.PAT.TransportStreamID) + log.Println(" Programs:") for _, p := range d.PAT.Programs { - astilog.Infof(" %+v", p) + log.Printf(" %+v\n", p) } } else if d.PES != nil && (logAll || logPES) { - astilog.Infof("PES: %d", d.PID) - astilog.Infof(" Stream ID: %v", d.PES.Header.StreamID) - astilog.Infof(" Packet Length: %v", d.PES.Header.PacketLength) - astilog.Infof(" Optional Header: %+v", d.PES.Header.OptionalHeader) + log.Printf("PES: %d\n", d.PID) + log.Printf(" Stream ID: %v\n", d.PES.Header.StreamID) + log.Printf(" Packet Length: %v\n", d.PES.Header.PacketLength) + log.Printf(" Optional Header: %+v\n", d.PES.Header.OptionalHeader) } else if d.PMT != nil && (logAll || logPMT) { - astilog.Infof("PMT: %d", d.PID) - astilog.Infof(" ProgramNumber: %v", d.PMT.ProgramNumber) - astilog.Infof(" PCR PID: %v", d.PMT.PCRPID) - astilog.Infof(" Elementary Streams:") + log.Printf("PMT: %d\n", d.PID) + log.Printf(" ProgramNumber: %v\n", d.PMT.ProgramNumber) + log.Printf(" PCR PID: %v\n", d.PMT.PCRPID) + log.Println(" Elementary Streams:") for _, s := range d.PMT.ElementaryStreams { - astilog.Infof(" %+v", s) + log.Printf(" %+v\n", s) } - astilog.Infof(" Program Descriptors:") + log.Println(" Program Descriptors:") for _, d := range d.PMT.ProgramDescriptors { - astilog.Infof(" %+v", d) + log.Printf(" %+v\n", d) } } else if d.SDT != nil && (logAll || logSDT) { - astilog.Infof("SDT: %d", d.PID) + log.Printf("SDT: %d\n", d.PID) } else if d.TOT != nil && (logAll || logTOT) { - astilog.Infof("TOT: %d", d.PID) + log.Printf("TOT: %d\n", d.PID) } } return @@ -282,7 +275,7 @@ func programs(dmx *astits.Demuxer) (o []*Program, err error) { var d *astits.Data var pgmsToProcess = make(map[uint16]bool) var pgms = make(map[uint16]*Program) - astilog.Debug("Fetching data...") + log.Println("Fetching data...") for { // Get next data if d, err = dmx.NextData(); err != nil { @@ -290,7 +283,7 @@ func programs(dmx *astits.Demuxer) (o []*Program, err error) { err = nil break } - err = errors.Wrap(err, "astits: getting next data failed") + err = fmt.Errorf("astits: getting next data failed: %w", err) return } diff --git a/data.go b/data.go index 23aaa51..0cadf9a 100644 --- a/data.go +++ b/data.go @@ -1,8 +1,9 @@ package astits import ( + "fmt" + "github.com/asticode/go-astikit" - "github.com/pkg/errors" ) // PIDs @@ -32,7 +33,7 @@ func parseData(ps []*Packet, prs PacketsParser, pm programMap) (ds []*Data, err if prs != nil { var skip bool if ds, skip, err = prs(ps); err != nil { - err = errors.Wrap(err, "astits: custom packets parsing failed") + err = fmt.Errorf("astits: custom packets parsing failed: %w", err) return } else if skip { return @@ -66,7 +67,7 @@ func parseData(ps []*Packet, prs PacketsParser, pm programMap) (ds []*Data, err // Parse PSI data var psiData *PSIData if psiData, err = parsePSIData(i); err != nil { - err = errors.Wrap(err, "astits: parsing PSI data failed") + err = fmt.Errorf("astits: parsing PSI data failed: %w", err) return } @@ -76,7 +77,7 @@ func parseData(ps []*Packet, prs PacketsParser, pm programMap) (ds []*Data, err // Parse PES data var pesData *PESData if pesData, err = parsePESData(i); err != nil { - err = errors.Wrap(err, "astits: parsing PES data failed") + err = fmt.Errorf("astits: parsing PES data failed: %w", err) return } diff --git a/data_eit.go b/data_eit.go index 48d9dcd..a8d4135 100644 --- a/data_eit.go +++ b/data_eit.go @@ -1,10 +1,10 @@ package astits import ( + "fmt" "time" "github.com/asticode/go-astikit" - "github.com/pkg/errors" ) // EITData represents an EIT data @@ -36,7 +36,7 @@ func parseEITSection(i *astikit.BytesIterator, offsetSectionsEnd int, tableIDExt // Get next 2 bytes var bs []byte if bs, err = i.NextBytes(2); err != nil { - err = errors.Wrap(err, "astits: fetching next bytes failed") + err = fmt.Errorf("astits: fetching next bytes failed: %w", err) return } @@ -45,7 +45,7 @@ func parseEITSection(i *astikit.BytesIterator, offsetSectionsEnd int, tableIDExt // Get next 2 bytes if bs, err = i.NextBytes(2); err != nil { - err = errors.Wrap(err, "astits: fetching next bytes failed") + err = fmt.Errorf("astits: fetching next bytes failed: %w", err) return } @@ -55,7 +55,7 @@ func parseEITSection(i *astikit.BytesIterator, offsetSectionsEnd int, tableIDExt // Get next byte var b byte if b, err = i.NextByte(); err != nil { - err = errors.Wrap(err, "astits: fetching next byte failed") + err = fmt.Errorf("astits: fetching next byte failed: %w", err) return } @@ -64,7 +64,7 @@ func parseEITSection(i *astikit.BytesIterator, offsetSectionsEnd int, tableIDExt // Get next byte if b, err = i.NextByte(); err != nil { - err = errors.Wrap(err, "astits: fetching next byte failed") + err = fmt.Errorf("astits: fetching next byte failed: %w", err) return } @@ -75,7 +75,7 @@ func parseEITSection(i *astikit.BytesIterator, offsetSectionsEnd int, tableIDExt for i.Offset() < offsetSectionsEnd { // Get next 2 bytes if bs, err = i.NextBytes(2); err != nil { - err = errors.Wrap(err, "astits: fetching next bytes failed") + err = fmt.Errorf("astits: fetching next bytes failed: %w", err) return } @@ -85,19 +85,19 @@ func parseEITSection(i *astikit.BytesIterator, offsetSectionsEnd int, tableIDExt // Start time if e.StartTime, err = parseDVBTime(i); err != nil { - err = errors.Wrap(err, "astits: parsing DVB time") + err = fmt.Errorf("astits: parsing DVB time") return } // Duration if e.Duration, err = parseDVBDurationSeconds(i); err != nil { - err = errors.Wrap(err, "astits: parsing DVB duration seconds failed") + err = fmt.Errorf("astits: parsing DVB duration seconds failed: %w", err) return } // Get next byte if b, err = i.NextByte(); err != nil { - err = errors.Wrap(err, "astits: fetching next byte failed") + err = fmt.Errorf("astits: fetching next byte failed: %w", err) return } @@ -112,7 +112,7 @@ func parseEITSection(i *astikit.BytesIterator, offsetSectionsEnd int, tableIDExt // Descriptors if e.Descriptors, err = parseDescriptors(i); err != nil { - err = errors.Wrap(err, "astits: parsing descriptors failed") + err = fmt.Errorf("astits: parsing descriptors failed: %w", err) return } diff --git a/data_nit.go b/data_nit.go index 3d39d5f..33d571f 100644 --- a/data_nit.go +++ b/data_nit.go @@ -1,8 +1,9 @@ package astits import ( + "fmt" + "github.com/asticode/go-astikit" - "github.com/pkg/errors" ) // NITData represents a NIT data @@ -27,14 +28,14 @@ func parseNITSection(i *astikit.BytesIterator, tableIDExtension uint16) (d *NITD // Network descriptors if d.NetworkDescriptors, err = parseDescriptors(i); err != nil { - err = errors.Wrap(err, "astits: parsing descriptors failed") + err = fmt.Errorf("astits: parsing descriptors failed: %w", err) return } // Get next bytes var bs []byte if bs, err = i.NextBytes(2); err != nil { - err = errors.Wrap(err, "astits: fetching next bytes failed") + err = fmt.Errorf("astits: fetching next bytes failed: %w", err) return } @@ -49,7 +50,7 @@ func parseNITSection(i *astikit.BytesIterator, tableIDExtension uint16) (d *NITD // Get next bytes if bs, err = i.NextBytes(2); err != nil { - err = errors.Wrap(err, "astits: fetching next bytes failed") + err = fmt.Errorf("astits: fetching next bytes failed: %w", err) return } @@ -58,7 +59,7 @@ func parseNITSection(i *astikit.BytesIterator, tableIDExtension uint16) (d *NITD // Get next bytes if bs, err = i.NextBytes(2); err != nil { - err = errors.Wrap(err, "astits: fetching next bytes failed") + err = fmt.Errorf("astits: fetching next bytes failed: %w", err) return } @@ -67,7 +68,7 @@ func parseNITSection(i *astikit.BytesIterator, tableIDExtension uint16) (d *NITD // Transport descriptors if ts.TransportDescriptors, err = parseDescriptors(i); err != nil { - err = errors.Wrap(err, "astits: parsing descriptors failed") + err = fmt.Errorf("astits: parsing descriptors failed: %w", err) return } diff --git a/data_pat.go b/data_pat.go index a684a5b..1c32836 100644 --- a/data_pat.go +++ b/data_pat.go @@ -1,8 +1,9 @@ package astits import ( + "fmt" + "github.com/asticode/go-astikit" - "github.com/pkg/errors" ) // PATData represents a PAT data @@ -28,7 +29,7 @@ func parsePATSection(i *astikit.BytesIterator, offsetSectionsEnd int, tableIDExt // Get next bytes var bs []byte if bs, err = i.NextBytes(4); err != nil { - err = errors.Wrap(err, "astits: fetching next bytes failed") + err = fmt.Errorf("astits: fetching next bytes failed: %w", err) return } diff --git a/data_pes.go b/data_pes.go index 49f619f..b84f051 100644 --- a/data_pes.go +++ b/data_pes.go @@ -1,8 +1,9 @@ package astits import ( + "fmt" + "github.com/asticode/go-astikit" - "github.com/pkg/errors" ) // P-STD buffer scales @@ -112,7 +113,7 @@ func parsePESData(i *astikit.BytesIterator) (d *PESData, err error) { // Parse header var dataStart, dataEnd int if d.Header, dataStart, dataEnd, err = parsePESHeader(i); err != nil { - err = errors.Wrap(err, "astits: parsing PES header failed") + err = fmt.Errorf("astits: parsing PES header failed: %w", err) return } @@ -121,7 +122,7 @@ func parsePESData(i *astikit.BytesIterator) (d *PESData, err error) { // Extract data if d.Data, err = i.NextBytes(dataEnd - dataStart); err != nil { - err = errors.Wrap(err, "astits: fetching next bytes failed") + err = fmt.Errorf("astits: fetching next bytes failed: %w", err) return } return @@ -140,7 +141,7 @@ func parsePESHeader(i *astikit.BytesIterator) (h *PESHeader, dataStart, dataEnd // Get next byte var b byte if b, err = i.NextByte(); err != nil { - err = errors.Wrap(err, "astits: fetching next byte failed") + err = fmt.Errorf("astits: fetching next byte failed: %w", err) return } @@ -150,7 +151,7 @@ func parsePESHeader(i *astikit.BytesIterator) (h *PESHeader, dataStart, dataEnd // Get next bytes var bs []byte if bs, err = i.NextBytes(2); err != nil { - err = errors.Wrap(err, "astits: fetching next bytes failed") + err = fmt.Errorf("astits: fetching next bytes failed: %w", err) return } @@ -167,7 +168,7 @@ func parsePESHeader(i *astikit.BytesIterator) (h *PESHeader, dataStart, dataEnd // Optional header if hasPESOptionalHeader(h.StreamID) { if h.OptionalHeader, dataStart, err = parsePESOptionalHeader(i); err != nil { - err = errors.Wrap(err, "astits: parsing PES optional header failed") + err = fmt.Errorf("astits: parsing PES optional header failed: %w", err) return } } else { @@ -184,7 +185,7 @@ func parsePESOptionalHeader(i *astikit.BytesIterator) (h *PESOptionalHeader, dat // Get next byte var b byte if b, err = i.NextByte(); err != nil { - err = errors.Wrap(err, "astits: fetching next byte failed") + err = fmt.Errorf("astits: fetching next byte failed: %w", err) return } @@ -208,7 +209,7 @@ func parsePESOptionalHeader(i *astikit.BytesIterator) (h *PESOptionalHeader, dat // Get next byte if b, err = i.NextByte(); err != nil { - err = errors.Wrap(err, "astits: fetching next byte failed") + err = fmt.Errorf("astits: fetching next byte failed: %w", err) return } @@ -225,7 +226,7 @@ func parsePESOptionalHeader(i *astikit.BytesIterator) (h *PESOptionalHeader, dat // Get next byte if b, err = i.NextByte(); err != nil { - err = errors.Wrap(err, "astits: fetching next byte failed") + err = fmt.Errorf("astits: fetching next byte failed: %w", err) return } @@ -238,16 +239,16 @@ func parsePESOptionalHeader(i *astikit.BytesIterator) (h *PESOptionalHeader, dat // PTS/DTS if h.PTSDTSIndicator == PTSDTSIndicatorOnlyPTS { if h.PTS, err = parsePTSOrDTS(i); err != nil { - err = errors.Wrap(err, "astits: parsing PTS failed") + err = fmt.Errorf("astits: parsing PTS failed: %w", err) return } } else if h.PTSDTSIndicator == PTSDTSIndicatorBothPresent { if h.PTS, err = parsePTSOrDTS(i); err != nil { - err = errors.Wrap(err, "astits: parsing PTS failed") + err = fmt.Errorf("astits: parsing PTS failed: %w", err) return } if h.DTS, err = parsePTSOrDTS(i); err != nil { - err = errors.Wrap(err, "astits: parsing PTS failed") + err = fmt.Errorf("astits: parsing PTS failed: %w", err) return } } @@ -255,7 +256,7 @@ func parsePESOptionalHeader(i *astikit.BytesIterator) (h *PESOptionalHeader, dat // ESCR if h.HasESCR { if h.ESCR, err = parseESCR(i); err != nil { - err = errors.Wrap(err, "astits: parsing ESCR failed") + err = fmt.Errorf("astits: parsing ESCR failed: %w", err) return } } @@ -264,7 +265,7 @@ func parsePESOptionalHeader(i *astikit.BytesIterator) (h *PESOptionalHeader, dat if h.HasESRate { var bs []byte if bs, err = i.NextBytes(3); err != nil { - err = errors.Wrap(err, "astits: fetching next bytes failed") + err = fmt.Errorf("astits: fetching next bytes failed: %w", err) return } h.ESRate = uint32(bs[0])&0x7f<<15 | uint32(bs[1])<<7 | uint32(bs[2])>>1 @@ -273,7 +274,7 @@ func parsePESOptionalHeader(i *astikit.BytesIterator) (h *PESOptionalHeader, dat // Trick mode if h.HasDSMTrickMode { if b, err = i.NextByte(); err != nil { - err = errors.Wrap(err, "astits: fetching next byte failed") + err = fmt.Errorf("astits: fetching next byte failed: %w", err) return } h.DSMTrickMode = parseDSMTrickMode(b) @@ -282,7 +283,7 @@ func parsePESOptionalHeader(i *astikit.BytesIterator) (h *PESOptionalHeader, dat // Additional copy info if h.HasAdditionalCopyInfo { if b, err = i.NextByte(); err != nil { - err = errors.Wrap(err, "astits: fetching next byte failed") + err = fmt.Errorf("astits: fetching next byte failed: %w", err) return } h.AdditionalCopyInfo = b & 0x7f @@ -292,7 +293,7 @@ func parsePESOptionalHeader(i *astikit.BytesIterator) (h *PESOptionalHeader, dat if h.HasCRC { var bs []byte if bs, err = i.NextBytes(2); err != nil { - err = errors.Wrap(err, "astits: fetching next bytes failed") + err = fmt.Errorf("astits: fetching next bytes failed: %w", err) return } h.CRC = uint16(bs[0])>>8 | uint16(bs[1]) @@ -302,7 +303,7 @@ func parsePESOptionalHeader(i *astikit.BytesIterator) (h *PESOptionalHeader, dat if h.HasExtension { // Get next byte if b, err = i.NextByte(); err != nil { - err = errors.Wrap(err, "astits: fetching next byte failed") + err = fmt.Errorf("astits: fetching next byte failed: %w", err) return } @@ -316,7 +317,7 @@ func parsePESOptionalHeader(i *astikit.BytesIterator) (h *PESOptionalHeader, dat // Private data if h.HasPrivateData { if h.PrivateData, err = i.NextBytes(16); err != nil { - err = errors.Wrap(err, "astits: fetching next bytes failed") + err = fmt.Errorf("astits: fetching next bytes failed: %w", err) return } } @@ -324,7 +325,7 @@ func parsePESOptionalHeader(i *astikit.BytesIterator) (h *PESOptionalHeader, dat // Pack field length if h.HasPackHeaderField { if b, err = i.NextByte(); err != nil { - err = errors.Wrap(err, "astits: fetching next byte failed") + err = fmt.Errorf("astits: fetching next byte failed: %w", err) return } h.PackField = uint8(b) @@ -334,7 +335,7 @@ func parsePESOptionalHeader(i *astikit.BytesIterator) (h *PESOptionalHeader, dat if h.HasProgramPacketSequenceCounter { var bs []byte if bs, err = i.NextBytes(2); err != nil { - err = errors.Wrap(err, "astits: fetching next bytes failed") + err = fmt.Errorf("astits: fetching next bytes failed: %w", err) return } h.PacketSequenceCounter = uint8(bs[0]) & 0x7f @@ -346,7 +347,7 @@ func parsePESOptionalHeader(i *astikit.BytesIterator) (h *PESOptionalHeader, dat if h.HasPSTDBuffer { var bs []byte if bs, err = i.NextBytes(2); err != nil { - err = errors.Wrap(err, "astits: fetching next bytes failed") + err = fmt.Errorf("astits: fetching next bytes failed: %w", err) return } h.PSTDBufferScale = bs[0] >> 5 & 0x1 @@ -358,14 +359,14 @@ func parsePESOptionalHeader(i *astikit.BytesIterator) (h *PESOptionalHeader, dat // Length var bs []byte if bs, err = i.NextBytes(2); err != nil { - err = errors.Wrap(err, "astits: fetching next bytes failed") + err = fmt.Errorf("astits: fetching next bytes failed: %w", err) return } h.Extension2Length = uint8(bs[0]) & 0x7f // Data if h.Extension2Data, err = i.NextBytes(int(h.Extension2Length)); err != nil { - err = errors.Wrap(err, "astits: fetching next bytes failed") + err = fmt.Errorf("astits: fetching next bytes failed: %w", err) return } } @@ -393,7 +394,7 @@ func parseDSMTrickMode(i byte) (m *DSMTrickMode) { func parsePTSOrDTS(i *astikit.BytesIterator) (cr *ClockReference, err error) { var bs []byte if bs, err = i.NextBytes(5); err != nil { - err = errors.Wrap(err, "astits: fetching next bytes failed") + err = fmt.Errorf("astits: fetching next bytes failed: %w", err) return } cr = newClockReference(int(uint64(bs[0])>>1&0x7<<30|uint64(bs[1])<<22|uint64(bs[2])>>1&0x7f<<15|uint64(bs[3])<<7|uint64(bs[4])>>1&0x7f), 0) @@ -404,7 +405,7 @@ func parsePTSOrDTS(i *astikit.BytesIterator) (cr *ClockReference, err error) { func parseESCR(i *astikit.BytesIterator) (cr *ClockReference, err error) { var bs []byte if bs, err = i.NextBytes(6); err != nil { - err = errors.Wrap(err, "astits: fetching next bytes failed") + err = fmt.Errorf("astits: fetching next bytes failed: %w", err) return } escr := uint64(bs[0])>>3&0x7<<39 | uint64(bs[0])&0x3<<37 | uint64(bs[1])<<29 | uint64(bs[2])>>3<<24 | uint64(bs[2])&0x3<<22 | uint64(bs[3])<<14 | uint64(bs[4])>>3<<9 | uint64(bs[4])&0x3<<7 | uint64(bs[5])>>1 diff --git a/data_pmt.go b/data_pmt.go index 6f45e86..d36a129 100644 --- a/data_pmt.go +++ b/data_pmt.go @@ -1,8 +1,9 @@ package astits import ( + "fmt" + "github.com/asticode/go-astikit" - "github.com/pkg/errors" ) // Stream types @@ -37,7 +38,7 @@ func parsePMTSection(i *astikit.BytesIterator, offsetSectionsEnd int, tableIDExt // Get next bytes var bs []byte if bs, err = i.NextBytes(2); err != nil { - err = errors.Wrap(err, "astits: fetching next bytes failed") + err = fmt.Errorf("astits: fetching next bytes failed: %w", err) return } @@ -46,7 +47,7 @@ func parsePMTSection(i *astikit.BytesIterator, offsetSectionsEnd int, tableIDExt // Program descriptors if d.ProgramDescriptors, err = parseDescriptors(i); err != nil { - err = errors.Wrap(err, "astits: parsing descriptors failed") + err = fmt.Errorf("astits: parsing descriptors failed: %w", err) return } @@ -58,7 +59,7 @@ func parsePMTSection(i *astikit.BytesIterator, offsetSectionsEnd int, tableIDExt // Get next byte var b byte if b, err = i.NextByte(); err != nil { - err = errors.Wrap(err, "astits: fetching next byte failed") + err = fmt.Errorf("astits: fetching next byte failed: %w", err) return } @@ -67,7 +68,7 @@ func parsePMTSection(i *astikit.BytesIterator, offsetSectionsEnd int, tableIDExt // Get next bytes if bs, err = i.NextBytes(2); err != nil { - err = errors.Wrap(err, "astits: fetching next bytes failed") + err = fmt.Errorf("astits: fetching next bytes failed: %w", err) return } @@ -76,7 +77,7 @@ func parsePMTSection(i *astikit.BytesIterator, offsetSectionsEnd int, tableIDExt // Elementary descriptors if e.ElementaryStreamDescriptors, err = parseDescriptors(i); err != nil { - err = errors.Wrap(err, "astits: parsing descriptors failed") + err = fmt.Errorf("astits: parsing descriptors failed: %w", err) return } diff --git a/data_psi.go b/data_psi.go index 851a294..64a13b3 100644 --- a/data_psi.go +++ b/data_psi.go @@ -2,10 +2,9 @@ package astits import ( "fmt" + "log" "github.com/asticode/go-astikit" - "github.com/asticode/go-astilog" - "github.com/pkg/errors" ) // PSI table IDs @@ -82,7 +81,7 @@ func parsePSIData(i *astikit.BytesIterator) (d *PSIData, err error) { // Get next byte var b byte if b, err = i.NextByte(); err != nil { - err = errors.Wrap(err, "astits: fetching next byte failed") + err = fmt.Errorf("astits: fetching next byte failed: %w", err) return } @@ -97,7 +96,7 @@ func parsePSIData(i *astikit.BytesIterator) (d *PSIData, err error) { var stop bool for i.HasBytesLeft() && !stop { if s, stop, err = parsePSISection(i); err != nil { - err = errors.Wrap(err, "astits: parsing PSI table failed") + err = fmt.Errorf("astits: parsing PSI table failed: %w", err) return } d.Sections = append(d.Sections, s) @@ -113,7 +112,7 @@ func parsePSISection(i *astikit.BytesIterator) (s *PSISection, stop bool, err er // Parse header var offsetStart, offsetSectionsEnd, offsetEnd int if s.Header, offsetStart, _, offsetSectionsEnd, offsetEnd, err = parsePSISectionHeader(i); err != nil { - err = errors.Wrap(err, "astits: parsing PSI section header failed") + err = fmt.Errorf("astits: parsing PSI section header failed: %w", err) return } @@ -127,7 +126,7 @@ func parsePSISection(i *astikit.BytesIterator) (s *PSISection, stop bool, err er if s.Header.SectionLength > 0 { // Parse syntax if s.Syntax, err = parsePSISectionSyntax(i, s.Header, offsetSectionsEnd); err != nil { - err = errors.Wrap(err, "astits: parsing PSI section syntax failed") + err = fmt.Errorf("astits: parsing PSI section syntax failed: %w", err) return } @@ -138,7 +137,7 @@ func parsePSISection(i *astikit.BytesIterator) (s *PSISection, stop bool, err er // Parse CRC32 if s.CRC32, err = parseCRC32(i); err != nil { - err = errors.Wrap(err, "astits: parsing CRC32 failed") + err = fmt.Errorf("astits: parsing CRC32 failed: %w", err) return } @@ -146,14 +145,14 @@ func parsePSISection(i *astikit.BytesIterator) (s *PSISection, stop bool, err er i.Seek(offsetStart) var crc32Data []byte if crc32Data, err = i.NextBytes(offsetSectionsEnd - offsetStart); err != nil { - err = errors.Wrap(err, "astits: fetching next bytes failed") + err = fmt.Errorf("astits: fetching next bytes failed: %w", err) return } // Compute CRC32 var crc32 uint32 if crc32, err = computeCRC32(crc32Data); err != nil { - err = errors.Wrap(err, "astits: computing CRC32 failed") + err = fmt.Errorf("astits: computing CRC32 failed: %w", err) return } @@ -174,7 +173,7 @@ func parsePSISection(i *astikit.BytesIterator) (s *PSISection, stop bool, err er func parseCRC32(i *astikit.BytesIterator) (c uint32, err error) { var bs []byte if bs, err = i.NextBytes(4); err != nil { - err = errors.Wrap(err, "astits: fetching next bytes failed") + err = fmt.Errorf("astits: fetching next bytes failed: %w", err) return } c = uint32(bs[0])<<24 | uint32(bs[1])<<16 | uint32(bs[2])<<8 | uint32(bs[3]) @@ -212,7 +211,7 @@ func parsePSISectionHeader(i *astikit.BytesIterator) (h *PSISectionHeader, offse // Get next byte var b byte if b, err = i.NextByte(); err != nil { - err = errors.Wrap(err, "astits: fetching next byte failed") + err = fmt.Errorf("astits: fetching next byte failed: %w", err) return } @@ -230,7 +229,7 @@ func parsePSISectionHeader(i *astikit.BytesIterator) (h *PSISectionHeader, offse // Get next bytes var bs []byte if bs, err = i.NextBytes(2); err != nil { - err = errors.Wrap(err, "astits: fetching next bytes failed") + err = fmt.Errorf("astits: fetching next bytes failed: %w", err) return } @@ -293,9 +292,9 @@ func psiTableType(tableID int) string { return PSITableTypeTDT case tableID == 0x73: return PSITableTypeTOT + default: + log.Printf("astits: unlisted PSI table ID %d\n", tableID) } - // TODO Remove this log - astilog.Debugf("astits: unlisted PSI table ID %d", tableID) return PSITableTypeUnknown } @@ -307,14 +306,14 @@ func parsePSISectionSyntax(i *astikit.BytesIterator, h *PSISectionHeader, offset // Header if hasPSISyntaxHeader(h.TableType) { if s.Header, err = parsePSISectionSyntaxHeader(i); err != nil { - err = errors.Wrap(err, "astits: parsing PSI section syntax header failed") + err = fmt.Errorf("astits: parsing PSI section syntax header failed: %w", err) return } } // Parse data if s.Data, err = parsePSISectionSyntaxData(i, h, s.Header, offsetSectionsEnd); err != nil { - err = errors.Wrap(err, "astits: parsing PSI section syntax data failed") + err = fmt.Errorf("astits: parsing PSI section syntax data failed: %w", err) return } return @@ -337,7 +336,7 @@ func parsePSISectionSyntaxHeader(i *astikit.BytesIterator) (h *PSISectionSyntaxH // Get next 2 bytes var bs []byte if bs, err = i.NextBytes(2); err != nil { - err = errors.Wrap(err, "astits: fetching next bytes failed") + err = fmt.Errorf("astits: fetching next bytes failed: %w", err) return } @@ -347,7 +346,7 @@ func parsePSISectionSyntaxHeader(i *astikit.BytesIterator) (h *PSISectionSyntaxH // Get next byte var b byte if b, err = i.NextByte(); err != nil { - err = errors.Wrap(err, "astits: fetching next byte failed") + err = fmt.Errorf("astits: fetching next byte failed: %w", err) return } @@ -359,7 +358,7 @@ func parsePSISectionSyntaxHeader(i *astikit.BytesIterator) (h *PSISectionSyntaxH // Get next byte if b, err = i.NextByte(); err != nil { - err = errors.Wrap(err, "astits: fetching next byte failed") + err = fmt.Errorf("astits: fetching next byte failed: %w", err) return } @@ -368,7 +367,7 @@ func parsePSISectionSyntaxHeader(i *astikit.BytesIterator) (h *PSISectionSyntaxH // Get next byte if b, err = i.NextByte(); err != nil { - err = errors.Wrap(err, "astits: fetching next byte failed") + err = fmt.Errorf("astits: fetching next byte failed: %w", err) return } @@ -390,29 +389,29 @@ func parsePSISectionSyntaxData(i *astikit.BytesIterator, h *PSISectionHeader, sh // TODO Parse DIT case PSITableTypeEIT: if d.EIT, err = parseEITSection(i, offsetSectionsEnd, sh.TableIDExtension); err != nil { - err = errors.Wrap(err, "astits: parsing EIT section failed") + err = fmt.Errorf("astits: parsing EIT section failed: %w", err) return } case PSITableTypeNIT: if d.NIT, err = parseNITSection(i, sh.TableIDExtension); err != nil { - err = errors.Wrap(err, "astits: parsing NIT section failed") + err = fmt.Errorf("astits: parsing NIT section failed: %w", err) return } case PSITableTypePAT: if d.PAT, err = parsePATSection(i, offsetSectionsEnd, sh.TableIDExtension); err != nil { - err = errors.Wrap(err, "astits: parsing PAT section failed") + err = fmt.Errorf("astits: parsing PAT section failed: %w", err) return } case PSITableTypePMT: if d.PMT, err = parsePMTSection(i, offsetSectionsEnd, sh.TableIDExtension); err != nil { - err = errors.Wrap(err, "astits: parsing PMT section failed") + err = fmt.Errorf("astits: parsing PMT section failed: %w", err) return } case PSITableTypeRST: // TODO Parse RST case PSITableTypeSDT: if d.SDT, err = parseSDTSection(i, offsetSectionsEnd, sh.TableIDExtension); err != nil { - err = errors.Wrap(err, "astits: parsing PMT section failed") + err = fmt.Errorf("astits: parsing PMT section failed: %w", err) return } case PSITableTypeSIT: @@ -421,7 +420,7 @@ func parsePSISectionSyntaxData(i *astikit.BytesIterator, h *PSISectionHeader, sh // TODO Parse ST case PSITableTypeTOT: if d.TOT, err = parseTOTSection(i); err != nil { - err = errors.Wrap(err, "astits: parsing TOT section failed") + err = fmt.Errorf("astits: parsing TOT section failed: %w", err) return } case PSITableTypeTDT: diff --git a/data_sdt.go b/data_sdt.go index 58bebf8..ce48af1 100644 --- a/data_sdt.go +++ b/data_sdt.go @@ -1,8 +1,9 @@ package astits import ( + "fmt" + "github.com/asticode/go-astikit" - "github.com/pkg/errors" ) // Running statuses @@ -41,7 +42,7 @@ func parseSDTSection(i *astikit.BytesIterator, offsetSectionsEnd int, tableIDExt // Get next bytes var bs []byte if bs, err = i.NextBytes(2); err != nil { - err = errors.Wrap(err, "astits: fetching next bytes failed") + err = fmt.Errorf("astits: fetching next bytes failed: %w", err) return } @@ -58,7 +59,7 @@ func parseSDTSection(i *astikit.BytesIterator, offsetSectionsEnd int, tableIDExt // Get next bytes if bs, err = i.NextBytes(2); err != nil { - err = errors.Wrap(err, "astits: fetching next bytes failed") + err = fmt.Errorf("astits: fetching next bytes failed: %w", err) return } @@ -68,7 +69,7 @@ func parseSDTSection(i *astikit.BytesIterator, offsetSectionsEnd int, tableIDExt // Get next byte var b byte if b, err = i.NextByte(); err != nil { - err = errors.Wrap(err, "astits: fetching next byte failed") + err = fmt.Errorf("astits: fetching next byte failed: %w", err) return } @@ -80,7 +81,7 @@ func parseSDTSection(i *astikit.BytesIterator, offsetSectionsEnd int, tableIDExt // Get next byte if b, err = i.NextByte(); err != nil { - err = errors.Wrap(err, "astits: fetching next byte failed") + err = fmt.Errorf("astits: fetching next byte failed: %w", err) return } @@ -95,7 +96,7 @@ func parseSDTSection(i *astikit.BytesIterator, offsetSectionsEnd int, tableIDExt // Descriptors if s.Descriptors, err = parseDescriptors(i); err != nil { - err = errors.Wrap(err, "astits: parsing descriptors failed") + err = fmt.Errorf("astits: parsing descriptors failed: %w", err) return } diff --git a/data_tot.go b/data_tot.go index 69aeaac..4f569d2 100644 --- a/data_tot.go +++ b/data_tot.go @@ -1,10 +1,10 @@ package astits import ( + "fmt" "time" "github.com/asticode/go-astikit" - "github.com/pkg/errors" ) // TOTData represents a TOT data @@ -21,13 +21,13 @@ func parseTOTSection(i *astikit.BytesIterator) (d *TOTData, err error) { // UTC time if d.UTCTime, err = parseDVBTime(i); err != nil { - err = errors.Wrap(err, "astits: parsing DVB time failed") + err = fmt.Errorf("astits: parsing DVB time failed: %w", err) return } // Descriptors if d.Descriptors, err = parseDescriptors(i); err != nil { - err = errors.Wrap(err, "astits: parsing descriptors failed") + err = fmt.Errorf("astits: parsing descriptors failed: %w", err) return } return diff --git a/demuxer.go b/demuxer.go index c8bb453..4db168f 100644 --- a/demuxer.go +++ b/demuxer.go @@ -2,9 +2,9 @@ package astits import ( "context" + "errors" + "fmt" "io" - - "github.com/pkg/errors" ) // Sync byte @@ -78,7 +78,7 @@ func (dmx *Demuxer) NextPacket() (p *Packet, err error) { // Create packet buffer if not exists if dmx.packetBuffer == nil { if dmx.packetBuffer, err = newPacketBuffer(dmx.r, dmx.optPacketSize); err != nil { - err = errors.Wrap(err, "astits: creating packet buffer failed") + err = fmt.Errorf("astits: creating packet buffer failed: %w", err) return } } @@ -86,7 +86,7 @@ func (dmx *Demuxer) NextPacket() (p *Packet, err error) { // Fetch next packet from buffer if p, err = dmx.packetBuffer.next(); err != nil { if err != ErrNoMorePackets { - err = errors.Wrap(err, "astits: fetching next packet from buffer failed") + err = fmt.Errorf("astits: fetching next packet from buffer failed: %w", err) } return } @@ -131,7 +131,7 @@ func (dmx *Demuxer) NextData() (d *Data, err error) { } return } - err = errors.Wrap(err, "astits: fetching next packet failed") + err = fmt.Errorf("astits: fetching next packet failed: %w", err) return } @@ -142,7 +142,7 @@ func (dmx *Demuxer) NextData() (d *Data, err error) { // Parse data if ds, err = parseData(ps, dmx.optPacketsParser, dmx.programMap); err != nil { - err = errors.Wrap(err, "astits: building new data failed") + err = fmt.Errorf("astits: building new data failed: %w", err) return } @@ -181,7 +181,7 @@ func (dmx *Demuxer) Rewind() (n int64, err error) { dmx.packetBuffer = nil dmx.packetPool = newPacketPool() if n, err = rewind(dmx.r); err != nil { - err = errors.Wrap(err, "astits: rewinding reader failed") + err = fmt.Errorf("astits: rewinding reader failed: %w", err) return } return diff --git a/descriptor.go b/descriptor.go index 5cd939f..222bb39 100644 --- a/descriptor.go +++ b/descriptor.go @@ -1,11 +1,11 @@ package astits import ( + "fmt" + "log" "time" "github.com/asticode/go-astikit" - "github.com/asticode/go-astilog" - "github.com/pkg/errors" ) // Audio types @@ -136,7 +136,7 @@ func newDescriptorAC3(i *astikit.BytesIterator, offsetEnd int) (d *DescriptorAC3 // Get next byte var b byte if b, err = i.NextByte(); err != nil { - err = errors.Wrap(err, "astits: fetching next byte failed") + err = fmt.Errorf("astits: fetching next byte failed: %w", err) return } @@ -151,7 +151,7 @@ func newDescriptorAC3(i *astikit.BytesIterator, offsetEnd int) (d *DescriptorAC3 // Component type if d.HasComponentType { if b, err = i.NextByte(); err != nil { - err = errors.Wrap(err, "astits: fetching next byte failed") + err = fmt.Errorf("astits: fetching next byte failed: %w", err) return } d.ComponentType = uint8(b) @@ -160,7 +160,7 @@ func newDescriptorAC3(i *astikit.BytesIterator, offsetEnd int) (d *DescriptorAC3 // BSID if d.HasBSID { if b, err = i.NextByte(); err != nil { - err = errors.Wrap(err, "astits: fetching next byte failed") + err = fmt.Errorf("astits: fetching next byte failed: %w", err) return } d.BSID = uint8(b) @@ -169,7 +169,7 @@ func newDescriptorAC3(i *astikit.BytesIterator, offsetEnd int) (d *DescriptorAC3 // Main ID if d.HasMainID { if b, err = i.NextByte(); err != nil { - err = errors.Wrap(err, "astits: fetching next byte failed") + err = fmt.Errorf("astits: fetching next byte failed: %w", err) return } d.MainID = uint8(b) @@ -178,7 +178,7 @@ func newDescriptorAC3(i *astikit.BytesIterator, offsetEnd int) (d *DescriptorAC3 // ASVC if d.HasASVC { if b, err = i.NextByte(); err != nil { - err = errors.Wrap(err, "astits: fetching next byte failed") + err = fmt.Errorf("astits: fetching next byte failed: %w", err) return } d.ASVC = uint8(b) @@ -187,7 +187,7 @@ func newDescriptorAC3(i *astikit.BytesIterator, offsetEnd int) (d *DescriptorAC3 // Additional info if i.Offset() < offsetEnd { if d.AdditionalInfo, err = i.NextBytes(offsetEnd - i.Offset()); err != nil { - err = errors.Wrap(err, "astits: fetching next bytes failed") + err = fmt.Errorf("astits: fetching next bytes failed: %w", err) return } } @@ -214,7 +214,7 @@ func newDescriptorAVCVideo(i *astikit.BytesIterator) (d *DescriptorAVCVideo, err // Get next byte var b byte if b, err = i.NextByte(); err != nil { - err = errors.Wrap(err, "astits: fetching next byte failed") + err = fmt.Errorf("astits: fetching next byte failed: %w", err) return } @@ -223,7 +223,7 @@ func newDescriptorAVCVideo(i *astikit.BytesIterator) (d *DescriptorAVCVideo, err // Get next byte if b, err = i.NextByte(); err != nil { - err = errors.Wrap(err, "astits: fetching next byte failed") + err = fmt.Errorf("astits: fetching next byte failed: %w", err) return } @@ -235,7 +235,7 @@ func newDescriptorAVCVideo(i *astikit.BytesIterator) (d *DescriptorAVCVideo, err // Get next byte if b, err = i.NextByte(); err != nil { - err = errors.Wrap(err, "astits: fetching next byte failed") + err = fmt.Errorf("astits: fetching next byte failed: %w", err) return } @@ -244,7 +244,7 @@ func newDescriptorAVCVideo(i *astikit.BytesIterator) (d *DescriptorAVCVideo, err // Get next byte if b, err = i.NextByte(); err != nil { - err = errors.Wrap(err, "astits: fetching next byte failed") + err = fmt.Errorf("astits: fetching next byte failed: %w", err) return } @@ -274,7 +274,7 @@ func newDescriptorComponent(i *astikit.BytesIterator, offsetEnd int) (d *Descrip // Get next byte var b byte if b, err = i.NextByte(); err != nil { - err = errors.Wrap(err, "astits: fetching next byte failed") + err = fmt.Errorf("astits: fetching next byte failed: %w", err) return } @@ -286,7 +286,7 @@ func newDescriptorComponent(i *astikit.BytesIterator, offsetEnd int) (d *Descrip // Get next byte if b, err = i.NextByte(); err != nil { - err = errors.Wrap(err, "astits: fetching next byte failed") + err = fmt.Errorf("astits: fetching next byte failed: %w", err) return } @@ -295,7 +295,7 @@ func newDescriptorComponent(i *astikit.BytesIterator, offsetEnd int) (d *Descrip // Get next byte if b, err = i.NextByte(); err != nil { - err = errors.Wrap(err, "astits: fetching next byte failed") + err = fmt.Errorf("astits: fetching next byte failed: %w", err) return } @@ -304,14 +304,14 @@ func newDescriptorComponent(i *astikit.BytesIterator, offsetEnd int) (d *Descrip // ISO639 language code if d.ISO639LanguageCode, err = i.NextBytes(3); err != nil { - err = errors.Wrap(err, "astits: fetching next bytes failed") + err = fmt.Errorf("astits: fetching next bytes failed: %w", err) return } // Text if i.Offset() < offsetEnd { if d.Text, err = i.NextBytes(offsetEnd - i.Offset()); err != nil { - err = errors.Wrap(err, "astits: fetching next bytes failed") + err = fmt.Errorf("astits: fetching next bytes failed: %w", err) return } } @@ -341,7 +341,7 @@ func newDescriptorContent(i *astikit.BytesIterator, offsetEnd int) (d *Descripto // Get next bytes var bs []byte if bs, err = i.NextBytes(2); err != nil { - err = errors.Wrap(err, "astits: fetching next bytes failed") + err = fmt.Errorf("astits: fetching next bytes failed: %w", err) return } @@ -363,7 +363,7 @@ type DescriptorDataStreamAlignment struct { func newDescriptorDataStreamAlignment(i *astikit.BytesIterator) (d *DescriptorDataStreamAlignment, err error) { var b byte if b, err = i.NextByte(); err != nil { - err = errors.Wrap(err, "astits: fetching next byte failed") + err = fmt.Errorf("astits: fetching next byte failed: %w", err) return } d = &DescriptorDataStreamAlignment{Type: uint8(b)} @@ -395,7 +395,7 @@ func newDescriptorEnhancedAC3(i *astikit.BytesIterator, offsetEnd int) (d *Descr // Get next byte var b byte if b, err = i.NextByte(); err != nil { - err = errors.Wrap(err, "astits: fetching next byte failed") + err = fmt.Errorf("astits: fetching next byte failed: %w", err) return } @@ -415,7 +415,7 @@ func newDescriptorEnhancedAC3(i *astikit.BytesIterator, offsetEnd int) (d *Descr if d.HasComponentType { // Get next byte if b, err = i.NextByte(); err != nil { - err = errors.Wrap(err, "astits: fetching next byte failed") + err = fmt.Errorf("astits: fetching next byte failed: %w", err) return } d.ComponentType = uint8(b) @@ -425,7 +425,7 @@ func newDescriptorEnhancedAC3(i *astikit.BytesIterator, offsetEnd int) (d *Descr if d.HasBSID { // Get next byte if b, err = i.NextByte(); err != nil { - err = errors.Wrap(err, "astits: fetching next byte failed") + err = fmt.Errorf("astits: fetching next byte failed: %w", err) return } d.BSID = uint8(b) @@ -435,7 +435,7 @@ func newDescriptorEnhancedAC3(i *astikit.BytesIterator, offsetEnd int) (d *Descr if d.HasMainID { // Get next byte if b, err = i.NextByte(); err != nil { - err = errors.Wrap(err, "astits: fetching next byte failed") + err = fmt.Errorf("astits: fetching next byte failed: %w", err) return } d.MainID = uint8(b) @@ -445,7 +445,7 @@ func newDescriptorEnhancedAC3(i *astikit.BytesIterator, offsetEnd int) (d *Descr if d.HasASVC { // Get next byte if b, err = i.NextByte(); err != nil { - err = errors.Wrap(err, "astits: fetching next byte failed") + err = fmt.Errorf("astits: fetching next byte failed: %w", err) return } d.ASVC = uint8(b) @@ -455,7 +455,7 @@ func newDescriptorEnhancedAC3(i *astikit.BytesIterator, offsetEnd int) (d *Descr if d.HasSubStream1 { // Get next byte if b, err = i.NextByte(); err != nil { - err = errors.Wrap(err, "astits: fetching next byte failed") + err = fmt.Errorf("astits: fetching next byte failed: %w", err) return } d.SubStream1 = uint8(b) @@ -465,7 +465,7 @@ func newDescriptorEnhancedAC3(i *astikit.BytesIterator, offsetEnd int) (d *Descr if d.HasSubStream2 { // Get next byte if b, err = i.NextByte(); err != nil { - err = errors.Wrap(err, "astits: fetching next byte failed") + err = fmt.Errorf("astits: fetching next byte failed: %w", err) return } d.SubStream2 = uint8(b) @@ -475,7 +475,7 @@ func newDescriptorEnhancedAC3(i *astikit.BytesIterator, offsetEnd int) (d *Descr if d.HasSubStream3 { // Get next byte if b, err = i.NextByte(); err != nil { - err = errors.Wrap(err, "astits: fetching next byte failed") + err = fmt.Errorf("astits: fetching next byte failed: %w", err) return } d.SubStream3 = uint8(b) @@ -484,7 +484,7 @@ func newDescriptorEnhancedAC3(i *astikit.BytesIterator, offsetEnd int) (d *Descr // Additional info if i.Offset() < offsetEnd { if d.AdditionalInfo, err = i.NextBytes(offsetEnd - i.Offset()); err != nil { - err = errors.Wrap(err, "astits: fetching next bytes failed") + err = fmt.Errorf("astits: fetching next bytes failed: %w", err) return } } @@ -515,7 +515,7 @@ func newDescriptorExtendedEvent(i *astikit.BytesIterator) (d *DescriptorExtended // Get next byte var b byte if b, err = i.NextByte(); err != nil { - err = errors.Wrap(err, "astits: fetching next byte failed") + err = fmt.Errorf("astits: fetching next byte failed: %w", err) return } @@ -527,13 +527,13 @@ func newDescriptorExtendedEvent(i *astikit.BytesIterator) (d *DescriptorExtended // ISO639 language code if d.ISO639LanguageCode, err = i.NextBytes(3); err != nil { - err = errors.Wrap(err, "astits: fetching next bytes failed") + err = fmt.Errorf("astits: fetching next bytes failed: %w", err) return } // Get next byte if b, err = i.NextByte(); err != nil { - err = errors.Wrap(err, "astits: fetching next byte failed") + err = fmt.Errorf("astits: fetching next byte failed: %w", err) return } @@ -546,7 +546,7 @@ func newDescriptorExtendedEvent(i *astikit.BytesIterator) (d *DescriptorExtended // Create item var item *DescriptorExtendedEventItem if item, err = newDescriptorExtendedEventItem(i); err != nil { - err = errors.Wrap(err, "astits: creating extended event item failed") + err = fmt.Errorf("astits: creating extended event item failed: %w", err) return } @@ -556,7 +556,7 @@ func newDescriptorExtendedEvent(i *astikit.BytesIterator) (d *DescriptorExtended // Get next byte if b, err = i.NextByte(); err != nil { - err = errors.Wrap(err, "astits: fetching next byte failed") + err = fmt.Errorf("astits: fetching next byte failed: %w", err) return } @@ -565,7 +565,7 @@ func newDescriptorExtendedEvent(i *astikit.BytesIterator) (d *DescriptorExtended // Text if d.Text, err = i.NextBytes(textLength); err != nil { - err = errors.Wrap(err, "astits: fetching next bytes failed") + err = fmt.Errorf("astits: fetching next bytes failed: %w", err) return } return @@ -578,7 +578,7 @@ func newDescriptorExtendedEventItem(i *astikit.BytesIterator) (d *DescriptorExte // Get next byte var b byte if b, err = i.NextByte(); err != nil { - err = errors.Wrap(err, "astits: fetching next byte failed") + err = fmt.Errorf("astits: fetching next byte failed: %w", err) return } @@ -587,13 +587,13 @@ func newDescriptorExtendedEventItem(i *astikit.BytesIterator) (d *DescriptorExte // Description if d.Description, err = i.NextBytes(descriptionLength); err != nil { - err = errors.Wrap(err, "astits: fetching next bytes failed") + err = fmt.Errorf("astits: fetching next bytes failed: %w", err) return } // Get next byte if b, err = i.NextByte(); err != nil { - err = errors.Wrap(err, "astits: fetching next byte failed") + err = fmt.Errorf("astits: fetching next byte failed: %w", err) return } @@ -602,7 +602,7 @@ func newDescriptorExtendedEventItem(i *astikit.BytesIterator) (d *DescriptorExte // Content if d.Content, err = i.NextBytes(contentLength); err != nil { - err = errors.Wrap(err, "astits: fetching next bytes failed") + err = fmt.Errorf("astits: fetching next bytes failed: %w", err) return } return @@ -619,7 +619,7 @@ func newDescriptorExtension(i *astikit.BytesIterator, offsetEnd int) (d *Descrip // Get next byte var b byte if b, err = i.NextByte(); err != nil { - err = errors.Wrap(err, "astits: fetching next byte failed") + err = fmt.Errorf("astits: fetching next byte failed: %w", err) return } @@ -630,12 +630,11 @@ func newDescriptorExtension(i *astikit.BytesIterator, offsetEnd int) (d *Descrip switch d.Tag { case DescriptorTagExtensionSupplementaryAudio: if d.SupplementaryAudio, err = newDescriptorExtensionSupplementaryAudio(i, offsetEnd); err != nil { - err = errors.Wrap(err, "astits: parsing extension supplementary audio descriptor failed") + err = fmt.Errorf("astits: parsing extension supplementary audio descriptor failed: %w", err) return } default: - // TODO Remove this log - astilog.Debugf("astits: unlisted extension tag 0x%x", d.Tag) + log.Printf("astits: unlisted extension tag 0x%x\n", d.Tag) } return } @@ -654,7 +653,7 @@ func newDescriptorExtensionSupplementaryAudio(i *astikit.BytesIterator, offsetEn // Get next byte var b byte if b, err = i.NextByte(); err != nil { - err = errors.Wrap(err, "astits: fetching next byte failed") + err = fmt.Errorf("astits: fetching next byte failed: %w", err) return } @@ -668,7 +667,7 @@ func newDescriptorExtensionSupplementaryAudio(i *astikit.BytesIterator, offsetEn // Language code if d.HasLanguageCode { if d.LanguageCode, err = i.NextBytes(3); err != nil { - err = errors.Wrap(err, "astits: fetching next bytes failed") + err = fmt.Errorf("astits: fetching next bytes failed: %w", err) return } } @@ -676,7 +675,7 @@ func newDescriptorExtensionSupplementaryAudio(i *astikit.BytesIterator, offsetEn // Private data if i.Offset() < offsetEnd { if d.PrivateData, err = i.NextBytes(offsetEnd - i.Offset()); err != nil { - err = errors.Wrap(err, "astits: fetching next bytes failed") + err = fmt.Errorf("astits: fetching next bytes failed: %w", err) return } } @@ -695,7 +694,7 @@ func newDescriptorISO639LanguageAndAudioType(i *astikit.BytesIterator, offsetEnd // Get next bytes var bs []byte if bs, err = i.NextBytes(offsetEnd - i.Offset()); err != nil { - err = errors.Wrap(err, "astits: fetching next bytes failed") + err = fmt.Errorf("astits: fetching next bytes failed: %w", err) return } @@ -735,14 +734,14 @@ func newDescriptorLocalTimeOffset(i *astikit.BytesIterator, offsetEnd int) (d *D // Country code if itm.CountryCode, err = i.NextBytes(3); err != nil { - err = errors.Wrap(err, "astits: fetching next bytes failed") + err = fmt.Errorf("astits: fetching next bytes failed: %w", err) return } // Get next byte var b byte if b, err = i.NextByte(); err != nil { - err = errors.Wrap(err, "astits: fetching next byte failed") + err = fmt.Errorf("astits: fetching next byte failed: %w", err) return } @@ -754,19 +753,19 @@ func newDescriptorLocalTimeOffset(i *astikit.BytesIterator, offsetEnd int) (d *D // Local time offset if itm.LocalTimeOffset, err = parseDVBDurationMinutes(i); err != nil { - err = errors.Wrap(err, "astits: parsing DVB durationminutes failed") + err = fmt.Errorf("astits: parsing DVB durationminutes failed: %w", err) return } // Time of change if itm.TimeOfChange, err = parseDVBTime(i); err != nil { - err = errors.Wrap(err, "astits: parsing DVB time failed") + err = fmt.Errorf("astits: parsing DVB time failed: %w", err) return } // Next time offset if itm.NextTimeOffset, err = parseDVBDurationMinutes(i); err != nil { - err = errors.Wrap(err, "astits: parsing DVB duration minutes failed") + err = fmt.Errorf("astits: parsing DVB duration minutes failed: %w", err) return } @@ -785,7 +784,7 @@ func newDescriptorMaximumBitrate(i *astikit.BytesIterator) (d *DescriptorMaximum // Get next bytes var bs []byte if bs, err = i.NextBytes(3); err != nil { - err = errors.Wrap(err, "astits: fetching next bytes failed") + err = fmt.Errorf("astits: fetching next bytes failed: %w", err) return } @@ -806,7 +805,7 @@ func newDescriptorNetworkName(i *astikit.BytesIterator, offsetEnd int) (d *Descr // Name if d.Name, err = i.NextBytes(offsetEnd - i.Offset()); err != nil { - err = errors.Wrap(err, "astits: fetching next bytes failed") + err = fmt.Errorf("astits: fetching next bytes failed: %w", err) return } return @@ -843,7 +842,7 @@ func newDescriptorParentalRating(i *astikit.BytesIterator, offsetEnd int) (d *De // Get next bytes var bs []byte if bs, err = i.NextBytes(4); err != nil { - err = errors.Wrap(err, "astits: fetching next bytes failed") + err = fmt.Errorf("astits: fetching next bytes failed: %w", err) return } @@ -865,7 +864,7 @@ func newDescriptorPrivateDataIndicator(i *astikit.BytesIterator) (d *DescriptorP // Get next bytes var bs []byte if bs, err = i.NextBytes(4); err != nil { - err = errors.Wrap(err, "astits: fetching next bytes failed") + err = fmt.Errorf("astits: fetching next bytes failed: %w", err) return } @@ -883,7 +882,7 @@ func newDescriptorPrivateDataSpecifier(i *astikit.BytesIterator) (d *DescriptorP // Get next bytes var bs []byte if bs, err = i.NextBytes(4); err != nil { - err = errors.Wrap(err, "astits: fetching next bytes failed") + err = fmt.Errorf("astits: fetching next bytes failed: %w", err) return } @@ -903,7 +902,7 @@ func newDescriptorRegistration(i *astikit.BytesIterator, offsetEnd int) (d *Desc // Get next bytes var bs []byte if bs, err = i.NextBytes(4); err != nil { - err = errors.Wrap(err, "astits: fetching next bytes failed") + err = fmt.Errorf("astits: fetching next bytes failed: %w", err) return } @@ -913,7 +912,7 @@ func newDescriptorRegistration(i *astikit.BytesIterator, offsetEnd int) (d *Desc // Additional identification info if i.Offset() < offsetEnd { if d.AdditionalIdentificationInfo, err = i.NextBytes(offsetEnd - i.Offset()); err != nil { - err = errors.Wrap(err, "astits: fetching next bytes failed") + err = fmt.Errorf("astits: fetching next bytes failed: %w", err) return } } @@ -932,7 +931,7 @@ func newDescriptorService(i *astikit.BytesIterator) (d *DescriptorService, err e // Get next byte var b byte if b, err = i.NextByte(); err != nil { - err = errors.Wrap(err, "astits: fetching next byte failed") + err = fmt.Errorf("astits: fetching next byte failed: %w", err) return } @@ -941,7 +940,7 @@ func newDescriptorService(i *astikit.BytesIterator) (d *DescriptorService, err e // Get next byte if b, err = i.NextByte(); err != nil { - err = errors.Wrap(err, "astits: fetching next byte failed") + err = fmt.Errorf("astits: fetching next byte failed: %w", err) return } @@ -950,13 +949,13 @@ func newDescriptorService(i *astikit.BytesIterator) (d *DescriptorService, err e // Provider if d.Provider, err = i.NextBytes(providerLength); err != nil { - err = errors.Wrap(err, "astits: fetching next bytes failed") + err = fmt.Errorf("astits: fetching next bytes failed: %w", err) return } // Get next byte if b, err = i.NextByte(); err != nil { - err = errors.Wrap(err, "astits: fetching next byte failed") + err = fmt.Errorf("astits: fetching next byte failed: %w", err) return } @@ -965,7 +964,7 @@ func newDescriptorService(i *astikit.BytesIterator) (d *DescriptorService, err e // Name if d.Name, err = i.NextBytes(nameLength); err != nil { - err = errors.Wrap(err, "astits: fetching next bytes failed") + err = fmt.Errorf("astits: fetching next bytes failed: %w", err) return } return @@ -985,14 +984,14 @@ func newDescriptorShortEvent(i *astikit.BytesIterator) (d *DescriptorShortEvent, // Language if d.Language, err = i.NextBytes(3); err != nil { - err = errors.Wrap(err, "astits: fetching next bytes failed") + err = fmt.Errorf("astits: fetching next bytes failed: %w", err) return } // Get next byte var b byte if b, err = i.NextByte(); err != nil { - err = errors.Wrap(err, "astits: fetching next byte failed") + err = fmt.Errorf("astits: fetching next byte failed: %w", err) return } @@ -1001,13 +1000,13 @@ func newDescriptorShortEvent(i *astikit.BytesIterator) (d *DescriptorShortEvent, // Event name if d.EventName, err = i.NextBytes(eventLength); err != nil { - err = errors.Wrap(err, "astits: fetching next bytes failed") + err = fmt.Errorf("astits: fetching next bytes failed: %w", err) return } // Get next byte if b, err = i.NextByte(); err != nil { - err = errors.Wrap(err, "astits: fetching next byte failed") + err = fmt.Errorf("astits: fetching next byte failed: %w", err) return } @@ -1016,7 +1015,7 @@ func newDescriptorShortEvent(i *astikit.BytesIterator) (d *DescriptorShortEvent, // Text if d.Text, err = i.NextBytes(textLength); err != nil { - err = errors.Wrap(err, "astits: fetching next bytes failed") + err = fmt.Errorf("astits: fetching next bytes failed: %w", err) return } return @@ -1029,7 +1028,7 @@ type DescriptorStreamIdentifier struct{ ComponentTag uint8 } func newDescriptorStreamIdentifier(i *astikit.BytesIterator) (d *DescriptorStreamIdentifier, err error) { var b byte if b, err = i.NextByte(); err != nil { - err = errors.Wrap(err, "astits: fetching next byte failed") + err = fmt.Errorf("astits: fetching next byte failed: %w", err) return } d = &DescriptorStreamIdentifier{ComponentTag: uint8(b)} @@ -1062,14 +1061,14 @@ func newDescriptorSubtitling(i *astikit.BytesIterator, offsetEnd int) (d *Descri // Language if itm.Language, err = i.NextBytes(3); err != nil { - err = errors.Wrap(err, "astits: fetching next bytes failed") + err = fmt.Errorf("astits: fetching next bytes failed: %w", err) return } // Get next byte var b byte if b, err = i.NextByte(); err != nil { - err = errors.Wrap(err, "astits: fetching next byte failed") + err = fmt.Errorf("astits: fetching next byte failed: %w", err) return } @@ -1079,7 +1078,7 @@ func newDescriptorSubtitling(i *astikit.BytesIterator, offsetEnd int) (d *Descri // Get next bytes var bs []byte if bs, err = i.NextBytes(2); err != nil { - err = errors.Wrap(err, "astits: fetching next bytes failed") + err = fmt.Errorf("astits: fetching next bytes failed: %w", err) return } @@ -1088,7 +1087,7 @@ func newDescriptorSubtitling(i *astikit.BytesIterator, offsetEnd int) (d *Descri // Get next bytes if bs, err = i.NextBytes(2); err != nil { - err = errors.Wrap(err, "astits: fetching next bytes failed") + err = fmt.Errorf("astits: fetching next bytes failed: %w", err) return } @@ -1127,14 +1126,14 @@ func newDescriptorTeletext(i *astikit.BytesIterator, offsetEnd int) (d *Descript // Language if itm.Language, err = i.NextBytes(3); err != nil { - err = errors.Wrap(err, "astits: fetching next bytes failed") + err = fmt.Errorf("astits: fetching next bytes failed: %w", err) return } // Get next byte var b byte if b, err = i.NextByte(); err != nil { - err = errors.Wrap(err, "astits: fetching next byte failed") + err = fmt.Errorf("astits: fetching next byte failed: %w", err) return } @@ -1146,7 +1145,7 @@ func newDescriptorTeletext(i *astikit.BytesIterator, offsetEnd int) (d *Descript // Get next byte if b, err = i.NextByte(); err != nil { - err = errors.Wrap(err, "astits: fetching next byte failed") + err = fmt.Errorf("astits: fetching next byte failed: %w", err) return } @@ -1191,7 +1190,7 @@ func newDescriptorVBIData(i *astikit.BytesIterator, offsetEnd int) (d *Descripto // Get next byte var b byte if b, err = i.NextByte(); err != nil { - err = errors.Wrap(err, "astits: fetching next byte failed") + err = fmt.Errorf("astits: fetching next byte failed: %w", err) return } @@ -1200,7 +1199,7 @@ func newDescriptorVBIData(i *astikit.BytesIterator, offsetEnd int) (d *Descripto // Get next byte if b, err = i.NextByte(); err != nil { - err = errors.Wrap(err, "astits: fetching next byte failed") + err = fmt.Errorf("astits: fetching next byte failed: %w", err) return } @@ -1218,7 +1217,7 @@ func newDescriptorVBIData(i *astikit.BytesIterator, offsetEnd int) (d *Descripto srv.DataServiceID == VBIDataServiceIDWSS { // Get next byte if b, err = i.NextByte(); err != nil { - err = errors.Wrap(err, "astits: fetching next byte failed") + err = fmt.Errorf("astits: fetching next byte failed: %w", err) return } @@ -1241,7 +1240,7 @@ func parseDescriptors(i *astikit.BytesIterator) (o []*Descriptor, err error) { // Get next 2 bytes var bs []byte if bs, err = i.NextBytes(2); err != nil { - err = errors.Wrap(err, "astits: fetching next bytes failed") + err = fmt.Errorf("astits: fetching next bytes failed: %w", err) return } @@ -1254,7 +1253,7 @@ func parseDescriptors(i *astikit.BytesIterator) (o []*Descriptor, err error) { for i.Offset() < offsetEnd { // Get next 2 bytes if bs, err = i.NextBytes(2); err != nil { - err = errors.Wrap(err, "astits: fetching next bytes failed") + err = fmt.Errorf("astits: fetching next bytes failed: %w", err) return } @@ -1274,7 +1273,7 @@ func parseDescriptors(i *astikit.BytesIterator) (o []*Descriptor, err error) { if d.Tag >= 0x80 && d.Tag <= 0xfe { // Get next bytes if d.UserDefined, err = i.NextBytes(int(d.Length)); err != nil { - err = errors.Wrap(err, "astits: fetching next bytes failed") + err = fmt.Errorf("astits: fetching next bytes failed: %w", err) return } } else { @@ -1282,122 +1281,121 @@ func parseDescriptors(i *astikit.BytesIterator) (o []*Descriptor, err error) { switch d.Tag { case DescriptorTagAC3: if d.AC3, err = newDescriptorAC3(i, offsetDescriptorEnd); err != nil { - err = errors.Wrap(err, "astits: parsing AC3 descriptor failed") + err = fmt.Errorf("astits: parsing AC3 descriptor failed: %w", err) return } case DescriptorTagAVCVideo: if d.AVCVideo, err = newDescriptorAVCVideo(i); err != nil { - err = errors.Wrap(err, "astits: parsing AVC Video descriptor failed") + err = fmt.Errorf("astits: parsing AVC Video descriptor failed: %w", err) return } case DescriptorTagComponent: if d.Component, err = newDescriptorComponent(i, offsetDescriptorEnd); err != nil { - err = errors.Wrap(err, "astits: parsing Component descriptor failed") + err = fmt.Errorf("astits: parsing Component descriptor failed: %w", err) return } case DescriptorTagContent: if d.Content, err = newDescriptorContent(i, offsetDescriptorEnd); err != nil { - err = errors.Wrap(err, "astits: parsing Content descriptor failed") + err = fmt.Errorf("astits: parsing Content descriptor failed: %w", err) return } case DescriptorTagDataStreamAlignment: if d.DataStreamAlignment, err = newDescriptorDataStreamAlignment(i); err != nil { - err = errors.Wrap(err, "astits: parsing Data Stream Alignment descriptor failed") + err = fmt.Errorf("astits: parsing Data Stream Alignment descriptor failed: %w", err) return } case DescriptorTagEnhancedAC3: if d.EnhancedAC3, err = newDescriptorEnhancedAC3(i, offsetDescriptorEnd); err != nil { - err = errors.Wrap(err, "astits: parsing Enhanced AC3 descriptor failed") + err = fmt.Errorf("astits: parsing Enhanced AC3 descriptor failed: %w", err) return } case DescriptorTagExtendedEvent: if d.ExtendedEvent, err = newDescriptorExtendedEvent(i); err != nil { - err = errors.Wrap(err, "astits: parsing Extended event descriptor failed") + err = fmt.Errorf("astits: parsing Extended event descriptor failed: %w", err) return } case DescriptorTagExtension: if d.Extension, err = newDescriptorExtension(i, offsetDescriptorEnd); err != nil { - err = errors.Wrap(err, "astits: parsing Extension descriptor failed") + err = fmt.Errorf("astits: parsing Extension descriptor failed: %w", err) return } case DescriptorTagISO639LanguageAndAudioType: if d.ISO639LanguageAndAudioType, err = newDescriptorISO639LanguageAndAudioType(i, offsetDescriptorEnd); err != nil { - err = errors.Wrap(err, "astits: parsing ISO639 Language and Audio Type descriptor failed") + err = fmt.Errorf("astits: parsing ISO639 Language and Audio Type descriptor failed: %w", err) return } case DescriptorTagLocalTimeOffset: if d.LocalTimeOffset, err = newDescriptorLocalTimeOffset(i, offsetDescriptorEnd); err != nil { - err = errors.Wrap(err, "astits: parsing Local Time Offset descriptor failed") + err = fmt.Errorf("astits: parsing Local Time Offset descriptor failed: %w", err) return } case DescriptorTagMaximumBitrate: if d.MaximumBitrate, err = newDescriptorMaximumBitrate(i); err != nil { - err = errors.Wrap(err, "astits: parsing Maximum Bitrate descriptor failed") + err = fmt.Errorf("astits: parsing Maximum Bitrate descriptor failed: %w", err) return } case DescriptorTagNetworkName: if d.NetworkName, err = newDescriptorNetworkName(i, offsetDescriptorEnd); err != nil { - err = errors.Wrap(err, "astits: parsing Network Name descriptor failed") + err = fmt.Errorf("astits: parsing Network Name descriptor failed: %w", err) return } case DescriptorTagParentalRating: if d.ParentalRating, err = newDescriptorParentalRating(i, offsetDescriptorEnd); err != nil { - err = errors.Wrap(err, "astits: parsing Parental Rating descriptor failed") + err = fmt.Errorf("astits: parsing Parental Rating descriptor failed: %w", err) return } case DescriptorTagPrivateDataIndicator: if d.PrivateDataIndicator, err = newDescriptorPrivateDataIndicator(i); err != nil { - err = errors.Wrap(err, "astits: parsing Private Data Indicator descriptor failed") + err = fmt.Errorf("astits: parsing Private Data Indicator descriptor failed: %w", err) return } case DescriptorTagPrivateDataSpecifier: if d.PrivateDataSpecifier, err = newDescriptorPrivateDataSpecifier(i); err != nil { - err = errors.Wrap(err, "astits: parsing Private Data Specifier descriptor failed") + err = fmt.Errorf("astits: parsing Private Data Specifier descriptor failed: %w", err) return } case DescriptorTagRegistration: if d.Registration, err = newDescriptorRegistration(i, offsetDescriptorEnd); err != nil { - err = errors.Wrap(err, "astits: parsing Registration descriptor failed") + err = fmt.Errorf("astits: parsing Registration descriptor failed: %w", err) return } case DescriptorTagService: if d.Service, err = newDescriptorService(i); err != nil { - err = errors.Wrap(err, "astits: parsing Service descriptor failed") + err = fmt.Errorf("astits: parsing Service descriptor failed: %w", err) return } case DescriptorTagShortEvent: if d.ShortEvent, err = newDescriptorShortEvent(i); err != nil { - err = errors.Wrap(err, "astits: parsing Short Event descriptor failed") + err = fmt.Errorf("astits: parsing Short Event descriptor failed: %w", err) return } case DescriptorTagStreamIdentifier: if d.StreamIdentifier, err = newDescriptorStreamIdentifier(i); err != nil { - err = errors.Wrap(err, "astits: parsing Stream Identifier descriptor failed") + err = fmt.Errorf("astits: parsing Stream Identifier descriptor failed: %w", err) return } case DescriptorTagSubtitling: if d.Subtitling, err = newDescriptorSubtitling(i, offsetDescriptorEnd); err != nil { - err = errors.Wrap(err, "astits: parsing Subtitling descriptor failed") + err = fmt.Errorf("astits: parsing Subtitling descriptor failed: %w", err) return } case DescriptorTagTeletext: if d.Teletext, err = newDescriptorTeletext(i, offsetDescriptorEnd); err != nil { - err = errors.Wrap(err, "astits: parsing Teletext descriptor failed") + err = fmt.Errorf("astits: parsing Teletext descriptor failed: %w", err) return } case DescriptorTagVBIData: if d.VBIData, err = newDescriptorVBIData(i, offsetDescriptorEnd); err != nil { - err = errors.Wrap(err, "astits: parsing VBI Date descriptor failed") + err = fmt.Errorf("astits: parsing VBI Date descriptor failed: %w", err) return } case DescriptorTagVBITeletext: if d.VBITeletext, err = newDescriptorTeletext(i, offsetDescriptorEnd); err != nil { - err = errors.Wrap(err, "astits: parsing VBI Teletext descriptor failed") + err = fmt.Errorf("astits: parsing VBI Teletext descriptor failed: %w", err) return } default: - // TODO Remove this log - astilog.Debugf("astits: unlisted descriptor tag 0x%x", d.Tag) + log.Printf("astits: unlisted descriptor tag 0x%x\n", d.Tag) } } diff --git a/dvb.go b/dvb.go index c831c4e..ec8e9c9 100644 --- a/dvb.go +++ b/dvb.go @@ -5,7 +5,6 @@ import ( "time" "github.com/asticode/go-astikit" - "github.com/pkg/errors" ) // parseDVBTime parses a DVB time @@ -18,7 +17,7 @@ func parseDVBTime(i *astikit.BytesIterator) (t time.Time, err error) { // Get next 2 bytes var bs []byte if bs, err = i.NextBytes(2); err != nil { - err = errors.Wrap(err, "astits: fetching next bytes failed") + err = fmt.Errorf("astits: fetching next bytes failed: %w", err) return } @@ -38,7 +37,7 @@ func parseDVBTime(i *astikit.BytesIterator) (t time.Time, err error) { // Time var s time.Duration if s, err = parseDVBDurationSeconds(i); err != nil { - err = errors.Wrap(err, "astits: parsing DVB duration seconds failed") + err = fmt.Errorf("astits: parsing DVB duration seconds failed: %w", err) return } t = t.Add(s) @@ -50,7 +49,7 @@ func parseDVBTime(i *astikit.BytesIterator) (t time.Time, err error) { func parseDVBDurationMinutes(i *astikit.BytesIterator) (d time.Duration, err error) { var bs []byte if bs, err = i.NextBytes(2); err != nil { - err = errors.Wrap(err, "astits: fetching next bytes failed") + err = fmt.Errorf("astits: fetching next bytes failed: %w", err) return } d = parseDVBDurationByte(bs[0])*time.Hour + parseDVBDurationByte(bs[1])*time.Minute @@ -62,7 +61,7 @@ func parseDVBDurationMinutes(i *astikit.BytesIterator) (d time.Duration, err err func parseDVBDurationSeconds(i *astikit.BytesIterator) (d time.Duration, err error) { var bs []byte if bs, err = i.NextBytes(3); err != nil { - err = errors.Wrap(err, "astits: fetching next bytes failed") + err = fmt.Errorf("astits: fetching next bytes failed: %w", err) return } d = parseDVBDurationByte(bs[0])*time.Hour + parseDVBDurationByte(bs[1])*time.Minute + parseDVBDurationByte(bs[2])*time.Second diff --git a/go.mod b/go.mod index efe5293..0ba7d11 100644 --- a/go.mod +++ b/go.mod @@ -3,9 +3,7 @@ module github.com/asticode/go-astits go 1.13 require ( - github.com/asticode/go-astikit v0.0.11 - github.com/asticode/go-astilog v1.4.0 - github.com/pkg/errors v0.8.1 + github.com/asticode/go-astikit v0.2.0 github.com/pkg/profile v1.4.0 github.com/stretchr/testify v1.4.0 ) diff --git a/go.sum b/go.sum index 6503676..6e232b2 100644 --- a/go.sum +++ b/go.sum @@ -1,39 +1,14 @@ -github.com/asticode/go-astikit v0.0.11 h1:ehXPlkacoNJTxiEo5K/oIWYFiQC4GkDn9THWjfumkNc= -github.com/asticode/go-astikit v0.0.11/go.mod h1:h4ly7idim1tNhaVkdVBeXQZEE3L0xblP7fCWbgwipF0= -github.com/asticode/go-astilog v1.4.0 h1:81eNYAC04VPg1b9UXdQe3NCT1EPo9CtGa2UUDnQyvik= -github.com/asticode/go-astilog v1.4.0/go.mod h1:0sGDwdYLRSFVbbvrXLbJC9niyGWL5JGTCEQWFJKHZr0= +github.com/asticode/go-astikit v0.2.0 h1:QonRVJKQB2btMYZGW+YkibMDOXje2F49RLW4UCnyjns= +github.com/asticode/go-astikit v0.2.0/go.mod h1:h4ly7idim1tNhaVkdVBeXQZEE3L0xblP7fCWbgwipF0= +github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -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/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk= -github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= -github.com/mattn/go-colorable v0.1.4 h1:snbPLB8fVfU9iwbbo30TPtbLRzwWu6aJS6Xh4eaaviA= -github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= -github.com/mattn/go-isatty v0.0.8 h1:HLtExJ+uU2HOZ+wI0Tt5DtUDrx8yhUqDcp7fYERX4CE= -github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= -github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= -github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/profile v1.4.0 h1:uCmaf4vVbWAOZz36k1hrQD7ijGRzLwaME8Am/7a4jZI= github.com/pkg/profile v1.4.0/go.mod h1:NWz/XGvpEW1FyYQ7fCx4dqYBLlfTcE+A9FLAkNKqjFE= 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.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4= -github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= -golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20191202143827-86a70503ff7e h1:egKlR8l7Nu9vHGWbcUV8lqR4987UfUbBd7GbhqGzNYU= -golang.org/x/crypto v0.0.0-20191202143827-86a70503ff7e/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -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= -golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= diff --git a/packet.go b/packet.go index ab72008..1bc1402 100644 --- a/packet.go +++ b/packet.go @@ -1,8 +1,9 @@ package astits import ( + "fmt" + "github.com/asticode/go-astikit" - "github.com/pkg/errors" ) // Scrambling Controls @@ -70,7 +71,7 @@ func parsePacket(i *astikit.BytesIterator) (p *Packet, err error) { // Get next byte var b byte if b, err = i.NextByte(); err != nil { - err = errors.Wrap(err, "astits: getting next byte failed") + err = fmt.Errorf("astits: getting next byte failed: %w", err) return } @@ -89,14 +90,14 @@ func parsePacket(i *astikit.BytesIterator) (p *Packet, err error) { // Parse header if p.Header, err = parsePacketHeader(i); err != nil { - err = errors.Wrap(err, "astits: parsing packet header failed") + err = fmt.Errorf("astits: parsing packet header failed: %w", err) return } // Parse adaptation field if p.Header.HasAdaptationField { if p.AdaptationField, err = parsePacketAdaptationField(i); err != nil { - err = errors.Wrap(err, "astits: parsing packet adaptation field failed") + err = fmt.Errorf("astits: parsing packet adaptation field failed: %w", err) return } } @@ -123,7 +124,7 @@ func parsePacketHeader(i *astikit.BytesIterator) (h *PacketHeader, err error) { // Get next bytes var bs []byte if bs, err = i.NextBytes(3); err != nil { - err = errors.Wrap(err, "astits: fetching next bytes failed") + err = fmt.Errorf("astits: fetching next bytes failed: %w", err) return } @@ -149,7 +150,7 @@ func parsePacketAdaptationField(i *astikit.BytesIterator) (a *PacketAdaptationFi // Get next byte var b byte if b, err = i.NextByte(); err != nil { - err = errors.Wrap(err, "astits: fetching next byte failed") + err = fmt.Errorf("astits: fetching next byte failed: %w", err) return } @@ -160,7 +161,7 @@ func parsePacketAdaptationField(i *astikit.BytesIterator) (a *PacketAdaptationFi if a.Length > 0 { // Get next byte if b, err = i.NextByte(); err != nil { - err = errors.Wrap(err, "astits: fetching next byte failed") + err = fmt.Errorf("astits: fetching next byte failed: %w", err) return } @@ -177,7 +178,7 @@ func parsePacketAdaptationField(i *astikit.BytesIterator) (a *PacketAdaptationFi // PCR if a.HasPCR { if a.PCR, err = parsePCR(i); err != nil { - err = errors.Wrap(err, "astits: parsing PCR failed") + err = fmt.Errorf("astits: parsing PCR failed: %w", err) return } } @@ -185,7 +186,7 @@ func parsePacketAdaptationField(i *astikit.BytesIterator) (a *PacketAdaptationFi // OPCR if a.HasOPCR { if a.OPCR, err = parsePCR(i); err != nil { - err = errors.Wrap(err, "astits: parsing PCR failed") + err = fmt.Errorf("astits: parsing PCR failed: %w", err) return } } @@ -193,7 +194,7 @@ func parsePacketAdaptationField(i *astikit.BytesIterator) (a *PacketAdaptationFi // Splicing countdown if a.HasSplicingCountdown { if b, err = i.NextByte(); err != nil { - err = errors.Wrap(err, "astits: fetching next byte failed") + err = fmt.Errorf("astits: fetching next byte failed: %w", err) return } a.SpliceCountdown = int(b) @@ -203,7 +204,7 @@ func parsePacketAdaptationField(i *astikit.BytesIterator) (a *PacketAdaptationFi if a.HasTransportPrivateData { // Length if b, err = i.NextByte(); err != nil { - err = errors.Wrap(err, "astits: fetching next byte failed") + err = fmt.Errorf("astits: fetching next byte failed: %w", err) return } a.TransportPrivateDataLength = int(b) @@ -211,7 +212,7 @@ func parsePacketAdaptationField(i *astikit.BytesIterator) (a *PacketAdaptationFi // Data if a.TransportPrivateDataLength > 0 { if a.TransportPrivateData, err = i.NextBytes(a.TransportPrivateDataLength); err != nil { - err = errors.Wrap(err, "astits: fetching next bytes failed") + err = fmt.Errorf("astits: fetching next bytes failed: %w", err) return } } @@ -224,7 +225,7 @@ func parsePacketAdaptationField(i *astikit.BytesIterator) (a *PacketAdaptationFi // Get next byte if b, err = i.NextByte(); err != nil { - err = errors.Wrap(err, "astits: fetching next byte failed") + err = fmt.Errorf("astits: fetching next byte failed: %w", err) return } @@ -233,7 +234,7 @@ func parsePacketAdaptationField(i *astikit.BytesIterator) (a *PacketAdaptationFi if a.AdaptationExtensionField.Length > 0 { // Get next byte if b, err = i.NextByte(); err != nil { - err = errors.Wrap(err, "astits: fetching next byte failed") + err = fmt.Errorf("astits: fetching next byte failed: %w", err) return } @@ -246,7 +247,7 @@ func parsePacketAdaptationField(i *astikit.BytesIterator) (a *PacketAdaptationFi if a.AdaptationExtensionField.HasLegalTimeWindow { var bs []byte if bs, err = i.NextBytes(2); err != nil { - err = errors.Wrap(err, "astits: fetching next bytes failed") + err = fmt.Errorf("astits: fetching next bytes failed: %w", err) return } a.AdaptationExtensionField.LegalTimeWindowIsValid = bs[0]&0x80 > 0 @@ -257,7 +258,7 @@ func parsePacketAdaptationField(i *astikit.BytesIterator) (a *PacketAdaptationFi if a.AdaptationExtensionField.HasPiecewiseRate { var bs []byte if bs, err = i.NextBytes(3); err != nil { - err = errors.Wrap(err, "astits: fetching next bytes failed") + err = fmt.Errorf("astits: fetching next bytes failed: %w", err) return } a.AdaptationExtensionField.PiecewiseRate = uint32(bs[0]&0x3f)<<16 | uint32(bs[1])<<8 | uint32(bs[2]) @@ -267,7 +268,7 @@ func parsePacketAdaptationField(i *astikit.BytesIterator) (a *PacketAdaptationFi if a.AdaptationExtensionField.HasSeamlessSplice { // Get next byte if b, err = i.NextByte(); err != nil { - err = errors.Wrap(err, "astits: fetching next byte failed") + err = fmt.Errorf("astits: fetching next byte failed: %w", err) return } @@ -279,7 +280,7 @@ func parsePacketAdaptationField(i *astikit.BytesIterator) (a *PacketAdaptationFi // DTS Next access unit if a.AdaptationExtensionField.DTSNextAccessUnit, err = parsePTSOrDTS(i); err != nil { - err = errors.Wrap(err, "astits: parsing DTS failed") + err = fmt.Errorf("astits: parsing DTS failed: %w", err) return } } @@ -294,7 +295,7 @@ func parsePacketAdaptationField(i *astikit.BytesIterator) (a *PacketAdaptationFi func parsePCR(i *astikit.BytesIterator) (cr *ClockReference, err error) { var bs []byte if bs, err = i.NextBytes(6); err != nil { - err = errors.Wrap(err, "astits: fetching next bytes failed") + err = fmt.Errorf("astits: fetching next bytes failed: %w", err) return } pcr := uint64(bs[0])<<40 | uint64(bs[1])<<32 | uint64(bs[2])<<24 | uint64(bs[3])<<16 | uint64(bs[4])<<8 | uint64(bs[5]) diff --git a/packet_buffer.go b/packet_buffer.go index cc2070c..5273b2e 100644 --- a/packet_buffer.go +++ b/packet_buffer.go @@ -5,7 +5,6 @@ import ( "io" "github.com/asticode/go-astikit" - "github.com/pkg/errors" ) // packetBuffer represents a packet buffer @@ -26,7 +25,7 @@ func newPacketBuffer(r io.Reader, packetSize int) (pb *packetBuffer, err error) if pb.packetSize == 0 { // Auto detect packet size if pb.packetSize, err = autoDetectPacketSize(r); err != nil { - err = errors.Wrap(err, "astits: auto detecting packet size failed") + err = fmt.Errorf("astits: auto detecting packet size failed: %w", err) return } } @@ -41,7 +40,7 @@ func autoDetectPacketSize(r io.Reader) (packetSize int, err error) { const l = 193 var b = make([]byte, l) if _, err = r.Read(b); err != nil { - err = errors.Wrapf(err, "astits: reading first %d bytes failed", l) + err = fmt.Errorf("astits: reading first %d bytes failed: %w", l, err) return } @@ -60,12 +59,12 @@ func autoDetectPacketSize(r io.Reader) (packetSize int, err error) { // Rewind or sync reader var n int64 if n, err = rewind(r); err != nil { - err = errors.Wrap(err, "astits: rewinding failed") + err = fmt.Errorf("astits: rewinding failed: %w", err) return } else if n == -1 { var ls = packetSize - (l - packetSize) if _, err = r.Read(make([]byte, ls)); err != nil { - err = errors.Wrapf(err, "astits: reading %d bytes to sync reader failed", ls) + err = fmt.Errorf("astits: reading %d bytes to sync reader failed: %w", ls, err) return } } @@ -80,7 +79,7 @@ func autoDetectPacketSize(r io.Reader) (packetSize int, err error) { func rewind(r io.Reader) (n int64, err error) { if s, ok := r.(io.Seeker); ok { if n, err = s.Seek(0, 0); err != nil { - err = errors.Wrap(err, "astits: seeking to 0 failed") + err = fmt.Errorf("astits: seeking to 0 failed: %w", err) return } return @@ -97,14 +96,14 @@ func (pb *packetBuffer) next() (p *Packet, err error) { if err == io.EOF || err == io.ErrUnexpectedEOF { err = ErrNoMorePackets } else { - err = errors.Wrapf(err, "astits: reading %d bytes failed", pb.packetSize) + err = fmt.Errorf("astits: reading %d bytes failed: %w", pb.packetSize, err) } return } // Parse packet if p, err = parsePacket(astikit.NewBytesIterator(b)); err != nil { - err = errors.Wrap(err, "astits: building packet failed") + err = fmt.Errorf("astits: building packet failed: %w", err) return } return