Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

various performance improvements #561

Merged
merged 1 commit into from
May 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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 @@
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 @@
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 @@
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
Loading