output/recorder: move functions into the struct
This commit is contained in:
parent
2983c2a24f
commit
a31129333c
|
@ -66,6 +66,9 @@ struct RecorderOutput {
|
||||||
|
|
||||||
bool Configure(const config_param ¶m, Error &error);
|
bool Configure(const config_param ¶m, Error &error);
|
||||||
|
|
||||||
|
bool Open(AudioFormat &audio_format, Error &error);
|
||||||
|
void Close();
|
||||||
|
|
||||||
bool WriteToFile(const void *data, size_t length, Error &error);
|
bool WriteToFile(const void *data, size_t length, Error &error);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -176,56 +179,68 @@ RecorderOutput::EncoderToFile(Error &error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
inline bool
|
||||||
recorder_output_open(AudioOutput *ao,
|
RecorderOutput::Open(AudioFormat &audio_format, Error &error)
|
||||||
AudioFormat &audio_format,
|
|
||||||
Error &error)
|
|
||||||
{
|
{
|
||||||
RecorderOutput *recorder = (RecorderOutput *)ao;
|
|
||||||
|
|
||||||
/* create the output file */
|
/* create the output file */
|
||||||
|
|
||||||
recorder->fd = open_cloexec(recorder->path,
|
fd = open_cloexec(path,
|
||||||
O_CREAT|O_WRONLY|O_TRUNC|O_BINARY,
|
O_CREAT|O_WRONLY|O_TRUNC|O_BINARY,
|
||||||
0666);
|
0666);
|
||||||
if (recorder->fd < 0) {
|
if (fd < 0) {
|
||||||
error.FormatErrno("Failed to create '%s'", recorder->path);
|
error.FormatErrno("Failed to create '%s'", path);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* open the encoder */
|
/* open the encoder */
|
||||||
|
|
||||||
if (!encoder_open(recorder->encoder, audio_format, error)) {
|
if (!encoder_open(encoder, audio_format, error)) {
|
||||||
close(recorder->fd);
|
close(fd);
|
||||||
unlink(recorder->path);
|
unlink(path);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!recorder->EncoderToFile(error)) {
|
if (!EncoderToFile(error)) {
|
||||||
encoder_close(recorder->encoder);
|
encoder_close(encoder);
|
||||||
close(recorder->fd);
|
close(fd);
|
||||||
unlink(recorder->path);
|
unlink(path);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static bool
|
||||||
recorder_output_close(AudioOutput *ao)
|
recorder_output_open(AudioOutput *ao,
|
||||||
|
AudioFormat &audio_format,
|
||||||
|
Error &error)
|
||||||
{
|
{
|
||||||
RecorderOutput *recorder = (RecorderOutput *)ao;
|
RecorderOutput &recorder = *(RecorderOutput *)ao;
|
||||||
|
|
||||||
|
return recorder.Open(audio_format, error);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void
|
||||||
|
RecorderOutput::Close()
|
||||||
|
{
|
||||||
/* flush the encoder and write the rest to the file */
|
/* flush the encoder and write the rest to the file */
|
||||||
|
|
||||||
if (encoder_end(recorder->encoder, IgnoreError()))
|
if (encoder_end(encoder, IgnoreError()))
|
||||||
recorder->EncoderToFile(IgnoreError());
|
EncoderToFile(IgnoreError());
|
||||||
|
|
||||||
/* now really close everything */
|
/* now really close everything */
|
||||||
|
|
||||||
encoder_close(recorder->encoder);
|
encoder_close(encoder);
|
||||||
|
|
||||||
close(recorder->fd);
|
close(fd);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
recorder_output_close(AudioOutput *ao)
|
||||||
|
{
|
||||||
|
RecorderOutput &recorder = *(RecorderOutput *)ao;
|
||||||
|
|
||||||
|
recorder.Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
static size_t
|
static size_t
|
||||||
|
|
Loading…
Reference in New Issue