# HG changeset patch # User Andrew O. Shadoura # Date 1213030099 -10800 # Node ID fa4b58a08f4c3f58cbb5e8253769f8cec20d8bf2 # Parent 6d08e3120615cf84af16ffd7c54508f6241f68c5 started icecast plugin (derived from filewriter) diff -r 6d08e3120615 -r fa4b58a08f4c src/icecast/Makefile --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/icecast/Makefile Mon Jun 09 19:48:19 2008 +0300 @@ -0,0 +1,14 @@ +PLUGIN = icecast${PLUGIN_SUFFIX} + +SRCS = icecast.c \ + ../filewriter/mp3.o \ + ../filewriter/vorbis.o + +include ../../buildsys.mk +include ../../extra.mk + +plugindir := ${plugindir}/${OUTPUT_PLUGIN_DIR} + +CFLAGS += ${PLUGIN_CFLAGS} +CPPFLAGS += ${PLUGIN_CPPFLAGS} ${GLIB_CFLAGS} ${GTK_CFLAGS} ${PANGO_CFLAGS} ${MOWGLI_CFLAGS} ${DBUS_CFLAGS} ${FILEWRITER_CFLAGS} ${OGG_VORBIS_CFLAGS} -I../../intl -I../.. +LIBS += ${GTK_LIBS} ${FILEWRITER_LIBS} diff -r 6d08e3120615 -r fa4b58a08f4c src/icecast/icecast.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/icecast/icecast.c Mon Jun 09 19:48:19 2008 +0300 @@ -0,0 +1,419 @@ +/* Icecast-Plugin + * (C) copyright 2008 based of FileWriter-plugin + * + * Original Out-Lame-Plugin: + * (C) copyright 2002 Lars Siebold + * (C) copyright 2006-2007 porting to audacious by Yoshiki Yazawa + * + * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "../filewriter/filewriter.h" +#include "../filewriter/plugins.h" + +struct format_info input; + +static GtkWidget *configure_win = NULL, *configure_vbox; +static GtkWidget *addr_hbox, *addr_label, *addr_entry; +static GtkWidget *configure_bbox, *configure_ok, *configure_cancel; + +static GtkWidget *streamformat_hbox, *streamformat_label, *streamformat_combo, *plugin_button; + +enum streamformat_t +{ +#ifdef FILEWRITER_MP3 + MP3, +#endif +#ifdef FILEWRITER_VORBIS + VORBIS, +#endif + streamformat_MAX +}; + +static gint streamformat = VORBIS; + +static FileWriter plugin; + +static gchar *server_address = NULL; + +VFSFile *output_file = NULL; +guint64 written = 0; +guint64 offset = 0; +Tuple *tuple = NULL; + +static void ice_init(void); +static void ice_about(void); +static gint ice_open(AFormat fmt, gint rate, gint nch); +static void ice_write(void *ptr, gint length); +static gint ice_write_output(void *ptr, gint length); +static void ice_close(void); +static void ice_flush(gint time); +static void ice_pause(short p); +static gint ice_free(void); +static gint ice_playing(void); +static gint ice_get_written_time(void); +static gint ice_get_output_time(void); +static void ice_configure(void); +/*static int ice_mod_samples(gpointer * d, gint length, AFormat afmt, gint srate, gint nch);*/ + +OutputPlugin ice_op = +{ + .description = "Icecast Plugin", + .init = ice_init, + .about = ice_about, + .configure = ice_configure, + .open_audio = ice_open, + .write_audio = ice_write, + .close_audio = ice_close, + .flush = ice_flush, + .pause = ice_pause, + .buffer_free = ice_free, + .buffer_playing = ice_playing, + .output_time = ice_get_output_time, + .written_time = ice_get_written_time +}; +/* +EffectPlugin ice_ep = +{ + .description = "Icecast Plugin", + .init = ice_init, + .cleanup = ice_cleanup, + .about = ice_about, + .configure = ice_configure, + .mod_samples = ice_mod_samples, +}; +*/ +OutputPlugin *ice_oplist[] = { &ice_op, NULL }; + +SIMPLE_OUTPUT_PLUGIN(icecast, ice_oplist); + +static void set_plugin(void) +{ + if (streamformat < 0 || streamformat >= streamformat_MAX) + streamformat = 0; + +#ifdef FILEWRITER_MP3 + if (streamformat == MP3) + plugin = mp3_plugin; +#endif +#ifdef FILEWRITER_VORBIS + if (streamformat == VORBIS) + plugin = vorbis_plugin; +#endif +} + +static void ice_init(void) +{ + ConfigDb *db; + puts("ICE_INIT"); + + db = aud_cfg_db_open(); + aud_cfg_db_get_int(db, "icecast", "streamformat", &streamformat); + aud_cfg_db_get_string(db, "icecast", "server_address", &server_address); + aud_cfg_db_close(db); + + set_plugin(); + if (plugin.init) + plugin.init(&ice_write_output); +} + +void ice_about(void) +{ + static GtkWidget *dialog; + + if (dialog != NULL) + return; + + dialog = audacious_info_dialog(_("About Icecast-Plugin"), + _("Icecast-Plugin\n\n" + "This program is free software; you can redistribute it and/or modify\n" + "it under the terms of the GNU General Public License as published by\n" + "the Free Software Foundation; either version 2 of the License, or\n" + "(at your option) any later version.\n" + "\n" + "This program is distributed in the hope that it will be useful,\n" + "but WITHOUT ANY WARRANTY; without even the implied warranty of\n" + "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" + "GNU General Public License for more details.\n" + "\n" + "You should have received a copy of the GNU General Public License\n" + "along with this program; if not, write to the Free Software\n" + "Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,\n" + "USA."), _("Ok"), FALSE, NULL, NULL); + gtk_signal_connect(GTK_OBJECT(dialog), "destroy", + GTK_SIGNAL_FUNC(gtk_widget_destroyed), &dialog); +} + +static gint ice_open(AFormat fmt, gint rate, gint nch) +{ + gint rv; + + input.format = fmt; + input.frequency = rate; + input.channels = nch; + + rv = (plugin.open)(); + + puts("ICE_OPEN"); + return rv; +} + +static void convert_buffer(gpointer buffer, gint length) +{ + gint i; + + if (input.format == FMT_S8) + { + guint8 *ptr1 = buffer; + gint8 *ptr2 = buffer; + + for (i = 0; i < length; i++) + *(ptr1++) = *(ptr2++) ^ 128; + } + if (input.format == FMT_S16_BE) + { + gint16 *ptr = buffer; + + for (i = 0; i < length >> 1; i++, ptr++) + *ptr = GUINT16_SWAP_LE_BE(*ptr); + } + if (input.format == FMT_S16_NE) + { + gint16 *ptr = buffer; + + for (i = 0; i < length >> 1; i++, ptr++) + *ptr = GINT16_TO_LE(*ptr); + } + if (input.format == FMT_U16_BE) + { + gint16 *ptr1 = buffer; + guint16 *ptr2 = buffer; + + for (i = 0; i < length >> 1; i++, ptr2++) + *(ptr1++) = GINT16_TO_LE(GUINT16_FROM_BE(*ptr2) ^ 32768); + } + if (input.format == FMT_U16_LE) + { + gint16 *ptr1 = buffer; + guint16 *ptr2 = buffer; + + for (i = 0; i < length >> 1; i++, ptr2++) + *(ptr1++) = GINT16_TO_LE(GUINT16_FROM_LE(*ptr2) ^ 32768); + } + if (input.format == FMT_U16_NE) + { + gint16 *ptr1 = buffer; + guint16 *ptr2 = buffer; + + for (i = 0; i < length >> 1; i++, ptr2++) + *(ptr1++) = GINT16_TO_LE((*ptr2) ^ 32768); + } +} + +static void ice_write(void *ptr, gint length) +{ + if (input.format == FMT_S8 || input.format == FMT_S16_BE || + input.format == FMT_U16_LE || input.format == FMT_U16_BE || + input.format == FMT_U16_NE) + convert_buffer(ptr, length); +#ifdef WORDS_BIGENDIAN + if (input.format == FMT_S16_NE) + convert_buffer(ptr, length); +#endif + + plugin.write(ptr, length); +} + +static gint ice_write_output(void *ptr, gint length) +{ + int i; + printf("ice_write("); + for (i=0;(i