new OutputBuffer abstraction stuff, implemented for mp3, now need to

implement in other decoders

git-svn-id: https://svn.musicpd.org/mpd/trunk@940 09075e82-0dd4-0310-85a5-a0d7c8717e4f
This commit is contained in:
Warren Dukes 2004-05-07 15:58:04 +00:00
parent 9196023f14
commit 3794126e56
18 changed files with 103 additions and 75 deletions

View File

@ -5,13 +5,15 @@ mpd_headers = buffer2array.h interface.h command.h playlist.h ls.h \
tag.h player.h listen.h conf.h ogg_decode.h volume.h flac_decode.h \
audio.h playerData.h stats.h myfprintf.h sig_handlers.h decode.h log.h \
audiofile_decode.h charConv.h permission.h mpd_types.h pcm_utils.h \
mp4_decode.h aac_decode.h signal_check.h utf8.h inputStream.h
mp4_decode.h aac_decode.h signal_check.h utf8.h inputStream.h \
outputBuffer.h
mpd_SOURCES = main.c buffer2array.c interface.c command.c playlist.c ls.c \
song.c list.c directory.c tables.c utils.c path.c mp3_decode.c \
tag.c player.c listen.c conf.c ogg_decode.c volume.c flac_decode.c \
audio.c playerData.c stats.c myfprintf.c sig_handlers.c decode.c log.c \
audiofile_decode.c charConv.c permission.c pcm_utils.c mp4_decode.c \
aac_decode.c signal_check.c utf8.c inputStream.c $(mpd_headers)
aac_decode.c signal_check.c utf8.c inputStream.c outputBuffer.c \
$(mpd_headers)
mpd_CFLAGS = $(MPD_CFLAGS)
mpd_LDADD = $(MPD_LIBS) $(ID3_LIB) $(MAD_LIB) $(MP4FF_LIB)

View File

