Updated to work with the new capsnego stuff.

Original commit message from CVS:
Updated to work with the new capsnego stuff.
This commit is contained in:
Leif Johnson 2002-01-22 04:44:21 +00:00
parent 1924c5ce0c
commit d3e8b42dfe
4 changed files with 53 additions and 91 deletions

View file

@ -3,19 +3,19 @@
void play (GtkButton *button, gpointer data) 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) 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) int main(int argc, char **argv)
{ {
guint channels; guint channels;
GtkWidget *window, *vbox, *play_button, *reset_button, *quit_button; 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); gst_init (&argc, &argv);
gtk_init (&argc, &argv); gtk_init (&argc, &argv);
@ -25,33 +25,25 @@ int main(int argc, char **argv)
exit(-1); exit(-1);
} }
filesrc = gst_elementfactory_make("filesrc", "filesrc"); src = gst_elementfactory_make("filesrc", "filesrc");
mad = gst_elementfactory_make("mad", "mad"); mad = gst_elementfactory_make("mad", "mad");
pod = gst_elementfactory_make("playondemand", "playondemand"); pod = gst_elementfactory_make("playondemand", "playondemand");
osssink = gst_elementfactory_make("osssink", "osssink"); osssink = gst_elementfactory_make("osssink", "osssink");
gtk_object_set(GTK_OBJECT(filesrc), "location", argv[1], NULL); g_object_set(G_OBJECT(src), "location", argv[1], NULL);
gtk_object_set(GTK_OBJECT(osssink), "fragment", 0x00180008, NULL); g_object_set(G_OBJECT(osssink), "fragment", 0x00180008, NULL);
gtk_object_get(GTK_OBJECT(osssink), "channels", &channels, NULL); g_object_get(G_OBJECT(osssink), "channels", &channels, NULL);
pipeline = gst_pipeline_new("app"); 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), mad);
gst_bin_add(GST_BIN(pipeline), pod); gst_bin_add(GST_BIN(pipeline), pod);
gst_bin_add(GST_BIN(pipeline), osssink); 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"); gst_element_connect(pod, "src", osssink, "sink");
gst_element_connect(mad, "src", pod, "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_set_state(pipeline, GST_STATE_PLAYING); 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); gtk_box_pack_start(GTK_BOX(vbox), quit_button, FALSE, FALSE, 2);
/* connect things ... */ /* connect things ... */
gtk_signal_connect(GTK_OBJECT(play_button), "clicked", play, pod); g_signal_connect(G_OBJECT(play_button), "clicked", G_CALLBACK(play), pod);
gtk_signal_connect(GTK_OBJECT(reset_button), "clicked", reset, pod); g_signal_connect(G_OBJECT(reset_button), "clicked", G_CALLBACK(reset), pod);
gtk_signal_connect(GTK_OBJECT(quit_button), "clicked", gtk_main_quit, NULL); g_signal_connect(G_OBJECT(quit_button), "clicked", gtk_main_quit, NULL);
/* show the gui. */ /* show the gui. */
gtk_widget_show(play_button); gtk_widget_show(play_button);

View file

@ -64,14 +64,7 @@ do {
} else { } else {
j = 0; j = 0;
if (filter->srcpool) { out = gst_buffer_new_from_pool(filter->bufpool, 0, 0);
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;
}
} }
/******************************************************************************/ /******************************************************************************/

View file

