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
291be847
Commit
291be847
authored
Sep 07, 2020
by
Max Kellermann
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'v0.21.x' into master
parents
67c7116f
962cf32b
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
42 additions
and
48 deletions
+42
-48
FileDescriptor.cxx
src/io/FileDescriptor.cxx
+18
-0
FileDescriptor.hxx
src/io/FileDescriptor.hxx
+6
-0
dump_playlist.cxx
test/dump_playlist.cxx
+3
-3
run_filter.cxx
test/run_filter.cxx
+2
-30
run_input.cxx
test/run_input.cxx
+13
-15
No files found.
src/io/FileDescriptor.cxx
View file @
291be847
...
...
@@ -306,6 +306,24 @@ FileDescriptor::FullRead(void *_buffer, size_t length)
}
}
void
FileDescriptor
::
FullWrite
(
const
void
*
_buffer
,
size_t
length
)
{
const
uint8_t
*
buffer
=
(
const
uint8_t
*
)
_buffer
;
while
(
length
>
0
)
{
ssize_t
nbytes
=
Write
(
buffer
,
length
);
if
(
nbytes
<=
0
)
{
if
(
nbytes
<
0
)
throw
MakeErrno
(
"Failed to write"
);
throw
std
::
runtime_error
(
"Failed to write"
);
}
buffer
+=
nbytes
;
length
-=
nbytes
;
}
}
#ifndef _WIN32
int
...
...
src/io/FileDescriptor.hxx
View file @
291be847
...
...
@@ -243,6 +243,12 @@ public:
return
::
write
(
fd
,
buffer
,
length
);
}
/**
* Write until all of the given buffer has been written.
* Throws on error.
*/
void
FullWrite
(
const
void
*
buffer
,
size_t
length
);
#ifndef _WIN32
int
Poll
(
short
events
,
int
timeout
)
const
noexcept
;
...
...
test/dump_playlist.cxx
View file @
291be847
...
...
@@ -41,9 +41,9 @@ static void
tag_save
(
FILE
*
file
,
const
Tag
&
tag
)
{
StdioOutputStream
sos
(
file
);
BufferedOutputStream
bos
(
sos
);
tag_save
(
bos
,
tag
);
bos
.
Flush
(
);
WithBufferedOutputStream
(
sos
,
[
&
](
auto
&
bos
){
tag_save
(
bos
,
tag
);
}
);
}
int
main
(
int
argc
,
char
**
argv
)
...
...
test/run_filter.cxx
View file @
291be847
...
...
@@ -71,34 +71,6 @@ ReadOrThrow(FileDescriptor fd, void *buffer, size_t size)
}
static
size_t
WriteOrThrow
(
FileDescriptor
fd
,
const
void
*
buffer
,
size_t
size
)
{
auto
nbytes
=
fd
.
Write
(
buffer
,
size
);
if
(
nbytes
<
0
)
throw
MakeErrno
(
"Write failed"
);
return
nbytes
;
}
static
void
FullWrite
(
FileDescriptor
fd
,
ConstBuffer
<
uint8_t
>
src
)
{
while
(
!
src
.
empty
())
{
size_t
nbytes
=
WriteOrThrow
(
fd
,
src
.
data
,
src
.
size
);
if
(
nbytes
==
0
)
throw
std
::
runtime_error
(
"Write failed"
);
src
.
skip_front
(
nbytes
);
}
}
static
void
FullWrite
(
FileDescriptor
fd
,
ConstBuffer
<
void
>
src
)
{
FullWrite
(
fd
,
ConstBuffer
<
uint8_t
>::
FromVoid
(
src
));
}
static
size_t
ReadFrames
(
FileDescriptor
fd
,
void
*
_buffer
,
size_t
size
,
size_t
frame_size
)
{
auto
buffer
=
(
uint8_t
*
)
_buffer
;
...
...
@@ -166,14 +138,14 @@ try {
break
;
auto
dest
=
filter
->
FilterPCM
({(
const
void
*
)
buffer
,
(
size_t
)
nbytes
});
FullWrite
(
output_fd
,
dest
);
output_fd
.
FullWrite
(
dest
.
data
,
dest
.
size
);
}
while
(
true
)
{
auto
dest
=
filter
->
Flush
();
if
(
dest
.
IsNull
())
break
;
FullWrite
(
output_fd
,
dest
);
output_fd
.
FullWrite
(
dest
.
data
,
dest
.
size
);
}
/* cleanup and exit */
...
...
test/run_input.cxx
View file @
291be847
...
...
@@ -124,26 +124,26 @@ static void
tag_save
(
FILE
*
file
,
const
Tag
&
tag
)
{
StdioOutputStream
sos
(
file
);
BufferedOutputStream
bos
(
sos
);
tag_save
(
bos
,
tag
);
bos
.
Flush
(
);
WithBufferedOutputStream
(
sos
,
[
&
](
auto
&
bos
){
tag_save
(
bos
,
tag
);
}
);
}
static
int
dump_input_stream
(
InputStream
*
is
)
dump_input_stream
(
InputStream
&
is
,
FileDescriptor
out
)
{
std
::
unique_lock
<
Mutex
>
lock
(
is
->
mutex
);
std
::
unique_lock
<
Mutex
>
lock
(
is
.
mutex
);
/* print meta data */
if
(
is
->
HasMimeType
())
fprintf
(
stderr
,
"MIME type: %s
\n
"
,
is
->
GetMimeType
());
if
(
is
.
HasMimeType
())
fprintf
(
stderr
,
"MIME type: %s
\n
"
,
is
.
GetMimeType
());
/* read data and tags from the stream */
while
(
!
is
->
IsEOF
())
{
while
(
!
is
.
IsEOF
())
{
{
auto
tag
=
is
->
ReadTag
();
auto
tag
=
is
.
ReadTag
();
if
(
tag
)
{
fprintf
(
stderr
,
"Received a tag:
\n
"
);
tag_save
(
stderr
,
*
tag
);
...
...
@@ -151,16 +151,14 @@ dump_input_stream(InputStream *is)
}
char
buffer
[
4096
];
size_t
num_read
=
is
->
Read
(
lock
,
buffer
,
sizeof
(
buffer
));
size_t
num_read
=
is
.
Read
(
lock
,
buffer
,
sizeof
(
buffer
));
if
(
num_read
==
0
)
break
;
ssize_t
num_written
=
write
(
1
,
buffer
,
num_read
);
if
(
num_written
<=
0
)
break
;
out
.
FullWrite
(
buffer
,
num_read
);
}
is
->
Check
();
is
.
Check
();
return
0
;
}
...
...
@@ -233,7 +231,7 @@ try {
Mutex
mutex
;
auto
is
=
InputStream
::
OpenReady
(
c
.
uri
,
mutex
);
return
dump_input_stream
(
is
.
get
(
));
return
dump_input_stream
(
*
is
,
FileDescriptor
(
STDOUT_FILENO
));
}
catch
(...)
{
PrintException
(
std
::
current_exception
());
return
EXIT_FAILURE
;
...
...
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