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
1678a6eb
Commit
1678a6eb
authored
Mar 14, 2019
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test/run_filter: ensure that partial frames will not get passed to the filter
parent
b4dc2c07
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
50 additions
and
4 deletions
+50
-4
run_filter.cxx
test/run_filter.cxx
+50
-4
No files found.
test/run_filter.cxx
View file @
1678a6eb
...
...
@@ -27,6 +27,7 @@
#include "filter/Prepared.hxx"
#include "pcm/Volume.hxx"
#include "mixer/MixerControl.hxx"
#include "system/Error.hxx"
#include "util/ConstBuffer.hxx"
#include "util/StringBuffer.hxx"
#include "util/RuntimeError.hxx"
...
...
@@ -60,6 +61,50 @@ LoadFilter(const ConfigData &config, const char *name)
return
filter_configured_new
(
*
param
);
}
static
size_t
ReadOrThrow
(
int
fd
,
void
*
buffer
,
size_t
size
)
{
auto
nbytes
=
read
(
fd
,
buffer
,
size
);
if
(
nbytes
<
0
)
throw
MakeErrno
(
"Read failed"
);
return
nbytes
;
}
static
void
FullRead
(
int
fd
,
void
*
_buffer
,
size_t
size
)
{
auto
buffer
=
(
uint8_t
*
)
_buffer
;
while
(
size
>
0
)
{
size_t
nbytes
=
ReadOrThrow
(
fd
,
buffer
,
size
);
if
(
nbytes
==
0
)
throw
std
::
runtime_error
(
"Premature end of input"
);
buffer
+=
nbytes
;
size
-=
nbytes
;
}
}
static
size_t
ReadFrames
(
int
fd
,
void
*
_buffer
,
size_t
size
,
size_t
frame_size
)
{
auto
buffer
=
(
uint8_t
*
)
_buffer
;
size
=
(
size
/
frame_size
)
*
frame_size
;
size_t
nbytes
=
ReadOrThrow
(
fd
,
buffer
,
size
);
const
size_t
modulo
=
nbytes
%
frame_size
;
if
(
modulo
>
0
)
{
size_t
rest
=
frame_size
-
modulo
;
FullRead
(
fd
,
buffer
+
nbytes
,
rest
);
nbytes
+=
rest
;
}
return
nbytes
;
}
int
main
(
int
argc
,
char
**
argv
)
try
{
if
(
argc
<
3
||
argc
>
4
)
{
...
...
@@ -80,6 +125,8 @@ try {
if
(
argc
>
3
)
audio_format
=
ParseAudioFormat
(
argv
[
3
],
false
);
const
size_t
in_frame_size
=
audio_format
.
GetFrameSize
();
/* initialize the filter */
auto
prepared_filter
=
LoadFilter
(
config
,
argv
[
2
]);
...
...
@@ -98,10 +145,9 @@ try {
while
(
true
)
{
char
buffer
[
4096
];
ssize_t
nbytes
;
nbytes
=
read
(
0
,
buffer
,
sizeof
(
buffer
));
if
(
nbytes
<=
0
)
ssize_t
nbytes
=
ReadFrames
(
0
,
buffer
,
sizeof
(
buffer
),
in_frame_size
);
if
(
nbytes
==
0
)
break
;
auto
dest
=
filter
->
FilterPCM
({(
const
void
*
)
buffer
,
(
size_t
)
nbytes
});
...
...
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