aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2012-10-01 23:59:50 +0200
committerMax Kellermann <max@duempel.org>2012-10-02 00:26:40 +0200
commit58e600f408bed5cfdc9b3cebded108a8593e5b7b (patch)
treeff7a4603a566362a21fe9fcfecd8bc7fb68b21da
parentd34e55c370db54ace2543d9801d360dae8e7c494 (diff)
downloadmpd-58e600f408bed5cfdc9b3cebded108a8593e5b7b.tar.gz
mpd-58e600f408bed5cfdc9b3cebded108a8593e5b7b.tar.xz
mpd-58e600f408bed5cfdc9b3cebded108a8593e5b7b.zip
output/recorder: move code to _write_to_file()
Diffstat (limited to '')
-rw-r--r--src/output/recorder_output_plugin.c50
1 files changed, 31 insertions, 19 deletions
diff --git a/src/output/recorder_output_plugin.c b/src/output/recorder_output_plugin.c
index e2366bf90..ac4a52107 100644
--- a/src/output/recorder_output_plugin.c
+++ b/src/output/recorder_output_plugin.c
@@ -120,32 +120,22 @@ recorder_output_finish(struct audio_output *ao)
g_free(recorder);
}
-/**
- * Writes pending data from the encoder to the output file.
- */
static bool
-recorder_output_encoder_to_file(struct recorder_output *recorder,
- GError **error_r)
+recorder_write_to_file(struct recorder_output *recorder,
+ const void *_data, size_t length,
+ GError **error_r)
{
- assert(recorder->fd >= 0);
+ assert(length > 0);
- /* read from the encoder */
+ const int fd = recorder->fd;
- size_t size = encoder_read(recorder->encoder, recorder->buffer,
- sizeof(recorder->buffer));
- if (size == 0)
- return true;
-
- /* write everything into the file */
+ const uint8_t *data = (const uint8_t *)_data, *end = data + length;
- size_t position = 0;
while (true) {
- ssize_t nbytes = write(recorder->fd,
- recorder->buffer + position,
- size - position);
+ ssize_t nbytes = write(fd, data, end - data);
if (nbytes > 0) {
- position += (size_t)nbytes;
- if (position >= size)
+ data += nbytes;
+ if (data == end)
return true;
} else if (nbytes == 0) {
/* shouldn't happen for files */
@@ -161,6 +151,28 @@ recorder_output_encoder_to_file(struct recorder_output *recorder,
}
}
+/**
+ * Writes pending data from the encoder to the output file.
+ */
+static bool
+recorder_output_encoder_to_file(struct recorder_output *recorder,
+ GError **error_r)
+{
+ assert(recorder->fd >= 0);
+
+ /* read from the encoder */
+
+ size_t size = encoder_read(recorder->encoder, recorder->buffer,
+ sizeof(recorder->buffer));
+ if (size == 0)
+ return true;
+
+ /* write everything into the file */
+
+ return recorder_write_to_file(recorder, recorder->buffer, size,
+ error_r);
+}
+
static bool
recorder_output_open(struct audio_output *ao,
struct audio_format *audio_format,