Make the OutputBuffer API more consistent

We had functions names varied between
outputBufferFoo, fooOutputBuffer, and output_buffer_foo

That was too confusing for my little brain to handle.
And the global variable was somehow named 'cb' instead of
the more obvious 'ob'...

git-svn-id: https://svn.musicpd.org/mpd/trunk@7355 09075e82-0dd4-0310-85a5-a0d7c8717e4f
This commit is contained in:
Eric Wong 2008-04-13 01:16:27 +00:00
parent c1963ed483
commit 412ce8bdc4
17 changed files with 146 additions and 146 deletions

View File

@ -85,7 +85,7 @@ static unsigned calculateCrossFadeChunks(AudioFormat * af, float totalTime)
chunks = (af->sampleRate * af->bits * af->channels / 8.0 / CHUNK_SIZE); chunks = (af->sampleRate * af->bits * af->channels / 8.0 / CHUNK_SIZE);
chunks = (chunks * pc.crossFade + 0.5); chunks = (chunks * pc.crossFade + 0.5);
buffered_chunks = cb.size; buffered_chunks = ob.size;
assert(buffered_chunks >= buffered_before_play); assert(buffered_chunks >= buffered_before_play);
if (chunks > (buffered_chunks - buffered_before_play)) if (chunks > (buffered_chunks - buffered_before_play))
chunks = buffered_chunks - buffered_before_play; chunks = buffered_chunks - buffered_before_play;
@ -124,7 +124,7 @@ static int decodeSeek(int *decodeWaitedOn, int *next)
dc.current_song != pc.current_song) { dc.current_song != pc.current_song) {
stopDecode(); stopDecode();
*next = -1; *next = -1;
clearOutputBuffer(); ob_clear();
dc.error = DECODE_ERROR_NOERROR; dc.error = DECODE_ERROR_NOERROR;
dc.start = 1; dc.start = 1;
waitOnDecode(decodeWaitedOn); waitOnDecode(decodeWaitedOn);
@ -344,7 +344,7 @@ void decoderInit(void)
FATAL("Failed to spawn decoder task: %s\n", strerror(errno)); FATAL("Failed to spawn decoder task: %s\n", strerror(errno));
} }
static void crossFade(OutputBufferChunk * a, OutputBufferChunk * b, static void crossFade(ob_chunk * a, ob_chunk * b,
AudioFormat * format, AudioFormat * format,
unsigned int fadePosition, unsigned int crossFadeChunks) unsigned int fadePosition, unsigned int crossFadeChunks)
{ {
@ -361,7 +361,7 @@ static void crossFade(OutputBufferChunk * a, OutputBufferChunk * b,
a->chunkSize = b->chunkSize; a->chunkSize = b->chunkSize;
} }
static int playChunk(OutputBufferChunk * chunk, static int playChunk(ob_chunk * chunk,
AudioFormat * format, double sizeToTime) AudioFormat * format, double sizeToTime)
{ {
pc.elapsedTime = chunk->times; pc.elapsedTime = chunk->times;
@ -413,7 +413,7 @@ static void decodeParent(void)
} }
if (buffering) { if (buffering) {
if (availableOutputBuffer() < bbp) { if (ob_available() < bbp) {
/* not enough decoded buffer space yet */ /* not enough decoded buffer space yet */
player_sleep(); player_sleep();
continue; continue;
@ -427,7 +427,7 @@ static void decodeParent(void)
dc.error==DECODE_ERROR_NOERROR) { dc.error==DECODE_ERROR_NOERROR) {
/* the decoder is ready and ok */ /* the decoder is ready and ok */
decodeWaitedOn = 0; decodeWaitedOn = 0;
if(openAudioDevice(&(cb.audioFormat))<0) { if(openAudioDevice(&(ob.audioFormat))<0) {
char tmp[MPD_PATH_MAX]; char tmp[MPD_PATH_MAX];
pc.errored_song = pc.current_song; pc.errored_song = pc.current_song;
pc.error = PLAYER_ERROR_AUDIO; pc.error = PLAYER_ERROR_AUDIO;
@ -446,7 +446,7 @@ static void decodeParent(void)
pc.sampleRate = dc.audioFormat.sampleRate; pc.sampleRate = dc.audioFormat.sampleRate;
pc.bits = dc.audioFormat.bits; pc.bits = dc.audioFormat.bits;
pc.channels = dc.audioFormat.channels; pc.channels = dc.audioFormat.channels;
sizeToTime = audioFormatSizeToTime(&cb.audioFormat); sizeToTime = audioFormatSizeToTime(&ob.audioFormat);
} }
else if(dc.state!=DECODE_STATE_START) { else if(dc.state!=DECODE_STATE_START) {
/* the decoder failed */ /* the decoder failed */
@ -467,7 +467,7 @@ static void decodeParent(void)
pc.queueLockState == PLAYER_QUEUE_UNLOCKED) { pc.queueLockState == PLAYER_QUEUE_UNLOCKED) {
/* the decoder has finished the current song; /* the decoder has finished the current song;
make it decode the next song */ make it decode the next song */
next = cb.end; next = ob.end;
dc.start = 1; dc.start = 1;
pc.queueState = PLAYER_QUEUE_DECODE; pc.queueState = PLAYER_QUEUE_DECODE;
wakeup_main_task(); wakeup_main_task();
@ -479,7 +479,7 @@ static void decodeParent(void)
calculate how many chunks will be required calculate how many chunks will be required
for it */ for it */
crossFadeChunks = crossFadeChunks =
calculateCrossFadeChunks(&(cb.audioFormat), calculateCrossFadeChunks(&(ob.audioFormat),
dc.totalTime); dc.totalTime);
if (crossFadeChunks > 0) { if (crossFadeChunks > 0) {
doCrossFade = 1; doCrossFade = 1;
@ -492,12 +492,12 @@ static void decodeParent(void)
if (do_pause) if (do_pause)
player_sleep(); player_sleep();
else if (!outputBufferEmpty() && (int)cb.begin != next) { else if (!ob_is_empty() && (int)ob.begin != next) {
OutputBufferChunk *beginChunk = ob_chunk *beginChunk =
outputBufferGetChunk(cb.begin); ob_get_chunk(ob.begin);
unsigned int fadePosition; unsigned int fadePosition;
if (doCrossFade == 1 && next >= 0 && if (doCrossFade == 1 && next >= 0 &&
(fadePosition = outputBufferRelative(next)) (fadePosition = ob_relative(next))
<= crossFadeChunks) { <= crossFadeChunks) {
/* perform cross fade */ /* perform cross fade */
if (nextChunk < 0) { if (nextChunk < 0) {
@ -508,11 +508,11 @@ static void decodeParent(void)
chunks in the old song */ chunks in the old song */
crossFadeChunks = fadePosition; crossFadeChunks = fadePosition;
} }
nextChunk = outputBufferAbsolute(crossFadeChunks); nextChunk = ob_absolute(crossFadeChunks);
if (nextChunk >= 0) { if (nextChunk >= 0) {
crossFade(beginChunk, crossFade(beginChunk,
outputBufferGetChunk(nextChunk), ob_get_chunk(nextChunk),
&(cb.audioFormat), &(ob.audioFormat),
fadePosition, fadePosition,
crossFadeChunks); crossFadeChunks);
} else { } else {
@ -533,19 +533,19 @@ static void decodeParent(void)
} }
/* play the current chunk */ /* play the current chunk */
if (playChunk(beginChunk, &(cb.audioFormat), if (playChunk(beginChunk, &(ob.audioFormat),
sizeToTime) < 0) sizeToTime) < 0)
break; break;
outputBufferShift(); ob_shift();
player_wakeup_decoder_nb(); player_wakeup_decoder_nb();
} else if (!outputBufferEmpty() && (int)cb.begin == next) { } else if (!ob_is_empty() && (int)ob.begin == next) {
/* at the beginning of a new song */ /* at the beginning of a new song */
if (doCrossFade == 1 && nextChunk >= 0) { if (doCrossFade == 1 && nextChunk >= 0) {
/* the cross-fade is finished; skip /* the cross-fade is finished; skip
the section which was cross-faded the section which was cross-faded
(and thus already played) */ (and thus already played) */
output_buffer_skip(crossFadeChunks); ob_skip(crossFadeChunks);
} }
doCrossFade = 0; doCrossFade = 0;
@ -584,7 +584,7 @@ static void decodeParent(void)
*/ */
void decode(void) void decode(void)
{ {
clearOutputBuffer(); ob_clear();
dc.error = DECODE_ERROR_NOERROR; dc.error = DECODE_ERROR_NOERROR;
dc.seek = 0; dc.seek = 0;

View File

@ -170,7 +170,7 @@ void flac_metadata_common_cb(const FLAC__StreamMetadata * block,
dc.audioFormat.sampleRate = si->sample_rate; dc.audioFormat.sampleRate = si->sample_rate;
dc.audioFormat.channels = (mpd_sint8)si->channels; dc.audioFormat.channels = (mpd_sint8)si->channels;
dc.totalTime = ((float)si->total_samples) / (si->sample_rate); dc.totalTime = ((float)si->total_samples) / (si->sample_rate);
getOutputAudioFormat(&(dc.audioFormat), &(cb.audioFormat)); getOutputAudioFormat(&(dc.audioFormat), &(ob.audioFormat));
break; break;
case FLAC__METADATA_TYPE_VORBIS_COMMENT: case FLAC__METADATA_TYPE_VORBIS_COMMENT:
flacParseReplayGain(block, data); flacParseReplayGain(block, data);

View File

@ -167,7 +167,7 @@ MpdTag *copyVorbisCommentBlockToMpdTag(const FLAC__StreamMetadata * block,
/* keep this inlined, this is just macro but prettier :) */ /* keep this inlined, this is just macro but prettier :) */
static inline int flacSendChunk(FlacData * data) static inline int flacSendChunk(FlacData * data)
{ {
if (sendDataToOutputBuffer(data->inStream, if (ob_send(data->inStream,
1, data->chunk, 1, data->chunk,
data->chunk_length, data->time, data->chunk_length, data->time,
data->bitRate, data->bitRate,

View File

@ -376,7 +376,7 @@ static int aac_decode(char *path)
dc.audioFormat.channels = frameInfo.channels; dc.audioFormat.channels = frameInfo.channels;
dc.audioFormat.sampleRate = sampleRate; dc.audioFormat.sampleRate = sampleRate;
getOutputAudioFormat(&(dc.audioFormat), getOutputAudioFormat(&(dc.audioFormat),
&(cb.audioFormat)); &(ob.audioFormat));
dc.state = DECODE_STATE_DECODE; dc.state = DECODE_STATE_DECODE;
} }
@ -395,7 +395,7 @@ static int aac_decode(char *path)
sampleBufferLen = sampleCount * 2; sampleBufferLen = sampleCount * 2;
sendDataToOutputBuffer(NULL, 0, sampleBuffer, ob_send(NULL, 0, sampleBuffer,
sampleBufferLen, file_time, sampleBufferLen, file_time,
bitRate, NULL); bitRate, NULL);
if (dc.seek) { if (dc.seek) {
@ -408,7 +408,7 @@ static int aac_decode(char *path)
} }
} }
flushOutputBuffer(); ob_flush();
faacDecClose(decoder); faacDecClose(decoder);
if (b.buffer) if (b.buffer)

View File

@ -72,7 +72,7 @@ static int audiofile_decode(char *path)
(unsigned int)afGetRate(af_fp, AF_DEFAULT_TRACK); (unsigned int)afGetRate(af_fp, AF_DEFAULT_TRACK);
dc.audioFormat.channels = dc.audioFormat.channels =
(mpd_uint8)afGetVirtualChannels(af_fp, AF_DEFAULT_TRACK); (mpd_uint8)afGetVirtualChannels(af_fp, AF_DEFAULT_TRACK);
getOutputAudioFormat(&(dc.audioFormat), &(cb.audioFormat)); getOutputAudioFormat(&(dc.audioFormat), &(ob.audioFormat));
frame_count = afGetFrameCount(af_fp, AF_DEFAULT_TRACK); frame_count = afGetFrameCount(af_fp, AF_DEFAULT_TRACK);
@ -97,7 +97,7 @@ static int audiofile_decode(char *path)
while (!eof) { while (!eof) {
if (dc.seek) { if (dc.seek) {
clearOutputBuffer(); ob_clear();
current = dc.seekWhere * current = dc.seekWhere *
dc.audioFormat.sampleRate; dc.audioFormat.sampleRate;
afSeekFrame(af_fp, AF_DEFAULT_TRACK, current); afSeekFrame(af_fp, AF_DEFAULT_TRACK, current);
@ -112,7 +112,7 @@ static int audiofile_decode(char *path)
eof = 1; eof = 1;
else { else {
current += ret; current += ret;
sendDataToOutputBuffer(NULL, ob_send(NULL,
1, 1,
chunk, chunk,
ret * fs, ret * fs,
@ -125,7 +125,7 @@ static int audiofile_decode(char *path)
} }
} }
flushOutputBuffer(); ob_flush();
} }
afCloseFile(af_fp); afCloseFile(af_fp);

View File

@ -430,7 +430,7 @@ static int flac_decode_internal(InputStream * inStream, int is_ogg)
FLAC__uint64 sampleToSeek = dc.seekWhere * FLAC__uint64 sampleToSeek = dc.seekWhere *
dc.audioFormat.sampleRate + 0.5; dc.audioFormat.sampleRate + 0.5;
if (flac_seek_absolute(flacDec, sampleToSeek)) { if (flac_seek_absolute(flacDec, sampleToSeek)) {
clearOutputBuffer(); ob_clear();
data.time = ((float)sampleToSeek) / data.time = ((float)sampleToSeek) /
dc.audioFormat.sampleRate; dc.audioFormat.sampleRate;
data.position = 0; data.position = 0;
@ -447,7 +447,7 @@ static int flac_decode_internal(InputStream * inStream, int is_ogg)
/* send last little bit */ /* send last little bit */
if (data.chunk_length > 0 && !dc.stop) { if (data.chunk_length > 0 && !dc.stop) {
flacSendChunk(&data); flacSendChunk(&data);
flushOutputBuffer(); ob_flush();
} }
fail: fail:

View File

@ -183,7 +183,7 @@ static int mod_decode(char *path)
dc.audioFormat.bits = 16; dc.audioFormat.bits = 16;
dc.audioFormat.sampleRate = 44100; dc.audioFormat.sampleRate = 44100;
dc.audioFormat.channels = 2; dc.audioFormat.channels = 2;
getOutputAudioFormat(&(dc.audioFormat), &(cb.audioFormat)); getOutputAudioFormat(&(dc.audioFormat), &(ob.audioFormat));
secPerByte = secPerByte =
1.0 / ((dc.audioFormat.bits * dc.audioFormat.channels / 8.0) * 1.0 / ((dc.audioFormat.bits * dc.audioFormat.channels / 8.0) *
@ -205,12 +205,12 @@ static int mod_decode(char *path)
ret = VC_WriteBytes(data->audio_buffer, MIKMOD_FRAME_SIZE); ret = VC_WriteBytes(data->audio_buffer, MIKMOD_FRAME_SIZE);
total_time += ret * secPerByte; total_time += ret * secPerByte;
sendDataToOutputBuffer(NULL, 0, ob_send(NULL, 0,
(char *)data->audio_buffer, ret, (char *)data->audio_buffer, ret,
total_time, 0, NULL); total_time, 0, NULL);
} }
flushOutputBuffer(); ob_flush();
mod_close(data); mod_close(data);

View File

@ -853,7 +853,7 @@ static int mp3Read(mp3DecodeData * data, ReplayGainInfo ** replayGainInfo)
case MUTEFRAME_SEEK: case MUTEFRAME_SEEK:
if (dc.seekWhere <= data->elapsedTime) { if (dc.seekWhere <= data->elapsedTime) {
data->outputPtr = data->outputBuffer; data->outputPtr = data->outputBuffer;
clearOutputBuffer(); ob_clear();
data->muteFrame = 0; data->muteFrame = 0;
dc.seek = 0; dc.seek = 0;
decoder_wakeup_player(); decoder_wakeup_player();
@ -928,7 +928,7 @@ static int mp3Read(mp3DecodeData * data, ReplayGainInfo ** replayGainInfo)
} }
if (data->outputPtr >= data->outputBufferEnd) { if (data->outputPtr >= data->outputBufferEnd) {
ret = sendDataToOutputBuffer(data->inStream, ret = ob_send(data->inStream,
data->inStream->seekable, data->inStream->seekable,
data->outputBuffer, data->outputBuffer,
data->outputPtr - data->outputBuffer, data->outputPtr - data->outputBuffer,
@ -963,7 +963,7 @@ static int mp3Read(mp3DecodeData * data, ReplayGainInfo ** replayGainInfo)
data->frameOffset[j]) == data->frameOffset[j]) ==
0) { 0) {
data->outputPtr = data->outputBuffer; data->outputPtr = data->outputBuffer;
clearOutputBuffer(); ob_clear();
data->currentFrame = j; data->currentFrame = j;
} else } else
dc.seekError = 1; dc.seekError = 1;
@ -1029,7 +1029,7 @@ static int mp3_decode(InputStream * inStream)
} }
initAudioFormatFromMp3DecodeData(&data, &(dc.audioFormat)); initAudioFormatFromMp3DecodeData(&data, &(dc.audioFormat));
getOutputAudioFormat(&(dc.audioFormat), &(cb.audioFormat)); getOutputAudioFormat(&(dc.audioFormat), &(ob.audioFormat));
dc.totalTime = data.totalTime; dc.totalTime = data.totalTime;
@ -1063,7 +1063,7 @@ static int mp3_decode(InputStream * inStream)
while (mp3Read(&data, &replayGainInfo) != DECODE_BREAK) ; while (mp3Read(&data, &replayGainInfo) != DECODE_BREAK) ;
/* send last little bit if not dc.stop */ /* send last little bit if not dc.stop */
if (!dc.stop && data.outputPtr != data.outputBuffer && data.flush) { if (!dc.stop && data.outputPtr != data.outputBuffer && data.flush) {
sendDataToOutputBuffer(NULL, ob_send(NULL,
data.inStream->seekable, data.inStream->seekable,
data.outputBuffer, data.outputBuffer,
data.outputPtr - data.outputBuffer, data.outputPtr - data.outputBuffer,
@ -1075,12 +1075,12 @@ static int mp3_decode(InputStream * inStream)
freeReplayGainInfo(replayGainInfo); freeReplayGainInfo(replayGainInfo);
if (dc.seek && data.muteFrame == MUTEFRAME_SEEK) { if (dc.seek && data.muteFrame == MUTEFRAME_SEEK) {
clearOutputBuffer(); ob_clear();
dc.seek = 0; dc.seek = 0;
decoder_wakeup_player(); decoder_wakeup_player();
} }
flushOutputBuffer(); ob_flush();
mp3DecodeDataFinalize(&data); mp3DecodeDataFinalize(&data);
return 0; return 0;

View File

@ -217,7 +217,7 @@ static int mp4_decode(InputStream * inStream)
if (seeking && seekPositionFound) { if (seeking && seekPositionFound) {
seekPositionFound = 0; seekPositionFound = 0;
clearOutputBuffer(); ob_clear();
seeking = 0; seeking = 0;
dc.seek = 0; dc.seek = 0;
decoder_wakeup_player(); decoder_wakeup_player();
@ -255,7 +255,7 @@ static int mp4_decode(InputStream * inStream)
dc.audioFormat.sampleRate = scale; dc.audioFormat.sampleRate = scale;
dc.audioFormat.channels = frameInfo.channels; dc.audioFormat.channels = frameInfo.channels;
getOutputAudioFormat(&(dc.audioFormat), getOutputAudioFormat(&(dc.audioFormat),
&(cb.audioFormat)); &(ob.audioFormat));
dc.state = DECODE_STATE_DECODE; dc.state = DECODE_STATE_DECODE;
} }
@ -277,7 +277,7 @@ static int mp4_decode(InputStream * inStream)
sampleBuffer += offset * channels * 2; sampleBuffer += offset * channels * 2;
sendDataToOutputBuffer(inStream, 1, sampleBuffer, ob_send(inStream, 1, sampleBuffer,
sampleBufferLen, file_time, sampleBufferLen, file_time,
bitRate, NULL); bitRate, NULL);
if (dc.stop) { if (dc.stop) {
@ -295,11 +295,11 @@ static int mp4_decode(InputStream * inStream)
return -1; return -1;
if (dc.seek && seeking) { if (dc.seek && seeking) {
clearOutputBuffer(); ob_clear();
dc.seek = 0; dc.seek = 0;
decoder_wakeup_player(); decoder_wakeup_player();
} }
flushOutputBuffer(); ob_flush();
return 0; return 0;
} }

View File

@ -170,7 +170,7 @@ static int mpc_decode(InputStream * inStream)
dc.audioFormat.channels = info.channels; dc.audioFormat.channels = info.channels;
dc.audioFormat.sampleRate = info.sample_freq; dc.audioFormat.sampleRate = info.sample_freq;
getOutputAudioFormat(&(dc.audioFormat), &(cb.audioFormat)); getOutputAudioFormat(&(dc.audioFormat), &(ob.audioFormat));
replayGainInfo = newReplayGainInfo(); replayGainInfo = newReplayGainInfo();
replayGainInfo->albumGain = info.gain_album * 0.01; replayGainInfo->albumGain = info.gain_album * 0.01;
@ -184,7 +184,7 @@ static int mpc_decode(InputStream * inStream)
if (dc.seek) { if (dc.seek) {
samplePos = dc.seekWhere * dc.audioFormat.sampleRate; samplePos = dc.seekWhere * dc.audioFormat.sampleRate;
if (mpc_decoder_seek_sample(&decoder, samplePos)) { if (mpc_decoder_seek_sample(&decoder, samplePos)) {
clearOutputBuffer(); ob_clear();
s16 = (mpd_sint16 *) chunk; s16 = (mpd_sint16 *) chunk;
chunkpos = 0; chunkpos = 0;
} else } else
@ -221,7 +221,7 @@ static int mpc_decode(InputStream * inStream)
bitRate = vbrUpdateBits * bitRate = vbrUpdateBits *
dc.audioFormat.sampleRate / 1152 / 1000; dc.audioFormat.sampleRate / 1152 / 1000;
sendDataToOutputBuffer(inStream, ob_send(inStream,
inStream->seekable, inStream->seekable,
chunk, chunkpos, chunk, chunkpos,
total_time, total_time,
@ -243,12 +243,12 @@ static int mpc_decode(InputStream * inStream)
bitRate = bitRate =
vbrUpdateBits * dc.audioFormat.sampleRate / 1152 / 1000; vbrUpdateBits * dc.audioFormat.sampleRate / 1152 / 1000;
sendDataToOutputBuffer(NULL, inStream->seekable, ob_send(NULL, inStream->seekable,
chunk, chunkpos, total_time, bitRate, chunk, chunkpos, total_time, bitRate,
replayGainInfo); replayGainInfo);
} }
flushOutputBuffer(); ob_flush();
freeReplayGainInfo(replayGainInfo); freeReplayGainInfo(replayGainInfo);

View File

@ -362,7 +362,7 @@ static int oggflac_decode(InputStream * inStream)
dc.audioFormat.sampleRate + 0.5; dc.audioFormat.sampleRate + 0.5;
if (OggFLAC__seekable_stream_decoder_seek_absolute if (OggFLAC__seekable_stream_decoder_seek_absolute
(decoder, sampleToSeek)) { (decoder, sampleToSeek)) {
clearOutputBuffer(); ob_clear();
data.time = ((float)sampleToSeek) / data.time = ((float)sampleToSeek) /
dc.audioFormat.sampleRate; dc.audioFormat.sampleRate;
data.position = 0; data.position = 0;
@ -381,7 +381,7 @@ static int oggflac_decode(InputStream * inStream)
/* send last little bit */ /* send last little bit */
if (data.chunk_length > 0 && !dc.stop) { if (data.chunk_length > 0 && !dc.stop) {
flacSendChunk(&data); flacSendChunk(&data);
flushOutputBuffer(); ob_flush();
} }
fail: fail:

View File

@ -275,7 +275,7 @@ static int oggvorbis_decode(InputStream * inStream)
while (1) { while (1) {
if (dc.seek) { if (dc.seek) {
if (0 == ov_time_seek_page(&vf, dc.seekWhere)) { if (0 == ov_time_seek_page(&vf, dc.seekWhere)) {
clearOutputBuffer(); ob_clear();
chunkpos = 0; chunkpos = 0;
} else } else
dc.seekError = 1; dc.seekError = 1;
@ -292,7 +292,7 @@ static int oggvorbis_decode(InputStream * inStream)
dc.audioFormat.sampleRate = vi->rate; dc.audioFormat.sampleRate = vi->rate;
if (dc.state == DECODE_STATE_START) { if (dc.state == DECODE_STATE_START) {
getOutputAudioFormat(&(dc.audioFormat), getOutputAudioFormat(&(dc.audioFormat),
&(cb.audioFormat)); &(ob.audioFormat));
dc.state = DECODE_STATE_DECODE; dc.state = DECODE_STATE_DECODE;
} }
comments = ov_comment(&vf, -1)->user_comments; comments = ov_comment(&vf, -1)->user_comments;
@ -316,7 +316,7 @@ static int oggvorbis_decode(InputStream * inStream)
if ((test = ov_bitrate_instant(&vf)) > 0) { if ((test = ov_bitrate_instant(&vf)) > 0) {
bitRate = test / 1000; bitRate = test / 1000;
} }
sendDataToOutputBuffer(inStream, ob_send(inStream,
inStream->seekable, inStream->seekable,
chunk, chunkpos, chunk, chunkpos,
ov_pcm_tell(&vf) / ov_pcm_tell(&vf) /
@ -329,7 +329,7 @@ static int oggvorbis_decode(InputStream * inStream)
} }
if (!dc.stop && chunkpos > 0) { if (!dc.stop && chunkpos > 0) {
sendDataToOutputBuffer(NULL, inStream->seekable, ob_send(NULL, inStream->seekable,
chunk, chunkpos, chunk, chunkpos,
ov_time_tell(&vf), bitRate, ov_time_tell(&vf), bitRate,
replayGainInfo); replayGainInfo);
@ -340,7 +340,7 @@ static int oggvorbis_decode(InputStream * inStream)
ov_clear(&vf); ov_clear(&vf);
flushOutputBuffer(); ob_flush();
return 0; return 0;
} }

View File

@ -166,7 +166,7 @@ static void wavpack_decode(WavpackContext *wpc, int canseek,
samplesreq = sizeof(chunk) / (4 * dc.audioFormat.channels); samplesreq = sizeof(chunk) / (4 * dc.audioFormat.channels);
getOutputAudioFormat(&(dc.audioFormat), &(cb.audioFormat)); getOutputAudioFormat(&(dc.audioFormat), &(ob.audioFormat));
dc.totalTime = (float)allsamples / dc.audioFormat.sampleRate; dc.totalTime = (float)allsamples / dc.audioFormat.sampleRate;
dc.state = DECODE_STATE_DECODE; dc.state = DECODE_STATE_DECODE;
@ -179,7 +179,7 @@ static void wavpack_decode(WavpackContext *wpc, int canseek,
if (canseek) { if (canseek) {
int where; int where;
clearOutputBuffer(); ob_clear();
where = dc.seekWhere * where = dc.seekWhere *
dc.audioFormat.sampleRate; dc.audioFormat.sampleRate;
@ -210,14 +210,14 @@ static void wavpack_decode(WavpackContext *wpc, int canseek,
format_samples(Bps, chunk, format_samples(Bps, chunk,
samplesgot * dc.audioFormat.channels); samplesgot * dc.audioFormat.channels);
sendDataToOutputBuffer(NULL, 0, chunk, ob_send(NULL, 0, chunk,
samplesgot * outsamplesize, samplesgot * outsamplesize,
file_time, bitrate, file_time, bitrate,
replayGainInfo); replayGainInfo);
} }
} while (samplesgot == samplesreq); } while (samplesgot == samplesreq);
flushOutputBuffer(); ob_flush();
} }
static char *wavpack_tag(WavpackContext *wpc, char *key) static char *wavpack_tag(WavpackContext *wpc, char *key)

View File

@ -22,37 +22,37 @@
#include "normalize.h" #include "normalize.h"
#include "playerData.h" #include "playerData.h"
void initOutputBuffer(unsigned int size) void ob_init(unsigned int size)
{ {
assert(size > 0); assert(size > 0);
memset(&cb.convState, 0, sizeof(ConvState)); memset(&ob.convState, 0, sizeof(ConvState));
cb.chunks = xmalloc(size * sizeof(*cb.chunks)); ob.chunks = xmalloc(size * sizeof(*ob.chunks));
cb.size = size; ob.size = size;
cb.begin = 0; ob.begin = 0;
cb.end = 0; ob.end = 0;
cb.chunks[0].chunkSize = 0; ob.chunks[0].chunkSize = 0;
} }
void output_buffer_free(void) void ob_free(void)
{ {
assert(cb.chunks != NULL); assert(ob.chunks != NULL);
free(cb.chunks); free(ob.chunks);
} }
void clearOutputBuffer(void) void ob_clear(void)
{ {
cb.end = cb.begin; ob.end = ob.begin;
cb.chunks[cb.end].chunkSize = 0; ob.chunks[ob.end].chunkSize = 0;
} }
/** return the index of the chunk after i */ /** return the index of the chunk after i */
static inline unsigned successor(unsigned i) static inline unsigned successor(unsigned i)
{ {
assert(i <= cb.size); assert(i <= ob.size);
++i; ++i;
return i == cb.size ? 0 : i; return i == ob.size ? 0 : i;
} }
/** /**
@ -61,13 +61,13 @@ static inline unsigned successor(unsigned i)
*/ */
static void output_buffer_expand(unsigned i) static void output_buffer_expand(unsigned i)
{ {
int was_empty = outputBufferEmpty(); int was_empty = ob_is_empty();
assert(i == (cb.end + 1) % cb.size); assert(i == (ob.end + 1) % ob.size);
assert(i != cb.end); assert(i != ob.end);
cb.end = i; ob.end = i;
cb.chunks[i].chunkSize = 0; ob.chunks[i].chunkSize = 0;
if (was_empty) if (was_empty)
/* if the buffer was empty, the player thread might be /* if the buffer was empty, the player thread might be
waiting for us; wake it up now that another decoded waiting for us; wake it up now that another decoded
@ -75,13 +75,13 @@ static void output_buffer_expand(unsigned i)
decoder_wakeup_player(); decoder_wakeup_player();
} }
void flushOutputBuffer(void) void ob_flush(void)
{ {
OutputBufferChunk *chunk = outputBufferGetChunk(cb.end); ob_chunk *chunk = ob_get_chunk(ob.end);
if (chunk->chunkSize > 0) { if (chunk->chunkSize > 0) {
unsigned int next = successor(cb.end); unsigned int next = successor(ob.end);
if (next == cb.begin) if (next == ob.begin)
/* all buffers are full; we have to wait for /* all buffers are full; we have to wait for
the player to free one, so don't flush the player to free one, so don't flush
right now */ right now */
@ -91,54 +91,54 @@ void flushOutputBuffer(void)
} }
} }
int outputBufferEmpty(void) int ob_is_empty(void)
{ {
return cb.begin == cb.end; return ob.begin == ob.end;
} }
void outputBufferShift(void) void ob_shift(void)
{ {
assert(cb.begin != cb.end); assert(ob.begin != ob.end);
assert(cb.begin < cb.size); assert(ob.begin < ob.size);
cb.begin = successor(cb.begin); ob.begin = successor(ob.begin);
} }
unsigned int outputBufferRelative(const unsigned i) unsigned int ob_relative(const unsigned i)
{ {
if (i >= cb.begin) if (i >= ob.begin)
return i - cb.begin; return i - ob.begin;
else else
return i + cb.size - cb.begin; return i + ob.size - ob.begin;
} }
unsigned availableOutputBuffer(void) unsigned ob_available(void)
{ {
return outputBufferRelative(cb.end); return ob_relative(ob.end);
} }
int outputBufferAbsolute(const unsigned relative) int ob_absolute(const unsigned relative)
{ {
unsigned i, max; unsigned i, max;
max = cb.end; max = ob.end;
if (max < cb.begin) if (max < ob.begin)
max += cb.size; max += ob.size;
i = (unsigned)cb.begin + relative; i = (unsigned)ob.begin + relative;
if (i >= max) if (i >= max)
return -1; return -1;
if (i >= cb.size) if (i >= ob.size)
i -= cb.size; i -= ob.size;
return (int)i; return (int)i;
} }
OutputBufferChunk * outputBufferGetChunk(const unsigned i) ob_chunk * ob_get_chunk(const unsigned i)
{ {
assert(i < cb.size); assert(i < ob.size);
return &cb.chunks[i]; return &ob.chunks[i];
} }
/** /**
@ -154,14 +154,14 @@ static int tailChunk(InputStream * inStream,
int seekable, float data_time, mpd_uint16 bitRate) int seekable, float data_time, mpd_uint16 bitRate)
{ {
unsigned int next; unsigned int next;
OutputBufferChunk *chunk; ob_chunk *chunk;
chunk = outputBufferGetChunk(cb.end); chunk = ob_get_chunk(ob.end);
assert(chunk->chunkSize <= sizeof(chunk->data)); assert(chunk->chunkSize <= sizeof(chunk->data));
if (chunk->chunkSize == sizeof(chunk->data)) { if (chunk->chunkSize == sizeof(chunk->data)) {
/* this chunk is full; allocate a new chunk */ /* this chunk is full; allocate a new chunk */
next = successor(cb.end); next = successor(ob.end);
while (cb.begin == next) { while (ob.begin == next) {
/* all chunks are full of decoded data; wait /* all chunks are full of decoded data; wait
for the player to free one */ for the player to free one */
@ -183,7 +183,7 @@ static int tailChunk(InputStream * inStream,
} }
output_buffer_expand(next); output_buffer_expand(next);
chunk = outputBufferGetChunk(next); chunk = ob_get_chunk(next);
assert(chunk->chunkSize == 0); assert(chunk->chunkSize == 0);
} }
@ -195,10 +195,10 @@ static int tailChunk(InputStream * inStream,
chunk->times = data_time; chunk->times = data_time;
} }
return cb.end; return ob.end;
} }
int sendDataToOutputBuffer(InputStream * inStream, int ob_send(InputStream * inStream,
int seekable, void *dataIn, int seekable, void *dataIn,
size_t dataInLen, float data_time, mpd_uint16 bitRate, size_t dataInLen, float data_time, mpd_uint16 bitRate,
ReplayGainInfo * replayGainInfo) ReplayGainInfo * replayGainInfo)
@ -208,14 +208,14 @@ int sendDataToOutputBuffer(InputStream * inStream,
size_t datalen; size_t datalen;
static char *convBuffer; static char *convBuffer;
static size_t convBufferLen; static size_t convBufferLen;
OutputBufferChunk *chunk = NULL; ob_chunk *chunk = NULL;
if (cmpAudioFormat(&(cb.audioFormat), &(dc.audioFormat)) == 0) { if (cmpAudioFormat(&(ob.audioFormat), &(dc.audioFormat)) == 0) {
data = dataIn; data = dataIn;
datalen = dataInLen; datalen = dataInLen;
} else { } else {
datalen = pcm_sizeOfConvBuffer(&(dc.audioFormat), dataInLen, datalen = pcm_sizeOfConvBuffer(&(dc.audioFormat), dataInLen,
&(cb.audioFormat)); &(ob.audioFormat));
if (datalen > convBufferLen) { if (datalen > convBufferLen) {
if (convBuffer != NULL) if (convBuffer != NULL)
free(convBuffer); free(convBuffer);
@ -224,14 +224,14 @@ int sendDataToOutputBuffer(InputStream * inStream,
} }
data = convBuffer; data = convBuffer;
datalen = pcm_convertAudioFormat(&(dc.audioFormat), dataIn, datalen = pcm_convertAudioFormat(&(dc.audioFormat), dataIn,
dataInLen, &(cb.audioFormat), dataInLen, &(ob.audioFormat),
data, &(cb.convState)); data, &(ob.convState));
} }
if (replayGainInfo && (replayGainState != REPLAYGAIN_OFF)) if (replayGainInfo && (replayGainState != REPLAYGAIN_OFF))
doReplayGain(replayGainInfo, data, datalen, &cb.audioFormat); doReplayGain(replayGainInfo, data, datalen, &ob.audioFormat);
else if (normalizationEnabled) else if (normalizationEnabled)
normalizeData(data, datalen, &cb.audioFormat); normalizeData(data, datalen, &ob.audioFormat);
while (datalen) { while (datalen) {
int chunk_index = tailChunk(inStream, seekable, int chunk_index = tailChunk(inStream, seekable,
@ -239,7 +239,7 @@ int sendDataToOutputBuffer(InputStream * inStream,
if (chunk_index < 0) if (chunk_index < 0)
return chunk_index; return chunk_index;
chunk = outputBufferGetChunk(chunk_index); chunk = ob_get_chunk(chunk_index);
dataToSend = sizeof(chunk->data) - chunk->chunkSize; dataToSend = sizeof(chunk->data) - chunk->chunkSize;
if (dataToSend > datalen) if (dataToSend > datalen)
@ -252,14 +252,14 @@ int sendDataToOutputBuffer(InputStream * inStream,
} }
if (chunk != NULL && chunk->chunkSize == sizeof(chunk->data)) if (chunk != NULL && chunk->chunkSize == sizeof(chunk->data))
flushOutputBuffer(); ob_flush();
return 0; return 0;
} }
void output_buffer_skip(unsigned num) void ob_skip(unsigned num)
{ {
int i = outputBufferAbsolute(num); int i = ob_absolute(num);
if (i >= 0) if (i >= 0)
cb.begin = i; ob.begin = i;
} }

View File

@ -36,14 +36,14 @@ typedef struct _OutputBufferChunk {
mpd_uint16 bitRate; mpd_uint16 bitRate;
float times; float times;
char data[CHUNK_SIZE]; char data[CHUNK_SIZE];
} OutputBufferChunk; } ob_chunk;
/** /**
* A ring set of buffers where the decoder appends data after the end, * A ring set of buffers where the decoder appends data after the end,
* and the player consumes data from the beginning. * and the player consumes data from the beginning.
*/ */
typedef struct _OutputBuffer { typedef struct _OutputBuffer {
OutputBufferChunk *chunks; ob_chunk *chunks;
unsigned int size; unsigned int size;
@ -57,45 +57,45 @@ typedef struct _OutputBuffer {
ConvState convState; ConvState convState;
} OutputBuffer; } OutputBuffer;
void initOutputBuffer(unsigned int size); void ob_init(unsigned int size);
void output_buffer_free(void); void ob_free(void);
void clearOutputBuffer(void); void ob_clear(void);
void flushOutputBuffer(void); void ob_flush(void);
/** is the buffer empty? */ /** is the buffer empty? */
int outputBufferEmpty(void); int ob_is_empty(void);
void outputBufferShift(void); void ob_shift(void);
/** /**
* what is the position of the specified chunk number, relative to * what is the position of the specified chunk number, relative to
* the first chunk in use? * the first chunk in use?
*/ */
unsigned int outputBufferRelative(const unsigned i); unsigned int ob_relative(const unsigned i);
/** determine the number of decoded chunks */ /** determine the number of decoded chunks */
unsigned availableOutputBuffer(void); unsigned ob_available(void);
/** /**
* Get the absolute index of the nth used chunk after the first one. * Get the absolute index of the nth used chunk after the first one.
* Returns -1 if there is no such chunk. * Returns -1 if there is no such chunk.
*/ */
int outputBufferAbsolute(const unsigned relative); int ob_absolute(const unsigned relative);
OutputBufferChunk * outputBufferGetChunk(const unsigned i); ob_chunk * ob_get_chunk(const unsigned i);
/* we send inStream for buffering the inputStream while waiting to /* we send inStream for buffering the inputStream while waiting to
send the next chunk */ send the next chunk */
int sendDataToOutputBuffer(InputStream * inStream, int ob_send(InputStream * inStream,
int seekable, int seekable,
void *data, void *data,
size_t datalen, size_t datalen,
float data_time, float data_time,
mpd_uint16 bitRate, ReplayGainInfo * replayGainInfo); mpd_uint16 bitRate, ReplayGainInfo * replayGainInfo);
void output_buffer_skip(unsigned num); void ob_skip(unsigned num);
#endif #endif

View File

@ -29,7 +29,7 @@ unsigned int buffered_before_play;
static PlayerData playerData_pd; static PlayerData playerData_pd;
PlayerControl pc; PlayerControl pc;
DecoderControl dc; DecoderControl dc;
OutputBuffer cb; /* rename this to 'ob' */ OutputBuffer ob;
void initPlayerData(void) void initPlayerData(void)
{ {
@ -77,7 +77,7 @@ void initPlayerData(void)
playerData_pd.audioDeviceStates = xmalloc(device_array_size); playerData_pd.audioDeviceStates = xmalloc(device_array_size);
initOutputBuffer(buffered_chunks); ob_init(buffered_chunks);
notifyInit(&pc.notify); notifyInit(&pc.notify);
pc.error = PLAYER_ERROR_NOERROR; pc.error = PLAYER_ERROR_NOERROR;
@ -104,6 +104,6 @@ void freePlayerData(void)
* access playerData_pd and we need to keep it available for them */ * access playerData_pd and we need to keep it available for them */
waitpid(-1, NULL, 0); waitpid(-1, NULL, 0);
output_buffer_free(); ob_free();
free(playerData_pd.audioDeviceStates); free(playerData_pd.audioDeviceStates);
} }

View File

@ -28,7 +28,7 @@
extern unsigned int buffered_before_play; extern unsigned int buffered_before_play;
extern PlayerControl pc; extern PlayerControl pc;
extern DecoderControl dc; extern DecoderControl dc;
extern OutputBuffer cb; /* rename this to 'ob' */ extern OutputBuffer ob;
typedef struct _PlayerData { typedef struct _PlayerData {
mpd_uint8 *audioDeviceStates; mpd_uint8 *audioDeviceStates;