MusicChunk: return WritableBuffer
This commit is contained in:
parent
5ee5a89a7f
commit
de1261ba28
@ -406,7 +406,6 @@ decoder_data(Decoder &decoder,
|
|||||||
|
|
||||||
while (length > 0) {
|
while (length > 0) {
|
||||||
struct music_chunk *chunk;
|
struct music_chunk *chunk;
|
||||||
size_t nbytes;
|
|
||||||
bool full;
|
bool full;
|
||||||
|
|
||||||
chunk = decoder_get_chunk(decoder);
|
chunk = decoder_get_chunk(decoder);
|
||||||
@ -415,17 +414,19 @@ decoder_data(Decoder &decoder,
|
|||||||
return dc.command;
|
return dc.command;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *dest = chunk->Write(dc.out_audio_format,
|
const auto dest =
|
||||||
decoder.timestamp -
|
chunk->Write(dc.out_audio_format,
|
||||||
dc.song->start_ms / 1000.0,
|
decoder.timestamp -
|
||||||
kbit_rate, &nbytes);
|
dc.song->start_ms / 1000.0,
|
||||||
if (dest == nullptr) {
|
kbit_rate);
|
||||||
|
if (dest.IsNull()) {
|
||||||
/* the chunk is full, flush it */
|
/* the chunk is full, flush it */
|
||||||
decoder_flush_chunk(decoder);
|
decoder_flush_chunk(decoder);
|
||||||
dc.client_cond.signal();
|
dc.client_cond.signal();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t nbytes = dest.size;
|
||||||
assert(nbytes > 0);
|
assert(nbytes > 0);
|
||||||
|
|
||||||
if (nbytes > length)
|
if (nbytes > length)
|
||||||
@ -433,7 +434,7 @@ decoder_data(Decoder &decoder,
|
|||||||
|
|
||||||
/* copy the buffer */
|
/* copy the buffer */
|
||||||
|
|
||||||
memcpy(dest, data, nbytes);
|
memcpy(dest.data, data, nbytes);
|
||||||
|
|
||||||
/* expand the music pipe chunk */
|
/* expand the music pipe chunk */
|
||||||
|
|
||||||
|
@ -39,10 +39,9 @@ music_chunk::CheckFormat(const AudioFormat other_format) const
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void *
|
WritableBuffer<void>
|
||||||
music_chunk::Write(const AudioFormat af,
|
music_chunk::Write(const AudioFormat af,
|
||||||
float data_time, uint16_t _bit_rate,
|
float data_time, uint16_t _bit_rate)
|
||||||
size_t *max_length_r)
|
|
||||||
{
|
{
|
||||||
assert(CheckFormat(af));
|
assert(CheckFormat(af));
|
||||||
assert(length == 0 || audio_format.IsValid());
|
assert(length == 0 || audio_format.IsValid());
|
||||||
@ -58,14 +57,13 @@ music_chunk::Write(const AudioFormat af,
|
|||||||
const size_t frame_size = af.GetFrameSize();
|
const size_t frame_size = af.GetFrameSize();
|
||||||
size_t num_frames = (sizeof(data) - length) / frame_size;
|
size_t num_frames = (sizeof(data) - length) / frame_size;
|
||||||
if (num_frames == 0)
|
if (num_frames == 0)
|
||||||
return nullptr;
|
return WritableBuffer<void>::Null();
|
||||||
|
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
audio_format = af;
|
audio_format = af;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
*max_length_r = num_frames * frame_size;
|
return { data + length, num_frames * frame_size };
|
||||||
return data + length;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
#define MPD_MUSIC_CHUNK_HXX
|
#define MPD_MUSIC_CHUNK_HXX
|
||||||
|
|
||||||
#include "ReplayGainInfo.hxx"
|
#include "ReplayGainInfo.hxx"
|
||||||
|
#include "util/WritableBuffer.hxx"
|
||||||
|
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
#include "AudioFormat.hxx"
|
#include "AudioFormat.hxx"
|
||||||
@ -126,9 +127,8 @@ struct music_chunk {
|
|||||||
* here
|
* here
|
||||||
* @return a writable buffer, or nullptr if the chunk is full
|
* @return a writable buffer, or nullptr if the chunk is full
|
||||||
*/
|
*/
|
||||||
void *Write(AudioFormat af,
|
WritableBuffer<void> Write(AudioFormat af,
|
||||||
float data_time, uint16_t bit_rate,
|
float data_time, uint16_t bit_rate);
|
||||||
size_t *max_length_r);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Increases the length of the chunk after the caller has written to
|
* Increases the length of the chunk after the caller has written to
|
||||||
|
Loading…
Reference in New Issue
Block a user