I've hacked together an output plugin that streams MP3 out to a
shoutcast server.  To do so, I basically took the existing shout plugin
and removed the Ogg/Vorbis specific bits, and replaced them with libmp3lame
bits.

The patch included can be applied to 0.13.2.  I know the version in Git
is a bit different, but at this time, the Git source's metadata
functionality isn't working, and since I'm new to MPD, I've held off on
working on that.

Unfortunately, I was unable to figure out how to get the autotools to
look for the lame libs for me, so I did an end-around in the
configure.ac file.  Sorry.  :/

I'm sure there are better ways to do this, and I welcome your comments,
input, or suggestions.

Thanks,

Eric
[EMAIL PROTECTED]


diff -pruN mpd-0.13.2/configure.ac mpd-0.13.2-shout_mp3/configure.ac
--- mpd-0.13.2/configure.ac     2008-06-16 23:39:38.000000000 -0600
+++ mpd-0.13.2-shout_mp3/configure.ac   2008-08-23 18:17:01.000000000 -0600
@@ -63,6 +63,7 @@ fi

  AC_ARG_ENABLE(ao,[  --enable-ao             enable support for libao 
(default: disable)],[enable_ao=$enableval],[enable_ao=no])
  AC_ARG_ENABLE(shout,[  --disable-shout         disable support for streaming 
through shout (default: enable)],[enable_shout=$enableval],[enable_shout=yes])
+AC_ARG_ENABLE(shout_mp3,[  --disable-shout_mp3         disable support for mp3 
streaming through shout (default: 
enable)],[enable_shout_mp3=$enableval],[enable_shout_mp3=yes])
  AC_ARG_ENABLE(iconv,[  --disable-iconv         disable iconv support 
(default: enable)],[enable_iconv=$enableval],[enable_iconv=yes])
  AC_ARG_ENABLE(ipv6,[  --disable-ipv6          disable IPv6 support (default: 
enable)],[enable_ipv6=$enableval],[enable_ipv6=yes])
  AC_ARG_ENABLE(oss,[  --disable-oss           disable OSS support (default: 
enable)],[enable_oss=$enableval],[enable_oss=yes])
@@ -169,10 +170,14 @@ if test x$enable_ao = xyes; then
        XIPH_PATH_AO([AC_DEFINE(HAVE_AO, 1, [Define to play with ao]) 
MPD_LIBS="$MPD_LIBS $AO_LIBS" MPD_CFLAGS="$MPD_CFLAGS $AO_CFLAGS"], 
enable_ao=no)
  fi