@ -24,10 +24,10 @@
#define POD_MAX_PLAYS 192 /* maximum number of simultaneous plays */ #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 bufferpool is available, must be divisible
by sizeof(gfloat) */ 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 */ sink buffer pool */
#define POD_BUFFER_SIZE 882000 /* enough space for 10 seconds of 16-bit audio #define POD_BUFFER_SIZE 882000 /* enough space for 10 seconds of 16-bit audio
at 44100 samples per second ... */ at 44100 samples per second ... */
@ -50,6 +50,8 @@ enum {
LAST_SIGNAL LAST_SIGNAL
}; };
static guint gst_pod_filter_signals[LAST_SIGNAL] = { 0 };
enum { enum {
ARG_0, ARG_0,
ARG_SILENT, ARG_SILENT,
@ -91,21 +93,20 @@ play_on_demand_src_factory (void)
return template; return template;
} }
static void play_on_demand_class_init (GstPlayOnDemandClass *klass); static void play_on_demand_class_init (GstPlayOnDemandClass *klass);
static void play_on_demand_init (GstPlayOnDemand *filter); 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_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_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_play_handler (GstElement *elem);
static void play_on_demand_reset_handler (GstElement *elem); static void play_on_demand_reset_handler (GstElement *elem);
static GstElementClass *parent_class = NULL; static GstElementClass *parent_class = NULL;
static guint gst_pod_filter_signals[LAST_SIGNAL] = { 0 };
static GstBufferPool* static GstBufferPool*
play_on_demand_get_bufferpool (GstPad *pad) play_on_demand_get_bufferpool (GstPad *pad)
@ -117,43 +118,16 @@ play_on_demand_get_bufferpool (GstPad *pad)
return gst_pad_get_bufferpool(filter->srcpad); return gst_pad_get_bufferpool(filter->srcpad);
} }
/* static GstPadConnectReturn
static GstPadNegotiateReturn play_on_demand_pad_connect (GstPad *pad, GstCaps *caps)
play_on_demand_negotiate_src (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->sinkpad, caps);
}
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);
}
*/
static gint
play_on_demand_parse_caps (GstPlayOnDemand *filter, GstCaps *caps)
{ {
const gchar *format; const gchar *format;
GstPlayOnDemand *filter;
g_return_val_if_fail(filter != NULL, -1); g_return_val_if_fail(caps != NULL, GST_PAD_CONNECT_DELAYED);
g_return_val_if_fail(caps != NULL, -1); g_return_val_if_fail(pad != NULL, GST_PAD_CONNECT_DELAYED);
filter = GST_PLAYONDEMAND(GST_PAD_PARENT(pad));
format = gst_caps_get_string(caps, "format"); format = gst_caps_get_string(caps, "format");
@ -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", g_print ("PlayOnDemand : format int, bit width %d, endianness %d, signed %s\n",
filter->width, filter->endianness, filter->is_signed ? "yes" : "no"); 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->format = GST_PLAYONDEMAND_FORMAT_FLOAT;
filter->layout = gst_caps_get_string(caps, "layout"); filter->layout = gst_caps_get_string(caps, "layout");
filter->intercept = gst_caps_get_float(caps, "intercept"); 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", g_print ("PlayOnDemand : format float, layout %s, intercept %f, slope %f\n",
filter->layout, filter->intercept, filter->slope); 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 GType
gst_play_on_demand_get_type(void) { gst_play_on_demand_get_type (void)
{
static GType play_on_demand_type = 0; static GType play_on_demand_type = 0;
if (! play_on_demand_type) { 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_object_class_install_property(G_OBJECT_CLASS(klass), ARG_SILENT,
g_param_spec_boolean("silent","silent","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_object_class_install_property(G_OBJECT_CLASS(klass), ARG_FOLLOWTAIL,
g_param_spec_boolean("follow-stream-tail","follow-stream-tail","follow-stream-tail", 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; guint i;
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"); 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); filter->sinkpad = gst_pad_new_from_template(play_on_demand_sink_factory(), "sink");
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->sinkpad);
gst_element_add_pad(GST_ELEMENT(filter), filter->srcpad); gst_element_add_pad(GST_ELEMENT(filter), filter->srcpad);
gst_element_set_loop_function(GST_ELEMENT(filter), play_on_demand_loop); 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->follow_stream_tail = FALSE;
filter->silent = TRUE; filter->silent = TRUE;
@ -309,7 +282,11 @@ play_on_demand_loop (GstElement *elem)
g_return_if_fail(filter != NULL); g_return_if_fail(filter != NULL);
g_return_if_fail(GST_IS_PLAYONDEMAND(filter)); 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); in = gst_pad_pull(filter->sinkpad);

View file

@ -57,7 +57,7 @@ struct _GstPlayOnDemand {
GstElement element; GstElement element;
GstPad *sinkpad, *srcpad; GstPad *sinkpad, *srcpad;
GstBufferPool *sinkpool, *srcpool; GstBufferPool *bufpool;
/* these next data elements are for the filter's internal buffers and list of /* 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 play pointers (offsets in the internal buffers). there are also flags for