@ -250,7 +250,7 @@ int getAacTotalTime(char * file) {
}
int aac_decode(Buffer * cb, AudioFormat * af, DecoderControl * dc) {
int aac_decode(OutputBuffer * cb, AudioFormat * af, DecoderControl * dc) {
float time;
float totalTime;
faacDecHandle decoder;

View File

@ -27,7 +27,7 @@
int getAacTotalTime(char * file);
int aac_decode(Buffer * cb, AudioFormat * af, DecoderControl * dc);
int aac_decode(OutputBuffer * cb, AudioFormat * af, DecoderControl * dc);
#endif /* HAVE_FAAD */

View File

@ -51,7 +51,7 @@ int getAudiofileTotalTime(char * file)
return time;
}
int audiofile_decode(Buffer * cb, AudioFormat * af, DecoderControl * dc)
int audiofile_decode(OutputBuffer * cb, AudioFormat * af, DecoderControl * dc)
{
int fs, frame_count;
AFfilehandle af_fp;

View File

@ -27,7 +27,7 @@
#include "playerData.h"
int audiofile_decode(Buffer * cb, AudioFormat * af, DecoderControl * dc);;
int audiofile_decode(OutputBuffer * cb, AudioFormat * af, DecoderControl * dc);
int getAudiofileTotalTime(char * file);

View File

@ -112,7 +112,7 @@ int calculateCrossFadeChunks(PlayerControl * pc, AudioFormat * af) {
}
int waitOnDecode(PlayerControl * pc, AudioFormat * af, DecoderControl * dc,
Buffer * cb)
OutputBuffer * cb)
{
while(decode_pid && *decode_pid>0 && dc->start) my_usleep(1000);
@ -143,7 +143,7 @@ int waitOnDecode(PlayerControl * pc, AudioFormat * af, DecoderControl * dc,
}
void decodeSeek(PlayerControl * pc, AudioFormat * af, DecoderControl * dc,
Buffer * cb)
OutputBuffer * cb)
{
if(decode_pid && *decode_pid>0) {
cb->next = -1;
@ -217,7 +217,7 @@ void decodeSeek(PlayerControl * pc, AudioFormat * af, DecoderControl * dc,
return; \
}
int decoderInit(PlayerControl * pc, Buffer * cb, AudioFormat *af,
int decoderInit(PlayerControl * pc, OutputBuffer * cb, AudioFormat *af,
DecoderControl * dc) {
int pid;
int ret;
@ -311,7 +311,7 @@ int decoderInit(PlayerControl * pc, Buffer * cb, AudioFormat *af,
* parent process does playing audio
*/
void decode() {
Buffer * cb;
OutputBuffer * cb;
PlayerControl * pc;
AudioFormat * af;
DecoderControl * dc;

View File

@ -37,7 +37,7 @@ typedef struct {
float time;
int bitRate;
FLAC__uint64 position;
Buffer * cb;
OutputBuffer * cb;
AudioFormat * af;
DecoderControl * dc;
char * file;
@ -65,7 +65,7 @@ FLAC__SeekableStreamDecoderLengthStatus flacLength(
const FLAC__SeekableStreamDecoder *, FLAC__uint64 *, void *);
FLAC__bool flacEOF(const FLAC__SeekableStreamDecoder *, void *);
void flacPlayFile(char *file, Buffer * cb, AudioFormat * af,
void flacPlayFile(char *file, OutputBuffer * cb, AudioFormat * af,
DecoderControl *dc)
{
FLAC__SeekableStreamDecoder * flacDec;
@ -392,7 +392,7 @@ int getFlacTotalTime(char * file) {
return (int)(totalTime+0.5);
}
int flac_decode(Buffer * cb, AudioFormat * af, DecoderControl * dc) {
int flac_decode(OutputBuffer * cb, AudioFormat * af, DecoderControl * dc) {
if(flac_getAudioFormatAndTime(dc->file,af,&(cb->totalTime))<0) {
ERROR("\"%s\" doesn't seem to be a flac\n",dc->file);
return -1;

View File

@ -25,7 +25,7 @@
#include <stdio.h>
int flac_decode(Buffer * cb, AudioFormat * af, DecoderControl * dc);
int flac_decode(OutputBuffer * cb, AudioFormat * af, DecoderControl * dc);
int getFlacTotalTime(char * file);

View File

@ -37,6 +37,7 @@
#include "log.h"
#include "utils.h"
#include "inputStream.h"
#include "outputBuffer.h"
#include <stdio.h>
#include <string.h>
@ -111,13 +112,15 @@ signed long audio_linear_dither(unsigned int bits, mad_fixed_t sample, struct au
/* decoder stuff is based on madlld */
#define MP3_DATA_OUTPUT_BUFFER_SIZE 4096
typedef struct _mp3DecodeData {
struct mad_stream stream;
struct mad_frame frame;
struct mad_synth synth;
mad_timer_t timer;
unsigned char readBuffer[READ_BUFFER_SIZE];
char outputBuffer[CHUNK_SIZE];
char outputBuffer[MP3_DATA_OUTPUT_BUFFER_SIZE];
char * outputPtr;
char * outputBufferEnd;
float totalTime;
@ -141,7 +144,7 @@ int initMp3DecodeData(mp3DecodeData * data, char * file) {
if(ret<0) return -1;
data->outputPtr = data->outputBuffer;
data->outputBufferEnd = data->outputBuffer+CHUNK_SIZE;
data->outputBufferEnd = data->outputBuffer+MP3_DATA_OUTPUT_BUFFER_SIZE;
data->muteFrame = 0;
data->highestFrame = 0;
data->maxFrames = 0;
@ -406,29 +409,7 @@ int openMp3(char * file, mp3DecodeData * data) {
return 0;
}
int mp3ChildSendData(mp3DecodeData * data, Buffer * cb, DecoderControl * dc) {
while(cb->begin==cb->end && cb->wrap && !dc->stop && !dc->seek)
my_usleep(10000);
if(dc->stop) return -1;
/* just for now, so it doesn't hang */
if(dc->seek) return 0;
/* be sure to remove this! */
memcpy(cb->chunks+cb->end*CHUNK_SIZE,data->outputBuffer,CHUNK_SIZE);
cb->chunkSize[cb->end] = data->outputPtr-data->outputBuffer;
cb->bitRate[cb->end] = data->bitRate/1000;
cb->times[cb->end] = data->elapsedTime;
cb->end++;
if(cb->end>=buffered_chunks) {
cb->end = 0;
cb->wrap = 1;
}
return 0;
}
int mp3Read(mp3DecodeData * data, Buffer * cb, DecoderControl * dc) {
int mp3Read(mp3DecodeData * data, OutputBuffer * cb, DecoderControl * dc) {
static int i;
static int ret;
static struct audio_dither dither;
@ -464,6 +445,8 @@ int mp3Read(mp3DecodeData * data, Buffer * cb, DecoderControl * dc) {
}
}
else {
long ret;
mad_synth_frame(&data->synth,&data->frame);
for(i=0;i<(data->synth).pcm.length;i++) {
@ -484,12 +467,24 @@ int mp3Read(mp3DecodeData * data, Buffer * cb, DecoderControl * dc) {
}
if(data->outputPtr==data->outputBufferEnd) {
if(mp3ChildSendData(data,cb,dc)<0) {
data->flush = 0;
ret = sendDataToOutputBuffer(cb,dc,
0,data->outputBuffer,
MP3_DATA_OUTPUT_BUFFER_SIZE,
data->elapsedTime,
data->bitRate/1000);
if(ret == OUTPUT_BUFFER_DC_STOP) {
return DECODE_BREAK;
}
data->outputPtr = data->outputBuffer;
if(dc->seek) break;
if(ret >= 0) {
memmove(data->outputBuffer,
data->outputBuffer+ret,
MP3_DATA_OUTPUT_BUFFER_SIZE-
ret);
data->outputPtr-=ret;
}
else data->outputPtr = data->outputBuffer;
if(ret == OUTPUT_BUFFER_DC_SEEK) break;
}
}
@ -534,7 +529,7 @@ void initAudioFormatFromMp3DecodeData(mp3DecodeData * data, AudioFormat * af) {
af->channels = MAD_NCHANNELS(&(data->frame).header);
}
int mp3_decode(Buffer * cb, AudioFormat * af, DecoderControl * dc) {
int mp3_decode(OutputBuffer * cb, AudioFormat * af, DecoderControl * dc) {
mp3DecodeData data;
if(openMp3(dc->file,&data) < 0) {
@ -550,7 +545,9 @@ int mp3_decode(Buffer * cb, AudioFormat * af, DecoderControl * dc) {
while(mp3Read(&data,cb,dc)!=DECODE_BREAK);
/* send last little bit if not dc->stop */
if(data.outputPtr!=data.outputBuffer && data.flush) {
mp3ChildSendData(&data,cb,dc);
sendDataToOutputBuffer(cb,dc,1,data.outputBuffer,
data.outputPtr-data.outputBuffer,
data.elapsedTime,data.bitRate/1000);
}
mp3DecodeDataFinalize(&data);
@ -567,4 +564,4 @@ int mp3_decode(Buffer * cb, AudioFormat * af, DecoderControl * dc) {
}
#endif
/* vim:set shiftwidth=4 tabstop=8 expandtab: */
/* vim:set shiftwidth=8 tabstop=8 expandtab: */

View File

@ -28,7 +28,7 @@
/* this is primarily used in tag.c */
int getMp3TotalTime(char * file);
int mp3_decode(Buffer * cb, AudioFormat * af, DecoderControl * dc);
int mp3_decode(OutputBuffer * cb, AudioFormat * af, DecoderControl * dc);
#endif

View File

@ -84,7 +84,7 @@ uint32_t mp4_inputStreamSeekCallback(void *inStream, uint64_t position) {
}
int mp4_decode(Buffer * cb, AudioFormat * af, DecoderControl * dc) {
int mp4_decode(OutputBuffer * cb, AudioFormat * af, DecoderControl * dc) {
mp4ff_t * mp4fh;
mp4ff_callback_t * mp4cb;
int32_t track;

View File

@ -29,7 +29,7 @@
int mp4_getAACTrack(mp4ff_t *infile);
int mp4_decode(Buffer * cb, AudioFormat * af, DecoderControl * dc);
int mp4_decode(OutputBuffer * cb, AudioFormat * af, DecoderControl * dc);
uint32_t mp4_inputStreamReadCallback(void *inStream, void *buffer,
uint32_t length);

View File

@ -82,7 +82,7 @@ long ogg_tell_cb(void * inStream) {
return ((InputStream *)inStream)->offset;
}
int ogg_decode(Buffer * cb, AudioFormat * af, DecoderControl * dc)
int ogg_decode(OutputBuffer * cb, AudioFormat * af, DecoderControl * dc)
{
OggVorbis_File vf;
ov_callbacks callbacks;

View File

@ -25,7 +25,7 @@
#include <stdio.h>
int ogg_decode(Buffer * cb, AudioFormat * af, DecoderControl * dc);
int ogg_decode(OutputBuffer * cb, AudioFormat * af, DecoderControl * dc);
int getOggTotalTime(char * file);

View File

@ -20,17 +20,13 @@
#include "pcm_utils.h"
#include "playerData.h"
#include "log.h"
#include "utils.h"
#include <string.h>
#include <errno.h>
#define OUTPUT_BUFFER_DC_STOP -1
#define OUTPUT_BUFFER_DC_SEEK -2
long sendDataToOutputBuffer(Buffer * cb, DecoderControl * dc, int flushAllData,
char * data, long datalen, float time, mpd_uint16 bitRate)
long sendDataToOutputBuffer(OutputBuffer * cb, DecoderControl * dc,
int flushAllData, char * data, long datalen, float time,
mpd_uint16 bitRate)
{
long dataSent = 0;
long dataToSend;

45
src/outputBuffer.h Normal file
View File

@ -0,0 +1,45 @@
/* the Music Player Daemon (MPD)
* (c)2003-2004 by Warren Dukes (shank@mercury.chem.pitt.edu)
* This project's homepage is: http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef OUTPUT_BUFFER_H
#define OUTPUT_BUFFER_H
#include "mpd_types.h"
#include "decode.h"
#define OUTPUT_BUFFER_DC_STOP -1
#define OUTPUT_BUFFER_DC_SEEK -2
typedef struct _OutputBuffer {
char * volatile chunks;
mpd_uint16 * volatile chunkSize;
mpd_uint16 * volatile bitRate;
float * volatile times;
mpd_sint16 volatile begin;
mpd_sint16 volatile end;
mpd_sint16 volatile next;
mpd_sint8 volatile wrap;
float totalTime;
} OutputBuffer;
long sendDataToOutputBuffer(OutputBuffer * cb, DecoderControl * dc,
int flushAllData, char * data, long datalen, float time,
mpd_uint16 bitRate);
#endif
/* vim:set shiftwidth=4 tabstop=8 expandtab: */

View File

@ -39,7 +39,7 @@ void initPlayerData() {
int crossfade = 0;
size_t bufferSize;
size_t allocationSize;
Buffer * buffer;
OutputBuffer * buffer;
bufferSize = strtol(getConf()[CONF_BUFFER_SIZE],&test,10);
if(*test!='\0' || bufferSize<=0) {

View File

@ -25,6 +25,7 @@
#include "player.h"
#include "decode.h"
#include "mpd_types.h"
#include "outputBuffer.h"
/* pick 1020 since its devisible for 8,16,24, and 32-bit audio */
#define CHUNK_SIZE 1020
@ -32,20 +33,8 @@
extern int buffered_before_play;
extern int buffered_chunks;
typedef struct _Buffer {
char * volatile chunks;
mpd_uint16 * volatile chunkSize;
mpd_uint16 * volatile bitRate;
float * volatile times;
mpd_sint16 volatile begin;
mpd_sint16 volatile end;
mpd_sint16 volatile next;
mpd_sint8 volatile wrap;
float totalTime;
} Buffer;
typedef struct _PlayerData {
Buffer buffer;
OutputBuffer buffer;
AudioFormat audioFormat;
PlayerControl playerControl;
DecoderControl decoderControl;
@ -54,7 +43,6 @@ typedef struct _PlayerData {
void initPlayerData();
PlayerData * getPlayerData();
Buffer * getBuffer();
void freePlayerData();