decoder_initialized() sets the state to DECODE_STATE_DECODE and wakes
up the player thread.  It is called by the decoder plugin after its
internal initialization is finished.  More arguments will be added
later to prevent direct accesses to the DecoderControl struct.
---

 src/Makefile.am                     |    1 +
 src/decoder_api.c                   |   31 +++++++++++++++++++++++++++++++
 src/decoder_api.h                   |    6 ++++++
 src/inputPlugins/_flac_common.h     |    2 +-
 src/inputPlugins/aac_plugin.c       |    6 +++---
 src/inputPlugins/audiofile_plugin.c |    6 +++---
 src/inputPlugins/flac_plugin.c      |    2 +-
 src/inputPlugins/mod_plugin.c       |    6 +++---
 src/inputPlugins/mp3_plugin.c       |    7 +++----
 src/inputPlugins/mp4_plugin.c       |    7 +++----
 src/inputPlugins/mpc_plugin.c       |    7 +++----
 src/inputPlugins/oggflac_plugin.c   |    2 +-
 src/inputPlugins/oggvorbis_plugin.c |    7 +++----
 src/inputPlugins/wavpack_plugin.c   |    7 ++++---
 14 files changed, 66 insertions(+), 31 deletions(-)
 create mode 100644 src/decoder_api.c

diff --git a/src/Makefile.am b/src/Makefile.am
index 4a41964..5d5375f 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -104,6 +104,7 @@ mpd_SOURCES = \
        conf.c \
        dbUtils.c \
        decode.c \
+       decoder_api.c \
        directory.c \
        inputPlugin.c \
        inputStream.c \
diff --git a/src/decoder_api.c b/src/decoder_api.c
new file mode 100644
index 0000000..dfd1850
--- /dev/null
+++ b/src/decoder_api.c
@@ -0,0 +1,31 @@
+/* the Music Player Daemon (MPD)
+ * Copyright (C) 2003-2007 by Warren Dukes ([EMAIL PROTECTED])
+ * Copyright (C) 2008 Max Kellermann <[EMAIL PROTECTED]>
+ * 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
+ */
+
+#include "decoder_api.h"
+
+#include "playerData.h"
+#include "gcc.h"
+
+void decoder_initialized(mpd_unused struct decoder * decoder)
+{
+       assert(dc.state == DECODE_STATE_START);
+
+       dc.state = DECODE_STATE_DECODE;
+       notify_signal(&pc.notify);
+}
diff --git a/src/decoder_api.h b/src/decoder_api.h
index f4e0c13..c9ab3eb 100644
--- a/src/decoder_api.h
+++ b/src/decoder_api.h
@@ -34,4 +34,10 @@
  */
 struct decoder;
 
+/**
+ * Notify the player thread that it has finished initialization and
+ * that it has read the song's meta data.
+ */
+void decoder_initialized(struct decoder * decoder);
+
 #endif
diff --git a/src/inputPlugins/_flac_common.h b/src/inputPlugins/_flac_common.h
index 0437a41..2d59f4d 100644
--- a/src/inputPlugins/_flac_common.h
+++ b/src/inputPlugins/_flac_common.h
@@ -22,7 +22,7 @@
 #ifndef _FLAC_COMMON_H
 #define _FLAC_COMMON_H
 
-#include "../inputPlugin.h"
+#include "../decoder_api.h"
 
 #if defined(HAVE_FLAC) || defined(HAVE_OGGFLAC)
 
diff --git a/src/inputPlugins/aac_plugin.c b/src/inputPlugins/aac_plugin.c
index 4f18184..d03826c 100644
--- a/src/inputPlugins/aac_plugin.c
+++ b/src/inputPlugins/aac_plugin.c
@@ -16,7 +16,7 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-#include "../inputPlugin.h"
+#include "../decoder_api.h"
 
 #ifdef HAVE_FAAD
 
@@ -278,7 +278,7 @@ static int getAacTotalTime(char *file)
        return file_time;
 }
 
-static int aac_decode(mpd_unused struct decoder * mpd_decoder, char *path)
+static int aac_decode(struct decoder * mpd_decoder, char *path)
 {
        float file_time;
        float totalTime;
@@ -373,7 +373,7 @@ static int aac_decode(mpd_unused struct decoder * 
mpd_decoder, char *path)
                        dc.audioFormat.sampleRate = sampleRate;
                        getOutputAudioFormat(&(dc.audioFormat),
                                             &(ob.audioFormat));
-                       dc.state = DECODE_STATE_DECODE;
+                       decoder_initialized(mpd_decoder);
                }
 
                advanceAacBuffer(&b, frameInfo.bytesconsumed);
diff --git a/src/inputPlugins/audiofile_plugin.c 
b/src/inputPlugins/audiofile_plugin.c
index 0cc3571..faa58fe 100644
--- a/src/inputPlugins/audiofile_plugin.c
+++ b/src/inputPlugins/audiofile_plugin.c
@@ -18,7 +18,7 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-#include "../inputPlugin.h"
+#include "../decoder_api.h"
 
 #ifdef HAVE_AUDIOFILE
 
