mirror of
https://github.com/aler9/gortsplib
synced 2025-10-27 09:11:17 +08:00
h264: move SPS bitstream restriction into dedicated struct
This commit is contained in:
@@ -131,9 +131,11 @@ func (d *DTSExtractor) extractInner(
|
|||||||
d.spsp = &spsp
|
d.spsp = &spsp
|
||||||
|
|
||||||
// in case of B-frames, we have to subtract from DTS the maximum number of reordered frames
|
// in case of B-frames, we have to subtract from DTS the maximum number of reordered frames
|
||||||
if d.spsp.VUI != nil && d.spsp.VUI.TimingInfo != nil {
|
if d.spsp.VUI != nil && d.spsp.VUI.TimingInfo != nil &&
|
||||||
d.ptsDTSOffset = time.Duration(math.Round(float64(time.Duration(d.spsp.VUI.MaxNumReorderFrames)*time.Second*
|
d.spsp.VUI.BitstreamRestriction != nil {
|
||||||
time.Duration(d.spsp.VUI.TimingInfo.NumUnitsInTick)*2) / float64(d.spsp.VUI.TimingInfo.TimeScale)))
|
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 {
|
} else {
|
||||||
d.ptsDTSOffset = 0
|
d.ptsDTSOffset = 0
|
||||||
}
|
}
|
||||||
@@ -170,7 +172,8 @@ func (d *DTSExtractor) extractInner(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// special case to eliminate errors near 0
|
// special case to eliminate errors near 0
|
||||||
if d.spsp.VUI != nil && d.spsp.VUI.TimingInfo != nil && pocDiff == -int32(d.spsp.VUI.MaxNumReorderFrames)*2 {
|
if d.spsp.VUI != nil && d.spsp.VUI.TimingInfo != nil && d.spsp.VUI.BitstreamRestriction != nil &&
|
||||||
|
pocDiff == -int32(d.spsp.VUI.BitstreamRestriction.MaxNumReorderFrames)*2 {
|
||||||
return pts, pocDiff, nil
|
return pts, pocDiff, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
103
pkg/h264/sps.go
103
pkg/h264/sps.go
@@ -221,6 +221,57 @@ func (t *SPS_TimingInfo) unmarshal(br *bitio.Reader) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SPS_BitstreamRestriction are bitstream restriction infos.
|
||||||
|
type SPS_BitstreamRestriction struct { //nolint:revive
|
||||||
|
MotionVectorsOverPicBoundariesFlag bool
|
||||||
|
MaxBytesPerPicDenom uint32
|
||||||
|
MaxBitsPerMbDenom uint32
|
||||||
|
Log2MaxMvLengthHorizontal uint32
|
||||||
|
Log2MaxMvLengthVertical uint32
|
||||||
|
MaxNumReorderFrames uint32
|
||||||
|
MaxDecFrameBuffering uint32
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *SPS_BitstreamRestriction) unmarshal(br *bitio.Reader) error {
|
||||||
|
var err error
|
||||||
|
r.MotionVectorsOverPicBoundariesFlag, err = readFlag(br)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
r.MaxBytesPerPicDenom, err = readGolombUnsigned(br)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
r.MaxBitsPerMbDenom, err = readGolombUnsigned(br)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
r.Log2MaxMvLengthHorizontal, err = readGolombUnsigned(br)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
r.Log2MaxMvLengthVertical, err = readGolombUnsigned(br)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
r.MaxNumReorderFrames, err = readGolombUnsigned(br)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
r.MaxDecFrameBuffering, err = readGolombUnsigned(br)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// SPS_VUI is a video usability information.
|
// SPS_VUI is a video usability information.
|
||||||
type SPS_VUI struct { //nolint:revive
|
type SPS_VUI struct { //nolint:revive
|
||||||
AspectRatioInfoPresentFlag bool
|
AspectRatioInfoPresentFlag bool
|
||||||
@@ -256,18 +307,11 @@ type SPS_VUI struct { //nolint:revive
|
|||||||
// vclHrdParametersPresentFlag == true
|
// vclHrdParametersPresentFlag == true
|
||||||
VclHRD *SPS_HRD
|
VclHRD *SPS_HRD
|
||||||
|
|
||||||
LowDelayHrdFlag bool
|
LowDelayHrdFlag bool
|
||||||
PicStructPresentFlag bool
|
PicStructPresentFlag bool
|
||||||
BitstreamRestrictionFlag bool
|
|
||||||
|
|
||||||
// BitstreamRestrictionFlag == true
|
// bitstreamRestrictionFlag == true
|
||||||
MotionVectorsOverPicBoundariesFlag bool
|
BitstreamRestriction *SPS_BitstreamRestriction
|
||||||
MaxBytesPerPicDenom uint32
|
|
||||||
MaxBitsPerMbDenom uint32
|
|
||||||
Log2MaxMvLengthHorizontal uint32
|
|
||||||
Log2MaxMvLengthVertical uint32
|
|
||||||
MaxNumReorderFrames uint32
|
|
||||||
MaxDecFrameBuffering uint32
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *SPS_VUI) unmarshal(br *bitio.Reader) error {
|
func (v *SPS_VUI) unmarshal(br *bitio.Reader) error {
|
||||||
@@ -416,43 +460,14 @@ func (v *SPS_VUI) unmarshal(br *bitio.Reader) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
v.BitstreamRestrictionFlag, err = readFlag(br)
|
bitstreamRestrictionFlag, err := readFlag(br)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if v.BitstreamRestrictionFlag {
|
if bitstreamRestrictionFlag {
|
||||||
v.MotionVectorsOverPicBoundariesFlag, err = readFlag(br)
|
v.BitstreamRestriction = &SPS_BitstreamRestriction{}
|
||||||
if err != nil {
|
err := v.BitstreamRestriction.unmarshal(br)
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
v.MaxBytesPerPicDenom, err = readGolombUnsigned(br)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
v.MaxBitsPerMbDenom, err = readGolombUnsigned(br)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
v.Log2MaxMvLengthHorizontal, err = readGolombUnsigned(br)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
v.Log2MaxMvLengthVertical, err = readGolombUnsigned(br)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
v.MaxNumReorderFrames, err = readGolombUnsigned(br)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
v.MaxDecFrameBuffering, err = readGolombUnsigned(br)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -74,12 +74,13 @@ func TestSPSUnmarshal(t *testing.T) {
|
|||||||
NumUnitsInTick: 1,
|
NumUnitsInTick: 1,
|
||||||
TimeScale: 60,
|
TimeScale: 60,
|
||||||
},
|
},
|
||||||
BitstreamRestrictionFlag: true,
|
BitstreamRestriction: &SPS_BitstreamRestriction{
|
||||||
MotionVectorsOverPicBoundariesFlag: true,
|
MotionVectorsOverPicBoundariesFlag: true,
|
||||||
Log2MaxMvLengthHorizontal: 11,
|
Log2MaxMvLengthHorizontal: 11,
|
||||||
Log2MaxMvLengthVertical: 11,
|
Log2MaxMvLengthVertical: 11,
|
||||||
MaxNumReorderFrames: 2,
|
MaxNumReorderFrames: 2,
|
||||||
MaxDecFrameBuffering: 4,
|
MaxDecFrameBuffering: 4,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
1280,
|
1280,
|
||||||
@@ -112,11 +113,12 @@ func TestSPSUnmarshal(t *testing.T) {
|
|||||||
NumUnitsInTick: 1,
|
NumUnitsInTick: 1,
|
||||||
TimeScale: 60,
|
TimeScale: 60,
|
||||||
},
|
},
|
||||||
BitstreamRestrictionFlag: true,
|
BitstreamRestriction: &SPS_BitstreamRestriction{
|
||||||
MotionVectorsOverPicBoundariesFlag: true,
|
MotionVectorsOverPicBoundariesFlag: true,
|
||||||
Log2MaxMvLengthHorizontal: 11,
|
Log2MaxMvLengthHorizontal: 11,
|
||||||
Log2MaxMvLengthVertical: 11,
|
Log2MaxMvLengthVertical: 11,
|
||||||
MaxDecFrameBuffering: 3,
|
MaxDecFrameBuffering: 3,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
1920,
|
1920,
|
||||||
@@ -149,12 +151,13 @@ func TestSPSUnmarshal(t *testing.T) {
|
|||||||
NumUnitsInTick: 1,
|
NumUnitsInTick: 1,
|
||||||
TimeScale: 60,
|
TimeScale: 60,
|
||||||
},
|
},
|
||||||
BitstreamRestrictionFlag: true,
|
BitstreamRestriction: &SPS_BitstreamRestriction{
|
||||||
MotionVectorsOverPicBoundariesFlag: true,
|
MotionVectorsOverPicBoundariesFlag: true,
|
||||||
Log2MaxMvLengthHorizontal: 11,
|
Log2MaxMvLengthHorizontal: 11,
|
||||||
Log2MaxMvLengthVertical: 11,
|
Log2MaxMvLengthVertical: 11,
|
||||||
MaxNumReorderFrames: 2,
|
MaxNumReorderFrames: 2,
|
||||||
MaxDecFrameBuffering: 4,
|
MaxDecFrameBuffering: 4,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
1920,
|
1920,
|
||||||
|
|||||||
Reference in New Issue
Block a user