diff options
author | Max Kellermann <max@duempel.org> | 2008-11-02 16:56:49 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2008-11-02 16:56:49 +0100 |
commit | cd61f6570f50c5ef3ba51a2864b07d52a7ab788c (patch) | |
tree | 9a6daf141e0b4d1ad46b3def5fbffad010ee9c02 /src | |
parent | e9e9d2bc2d9a144a09eb9954dd7857381e77a78a (diff) | |
download | mpd-cd61f6570f50c5ef3ba51a2864b07d52a7ab788c.tar.gz mpd-cd61f6570f50c5ef3ba51a2864b07d52a7ab788c.tar.xz mpd-cd61f6570f50c5ef3ba51a2864b07d52a7ab788c.zip |
music_pipe: moved code to music_chunk_append()
Diffstat (limited to 'src')
-rw-r--r-- | src/pipe.c | 41 |
1 files changed, 28 insertions, 13 deletions
diff --git a/src/pipe.c b/src/pipe.c index f1853dbac..911dcbdb5 100644 --- a/src/pipe.c +++ b/src/pipe.c @@ -185,13 +185,34 @@ tail_chunk(float data_time, uint16_t bitRate, size_t frame_size) return chunk; } +static size_t +music_chunk_append(struct music_chunk *chunk, const void *data, size_t length, + size_t frame_size) +{ + size_t rest = sizeof(chunk->data) - chunk->chunkSize; + + assert(rest >= frame_size); + + if (length > rest) + length = rest; + + /* don't split frames */ + length /= frame_size; + length *= frame_size; + + memcpy(chunk->data + chunk->chunkSize, data, length); + chunk->chunkSize += length; + + return length; +} + size_t music_pipe_append(const void *data0, size_t datalen, const struct audio_format *audio_format, float data_time, uint16_t bitRate) { const unsigned char *data = data0; const size_t frame_size = audio_format_frame_size(audio_format); - size_t ret = 0, dataToSend; + size_t ret = 0, nbytes; struct music_chunk *chunk = NULL; /* no partial frames allowed */ @@ -202,19 +223,13 @@ size_t music_pipe_append(const void *data0, size_t datalen, if (chunk == NULL) return ret; - dataToSend = sizeof(chunk->data) - chunk->chunkSize; - if (dataToSend > datalen) - dataToSend = datalen; - - /* don't split frames */ - dataToSend /= frame_size; - dataToSend *= frame_size; + nbytes = music_chunk_append(chunk, data, datalen, + frame_size); + assert(nbytes > 0); - memcpy(chunk->data + chunk->chunkSize, data, dataToSend); - chunk->chunkSize += dataToSend; - datalen -= dataToSend; - data += dataToSend; - ret += dataToSend; + datalen -= nbytes; + data += nbytes; + ret += nbytes; } if (chunk != NULL && chunk->chunkSize == sizeof(chunk->data)) |