Skip to content

Commit

Permalink
various performance improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
aler9 committed May 5, 2024
1 parent 3f62e11 commit 108666e
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 6 deletions.
6 changes: 5 additions & 1 deletion pkg/format/h264.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func (f *H264) PTSEqualsDTS(pkt *rtp.Packet) bool {
case 24: // STAP-A
payload := pkt.Payload[1:]

for len(payload) > 0 {
for {

Check warning on line 139 in pkg/format/h264.go

View check run for this annotation

Codecov / codecov/patch

pkg/format/h264.go#L139

Added line #L139 was not covered by tests
if len(payload) < 2 {
return false
}
Expand All @@ -156,6 +156,10 @@ func (f *H264) PTSEqualsDTS(pkt *rtp.Packet) bool {
case h264.NALUTypeIDR, h264.NALUTypeSPS, h264.NALUTypePPS:
return true
}

if len(payload) == 0 {
break

Check warning on line 161 in pkg/format/h264.go

View check run for this annotation

Codecov / codecov/patch

pkg/format/h264.go#L160-L161

Added lines #L160 - L161 were not covered by tests
}
}

case 28: // FU-A
Expand Down
6 changes: 5 additions & 1 deletion pkg/format/h265.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func (f *H265) PTSEqualsDTS(pkt *rtp.Packet) bool {
case h265.NALUType_AggregationUnit:
payload := pkt.Payload[2:]

for len(payload) > 0 {
for {

Check warning on line 145 in pkg/format/h265.go

View check run for this annotation

Codecov / codecov/patch

pkg/format/h265.go#L145

Added line #L145 was not covered by tests
if len(payload) < 2 {
return false
}
Expand All @@ -163,6 +163,10 @@ func (f *H265) PTSEqualsDTS(pkt *rtp.Packet) bool {
h265.NALUType_VPS_NUT, h265.NALUType_SPS_NUT, h265.NALUType_PPS_NUT:
return true
}

if len(payload) == 0 {
break

Check warning on line 168 in pkg/format/h265.go

View check run for this annotation

Codecov / codecov/patch

pkg/format/h265.go#L167-L168

Added lines #L167 - L168 were not covered by tests
}
}

case h265.NALUType_FragmentationUnit:
Expand Down
6 changes: 5 additions & 1 deletion pkg/format/rtph264/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func (d *Decoder) decodeNALUs(pkt *rtp.Packet) ([][]byte, error) {

payload := pkt.Payload[1:]

for len(payload) > 0 {
for {
if len(payload) < 2 {
return nil, fmt.Errorf("invalid STAP-A packet (invalid size)")
}
Expand All @@ -136,6 +136,10 @@ func (d *Decoder) decodeNALUs(pkt *rtp.Packet) ([][]byte, error) {

nalus = append(nalus, payload[:size])
payload = payload[size:]

if len(payload) == 0 {
break
}
}

if nalus == nil {
Expand Down
6 changes: 5 additions & 1 deletion pkg/format/rtph265/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (d *Decoder) decodeNALUs(pkt *rtp.Packet) ([][]byte, error) {

payload := pkt.Payload[2:]

for len(payload) > 0 {
for {
if len(payload) < 2 {
return nil, fmt.Errorf("invalid aggregation unit (invalid size)")
}
Expand All @@ -85,6 +85,10 @@ func (d *Decoder) decodeNALUs(pkt *rtp.Packet) ([][]byte, error) {

nalus = append(nalus, payload[:size])
payload = payload[size:]

if len(payload) == 0 {
break
}
}

if nalus == nil {
Expand Down
8 changes: 6 additions & 2 deletions pkg/format/rtpmjpeg/encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ outer:
return nil, fmt.Errorf("JPEG type %d is not supported", sof.Type)
}

if data == nil {
if len(data) == 0 {
return nil, fmt.Errorf("image data not found")
}

Expand All @@ -211,7 +211,7 @@ outer:
offset := 0
var ret []*rtp.Packet

for len(data) > 0 {
for {
var buf []byte

jh.FragmentOffset = uint32(offset)
Expand Down Expand Up @@ -266,6 +266,10 @@ outer:
Payload: buf,
})
e.sequenceNumber++

if len(data) == 0 {
break
}
}

return ret, nil
Expand Down

0 comments on commit 108666e

Please sign in to comment.