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
eff50b26
Commit
eff50b26
authored
Mar 08, 2021
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test/run_output: use class StaticFifoBuffer
parent
2bebc793
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
15 deletions
+21
-15
run_output.cxx
test/run_output.cxx
+21
-15
No files found.
test/run_output.cxx
View file @
eff50b26
...
...
@@ -31,6 +31,7 @@
#include "util/StringBuffer.hxx"
#include "util/RuntimeError.hxx"
#include "util/ScopeExit.hxx"
#include "util/StaticFifoBuffer.hxx"
#include "util/PrintException.hxx"
#include "LogBackend.hxx"
...
...
@@ -127,32 +128,37 @@ RunOutput(AudioOutput &ao, AudioFormat audio_format,
fprintf
(
stderr
,
"audio_format=%s
\n
"
,
ToString
(
audio_format
).
c_str
());
size_t
frame_size
=
audio_format
.
GetFrameSize
();
const
size_t
in_
frame_size
=
audio_format
.
GetFrameSize
();
/* play */
size_t
length
=
0
;
char
buffer
[
4096
];
StaticFifoBuffer
<
std
::
byte
,
4096
>
buffer
;
while
(
true
)
{
if
(
length
<
sizeof
(
buffer
))
{
ssize_t
nbytes
=
in_fd
.
Read
(
buffer
+
length
,
sizeof
(
buffer
)
-
length
);
{
const
auto
dest
=
buffer
.
Write
();
assert
(
!
dest
.
empty
());
ssize_t
nbytes
=
in_fd
.
Read
(
dest
.
data
,
dest
.
size
);
if
(
nbytes
<=
0
)
break
;
length
+=
(
size_t
)
nbytes
;
buffer
.
Append
(
nbytes
)
;
}
size_t
play_length
=
(
length
/
frame_size
)
*
frame_size
;
if
(
play_length
>
0
)
{
size_t
consumed
=
ao
.
Play
(
buffer
,
play_length
);
auto
src
=
buffer
.
Read
();
assert
(
!
src
.
empty
());
assert
(
consumed
<=
length
);
assert
(
consumed
%
frame_size
==
0
);
src
.
size
-=
src
.
size
%
in_frame_size
;
if
(
src
.
empty
())
continue
;
length
-=
consumed
;
memmove
(
buffer
,
buffer
+
consumed
,
length
);
}
size_t
consumed
=
ao
.
Play
(
src
.
data
,
src
.
size
);
assert
(
consumed
<=
src
.
size
);
assert
(
consumed
%
in_frame_size
==
0
);
buffer
.
Consume
(
consumed
);
}
}
...
...
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