[xiph-commits] r8979 - icecast/branches/kh/ices/src

karl at motherfish-iii.xiph.org karl at motherfish-iii.xiph.org
Thu Feb 24 04:41:00 PST 2005


Author: karl
Date: 2005-02-24 04:40:57 -0800 (Thu, 24 Feb 2005)
New Revision: 8979

Modified:
   icecast/branches/kh/ices/src/Makefile.am
   icecast/branches/kh/ices/src/om_shout.c
Log:
fixup to use libshout 2.1 non-blocking API


Modified: icecast/branches/kh/ices/src/Makefile.am
===================================================================
--- icecast/branches/kh/ices/src/Makefile.am	2005-02-24 07:26:32 UTC (rev 8978)
+++ icecast/branches/kh/ices/src/Makefile.am	2005-02-24 12:40:57 UTC (rev 8979)
@@ -2,14 +2,13 @@
 
 AUTOMAKE_OPTIONS = foreign
 
-SUBDIRS = log 
+SUBDIRS = log thread timing avl
 
 bin_PROGRAMS = ices
 AM_CFLAGS = @XIPH_CFLAGS@
 AM_CPPFLAGS = @XIPH_CPPFLAGS@
 CFLAGS= -g -O20
 
-EXTRA_DIST = thread net timing
 EXTRA_ices_SOURCES = im_oss.c im_sun.c im_alsa.c
 
 if HAVE_OSS_AUDIO
@@ -36,7 +35,7 @@
 output_srcs = om_shout.c om_file.c
 ices_SOURCES = input.c cfgparse.c runner.c ices.c signals.c reencode.c encode.c stream.c metadata.c audio.c resample.c $(input_srcs) $(output_srcs)
 
-ices_LDADD = log/libicelog.la @ALSA_LIBS@ @JACK_LIBS@ @XIPH_LIBS@
+ices_LDADD = log/libicelog.la thread/libicethread.la avl/libiceavl.la timing/libicetiming.la @ALSA_LIBS@ @JACK_LIBS@ @XIPH_LIBS@
 
 debug:
 	$(MAKE) all CFLAGS="@DEBUG@"

