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

karl at motherfish-iii.xiph.org karl at motherfish-iii.xiph.org
Thu Feb 24 08:46:22 PST 2005


Author: karl
Date: 2005-02-24 08:46:19 -0800 (Thu, 24 Feb 2005)
New Revision: 8980

Modified:
   icecast/branches/kh/ices/src/im_alsa.c
   icecast/branches/kh/ices/src/im_alsa.h
   icecast/branches/kh/ices/src/om_shout.c
   icecast/branches/kh/ices/src/om_shout.h
Log:
updates that appeared in the ices 2.0.1 release


Modified: icecast/branches/kh/ices/src/im_alsa.c
===================================================================
--- icecast/branches/kh/ices/src/im_alsa.c	2005-02-24 12:40:57 UTC (rev 8979)
+++ icecast/branches/kh/ices/src/im_alsa.c	2005-02-24 16:46:19 UTC (rev 8980)
@@ -44,7 +44,28 @@
 
 #define SAMPLES 8192
 
+static void alsa_free_buffer (input_module_t *mod, input_buffer *ib)
+{
+    im_alsa_state *s = mod->internal;
+    float **ptr;
+    int i;
 
+    ptr = ib->buf;
+    for (i=s->channels; i; i--)
+    {
+        if (ptr)
+        {
+            free (*ptr);
+            *ptr = NULL;
+        }
+        ptr++;
+    }
+    free (ib->buf);
+    ib->buf = NULL;
+}
+
+
+
 static int alsa_initialise_buffer (input_module_t *mod, input_buffer *ib)
 {
 	im_alsa_state *s = mod->internal;
@@ -74,12 +95,16 @@
 {
 	if (mod)
 	{
+        LOG_INFO0 ("closing ALSA module");
 		if (mod->internal)
 		{
 			im_alsa_state *s = mod->internal;
 			if (s->fd != NULL)
+            {
+                LOG_DEBUG0 ("closing alsa pcm handle");
 				snd_pcm_close(s->fd);
-			free(s);
+            }
+            s->fd = NULL;
 		}
 	}
 }
@@ -90,8 +115,10 @@
     im_alsa_state *s = mod->internal;
 
     LOG_INFO0 ("Shutdown ALSA module");
+    free (s->read_buffer);
     free (s);
     mod->internal = NULL;
+    snd_config_update_free_global ();
 }
 
 
@@ -182,6 +209,7 @@
 	mod->subtype = INPUT_PCM_LE_16;
 	mod->getdata = alsa_read;
     /* mod->release_input_buffer = alsa_return_buffer; */
+    mod->free_input_buffer = alsa_free_buffer;
     mod->initialise_buffer = alsa_initialise_buffer;
     mod->buffer_count = ices_config->runner_count*10 + 5;
     mod->prealloc_count = ices_config->runner_count * 4;
@@ -195,7 +223,7 @@
 	rate = 44100; /* Defaults */
 	channels = 2; 
     samples = SAMPLES;
-    s->periods = 2;
+    s->periods = -1;
     s->buffer_time = 500000;
 
 	current = mod->module_params;
@@ -291,10 +319,13 @@
         LOG_ERROR2("Error setting buffer time %u: %s", s->buffer_time, snd_strerror(err));
         goto fail;
     }
-    if ((err = snd_pcm_hw_params_set_periods(s->fd, hwparams, s->periods, 0)) < 0)
+    if (s->periods > 0)
     {
-        LOG_ERROR2("Error setting %u periods: %s", s->periods, snd_strerror(err));
-        goto fail;
+        if ((err = snd_pcm_hw_params_set_periods(s->fd, hwparams, s->periods, 0)) < 0)
+        {
+            LOG_ERROR2("Error setting %u periods: %s", s->periods, snd_strerror(err));
+            goto fail;
+        }
     }
 
 	if ((err = snd_pcm_hw_params(s->fd, hwparams)) < 0)
@@ -306,8 +337,11 @@
 
 	/* We're done, and we didn't fail! */
 	LOG_INFO1("Opened audio device %s", s->device);
