[xiph-commits] r10692 - in icecast/branches/kh/ices: . conf src

karl at svn.xiph.org karl at svn.xiph.org
Tue Jan 3 17:28:55 PST 2006


Author: karl
Date: 2006-01-03 17:28:47 -0800 (Tue, 03 Jan 2006)
New Revision: 10692

Modified:
   icecast/branches/kh/ices/conf/ices-oss.xml
   icecast/branches/kh/ices/configure.in
   icecast/branches/kh/ices/src/cfgparse.c
   icecast/branches/kh/ices/src/cfgparse.h
   icecast/branches/kh/ices/src/encode.c
   icecast/branches/kh/ices/src/encode.h
   icecast/branches/kh/ices/src/im_jack.c
   icecast/branches/kh/ices/src/im_oss.c
   icecast/branches/kh/ices/src/im_playlist.c
   icecast/branches/kh/ices/src/input.c
   icecast/branches/kh/ices/src/metadata.c
   icecast/branches/kh/ices/src/om_shout.c
   icecast/branches/kh/ices/src/om_shout.h
   icecast/branches/kh/ices/src/reencode.c
   icecast/branches/kh/ices/src/stream.c
Log:
check in various small cleanups that have been collected


Modified: icecast/branches/kh/ices/conf/ices-oss.xml
===================================================================
--- icecast/branches/kh/ices/conf/ices-oss.xml	2006-01-03 19:39:04 UTC (rev 10691)
+++ icecast/branches/kh/ices/conf/ices-oss.xml	2006-01-04 01:28:47 UTC (rev 10692)
@@ -55,6 +55,7 @@
                     <port>8000</port>
                     <password>hackme</password>
                     <mount>/example1.ogg</mount>
+                    <yp>1</yp>
                 </shout>
 
                 <!-- resample input to the stated samplerate  - optional

Modified: icecast/branches/kh/ices/configure.in
===================================================================
--- icecast/branches/kh/ices/configure.in	2006-01-03 19:39:04 UTC (rev 10691)
+++ icecast/branches/kh/ices/configure.in	2006-01-04 01:28:47 UTC (rev 10692)
@@ -14,11 +14,12 @@
 dnl Set some options based on environment
 
 case "$host" in
-   *bsd*|*irix*)
+   *bsd*|*irix*|*darwin*)
    ;;
    *) AC_DEFINE(_XOPEN_SOURCE, 600, [Define if you have POSIX and XPG specifications])
    ;;
 esac
+
 case "$host" in 
 *-*-irix*)
         DEBUG="-g -signed" 
@@ -32,7 +33,7 @@
         PROFILE="-v -xpg -g -xO4 -fast -native -fsimple -xcg92 -Dsuncc"
 ;;
 *)
-        AC_DEFINE(GNU_SOURCE, 1, [define to 1 to enable some GNU extensions])
+        AC_DEFINE(_GNU_SOURCE, 1, [define to 1 to enable GNU extensions])
         DEBUG="-g"
         XIPH_CFLAGS="-ffast-math -fsigned-char"
         PROFILE="-g -p" 
@@ -125,6 +126,7 @@
 
 dnl Checks for library functions.
 AC_FUNC_STRERROR_R
+AC_CHECK_FUNCS([strndup])
 
 dnl -- configure options --
 

Modified: icecast/branches/kh/ices/src/cfgparse.c
===================================================================
--- icecast/branches/kh/ices/src/cfgparse.c	2006-01-03 19:39:04 UTC (rev 10691)
+++ icecast/branches/kh/ices/src/cfgparse.c	2006-01-04 01:28:47 UTC (rev 10692)
@@ -63,7 +63,18 @@
 /* this is the global config variable */
 config_t *ices_config;
 
+#ifndef HAVE_STRNDUP
+char *strndup(const char *str, size_t len)
+{
+    char *dup= malloc (len+1);
+    if (dup == NULL) abort();
+    strncpy (dup, str, len);
+    dup[len]= '\0';
+    return dup;
+}
+#endif
 
+
 int get_xml_float (xmlNodePtr node, void *x)
 {
     char *tmp = (char *)xmlNodeListGetString (node->doc, node->xmlChildrenNode, 1);

Modified: icecast/branches/kh/ices/src/cfgparse.h
===================================================================
--- icecast/branches/kh/ices/src/cfgparse.h	2006-01-03 19:39:04 UTC (rev 10691)
+++ icecast/branches/kh/ices/src/cfgparse.h	2006-01-04 01:28:47 UTC (rev 10692)
@@ -31,6 +31,10 @@
 
 extern int realtime_enabled;
 
+#ifndef HAVE_STRNDUP
+char *strndup(const char *str, size_t len);
+#endif
+
 struct cfg_tag
 {
     const char *name;
@@ -50,6 +54,8 @@
     void *specific;
     int need_headers;
     ogg_stream_state os;
+    ogg_packet *prev_packet;
+    int initial_granulepos;
     long serial;
     int in_use;
     long packetno;

Modified: icecast/branches/kh/ices/src/encode.c
===================================================================
--- icecast/branches/kh/ices/src/encode.c	2006-01-03 19:39:04 UTC (rev 10691)
+++ icecast/branches/kh/ices/src/encode.c	2006-01-04 01:28:47 UTC (rev 10692)
@@ -36,17 +36,24 @@
     vorbis_comment vc;
     vorbis_dsp_state vd;
     vorbis_block vb;
-                                                                                                                                      
+
     unsigned samplerate;
     int in_use;
     int in_header;
-                                                                                                                                      
+
     int flushed;
     ogg_packet headers[3];
+    unsigned int samples;
+    uint64_t prev_samples;
 };
 
 
+unsigned int encoder_pkt_samples (struct encoder *s)
+{
+    return s->samples;
+}
 
+
 void encode_free (struct encoder *s)
 {
     if (s)
@@ -160,6 +167,8 @@
         s->in_header = 3;
         s->samplerate = settings->samplerate;
         s->in_use = 1;
+        s->prev_samples = 0;
+        s->samples = 0;
 
         return 0;
     } while (0);
@@ -190,7 +199,7 @@
     src = pcm;
     dest = buf;
     size = samples*sizeof(float);
-    for(; i ; i--)
+    for(i=0; i<s->vi.channels ; i++)
     {
         memcpy(*dest, *src, size);
         dest++;
@@ -223,6 +232,8 @@
         vorbis_analysis (&s->vb, NULL);
         vorbis_bitrate_addblock (&s->vb);
     }
+    s->samples = op->granulepos - s->prev_samples;
+    s->prev_samples = op->granulepos;
     return 1;
 }
 

Modified: icecast/branches/kh/ices/src/encode.h
===================================================================
--- icecast/branches/kh/ices/src/encode.h	2006-01-03 19:39:04 UTC (rev 10691)
+++ icecast/branches/kh/ices/src/encode.h	2006-01-04 01:28:47 UTC (rev 10692)
@@ -49,6 +49,7 @@
 void encode_free (struct encoder *s);
 void encode_clear (struct encoder *s);
 void encode_comment (struct encoder *s, char *);
+unsigned int encoder_pkt_samples (struct encoder *s);
 
 int encode_endstream (struct encoder *s);
 void encode_data_float (struct encoder *s, float **pcm, size_t samples);

Modified: icecast/branches/kh/ices/src/im_jack.c
===================================================================
--- icecast/branches/kh/ices/src/im_jack.c	2006-01-03 19:39:04 UTC (rev 10691)
+++ icecast/branches/kh/ices/src/im_jack.c	2006-01-04 01:28:47 UTC (rev 10692)
@@ -310,12 +310,12 @@
     size_t rb_size;
     const char *con_ptr=s->connect;
     const char *ind;
-    const char connect[16][32];
     int con_ports=0;
     int last=0;
     jack_port_t *input_port;
     const char *input_port_name;
     const char *output_port_name;
+    char *connect[16];
 
     // Find out which ports to connect to.
     if(strcmp(s->connect, "")) {
@@ -325,8 +325,7 @@
                 ind=con_ptr+strlen(con_ptr);
                 last=-1;
             }
-            strncpy((char *)connect[con_ports],con_ptr,ind-con_ptr);
-            strncpy((char *)connect[con_ports]+(ind-con_ptr),"\0",1);
+            connect[con_ports] = strndup (con_ptr, (ind-con_ptr));
             //LOG_DEBUG1("Found port connect param: %s", connect[con_ports]);
             con_ptr=ind+1;
             con_ports++;
@@ -376,7 +375,7 @@
     /* Create and connect the jack ports */
     for (i = 0; i < s->channels; i++) 
     {
-        sprintf(port_name, "in_%d", i+1);
+        snprintf (port_name, sizeof(port_name),"in_%d", i+1);
         s->jack_ports[i] = jack_port_register(s->client, port_name, 
                 JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput,0); 
 	
@@ -403,11 +402,15 @@
 
     s->newtrack = 1;
 
+    for (i=0; i<con_ports; i++)
+        free (connect[i]);
     LOG_INFO2("Channels %d / Samplerate %d", s->channels, s->rate);
     s->can_process=1;
     return 0;
 
 fail:
+    for (i=0; i<con_ports; i++)
+        free (connect[i]);
     jack_shutdown_module(mod); /* safe, this checks for valid contents */
     return -1;
 }

