Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
sfu
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alain Takoudjou
sfu
Commits
f641e263
Commit
f641e263
authored
May 20, 2020
by
Juliusz Chroboczek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make packetcache.Get use a caller-allocated buffer.
parent
a6ff98a3
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
16 deletions
+26
-16
client.go
client.go
+5
-4
packetcache/packetcache.go
packetcache/packetcache.go
+6
-5
packetcache/packetcache_test.go
packetcache/packetcache_test.go
+15
-7
No files found.
client.go
View file @
f641e263
...
...
@@ -855,13 +855,14 @@ func sendNACK(pc *webrtc.PeerConnection, ssrc uint32, first uint16, bitmap uint1
func
sendRecovery
(
p
*
rtcp
.
TransportLayerNack
,
track
*
downTrack
)
{
var
packet
rtp
.
Packet
buf
:=
make
([]
byte
,
packetcache
.
BufSize
)
for
_
,
nack
:=
range
p
.
Nacks
{
for
_
,
seqno
:=
range
nack
.
PacketList
()
{
raw
:=
track
.
remote
.
cache
.
Get
(
seqno
)
if
raw
==
nil
{
l
:=
track
.
remote
.
cache
.
Get
(
seqno
,
buf
)
if
l
==
0
{
continue
}
err
:=
packet
.
Unmarshal
(
raw
)
err
:=
packet
.
Unmarshal
(
buf
[
:
l
]
)
if
err
!=
nil
{
continue
}
...
...
@@ -870,7 +871,7 @@ func sendRecovery(p *rtcp.TransportLayerNack, track *downTrack) {
log
.
Printf
(
"%v"
,
err
)
continue
}
track
.
rate
.
Add
(
uint32
(
l
en
(
raw
)
))
track
.
rate
.
Add
(
uint32
(
l
))
}
}
}
...
...
packetcache/packetcache.go
View file @
f641e263
...
...
@@ -115,7 +115,7 @@ func (cache *Cache) Expect(n int) {
cache
.
expected
+=
uint32
(
n
)
}
func
(
cache
*
Cache
)
Get
(
seqno
uint16
)
[]
byte
{
func
(
cache
*
Cache
)
Get
(
seqno
uint16
,
result
[]
byte
)
uint16
{
cache
.
mu
.
Lock
()
defer
cache
.
mu
.
Unlock
()
...
...
@@ -124,11 +124,12 @@ func (cache *Cache) Get(seqno uint16) []byte {
cache
.
entries
[
i
]
.
seqno
!=
seqno
{
continue
}
buf
:=
make
([]
byte
,
cache
.
entries
[
i
]
.
length
)
copy
(
buf
,
cache
.
entries
[
i
]
.
buf
[
:
])
return
buf
return
uint16
(
copy
(
result
[
:
cache
.
entries
[
i
]
.
length
],
cache
.
entries
[
i
]
.
buf
[
:
]),
)
}
return
nil
return
0
}
// Shift 17 bits out of the bitmap. Return a boolean indicating if any
...
...
packetcache/packetcache_test.go
View file @
f641e263
...
...
@@ -23,13 +23,20 @@ func TestCache(t *testing.T) {
cache
.
Store
(
13
,
buf1
)
cache
.
Store
(
17
,
buf2
)
if
bytes
.
Compare
(
cache
.
Get
(
13
),
buf1
)
!=
0
{
buf
:=
make
([]
byte
,
BufSize
)
l
:=
cache
.
Get
(
13
,
buf
)
if
bytes
.
Compare
(
buf
[
:
l
],
buf1
)
!=
0
{
t
.
Errorf
(
"Couldn't get 13"
)
}
if
bytes
.
Compare
(
cache
.
Get
(
17
),
buf2
)
!=
0
{
l
=
cache
.
Get
(
17
,
buf
)
if
bytes
.
Compare
(
buf
[
:
l
],
buf2
)
!=
0
{
t
.
Errorf
(
"Couldn't get 17"
)
}
if
cache
.
Get
(
42
)
!=
nil
{
l
=
cache
.
Get
(
42
,
buf
)
if
l
!=
0
{
t
.
Errorf
(
"Creation ex nihilo"
)
}
}
...
...
@@ -42,14 +49,15 @@ func TestCacheOverflow(t *testing.T) {
}
for
i
:=
0
;
i
<
32
;
i
++
{
buf
:=
cache
.
Get
(
uint16
(
i
))
buf
:=
make
([]
byte
,
BufSize
)
l
:=
cache
.
Get
(
uint16
(
i
),
buf
)
if
i
<
16
{
if
buf
!=
nil
{
if
l
>
0
{
t
.
Errorf
(
"Creation ex nihilo: %v"
,
i
)
}
}
else
{
if
l
en
(
buf
)
!=
1
||
buf
[
0
]
!=
uint8
(
i
)
{
t
.
Errorf
(
"Expected [%v], got %v"
,
i
,
buf
)
if
l
!=
1
||
buf
[
0
]
!=
uint8
(
i
)
{
t
.
Errorf
(
"Expected [%v], got %v"
,
i
,
buf
[
:
l
]
)
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment