[xiph-cvs] cvs commit: ices/src playlist_script.c playlist_basic.h im_playlist.c

Michael Smith msmith at xiph.org
Sat Jun 29 08:19:19 PDT 2002



msmith      02/06/29 08:19:19

  Modified:    src      playlist_basic.h im_playlist.c
  Added:       src      playlist_script.c
  Log:
  Add support for calling an external program to get a filename for playlist
  streaming, for a user who wanted this.

Revision  Changes    Path
1.4       +2 -1      ices/src/playlist_basic.h

Index: playlist_basic.h
===================================================================
RCS file: /usr/local/cvsroot/ices/src/playlist_basic.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- playlist_basic.h	2001/09/28 10:16:54	1.3
+++ playlist_basic.h	2002/06/29 15:19:18	1.4
@@ -1,7 +1,7 @@
 /* playlist_basic.h
  * - Simple unscripted playlist
  *
- * $Id: playlist_basic.h,v 1.3 2001/09/28 10:16:54 msmith Exp $
+ * $Id: playlist_basic.h,v 1.4 2002/06/29 15:19:18 msmith Exp $
  *
  * Copyright (c) 2001 Michael Smith <msmith at labyrinth.net.au>
  *
@@ -30,6 +30,7 @@
 void playlist_basic_clear(void *data);
 char *playlist_basic_get_next_filename(void *data);
 int playlist_basic_initialise(module_param_t *params, playlist_state_t *pl);
+int playlist_script_initialise(module_param_t *params, playlist_state_t *pl);
 
 
 #endif  /* __PLAYLIST_BASIC_H__ */

<p><p>1.4       +2 -1      ices/src/im_playlist.c

Index: im_playlist.c
===================================================================
RCS file: /usr/local/cvsroot/ices/src/im_playlist.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- im_playlist.c	2001/10/21 10:21:59	1.3
+++ im_playlist.c	2002/06/29 15:19:18	1.4
@@ -1,7 +1,7 @@
 /* playlist.c
  * - Basic playlist functionality
  *
- * $Id: im_playlist.c,v 1.3 2001/10/21 10:21:59 msmith Exp $
+ * $Id: im_playlist.c,v 1.4 2002/06/29 15:19:18 msmith Exp $
  *
  * Copyright (c) 2001 Michael Smith <msmith at labyrinth.net.au>
  *
@@ -41,6 +41,7 @@
 
 static module modules[] = {
         { "basic", playlist_basic_initialise},
+	{ "script", playlist_script_initialise},
         {NULL,NULL}
 };
 

<p><p>1.1                  ices/src/playlist_script.c

Index: playlist_script.c
===================================================================
/* playlist_script.c
 * - Gets a filename to play back based on output from a program/shell script
 *   run each time.
 *
 * $Id: playlist_script.c,v 1.1 2002/06/29 15:19:18 msmith Exp $
 *
 * Copyright (c) 2001 Michael Smith <msmith at labyrinth.net.au>
 *
 * This program is distributed under the terms of the GNU General
 * Public License, version 2. You may use, modify, and redistribute
 * it under the terms of this license. A copy should be included
 * with this source.
 */

#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>

#include "config.h"
#include "inputmodule.h"
#include "im_playlist.h"

#define MODULE "playlist-script/"
#include "logging.h"

typedef struct {
    char *program;
    char fn[1024];
} script_playlist;

void playlist_script_clear(void *data) {
    if(data)
        free(data);
}

char *playlist_script_get_filename(void *data) {
    script_playlist *pl = data;
    char *prog = pl->program;
    FILE *pipe;
    char *buf = pl->fn;

<p>    pipe = popen(prog, "r");

    if(fgets(buf, 1024, pipe) == NULL) {
        LOG_ERROR1("Couldn't read filename from pipe to program \"%s\"", prog);
        return NULL;
    }

    if(buf[0] == '\n' || (buf[0] == '\r' && buf[1] == '\n')) {
        LOG_ERROR1("Got newlines instead of filename from program \"%s\"", prog);
        return NULL;
    }

    if(buf[strlen(buf)-1] == '\n')
        buf[strlen(buf)-1] = 0;
    /* De-fuck windows files. */
    if(strlen(buf) > 0 && buf[strlen(buf)-1] == '\r')
        buf[strlen(buf)-1] = 0;

    return buf;
}

int playlist_script_initialise(module_param_t *params, playlist_state_t *pl)
{
    script_playlist *data;

    pl->get_filename = playlist_script_get_filename;
    pl->clear = playlist_script_clear;

    pl->data = calloc(1, sizeof(script_playlist));

    data = (script_playlist *)pl->data;

    while(params != NULL) {
        if(!strcmp(params->name, "program")) {
            if(data->program) free(data->program);
            data->program = params->value;
        }
        else if(!strcmp(params->name, "type")) {
            /* We ignore this one */
        }
        else
            LOG_WARN1("Unknown parameter to playlist script module: %s",
                    params->name);
        params = params->next;
    }

    if(!data->program) {
        LOG_ERROR0("No program name specified for playlist module");
        free(data);
        return -1;
    }

    return 0;
}

<p><p><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