-
Notifications
You must be signed in to change notification settings - Fork 115
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
Additional testing and associated bug fixes related to H.265 payloader #287
Open
y-kawawa
wants to merge
4
commits into
pion:h265
Choose a base branch
from
y-kawawa:master
base: h265
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+311
−10
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -962,7 +962,7 @@ type H265Payloader struct { | |
// Payload fragments a H265 packet across one or more byte arrays | ||
func (p *H265Payloader) Payload(mtu uint16, payload []byte) [][]byte { //nolint: gocognit | ||
var payloads [][]byte | ||
if len(payload) == 0 { | ||
if len(payload) == 0 || mtu == 0 { | ||
return payloads | ||
} | ||
|
||
|
@@ -998,7 +998,7 @@ func (p *H265Payloader) Payload(mtu uint16, payload []byte) [][]byte { //nolint: | |
} | ||
} else { | ||
// construct an aggregation packet | ||
aggregationPacketSize := aggregationBufferSize + 2 | ||
aggregationPacketSize := aggregationBufferSize | ||
buf := make([]byte, aggregationPacketSize) | ||
|
||
layerID := uint8(math.MaxUint8) | ||
|
@@ -1039,22 +1039,39 @@ func (p *H265Payloader) Payload(mtu uint16, payload []byte) [][]byte { //nolint: | |
aggregationBufferSize = 0 | ||
} | ||
|
||
calcMarginalAggregationSize := func(nalu []byte) int { | ||
marginalAggregationSize := len(nalu) + 2 // +2 is NALU size Field size | ||
if len(bufferedNALUs) == 1 { | ||
marginalAggregationSize = len(nalu) + 4 // +4 are Aggregation header + NALU size Field size | ||
} | ||
if p.AddDONL { | ||
if len(bufferedNALUs) == 0 { | ||
marginalAggregationSize += 2 | ||
} else { | ||
marginalAggregationSize++ | ||
} | ||
} | ||
return marginalAggregationSize | ||
} | ||
|
||
emitNalus(payload, func(nalu []byte) { | ||
if len(nalu) == 0 { | ||
if len(nalu) < 2 { | ||
// NALU header is 2 bytes | ||
return | ||
} | ||
|
||
if len(nalu) <= int(mtu) { | ||
naluLen := len(nalu) + 2 | ||
if p.AddDONL { | ||
naluLen += 2 | ||
} | ||
if naluLen <= int(mtu) { | ||
// this nalu fits into a single packet, either it can be emitted as | ||
// a single nalu or appended to the previous aggregation packet | ||
|
||
marginalAggregationSize := len(nalu) + 2 | ||
if p.AddDONL { | ||
marginalAggregationSize++ | ||
} | ||
marginalAggregationSize := calcMarginalAggregationSize(nalu) | ||
|
||
if aggregationBufferSize+marginalAggregationSize > int(mtu) { | ||
flushBufferedNals() | ||
marginalAggregationSize = calcMarginalAggregationSize(nalu) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After flushing, recalculate because the margin conditions change. |
||
} | ||
bufferedNALUs = append(bufferedNALUs, nalu) | ||
aggregationBufferSize += marginalAggregationSize | ||
|
@@ -1077,7 +1094,7 @@ func (p *H265Payloader) Payload(mtu uint16, payload []byte) [][]byte { //nolint: | |
// the nalu header is omitted from the fragmentation packet payload | ||
nalu = nalu[h265NaluHeaderSize:] | ||
|
||
if maxFUPayloadSize == 0 || len(nalu) == 0 { | ||
if maxFUPayloadSize <= 0 || len(nalu) == 0 { | ||
return | ||
} | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To prevent the MTU size from being exceeded during aggregation packet, the size is compared by adding 2 bytes for the aggregation header.