MusicChunk: return WritableBuffer
This commit is contained in:
parent
5ee5a89a7f
commit
de1261ba28
@ -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 */
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user