[xiph-commits] r9157 - icecast/branches/kh/icecast/src

karl at motherfish-iii.xiph.org karl at motherfish-iii.xiph.org
Tue Apr 19 18:16:15 PDT 2005


Author: karl
Date: 2005-04-19 18:16:10 -0700 (Tue, 19 Apr 2005)
New Revision: 9157

Added:
   icecast/branches/kh/icecast/src/format_flac.c
   icecast/branches/kh/icecast/src/format_flac.h
   icecast/branches/kh/icecast/src/format_midi.c
   icecast/branches/kh/icecast/src/format_midi.h
Modified:
   icecast/branches/kh/icecast/src/Makefile.am
   icecast/branches/kh/icecast/src/format_ogg.c
   icecast/branches/kh/icecast/src/slave.c
Log:
minor comment change in slave and extend ogg to include flac and
midi logical streams


Modified: icecast/branches/kh/icecast/src/Makefile.am
===================================================================
--- icecast/branches/kh/icecast/src/Makefile.am	2005-04-19 13:29:37 UTC (rev 9156)
+++ icecast/branches/kh/icecast/src/Makefile.am	2005-04-20 01:16:10 UTC (rev 9157)
@@ -9,11 +9,13 @@
 noinst_HEADERS = admin.h cfgfile.h os.h logging.h sighandler.h connection.h \
     global.h util.h slave.h source.h stats.h refbuf.h client.h format.h \
     compat.h format_mp3.h fserve.h xslt.h yp.h event.h md5.h \
-    auth.h auth_htpasswd.h auth_cmd.h auth_url.h format_ogg.h \
-    format_vorbis.h format_theora.h format_speex.h
-icecast_SOURCES = cfgfile.c main.c logging.c sighandler.c connection.c global.c \
-    util.c slave.c source.c stats.c refbuf.c client.c format.c format_ogg.c \
-    format_mp3.c xslt.c fserve.c event.c admin.c auth.c auth_htpasswd.c md5.c
+    auth.h auth_htpasswd.h auth_cmd.h auth_url.h format_ogg.h format_flac.h \
+    format_vorbis.h format_theora.h format_speex.h format_midi.h
+icecast_SOURCES = cfgfile.c main.c logging.c sighandler.c connection.c \
+    global.c util.c slave.c source.c stats.c refbuf.c client.c \
+    xslt.c fserve.c event.c admin.c md5.c \
+    format.c format_ogg.c format_mp3.c format_midi.c format_flac.c \
+    auth.c auth_htpasswd.c
 EXTRA_icecast_SOURCES = yp.c auth_url.c auth_cmd.c \
     format_vorbis.c format_theora.c format_speex.c
     

Added: icecast/branches/kh/icecast/src/format_flac.c
===================================================================
--- icecast/branches/kh/icecast/src/format_flac.c	2005-04-19 13:29:37 UTC (rev 9156)
+++ icecast/branches/kh/icecast/src/format_flac.c	2005-04-20 01:16:10 UTC (rev 9157)
@@ -0,0 +1,126 @@
+/* Icecast
+ *
+ * This program is distributed under the GNU General Public License, version 2.
+ * A copy of this license is included with this source.
+ *
+ * Copyright 2000-2004, Jack Moffitt <jack at xiph.org, 
+ *                      Michael Smith <msmith at xiph.org>,
+ *                      oddsock <oddsock at xiph.org>,
+ *                      Karl Heyes <karl at xiph.org>
+ *                      and others (see AUTHORS for details).
+ */
+
+
+/* Ogg codec handler for FLAC logical streams */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdlib.h>
+#include <ogg/ogg.h>
+#include <string.h>
+
+typedef struct source_tag source_t;
+
+#include "refbuf.h"
+#include "format_ogg.h"
+#include "client.h"
+#include "stats.h"
+
+#define CATMODULE "format-flac"
+#include "logging.h"
+
+
+static void flac_codec_free (ogg_state_t *ogg_info, ogg_codec_t *codec)
+{
+    DEBUG0 ("freeing FLAC codec");
+    stats_event (ogg_info->mount, "FLAC_version", NULL);
+    ogg_stream_clear (&codec->os);
+    free (codec);
+}
+
+
+/* Here, we just verify the page is ok and then add it to the queue */
+static refbuf_t *process_flac_page (ogg_state_t *ogg_info, ogg_codec_t *codec, ogg_page *page)
+{
+    refbuf_t * refbuf;
+
+    if (ogg_stream_pagein (&codec->os, page) < 0)
+    {
+        ogg_info->error = 1;
+        return NULL;
+    }
+    if (codec->headers)
+    {
+        ogg_packet packet;
+        while (ogg_stream_packetout (&codec->os, &packet))
+        {
+            int type = packet.packet[0];
+            if (type == 0xFF)
+            {
+                codec->headers = 0;
+                break;
+            }
+            if (type >= 1 && type <= 0x7E)
+                continue;
+            if (type >= 0x81 && type <= 0xFE)
+                continue;
+            ogg_info->error = 1;
+            return NULL;
+        }
+        if (codec->headers)
+        {
+            format_ogg_attach_header (ogg_info, page);
+            return NULL;
+        }
+    }
+    refbuf = make_refbuf_with_page (page);
+    return refbuf;
+}
+
+
+/* Check for flac header in logical stream */
+
+ogg_codec_t *initial_flac_page (format_plugin_t *plugin, ogg_page *page)
+{
+    ogg_state_t *ogg_info = plugin->_state;
+    ogg_codec_t *codec = calloc (1, sizeof (ogg_codec_t));
+    ogg_packet packet;
+
+    ogg_stream_init (&codec->os, ogg_page_serialno (page));
+    ogg_stream_pagein (&codec->os, page);
+
+    ogg_stream_packetout (&codec->os, &packet);
+
+    DEBUG0("checking for FLAC codec");
+    do
+    {
+        unsigned char *parse = packet.packet;
+
+        if (page->header_len + page->body_len != 79)
+            break;
+        if (*parse != 0x7F)
+            break;
+        parse++;
+        if (memcmp (parse, "FLAC", 4) != 0)
+            break;
+
+        INFO0 ("seen initial FLAC header");
+
+        parse += 4;
+        stats_event_args (ogg_info->mount, "FLAC_version", "%d.%d",  parse[0], parse[1]);
+        codec->process_page = process_flac_page;
+        codec->codec_free = flac_codec_free;
+        codec->headers = 1;
+        codec->name = "FLAC";
+
+        format_ogg_attach_header (ogg_info, page);
+        return codec;
+    } while (0);
+
+    ogg_stream_clear (&codec->os);
+    free (codec);
+    return NULL;
+}
+

