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
Hide 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 @@
...
@@ -26,17 +26,11 @@
#include "config/ConfigError.hxx"
#include "config/ConfigError.hxx"
#include "Log.hxx"
#include "Log.hxx"
#include "fs/AllocatedPath.hxx"
#include "fs/AllocatedPath.hxx"
#include "fs/
FileSyste
m.hxx"
#include "fs/
io/FileOutputStrea
m.hxx"
#include "util/Error.hxx"
#include "util/Error.hxx"
#include "util/Domain.hxx"
#include "util/Domain.hxx"
#include "system/fd_util.h"
#include "open.h"
#include <assert.h>
#include <assert.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <errno.h>
struct
RecorderOutput
{
struct
RecorderOutput
{
AudioOutput
base
;
AudioOutput
base
;
...
@@ -52,9 +46,9 @@ struct RecorderOutput {
...
@@ -52,9 +46,9 @@ struct RecorderOutput {
AllocatedPath
path
;
AllocatedPath
path
;
/**
/**
* The destination file
descriptor
.
* The destination file.
*/
*/
int
fd
;
FileOutputStream
*
file
;
/**
/**
* The buffer for encoder_read().
* The buffer for encoder_read().
...
@@ -76,8 +70,6 @@ struct RecorderOutput {
...
@@ -76,8 +70,6 @@ struct RecorderOutput {
bool
Open
(
AudioFormat
&
audio_format
,
Error
&
error
);
bool
Open
(
AudioFormat
&
audio_format
,
Error
&
error
);
void
Close
();
void
Close
();
bool
WriteToFile
(
const
void
*
data
,
size_t
length
,
Error
&
error
);
/**
/**
* Writes pending data from the encoder to the output file.
* Writes pending data from the encoder to the output file.
*/
*/
...
@@ -154,35 +146,10 @@ recorder_output_finish(AudioOutput *ao)
...
@@ -154,35 +146,10 @@ recorder_output_finish(AudioOutput *ao)
}
}
inline
bool
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
)
RecorderOutput
::
EncoderToFile
(
Error
&
error
)
{
{
assert
(
fd
>=
0
);
assert
(
file
!=
nullptr
);
assert
(
file
->
IsDefined
());
while
(
true
)
{
while
(
true
)
{
/* read from the encoder */
/* read from the encoder */
...
@@ -193,7 +160,7 @@ RecorderOutput::EncoderToFile(Error &error)
...
@@ -193,7 +160,7 @@ RecorderOutput::EncoderToFile(Error &error)
/* write everything into the file */
/* write everything into the file */
if
(
!
WriteToFil
e
(
buffer
,
size
,
error
))
if
(
!
file
->
Writ
e
(
buffer
,
size
,
error
))
return
false
;
return
false
;
}
}
}
}
...
@@ -203,26 +170,22 @@ RecorderOutput::Open(AudioFormat &audio_format, Error &error)
...
@@ -203,26 +170,22 @@ RecorderOutput::Open(AudioFormat &audio_format, Error &error)
{
{
/* create the output file */
/* create the output file */
fd
=
OpenFile
(
path
,
file
=
new
FileOutputStream
(
path
,
error
);
O_CREAT
|
O_WRONLY
|
O_TRUNC
|
O_BINARY
,
if
(
!
file
->
IsDefined
())
{
0666
);
delete
file
;
if
(
fd
<
0
)
{
error
.
FormatErrno
(
"Failed to create '%s'"
,
path
.
c_str
());
return
false
;
return
false
;
}
}
/* open the encoder */
/* open the encoder */
if
(
!
encoder_open
(
encoder
,
audio_format
,
error
))
{
if
(
!
encoder_open
(
encoder
,
audio_format
,
error
))
{
close
(
fd
);
delete
file
;
RemoveFile
(
path
);
return
false
;
return
false
;
}
}
if
(
!
EncoderToFile
(
error
))
{
if
(
!
EncoderToFile
(
error
))
{
encoder_close
(
encoder
);
encoder_close
(
encoder
);
close
(
fd
);
delete
file
;
RemoveFile
(
path
);
return
false
;
return
false
;
}
}
...
@@ -241,7 +204,10 @@ RecorderOutput::Commit(Error &error)
...
@@ -241,7 +204,10 @@ RecorderOutput::Commit(Error &error)
encoder_close
(
encoder
);
encoder_close
(
encoder
);
close
(
fd
);
if
(
success
&&
!
file
->
Commit
(
error
))
success
=
false
;
delete
file
;
return
success
;
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