added struct decoder

The decoder struct should later be made opaque to the decoder plugin,
because maintaining a stable struct ABI is quite difficult.  The ABI
should only consist of a small number of stable functions.
This commit is contained in:
Max Kellermann 2008-08-26 08:27:04 +02:00
parent 241cd043ca
commit 154aa496e8
17 changed files with 121 additions and 30 deletions

View File

@ -40,6 +40,8 @@ mpd_headers = \
conf.h \
dbUtils.h \
decode.h \
decoder_api.h \
decoder_internal.h \
directory.h \
gcc.h \
inputPlugin.h \

View File

@ -17,6 +17,7 @@
*/
#include "decode.h"
#include "decoder_internal.h"
#include "player.h"
#include "playerData.h"
@ -205,6 +206,7 @@ static void processDecodeInput(int *pause_r, unsigned int *bbp_r,
static void decodeStart(void)
{
struct decoder decoder;
int ret;
int close_instream = 1;
InputStream inStream;
@ -250,7 +252,7 @@ static void decodeStart(void)
if (plugin->tryDecodeFunc
&& !plugin->tryDecodeFunc(&inStream))
continue;
ret = plugin->streamDecodeFunc(&inStream);
ret = plugin->streamDecodeFunc(&decoder, &inStream);
break;
}
@ -267,7 +269,8 @@ static void decodeStart(void)
if (plugin->tryDecodeFunc &&
!plugin->tryDecodeFunc(&inStream))
continue;
ret = plugin->streamDecodeFunc(&inStream);
decoder.plugin = plugin;
ret = plugin->streamDecodeFunc(&decoder, &inStream);
break;
}
}
@ -278,7 +281,9 @@ static void decodeStart(void)
/* we already know our mp3Plugin supports streams, no
* need to check for stream{Types,DecodeFunc} */
if ((plugin = getInputPluginFromName("mp3"))) {
ret = plugin->streamDecodeFunc(&inStream);
decoder.plugin = plugin;
ret = plugin->streamDecodeFunc(&decoder,
&inStream);
}
}
} else {
@ -295,10 +300,13 @@ static void decodeStart(void)
if (plugin->fileDecodeFunc) {
closeInputStream(&inStream);
close_instream = 0;
ret = plugin->fileDecodeFunc(path_max_fs);
decoder.plugin = plugin;
ret = plugin->fileDecodeFunc(&decoder,
path_max_fs);
break;
} else if (plugin->streamDecodeFunc) {
ret = plugin->streamDecodeFunc(&inStream);
decoder.plugin = plugin;
ret = plugin->streamDecodeFunc(&decoder, &inStream);
break;
}
}

37
src/decoder_api.h Normal file
View File

@ -0,0 +1,37 @@
/* the Music Player Daemon (MPD)
* Copyright (C) 2003-2007 by Warren Dukes (warren.dukes@gmail.com)
* Copyright (C) 2008 Max Kellermann <max@duempel.org>
* 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 DECODER_API_H
#define DECODER_API_H
/*
* This is the public API which is used by decoder plugins to
* communicate with the mpd core.
*
*/
#include "inputPlugin.h"
/**
* Opaque handle which the decoder plugin passes to the functions in
* this header.
*/
struct decoder;
#endif

28
src/decoder_internal.h Normal file
View File

@ -0,0 +1,28 @@
/* the Music Player Daemon (MPD)
* Copyright (C) 2008 Max Kellermann <max@duempel.org>
* 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 DECODER_INTERNAL_H
#define DECODER_INTERNAL_H
#include "decoder_api.h"
struct decoder {
InputPlugin *plugin;
};
#endif

View File

@ -27,6 +27,8 @@
#define INPUT_PLUGIN_STREAM_FILE 0x01
#define INPUT_PLUGIN_STREAM_URL 0x02
struct decoder;
/* optional, set this to NULL if the InputPlugin doesn't have/need one
* this must return < 0 if there is an error and >= 0 otherwise */
typedef int (*InputPlugin_initFunc) (void);
@ -42,14 +44,16 @@ typedef unsigned int (*InputPlugin_tryDecodeFunc) (InputStream *);
* and networked (HTTP) connections.
*
* returns -1 on error, 0 on success */
typedef int (*InputPlugin_streamDecodeFunc) (InputStream *);
typedef int (*InputPlugin_streamDecodeFunc) (struct decoder *,
InputStream *);
/* use this if and only if your InputPlugin can only be passed a filename or
* handle as input, and will not allow callbacks to be set (like Ogg-Vorbis
* and FLAC libraries allow)
*
* returns -1 on error, 0 on success */
typedef int (*InputPlugin_fileDecodeFunc) (char *path);
typedef int (*InputPlugin_fileDecodeFunc) (struct decoder *,
char *path);
/* file should be the full path! Returns NULL if a tag cannot be found
* or read */