Added: icecast/branches/kh/icecast/src/format_flac.h
===================================================================
--- icecast/branches/kh/icecast/src/format_flac.h	2005-04-19 13:29:37 UTC (rev 9156)
+++ icecast/branches/kh/icecast/src/format_flac.h	2005-04-20 01:16:10 UTC (rev 9157)
@@ -0,0 +1,21 @@
+/* Icecast
+ *
+ * This program is distributed under the GNU General Public License, version 2.
+ * A copy of this license is included with this source.
+ *
+ * Copyright 2000-2004, Jack Moffitt <jack at xiph.org, 
+ *                      Michael Smith <msmith at xiph.org>,
+ *                      oddsock <oddsock at xiph.org>,
+ *                      Karl Heyes <karl at xiph.org>
+ *                      and others (see AUTHORS for details).
+ */
+
+
+#ifndef __FORMAT_FLAC_H
+#define __FORMAT_FLAC_H
+
+#include "format_ogg.h"
+
+ogg_codec_t *initial_flac_page (format_plugin_t *plugin, ogg_page *page);
+
+#endif /* __FORMAT_FLAC_H */

Added: icecast/branches/kh/icecast/src/format_midi.c
===================================================================
--- icecast/branches/kh/icecast/src/format_midi.c	2005-04-19 13:29:37 UTC (rev 9156)
+++ icecast/branches/kh/icecast/src/format_midi.c	2005-04-20 01:16:10 UTC (rev 9157)
@@ -0,0 +1,95 @@
+/* Icecast
+ *
+ * This program is distributed under the GNU General Public License, version 2.
+ * A copy of this license is included with this source.
+ *
+ * Copyright 2000-2004, Jack Moffitt <jack at xiph.org, 
+ *                      Michael Smith <msmith at xiph.org>,
+ *                      oddsock <oddsock at xiph.org>,
+ *                      Karl Heyes <karl at xiph.org>
+ *                      and others (see AUTHORS for details).
+ */
+
+
+/* Ogg codec handler for MIDI logical streams */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdlib.h>
+#include <ogg/ogg.h>
+#include <string.h>
+
+typedef struct source_tag source_t;
+
+#include "refbuf.h"
+#include "format_ogg.h"
+#include "client.h"
+#include "stats.h"
+
+#define CATMODULE "format-midi"
+#include "logging.h"
+
+
+static void midi_codec_free (ogg_state_t *ogg_info, ogg_codec_t *codec)
+{
+    DEBUG0 ("freeing MIDI codec");
+    ogg_stream_clear (&codec->os);
+    free (codec);
+}
+
+
+/* Here, we just verify the page is ok and then add it to the queue */
+static refbuf_t *process_midi_page (ogg_state_t *ogg_info, ogg_codec_t *codec, ogg_page *page)
+{
+    refbuf_t * refbuf;
+
+    if (ogg_stream_pagein (&codec->os, page) < 0)
+    {
+        ogg_info->error = 1;
+        return NULL;
+    }
+    refbuf = make_refbuf_with_page (page);
+    return refbuf;
+}
+
+
+/* Check for midi header in logical stream */
+
+ogg_codec_t *initial_midi_page (format_plugin_t *plugin, ogg_page *page)
+{
+    ogg_state_t *ogg_info = plugin->_state;
+    ogg_codec_t *codec = calloc (1, sizeof (ogg_codec_t));
+    ogg_packet packet;
+
+    ogg_stream_init (&codec->os, ogg_page_serialno (page));
+    ogg_stream_pagein (&codec->os, page);
+
+    ogg_stream_packetout (&codec->os, &packet);
+
+    DEBUG0("checking for MIDI codec");
+    do
+    {
+        if (packet.bytes < 9)
+            break;
+        if (memcmp (packet.packet, "OggMIDI\000", 8) != 0)
+            break;
+        if (packet.bytes != 12)
+            break;
+
+        INFO0 ("seen initial MIDI header");
+        codec->process_page = process_midi_page;
+        codec->codec_free = midi_codec_free;
+        codec->headers = 1;
+        codec->name = "MIDI";
+
+        format_ogg_attach_header (ogg_info, page);
+        return codec;
+    } while (0);
+
+    ogg_stream_clear (&codec->os);
+    free (codec);
+    return NULL;
+}
+

