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
19162413
Commit
19162413
authored
Jun 08, 2020
by
Juliusz Chroboczek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use packet timestamps when saving to disk.
parent
f9edde65
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
18 deletions
+27
-18
disk.go
disk.go
+27
-18
No files found.
disk.go
View file @
19162413
...
...
@@ -78,11 +78,13 @@ func (client *diskClient) pushConn(conn upConnection, tracks []upTrack, label st
type
diskConn
struct
{
directory
string
label
string
hasVideo
bool
mu
sync
.
Mutex
file
*
os
.
File
remote
upConnection
tracks
[]
*
diskTrack
reference
int
// the track used as a time reference
width
,
height
uint32
}
...
...
@@ -126,7 +128,7 @@ func (conn *diskConn) Close() error {
}
func
openDiskFile
(
directory
,
label
string
)
(
*
os
.
File
,
error
)
{
filename
:=
time
.
Now
()
.
Format
(
"2006-01-02T15:04:05"
)
filename
:=
time
.
Now
()
.
Format
(
"2006-01-02T15:04:05
.000
"
)
if
label
!=
""
{
filename
=
filename
+
"-"
+
label
}
...
...
@@ -155,9 +157,11 @@ type diskTrack struct {
remote
upTrack
conn
*
diskConn
writer
webm
.
BlockWriteCloser
builder
*
samplebuilder
.
SampleBuilder
timestamp
uint32
writer
webm
.
BlockWriteCloser
builder
*
samplebuilder
.
SampleBuilder
// bit 32 is a boolean indicating that the origin is valid
origin
uint64
}
func
newDiskConn
(
directory
,
label
string
,
up
upConnection
,
remoteTracks
[]
upTrack
)
(
*
diskConn
,
error
)
{
...
...
@@ -167,18 +171,17 @@ func newDiskConn(directory, label string, up upConnection, remoteTracks []upTrac
tracks
:
make
([]
*
diskTrack
,
0
,
len
(
remoteTracks
)),
remote
:
up
,
}
video
:=
false
for
_
,
remote
:=
range
remoteTracks
{
var
builder
*
samplebuilder
.
SampleBuilder
switch
remote
.
Codec
()
.
Name
{
case
webrtc
.
Opus
:
builder
=
samplebuilder
.
New
(
16
,
&
codecs
.
OpusPacket
{})
case
webrtc
.
VP8
:
if
v
ideo
{
if
conn
.
hasV
ideo
{
return
nil
,
errors
.
New
(
"multiple video tracks not supported"
)
}
builder
=
samplebuilder
.
New
(
32
,
&
codecs
.
VP8Packet
{})
v
ideo
=
true
conn
.
hasV
ideo
=
true
}
track
:=
&
diskTrack
{
remote
:
remote
,
...
...
@@ -189,13 +192,6 @@ func newDiskConn(directory, label string, up upConnection, remoteTracks []upTrac
remote
.
addLocal
(
track
)
}
if
!
video
{
err
:=
conn
.
initWriter
(
0
,
0
)
if
err
!=
nil
{
return
nil
,
err
}
}
err
:=
up
.
addLocal
(
&
conn
)
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -237,13 +233,11 @@ func (t *diskTrack) WriteRTP(packet *rtp.Packet) error {
t
.
builder
.
Push
(
p
)
for
{
sample
:=
t
.
builder
.
Po
p
()
sample
,
ts
:=
t
.
builder
.
PopWithTimestam
p
()
if
sample
==
nil
{
return
nil
}
t
.
timestamp
+=
sample
.
Samples
keyframe
:=
true
switch
t
.
remote
.
Codec
()
.
Name
{
...
...
@@ -258,7 +252,17 @@ func (t *diskTrack) WriteRTP(packet *rtp.Packet) error {
return
err
}
}
default
:
if
t
.
writer
==
nil
{
if
!
t
.
conn
.
hasVideo
{
err
:=
t
.
conn
.
initWriter
(
0
,
0
)
if
err
!=
nil
{
return
err
}
}
}
}
if
t
.
writer
==
nil
{
if
!
keyframe
{
return
ErrKeyframeNeeded
...
...
@@ -266,7 +270,12 @@ func (t *diskTrack) WriteRTP(packet *rtp.Packet) error {
return
nil
}
tm
:=
t
.
timestamp
/
(
t
.
remote
.
Codec
()
.
ClockRate
/
1000
)
if
t
.
origin
==
0
{
t
.
origin
=
uint64
(
ts
)
|
(
1
<<
32
)
}
ts
-=
uint32
(
t
.
origin
)
tm
:=
ts
/
(
t
.
remote
.
Codec
()
.
ClockRate
/
1000
)
_
,
err
:=
t
.
writer
.
Write
(
keyframe
,
int64
(
tm
),
sample
.
Data
)
if
err
!=
nil
{
return
err
...
...
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