Modified: icecast/branches/kh/ices/src/om_shout.c
===================================================================
--- icecast/branches/kh/ices/src/om_shout.c	2005-02-24 07:26:32 UTC (rev 8978)
+++ icecast/branches/kh/ices/src/om_shout.c	2005-02-24 12:40:57 UTC (rev 8979)
@@ -54,108 +54,104 @@
 void check_shout_connected (struct output_module *mod)
 {
     struct output_shout_state *stream = mod->specific;
-    if (shout_connection_ready (stream->shout))
-        return;
-    if (stream->reconnect_attempts == -1 ||
-            stream->reconnect_attempts > stream->reconnect_count)
+    int shouterr;
+    time_t now = time (NULL);
+
+    if (stream->shout == NULL)
     {
-        time_t now = time (NULL);
-
         if (stream->restart_time <= now)
         {
-            int shouterr;
+            char audio_info[11];
+            int failed = 1;
+            struct output_state *state = mod->parent;
 
-            if (stream->shout == NULL || shout_get_errno (stream->shout) != SHOUTERR_PENDING)
+            LOG_DEBUG3 ("Time we started stream on %s:%d%s", stream->hostname, 
+                    stream->port, stream->mount);
+            /* allow for traping long icecast connects */
+            stream->restart_time = now;
+
+            do
             {
-                char audio_info[11];
-                int failed = 1;
-                struct output_state *state = mod->parent;
+                if ((stream->shout = shout_new ()) == NULL)
+                    break;
+                if (shout_set_host (stream->shout, stream->hostname) != SHOUTERR_SUCCESS)
+                    break;
+                if (shout_set_password (stream->shout, stream->password) != SHOUTERR_SUCCESS)
+                    break;
+                if (shout_set_port (stream->shout, stream->port) != SHOUTERR_SUCCESS)
+                    break;
+                if (stream->user && shout_set_user (stream->shout, stream->user) != SHOUTERR_SUCCESS)
+                    break;
+                if (shout_set_mount (stream->shout, stream->mount) != SHOUTERR_SUCCESS)
+                    break;
+                if (shout_set_agent (stream->shout, PACKAGE_STRING) != SHOUTERR_SUCCESS)
+                    break;
+                if (shout_set_name (stream->shout, state->name) != SHOUTERR_SUCCESS)
+                    break;
+                if (shout_set_genre (stream->shout, state->genre) != SHOUTERR_SUCCESS)
+                    break;
+                if (state->url && shout_set_url (stream->shout, state->url) != SHOUTERR_SUCCESS)
+                    break;
+                if (shout_set_description (stream->shout, state->description) != SHOUTERR_SUCCESS)
+                    break;
+                if (stream->yp && shout_set_public (stream->shout, 1) != SHOUTERR_SUCCESS)
+                    break;
 
-                LOG_DEBUG3 ("Time we started stream on %s:%d%s", stream->hostname, 
-                        stream->port, stream->mount);
-                /* allow for traping long icecast connects */
-                stream->restart_time = now;
+                shout_set_nonblocking (stream->shout, 1);
+                shout_set_format (stream->shout, SHOUT_FORMAT_OGG);
+                shout_set_protocol (stream->shout, SHOUT_PROTOCOL_HTTP);
 
-                do
-                {
-                    if ((stream->shout = shout_new ()) == NULL)
-                        break;
-                    if (shout_set_host (stream->shout, stream->hostname) != SHOUTERR_SUCCESS)
-                        break;
-                    if (shout_set_password (stream->shout, stream->password) != SHOUTERR_SUCCESS)
-                        break;
-                    if (shout_set_port (stream->shout, stream->port) != SHOUTERR_SUCCESS)
-                        break;
-                    if (stream->user && shout_set_user (stream->shout, stream->user) != SHOUTERR_SUCCESS)
-                        break;
-                    if (shout_set_mount (stream->shout, stream->mount) != SHOUTERR_SUCCESS)
-                        break;
-                    if (shout_set_agent (stream->shout, PACKAGE_STRING) != SHOUTERR_SUCCESS)
-                        break;
-                    if (shout_set_name (stream->shout, state->name) != SHOUTERR_SUCCESS)
-                        break;
-                    if (shout_set_genre (stream->shout, state->genre) != SHOUTERR_SUCCESS)
-                        break;
-                    if (state->url && shout_set_url (stream->shout, state->url) != SHOUTERR_SUCCESS)
-                        break;
-                    if (shout_set_description (stream->shout, state->description) != SHOUTERR_SUCCESS)
-                        break;
-                    if (stream->yp && shout_set_public (stream->shout, 1) != SHOUTERR_SUCCESS)
-                        break;
+                snprintf(audio_info, sizeof(audio_info), "%ld", state->vi.bitrate_nominal/1000);
+                shout_set_audio_info (stream->shout, SHOUT_AI_BITRATE, audio_info);
 
-                    shout_set_nonblocking (stream->shout, 1);
-                    shout_set_format (stream->shout, SHOUT_FORMAT_VORBISPAGE);
-                    shout_set_protocol (stream->shout, SHOUT_PROTOCOL_HTTP);
+                snprintf(audio_info, sizeof(audio_info), "%ld", state->vi.rate);
+                shout_set_audio_info (stream->shout, SHOUT_AI_SAMPLERATE, audio_info);
 
-                    snprintf(audio_info, sizeof(audio_info), "%ld", state->vi.bitrate_nominal/1000);
-                    shout_set_audio_info (stream->shout, SHOUT_AI_BITRATE, audio_info);
+                snprintf(audio_info, sizeof(audio_info), "%d", state->vi.channels);
+                shout_set_audio_info (stream->shout, SHOUT_AI_CHANNELS, audio_info);
+                failed = 0;
+            } while (0);
 
-                    snprintf(audio_info, sizeof(audio_info), "%ld", state->vi.rate);
-                    shout_set_audio_info (stream->shout, SHOUT_AI_SAMPLERATE, audio_info);
-
-                    snprintf(audio_info, sizeof(audio_info), "%d", state->vi.channels);
-                    shout_set_audio_info (stream->shout, SHOUT_AI_CHANNELS, audio_info);
-                    failed = 0;
-                }
-                while (0);
-                if (failed)
-                {
-                    _output_connection_close (mod);
-                    return;
-                }
-            }
-            if ((shouterr = shout_open(stream->shout)) == SHOUTERR_SUCCESS)
+            if (failed)
             {
-                LOG_INFO3("Connected to server: %s:%d%s",
-                        shout_get_host(stream->shout), shout_get_port(stream->shout), shout_get_mount(stream->shout));
-                stream->connected = 1;
-                stream->reconnect_count = 0;
-                mod->need_headers = 1;
+                _output_connection_close (mod);
                 return;
             }
-            if (shouterr == SHOUTERR_PENDING)
-            {
-                if (now - stream->restart_time > SHOUT_TIMEOUT)
-                {
-                    LOG_ERROR3("Terminating connection to %s:%d%s",
-                            shout_get_host(stream->shout), shout_get_port(stream->shout),
-                            shout_get_mount(stream->shout));
-                    LOG_ERROR1("no reply came in %d seconds", SHOUT_TIMEOUT);
-                    _output_connection_close (mod);
-                }
-                /* ok, we just need to come back to this connection later */
-            }
-            else
-            {
-                LOG_ERROR4("Failed to connect to %s:%d%s (%s)",
-                        shout_get_host(stream->shout), shout_get_port(stream->shout),
-                        shout_get_mount(stream->shout), shout_get_error(stream->shout));
-                _output_connection_close (mod);
-            }
+            shout_open(stream->shout);
         }
+        else
+            return;
+    }
+    shouterr = shout_get_connected (stream->shout);
+    if (shouterr == SHOUTERR_CONNECTED)
+    {
+        LOG_INFO3("Connected to server: %s:%d%s",
+                shout_get_host (stream->shout), shout_get_port (stream->shout),
+                shout_get_mount (stream->shout));
+        stream->connected = 1;
+        stream->reconnect_count = 0;
+        mod->need_headers = 1;
         return;
     }
