remove redundant variables

This commit is contained in:
aler9
2022-12-28 23:32:20 +01:00
parent da21f946e5
commit 33fe24eb6d
2 changed files with 14 additions and 23 deletions

View File

@@ -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:

View File

@@ -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")
}