Modified: icecast/branches/kh/ices/src/im_oss.c
===================================================================
--- icecast/branches/kh/ices/src/im_oss.c	2006-01-03 19:39:04 UTC (rev 10691)
+++ icecast/branches/kh/ices/src/im_oss.c	2006-01-04 01:28:47 UTC (rev 10692)
@@ -79,9 +79,6 @@
     float **ptr;
     int i;
 
-    if ((ib->buf = calloc (1, s->default_len)) == NULL)
-        return -1;
-
     if ((ib->buf = calloc (s->channels, sizeof (float*))) == NULL)
         return -1;
     ptr = ib->buf;
@@ -191,6 +188,7 @@
 	im_oss_state *s = mod->internal;
 
     LOG_INFO0 ("Shutdown OSS module");
+    free (s->read_buffer);
     free (s);
     mod->internal = NULL;
 }

Modified: icecast/branches/kh/ices/src/im_playlist.c
===================================================================
--- icecast/branches/kh/ices/src/im_playlist.c	2006-01-03 19:39:04 UTC (rev 10691)
+++ icecast/branches/kh/ices/src/im_playlist.c	2006-01-04 01:28:47 UTC (rev 10692)
@@ -453,7 +453,8 @@
     mod->name = "playlist";
     mod->getdata = playlist_read;
     mod->initialise_buffer = playlist_init_buffer;
-    mod->buffer_count = ices_config->runner_count*100 + 200;
+    if (mod->buffer_count == 0)
+        mod->buffer_count = ices_config->runner_count*100 + 400;
     mod->prealloc_count = ices_config->runner_count * 30 + 40;
 
     mod->internal = calloc(1, sizeof(struct playlist_state));