View File

@ -30,12 +30,14 @@
#include <FLAC/format.h>
#include <FLAC/metadata.h>
void init_FlacData(FlacData * data, InputStream * inStream)
void init_FlacData(FlacData * data, struct decoder * decoder,
InputStream * inStream)
{
data->chunk_length = 0;
data->time = 0;
data->position = 0;
data->bitRate = 0;
data->decoder = decoder;
data->inStream = inStream;
data->replayGainInfo = NULL;
data->tag = NULL;

View File

@ -144,13 +144,15 @@ typedef struct {
float time;
unsigned int bitRate;
FLAC__uint64 position;
struct decoder *decoder;
InputStream *inStream;
ReplayGainInfo *replayGainInfo;
MpdTag *tag;
} FlacData;
/* initializes a given FlacData struct */
void init_FlacData(FlacData * data, InputStream * inStream);
void init_FlacData(FlacData * data, struct decoder * decoder,
InputStream * inStream);
void flac_metadata_common_cb(const FLAC__StreamMetadata * block,
FlacData * data);
void flac_error_common_cb(const char *plugin,

View File

@ -278,7 +278,7 @@ static int getAacTotalTime(char *file)
return file_time;
}
static int aac_decode(char *path)
static int aac_decode(mpd_unused struct decoder * mpd_decoder, char *path)
{
float file_time;
float totalTime;

View File

@ -40,7 +40,7 @@ static int getAudiofileTotalTime(char *file)
return total_time;
}
static int audiofile_decode(char *path)
static int audiofile_decode(mpd_unused struct decoder * decoder, char *path)
{
int fs, frame_count;
AFfilehandle af_fp;

View File

@ -376,7 +376,8 @@ static MpdTag *flacTagDup(char *file)
return ret;
}
static int flac_decode_internal(InputStream * inStream, int is_ogg)
static int flac_decode_internal(struct decoder * decoder,
InputStream * inStream, int is_ogg)
{
flac_decoder *flacDec;
FlacData data;
@ -384,7 +385,7 @@ static int flac_decode_internal(InputStream * inStream, int is_ogg)
if (!(flacDec = flac_new()))
return -1;
init_FlacData(&data, inStream);
init_FlacData(&data, decoder, inStream);
#if defined(FLAC_API_VERSION_CURRENT) && FLAC_API_VERSION_CURRENT > 7
if(!FLAC__stream_decoder_set_metadata_respond(flacDec, FLAC__METADATA_TYPE_VORBIS_COMMENT))
@ -458,9 +459,9 @@ fail:
return 0;
}
static int flac_decode(InputStream * inStream)
static int flac_decode(struct decoder * decoder, InputStream * inStream)
{
return flac_decode_internal(inStream, 0);
return flac_decode_internal(decoder, inStream, 0);
}
#if !defined(FLAC_API_VERSION_CURRENT) || FLAC_API_VERSION_CURRENT <= 7
@ -499,9 +500,9 @@ out:
return ret;
}
static int oggflac_decode(InputStream * inStream)
static int oggflac_decode(struct decoder *decoder, InputStream * inStream)
{
return flac_decode_internal(inStream, 1);
return flac_decode_internal(decoder, inStream, 1);
}
static unsigned int oggflac_try_decode(InputStream * inStream)

View File

