Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
71e7d32b
Commit
71e7d32b
authored
Dec 28, 2016
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
output/Timer: use std::chrono
parent
d5e42297
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
22 additions
and
18 deletions
+22
-18
Timer.cxx
src/output/Timer.cxx
+8
-10
Timer.hxx
src/output/Timer.hxx
+11
-5
FifoOutputPlugin.cxx
src/output/plugins/FifoOutputPlugin.cxx
+1
-1
NullOutputPlugin.cxx
src/output/plugins/NullOutputPlugin.cxx
+1
-1
HttpdOutputPlugin.cxx
src/output/plugins/httpd/HttpdOutputPlugin.cxx
+1
-1
No files found.
src/output/Timer.cxx
View file @
71e7d32b
...
...
@@ -33,7 +33,7 @@ Timer::Timer(const AudioFormat af)
void
Timer
::
Start
()
{
time
=
MonotonicClockUS
();
time
=
Now
();
started
=
true
;
}
...
...
@@ -49,19 +49,17 @@ Timer::Add(size_t size)
// (size samples) / (rate samples per second) = duration seconds
// duration seconds * 1000000 = duration us
time
+=
((
uint64_t
)
size
*
1000000
)
/
rate
;
time
+=
Time
(((
uint64_t
)
size
*
Time
::
period
::
den
)
/
(
Time
::
period
::
num
*
rate
))
;
}
unsigned
Timer
::
GetDelay
()
const
std
::
chrono
::
steady_clock
::
duration
Timer
::
GetDelay
()
const
{
assert
(
started
);
int64_t
delay
=
(
int64_t
)(
time
-
MonotonicClockUS
())
/
1000
;
if
(
delay
<
0
)
return
0
;
const
auto
delay
=
time
-
Now
()
;
if
(
delay
<
Time
::
zero
()
)
return
Time
::
zero
()
;
if
(
delay
>
std
::
numeric_limits
<
int
>::
max
())
delay
=
std
::
numeric_limits
<
int
>::
max
();
return
delay
;
return
std
::
chrono
::
duration_cast
<
std
::
chrono
::
steady_clock
::
duration
>
(
delay
);
}
src/output/Timer.hxx
View file @
71e7d32b
...
...
@@ -20,13 +20,14 @@
#ifndef MPD_TIMER_HXX
#define MPD_TIMER_HXX
#include <stdint.h>
#include <stddef.h>
#include <chrono>
struct
AudioFormat
;
class
Timer
{
uint64_t
time
;
typedef
std
::
chrono
::
microseconds
Time
;
Time
time
;
bool
started
=
false
;
const
int
rate
;
public
:
...
...
@@ -40,9 +41,14 @@ public:
void
Add
(
size_t
size
);
/**
* Returns the
number of milliseconds
to sleep to get back to sync.
* Returns the
duration
to sleep to get back to sync.
*/
unsigned
GetDelay
()
const
;
std
::
chrono
::
steady_clock
::
duration
GetDelay
()
const
;
private
:
static
Time
Now
()
{
return
std
::
chrono
::
duration_cast
<
Time
>
(
std
::
chrono
::
steady_clock
::
now
().
time_since_epoch
());
}
};
#endif
src/output/plugins/FifoOutputPlugin.cxx
View file @
71e7d32b
...
...
@@ -208,7 +208,7 @@ inline std::chrono::steady_clock::duration
FifoOutput
::
Delay
()
const
{
return
timer
->
IsStarted
()
?
std
::
chrono
::
milliseconds
(
timer
->
GetDelay
()
)
?
timer
->
GetDelay
(
)
:
std
::
chrono
::
steady_clock
::
duration
::
zero
();
}
...
...
src/output/plugins/NullOutputPlugin.cxx
View file @
71e7d32b
...
...
@@ -51,7 +51,7 @@ public:
std
::
chrono
::
steady_clock
::
duration
Delay
()
const
{
return
sync
&&
timer
->
IsStarted
()
?
std
::
chrono
::
milliseconds
(
timer
->
GetDelay
()
)
?
timer
->
GetDelay
(
)
:
std
::
chrono
::
steady_clock
::
duration
::
zero
();
}
...
...
src/output/plugins/httpd/HttpdOutputPlugin.cxx
View file @
71e7d32b
...
...
@@ -361,7 +361,7 @@ HttpdOutput::Delay() const
}
return
timer
->
IsStarted
()
?
std
::
chrono
::
milliseconds
(
timer
->
GetDelay
()
)
?
timer
->
GetDelay
(
)
:
std
::
chrono
::
steady_clock
::
duration
::
zero
();
}
...
...
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