Modified: icecast/branches/kh/ices/src/input.c
===================================================================
--- icecast/branches/kh/ices/src/input.c	2006-01-03 19:39:04 UTC (rev 10691)
+++ icecast/branches/kh/ices/src/input.c	2006-01-04 01:28:47 UTC (rev 10692)
@@ -189,9 +189,12 @@
         {
             ib = calloc (1, sizeof (input_buffer));
             if (ib == NULL)
-               return -1;
+                return -1;
             if (mod->initialise_buffer && mod->initialise_buffer (mod, ib) < 0)
-               return -1;
+            {
+                free (ib);
+                return -1;
+            }
 
             *mod->free_list_tail = ib;
             mod->free_list_tail = &ib->next;
@@ -214,6 +217,7 @@
 
     mod = ib->mod;
 
+    /* LOG_DEBUG1 ("releasing %llu", ib->serial); */
     if (ib->serial != mod->expected)
     {
         LOG_DEBUG2("expected %lld, saw %lld", mod->expected, ib->serial);
@@ -265,7 +269,10 @@
             if (ib == NULL)
                 return NULL;
             if (mod->initialise_buffer && mod->initialise_buffer (mod, ib) < 0)
+            {
+                free (ib);
                 return NULL;
+            }
             mod->buffer_alloc++;
             mod->delay_buffer_check = 1000;
             /* LOG_DEBUG1 ("added buffer, length now %d", mod->allotted_serial - mod->released_serial); */
@@ -291,6 +298,7 @@
 
     ib->next = NULL;
     ib->serial = mod->allotted_serial++;
+    /* LOG_DEBUG1 ("issue buffer id %llu", ib->serial); */
 
     return ib;
 }
@@ -357,20 +365,23 @@
 static void free_modules()
 {
     input_module_t *mod = ices_config->inputs;
-    input_buffer *next, *ib;
 
     LOG_DEBUG0 ("freeing up module storage");
     while (mod)
     {
-        ib = mod->free_list;
-        while (ib)
+        int i = 0;
+
+        LOG_DEBUG1 ("freeing up module %s", mod->name);
+        while (mod->free_list)
         {
-            next = ib->next;
+            input_buffer *ib = mod->free_list;
+            mod->free_list = ib->next;
             if (mod->free_input_buffer)
                 mod->free_input_buffer (mod, ib);
             free (ib);
-            ib = next;
+            i++;
         }
+        LOG_DEBUG1 (" %d buffers freed", i);
         mod->free_list = NULL;
         mod->free_list_tail = NULL;
         mod = mod->next;
@@ -437,6 +448,7 @@
 	LOG_DEBUG0("All input stopped, shutting down.");
 
     runner_close (r);
+    thread_sleep (200000);
     free_modules();
 
     return NULL;

Modified: icecast/branches/kh/ices/src/metadata.c
===================================================================
--- icecast/branches/kh/ices/src/metadata.c	2006-01-03 19:39:04 UTC (rev 10691)
+++ icecast/branches/kh/ices/src/metadata.c	2006-01-04 01:28:47 UTC (rev 10692)
@@ -47,11 +47,10 @@
 #ifdef STRERROR_R_CHAR_P
         char *buf = strerror_r (errno, line, sizeof (line));
 #else
-        char buf[256];
         int i = strerror_r (errno, line, sizeof (line));
 #endif
         LOG_WARN2("Failed to open file \"%s\" for metadata update: %s", 
-                mod->metadata_filename, buf);
+                mod->metadata_filename, line);
         return;
     }
 

Modified: icecast/branches/kh/ices/src/om_shout.c
===================================================================
--- icecast/branches/kh/ices/src/om_shout.c	2006-01-03 19:39:04 UTC (rev 10691)
+++ icecast/branches/kh/ices/src/om_shout.c	2006-01-04 01:28:47 UTC (rev 10692)
@@ -32,6 +32,38 @@
 #define DEFAULT_RECONN_ATTEMPTS -1
 
 
+static ogg_packet *copy_ogg_packet (ogg_packet *packet)
+{
+    ogg_packet *next;
+    do
+    {
+        next = malloc (sizeof (ogg_packet));
+        if (next == NULL)
+            break;
+        memcpy (next, packet, sizeof (ogg_packet));
+        next->packet = malloc (next->bytes);
+        if (next->packet == NULL)
+            break;
+        memcpy (next->packet, packet->packet, next->bytes);
+        return next;
+    } while (0);
+
+    if (next)
+        free (next);
+    return NULL;
+}
+
+
+static void free_ogg_packet (ogg_packet *packet)
+{
+    if (packet)
+    {
+        free (packet->packet);
+        free (packet);
+    }
+}   
+
+
 static void _output_connection_close (struct output_module *mod)
 {
     struct output_shout_state *stream = mod->specific;
@@ -133,7 +165,7 @@
         mod->need_headers = 1;
         return;
     }
-    if (shouterr != SHOUTERR_UNCONNECTED)
+    if (shouterr == SHOUTERR_BUSY)
     {
         if (now - stream->restart_time > SHOUT_TIMEOUT)
         {
@@ -159,25 +191,15 @@
 {
     struct output_shout_state *stream = mod->specific;
     int ret;
-    uint64_t samples;
 
-    if (mod->initial_packets)
-    {
-        mod->initial_packets--;
-        if (mod->initial_packets == 0)
-            ret = ogg_stream_flush (&mod->os, page);
-        else
-            ret = 0;
-    }
-    else if (stream->page_samples >= stream->flush_trigger)
+    if (stream->page_samples >= stream->flush_trigger)
         ret = ogg_stream_flush (&mod->os, page);
     else
         ret = ogg_stream_pageout (&mod->os, page);
 
     if (ret > 0)
     {
-        samples = ogg_page_granulepos (page) - stream->prev_page_granulepos;
-        stream->page_samples -= samples;
+        stream->page_samples -= (ogg_page_granulepos (page) - stream->prev_page_granulepos);
         stream->prev_page_granulepos = ogg_page_granulepos (page);
     }
 
@@ -185,6 +207,14 @@
 }
 
 
+static void add_packet (struct output_module *mod, ogg_packet *op)
+{
+    op->packetno = mod->packetno++;
+    op->granulepos -= mod->initial_granulepos;
+    ogg_stream_packetin (&mod->os, op);
+}
+
+
 int output_ogg_shout (struct output_module *mod, ogg_packet *op, unsigned samples)
 {
     struct output_shout_state *stream = mod->specific;
@@ -195,11 +225,8 @@
         int send_it = 1;
         ogg_page page;
         long packetno = op->packetno;
-        ogg_int64_t granule = op->granulepos;
         struct output_state *state = mod->parent;
 
-        op -> packetno = mod->packetno++;
-
         if (state->new_headers || mod->need_headers)
         {
             int val = mod->serial;
@@ -218,9 +245,6 @@
             ogg_stream_packetin (&mod->os, &state->packets[1]);
             ogg_stream_packetin (&mod->os, &state->packets[2]);
             mod->need_headers = 0;
-            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;
 
@@ -241,15 +265,16 @@
                 }
             }
             mod->packetno = 3;
-            mod->initial_packets = 2; /* flush 2 packets into a single page */
+            mod->initial_granulepos = op->granulepos;
+            stream->page_samples = 0;
+            stream->prev_page_granulepos = 0;
         }
 
-        op->granulepos -= mod->start_pos;
-        ogg_stream_packetin (&mod->os, op);
+        free_ogg_packet (mod->prev_packet);
+        mod->prev_packet = copy_ogg_packet (op);
+        add_packet (mod, op);
+        stream->page_samples += samples;
 
-        stream->page_samples += (op->granulepos - stream->prev_packet_granulepos);
-        stream->prev_packet_granulepos = op->granulepos;
-
         while (shout_audio_pageout (mod, &page) > 0)
         {
             if (shout_send_raw (stream->shout, page.header, page.header_len) < 0)
@@ -268,7 +293,6 @@
         }
         /* reset to what it was */
         op->packetno = packetno;
-        op->granulepos = granule;
     }
     return 0;
 }