@@ -40,7 +40,7 @@ static int getAudiofileTotalTime(char *file)
        return total_time;
 }
 
-static int audiofile_decode(mpd_unused struct decoder * decoder, char *path)
+static int audiofile_decode(struct decoder * decoder, char *path)
 {
        int fs, frame_count;
        AFfilehandle af_fp;
@@ -85,7 +85,7 @@ static int audiofile_decode(mpd_unused struct decoder * 
decoder, char *path)
 
        fs = (int)afGetVirtualFrameSize(af_fp, AF_DEFAULT_TRACK, 1);
 
-       dc.state = DECODE_STATE_DECODE;
+       decoder_initialized(decoder);
        {
                int ret, eof = 0, current = 0;
                char chunk[CHUNK_SIZE];
diff --git a/src/inputPlugins/flac_plugin.c b/src/inputPlugins/flac_plugin.c
index 7c4b8e3..43be1a2 100644
--- a/src/inputPlugins/flac_plugin.c
+++ b/src/inputPlugins/flac_plugin.c
@@ -415,7 +415,7 @@ static int flac_decode_internal(struct decoder * decoder,
                }
        }
 
-       dc.state = DECODE_STATE_DECODE;
+       decoder_initialized(decoder);
 
        while (1) {
                if (!flac_process_single(flacDec))
diff --git a/src/inputPlugins/mod_plugin.c b/src/inputPlugins/mod_plugin.c
index a041f1e..c09803e 100644
--- a/src/inputPlugins/mod_plugin.c
+++ b/src/inputPlugins/mod_plugin.c
@@ -16,7 +16,7 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-#include "../inputPlugin.h"
+#include "../decoder_api.h"
 
 #ifdef HAVE_MIKMOD
 
@@ -159,7 +159,7 @@ static void mod_close(mod_Data * data)
        free(data);
 }
 
-static int mod_decode(mpd_unused struct decoder * decoder, char *path)
+static int mod_decode(struct decoder * decoder, char *path)
 {
        mod_Data *data;
        float total_time = 0.0;
@@ -185,7 +185,7 @@ static int mod_decode(mpd_unused struct decoder * decoder, 
char *path)
            1.0 / ((dc.audioFormat.bits * dc.audioFormat.channels / 8.0) *
                   (float)dc.audioFormat.sampleRate);
 
-       dc.state = DECODE_STATE_DECODE;
+       decoder_initialized(decoder);
        while (1) {
                if (dc.command == DECODE_COMMAND_SEEK) {
                        dc.seekError = 1;
diff --git a/src/inputPlugins/mp3_plugin.c b/src/inputPlugins/mp3_plugin.c
index e684524..f918953 100644
--- a/src/inputPlugins/mp3_plugin.c
+++ b/src/inputPlugins/mp3_plugin.c
@@ -16,7 +16,7 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-#include "../inputPlugin.h"
+#include "../decoder_api.h"
 
 #ifdef HAVE_MAD
 
@@ -1015,8 +1015,7 @@ static void 
initAudioFormatFromMp3DecodeData(mp3DecodeData * data,
        af->channels = MAD_NCHANNELS(&(data->frame).header);
 }
 
-static int mp3_decode(mpd_unused struct decoder * decoder,
-                     InputStream * inStream)
+static int mp3_decode(struct decoder * decoder, InputStream * inStream)
 {
        mp3DecodeData data;
        MpdTag *tag = NULL;
@@ -1062,7 +1061,7 @@ static int mp3_decode(mpd_unused struct decoder * decoder,
                freeMpdTag(tag);
        }
 
-       dc.state = DECODE_STATE_DECODE;
+       decoder_initialized(decoder);
 
        while (mp3Read(&data, &replayGainInfo) != DECODE_BREAK) ;
        /* send last little bit if not DECODE_COMMAND_STOP */
diff --git a/src/inputPlugins/mp4_plugin.c b/src/inputPlugins/mp4_plugin.c
index e715b39..de65851 100644
--- a/src/inputPlugins/mp4_plugin.c
+++ b/src/inputPlugins/mp4_plugin.c
@@ -16,7 +16,7 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-#include "../inputPlugin.h"
+#include "../decoder_api.h"
 
 #ifdef HAVE_FAAD
 
@@ -78,8 +78,7 @@ static uint32_t mp4_inputStreamSeekCallback(void *inStream, 
uint64_t position)
        return seekInputStream((InputStream *) inStream, position, SEEK_SET);
 }
 
-static int mp4_decode(mpd_unused struct decoder * mpd_decoder,
-                     InputStream * inStream)
+static int mp4_decode(struct decoder * mpd_decoder, InputStream * inStream)
 {
        mp4ff_t *mp4fh;
        mp4ff_callback_t *mp4cb;
@@ -250,7 +249,7 @@ static int mp4_decode(mpd_unused struct decoder * 
mpd_decoder,
                        dc.audioFormat.channels = frameInfo.channels;
                        getOutputAudioFormat(&(dc.audioFormat),
                                             &(ob.audioFormat));
-                       dc.state = DECODE_STATE_DECODE;
+                       decoder_initialized(mpd_decoder);
                }
 
                if (channels * (unsigned long)(dur + offset) > 
frameInfo.samples) {
diff --git a/src/inputPlugins/mpc_plugin.c b/src/inputPlugins/mpc_plugin.c
index f69e9ed..d4ee40f 100644
--- a/src/inputPlugins/mpc_plugin.c
+++ b/src/inputPlugins/mpc_plugin.c
@@ -16,7 +16,7 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-#include "../inputPlugin.h"
+#include "../decoder_api.h"
 
 #ifdef HAVE_MPCDEC
 
@@ -106,8 +106,7 @@ static inline mpd_sint16 convertSample(MPC_SAMPLE_FORMAT 
sample)
        return val;
 }
 
-static int mpc_decode(mpd_unused struct decoder * mpd_decoder,
-                     InputStream * inStream)
+static int mpc_decode(struct decoder * mpd_decoder, InputStream * inStream)
 {
        mpc_decoder decoder;
        mpc_reader reader;
@@ -174,7 +173,7 @@ static int mpc_decode(mpd_unused struct decoder * 
mpd_decoder,
        replayGainInfo->trackGain = info.gain_title * 0.01;
        replayGainInfo->trackPeak = info.peak_title / 32767.0;
 
-       dc.state = DECODE_STATE_DECODE;
+       decoder_initialized(mpd_decoder);
 
        while (!eof) {
                if (dc.command == DECODE_COMMAND_SEEK) {
diff --git a/src/inputPlugins/oggflac_plugin.c 
b/src/inputPlugins/oggflac_plugin.c
index a365f73..91b4de4 100644
--- a/src/inputPlugins/oggflac_plugin.c
+++ b/src/inputPlugins/oggflac_plugin.c
@@ -346,7 +346,7 @@ static int oggflac_decode(struct decoder * mpd_decoder, 
InputStream * inStream)
                goto fail;
        }
 
-       dc.state = DECODE_STATE_DECODE;
+       decoder_initialized(mpd_decoder);
 
        while (1) {
                OggFLAC__seekable_stream_decoder_process_single(decoder);
diff --git a/src/inputPlugins/oggvorbis_plugin.c 
b/src/inputPlugins/oggvorbis_plugin.c
index cb0c5a9..0867de6 100644
--- a/src/inputPlugins/oggvorbis_plugin.c
+++ b/src/inputPlugins/oggvorbis_plugin.c
@@ -18,7 +18,7 @@
 
 /* TODO 'ogg' should probably be replaced with 'oggvorbis' in all instances */
 
-#include "../inputPlugin.h"
+#include "../decoder_api.h"
 
 #ifdef HAVE_OGGVORBIS
 
@@ -210,8 +210,7 @@ static void putOggCommentsIntoOutputBuffer(char *streamName,
 }
 
 /* public */
-static int oggvorbis_decode(mpd_unused struct decoder * decoder,
-                           InputStream * inStream)
+static int oggvorbis_decode(struct decoder * decoder, InputStream * inStream)
 {
        OggVorbis_File vf;
        ov_callbacks callbacks;
@@ -287,7 +286,7 @@ static int oggvorbis_decode(mpd_unused struct decoder * 
decoder,
                        if (dc.state == DECODE_STATE_START) {
                                getOutputAudioFormat(&(dc.audioFormat),
                                                     &(ob.audioFormat));
-                               dc.state = DECODE_STATE_DECODE;
+                               decoder_initialized(decoder);
                        }
                        comments = ov_comment(&vf, -1)->user_comments;
                        putOggCommentsIntoOutputBuffer(inStream->metaName,
diff --git a/src/inputPlugins/wavpack_plugin.c 
b/src/inputPlugins/wavpack_plugin.c
index 99491a2..cd832fd 100644
--- a/src/inputPlugins/wavpack_plugin.c
+++ b/src/inputPlugins/wavpack_plugin.c
@@ -18,7 +18,7 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
-#include "../inputPlugin.h"
+#include "../decoder_api.h"
 
 #ifdef HAVE_WAVPACK
 
@@ -124,7 +124,7 @@ 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(mpd_unused struct decoder * decoder,
+static void wavpack_decode(struct decoder * decoder,
                            WavpackContext *wpc, int canseek,
                            ReplayGainInfo *replayGainInfo)
 {
@@ -166,9 +166,10 @@ static void wavpack_decode(mpd_unused struct decoder * 
decoder,
        getOutputAudioFormat(&(dc.audioFormat), &(ob.audioFormat));
 
        dc.totalTime = (float)allsamples / dc.audioFormat.sampleRate;
-       dc.state = DECODE_STATE_DECODE;
        dc.seekable = canseek;
 
+       decoder_initialized(decoder);
+
        position = 0;
 
        do {


-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Musicpd-dev-team mailing list
Musicpd-dev-team@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/musicpd-dev-team

Reply via email to