[svn r621] added test file trunk
authorrenatofilho
Tue May 01 22:19:50 2007 +0100 (2007-05-01)
branchtrunk
changeset 6154fda44a11929
parent 614 24c3dd0bc57e
child 616 176270f861b4
[svn r621] added test file
gmyth-stream/gmemcoder/tests/Makefile.am
gmyth-stream/gmemcoder/tests/main.c
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gmyth-stream/gmemcoder/tests/Makefile.am	Tue May 01 22:19:50 2007 +0100
     1.3 @@ -0,0 +1,15 @@
     1.4 +bin_PROGRAMS = \
     1.5 +	gnl-test
     1.6 +
     1.7 +gnl_test_SOURCES = \
     1.8 +	main.c 
     1.9 +	
    1.10 +gnl_test_LDADD = \
    1.11 +	$(GLIB_LIBS) \
    1.12 +	$(GST_LIBS)
    1.13 +
    1.14 +AM_CPPFLAGS = \
    1.15 +	$(GLIB_CFLAGS) \
    1.16 +	$(GST_CFLAGS)
    1.17 +
    1.18 +CLEANFILES = 
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/gmyth-stream/gmemcoder/tests/main.c	Tue May 01 22:19:50 2007 +0100
     2.3 @@ -0,0 +1,237 @@
     2.4 +#include <sys/stat.h>
     2.5 +#include <fcntl.h>
     2.6 +#include <unistd.h>
     2.7 +#include <string.h>
     2.8 +
     2.9 +#include <gst/gst.h>
    2.10 +#include <glib.h> 
    2.11 +
    2.12 +
    2.13 +static GMainLoop *mainloop = NULL;
    2.14 +static gint64 d = 0;
    2.15 +static gint64 gap = 10;
    2.16 +
    2.17 +typedef enum {
    2.18 +    MY_STREAM_TYPE_AUDIO = 0,
    2.19 +    MY_STREAM_TYPE_VIDEO = 1
    2.20 +} MyStreamType;
    2.21 +
    2.22 +typedef struct _StreamData StreamData;
    2.23 +struct _StreamData {
    2.24 +    GstElement *bin;
    2.25 +    MyStreamType type;
    2.26 +};
    2.27 +
    2.28 +static void
    2.29 +_stream_decode_pad_added_cb (GstElement *decode, 
    2.30 +                            GstPad *pad,
    2.31 +                            gboolean arg1,
    2.32 +                            gpointer user_data)
    2.33 +{
    2.34 +    StreamData *data = (StreamData *) user_data;
    2.35 +    GstElement *queue;
    2.36 +    GstPad* sink_pad;
    2.37 +    GstCaps* caps = gst_pad_get_caps (pad);
    2.38 +    gchar *str_caps = gst_caps_to_string (caps);
    2.39 +
    2.40 +    g_debug ("decode caps: [%d] [%s]", data->type, str_caps);
    2.41 +
    2.42 +    switch (data->type)
    2.43 +    {
    2.44 +        case MY_STREAM_TYPE_AUDIO:
    2.45 +            g_debug ("Audio");
    2.46 +            if (strstr (str_caps, "audio") == NULL) 
    2.47 +                goto done;
    2.48 +            break;
    2.49 +        case MY_STREAM_TYPE_VIDEO:
    2.50 +            g_debug ("Video");
    2.51 +            if (strstr (str_caps, "video") == NULL)
    2.52 +                goto done;
    2.53 +            break;
    2.54 +    }
    2.55 +
    2.56 +    queue = gst_bin_get_by_name (GST_BIN (data->bin), "queue");
    2.57 +    sink_pad = gst_element_get_pad (queue, "sink");
    2.58 +
    2.59 +    if (gst_pad_link (pad, sink_pad) != GST_PAD_LINK_OK) {
    2.60 +        g_warning ("Failed to link decode");
    2.61 +    }
    2.62 +
    2.63 +    gst_object_unref (queue);
    2.64 +    gst_object_unref (sink_pad);
    2.65 +    //g_free (data);
    2.66 +    g_debug ("Linked");
    2.67 +
    2.68 +done:
    2.69 +    gst_caps_unref (caps);
    2.70 +    g_free (str_caps);
    2.71 +}
    2.72 +
    2.73 +
    2.74 +static GstElement*
    2.75 +_create_src_element (const gchar* name,
    2.76 +                     const gchar* uri,                 
    2.77 +                     MyStreamType type,
    2.78 +                     guint priority)
    2.79 +{
    2.80 +    StreamData *data;
    2.81 +    GstElement *bin;
    2.82 +    GstElement *src;
    2.83 +    GstElement *decode;
    2.84 +    GstElement *queue;
    2.85 +    GstPad *src_pad;
    2.86 +
    2.87 +    GstElement *gnl_src;
    2.88 +
    2.89 +    g_debug ("element from uri: %s", uri);
    2.90 +
    2.91 +    bin = gst_bin_new ("bin");
    2.92 +    src = gst_element_make_from_uri (GST_URI_SRC, uri, "src");
    2.93 +    g_return_val_if_fail (src != NULL, NULL);
    2.94 +
    2.95 +    decode = gst_element_factory_make ("decodebin", NULL);
    2.96 +    g_return_val_if_fail (decode != NULL, NULL);
    2.97 +
    2.98 +    queue = gst_element_factory_make ("queue", "queue");
    2.99 +    g_return_val_if_fail (queue != NULL, NULL);
   2.100 +
   2.101 +    gst_bin_add_many (GST_BIN (bin), src, decode, queue, NULL);
   2.102 +    gst_element_link (src, decode);
   2.103 +
   2.104 +    data = g_new0 (StreamData, 1);
   2.105 +    data->bin = bin;
   2.106 +    data->type = type;
   2.107 +    g_debug ("Type : %d = %d", type, data->type);
   2.108 +
   2.109 +    g_signal_connect (G_OBJECT (decode), "new-decoded-pad",
   2.110 +                      G_CALLBACK (_stream_decode_pad_added_cb), 
   2.111 +                      data);
   2.112 +
   2.113 +    
   2.114 +    src_pad = gst_element_get_pad (queue, "src");
   2.115 +    g_return_val_if_fail (src_pad != NULL, NULL);
   2.116 +
   2.117 +    gst_element_add_pad (bin,
   2.118 +        gst_ghost_pad_new ("src", src_pad));
   2.119 +
   2.120 +    gst_object_unref (src_pad);
   2.121 +
   2.122 +    gnl_src = gst_element_factory_make ("gnlsource", name);
   2.123 +    g_return_val_if_fail (gnl_src != NULL, NULL);
   2.124 +    gst_bin_add (GST_BIN (gnl_src), bin);
   2.125 +
   2.126 +    g_debug ("ADDING WITH: START [%lli] DUR [%lli]", d, gap);
   2.127 +    if (d == 0) {
   2.128 +        g_object_set (G_OBJECT (gnl_src),
   2.129 +                        //"start", 0L,
   2.130 +                        "duration", 10 * GST_SECOND,
   2.131 +                        //"media-start", 0L,
   2.132 +                        //"media-duration", 10 * GST_SECOND,
   2.133 +                        "priority", priority,
   2.134 +                        NULL);
   2.135 +
   2.136 +    } else {
   2.137 +        g_object_set (G_OBJECT (gnl_src),
   2.138 +                        "start", 10 * GST_SECOND,
   2.139 +                        "duration", 10 * GST_SECOND,
   2.140 +                        ///"media-start", 10 * GST_SECOND,
   2.141 +                        //"media-duration", 10 * GST_SECOND,
   2.142 +                        "priority", priority,
   2.143 +                        NULL);
   2.144 +
   2.145 +    }
   2.146 +    d++;
   2.147 +
   2.148 +    return gnl_src;
   2.149 +}
   2.150 +
   2.151 +static void
   2.152 +_composition_pad_added_cb (GstElement *composition, 
   2.153 +                           GstPad *pad,
   2.154 +                           gpointer data)
   2.155 +{
   2.156 +    GstPad *sink_pad = gst_element_get_pad (GST_ELEMENT (data), "sink");
   2.157 +    g_debug ("compose pad added");
   2.158 +
   2.159 +    if (gst_pad_link (pad, sink_pad) != GST_PAD_LINK_OK) {
   2.160 +        g_warning ("Failed to link decode");
   2.161 +    }
   2.162 +
   2.163 +    g_debug ("Linked ok");
   2.164 +}
   2.165 +
   2.166 +static void
   2.167 +_compose_add_file (GstElement *compose,
   2.168 +                   const gchar* e_name,
   2.169 +                   const gchar* uri,
   2.170 +                   MyStreamType type, 
   2.171 +                   guint priority)
   2.172 +{
   2.173 +    GstElement *src;
   2.174 +
   2.175 +    src = _create_src_element (e_name, uri, type, priority);
   2.176 +    gst_bin_add (GST_BIN (compose), src);
   2.177 +}
   2.178 +
   2.179 +
   2.180 +int 
   2.181 +main (int argc, char** argv)
   2.182 +{
   2.183 +    GstElement* pipe;
   2.184 +    GstElement* gnl_compose_a;
   2.185 +    GstElement* gnl_compose_v;
   2.186 +    GstElement* asink;
   2.187 +    GstElement* vsink;
   2.188 +    GstElement* aqueue;
   2.189 +    GstElement* vqueue;
   2.190 +
   2.191 +    g_type_init ();
   2.192 +    gst_init (&argc, &argv);
   2.193 +
   2.194 +	mainloop = g_main_loop_new (NULL, FALSE);
   2.195 +
   2.196 +    pipe = gst_pipeline_new ("test_pipeline");
   2.197 +
   2.198 +    gnl_compose_a = gst_element_factory_make ("gnlcomposition", "acompose");
   2.199 +    g_return_val_if_fail (gnl_compose_a != NULL, 1);
   2.200 +
   2.201 +    gnl_compose_v = gst_element_factory_make ("gnlcomposition", "vcompose");
   2.202 +    g_return_val_if_fail (gnl_compose_v != NULL, 1);
   2.203 +
   2.204 +
   2.205 +    //_compose_add_file (gnl_compose_a, "src0", argv[1], MY_STREAM_TYPE_AUDIO, 1);
   2.206 +    //_compose_add_file (gnl_compose_a, "src1", argv[2], MY_STREAM_TYPE_AUDIO, 1);
   2.207 +
   2.208 +    d = 0;
   2.209 +
   2.210 +    _compose_add_file (gnl_compose_v, "src2", argv[1], MY_STREAM_TYPE_VIDEO, 1);
   2.211 +    _compose_add_file (gnl_compose_v, "src3", argv[2], MY_STREAM_TYPE_VIDEO, 1);
   2.212 +
   2.213 +
   2.214 +    //aqueue = gst_element_factory_make ("queue", "aqueue");
   2.215 +    //asink = gst_element_factory_make ("alsasink", "asink");
   2.216 +
   2.217 +    vqueue = gst_element_factory_make ("queue", "vqueue");
   2.218 +    vsink = gst_element_factory_make ("xvimagesink", "vsink");
   2.219 +
   2.220 +    gst_bin_add_many (GST_BIN (pipe), gnl_compose_a, gnl_compose_v, 
   2.221 +            vqueue, vsink, 
   2.222 +            //aqueue, asink, 
   2.223 +            NULL);
   2.224 +
   2.225 +    gst_element_link (vqueue, vsink);
   2.226 +    //gst_element_link (aqueue, asink);
   2.227 +
   2.228 +    //g_signal_connect (G_OBJECT (gnl_compose_a), "pad-added",
   2.229 +    //                  G_CALLBACK (_composition_pad_added_cb), aqueue);
   2.230 +
   2.231 +    g_signal_connect (G_OBJECT (gnl_compose_v), "pad-added",
   2.232 +                      G_CALLBACK (_composition_pad_added_cb), vqueue);
   2.233 +
   2.234 +
   2.235 +    //g_idle_add (_play, pipe);
   2.236 +    gst_element_set_state (GST_ELEMENT (pipe), GST_STATE_PLAYING);
   2.237 +	g_main_loop_run (mainloop);
   2.238 +
   2.239 +	return 0;
   2.240 +}