-    LOG_INFO4("with %d channel(s), %d Hz, buffer %u ms (%u periods)",
-			s->channels, s->rate, s->buffer_time/1000, s->periods);
+    LOG_INFO2("with %d channel(s), %d Hz", s->channels, s->rate);
+    if (s->periods == -1)
+        LOG_DEBUG1 ("using %umS buffer", s->buffer_time/1000);
+    else
+        LOG_DEBUG2 ("using %umS buffer and %d periods", s->buffer_time/1000, s->periods);
 
 	return 0;
 

Modified: icecast/branches/kh/ices/src/im_alsa.h
===================================================================
--- icecast/branches/kh/ices/src/im_alsa.h	2005-02-24 12:40:57 UTC (rev 8979)
+++ icecast/branches/kh/ices/src/im_alsa.h	2005-02-24 16:46:19 UTC (rev 8980)
@@ -36,7 +36,7 @@
 	int rate;
 	int channels;
     unsigned buffer_time;
-    unsigned periods;
+    int periods;
 
 	snd_pcm_t *fd;
     const char *device;

Modified: icecast/branches/kh/ices/src/om_shout.c
===================================================================
--- icecast/branches/kh/ices/src/om_shout.c	2005-02-24 12:40:57 UTC (rev 8979)
+++ icecast/branches/kh/ices/src/om_shout.c	2005-02-24 16:46:19 UTC (rev 8980)
@@ -169,7 +169,7 @@
         else
             ret = 0;
     }
-    else if (stream->page_samples > (uint64_t)mod->parent->vi.rate)
+    else if (stream->page_samples >= stream->flush_trigger)
         ret = ogg_stream_flush (&mod->os, page);
     else
         ret = ogg_stream_pageout (&mod->os, page);
@@ -221,6 +221,8 @@
             mod->start_pos = granule;
             stream->prev_page_granulepos = 0;
             stream->prev_packet_granulepos = 0;
+            if (stream->flush_trigger == 0)
+                stream->flush_trigger = state->vi.rate;
 
             while (send_it && ogg_stream_flush (&mod->os, &page) > 0)
             {
@@ -300,6 +302,7 @@
     int  yp          = 0,
          reconnect_delay = DEFAULT_RECONN_DELAY,
          reconnect_attempts = DEFAULT_RECONN_ATTEMPTS,
+         flush_samples = 0,
          port        = 8000;
 
     struct cfg_tag shout_tags[] =
@@ -310,6 +313,7 @@
         { "username",           get_xml_string, &user },
         { "mount",              get_xml_string, &mount },
         { "yp",                 get_xml_bool,   &yp },
+        { "flush-samples",      get_xml_int,    &flush_samples },
         { "reconnectdelay",     get_xml_int,    &reconnect_delay },
         { "reconnectattempts",  get_xml_int,    &reconnect_attempts },
         { NULL, NULL, NULL }
@@ -340,6 +344,7 @@
         stream->mount = mount;
         stream->port = port;
         stream->yp = yp;
+        stream->flush_trigger = flush_samples;
 
         stream->reconnect_delay = reconnect_delay;
         stream->reconnect_attempts = reconnect_attempts;
@@ -349,7 +354,7 @@
         state->head = mod;
         return 0;
     }
-    fprintf (stderr, "shout output failed\n");
+    LOG_ERROR0 ("shout output failed");
     if (hostname)   xmlFree (hostname);
     if (user)       xmlFree (user);
     if (password)   xmlFree (password);

Modified: icecast/branches/kh/ices/src/om_shout.h
===================================================================
--- icecast/branches/kh/ices/src/om_shout.h	2005-02-24 12:40:57 UTC (rev 8979)
+++ icecast/branches/kh/ices/src/om_shout.h	2005-02-24 16:46:19 UTC (rev 8980)
@@ -26,11 +26,12 @@
     int port;
     int yp;
     int connected;
+    int flush_trigger;
     int reconnect_delay;
     int reconnect_count;
     int reconnect_attempts;
     time_t restart_time;
-    uint64_t page_samples;
+    int page_samples;
     uint64_t prev_page_granulepos;
     uint64_t prev_packet_granulepos;
 };



More information about the commits mailing list