-if test x$enable_shout = xyes; then
+if test x$enable_shout = xyes; then
        XIPH_PATH_SHOUT([AC_DEFINE(HAVE_SHOUT, 1, [Define to enable libshout 
support]) MPD_LIBS="$MPD_LIBS $SHOUT_LIBS" MPD_CFLAGS="$MPD_CFLAGS 
$SHOUT_CFLAGS"], enable_shout=no)
  fi

+if test x$enable_shout_mp3 = xyes; then 
+       XIPH_PATH_SHOUT([AC_DEFINE(HAVE_SHOUT_MP3, 1, [Define to enable mp3 
libshout support]) MPD_LIBS="$MPD_LIBS $SHOUT_LIBS" MPD_CFLAGS="$MPD_CFLAGS 
$SHOUT_CFLAGS"], enable_shout_mp3=no)
+fi
+
  if test x$enable_oss = xyes; then
        
AC_CHECK_HEADER(sys/soundcard.h,[enable_oss=yes;AC_DEFINE(HAVE_OSS,1,[Define to 
enable OSS])],[AC_MSG_WARN(Soundcard headers not found -- disabling OSS 
support);enable_oss=no])
  fi
@@ -502,6 +507,11 @@ elif test x$enable_oggvorbis = xyes; the
        fi
  fi

+if test x$enable_shout_mp3 = xyes; then
+       MPD_LIBS="$MPD_LIBS -lmp3lame"
+       MPD_CFLAGS="$MPD_CFLAGS -I/usr/local/include"
+fi
+
  if test x$enable_oggvorbis = xyes; then
        AC_DEFINE(HAVE_OGGVORBIS,1,[Define for Ogg Vorbis support])
  fi
@@ -673,11 +683,18 @@ else
        echo " Shout streaming support .......disabled"
  fi

+if test x$enable_shout_mp3 = xyes; then
+       echo " Shout mp3 streaming support ...enabled"
+else
+       echo " Shout mp3 streaming support ...disabled"
+fi
+
  echo ""

  if test x$enable_ao = xno &&
     test x$enable_oss = xno &&
     test x$enable_shout = xno &&
+   test x$enable_shout_mp3 = xno &&
     test x$enable_alsa = xno &&
     test x$enable_osx = xno &&
     test x$enable_pulse = xno &&
diff -pruN mpd-0.13.2/src/audio.c mpd-0.13.2-shout_mp3/src/audio.c
--- mpd-0.13.2/src/audio.c      2007-05-26 12:15:54.000000000 -0600
+++ mpd-0.13.2-shout_mp3/src/audio.c    2008-08-23 15:11:13.000000000 -0600
@@ -35,9 +35,9 @@
  #include <errno.h>
  #include <unistd.h>

-#define AUDIO_DEVICE_STATE     "audio_device_state:"
-#define AUDIO_DEVICE_STATE_LEN 19      /* strlen(AUDIO_DEVICE_STATE) */
-#define AUDIO_BUFFER_SIZE      2*MAXPATHLEN
+#define AUDIO_DEVICE_STATE      "audio_device_state:"
+#define AUDIO_DEVICE_STATE_LEN  19      /* strlen(AUDIO_DEVICE_STATE) */
+#define AUDIO_BUFFER_SIZE       2*MAXPATHLEN

  static AudioFormat audio_format;

@@ -46,9 +46,9 @@ static AudioFormat *audio_configFormat;
  static AudioOutput *audioOutputArray;
  static mpd_uint8 audioOutputArraySize;

-#define        DEVICE_OFF        0x00
-#define DEVICE_ENABLE    0x01   /* currently off, but to be turned on */
-#define        DEVICE_ON         0x03
+#define DEVICE_OFF        0x00
+#define DEVICE_ENABLE     0x01   /* currently off, but to be turned on */
+#define DEVICE_ON         0x03
  #define DEVICE_DISABLE    0x04   /* currently on, but to be turned off */

  /* the audioEnabledArray should be stuck into shared memory, and then disable
@@ -99,6 +99,7 @@ void loadAudioDrivers(void)
        loadAudioOutputPlugin(&pulsePlugin);
        loadAudioOutputPlugin(&mvpPlugin);
        loadAudioOutputPlugin(&shoutPlugin);
+       loadAudioOutputPlugin(&shoutMp3Plugin);
        loadAudioOutputPlugin(&jackPlugin);
  }

@@ -461,7 +462,7 @@ void printAudioDevices(int fd)

        for (i = 0; i < audioOutputArraySize; i++) {
                fdprintf(fd,
-                        "outputid: %i\noutputname: %s\noutputenabled: %i\n",
+                        "outputid: %i\noutputname: %s\noutputenabled: %i\n",
                         i,
                         audioOutputArray[i].name,
                         audioDeviceStates[i] & 0x01);
@@ -476,7 +477,7 @@ void saveAudioDevicesState(FILE *fp)
        for (i = 0; i < audioOutputArraySize; i++) {
                fprintf(fp, AUDIO_DEVICE_STATE "%d:%s\n",
                        audioDeviceStates[i] & 0x01,
-                       audioOutputArray[i].name);
+                       audioOutputArray[i].name);
        }
  }

diff -pruN mpd-0.13.2/src/audioOutput.h mpd-0.13.2-shout_mp3/src/audioOutput.h
--- mpd-0.13.2/src/audioOutput.h        2007-05-24 15:15:37.000000000 -0600
+++ mpd-0.13.2-shout_mp3/src/audioOutput.h      2008-08-23 15:11:13.000000000 
-0600
@@ -112,6 +112,7 @@ extern AudioOutputPlugin osxPlugin;
  extern AudioOutputPlugin pulsePlugin;
  extern AudioOutputPlugin mvpPlugin;
  extern AudioOutputPlugin shoutPlugin;
+extern AudioOutputPlugin shoutMp3Plugin;
  extern AudioOutputPlugin jackPlugin;

  #endif
diff -pruN mpd-0.13.2/src/audioOutputs/audioOutput_shout_mp3.c 
mpd-0.13.2-shout_mp3/src/audioOutputs/audioOutput_shout_mp3.c
--- mpd-0.13.2/src/audioOutputs/audioOutput_shout_mp3.c 1969-12-31 
17:00:00.000000000 -0700
+++ mpd-0.13.2-shout_mp3/src/audioOutputs/audioOutput_shout_mp3.c       
2008-08-23 17:40:14.000000000 -0600
@@ -0,0 +1,608 @@
+/* the Music Player Daemon (MPD)
+ * Copyright (C) 2003-2007 by Warren Dukes ([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 "../audioOutput.h"
+
+#include <stdlib.h>
+
+#ifdef HAVE_SHOUT_MP3
+
+#include "../conf.h"
+#include "../log.h"
+#include "../pcm_utils.h"
+
+#include <string.h>
+#include <time.h>
+
+#include <shout/shout.h>
+#include <lame/lame.h>
+
+#define CONN_ATTEMPT_INTERVAL   60
+#define MP3_BUF_SIZE 1048576
+
+static int shoutInitCount;
+
+/* lots of this code blatantly stolent from bossogg/bossao2 */
+
+typedef struct _ShoutData {
+        shout_t *shoutConn;
+        int shoutError;
+        shout_metadata_t *shoutMeta;
+
+        lame_global_flags *gfp;
+        unsigned char mp3buf[MP3_BUF_SIZE];
+        unsigned int mp3buf_full;
+
+        float quality;
+        int bitrate;
+
+        int opened;
+
+        MpdTag *tag;
+        int tagToSend;
+
+        int connAttempts;
+        time_t lastAttempt;
+        int last_err;
+
+        /* just a pointer to audioOutput->outAudioFormat */
+        AudioFormat *audioFormat;
+} ShoutData;
+
+static ShoutData *newShoutData(void)
+{
+        ShoutData *ret = xmalloc(sizeof(ShoutData));
+
+        ret->shoutConn = shout_new();
+        ret->shoutMeta = shout_metadata_new();
+        ret->opened = 0;
+        ret->tag = NULL;
+        ret->tagToSend = 0;
+        ret->bitrate = -1;
+        ret->quality = -2.0;
+        ret->connAttempts = 0;
+        ret->lastAttempt = 0;
+        ret->audioFormat = NULL;
+        ret->last_err = SHOUTERR_UNCONNECTED;
+
+        return ret;
+}
+
+static void freeShoutData(ShoutData * sd)
+{
+        if (sd->shoutMeta)
+                shout_metadata_free(sd->shoutMeta);
+        if (sd->shoutConn)
+                shout_free(sd->shoutConn);
+        if (sd->tag)
+                freeMpdTag(sd->tag);
+
+        free(sd);
+}
+
+#define checkBlockParam(name) { \
+        blockParam = getBlockParam(param, name); \
+        if (!blockParam) { \
+                FATAL("no \"%s\" defined for shout device defined at line " \
+                                "%i\n", name, param->line); \
+        } \
+}
+
+static int myShoutMp3_initDriver(AudioOutput * audioOutput, ConfigParam * 
param)
+{
+        ShoutData *sd;
+        char *test;
+        int port;
+        char *host;
+        char *mount;
+        char *passwd;
+        char *user;
+        char *name;
+        BlockParam *blockParam;
+        unsigned int public = 0;
+
+        sd = newShoutData();
+
+        if (shoutInitCount == 0)
+                shout_init();
+
+        shoutInitCount++;
+
+        checkBlockParam("host");
+        host = blockParam->value;
+
+        checkBlockParam("mount");
+        mount = blockParam->value;
+
+        checkBlockParam("port");
+
+        port = strtol(blockParam->value, &test, 10);
+
+        if (*test != '\0' || port <= 0) {
+                FATAL("shout port \"%s\" is not a positive integer, line %i\n",
+                      blockParam->value, blockParam->line);
+        }
+
+        checkBlockParam("password");
+        passwd = blockParam->value;
+
+        checkBlockParam("name");
+        name = blockParam->value;
+
+        blockParam = getBlockParam(param, "public");
+        if (blockParam) {
+                if (0 == strcmp(blockParam->value, "yes")) {
+                        public = 1;
+                } else if (0 == strcmp(blockParam->value, "no")) {
+                        public = 0;
+                } else {
+                        FATAL("public \"%s\" is not \"yes\" or \"no\" at line "
+                              "%i\n", param->value, param->line);
+                }
+        }
+
+        blockParam = getBlockParam(param, "user");
+        if (blockParam)
+                user = blockParam->value;
+        else
+                user = "source";
+
+        blockParam = getBlockParam(param, "quality");
+
+        if (blockParam) {
+                int line = blockParam->line;
+
+                sd->quality = strtod(blockParam->value, &test);
+
+                if (*test != '\0' || sd->quality < -1.0 || sd->quality > 10.0) 
{
+                        FATAL("shout quality \"%s\" is not a number in the "
+                              "range -1 to 10, line %i\n", blockParam->value,
+                              blockParam->line);
+                }
+
+                blockParam = getBlockParam(param, "bitrate");
+
+                if (blockParam) {
+                        FATAL("quality (line %i) and bitrate (line %i) are "
+                              "both defined for shout output\n", line,
+                              blockParam->line);
+                }
+        } else {
+                blockParam = getBlockParam(param, "bitrate");
+
+                if (!blockParam) {
+                        FATAL("neither bitrate nor quality defined for shout "
+                              "output at line %i\n", param->line);
+                }
+
+                sd->bitrate = strtol(blockParam->value, &test, 10);
+
+                if (*test != '\0' || sd->bitrate <= 0) {
+                        FATAL("bitrate at line %i should be a positive integer 
"
+                              "\n", blockParam->line);
+                }
+        }
+
+        checkBlockParam("format");
+        sd->audioFormat = &audioOutput->outAudioFormat;
+
+        if (shout_set_host(sd->shoutConn, host) != SHOUTERR_SUCCESS ||
+            shout_set_port(sd->shoutConn, port) != SHOUTERR_SUCCESS ||
+            shout_set_password(sd->shoutConn, passwd) != SHOUTERR_SUCCESS ||
+            shout_set_mount(sd->shoutConn, mount) != SHOUTERR_SUCCESS ||
+            shout_set_name(sd->shoutConn, name) != SHOUTERR_SUCCESS ||
+            shout_set_user(sd->shoutConn, user) != SHOUTERR_SUCCESS ||
+            shout_set_public(sd->shoutConn, public) != SHOUTERR_SUCCESS ||
+            shout_set_nonblocking(sd->shoutConn, 1) != SHOUTERR_SUCCESS ||
+            shout_set_format(sd->shoutConn, SHOUT_FORMAT_MP3)
+            != SHOUTERR_SUCCESS ||
+            shout_set_protocol(sd->shoutConn, SHOUT_PROTOCOL_HTTP)
+            != SHOUTERR_SUCCESS ||
+            shout_set_agent(sd->shoutConn, "MPD") != SHOUTERR_SUCCESS) {
+                FATAL("error configuring shout defined at line %i: %s\n",
+                      param->line, shout_get_error(sd->shoutConn));
+        }
+
+        /* optional paramters */
+        blockParam = getBlockParam(param, "genre");
+        if (blockParam && shout_set_genre(sd->shoutConn, blockParam->value)) {
+                FATAL("error configuring shout defined at line %i: %s\n",
+                      param->line, shout_get_error(sd->shoutConn));
+        }
+
+        blockParam = getBlockParam(param, "description");
+        if (blockParam && shout_set_description(sd->shoutConn,
+                                                blockParam->value)) {
+                FATAL("error configuring shout defined at line %i: %s\n",
+                      param->line, shout_get_error(sd->shoutConn));
+        }
+
+        {
+                char temp[11];
+                memset(temp, 0, sizeof(temp));
+
+                snprintf(temp, sizeof(temp), "%d", sd->audioFormat->channels);
+                shout_set_audio_info(sd->shoutConn, SHOUT_AI_CHANNELS, temp);
+
+                snprintf(temp, sizeof(temp), "%d", 
sd->audioFormat->sampleRate);
+
+                shout_set_audio_info(sd->shoutConn, SHOUT_AI_SAMPLERATE, temp);
+
+                if (sd->quality >= -1.0) {
+                        snprintf(temp, sizeof(temp), "%2.2f", sd->quality);
+                        shout_set_audio_info(sd->shoutConn, SHOUT_AI_QUALITY,
+                                             temp);
+                } else {
+                        snprintf(temp, sizeof(temp), "%d", sd->bitrate);
+                        shout_set_audio_info(sd->shoutConn, SHOUT_AI_BITRATE,
+                                             temp);
+                }
+        }
+
+        audioOutput->data = sd;
+
+        return 0;
+}
+
+static int myShoutMp3_handleError(ShoutData * sd, int err)
+{
+        switch (err) {
+        case SHOUTERR_SUCCESS:
+                break;
+        case SHOUTERR_UNCONNECTED:
+        case SHOUTERR_SOCKET:
+                ERROR("Lost shout connection to %s:%i : %s\n",
+                      shout_get_host(sd->shoutConn),
+                      shout_get_port(sd->shoutConn),
+                      shout_get_error(sd->shoutConn));
+                sd->shoutError = 1;
+                return -1;
+        default:
+                ERROR("shout: connection to %s:%i error : %s\n",
+                      shout_get_host(sd->shoutConn),
+                      shout_get_port(sd->shoutConn),
+                      shout_get_error(sd->shoutConn));
+                sd->shoutError = 1;
+                return -1;
+        }
+
+        return 0;
+}
+
+static int write_page(ShoutData * sd)
+{
+        int err = 0;
+
+        /*DEBUG("shout_delay: %i\n", shout_delay(sd->shoutConn)); */
+        shout_sync(sd->shoutConn);
+        err = shout_send(sd->shoutConn, sd->mp3buf, sd->mp3buf_full);
+        if (myShoutMp3_handleError(sd, err) < 0)
+                return -1;
+
+        return 0;
+}
+
+static void finishEncoder(ShoutData * sd)
+{
+        /* Does lame require anything be done here? */
+}
+
+static int flushEncoder(ShoutData * sd)
+{
+        /* Does lame require anything be done here? */
+        /* lame_get_size_mp3buffer(sd->gfp); */
+        return 0;
+}
+
+static void clearEncoder(ShoutData * sd)
+{
+        finishEncoder(sd);
+        while (1 == flushEncoder(sd)) {
+                if (!sd->shoutError)
+                        write_page(sd);
+        }
+
+        lame_close(sd->gfp);
+}
+
+static void myShoutMp3_closeShoutConn(ShoutData * sd)
+{
+        if (sd->opened) {
+                clearEncoder(sd);
+
+                if (shout_close(sd->shoutConn) != SHOUTERR_SUCCESS) {
+                        ERROR("problem closing connection to shout server: "
+                              "%s\n", shout_get_error(sd->shoutConn));
+                }
+        }
+
+        sd->last_err = SHOUTERR_UNCONNECTED;
+        sd->opened = 0;
+}
+
+static void myShoutMp3_finishDriver(AudioOutput * audioOutput)
+{
+        ShoutData *sd = (ShoutData *) audioOutput->data;
+
+        myShoutMp3_closeShoutConn(sd);
+
+        freeShoutData(sd);
+
+        shoutInitCount--;
+
+        if (shoutInitCount == 0)
+                shout_shutdown();
+}
+
+static void myShoutMp3_dropBufferedAudio(AudioOutput * audioOutput)
+{
+        /* needs to be implemented */
+}
+
+static void myShoutMp3_closeDevice(AudioOutput * audioOutput)
+{
+        ShoutData *sd = (ShoutData *) audioOutput->data;
+
+        myShoutMp3_closeShoutConn(sd);
+
+        audioOutput->open = 0;
+}
+
+static void sendMetadata(ShoutData *sd)
+{
+    const size_t tag_size = 1024;
+    char song[tag_size];
+    char artist[tag_size];
+    char title[tag_size];
+
+        if (sd->tag) {
+                int i;
+
+                for (i = 0; i < sd->tag->numOfItems; i++) {
+                        switch (sd->tag->items[i].type) {
+                        case TAG_ITEM_ARTIST:
+                                snprintf(artist, tag_size, "%s",
+                                         sd->tag->items[i].value);
+                                break;
+                        case TAG_ITEM_TITLE:
+                                snprintf(title, tag_size, "%s",
+                                         sd->tag->items[i].value);
+                                break;
+                        }
+                }
+                snprintf(song, tag_size, "%s - %s", title, artist);
+                shout_metadata_add(sd->shoutMeta, "song", song);
+        }
+        if (SHOUTERR_SUCCESS != shout_set_metadata(sd->shoutConn,
+                                                   sd->shoutMeta)) {
+                ERROR("error setting shout metadata\n");
+                return;
+        }
+
+}
+
+static int initEncoder(ShoutData * sd)
+{
+        if (NULL == (sd->gfp = lame_init())) {
+                ERROR("problem setting up lame encoder for shout\n");
+                lame_close(sd->gfp); /* necessary? */
+                return -1;
+        }
+
+        if (sd->quality >= -1.0) {
+               if (0 != lame_set_VBR(sd->gfp, vbr_rh)) {
+                        ERROR("problem setting up lame encoder for shout\n");
+                        lame_close(sd->gfp);
+                        return -1;
+                }
+                if (0 != lame_set_VBR_q(sd->gfp, sd->quality)) {
+                        ERROR("problem setting up lame encoder for shout\n");
+                        lame_close(sd->gfp);
+                        return -1;
+                }
+        }
+        if (0 != lame_set_num_channels(sd->gfp,
+                                       sd->audioFormat->channels)) {
+                ERROR("problem setting up lame encoder for shout\n");
+                lame_close(sd->gfp);
+                return -1;
+        }
+        if (0 != lame_set_in_samplerate(sd->gfp,
+                                        sd->audioFormat->sampleRate)) {
+                ERROR("problem setting up lame encoder for shout\n");
+                lame_close(sd->gfp);
+                return -1;
+        }
+
+        if (0 > lame_init_params(sd->gfp)) {
+                ERROR("problem setting up lame encoder for shout\n");
+                lame_close(sd->gfp);
+                return -1;
+        }
+
+        return 0;
+}
+
+static int myShoutMp3_openShoutConn(AudioOutput * audioOutput)
+{
+        ShoutData *sd = (ShoutData *) audioOutput->data;
+        time_t t = time(NULL);
+
+        if (sd->connAttempts != 0 &&
+            (t - sd->lastAttempt) < CONN_ATTEMPT_INTERVAL) {
+                return -1;
+        }
+
+        sd->connAttempts++;
+
+        if (sd->last_err == SHOUTERR_UNCONNECTED)
+                sd->last_err = shout_open(sd->shoutConn);
+        switch (sd->last_err) {
+        case SHOUTERR_SUCCESS:
+        case SHOUTERR_CONNECTED:
+                break;
+        case SHOUTERR_BUSY:
+                sd->last_err = shout_get_connected(sd->shoutConn);
+                if (sd->last_err == SHOUTERR_CONNECTED)
+                        break;
+                return -1;
+        default:
+                sd->lastAttempt = t;
+                ERROR("problem opening connection to shout server %s:%i "
+                      "(attempt %i): %s\n",
+                      shout_get_host(sd->shoutConn),
+                      shout_get_port(sd->shoutConn),
+                      sd->connAttempts, shout_get_error(sd->shoutConn));
+                return -1;
+        }
+
+        if (initEncoder(sd) < 0) {
+                shout_close(sd->shoutConn);
+                return -1;
+        }
+
+        sd->shoutError = 0;
+
+        sendMetadata(sd);
+
+        sd->opened = 1;
+        sd->tagToSend = 0;
+
+        while (lame_encode_flush(sd->gfp, sd->mp3buf, sd->mp3buf_full)) {
+                if (write_page(sd) < 0) {
+                        myShoutMp3_closeShoutConn(sd);
+                        return -1;
+                }
+        }
+
+        sd->connAttempts = 0;
+
+        return 0;
+}
+
+static int myShoutMp3_openDevice(AudioOutput * audioOutput)
+{
+        ShoutData *sd = (ShoutData *) audioOutput->data;
+
+        audioOutput->open = 1;
+
+        if (sd->opened)
+                return 0;
+
+        if (myShoutMp3_openShoutConn(audioOutput) < 0) {
+                audioOutput->open = 0;
+                return -1;
+        }
+
+        return 0;
+}
+
+static void myShoutMp3_sendMetadata(ShoutData * sd)
+{
+        if (!sd->opened || !sd->tag)
+                return;
+
+        clearEncoder(sd);
+        if (initEncoder(sd) < 0)
+                return;
+
+        sendMetadata(sd);
+
+        /*if(sd->tag) freeMpdTag(sd->tag);
+           sd->tag = NULL; */
+        sd->tagToSend = 0;
+}
+
+static int myShoutMp3_play(AudioOutput * audioOutput, char *playChunk, int 
size)
+{
+        int i, j;
+        ShoutData *sd = (ShoutData *) audioOutput->data;
+        float lamebuf[2][50000];
+        int samples;
+        int bytes = sd->audioFormat->bits / 8;
+
+        if (sd->opened && sd->tagToSend)
+                myShoutMp3_sendMetadata(sd);
+
+        if (!sd->opened) {
+                if (myShoutMp3_openShoutConn(audioOutput) < 0) {
+                        return -1;
+                }
+        }
+
+        samples = size / (bytes * sd->audioFormat->channels);
+
+        /* this is for only 16-bit audio */
+
+        for (i = 0; i < samples; i++) {
+                for (j = 0; j < sd->audioFormat->channels; j++) {
+                        lamebuf[j][i] = *((mpd_sint16 *) playChunk);
+                        playChunk += bytes;
+                }
+        }
+
+        if (0 > (sd->mp3buf_full =
+                 (lame_encode_buffer_float(sd->gfp, lamebuf[0], lamebuf[1],
+                                           samples, sd->mp3buf,
+                                           MP3_BUF_SIZE)))) {
+                ERROR("problem encoding lame buffer for shout\n");
+                lame_close(sd->gfp);
+                myShoutMp3_closeShoutConn(sd);
+                return -1;
+        }
+
+        if (write_page(sd) < 0) {
+                myShoutMp3_closeShoutConn(sd);
+                return -1;
+        }
+
+        return 0;
+}
+
+static void myShoutMp3_setTag(AudioOutput * audioOutput, MpdTag * tag)
+{
+        ShoutData *sd = (ShoutData *) audioOutput->data;
+
+        if (sd->tag)
+                freeMpdTag(sd->tag);
+        sd->tag = NULL;
+        sd->tagToSend = 0;
+
+        if (!tag)
+                return;
+
+        sd->tag = mpdTagDup(tag);
+        sd->tagToSend = 1;
+}
+
+AudioOutputPlugin shoutMp3Plugin = {
+        "shout_mp3",
+        NULL,
+        myShoutMp3_initDriver,
+        myShoutMp3_finishDriver,
+        myShoutMp3_openDevice,
+        myShoutMp3_play,
+        myShoutMp3_dropBufferedAudio,
+        myShoutMp3_closeDevice,
+        myShoutMp3_setTag,
+};
+
+#else
+
+DISABLED_AUDIO_OUTPUT_PLUGIN(shoutMp3Plugin)
+#endif
diff -pruN mpd-0.13.2/src/Makefile.am mpd-0.13.2-shout_mp3/src/Makefile.am
--- mpd-0.13.2/src/Makefile.am  2007-05-28 06:42:44.000000000 -0600
+++ mpd-0.13.2-shout_mp3/src/Makefile.am        2008-08-23 15:16:20.000000000 
-0600
@@ -9,6 +9,7 @@ mpd_audioOutputs = \
        audioOutputs/audioOutput_pulse.c \
        audioOutputs/audioOutput_mvp.c \
        audioOutputs/audioOutput_shout.c \
+       audioOutputs/audioOutput_shout_mp3.c \
        audioOutputs/audioOutput_jack.c

  mpd_inputPlugins = \

-------------------------------------------------------------------------
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