From 33fe24eb6d40710dc8e9b716d7a01d65a52f44e6 Mon Sep 17 00:00:00 2001 From: aler9 <46489434+aler9@users.noreply.github.com> Date: Wed, 28 Dec 2022 23:32:20 +0100 Subject: [PATCH] remove redundant variables --- pkg/codecs/h264/dtsextractor.go | 31 +++++++++++++------------------ pkg/codecs/h265/dtsextractor.go | 6 +----- 2 files changed, 14 insertions(+), 23 deletions(-) diff --git a/pkg/codecs/h264/dtsextractor.go b/pkg/codecs/h264/dtsextractor.go index 3488d612..d42742f3 100644 --- a/pkg/codecs/h264/dtsextractor.go +++ b/pkg/codecs/h264/dtsextractor.go @@ -1,7 +1,6 @@ package h264 import ( - "bytes" "fmt" "math" "time" @@ -163,7 +162,6 @@ func findSEITimingInfo(nalus [][]byte, sps *SPS) (*seiTimingInfo, bool) { // DTSExtractor allows to extract DTS from PTS. type DTSExtractor struct { - sps []byte spsp *SPS prevPTS time.Duration prevDTSFilled bool @@ -185,23 +183,20 @@ func (d *DTSExtractor) extractInner(nalus [][]byte, pts time.Duration) (time.Dur typ := NALUType(nalu[0] & 0x1F) switch typ { case NALUTypeSPS: - if d.sps == nil || !bytes.Equal(d.sps, nalu) { - var spsp SPS - err := spsp.Unmarshal(nalu) - if err != nil { - return 0, 0, fmt.Errorf("invalid SPS: %v", err) - } - d.sps = append([]byte(nil), nalu...) - d.spsp = &spsp + var spsp SPS + err := spsp.Unmarshal(nalu) + if err != nil { + return 0, 0, fmt.Errorf("invalid SPS: %v", err) + } + d.spsp = &spsp - if d.spsp.VUI != nil && d.spsp.VUI.TimingInfo != nil && - d.spsp.VUI.BitstreamRestriction != nil { - d.ptsDTSOffset = time.Duration(math.Round(float64( - time.Duration(d.spsp.VUI.BitstreamRestriction.MaxNumReorderFrames)*time.Second* - time.Duration(d.spsp.VUI.TimingInfo.NumUnitsInTick)*2) / float64(d.spsp.VUI.TimingInfo.TimeScale))) - } else { - d.ptsDTSOffset = 0 - } + if d.spsp.VUI != nil && d.spsp.VUI.TimingInfo != nil && + d.spsp.VUI.BitstreamRestriction != nil { + d.ptsDTSOffset = time.Duration(math.Round(float64( + time.Duration(d.spsp.VUI.BitstreamRestriction.MaxNumReorderFrames)*time.Second* + time.Duration(d.spsp.VUI.TimingInfo.NumUnitsInTick)*2) / float64(d.spsp.VUI.TimingInfo.TimeScale))) + } else { + d.ptsDTSOffset = 0 } case NALUTypeIDR: diff --git a/pkg/codecs/h265/dtsextractor.go b/pkg/codecs/h265/dtsextractor.go index 49244853..3844f964 100644 --- a/pkg/codecs/h265/dtsextractor.go +++ b/pkg/codecs/h265/dtsextractor.go @@ -131,9 +131,7 @@ func getPictureOrderCountDiff(poc1 uint32, poc2 uint32, sps *SPS) int32 { // DTSExtractor allows to extract DTS from PTS. type DTSExtractor struct { - sps []byte spsp *SPS - pps []byte ppsp *PPS prevDTSFilled bool prevDTS time.Duration @@ -157,7 +155,6 @@ func (d *DTSExtractor) extractInner(nalus [][]byte, pts time.Duration) (time.Dur if err != nil { return 0, fmt.Errorf("invalid SPS: %v", err) } - d.sps = append([]byte(nil), nalu...) d.spsp = &spsp case NALUType_PPS_NUT: @@ -166,7 +163,6 @@ func (d *DTSExtractor) extractInner(nalus [][]byte, pts time.Duration) (time.Dur if err != nil { return 0, fmt.Errorf("invalid PPS: %v", err) } - d.pps = append([]byte(nil), nalu...) d.ppsp = &ppsp case NALUType_IDR_W_RADL, NALUType_IDR_N_LP: @@ -178,7 +174,7 @@ func (d *DTSExtractor) extractInner(nalus [][]byte, pts time.Duration) (time.Dur return 0, fmt.Errorf("SPS not received yet") } - if d.pps == nil { + if d.ppsp == nil { return 0, fmt.Errorf("PPS not received yet") }