Added: icecast/branches/kh/icecast/src/format_midi.h
===================================================================
--- icecast/branches/kh/icecast/src/format_midi.h	2005-04-19 13:29:37 UTC (rev 9156)
+++ icecast/branches/kh/icecast/src/format_midi.h	2005-04-20 01:16:10 UTC (rev 9157)
@@ -0,0 +1,21 @@
+/* Icecast
+ *
+ * This program is distributed under the GNU General Public License, version 2.
+ * A copy of this license is included with this source.
+ *
+ * Copyright 2000-2004, Jack Moffitt <jack at xiph.org, 
+ *                      Michael Smith <msmith at xiph.org>,
+ *                      oddsock <oddsock at xiph.org>,
+ *                      Karl Heyes <karl at xiph.org>
+ *                      and others (see AUTHORS for details).
+ */
+
+
+#ifndef __FORMAT_MIDI_H
+#define __FORMAT_MIDI_H
+
+#include "format_ogg.h"
+
+ogg_codec_t *initial_midi_page (format_plugin_t *plugin, ogg_page *page);
+
+#endif /* __FORMAT_MIDI_H */

Modified: icecast/branches/kh/icecast/src/format_ogg.c
===================================================================
--- icecast/branches/kh/icecast/src/format_ogg.c	2005-04-19 13:29:37 UTC (rev 9156)
+++ icecast/branches/kh/icecast/src/format_ogg.c	2005-04-20 01:16:10 UTC (rev 9157)
@@ -40,6 +40,8 @@
 #ifdef HAVE_SPEEX
 #include "format_speex.h"
 #endif
+#include "format_midi.h"
+#include "format_flac.h"
 
 #ifdef _WIN32
 #define snprintf _snprintf
@@ -217,11 +219,18 @@
         if (codec)
             break;
 #endif
+        codec = initial_midi_page (plugin, page);
+        if (codec)
+            break;
+        codec = initial_flac_page (plugin, page);
+        if (codec)
+            break;
 #ifdef HAVE_SPEEX
         codec = initial_speex_page (plugin, page);
         if (codec)
             break;
 #endif
+
         /* any others */
         ERROR0 ("Seen BOS page with unknown type");
         return -1;

Modified: icecast/branches/kh/icecast/src/slave.c
===================================================================
--- icecast/branches/kh/icecast/src/slave.c	2005-04-19 13:29:37 UTC (rev 9156)
+++ icecast/branches/kh/icecast/src/slave.c	2005-04-20 01:16:10 UTC (rev 9157)
@@ -435,7 +435,10 @@
     }
 }
 
-/* return 1 if the relay needs to be restarted */
+
+/* compare the 2 relays to see if there are any changes, return 1 if
+ * the relay needs to be restarted, 0 otherwise
+ */
 static int relay_has_changed (relay_server *new, relay_server *old)
 {
     do
@@ -444,10 +447,10 @@
             break;
         if (strcmp (new->server, old->server) != 0)
             break;
+        if (new->port != old->port)
+            break;
         if (new->mp3metadata != old->mp3metadata)
             break;
-        if (new->port != old->port)
-            break;
         if (new->on_demand != old->on_demand)
             old->on_demand = new->on_demand;
         return 0;



More information about the commits mailing list