[xiph-cvs] cvs commit: ices/src im_stdinpcm.c im_stdinpcm.h

Brendan brendan at xiph.org
Sat Jul 5 23:20:35 PDT 2003



brendan     03/07/06 02:20:34

  Modified:    src      im_stdinpcm.c im_stdinpcm.h
  Log:
  metadata support for stdinpcm, modified from a patch by Deti Fliegl, which
  in turn was mostly cut and pasted from im_oss.c :)

Revision  Changes    Path
1.9       +67 -9     ices/src/im_stdinpcm.c

Index: im_stdinpcm.c
===================================================================
RCS file: /usr/local/cvsroot/ices/src/im_stdinpcm.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -p -u -r1.8 -r1.9
--- im_stdinpcm.c	28 Mar 2003 01:07:37 -0000	1.8
+++ im_stdinpcm.c	6 Jul 2003 06:20:34 -0000	1.9
@@ -1,7 +1,7 @@
 /* im_stdinpcm.c
  * - Raw PCM input from stdin
  *
- * $Id: im_stdinpcm.c,v 1.8 2003/03/28 01:07:37 karl Exp $
+ * $Id: im_stdinpcm.c,v 1.9 2003/07/06 06:20:34 brendan Exp $
  *
  * Copyright (c) 2001 Michael Smith <msmith at labyrinth.net.au>
  *
@@ -26,6 +26,7 @@
 #include "cfgparse.h"
 #include "stream.h"
 
+#include "metadata.h"
 #include "inputmodule.h"
 #include "input.h"
 #include "im_stdinpcm.h"
@@ -35,21 +36,46 @@
 
 #define BUFSIZE 32768
 
+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:
-            if(mod)
-            {
-                if(mod->internal)
-                    free(mod->internal);
-                free(mod);
-            }
+	    close_module(mod);
             break;
         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 +84,24 @@ static int event_handler(input_module_t 
     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 +145,21 @@ input_module_t *stdin_open_module(module
     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 = NULL;
+
+    thread_mutex_create(&s->metadatalock);
 
     current = params;
 
@@ -121,13 +169,23 @@ input_module_t *stdin_open_module(module
             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;
 }
-
 

<p><p>1.4       +3 -1      ices/src/im_stdinpcm.h

Index: im_stdinpcm.h
===================================================================
RCS file: /usr/local/cvsroot/ices/src/im_stdinpcm.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -p -u -r1.3 -r1.4
--- im_stdinpcm.h	16 Mar 2003 14:21:48 -0000	1.3
+++ im_stdinpcm.h	6 Jul 2003 06:20:34 -0000	1.4
@@ -1,7 +1,7 @@
 /* im_stdinpcm.h
  * - stdin reading
  *
- * $Id: im_stdinpcm.h,v 1.3 2003/03/16 14:21:48 msmith Exp $
+ * $Id: im_stdinpcm.h,v 1.4 2003/07/06 06:20:34 brendan Exp $
  *
  * Copyright (c) 2001 Michael Smith <msmith at labyrinth.net.au>
  *
@@ -21,7 +21,9 @@ typedef struct
 {
     int rate;
     int channels;
+    char **metadata;
     int newtrack;
+    mutex_t metadatalock;
 } stdinpcm_state; 
 
 input_module_t *stdin_open_module(module_param_t *params);

<p><p>--- >8 ----
List archives:  http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'cvs-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 commits mailing list