Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
galene
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
nexedi
galene
Commits
99055e5c
Commit
99055e5c
authored
Apr 15, 2022
by
Juliusz Chroboczek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make duration functions work with negative values.
parent
d36111d9
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
32 additions
and
13 deletions
+32
-13
estimator/estimator.go
estimator/estimator.go
+4
-2
rtpconn/rtpstats.go
rtpconn/rtpstats.go
+1
-1
rtpconn/rtpwriter.go
rtpconn/rtpwriter.go
+1
-1
rtptime/rtptime.go
rtptime/rtptime.go
+13
-6
rtptime/rtptime_test.go
rtptime/rtptime_test.go
+13
-3
No files found.
estimator/estimator.go
View file @
99055e5c
...
@@ -23,8 +23,10 @@ type Estimator struct {
...
@@ -23,8 +23,10 @@ type Estimator struct {
// New creates a new estimator that estimates rate over the last interval.
// New creates a new estimator that estimates rate over the last interval.
func
New
(
interval
time
.
Duration
)
*
Estimator
{
func
New
(
interval
time
.
Duration
)
*
Estimator
{
return
&
Estimator
{
return
&
Estimator
{
interval
:
rtptime
.
FromDuration
(
interval
,
rtptime
.
JiffiesPerSec
),
interval
:
uint64
(
time
:
rtptime
.
Now
(
rtptime
.
JiffiesPerSec
),
rtptime
.
FromDuration
(
interval
,
rtptime
.
JiffiesPerSec
),
),
time
:
rtptime
.
Now
(
rtptime
.
JiffiesPerSec
),
}
}
}
}
...
...
rtpconn/rtpstats.go
View file @
99055e5c
...
@@ -57,7 +57,7 @@ func (c *webClient) GetStats() *stats.Client {
...
@@ -57,7 +57,7 @@ func (c *webClient) GetStats() *stats.Client {
maxTid
:=
layer
.
maxTid
maxTid
:=
layer
.
maxTid
rate
,
_
:=
t
.
rate
.
Estimate
()
rate
,
_
:=
t
.
rate
.
Estimate
()
maxRate
,
_
,
_
:=
t
.
GetMaxBitrate
()
maxRate
,
_
,
_
:=
t
.
GetMaxBitrate
()
rtt
:=
rtptime
.
ToDuration
(
t
.
getRTT
(
),
rtt
:=
rtptime
.
ToDuration
(
int64
(
t
.
getRTT
()
),
rtptime
.
JiffiesPerSec
)
rtptime
.
JiffiesPerSec
)
loss
,
jitter
:=
t
.
stats
.
Get
(
jiffies
)
loss
,
jitter
:=
t
.
stats
.
Get
(
jiffies
)
j
:=
time
.
Duration
(
jitter
)
*
time
.
Second
/
j
:=
time
.
Duration
(
jitter
)
*
time
.
Second
/
...
...
rtpconn/rtpwriter.go
View file @
99055e5c
...
@@ -138,7 +138,7 @@ func (wp *rtpWriterPool) write(seqno uint16, index uint16, delay uint32, isvideo
...
@@ -138,7 +138,7 @@ func (wp *rtpWriterPool) write(seqno uint16, index uint16, delay uint32, isvideo
// audio, try again with a delay
// audio, try again with a delay
d
:=
delay
/
uint32
(
2
*
len
(
wp
.
writers
))
d
:=
delay
/
uint32
(
2
*
len
(
wp
.
writers
))
timer
:=
time
.
NewTimer
(
rtptime
.
ToDuration
(
timer
:=
time
.
NewTimer
(
rtptime
.
ToDuration
(
u
int64
(
d
),
rtptime
.
JiffiesPerSec
,
int64
(
d
),
rtptime
.
JiffiesPerSec
,
))
))
select
{
select
{
...
...
rtptime/rtptime.go
View file @
99055e5c
...
@@ -9,18 +9,25 @@ import (
...
@@ -9,18 +9,25 @@ import (
var
epoch
=
time
.
Now
()
var
epoch
=
time
.
Now
()
// FromDuration converts a time.Duration into units of 1/hz.
// FromDuration converts a time.Duration into units of 1/hz.
func
FromDuration
(
d
time
.
Duration
,
hz
uint32
)
u
int64
{
func
FromDuration
(
d
time
.
Duration
,
hz
uint32
)
int64
{
return
uint64
(
d
)
*
uint64
(
hz
)
/
u
int64
(
time
.
Second
)
return
int64
(
d
)
*
int64
(
hz
)
/
int64
(
time
.
Second
)
}
}
// ToDuration converts units of 1/hz into a time.Duration.
// ToDuration converts units of 1/hz into a time.Duration.
func
ToDuration
(
tm
uint64
,
hz
uint32
)
time
.
Duration
{
func
ToDuration
(
tm
int64
,
hz
uint32
)
time
.
Duration
{
return
time
.
Duration
(
tm
*
uint64
(
time
.
Second
)
/
uint64
(
hz
))
return
time
.
Duration
(
tm
*
int64
(
time
.
Second
)
/
int64
(
hz
))
}
func
sat
(
a
int64
)
uint64
{
if
a
<
0
{
return
0
}
return
uint64
(
a
)
}
}
// Now returns the current time in units of 1/hz from an arbitrary origin.
// Now returns the current time in units of 1/hz from an arbitrary origin.
func
Now
(
hz
uint32
)
uint64
{
func
Now
(
hz
uint32
)
uint64
{
return
FromDuration
(
time
.
Since
(
epoch
),
hz
)
return
sat
(
FromDuration
(
time
.
Since
(
epoch
),
hz
)
)
}
}
// Microseconds is like Now, but uses microseconds.
// Microseconds is like Now, but uses microseconds.
...
@@ -39,7 +46,7 @@ func Jiffies() uint64 {
...
@@ -39,7 +46,7 @@ func Jiffies() uint64 {
// TimeToJiffies converts a time.Time into jiffies.
// TimeToJiffies converts a time.Time into jiffies.
func
TimeToJiffies
(
tm
time
.
Time
)
uint64
{
func
TimeToJiffies
(
tm
time
.
Time
)
uint64
{
return
FromDuration
(
tm
.
Sub
(
epoch
),
JiffiesPerSec
)
return
sat
(
FromDuration
(
tm
.
Sub
(
epoch
),
JiffiesPerSec
)
)
}
}
// The origin of NTP time.
// The origin of NTP time.
...
...
rtptime/rtptime_test.go
View file @
99055e5c
...
@@ -11,9 +11,19 @@ func TestDuration(t *testing.T) {
...
@@ -11,9 +11,19 @@ func TestDuration(t *testing.T) {
t
.
Errorf
(
"Expected 48000, got %v"
,
a
)
t
.
Errorf
(
"Expected 48000, got %v"
,
a
)
}
}
b
:=
ToDuration
(
48000
,
48000
)
b
:=
FromDuration
(
-
time
.
Second
,
48000
)
if
b
!=
time
.
Second
{
if
b
!=
-
48000
{
t
.
Errorf
(
"Expected %v, got %v"
,
time
.
Second
,
b
)
t
.
Errorf
(
"Expected -48000, got %v"
,
b
)
}
c
:=
ToDuration
(
48000
,
48000
)
if
c
!=
time
.
Second
{
t
.
Errorf
(
"Expected %v, got %v"
,
time
.
Second
,
c
)
}
d
:=
ToDuration
(
-
48000
,
48000
)
if
d
!=
-
time
.
Second
{
t
.
Errorf
(
"Expected %v, got %v"
,
-
time
.
Second
,
d
)
}
}
}
}
...
...
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