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
cd1ac8a8
Commit
cd1ac8a8
authored
Apr 30, 2021
by
Juliusz Chroboczek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Document rtptime.
parent
6c752b58
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
1 deletion
+13
-1
rtptime/rtptime.go
rtptime/rtptime.go
+13
-1
No files found.
rtptime/rtptime.go
View file @
cd1ac8a8
// Package rtptime manipulates RTP and NTP time
package
rtptime
package
rtptime
import
(
import
(
"time"
"time"
)
)
// epoch is the origin of NTP time
var
epoch
=
time
.
Now
()
var
epoch
=
time
.
Now
()
// FromDuration converts a time.Duration into units of 1/hz.
func
FromDuration
(
d
time
.
Duration
,
hz
uint32
)
uint64
{
func
FromDuration
(
d
time
.
Duration
,
hz
uint32
)
uint64
{
return
uint64
(
d
)
*
uint64
(
hz
)
/
uint64
(
time
.
Second
)
return
uint64
(
d
)
*
uint64
(
hz
)
/
uint64
(
time
.
Second
)
}
}
// ToDuration converts units of 1/hz into a time.Duration.
func
ToDuration
(
tm
uint64
,
hz
uint32
)
time
.
Duration
{
func
ToDuration
(
tm
uint64
,
hz
uint32
)
time
.
Duration
{
return
time
.
Duration
(
tm
*
uint64
(
time
.
Second
)
/
uint64
(
hz
))
return
time
.
Duration
(
tm
*
uint64
(
time
.
Second
)
/
uint64
(
hz
))
}
}
// 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
FromDuration
(
time
.
Since
(
epoch
),
hz
)
}
}
// Microseconds is like Now, but uses microseconds.
func
Microseconds
()
uint64
{
func
Microseconds
()
uint64
{
return
Now
(
1000000
)
return
Now
(
1000000
)
}
}
// JiffiesPerSec is the LCM of 48000, 96000 and 65536
// JiffiesPerSec is the number of jiffies in a second. This is the LCM of
// 48000, 96000 and 65536.
const
JiffiesPerSec
=
24576000
const
JiffiesPerSec
=
24576000
// Jiffies returns the current time in jiffies.
func
Jiffies
()
uint64
{
func
Jiffies
()
uint64
{
return
Now
(
JiffiesPerSec
)
return
Now
(
JiffiesPerSec
)
}
}
// 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
FromDuration
(
tm
.
Sub
(
epoch
),
JiffiesPerSec
)
}
}
// The origin of NTP time.
var
ntpEpoch
=
time
.
Date
(
1900
,
1
,
1
,
0
,
0
,
0
,
0
,
time
.
UTC
)
var
ntpEpoch
=
time
.
Date
(
1900
,
1
,
1
,
0
,
0
,
0
,
0
,
time
.
UTC
)
// NTPToTime converts an NTP time into a time.Time.
func
NTPToTime
(
ntp
uint64
)
time
.
Time
{
func
NTPToTime
(
ntp
uint64
)
time
.
Time
{
sec
:=
uint32
(
ntp
>>
32
)
sec
:=
uint32
(
ntp
>>
32
)
frac
:=
uint32
(
ntp
&
0xFFFFFFFF
)
frac
:=
uint32
(
ntp
&
0xFFFFFFFF
)
...
@@ -44,6 +55,7 @@ func NTPToTime(ntp uint64) time.Time {
...
@@ -44,6 +55,7 @@ func NTPToTime(ntp uint64) time.Time {
)
)
}
}
// TimeToNTP converts a time.Time into an NTP time.
func
TimeToNTP
(
tm
time
.
Time
)
uint64
{
func
TimeToNTP
(
tm
time
.
Time
)
uint64
{
d
:=
tm
.
Sub
(
ntpEpoch
)
d
:=
tm
.
Sub
(
ntpEpoch
)
sec
:=
uint32
(
d
/
time
.
Second
)
sec
:=
uint32
(
d
/
time
.
Second
)
...
...
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