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
b7acf864
Commit
b7acf864
authored
Jan 07, 2015
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
output/recorder: use FileOutputStream
parent
58c4db92
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
49 deletions
+15
-49
RecorderOutputPlugin.cxx
src/output/plugins/RecorderOutputPlugin.cxx
+15
-49
No files found.
src/output/plugins/RecorderOutputPlugin.cxx
View file @
b7acf864
...
...
@@ -26,17 +26,11 @@
#include "config/ConfigError.hxx"
#include "Log.hxx"
#include "fs/AllocatedPath.hxx"
#include "fs/
FileSyste
m.hxx"
#include "fs/
io/FileOutputStrea
m.hxx"
#include "util/Error.hxx"
#include "util/Domain.hxx"
#include "system/fd_util.h"
#include "open.h"
#include <assert.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <errno.h>
struct
RecorderOutput
{
AudioOutput
base
;
...
...
@@ -52,9 +46,9 @@ struct RecorderOutput {
AllocatedPath
path
;
/**
* The destination file
descriptor
.
* The destination file.
*/
int
fd
;
FileOutputStream
*
file
;
/**
* The buffer for encoder_read().
...
...
@@ -76,8 +70,6 @@ struct RecorderOutput {
bool
Open
(
AudioFormat
&
audio_format
,
Error
&
error
);
void
Close
();
bool
WriteToFile
(
const
void
*
data
,
size_t
length
,
Error
&
error
);
/**
* Writes pending data from the encoder to the output file.
*/
...
...
@@ -154,35 +146,10 @@ recorder_output_finish(AudioOutput *ao)
}
inline
bool
RecorderOutput
::
WriteToFile
(
const
void
*
_data
,
size_t
length
,
Error
&
error
)
{
assert
(
length
>
0
);
const
uint8_t
*
data
=
(
const
uint8_t
*
)
_data
,
*
end
=
data
+
length
;
while
(
true
)
{
ssize_t
nbytes
=
write
(
fd
,
data
,
end
-
data
);
if
(
nbytes
>
0
)
{
data
+=
nbytes
;
if
(
data
==
end
)
return
true
;
}
else
if
(
nbytes
==
0
)
{
/* shouldn't happen for files */
error
.
Set
(
recorder_output_domain
,
"write() returned 0"
);
return
false
;
}
else
if
(
errno
!=
EINTR
)
{
error
.
FormatErrno
(
"Failed to write to '%s'"
,
path
.
c_str
());
return
false
;
}
}
}
inline
bool
RecorderOutput
::
EncoderToFile
(
Error
&
error
)
{
assert
(
fd
>=
0
);
assert
(
file
!=
nullptr
);
assert
(
file
->
IsDefined
());
while
(
true
)
{
/* read from the encoder */
...
...
@@ -193,7 +160,7 @@ RecorderOutput::EncoderToFile(Error &error)
/* write everything into the file */
if
(
!
WriteToFil
e
(
buffer
,
size
,
error
))
if
(
!
file
->
Writ
e
(
buffer
,
size
,
error
))
return
false
;
}
}
...
...
@@ -203,26 +170,22 @@ RecorderOutput::Open(AudioFormat &audio_format, Error &error)
{
/* create the output file */
fd
=
OpenFile
(
path
,
O_CREAT
|
O_WRONLY
|
O_TRUNC
|
O_BINARY
,
0666
);
if
(
fd
<
0
)
{
error
.
FormatErrno
(
"Failed to create '%s'"
,
path
.
c_str
());
file
=
new
FileOutputStream
(
path
,
error
);
if
(
!
file
->
IsDefined
())
{
delete
file
;
return
false
;
}
/* open the encoder */
if
(
!
encoder_open
(
encoder
,
audio_format
,
error
))
{
close
(
fd
);
RemoveFile
(
path
);
delete
file
;
return
false
;
}
if
(
!
EncoderToFile
(
error
))
{
encoder_close
(
encoder
);
close
(
fd
);
RemoveFile
(
path
);
delete
file
;
return
false
;
}
...
...
@@ -241,7 +204,10 @@ RecorderOutput::Commit(Error &error)
encoder_close
(
encoder
);
close
(
fd
);
if
(
success
&&
!
file
->
Commit
(
error
))
success
=
false
;
delete
file
;
return
success
;
}
...
...
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