[icecast-dev] ices: Metadata for im_stdinpcm

Deti Fliegl fliegl at cs.tum.edu
Tue Jun 17 04:39:52 PDT 2003



Hi,

I added metadata support for the stdinpcm module of ices. The metadata
have to be submitted via file (as stdin is already used for the strem).
Please apply this patch to the current cvs sources.

<p>Deti

<p>


Index: im_stdinpcm.c
===================================================================
RCS file: /usr/local/cvsroot/ices/src/im_stdinpcm.c,v
retrieving revision 1.8
diff -u -r1.8 im_stdinpcm.c
--- im_stdinpcm.c	28 Mar 2003 01:07:37 -0000	1.8
+++ im_stdinpcm.c	17 Jun 2003 11:03:09 -0000
@@ -25,7 +25,7 @@
 
 #include "cfgparse.h"
 #include "stream.h"
-
+#include "metadata.h"
 #include "inputmodule.h"
 #include "input.h"
 #include "im_stdinpcm.h"
@@ -35,8 +35,25 @@
 
 #define BUFSIZE 32768
 
+/* Currently not used, but for future use */
+static void close_module(input_module_t *mod)
+{
+    if(mod)
+    {
+        if(mod->internal)
+        {
+            stdinpcm_state *s = mod->internal;
+            thread_mutex_destroy(&s->metadatalock);
+            free(s);
+        }
+        free(mod);
+    }
+}
+
 static int event_handler(input_module_t *mod, enum event_type ev, void *param)
 {
+    stdinpcm_state *s = mod->internal;
+
     switch(ev)
     {
         case EVENT_SHUTDOWN:
@@ -50,6 +67,20 @@
         case EVENT_NEXTTRACK:
             ((stdinpcm_state *)mod->internal)->newtrack = 1;
             break;
+        case EVENT_METADATAUPDATE:
+            thread_mutex_lock(&s->metadatalock);
+            if(s->metadata)
+            {
+                char **md = s->metadata;
+                while(*md)
+                    free(*md++);
+                free(s->metadata);
+            }
+
+            s->metadata = (char **)param;
+            s->newtrack = 1;
+            thread_mutex_unlock(&s->metadatalock);
+            break;
         default:
             LOG_WARN1("Unhandled event %d", ev);
             return -1;
@@ -58,6 +89,24 @@
     return 0;
 }
 
+static void metadata_update(void *self, vorbis_comment *vc)
+{
+    stdinpcm_state *s = self;
+    char **md;
+
+    thread_mutex_lock(&s->metadatalock);
+
+    md = s->metadata;
+
+    if(md)
+    {
+        while(*md)
+            vorbis_comment_add(vc, *md++);
+    }
+
+    thread_mutex_unlock(&s->metadatalock);
+}
+
 /* Core streaming function for this module
  * This is what actually produces the data which gets streamed.
  *
@@ -101,17 +150,21 @@
     input_module_t *mod = calloc(1, sizeof(input_module_t));
     stdinpcm_state *s;
     module_param_t *current;
+    int use_metadata = 1; /* Default to on */
 
     mod->type = ICES_INPUT_PCM;
     mod->getdata = stdin_read;
     mod->handle_event = event_handler;
-    mod->metadata_update = NULL;
+    mod->metadata_update = metadata_update;
 
     mod->internal = malloc(sizeof(stdinpcm_state));
     s = mod->internal;
 
     s->rate = 44100; /* Defaults */
     s->channels = 2; 
+    s->metadata = 0;
+
+    thread_mutex_create(&s->metadatalock);
 
     current = params;
 
@@ -121,10 +174,20 @@
             s->rate = atoi(current->value);
         else if(!strcmp(current->name, "channels"))
             s->channels = atoi(current->value);
+        else if(!strcmp(current->name, "metadata"))
+            use_metadata = atoi(current->value);
+        else if(!strcmp(current->name, "metadatafilename"))
+            ices_config->metadata_filename = current->value;
         else
             LOG_WARN1("Unknown parameter %s for stdinpcm module", current->name);
 
         current = current->next;
+    }
+    if(use_metadata)
+    {
+        if(ices_config->metadata_filename)
+            thread_create("im_stdinpcm-metadata", metadata_thread_signal, mod, 1);
+        LOG_INFO0("Started metadata update thread");
     }
 
     return mod;
Index: im_stdinpcm.h
===================================================================
RCS file: /usr/local/cvsroot/ices/src/im_stdinpcm.h,v
retrieving revision 1.3
diff -u -r1.3 im_stdinpcm.h
--- im_stdinpcm.h	16 Mar 2003 14:21:48 -0000	1.3
+++ im_stdinpcm.h	17 Jun 2003 11:03:09 -0000
@@ -21,7 +21,9 @@
 {
     int rate;
     int channels;
+    char **metadata;
     int newtrack;
+    mutex_t metadatalock;
 } stdinpcm_state; 
 
 input_module_t *stdin_open_module(module_param_t *params);

<p>--- >8 ----
List archives:  http://www.xiph.org/archives/
icecast project homepage: http://www.icecast.org/
To unsubscribe from this list, send a message to 'icecast-dev-request at xiph.org'
containing only the word 'unsubscribe' in the body.  No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.



More information about the Icecast-dev mailing list