Modified: icecast/branches/kh/ices/src/om_shout.h
===================================================================
--- icecast/branches/kh/ices/src/om_shout.h	2006-01-03 19:39:04 UTC (rev 10691)
+++ icecast/branches/kh/ices/src/om_shout.h	2006-01-04 01:28:47 UTC (rev 10692)
@@ -33,7 +33,6 @@
     time_t restart_time;
     int page_samples;
     uint64_t prev_page_granulepos;
-    uint64_t prev_packet_granulepos;
 };
 
 int parse_shout (xmlNodePtr node, void *arg);

Modified: icecast/branches/kh/ices/src/reencode.c
===================================================================
--- icecast/branches/kh/ices/src/reencode.c	2006-01-03 19:39:04 UTC (rev 10691)
+++ icecast/branches/kh/ices/src/reencode.c	2006-01-04 01:28:47 UTC (rev 10692)
@@ -61,11 +61,8 @@
 {
     if (s)
     {
-        if (s->need_headers == 0)
-        {
-            vorbis_block_clear (&s->vb);
-            vorbis_dsp_clear (&s->vd);
-        }
+        vorbis_block_clear (&s->vb);
+        vorbis_dsp_clear (&s->vd);
         vorbis_comment_clear (&s->vc);
         vorbis_info_clear (&s->vi);
         downmix_clear (s->downmix);

Modified: icecast/branches/kh/ices/src/stream.c
===================================================================
--- icecast/branches/kh/ices/src/stream.c	2006-01-03 19:39:04 UTC (rev 10691)
+++ icecast/branches/kh/ices/src/stream.c	2006-01-04 01:28:47 UTC (rev 10692)
@@ -106,6 +106,7 @@
 {
     struct output_state *state = &stream->output;
     struct output_module *mod;
+    ogg_int64_t granulepos;
 
     if (op->b_o_s)
     {
@@ -190,9 +191,11 @@
     /* printf("granulepos is %lld\n", op->granulepos); */
 
     mod = state->head;
+    granulepos = op->granulepos;
     while (mod)
     {
         mod->output_send (mod, op, samples);
+        op->granulepos = granulepos;
         mod = mod->next;
     }
 
@@ -223,7 +226,7 @@
         LOG_DEBUG1("Flushing out encoded ogg packets stream %d", stream->id);
         while (encode_packetout (s->enc, &op) > 0)
         {
-            if (send_it && _output_oggpacket (stream, &op, 0) < 0)
+            if (send_it && _output_oggpacket (stream, &op, encoder_pkt_samples (s->enc)) < 0)
                 send_it = 0;
         }
     }
@@ -266,7 +269,7 @@
     }
     while (encode_packetout (s->enc, &op) > 0)
     {
-        if (ret == 0 && _output_oggpacket (stream, &op, 0) < 0)
+        if (ret == 0 && _output_oggpacket (stream, &op, encoder_pkt_samples (s->enc)) < 0)
         {
             ret = -1;
             break;
@@ -335,7 +338,7 @@
         }
         while (encode_packetout (enc, &op) > 0)
         {
-            _output_oggpacket (stream, &op, 0);
+            _output_oggpacket (stream, &op, encoder_pkt_samples (enc));
         }
         ops->data = s;
         ops->flush_data = flush_ogg_packets;
@@ -370,10 +373,11 @@
     while (1)
     {
         ogg_packet reencoded_packet;
+        struct reencode *reenc = stream->ops->data;
 
         if ((ret = reencode_packetout (stream->ops->data, &reencoded_packet)) > 0)
         {
-            _output_oggpacket (stream, &reencoded_packet, 0);
+            _output_oggpacket (stream, &reencoded_packet, encoder_pkt_samples (reenc->encoder));
         }
         else
         {



More information about the commits mailing list