-    LOG_INFO1 ("%d reconnect attempts, will keep re-trying", stream->reconnect_count);
+    if (shouterr != SHOUTERR_UNCONNECTED)
+    {
+        if (now - stream->restart_time > SHOUT_TIMEOUT)
+        {
+            LOG_ERROR3("Terminating connection to %s:%d%s",
+                    shout_get_host(stream->shout), shout_get_port(stream->shout),
+                    shout_get_mount(stream->shout));
+            LOG_ERROR1("no reply came in %d seconds", SHOUT_TIMEOUT);
+            _output_connection_close (mod);
+        }
+        /* ok, we just need to come back to this connection later */
+    }
+    else
+    {
+        LOG_ERROR4("Failed to connect to %s:%d%s (%s)",
+                shout_get_host(stream->shout), shout_get_port(stream->shout),
+                shout_get_mount(stream->shout), shout_get_error(stream->shout));
+        _output_connection_close (mod);
+    }
 }
 
 
@@ -192,7 +188,8 @@
 int output_ogg_shout (struct output_module *mod, ogg_packet *op, unsigned samples)
 {
     struct output_shout_state *stream = mod->specific;
-    check_shout_connected (mod);
+    if (stream->connected == 0)
+        check_shout_connected (mod);
     if (stream->connected)
     {
         int send_it = 1;
@@ -225,11 +222,15 @@
             stream->prev_page_granulepos = 0;
             stream->prev_packet_granulepos = 0;
 
-            while (ogg_stream_flush (&mod->os, &page) > 0)
+            while (send_it && ogg_stream_flush (&mod->os, &page) > 0)
             {
-                if (send_it && shout_send (stream->shout, &page, 1) != SHOUTERR_SUCCESS)
+                if (shout_send_raw (stream->shout, page.header, page.header_len) < 0)
+                    send_it = 0;
+                if (send_it && shout_send_raw (stream->shout, page.body, page.body_len) < 0)
+                    send_it = 0;
+
+                if (send_it == 0)
                 {
-                    send_it = 0;
                     LOG_ERROR4("Failed to write headers to %s:%d%s (%s)",
                             shout_get_host (stream->shout), shout_get_port (stream->shout),
                             shout_get_mount (stream->shout), shout_get_error (stream->shout));
@@ -249,9 +250,13 @@
 
         while (shout_audio_pageout (mod, &page) > 0)
         {
-            if (send_it && shout_send (stream->shout, &page, 1) != SHOUTERR_SUCCESS)
+            if (shout_send_raw (stream->shout, page.header, page.header_len) < 0)
+                send_it = 0;
+            if (send_it && shout_send_raw (stream->shout, page.body, page.body_len) < 0)
+                send_it = 0;
+
+            if (send_it == 0 || shout_queuelen(stream->shout) > 65535)
             {
-                send_it = 0;
                 LOG_ERROR4("Failed to write to %s:%d%s (%s)",
                         shout_get_host (stream->shout), shout_get_port (stream->shout),
                         shout_get_mount (stream->shout), shout_get_error (stream->shout));



More information about the commits mailing list