aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2008-04-12 04:13:24 +0000
committerEric Wong <normalperson@yhbt.net>2008-04-12 04:13:24 +0000
commit74910df0f367143e73e460524b31bacead953b16 (patch)
tree571196ade2bc01216679b5181b72d7e754a1f48a /src
parent68a625b5b819416dacf2e4def6e124413d5226c5 (diff)
downloadmpd-74910df0f367143e73e460524b31bacead953b16.tar.gz
mpd-74910df0f367143e73e460524b31bacead953b16.tar.xz
mpd-74910df0f367143e73e460524b31bacead953b16.zip
added struct OutputBufferChunk
To make access to OutputBuffer easier, move everything which belongs to a chunk into its own structure, namely OutputBufferChunk. git-svn-id: https://svn.musicpd.org/mpd/trunk@7269 09075e82-0dd4-0310-85a5-a0d7c8717e4f
Diffstat (limited to 'src')
-rw-r--r--src/decode.c35
-rw-r--r--src/outputBuffer.c32
-rw-r--r--src/outputBuffer.h16
-rw-r--r--src/playerData.c4
4 files changed, 46 insertions, 41 deletions
diff --git a/src/decode.c b/src/decode.c
index 8650184c6..af0173fa5 100644
--- a/src/decode.c
+++ b/src/decode.c
@@ -491,6 +491,8 @@ static void decodeParent(PlayerControl * pc, DecoderControl * dc, OutputBuffer *
if (pause)
player_sleep();
else if (!outputBufferEmpty(cb) && cb->begin != next) {
+ OutputBufferChunk *beginChunk =
+ outputBufferGetChunk(cb, cb->begin);
unsigned int fadePosition;
if (doCrossFade == 1 && next >= 0 &&
(fadePosition = outputBufferRelative(cb, next))
@@ -506,18 +508,20 @@ static void decodeParent(PlayerControl * pc, DecoderControl * dc, OutputBuffer *
}
nextChunk = outputBufferAbsolute(cb, crossFadeChunks);
if (nextChunk >= 0) {
- pcm_mix(outputBufferChunkData(cb, cb->begin),
- outputBufferChunkData(cb, nextChunk),
- cb->chunkSize[cb->begin],
- cb->chunkSize[nextChunk],
+ OutputBufferChunk *fadeChunk =
+ outputBufferGetChunk(cb, nextChunk);
+ pcm_mix(beginChunk->data,
+ fadeChunk->data,
+ beginChunk->chunkSize,
+ fadeChunk->chunkSize,
&(cb->audioFormat),
((float)fadePosition) /
crossFadeChunks);
- if (cb->chunkSize[nextChunk] >
- cb->chunkSize[cb->begin]
+ if (fadeChunk->chunkSize >
+ beginChunk->chunkSize
) {
- cb->chunkSize[cb->begin]
- = cb->chunkSize[nextChunk];
+ beginChunk->chunkSize
+ = fadeChunk->chunkSize;
}
} else {
/* there are not enough
@@ -535,18 +539,17 @@ static void decodeParent(PlayerControl * pc, DecoderControl * dc, OutputBuffer *
}
/* play the current chunk */
- pc->elapsedTime = cb->times[cb->begin];
- pc->bitRate = cb->bitRate[cb->begin];
- pcm_volumeChange(cb->chunks + cb->begin *
- CHUNK_SIZE,
- cb->chunkSize[cb->begin],
+ pc->elapsedTime = beginChunk->times;
+ pc->bitRate = beginChunk->bitRate;
+ pcm_volumeChange(beginChunk->data,
+ beginChunk->chunkSize,
&(cb->audioFormat),
pc->softwareVolume);
- if (playAudio(cb->chunks + cb->begin * CHUNK_SIZE,
- cb->chunkSize[cb->begin]) < 0)
+ if (playAudio(beginChunk->data,
+ beginChunk->chunkSize) < 0)
break;
pc->totalPlayTime +=
- sizeToTime * cb->chunkSize[cb->begin];
+ sizeToTime * beginChunk->chunkSize;
if ((unsigned)cb->begin + 1 >= buffered_chunks) {
cb->begin = 0;
} else
diff --git a/src/outputBuffer.c b/src/outputBuffer.c
index 157e36374..ad584c8c8 100644
--- a/src/outputBuffer.c
+++ b/src/outputBuffer.c
@@ -28,16 +28,10 @@
static mpd_sint16 currentChunk = -1;
-void initOutputBuffer(OutputBuffer * cb, char *chunks)
+void initOutputBuffer(OutputBuffer * cb, OutputBufferChunk * chunks)
{
memset(&cb->convState, 0, sizeof(ConvState));
cb->chunks = chunks;
- cb->chunkSize = (mpd_uint16 *) (((char *)cb->chunks) +
- buffered_chunks * CHUNK_SIZE);
- cb->bitRate = (mpd_uint16 *) (((char *)cb->chunkSize) +
- buffered_chunks * sizeof(mpd_sint16));
- cb->times = (float *)(((char *)cb->bitRate) +
- buffered_chunks * sizeof(mpd_sint8));
}
void clearOutputBuffer(OutputBuffer * cb)
@@ -92,11 +86,11 @@ int outputBufferAbsolute(const OutputBuffer * cb, unsigned relative)
return (int)i;
}
-char * outputBufferChunkData(const OutputBuffer * cb, unsigned i)
+OutputBufferChunk * outputBufferGetChunk(const OutputBuffer * cb, unsigned i)
{
assert(i < buffered_chunks);
- return cb->chunks + i * CHUNK_SIZE;
+ return &cb->chunks[i];
}
/**
@@ -113,6 +107,7 @@ static int tailChunk(OutputBuffer * cb, InputStream * inStream,
float data_time, mpd_uint16 bitRate)
{
unsigned int next;
+ OutputBufferChunk *chunk;
if (currentChunk == cb->end)
return currentChunk;
@@ -140,9 +135,10 @@ static int tailChunk(OutputBuffer * cb, InputStream * inStream,
return OUTPUT_BUFFER_DC_STOP;
currentChunk = cb->end;
- cb->chunkSize[currentChunk] = 0;
- cb->bitRate[currentChunk] = bitRate;
- cb->times[currentChunk] = data_time;
+ chunk = outputBufferGetChunk(cb, currentChunk);
+ chunk->chunkSize = 0;
+ chunk->bitRate = bitRate;
+ chunk->times = data_time;
return currentChunk;
}
@@ -183,22 +179,24 @@ int sendDataToOutputBuffer(OutputBuffer * cb, InputStream * inStream,
normalizeData(data, datalen, &cb->audioFormat);
while (datalen) {
+ OutputBufferChunk *chunk;
int chunk_index = tailChunk(cb, inStream,
dc, seekable,
data_time, bitRate);
if (chunk_index < 0)
return chunk_index;
- chunkLeft = CHUNK_SIZE - cb->chunkSize[chunk_index];
+ chunk = outputBufferGetChunk(cb, chunk_index);
+
+ chunkLeft = CHUNK_SIZE - chunk->chunkSize;
dataToSend = datalen > chunkLeft ? chunkLeft : datalen;
- memcpy(cb->chunks + chunk_index * CHUNK_SIZE +
- cb->chunkSize[chunk_index], data, dataToSend);
- cb->chunkSize[chunk_index] += dataToSend;
+ memcpy(chunk->data + chunk->chunkSize, data, dataToSend);
+ chunk->chunkSize += dataToSend;
datalen -= dataToSend;
data += dataToSend;
- if (cb->chunkSize[chunk_index] == CHUNK_SIZE) {
+ if (chunk->chunkSize == CHUNK_SIZE) {
flushOutputBuffer(cb);
}
}
diff --git a/src/outputBuffer.h b/src/outputBuffer.h
index b4d96acf2..a99489968 100644
--- a/src/outputBuffer.h
+++ b/src/outputBuffer.h
@@ -32,15 +32,19 @@
/* pick 1020 since its devisible for 8,16,24, and 32-bit audio */
#define CHUNK_SIZE 1020
+typedef struct _OutputBufferChunk {
+ volatile mpd_uint16 chunkSize;
+ volatile mpd_uint16 bitRate;
+ volatile float times;
+ char data[CHUNK_SIZE];
+} OutputBufferChunk;
+
/**
* A ring set of buffers where the decoder appends data after the end,
* and the player consumes data from the beginning.
*/
typedef struct _OutputBuffer {
- char *volatile chunks;
- mpd_uint16 *volatile chunkSize;
- mpd_uint16 *volatile bitRate;
- float *volatile times;
+ OutputBufferChunk *chunks;
/** the index of the first decoded chunk */
mpd_uint16 volatile begin;
@@ -52,7 +56,7 @@ typedef struct _OutputBuffer {
ConvState convState;
} OutputBuffer;
-void initOutputBuffer(OutputBuffer * cb, char *chunks);
+void initOutputBuffer(OutputBuffer * cb, OutputBufferChunk * chunks);
void clearOutputBuffer(OutputBuffer * cb);
@@ -76,7 +80,7 @@ unsigned availableOutputBuffer(const OutputBuffer * cb);
*/
int outputBufferAbsolute(const OutputBuffer * cb, unsigned relative);
-char * outputBufferChunkData(const OutputBuffer * cb, unsigned i);
+OutputBufferChunk * outputBufferGetChunk(const OutputBuffer * cb, unsigned i);
/* we send inStream for buffering the inputStream while waiting to
send the next chunk */
diff --git a/src/playerData.c b/src/playerData.c
index 718b28771..f9cc314a9 100644
--- a/src/playerData.c
+++ b/src/playerData.c
@@ -74,7 +74,7 @@ void initPlayerData(void)
buffered_before_play = buffered_chunks;
}
- allocationSize = buffered_chunks * CHUNK_SIZE; /*actual buffer */
+ allocationSize = buffered_chunks * sizeof(OutputBufferChunk); /*actual buffer */
allocationSize += buffered_chunks * sizeof(float); /*for times */
allocationSize += buffered_chunks * sizeof(mpd_sint16); /*for chunkSize */
allocationSize += buffered_chunks * sizeof(mpd_sint16); /*for bitRate */
@@ -94,7 +94,7 @@ void initPlayerData(void)
allocationSize - device_array_size;
initOutputBuffer(&(playerData_pd->buffer),
- ((char *)playerData_pd) + sizeof(PlayerData));
+ (OutputBufferChunk*)(((char *)playerData_pd) + sizeof(PlayerData)));
playerData_pd->playerControl.stop = 0;
playerData_pd->playerControl.pause = 0;