aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2014-12-26 14:57:29 +0100
committerMax Kellermann <max@duempel.org>2014-12-26 14:57:29 +0100
commita31129333c9a6d702738cfd06d75f970179a3598 (patch)
tree4cdfdf4b11011416cdf9f36f726d7413df41afcb /src
parent2983c2a24f9c06a7ce5bd7ece004e0c245740c2b (diff)
downloadmpd-a31129333c9a6d702738cfd06d75f970179a3598.tar.gz
mpd-a31129333c9a6d702738cfd06d75f970179a3598.tar.xz
mpd-a31129333c9a6d702738cfd06d75f970179a3598.zip
output/recorder: move functions into the struct
Diffstat (limited to '')
-rw-r--r--src/output/plugins/RecorderOutputPlugin.cxx65
1 files changed, 40 insertions, 25 deletions
diff --git a/src/output/plugins/RecorderOutputPlugin.cxx b/src/output/plugins/RecorderOutputPlugin.cxx
index 87e23f55a..e0ef569d0 100644
--- a/src/output/plugins/RecorderOutputPlugin.cxx
+++ b/src/output/plugins/RecorderOutputPlugin.cxx
@@ -66,6 +66,9 @@ struct RecorderOutput {
bool Configure(const config_param &param, Error &error);
+ bool Open(AudioFormat &audio_format, Error &error);
+ void Close();
+
bool WriteToFile(const void *data, size_t length, Error &error);
/**
@@ -176,56 +179,68 @@ RecorderOutput::EncoderToFile(Error &error)
}
}
-static bool
-recorder_output_open(AudioOutput *ao,
- AudioFormat &audio_format,
- Error &error)
+inline bool
+RecorderOutput::Open(AudioFormat &audio_format, Error &error)
{
- RecorderOutput *recorder = (RecorderOutput *)ao;
-
/* create the output file */
- recorder->fd = open_cloexec(recorder->path,
- O_CREAT|O_WRONLY|O_TRUNC|O_BINARY,
- 0666);
- if (recorder->fd < 0) {
- error.FormatErrno("Failed to create '%s'", recorder->path);
+ fd = open_cloexec(path,
+ O_CREAT|O_WRONLY|O_TRUNC|O_BINARY,
+ 0666);
+ if (fd < 0) {
+ error.FormatErrno("Failed to create '%s'", path);
return false;
}
/* open the encoder */
- if (!encoder_open(recorder->encoder, audio_format, error)) {
- close(recorder->fd);
- unlink(recorder->path);
+ if (!encoder_open(encoder, audio_format, error)) {
+ close(fd);
+ unlink(path);
return false;
}
- if (!recorder->EncoderToFile(error)) {
- encoder_close(recorder->encoder);
- close(recorder->fd);
- unlink(recorder->path);
+ if (!EncoderToFile(error)) {
+ encoder_close(encoder);
+ close(fd);
+ unlink(path);
return false;
}
return true;
}
-static void
-recorder_output_close(AudioOutput *ao)
+static bool
+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 */
- if (encoder_end(recorder->encoder, IgnoreError()))
- recorder->EncoderToFile(IgnoreError());
+ if (encoder_end(encoder, IgnoreError()))
+ EncoderToFile(IgnoreError());
/* now really close everything */
- encoder_close(recorder->encoder);
+ encoder_close(encoder);
+
+ close(fd);
+}
+
+static void
+recorder_output_close(AudioOutput *ao)
+{
+ RecorderOutput &recorder = *(RecorderOutput *)ao;
- close(recorder->fd);
+ recorder.Close();
}
static size_t