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