Skip to content
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
25 changes: 7 additions & 18 deletions codecs/vp8_packet.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,11 @@ func (p *VP8Payloader) Payload(mtu uint16, payload []byte) [][]byte { //nolint:c
* first packet of each encoded frame.
*/

// Like libwebrtc, always use the 15-bit PictureID so the descriptor size
// does not change and SFUs can rewrite the PictureID in place.
usingHeaderSize := vp8HeaderSize
if p.EnablePictureID {
switch {
case p.pictureID < 128:
usingHeaderSize = vp8HeaderSize + 2
default:
usingHeaderSize = vp8HeaderSize + 3
}
usingHeaderSize = vp8HeaderSize + 3
}

maxFragmentSize := int(mtu) - usingHeaderSize
Expand All @@ -68,18 +65,10 @@ func (p *VP8Payloader) Payload(mtu uint16, payload []byte) [][]byte { //nolint:c
first = false
}
if p.EnablePictureID {
switch usingHeaderSize {
case vp8HeaderSize:
case vp8HeaderSize + 2:
out[0] |= 0x80
out[1] |= 0x80
out[2] |= uint8(p.pictureID & 0x7F) // nolint: gosec // G115 false positive
case vp8HeaderSize + 3:
out[0] |= 0x80
out[1] |= 0x80
out[2] |= 0x80 | uint8((p.pictureID>>8)&0x7F) // nolint: gosec // G115 false positive
out[3] |= uint8(p.pictureID & 0xFF) // nolint: gosec // G115 false positive
}
out[0] |= 0x80
out[1] |= 0x80
out[2] |= 0x80 | uint8((p.pictureID>>8)&0x7F) // nolint: gosec // G115 false positive
out[3] |= uint8(p.pictureID & 0xFF) // nolint: gosec // G115 false positive
}

copy(out[usingHeaderSize:], payloadData[payloadDataIndex:payloadDataIndex+currentFragmentSize])
Expand Down
16 changes: 8 additions & 8 deletions codecs/vp8_packet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,27 +103,27 @@ func TestVP8Payloader_Payload(t *testing.T) {
{{0x10, 0x91}, {0x00, 0x91}},
},
},
"WithPictureID_1byte": {
"WithPictureID_small": {
payloader: VP8Payloader{
EnablePictureID: true,
pictureID: 0x20,
},
mtu: 5,
mtu: 6,
payload: [][]byte{
{0x90, 0x90, 0x90},
{0x91, 0x91},
},
expected: [][][]byte{
{
{0x90, 0x80, 0x20, 0x90, 0x90},
{0x80, 0x80, 0x20, 0x90},
{0x90, 0x80, 0x80, 0x20, 0x90, 0x90},
{0x80, 0x80, 0x80, 0x20, 0x90},
},
{
{0x90, 0x80, 0x21, 0x91, 0x91},
{0x90, 0x80, 0x80, 0x21, 0x91, 0x91},
},
},
},
"WithPictureID_2bytes": {
"WithPictureID_large": {
payloader: VP8Payloader{
EnablePictureID: true,
pictureID: 0x120,
Expand Down Expand Up @@ -159,10 +159,10 @@ func TestVP8Payloader_Payload(t *testing.T) {
{0x90, 0x80, 0xFF, 0xFF, 0x90, 0x90},
},
{
{0x90, 0x80, 0x00, 0x91, 0x91},
{0x90, 0x80, 0x80, 0x00, 0x91, 0x91},
},
{
{0x90, 0x80, 0x01, 0x92, 0x92},
{0x90, 0x80, 0x80, 0x01, 0x92, 0x92},
},
},
},
Expand Down
Loading