@ -159,7 +159,7 @@ static void mod_close(mod_Data * data)
free(data);
}
static int mod_decode(char *path)
static int mod_decode(mpd_unused struct decoder * decoder, char *path)
{
mod_Data *data;
float total_time = 0.0;

View File

@ -1015,7 +1015,8 @@ static void initAudioFormatFromMp3DecodeData(mp3DecodeData * data,
af->channels = MAD_NCHANNELS(&(data->frame).header);
}
static int mp3_decode(InputStream * inStream)
static int mp3_decode(mpd_unused struct decoder * decoder,
InputStream * inStream)
{
mp3DecodeData data;
MpdTag *tag = NULL;

View File

@ -78,7 +78,8 @@ static uint32_t mp4_inputStreamSeekCallback(void *inStream, uint64_t position)
return seekInputStream((InputStream *) inStream, position, SEEK_SET);
}
static int mp4_decode(InputStream * inStream)
static int mp4_decode(mpd_unused struct decoder * mpd_decoder,
InputStream * inStream)
{
mp4ff_t *mp4fh;
mp4ff_callback_t *mp4cb;

View File

@ -106,7 +106,8 @@ static inline mpd_sint16 convertSample(MPC_SAMPLE_FORMAT sample)
return val;
}
static int mpc_decode(InputStream * inStream)
static int mpc_decode(mpd_unused struct decoder * mpd_decoder,
InputStream * inStream)
{
mpc_decoder decoder;
mpc_reader reader;

View File

@ -314,7 +314,7 @@ static MpdTag *oggflac_TagDup(char *file)
return NULL;
}
init_FlacData(&data, &inStream);
init_FlacData(&data, NULL, &inStream);
/* errors here won't matter,
* data.tag will be set or unset, that's all we care about */
@ -331,13 +331,15 @@ static unsigned int oggflac_try_decode(InputStream * inStream)
return (ogg_stream_type_detect(inStream) == FLAC) ? 1 : 0;
}
static int oggflac_decode(InputStream * inStream)
static int oggflac_decode(struct decoder * mpd_decoder, InputStream * inStream)
{
DecoderControl *dc = mpd_decoder->dc;
OutputBuffer *ob = mpd_decoder->ob;
OggFLAC__SeekableStreamDecoder *decoder = NULL;
FlacData data;
int ret = 0;
init_FlacData(&data, inStream);
init_FlacData(&data, mpd_decoder, inStream);
if (!(decoder = full_decoder_init_and_read_metadata(&data, 0))) {
ret = -1;

View File

@ -210,7 +210,8 @@ static void putOggCommentsIntoOutputBuffer(char *streamName,
}
/* public */
static int oggvorbis_decode(InputStream * inStream)
static int oggvorbis_decode(mpd_unused struct decoder * decoder,
InputStream * inStream)
{
OggVorbis_File vf;
ov_callbacks callbacks;

View File

@ -124,7 +124,8 @@ static void format_samples_float(mpd_unused int Bps, void *buffer,
* This does the main decoding thing.
* Requires an already opened WavpackContext.
*/
static void wavpack_decode(WavpackContext *wpc, int canseek,
static void wavpack_decode(mpd_unused struct decoder * decoder,
WavpackContext *wpc, int canseek,
ReplayGainInfo *replayGainInfo)
{
void (*format_samples)(int Bps, void *buffer, uint32_t samcnt);
@ -436,7 +437,7 @@ static unsigned int wavpack_trydecode(InputStream *is)
/*
* Decodes a stream.
*/
static int wavpack_streamdecode(InputStream *is)
static int wavpack_streamdecode(struct decoder * decoder, InputStream *is)
{
char error[ERRORLEN];
WavpackContext *wpc;
@ -535,7 +536,7 @@ static int wavpack_streamdecode(InputStream *is)
return -1;
}
wavpack_decode(wpc, canseek, NULL);
wavpack_decode(decoder, wpc, canseek, NULL);
WavpackCloseFile(wpc);
if (wvc_url != NULL) {
@ -550,7 +551,7 @@ static int wavpack_streamdecode(InputStream *is)
/*
* Decodes a file.
*/
static int wavpack_filedecode(char *fname)
static int wavpack_filedecode(struct decoder * decoder, char *fname)
{
char error[ERRORLEN];
WavpackContext *wpc;
@ -566,7 +567,7 @@ static int wavpack_filedecode(char *fname)
replayGainInfo = wavpack_replaygain(wpc);
wavpack_decode(wpc, 1, replayGainInfo);
wavpack_decode(decoder, wpc, 1, replayGainInfo);
if (replayGainInfo)
freeReplayGainInfo(replayGainInfo);