gmyth-stream/gmemcoder/tests/main.c
branchtrunk
changeset 753 8ee634511c1e
parent 615 4fda44a11929
child 754 cb885ee44618
     1.1 --- a/gmyth-stream/gmemcoder/tests/main.c	Tue May 01 22:19:50 2007 +0100
     1.2 +++ b/gmyth-stream/gmemcoder/tests/main.c	Thu Jun 14 18:22:32 2007 +0100
     1.3 @@ -4,234 +4,228 @@
     1.4  #include <string.h>
     1.5  
     1.6  #include <gst/gst.h>
     1.7 -#include <glib.h> 
     1.8 +#include <glib.h>
     1.9  
    1.10  
    1.11  static GMainLoop *mainloop = NULL;
    1.12  static gint64 d = 0;
    1.13  static gint64 gap = 10;
    1.14  
    1.15 -typedef enum {
    1.16 -    MY_STREAM_TYPE_AUDIO = 0,
    1.17 -    MY_STREAM_TYPE_VIDEO = 1
    1.18 +typedef enum
    1.19 +{
    1.20 +  MY_STREAM_TYPE_AUDIO = 0,
    1.21 +  MY_STREAM_TYPE_VIDEO = 1
    1.22  } MyStreamType;
    1.23  
    1.24  typedef struct _StreamData StreamData;
    1.25 -struct _StreamData {
    1.26 -    GstElement *bin;
    1.27 -    MyStreamType type;
    1.28 +struct _StreamData
    1.29 +{
    1.30 +  GstElement *bin;
    1.31 +  MyStreamType type;
    1.32  };
    1.33  
    1.34  static void
    1.35 -_stream_decode_pad_added_cb (GstElement *decode, 
    1.36 -                            GstPad *pad,
    1.37 -                            gboolean arg1,
    1.38 -                            gpointer user_data)
    1.39 +_stream_decode_pad_added_cb(GstElement * decode,
    1.40 +							GstPad * pad, gboolean arg1, gpointer user_data)
    1.41  {
    1.42 -    StreamData *data = (StreamData *) user_data;
    1.43 -    GstElement *queue;
    1.44 -    GstPad* sink_pad;
    1.45 -    GstCaps* caps = gst_pad_get_caps (pad);
    1.46 -    gchar *str_caps = gst_caps_to_string (caps);
    1.47 +  StreamData *data = (StreamData *) user_data;
    1.48 +  GstElement *queue;
    1.49 +  GstPad *sink_pad;
    1.50 +  GstCaps *caps = gst_pad_get_caps(pad);
    1.51 +  gchar *str_caps = gst_caps_to_string(caps);
    1.52  
    1.53 -    g_debug ("decode caps: [%d] [%s]", data->type, str_caps);
    1.54 +  g_debug("decode caps: [%d] [%s]", data->type, str_caps);
    1.55  
    1.56 -    switch (data->type)
    1.57 -    {
    1.58 -        case MY_STREAM_TYPE_AUDIO:
    1.59 -            g_debug ("Audio");
    1.60 -            if (strstr (str_caps, "audio") == NULL) 
    1.61 -                goto done;
    1.62 -            break;
    1.63 -        case MY_STREAM_TYPE_VIDEO:
    1.64 -            g_debug ("Video");
    1.65 -            if (strstr (str_caps, "video") == NULL)
    1.66 -                goto done;
    1.67 -            break;
    1.68 -    }
    1.69 +  switch (data->type)
    1.70 +	{
    1.71 +	case MY_STREAM_TYPE_AUDIO:
    1.72 +	  g_debug("Audio");
    1.73 +	  if (strstr(str_caps, "audio") == NULL)
    1.74 +		goto done;
    1.75 +	  break;
    1.76 +	case MY_STREAM_TYPE_VIDEO:
    1.77 +	  g_debug("Video");
    1.78 +	  if (strstr(str_caps, "video") == NULL)
    1.79 +		goto done;
    1.80 +	  break;
    1.81 +	}
    1.82  
    1.83 -    queue = gst_bin_get_by_name (GST_BIN (data->bin), "queue");
    1.84 -    sink_pad = gst_element_get_pad (queue, "sink");
    1.85 +  queue = gst_bin_get_by_name(GST_BIN(data->bin), "queue");
    1.86 +  sink_pad = gst_element_get_pad(queue, "sink");
    1.87  
    1.88 -    if (gst_pad_link (pad, sink_pad) != GST_PAD_LINK_OK) {
    1.89 -        g_warning ("Failed to link decode");
    1.90 -    }
    1.91 +  if (gst_pad_link(pad, sink_pad) != GST_PAD_LINK_OK)
    1.92 +	{
    1.93 +	  g_warning("Failed to link decode");
    1.94 +	}
    1.95  
    1.96 -    gst_object_unref (queue);
    1.97 -    gst_object_unref (sink_pad);
    1.98 -    //g_free (data);
    1.99 -    g_debug ("Linked");
   1.100 +  gst_object_unref(queue);
   1.101 +  gst_object_unref(sink_pad);
   1.102 + //g_free (data);
   1.103 +  g_debug("Linked");
   1.104  
   1.105  done:
   1.106 -    gst_caps_unref (caps);
   1.107 -    g_free (str_caps);
   1.108 +  gst_caps_unref(caps);
   1.109 +  g_free(str_caps);
   1.110  }
   1.111  
   1.112  
   1.113 -static GstElement*
   1.114 -_create_src_element (const gchar* name,
   1.115 -                     const gchar* uri,                 
   1.116 -                     MyStreamType type,
   1.117 -                     guint priority)
   1.118 +static GstElement *
   1.119 +_create_src_element(const gchar * name,
   1.120 +					const gchar * uri, MyStreamType type, guint priority)
   1.121  {
   1.122 -    StreamData *data;
   1.123 -    GstElement *bin;
   1.124 -    GstElement *src;
   1.125 -    GstElement *decode;
   1.126 -    GstElement *queue;
   1.127 -    GstPad *src_pad;
   1.128 +  StreamData *data;
   1.129 +  GstElement *bin;
   1.130 +  GstElement *src;
   1.131 +  GstElement *decode;
   1.132 +  GstElement *queue;
   1.133 +  GstPad *src_pad;
   1.134  
   1.135 -    GstElement *gnl_src;
   1.136 +  GstElement *gnl_src;
   1.137  
   1.138 -    g_debug ("element from uri: %s", uri);
   1.139 +  g_debug("element from uri: %s", uri);
   1.140  
   1.141 -    bin = gst_bin_new ("bin");
   1.142 -    src = gst_element_make_from_uri (GST_URI_SRC, uri, "src");
   1.143 -    g_return_val_if_fail (src != NULL, NULL);
   1.144 +  bin = gst_bin_new("bin");
   1.145 +  src = gst_element_make_from_uri(GST_URI_SRC, uri, "src");
   1.146 +  g_return_val_if_fail(src != NULL, NULL);
   1.147  
   1.148 -    decode = gst_element_factory_make ("decodebin", NULL);
   1.149 -    g_return_val_if_fail (decode != NULL, NULL);
   1.150 +  decode = gst_element_factory_make("decodebin", NULL);
   1.151 +  g_return_val_if_fail(decode != NULL, NULL);
   1.152  
   1.153 -    queue = gst_element_factory_make ("queue", "queue");
   1.154 -    g_return_val_if_fail (queue != NULL, NULL);
   1.155 +  queue = gst_element_factory_make("queue", "queue");
   1.156 +  g_return_val_if_fail(queue != NULL, NULL);
   1.157  
   1.158 -    gst_bin_add_many (GST_BIN (bin), src, decode, queue, NULL);
   1.159 -    gst_element_link (src, decode);
   1.160 +  gst_bin_add_many(GST_BIN(bin), src, decode, queue, NULL);
   1.161 +  gst_element_link(src, decode);
   1.162  
   1.163 -    data = g_new0 (StreamData, 1);
   1.164 -    data->bin = bin;
   1.165 -    data->type = type;
   1.166 -    g_debug ("Type : %d = %d", type, data->type);
   1.167 +  data = g_new0(StreamData, 1);
   1.168 +  data->bin = bin;
   1.169 +  data->type = type;
   1.170 +  g_debug("Type : %d = %d", type, data->type);
   1.171  
   1.172 -    g_signal_connect (G_OBJECT (decode), "new-decoded-pad",
   1.173 -                      G_CALLBACK (_stream_decode_pad_added_cb), 
   1.174 -                      data);
   1.175 +  g_signal_connect(G_OBJECT(decode), "new-decoded-pad",
   1.176 +				   G_CALLBACK(_stream_decode_pad_added_cb), data);
   1.177  
   1.178 -    
   1.179 -    src_pad = gst_element_get_pad (queue, "src");
   1.180 -    g_return_val_if_fail (src_pad != NULL, NULL);
   1.181  
   1.182 -    gst_element_add_pad (bin,
   1.183 -        gst_ghost_pad_new ("src", src_pad));
   1.184 +  src_pad = gst_element_get_pad(queue, "src");
   1.185 +  g_return_val_if_fail(src_pad != NULL, NULL);
   1.186  
   1.187 -    gst_object_unref (src_pad);
   1.188 +  gst_element_add_pad(bin, gst_ghost_pad_new("src", src_pad));
   1.189  
   1.190 -    gnl_src = gst_element_factory_make ("gnlsource", name);
   1.191 -    g_return_val_if_fail (gnl_src != NULL, NULL);
   1.192 -    gst_bin_add (GST_BIN (gnl_src), bin);
   1.193 +  gst_object_unref(src_pad);
   1.194  
   1.195 -    g_debug ("ADDING WITH: START [%lli] DUR [%lli]", d, gap);
   1.196 -    if (d == 0) {
   1.197 -        g_object_set (G_OBJECT (gnl_src),
   1.198 -                        //"start", 0L,
   1.199 -                        "duration", 10 * GST_SECOND,
   1.200 -                        //"media-start", 0L,
   1.201 -                        //"media-duration", 10 * GST_SECOND,
   1.202 -                        "priority", priority,
   1.203 -                        NULL);
   1.204 +  gnl_src = gst_element_factory_make("gnlsource", name);
   1.205 +  g_return_val_if_fail(gnl_src != NULL, NULL);
   1.206 +  gst_bin_add(GST_BIN(gnl_src), bin);
   1.207  
   1.208 -    } else {
   1.209 -        g_object_set (G_OBJECT (gnl_src),
   1.210 -                        "start", 10 * GST_SECOND,
   1.211 -                        "duration", 10 * GST_SECOND,
   1.212 -                        ///"media-start", 10 * GST_SECOND,
   1.213 -                        //"media-duration", 10 * GST_SECOND,
   1.214 -                        "priority", priority,
   1.215 -                        NULL);
   1.216 +  g_debug("ADDING WITH: START [%lli] DUR [%lli]", d, gap);
   1.217 +  if (d == 0)
   1.218 +	{
   1.219 +	  g_object_set(G_OBJECT(gnl_src),
   1.220 +				  //"start", 0L,
   1.221 +				   "duration", 10 * GST_SECOND,
   1.222 +				  //"media-start", 0L,
   1.223 +				  //"media-duration", 10 * GST_SECOND,
   1.224 +				   "priority", priority, NULL);
   1.225  
   1.226 -    }
   1.227 -    d++;
   1.228 +	}
   1.229 +  else
   1.230 +	{
   1.231 +	  g_object_set(G_OBJECT(gnl_src),
   1.232 +				   "start", 10 * GST_SECOND, "duration", 10 * GST_SECOND,
   1.233 +				  ///"media-start", 10 * GST_SECOND,
   1.234 +				  //"media-duration", 10 * GST_SECOND,
   1.235 +				   "priority", priority, NULL);
   1.236  
   1.237 -    return gnl_src;
   1.238 +	}
   1.239 +  d++;
   1.240 +
   1.241 +  return gnl_src;
   1.242  }
   1.243  
   1.244  static void
   1.245 -_composition_pad_added_cb (GstElement *composition, 
   1.246 -                           GstPad *pad,
   1.247 -                           gpointer data)
   1.248 +_composition_pad_added_cb(GstElement * composition,
   1.249 +						  GstPad * pad, gpointer data)
   1.250  {
   1.251 -    GstPad *sink_pad = gst_element_get_pad (GST_ELEMENT (data), "sink");
   1.252 -    g_debug ("compose pad added");
   1.253 +  GstPad *sink_pad = gst_element_get_pad(GST_ELEMENT(data), "sink");
   1.254 +  g_debug("compose pad added");
   1.255  
   1.256 -    if (gst_pad_link (pad, sink_pad) != GST_PAD_LINK_OK) {
   1.257 -        g_warning ("Failed to link decode");
   1.258 -    }
   1.259 +  if (gst_pad_link(pad, sink_pad) != GST_PAD_LINK_OK)
   1.260 +	{
   1.261 +	  g_warning("Failed to link decode");
   1.262 +	}
   1.263  
   1.264 -    g_debug ("Linked ok");
   1.265 +  g_debug("Linked ok");
   1.266  }
   1.267  
   1.268  static void
   1.269 -_compose_add_file (GstElement *compose,
   1.270 -                   const gchar* e_name,
   1.271 -                   const gchar* uri,
   1.272 -                   MyStreamType type, 
   1.273 -                   guint priority)
   1.274 +_compose_add_file(GstElement * compose,
   1.275 +				  const gchar * e_name,
   1.276 +				  const gchar * uri, MyStreamType type, guint priority)
   1.277  {
   1.278 -    GstElement *src;
   1.279 +  GstElement *src;
   1.280  
   1.281 -    src = _create_src_element (e_name, uri, type, priority);
   1.282 -    gst_bin_add (GST_BIN (compose), src);
   1.283 +  src = _create_src_element(e_name, uri, type, priority);
   1.284 +  gst_bin_add(GST_BIN(compose), src);
   1.285  }
   1.286  
   1.287  
   1.288 -int 
   1.289 -main (int argc, char** argv)
   1.290 +int
   1.291 +main(int argc, char **argv)
   1.292  {
   1.293 -    GstElement* pipe;
   1.294 -    GstElement* gnl_compose_a;
   1.295 -    GstElement* gnl_compose_v;
   1.296 -    GstElement* asink;
   1.297 -    GstElement* vsink;
   1.298 -    GstElement* aqueue;
   1.299 -    GstElement* vqueue;
   1.300 +  GstElement *pipe;
   1.301 +  GstElement *gnl_compose_a;
   1.302 +  GstElement *gnl_compose_v;
   1.303 +  GstElement *asink;
   1.304 +  GstElement *vsink;
   1.305 +  GstElement *aqueue;
   1.306 +  GstElement *vqueue;
   1.307  
   1.308 -    g_type_init ();
   1.309 -    gst_init (&argc, &argv);
   1.310 +  g_type_init();
   1.311 +  gst_init(&argc, &argv);
   1.312  
   1.313 -	mainloop = g_main_loop_new (NULL, FALSE);
   1.314 +  mainloop = g_main_loop_new(NULL, FALSE);
   1.315  
   1.316 -    pipe = gst_pipeline_new ("test_pipeline");
   1.317 +  pipe = gst_pipeline_new("test_pipeline");
   1.318  
   1.319 -    gnl_compose_a = gst_element_factory_make ("gnlcomposition", "acompose");
   1.320 -    g_return_val_if_fail (gnl_compose_a != NULL, 1);
   1.321 +  gnl_compose_a = gst_element_factory_make("gnlcomposition", "acompose");
   1.322 +  g_return_val_if_fail(gnl_compose_a != NULL, 1);
   1.323  
   1.324 -    gnl_compose_v = gst_element_factory_make ("gnlcomposition", "vcompose");
   1.325 -    g_return_val_if_fail (gnl_compose_v != NULL, 1);
   1.326 +  gnl_compose_v = gst_element_factory_make("gnlcomposition", "vcompose");
   1.327 +  g_return_val_if_fail(gnl_compose_v != NULL, 1);
   1.328  
   1.329  
   1.330 -    //_compose_add_file (gnl_compose_a, "src0", argv[1], MY_STREAM_TYPE_AUDIO, 1);
   1.331 -    //_compose_add_file (gnl_compose_a, "src1", argv[2], MY_STREAM_TYPE_AUDIO, 1);
   1.332 + //_compose_add_file (gnl_compose_a, "src0", argv[1], MY_STREAM_TYPE_AUDIO, 1);
   1.333 + //_compose_add_file (gnl_compose_a, "src1", argv[2], MY_STREAM_TYPE_AUDIO, 1);
   1.334  
   1.335 -    d = 0;
   1.336 +  d = 0;
   1.337  
   1.338 -    _compose_add_file (gnl_compose_v, "src2", argv[1], MY_STREAM_TYPE_VIDEO, 1);
   1.339 -    _compose_add_file (gnl_compose_v, "src3", argv[2], MY_STREAM_TYPE_VIDEO, 1);
   1.340 +  _compose_add_file(gnl_compose_v, "src2", argv[1], MY_STREAM_TYPE_VIDEO, 1);
   1.341 +  _compose_add_file(gnl_compose_v, "src3", argv[2], MY_STREAM_TYPE_VIDEO, 1);
   1.342  
   1.343  
   1.344 -    //aqueue = gst_element_factory_make ("queue", "aqueue");
   1.345 -    //asink = gst_element_factory_make ("alsasink", "asink");
   1.346 + //aqueue = gst_element_factory_make ("queue", "aqueue");
   1.347 + //asink = gst_element_factory_make ("alsasink", "asink");
   1.348  
   1.349 -    vqueue = gst_element_factory_make ("queue", "vqueue");
   1.350 -    vsink = gst_element_factory_make ("xvimagesink", "vsink");
   1.351 +  vqueue = gst_element_factory_make("queue", "vqueue");
   1.352 +  vsink = gst_element_factory_make("xvimagesink", "vsink");
   1.353  
   1.354 -    gst_bin_add_many (GST_BIN (pipe), gnl_compose_a, gnl_compose_v, 
   1.355 -            vqueue, vsink, 
   1.356 -            //aqueue, asink, 
   1.357 -            NULL);
   1.358 +  gst_bin_add_many(GST_BIN(pipe), gnl_compose_a, gnl_compose_v, vqueue, vsink,
   1.359 +				  //aqueue, asink, 
   1.360 +				   NULL);
   1.361  
   1.362 -    gst_element_link (vqueue, vsink);
   1.363 -    //gst_element_link (aqueue, asink);
   1.364 +  gst_element_link(vqueue, vsink);
   1.365 + //gst_element_link (aqueue, asink);
   1.366  
   1.367 -    //g_signal_connect (G_OBJECT (gnl_compose_a), "pad-added",
   1.368 -    //                  G_CALLBACK (_composition_pad_added_cb), aqueue);
   1.369 + //g_signal_connect (G_OBJECT (gnl_compose_a), "pad-added",
   1.370 + //                  G_CALLBACK (_composition_pad_added_cb), aqueue);
   1.371  
   1.372 -    g_signal_connect (G_OBJECT (gnl_compose_v), "pad-added",
   1.373 -                      G_CALLBACK (_composition_pad_added_cb), vqueue);
   1.374 +  g_signal_connect(G_OBJECT(gnl_compose_v), "pad-added",
   1.375 +				   G_CALLBACK(_composition_pad_added_cb), vqueue);
   1.376  
   1.377  
   1.378 -    //g_idle_add (_play, pipe);
   1.379 -    gst_element_set_state (GST_ELEMENT (pipe), GST_STATE_PLAYING);
   1.380 -	g_main_loop_run (mainloop);
   1.381 + //g_idle_add (_play, pipe);
   1.382 +  gst_element_set_state(GST_ELEMENT(pipe), GST_STATE_PLAYING);
   1.383 +  g_main_loop_run(mainloop);
   1.384  
   1.385 -	return 0;
   1.386 +  return 0;
   1.387  }