aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/DecoderAPI.cxx15
-rw-r--r--src/MusicChunk.cxx10
-rw-r--r--src/MusicChunk.hxx6
3 files changed, 15 insertions, 16 deletions
diff --git a/src/DecoderAPI.cxx b/src/DecoderAPI.cxx
index eede7c903..aaa8bb17f 100644
--- a/src/DecoderAPI.cxx
+++ b/src/DecoderAPI.cxx
@@ -406,7 +406,6 @@ decoder_data(Decoder &decoder,
while (length > 0) {
struct music_chunk *chunk;
- size_t nbytes;
bool full;
chunk = decoder_get_chunk(decoder);
@@ -415,17 +414,19 @@ decoder_data(Decoder &decoder,
return dc.command;
}
- void *dest = chunk->Write(dc.out_audio_format,
- decoder.timestamp -
- dc.song->start_ms / 1000.0,
- kbit_rate, &nbytes);
- if (dest == nullptr) {
+ const auto dest =
+ chunk->Write(dc.out_audio_format,
+ decoder.timestamp -
+ dc.song->start_ms / 1000.0,
+ kbit_rate);
+ if (dest.IsNull()) {
/* the chunk is full, flush it */
decoder_flush_chunk(decoder);
dc.client_cond.signal();
continue;
}
+ size_t nbytes = dest.size;
assert(nbytes > 0);
if (nbytes > length)
@@ -433,7 +434,7 @@ decoder_data(Decoder &decoder,
/* copy the buffer */
- memcpy(dest, data, nbytes);
+ memcpy(dest.data, data, nbytes);
/* expand the music pipe chunk */
diff --git a/src/MusicChunk.cxx b/src/MusicChunk.cxx
index 1d6081a9e..2d20ac7ac 100644
--- a/src/MusicChunk.cxx
+++ b/src/MusicChunk.cxx
@@ -39,10 +39,9 @@ music_chunk::CheckFormat(const AudioFormat other_format) const
}
#endif
-void *
+WritableBuffer<void>
music_chunk::Write(const AudioFormat af,
- float data_time, uint16_t _bit_rate,
- size_t *max_length_r)
+ float data_time, uint16_t _bit_rate)
{
assert(CheckFormat(af));
assert(length == 0 || audio_format.IsValid());
@@ -58,14 +57,13 @@ music_chunk::Write(const AudioFormat af,
const size_t frame_size = af.GetFrameSize();
size_t num_frames = (sizeof(data) - length) / frame_size;
if (num_frames == 0)
- return nullptr;
+ return WritableBuffer<void>::Null();
#ifndef NDEBUG
audio_format = af;
#endif
- *max_length_r = num_frames * frame_size;
- return data + length;
+ return { data + length, num_frames * frame_size };
}
bool
diff --git a/src/MusicChunk.hxx b/src/MusicChunk.hxx
index 96db5a699..ecd57090b 100644
--- a/src/MusicChunk.hxx
+++ b/src/MusicChunk.hxx
@@ -21,6 +21,7 @@
#define MPD_MUSIC_CHUNK_HXX
#include "ReplayGainInfo.hxx"
+#include "util/WritableBuffer.hxx"
#ifndef NDEBUG
#include "AudioFormat.hxx"
@@ -126,9 +127,8 @@ struct music_chunk {
* here
* @return a writable buffer, or nullptr if the chunk is full
*/
- void *Write(AudioFormat af,
- float data_time, uint16_t bit_rate,
- size_t *max_length_r);
+ WritableBuffer<void> Write(AudioFormat af,
+ float data_time, uint16_t bit_rate);
/**
* Increases the length of the chunk after the caller has written to