-/* Gnome-Streamer
- * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
+/* GStreamer
+ * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
+ * 2000 Wim Taymans <wtay@chello.be>
+ *
+ * gstpipefilter.c:
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
void gst_pipefilter_chain(GstPad *pad,GstBuffer *buf);
-static gboolean gst_pipefilter_change_state(GstElement *element,
- GstElementState state);
+static GstElementStateReturn gst_pipefilter_change_state(GstElement *element);
-static GstFilterClass *parent_class = NULL;
+static GstElementClass *parent_class = NULL;
//static guint gst_pipefilter_signals[LAST_SIGNAL] = { 0 };
GtkType
(GtkArgGetFunc)gst_pipefilter_get_arg,
(GtkClassInitFunc)NULL,
};
- pipefilter_type = gtk_type_unique(GST_TYPE_FILTER,&pipefilter_info);
+ pipefilter_type = gtk_type_unique(GST_TYPE_ELEMENT,&pipefilter_info);
}
return pipefilter_type;
}
static void gst_pipefilter_class_init(GstPipefilterClass *klass) {
GtkObjectClass *gtkobject_class;
- GstFilterClass *gstfilter_class;
GstElementClass *gstelement_class;
gtkobject_class = (GtkObjectClass*)klass;
- gstfilter_class = (GstFilterClass*)klass;
gstelement_class = (GstElementClass*)klass;
- parent_class = gtk_type_class(GST_TYPE_FILTER);
+ parent_class = gtk_type_class(GST_TYPE_ELEMENT);
gstelement_class->change_state = gst_pipefilter_change_state;
pipefilter->seq = 0;
}
-GstElement *gst_pipefilter_new(gchar *name) {
- GstElement *pipefilter = GST_ELEMENT(gtk_type_new(GST_TYPE_PIPEFILTER));
- gst_element_set_name(GST_ELEMENT(pipefilter),name);
- return pipefilter;
-}
-
-
static gboolean gst_pipefilter_read_and_push(GstPipefilter *pipefilter) {
GstBuffer *newbuf;
glong readbytes;
g_return_val_if_fail(GST_BUFFER_DATA(newbuf) != NULL, FALSE);
/* read it in from the file */
- DEBUG("attemting to read %d bytes\n", pipefilter->bytes_per_read);
+ GST_DEBUG (0,"attemting to read %ld bytes\n", pipefilter->bytes_per_read);
readbytes = read(pipefilter->fdout[0],GST_BUFFER_DATA(newbuf),pipefilter->bytes_per_read);
- DEBUG("read %d bytes\n", readbytes);
+ GST_DEBUG (0,"read %ld bytes\n", readbytes);
if (readbytes < 0) {
if (errno == EAGAIN) {
- DEBUG("no input yet\n");
+ GST_DEBUG (0,"no input yet\n");
gst_buffer_unref(newbuf);
return FALSE;
}
g_return_if_fail(GST_IS_PAD(pad));
g_return_if_fail(buf != NULL);
- pipefilter = GST_PIPEFILTER(pad->parent);
+ pipefilter = GST_PIPEFILTER (gst_pad_get_parent (pad));
while (gst_pipefilter_read_and_push(pipefilter));
data = GST_BUFFER_DATA(buf);
size = GST_BUFFER_SIZE(buf);
- DEBUG("attemting to write %d bytes\n", size);
+ GST_DEBUG (0,"attemting to write %ld bytes\n", size);
writebytes = write(pipefilter->fdin[1],data,size);
- DEBUG("written %d bytes\n", writebytes);
+ GST_DEBUG (0,"written %ld bytes\n", writebytes);
if (writebytes < 0) {
perror("write");
gst_element_error(GST_ELEMENT(pipefilter),"writing");
GST_FLAG_UNSET(src,GST_PIPEFILTER_OPEN);
}
-static gboolean gst_pipefilter_change_state(GstElement *element,
- GstElementState state) {
+static GstElementStateReturn gst_pipefilter_change_state(GstElement *element) {
g_return_val_if_fail(GST_IS_PIPEFILTER(element), FALSE);
- switch (state) {
- case GST_STATE_RUNNING:
- if (!gst_pipefilter_open_file(GST_PIPEFILTER(element)))
- return FALSE;
- break;
- case ~GST_STATE_RUNNING:
+ /* if going down into NULL state, close the file if it's open */
+ if (GST_STATE_PENDING(element) == GST_STATE_NULL) {
+ if (GST_FLAG_IS_SET(element,GST_PIPEFILTER_OPEN))
gst_pipefilter_close_file(GST_PIPEFILTER(element));
- break;
- default:
- break;
- }
+ /* otherwise (READY or higher) we need to open the file */
+ } else {
+ if (!GST_FLAG_IS_SET(element,GST_PIPEFILTER_OPEN)) {
+ if (!gst_pipefilter_open_file(GST_PIPEFILTER(element)))
+ return GST_STATE_FAILURE;
+ }
+ }
if (GST_ELEMENT_CLASS(parent_class)->change_state)
- return GST_ELEMENT_CLASS(parent_class)->change_state(element,state);
- return TRUE;
+ return GST_ELEMENT_CLASS(parent_class)->change_state(element);
+ return GST_STATE_SUCCESS;
}