diff options
Diffstat (limited to 'gst/playondemand')
-rw-r--r-- | gst/playondemand/demo-mp3.c | 34 | ||||
-rw-r--r-- | gst/playondemand/filter.func | 9 | ||||
-rw-r--r-- | gst/playondemand/gstplayondemand.c | 95 | ||||
-rw-r--r-- | gst/playondemand/gstplayondemand.h | 2 |
4 files changed, 51 insertions, 89 deletions
diff --git a/gst/playondemand/demo-mp3.c b/gst/playondemand/demo-mp3.c index 0cfb3397..d0264060 100644 --- a/gst/playondemand/demo-mp3.c +++ b/gst/playondemand/demo-mp3.c @@ -3,19 +3,19 @@ void play (GtkButton *button, gpointer data) { - gtk_signal_emit_by_name(GTK_OBJECT(data), "play"); + g_signal_emit_by_name(G_OBJECT(data), "play"); } void reset (GtkButton *button, gpointer data) { - gtk_signal_emit_by_name(GTK_OBJECT(data), "reset"); + g_signal_emit_by_name(G_OBJECT(data), "reset"); } int main(int argc, char **argv) { guint channels; GtkWidget *window, *vbox, *play_button, *reset_button, *quit_button; - GstElement *filesrc, *mad, *stereo2mono, *pod, *osssink, *pipeline; + GstElement *src, *mad, *pod, *osssink, *pipeline; gst_init (&argc, &argv); gtk_init (&argc, &argv); @@ -25,33 +25,25 @@ int main(int argc, char **argv) exit(-1); } - filesrc = gst_elementfactory_make("filesrc", "filesrc"); + src = gst_elementfactory_make("filesrc", "filesrc"); mad = gst_elementfactory_make("mad", "mad"); pod = gst_elementfactory_make("playondemand", "playondemand"); osssink = gst_elementfactory_make("osssink", "osssink"); - gtk_object_set(GTK_OBJECT(filesrc), "location", argv[1], NULL); - gtk_object_set(GTK_OBJECT(osssink), "fragment", 0x00180008, NULL); - gtk_object_get(GTK_OBJECT(osssink), "channels", &channels, NULL); + g_object_set(G_OBJECT(src), "location", argv[1], NULL); + g_object_set(G_OBJECT(osssink), "fragment", 0x00180008, NULL); + g_object_get(G_OBJECT(osssink), "channels", &channels, NULL); pipeline = gst_pipeline_new("app"); - gst_bin_add(GST_BIN(pipeline), filesrc); + gst_bin_add(GST_BIN(pipeline), src); gst_bin_add(GST_BIN(pipeline), mad); gst_bin_add(GST_BIN(pipeline), pod); gst_bin_add(GST_BIN(pipeline), osssink); - gst_element_connect(filesrc, "src", mad, "sink"); + gst_element_connect(src, "src", mad, "sink"); gst_element_connect(pod, "src", osssink, "sink"); - - if (channels != 2) { - gst_element_connect(mad, "src", pod, "sink"); - } else { - stereo2mono = gst_elementfactory_make("stereo2mono", "stereo2mono"); - gst_bin_add(GST_BIN(pipeline), stereo2mono); - gst_element_connect(mad, "src", stereo2mono, "sink"); - gst_element_connect(stereo2mono, "src", pod, "sink"); - } + gst_element_connect(mad, "src", pod, "sink"); gst_element_set_state(pipeline, GST_STATE_PLAYING); @@ -70,9 +62,9 @@ int main(int argc, char **argv) gtk_box_pack_start(GTK_BOX(vbox), quit_button, FALSE, FALSE, 2); /* connect things ... */ - gtk_signal_connect(GTK_OBJECT(play_button), "clicked", play, pod); - gtk_signal_connect(GTK_OBJECT(reset_button), "clicked", reset, pod); - gtk_signal_connect(GTK_OBJECT(quit_button), "clicked", gtk_main_quit, NULL); + g_signal_connect(G_OBJECT(play_button), "clicked", G_CALLBACK(play), pod); + g_signal_connect(G_OBJECT(reset_button), "clicked", G_CALLBACK(reset), pod); + g_signal_connect(G_OBJECT(quit_button), "clicked", gtk_main_quit, NULL); /* show the gui. */ gtk_widget_show(play_button); diff --git a/gst/playondemand/filter.func b/gst/playondemand/filter.func index 08bc2f97..2c11717b 100644 --- a/gst/playondemand/filter.func +++ b/gst/playondemand/filter.func @@ -64,14 +64,7 @@ do { } else { j = 0; - if (filter->srcpool) { - out = gst_buffer_new_from_pool(filter->srcpool, 0, 0); - } else { - out = gst_buffer_new(); - - GST_BUFFER_DATA(out) = (gchar *) g_new(_TYPE_, POD_GSTBUFSIZE / sizeof(_TYPE_)); - GST_BUFFER_SIZE(out) = POD_GSTBUFSIZE; - } + out = gst_buffer_new_from_pool(filter->bufpool, 0, 0); } /******************************************************************************/ diff --git a/gst/playondemand/gstplayondemand.c b/gst/playondemand/gstplayondemand.c index b3d99846..103e998c 100644 --- a/gst/playondemand/gstplayondemand.c +++ b/gst/playondemand/gstplayondemand.c @@ -24,10 +24,10 @@ #define POD_MAX_PLAYS 192 /* maximum number of simultaneous plays */ -#define POD_GSTBUFSIZE 4096 /* gstreamer buffer size to make if no +#define POD_BUFPOOL_SIZE 4096 /* gstreamer buffer size to make if no bufferpool is available, must be divisible by sizeof(gfloat) */ -#define POD_BUFSPERCHUNK 6 /* number of buffers to allocate per chunk in +#define POD_BUFPOOL_NUM 6 /* number of buffers to allocate per chunk in sink buffer pool */ #define POD_BUFFER_SIZE 882000 /* enough space for 10 seconds of 16-bit audio at 44100 samples per second ... */ @@ -50,6 +50,8 @@ enum { LAST_SIGNAL }; +static guint gst_pod_filter_signals[LAST_SIGNAL] = { 0 }; + enum { ARG_0, ARG_SILENT, @@ -91,21 +93,20 @@ play_on_demand_src_factory (void) return template; } -static void play_on_demand_class_init (GstPlayOnDemandClass *klass); -static void play_on_demand_init (GstPlayOnDemand *filter); +static void play_on_demand_class_init (GstPlayOnDemandClass *klass); +static void play_on_demand_init (GstPlayOnDemand *filter); -static void play_on_demand_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec); -static void play_on_demand_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec); +static void play_on_demand_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec); +static void play_on_demand_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec); -static gint play_on_demand_parse_caps (GstPlayOnDemand *filter, GstCaps *caps); +static GstPadConnectReturn play_on_demand_pad_connect (GstPad *pad, GstCaps *caps); -static void play_on_demand_loop (GstElement *elem); +static void play_on_demand_loop (GstElement *elem); -static void play_on_demand_play_handler (GstElement *elem); -static void play_on_demand_reset_handler (GstElement *elem); +static void play_on_demand_play_handler (GstElement *elem); +static void play_on_demand_reset_handler (GstElement *elem); static GstElementClass *parent_class = NULL; -static guint gst_pod_filter_signals[LAST_SIGNAL] = { 0 }; static GstBufferPool* play_on_demand_get_bufferpool (GstPad *pad) @@ -117,44 +118,17 @@ play_on_demand_get_bufferpool (GstPad *pad) return gst_pad_get_bufferpool(filter->srcpad); } -/* -static GstPadNegotiateReturn -play_on_demand_negotiate_src (GstPad *pad, GstCaps **caps, gpointer *data) +static GstPadConnectReturn +play_on_demand_pad_connect (GstPad *pad, GstCaps *caps) { - GstPlayOnDemand* filter = GST_PLAYONDEMAND(gst_pad_get_parent(pad)); - - if (*caps == NULL) - return GST_PAD_NEGOTIATE_FAIL; - - if (play_on_demand_parse_caps(filter, *caps)) - return GST_PAD_NEGOTIATE_FAIL; + const gchar *format; + GstPlayOnDemand *filter; - return gst_pad_negotiate_proxy(pad, filter->sinkpad, caps); -} + g_return_val_if_fail(caps != NULL, GST_PAD_CONNECT_DELAYED); + g_return_val_if_fail(pad != NULL, GST_PAD_CONNECT_DELAYED); -static GstPadNegotiateReturn -play_on_demand_negotiate_sink (GstPad *pad, GstCaps **caps, gpointer *data) -{ - GstPlayOnDemand* filter = GST_PLAYONDEMAND(gst_pad_get_parent(pad)); - - if (*caps == NULL) - return GST_PAD_NEGOTIATE_FAIL; - - if (play_on_demand_parse_caps(filter, *caps)) - return GST_PAD_NEGOTIATE_FAIL; - - return gst_pad_negotiate_proxy(pad, filter->srcpad, caps); -} -*/ + filter = GST_PLAYONDEMAND(GST_PAD_PARENT(pad)); -static gint -play_on_demand_parse_caps (GstPlayOnDemand *filter, GstCaps *caps) -{ - const gchar *format; - - g_return_val_if_fail(filter != NULL, -1); - g_return_val_if_fail(caps != NULL, -1); - format = gst_caps_get_string(caps, "format"); filter->rate = gst_caps_get_int(caps, "rate"); @@ -173,7 +147,7 @@ play_on_demand_parse_caps (GstPlayOnDemand *filter, GstCaps *caps) g_print ("PlayOnDemand : format int, bit width %d, endianness %d, signed %s\n", filter->width, filter->endianness, filter->is_signed ? "yes" : "no"); } - } else if (strcmp(format, "float")==0) { + } else if (strcmp(format, "float") == 0) { filter->format = GST_PLAYONDEMAND_FORMAT_FLOAT; filter->layout = gst_caps_get_string(caps, "layout"); filter->intercept = gst_caps_get_float(caps, "intercept"); @@ -184,15 +158,17 @@ play_on_demand_parse_caps (GstPlayOnDemand *filter, GstCaps *caps) g_print ("PlayOnDemand : format float, layout %s, intercept %f, slope %f\n", filter->layout, filter->intercept, filter->slope); } - } else { - return -1; } - return 0; -} + if (GST_CAPS_IS_FIXED (caps) && ! gst_pad_try_set_caps (filter->srcpad, caps)) + return GST_PAD_CONNECT_REFUSED; + + return GST_PAD_CONNECT_DELAYED; +} GType -gst_play_on_demand_get_type(void) { +gst_play_on_demand_get_type (void) +{ static GType play_on_demand_type = 0; if (! play_on_demand_type) { @@ -246,7 +222,7 @@ play_on_demand_class_init (GstPlayOnDemandClass *klass) g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_SILENT, g_param_spec_boolean("silent","silent","silent", - TRUE, G_PARAM_READWRITE)); // CHECKME + TRUE, G_PARAM_READWRITE)); g_object_class_install_property(G_OBJECT_CLASS(klass), ARG_FOLLOWTAIL, g_param_spec_boolean("follow-stream-tail","follow-stream-tail","follow-stream-tail", @@ -265,20 +241,17 @@ play_on_demand_init (GstPlayOnDemand *filter) { guint i; + filter->srcpad = gst_pad_new_from_template(play_on_demand_src_factory(), "src"); filter->sinkpad = gst_pad_new_from_template(play_on_demand_sink_factory(), "sink"); - //gst_pad_set_negotiate_function(filter->sinkpad, play_on_demand_negotiate_sink); - gst_pad_set_bufferpool_function(filter->sinkpad, play_on_demand_get_bufferpool); - filter->srcpad = gst_pad_new_from_template(play_on_demand_src_factory(), "src"); - //gst_pad_set_negotiate_function(filter->srcpad, play_on_demand_negotiate_src); + gst_pad_set_bufferpool_function(filter->sinkpad, play_on_demand_get_bufferpool); + gst_pad_set_connect_function(filter->sinkpad, play_on_demand_pad_connect); gst_element_add_pad(GST_ELEMENT(filter), filter->sinkpad); gst_element_add_pad(GST_ELEMENT(filter), filter->srcpad); gst_element_set_loop_function(GST_ELEMENT(filter), play_on_demand_loop); - filter->sinkpool = gst_buffer_pool_get_default(POD_GSTBUFSIZE, POD_BUFSPERCHUNK); - filter->follow_stream_tail = FALSE; filter->silent = TRUE; @@ -309,7 +282,11 @@ play_on_demand_loop (GstElement *elem) g_return_if_fail(filter != NULL); g_return_if_fail(GST_IS_PLAYONDEMAND(filter)); - filter->srcpool = gst_pad_get_bufferpool(filter->srcpad); + filter->bufpool = gst_pad_get_bufferpool(filter->srcpad); + + if (filter->bufpool == NULL) { + filter->bufpool = gst_buffer_pool_get_default(POD_BUFPOOL_SIZE, POD_BUFPOOL_NUM); + } in = gst_pad_pull(filter->sinkpad); diff --git a/gst/playondemand/gstplayondemand.h b/gst/playondemand/gstplayondemand.h index 7ca8206e..57dd189d 100644 --- a/gst/playondemand/gstplayondemand.h +++ b/gst/playondemand/gstplayondemand.h @@ -57,7 +57,7 @@ struct _GstPlayOnDemand { GstElement element; GstPad *sinkpad, *srcpad; - GstBufferPool *sinkpool, *srcpool; + GstBufferPool *bufpool; /* these next data elements are for the filter's internal buffers and list of play pointers (offsets in the internal buffers). there are also flags for |