music_pipe: moved code to music_chunk_append()
This commit is contained in:
parent
e9e9d2bc2d
commit
cd61f6570f
41
src/pipe.c
41
src/pipe.c
|
@ -185,13 +185,34 @@ tail_chunk(float data_time, uint16_t bitRate, size_t frame_size)
|
||||||
return chunk;
|
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,
|
size_t music_pipe_append(const void *data0, size_t datalen,
|
||||||
const struct audio_format *audio_format,
|
const struct audio_format *audio_format,
|
||||||
float data_time, uint16_t bitRate)
|
float data_time, uint16_t bitRate)
|
||||||
{
|
{
|
||||||
const unsigned char *data = data0;
|
const unsigned char *data = data0;
|
||||||
const size_t frame_size = audio_format_frame_size(audio_format);
|
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;
|
struct music_chunk *chunk = NULL;
|
||||||
|
|
||||||
/* no partial frames allowed */
|
/* no partial frames allowed */
|
||||||
|
@ -202,19 +223,13 @@ size_t music_pipe_append(const void *data0, size_t datalen,
|
||||||
if (chunk == NULL)
|
if (chunk == NULL)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
dataToSend = sizeof(chunk->data) - chunk->chunkSize;
|
nbytes = music_chunk_append(chunk, data, datalen,
|
||||||
if (dataToSend > datalen)
|
frame_size);
|
||||||
dataToSend = datalen;
|
assert(nbytes > 0);
|
||||||
|
|
||||||
/* don't split frames */
|
datalen -= nbytes;
|
||||||
dataToSend /= frame_size;
|
data += nbytes;
|
||||||
dataToSend *= frame_size;
|
ret += nbytes;
|
||||||
|
|
||||||
memcpy(chunk->data + chunk->chunkSize, data, dataToSend);
|
|
||||||
chunk->chunkSize += dataToSend;
|
|
||||||
datalen -= dataToSend;
|
|
||||||
data += dataToSend;
|
|
||||||
ret += dataToSend;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (chunk != NULL && chunk->chunkSize == sizeof(chunk->data))
|
if (chunk != NULL && chunk->chunkSize == sizeof(chunk->data))
|
||||||
|
|
Loading…
Reference in New Issue