2001-11-29 20:36:46 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) 2001 Steve Baker <stevebaker_org@yahoo.co.uk>
|
|
|
|
*
|
|
|
|
* dparamstest.c:
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2003-11-04 04:26:26 +00:00
|
|
|
#include <unistd.h>
|
2003-10-15 01:25:41 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
2001-11-29 20:36:46 +00:00
|
|
|
|
|
|
|
#include <gst/gst.h>
|
2002-02-22 18:12:37 +00:00
|
|
|
#include <gst/control/control.h>
|
2001-11-29 20:36:46 +00:00
|
|
|
|
|
|
|
#define GST_TYPE_DPTEST (gst_dptest_get_type())
|
|
|
|
#define GST_DPTEST(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_DPTEST,GstDpTest))
|
|
|
|
#define GST_DPTEST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_DPTEST,GstDpTestClass))
|
|
|
|
#define GST_IS_DPTEST(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_DPTEST))
|
|
|
|
#define GST_IS_DPTEST_CLASS(obj) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_DPTEST))
|
|
|
|
|
|
|
|
typedef struct _GstDpTest GstDpTest;
|
|
|
|
typedef struct _GstDpTestClass GstDpTestClass;
|
|
|
|
|
|
|
|
struct _GstDpTest
|
|
|
|
{
|
|
|
|
GstElement element;
|
|
|
|
|
|
|
|
GstPad *sinkpad;
|
|
|
|
GstPad *srcpad;
|
|
|
|
GstDParamManager *dpman;
|
2004-03-13 15:27:01 +00:00
|
|
|
|
2001-11-29 20:36:46 +00:00
|
|
|
gfloat float1;
|
|
|
|
gfloat float2;
|
|
|
|
gboolean bool1;
|
|
|
|
gdouble double1;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct _GstDpTestClass
|
|
|
|
{
|
|
|
|
GstElementClass parent_class;
|
|
|
|
};
|
|
|
|
|
|
|
|
GType gst_dptest_get_type (void);
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
ARG_0,
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
static void gst_dptest_base_init (gpointer g_class);
|
|
|
|
static void gst_dptest_class_init (GstDpTestClass * klass);
|
|
|
|
static void gst_dptest_init (GstDpTest * dptest);
|
2001-11-29 20:36:46 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
static void gst_dptest_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec);
|
2001-11-29 20:36:46 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
static GstElementStateReturn gst_dptest_change_state (GstElement * element);
|
|
|
|
static void gst_dptest_chain (GstPad * pad, GstData * buf);
|
2001-11-29 20:36:46 +00:00
|
|
|
|
|
|
|
static GstElementClass *parent_class = NULL;
|
|
|
|
|
|
|
|
GType
|
|
|
|
gst_dptest_get_type (void)
|
|
|
|
{
|
|
|
|
static GType dptest_type = 0;
|
|
|
|
|
|
|
|
if (!dptest_type) {
|
|
|
|
static const GTypeInfo dptest_info = {
|
2003-11-04 04:26:26 +00:00
|
|
|
sizeof (GstDpTestClass),
|
|
|
|
gst_dptest_base_init,
|
2001-11-29 20:36:46 +00:00
|
|
|
NULL,
|
|
|
|
(GClassInitFunc) gst_dptest_class_init,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
sizeof (GstDpTest),
|
|
|
|
0,
|
|
|
|
(GInstanceInitFunc) gst_dptest_init,
|
|
|
|
};
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
dptest_type =
|
2004-03-15 19:27:17 +00:00
|
|
|
g_type_register_static (GST_TYPE_ELEMENT, "GstDpTest", &dptest_info, 0);
|
2001-11-29 20:36:46 +00:00
|
|
|
}
|
|
|
|
return dptest_type;
|
|
|
|
}
|
|
|
|
|
2003-11-04 04:26:26 +00:00
|
|
|
static void
|
|
|
|
gst_dptest_base_init (gpointer g_class)
|
|
|
|
{
|
2004-03-13 15:27:01 +00:00
|
|
|
static GstElementDetails dptest_details = GST_ELEMENT_DETAILS ("DParamTest",
|
|
|
|
"Filter",
|
|
|
|
"Test for the GstDParam code",
|
|
|
|
"Steve Baker <stevebaker_org@yahoo.co.uk>");
|
2003-11-04 04:26:26 +00:00
|
|
|
GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
|
|
|
|
|
|
|
|
gst_element_class_set_details (element_class, &dptest_details);
|
|
|
|
}
|
|
|
|
|
2001-11-29 20:36:46 +00:00
|
|
|
static void
|
|
|
|
gst_dptest_class_init (GstDpTestClass * klass)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class;
|
|
|
|
GstElementClass *gstelement_class;
|
|
|
|
|
|
|
|
gobject_class = (GObjectClass *) klass;
|
2004-03-13 15:27:01 +00:00
|
|
|
gstelement_class = (GstElementClass *) klass;
|
2001-11-29 20:36:46 +00:00
|
|
|
|
|
|
|
parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
|
|
|
|
|
|
|
|
gobject_class->set_property = GST_DEBUG_FUNCPTR (gst_dptest_set_property);
|
|
|
|
|
|
|
|
gstelement_class->change_state = gst_dptest_change_state;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_dptest_init (GstDpTest * dptest)
|
|
|
|
{
|
|
|
|
|
|
|
|
dptest->sinkpad = gst_pad_new ("sink", GST_PAD_SINK);
|
|
|
|
gst_element_add_pad (GST_ELEMENT (dptest), dptest->sinkpad);
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_pad_set_chain_function (dptest->sinkpad, gst_dptest_chain);
|
2001-11-29 20:36:46 +00:00
|
|
|
|
|
|
|
dptest->srcpad = gst_pad_new ("src", GST_PAD_SRC);
|
|
|
|
gst_element_add_pad (GST_ELEMENT (dptest), dptest->srcpad);
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
dptest->dpman = gst_dpman_new ("dptest_dpman", GST_ELEMENT (dptest));
|
|
|
|
|
|
|
|
gst_dpman_add_required_dparam_direct (dptest->dpman,
|
|
|
|
g_param_spec_float ("float1", "float1", "float1",
|
2004-03-15 19:27:17 +00:00
|
|
|
0.0, 1.0, 0.5, G_PARAM_READWRITE), "float", &(dptest->float1)
|
2004-03-13 15:27:01 +00:00
|
|
|
);
|
2001-11-29 20:36:46 +00:00
|
|
|
|
|
|
|
dptest->float1 = 0.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_dptest_set_property (GObject * object, guint prop_id, const GValue * value,
|
|
|
|
GParamSpec * pspec)
|
2001-11-29 20:36:46 +00:00
|
|
|
{
|
|
|
|
GstDpTest *dptest;
|
|
|
|
|
|
|
|
/* it's not null if we got it, but it might not be ours */
|
|
|
|
g_return_if_fail (GST_IS_DPTEST (object));
|
|
|
|
|
|
|
|
dptest = GST_DPTEST (object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstElementStateReturn
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_dptest_change_state (GstElement * element)
|
2001-11-29 20:36:46 +00:00
|
|
|
{
|
|
|
|
GstDpTest *dptest;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_DPTEST (element), GST_STATE_FAILURE);
|
|
|
|
|
|
|
|
dptest = GST_DPTEST (element);
|
|
|
|
if (GST_ELEMENT_CLASS (parent_class)->change_state)
|
|
|
|
return GST_ELEMENT_CLASS (parent_class)->change_state (element);
|
2004-03-13 15:27:01 +00:00
|
|
|
|
2001-11-29 20:36:46 +00:00
|
|
|
return GST_STATE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
static void
|
|
|
|
gst_dptest_chain (GstPad * pad, GstData * data)
|
2001-11-29 20:36:46 +00:00
|
|
|
{
|
2002-03-04 18:55:17 +00:00
|
|
|
GstDpTest *dptest;
|
2004-07-02 13:24:33 +00:00
|
|
|
gint frame_count;
|
2002-03-04 18:55:17 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
dptest = GST_DPTEST (gst_pad_get_parent (pad));
|
|
|
|
g_assert (dptest);
|
2004-07-02 13:24:33 +00:00
|
|
|
g_print ("dp chain\n");
|
2001-11-29 20:36:46 +00:00
|
|
|
|
2002-03-04 18:55:17 +00:00
|
|
|
/* we're using a made up buffer size of 64 and a timestamp of zero */
|
2004-07-02 13:24:33 +00:00
|
|
|
g_print ("preprocess\n");
|
|
|
|
frame_count = 0;
|
|
|
|
GST_DPMAN_PREPROCESS (dptest->dpman, 64, 0LL);
|
2004-03-13 15:27:01 +00:00
|
|
|
|
2004-07-02 13:24:33 +00:00
|
|
|
while (GST_DPMAN_PROCESS (dptest->dpman, frame_count)) {
|
|
|
|
++frame_count;
|
|
|
|
}
|
|
|
|
g_print ("dp chain done\n");
|
2001-11-29 20:36:46 +00:00
|
|
|
}
|
|
|
|
|
2003-11-04 04:26:26 +00:00
|
|
|
gboolean
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_dptest_register_elements (GstPlugin * plugin)
|
2003-11-04 04:26:26 +00:00
|
|
|
{
|
|
|
|
return gst_element_register (plugin, "dptest", GST_RANK_NONE,
|
|
|
|
GST_TYPE_DPTEST);
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstPluginDesc plugin_desc = {
|
|
|
|
GST_VERSION_MAJOR,
|
|
|
|
GST_VERSION_MINOR,
|
|
|
|
"dptest_elements",
|
|
|
|
"test elements",
|
|
|
|
&gst_dptest_register_elements,
|
|
|
|
NULL,
|
|
|
|
VERSION,
|
|
|
|
GST_LICENSE,
|
|
|
|
GST_PACKAGE,
|
|
|
|
GST_ORIGIN
|
|
|
|
};
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
int
|
|
|
|
main (int argc, char *argv[])
|
|
|
|
{
|
2001-11-29 20:36:46 +00:00
|
|
|
|
|
|
|
GstElement *src;
|
|
|
|
GstElement *sink;
|
2002-03-04 18:55:17 +00:00
|
|
|
GstElement *testelement;
|
2001-11-29 20:36:46 +00:00
|
|
|
GstElement *pipeline;
|
2002-03-04 18:55:17 +00:00
|
|
|
GstDParamManager *dpman;
|
|
|
|
GstDParam *dp_float1;
|
|
|
|
GValue *dp_float1_value;
|
2004-03-13 15:27:01 +00:00
|
|
|
|
2001-11-29 20:36:46 +00:00
|
|
|
gst_init (&argc, &argv);
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_control_init (&argc, &argv);
|
2003-11-04 04:26:26 +00:00
|
|
|
|
|
|
|
_gst_plugin_register_static (&plugin_desc);
|
2001-11-29 20:36:46 +00:00
|
|
|
|
2002-04-11 20:35:18 +00:00
|
|
|
pipeline = gst_element_factory_make ("pipeline", "pipeline");
|
2001-11-29 20:36:46 +00:00
|
|
|
g_assert (pipeline);
|
|
|
|
|
2002-04-11 20:35:18 +00:00
|
|
|
src = gst_element_factory_make ("fakesrc", "src");
|
2001-11-29 20:36:46 +00:00
|
|
|
g_assert (src);
|
|
|
|
|
2002-04-11 20:35:18 +00:00
|
|
|
sink = gst_element_factory_make ("fakesink", "sink");
|
2001-11-29 20:36:46 +00:00
|
|
|
g_assert (sink);
|
|
|
|
|
2002-04-11 20:35:18 +00:00
|
|
|
testelement = gst_element_factory_make ("dptest", "testelement");
|
2002-03-04 18:55:17 +00:00
|
|
|
g_assert (testelement);
|
2001-11-29 20:36:46 +00:00
|
|
|
|
2004-07-02 13:54:59 +00:00
|
|
|
gst_bin_add_many (GST_BIN (pipeline), src, testelement, sink, NULL);
|
|
|
|
gst_element_link_many (src, testelement, sink, NULL);
|
2004-03-13 15:27:01 +00:00
|
|
|
|
|
|
|
g_object_set (G_OBJECT (src), "num_buffers", 1, NULL);
|
2002-03-04 18:55:17 +00:00
|
|
|
|
2004-07-02 13:24:33 +00:00
|
|
|
g_print ("setting pipeline to play\n");
|
2001-11-29 20:36:46 +00:00
|
|
|
gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PLAYING);
|
|
|
|
|
2002-03-04 18:55:17 +00:00
|
|
|
/* test that dparam manager is accessable */
|
2004-03-13 15:27:01 +00:00
|
|
|
g_print ("getting dparam manager\n");
|
2002-03-04 18:55:17 +00:00
|
|
|
dpman = gst_dpman_get_manager (testelement);
|
2004-03-13 15:27:01 +00:00
|
|
|
gst_dpman_set_mode (dpman, "synchronous");
|
|
|
|
|
|
|
|
g_assert (dpman);
|
|
|
|
g_assert (GST_IS_DPMAN (dpman));
|
|
|
|
|
|
|
|
g_print ("creating dparam for float1\n");
|
|
|
|
dp_float1 = gst_dparam_new (G_TYPE_FLOAT);;
|
|
|
|
g_assert (dp_float1);
|
|
|
|
g_assert (GST_IS_DPARAM (dp_float1));
|
|
|
|
|
|
|
|
g_print ("attach dparam to float1\n");
|
|
|
|
g_assert (gst_dpman_attach_dparam (dpman, "float1", dp_float1));
|
|
|
|
|
|
|
|
dp_float1_value = g_new0 (GValue, 1);
|
|
|
|
g_value_init (dp_float1_value, G_TYPE_FLOAT);
|
|
|
|
|
|
|
|
g_value_set_float (dp_float1_value, 0.1);
|
|
|
|
g_object_set_property (G_OBJECT (dp_float1), "value_float", dp_float1_value);
|
|
|
|
|
|
|
|
g_print ("iterate once\n");
|
2001-11-29 20:36:46 +00:00
|
|
|
gst_bin_iterate (GST_BIN (pipeline));
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
g_print ("check that value changed\n");
|
|
|
|
g_assert (GST_DPTEST (testelement)->float1 == 0.1F);
|
|
|
|
g_assert (!GST_DPARAM_READY_FOR_UPDATE (dp_float1));
|
|
|
|
|
|
|
|
g_print ("nulling pipeline\n");
|
2001-11-29 20:36:46 +00:00
|
|
|
gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_NULL);
|
2002-03-04 18:55:17 +00:00
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
g_print ("playing pipeline\n");
|
2001-11-29 20:36:46 +00:00
|
|
|
gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PLAYING);
|
|
|
|
|
2004-03-13 15:27:01 +00:00
|
|
|
g_print ("iterate twice\n");
|
2002-03-04 18:55:17 +00:00
|
|
|
|
2001-11-29 20:36:46 +00:00
|
|
|
g_object_set (G_OBJECT (src), "num_buffers", 2, NULL);
|
|
|
|
gst_bin_iterate (GST_BIN (pipeline));
|
2004-03-13 15:27:01 +00:00
|
|
|
|
2001-11-29 20:36:46 +00:00
|
|
|
return 0;
|
|
|
|
}
|