gstreamer_core/tsrc/check/gst/gstghostpad/src/gstghostpad.c
changeset 0 0e761a78d257
child 8 4a7fac7dd34a
equal deleted inserted replaced
-1:000000000000 0:0e761a78d257
       
     1 /* GStreamer
       
     2  * Copyright (C) 2005 Wim Taymans <wim@fluendo.com>
       
     3  *
       
     4  * gstghostpad.c: Unit test for GstGhostPad
       
     5  *
       
     6  * This library is free software; you can redistribute it and/or
       
     7  * modify it under the terms of the GNU Library General Public
       
     8  * License as published by the Free Software Foundation; either
       
     9  * version 2 of the License, or (at your option) any later version.
       
    10  *
       
    11  * This library is distributed in the hope that it will be useful,
       
    12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
       
    14  * Library General Public License for more details.
       
    15  *
       
    16  * You should have received a copy of the GNU Library General Public
       
    17  * License along with this library; if not, write to the
       
    18  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
       
    19  * Boston, MA 02111-1307, USA.
       
    20  */
       
    21 
       
    22 
       
    23 #include <gst/gst_global.h>
       
    24 #include <gst/check/gstcheck.h>
       
    25 #include <glib_global.h>
       
    26 #include <glib.h>
       
    27 #include <glib/gstdio.h>
       
    28 
       
    29 #include "libgstreamer_wsd_solution.h" 
       
    30 #include <libgstreamer_wsd_macros.h>
       
    31 #ifndef EMULATOR
       
    32 #define assert_failed *(get_assert_failed())
       
    33 #define fp_std_log *(get_fp_std_log())
       
    34 #define xmlfile *(get_xmlfile())
       
    35 #endif
       
    36 
       
    37 #define LOG_FILE "c:\\logs\\gstghostpad_log1.txt"
       
    38 #include "std_log_result.h"
       
    39 #define LOG_FILENAME_LINE __FILE__, __LINE__
       
    40 
       
    41 
       
    42 
       
    43 #if EMULATOR
       
    44 GET_GLOBAL_VAR_FROM_TLS(buffers,gstcheck,GList*)
       
    45 #define buffers (*GET_GSTREAMER_WSD_VAR_NAME(buffers,gstcheck,g)())
       
    46 #else 
       
    47 extern GList *buffers = NULL;
       
    48 #endif
       
    49 
       
    50 void create_xml(int result)
       
    51 {
       
    52     if(result)
       
    53         assert_failed = 1;
       
    54     
       
    55     testResultXml(xmlfile);
       
    56     close_log_file();
       
    57 }
       
    58 
       
    59 
       
    60 /* test if removing a bin also cleans up the ghostpads
       
    61  */
       
    62 void test_remove1()
       
    63 {
       
    64   GstElement *b1, *b2, *src, *sink;
       
    65   GstPad *srcpad, *sinkpad;
       
    66   GstPadLinkReturn ret;
       
    67 	xmlfile = "gstghostpad_test_remove1";
       
    68 	std_log(LOG_FILENAME_LINE, "Test Started test_remove1");
       
    69   b1 = gst_element_factory_make ("pipeline", NULL);
       
    70   b2 = gst_element_factory_make ("bin", NULL);
       
    71   src = gst_element_factory_make ("fakesrc", NULL);
       
    72   sink = gst_element_factory_make ("fakesink", NULL);
       
    73   ASSERT_OBJECT_REFCOUNT (b1, "pipeline", 1);
       
    74   ASSERT_OBJECT_REFCOUNT (b2, "bin", 1);
       
    75 
       
    76   fail_unless (gst_bin_add (GST_BIN (b2), sink));
       
    77   fail_unless (gst_bin_add (GST_BIN (b1), src));
       
    78   ASSERT_OBJECT_REFCOUNT (b1, "pipeline", 1);
       
    79   ASSERT_OBJECT_REFCOUNT (b2, "bin", 1);
       
    80   fail_unless (gst_bin_add (GST_BIN (b1), b2));
       
    81   ASSERT_OBJECT_REFCOUNT (b1, "pipeline", 1);
       
    82   ASSERT_OBJECT_REFCOUNT (b2, "bin", 1);
       
    83 
       
    84   sinkpad = gst_element_get_pad (sink, "sink");
       
    85   gst_element_add_pad (b2, gst_ghost_pad_new ("sink", sinkpad));
       
    86   gst_object_unref (sinkpad);
       
    87 
       
    88   srcpad = gst_element_get_pad (src, "src");
       
    89   /* get the ghostpad */
       
    90   sinkpad = gst_element_get_pad (b2, "sink");
       
    91 
       
    92   ret = gst_pad_link (srcpad, sinkpad);
       
    93   fail_unless (ret == GST_PAD_LINK_OK);
       
    94   gst_object_unref (srcpad);
       
    95   gst_object_unref (sinkpad);
       
    96 
       
    97   /* now remove the bin with the ghostpad, b2 is disposed now. */
       
    98   ASSERT_OBJECT_REFCOUNT (b1, "pipeline", 1);
       
    99   ASSERT_OBJECT_REFCOUNT (b2, "bin", 1);
       
   100   gst_bin_remove (GST_BIN (b1), b2);
       
   101 
       
   102   srcpad = gst_element_get_pad (src, "src");
       
   103   /* pad cannot be linked now */
       
   104   fail_if (gst_pad_is_linked (srcpad));
       
   105   gst_object_unref (srcpad);
       
   106 
       
   107   ASSERT_OBJECT_REFCOUNT (b1, "pipeline", 1);
       
   108   gst_object_unref (b1);
       
   109   std_log(LOG_FILENAME_LINE, "Test Successful");
       
   110 	create_xml(0);
       
   111 
       
   112 
       
   113 }
       
   114 
       
   115 
       
   116 
       
   117 /* test if removing a bin also cleans up the ghostpads
       
   118  */
       
   119 void test_remove2()
       
   120 {
       
   121   GstElement *b1, *b2, *src, *sink;
       
   122   GstPad *srcpad, *sinkpad;
       
   123   GstPadLinkReturn ret;
       
   124 	xmlfile = "gstghostpad_testremove2";
       
   125   std_log(LOG_FILENAME_LINE, "Test Started test_remove2");  
       
   126   b1 = gst_element_factory_make ("pipeline", NULL);
       
   127   b2 = gst_element_factory_make ("bin", NULL);
       
   128   src = gst_element_factory_make ("fakesrc", NULL);
       
   129   sink = gst_element_factory_make ("fakesink", NULL);
       
   130   ASSERT_OBJECT_REFCOUNT (src, "src", 1);
       
   131 
       
   132   fail_unless (gst_bin_add (GST_BIN (b2), sink));
       
   133   fail_unless (gst_bin_add (GST_BIN (b1), src));
       
   134   fail_unless (gst_bin_add (GST_BIN (b1), b2));
       
   135   ASSERT_OBJECT_REFCOUNT (src, "src", 1);
       
   136 
       
   137   sinkpad = gst_element_get_pad (sink, "sink");
       
   138   gst_element_add_pad (b2, gst_ghost_pad_new ("sink", sinkpad));
       
   139   gst_object_unref (sinkpad);
       
   140 
       
   141   srcpad = gst_element_get_pad (src, "src");
       
   142   ASSERT_OBJECT_REFCOUNT (srcpad, "srcpad", 2); /* since we got one */
       
   143   /* get the ghostpad */
       
   144   sinkpad = gst_element_get_pad (b2, "sink");
       
   145   ASSERT_OBJECT_REFCOUNT (sinkpad, "sinkpad", 2);       /* since we got one */
       
   146 
       
   147   GST_DEBUG ("linking srcpad and sinkpad");
       
   148   ret = gst_pad_link (srcpad, sinkpad);
       
   149   GST_DEBUG ("linked srcpad and sinkpad");
       
   150   fail_unless (ret == GST_PAD_LINK_OK);
       
   151   /* the linking causes a proxypad to be created for srcpad,
       
   152    * to which sinkpad gets linked.  This proxypad has a ref to srcpad */
       
   153   ASSERT_OBJECT_REFCOUNT (srcpad, "srcpad", 3);
       
   154   ASSERT_OBJECT_REFCOUNT (sinkpad, "sinkpad", 2);
       
   155   gst_object_unref (srcpad);
       
   156   gst_object_unref (sinkpad);
       
   157 
       
   158   /* now remove the sink from the bin */
       
   159   gst_bin_remove (GST_BIN (b2), sink);
       
   160 
       
   161   srcpad = gst_element_get_pad (src, "src");
       
   162   /* pad is still linked to ghostpad */
       
   163   fail_if (!gst_pad_is_linked (srcpad));
       
   164   ASSERT_OBJECT_REFCOUNT (src, "src", 1);
       
   165   ASSERT_OBJECT_REFCOUNT (srcpad, "srcpad", 3);
       
   166   gst_object_unref (srcpad);
       
   167   ASSERT_OBJECT_REFCOUNT (sinkpad, "sinkpad", 1);
       
   168 
       
   169   /* cleanup */
       
   170   /* now unlink the pads */
       
   171   gst_pad_unlink (srcpad, sinkpad);
       
   172   ASSERT_OBJECT_REFCOUNT (srcpad, "srcpad", 1); /* proxy has dropped ref */
       
   173   ASSERT_OBJECT_REFCOUNT (sinkpad, "sinkpad", 1);
       
   174 
       
   175   ASSERT_OBJECT_REFCOUNT (src, "src", 1);
       
   176   ASSERT_OBJECT_REFCOUNT (b2, "bin", 1);
       
   177   /* remove b2 from b1 */
       
   178   gst_bin_remove (GST_BIN (b1), b2);
       
   179 
       
   180   /* flush the message, dropping the b1 refcount to 1 */
       
   181   gst_element_set_state (b1, GST_STATE_READY);
       
   182   gst_element_set_state (b1, GST_STATE_NULL);
       
   183   ASSERT_OBJECT_REFCOUNT (b1, "pipeline", 1);
       
   184   gst_object_unref (b1);
       
   185 	std_log(LOG_FILENAME_LINE, "Test Successful");
       
   186 	create_xml(0);
       
   187 
       
   188 }
       
   189 
       
   190 
       
   191 
       
   192 /* test if a ghost pad without a target can be linked and
       
   193  * unlinked. An untargeted ghostpad has a default ANY caps unless there 
       
   194  * is a padtemplate that says something else.
       
   195  */
       
   196 void test_ghost_pads_notarget()
       
   197 {
       
   198   GstElement *b1, *b2, *sink;
       
   199   GstPad *srcpad, *sinkpad, *peer;
       
   200   GstPadLinkReturn ret;
       
   201   gboolean bret;
       
   202   GstBus *bus;
       
   203   GstCaps *caps;
       
   204 	xmlfile = "gstghostpad_test_ghost_pads_notarget";
       
   205   std_log(LOG_FILENAME_LINE, "Test Started test_ghost_pads_notarget");  
       
   206   b1 = gst_element_factory_make ("pipeline", NULL);
       
   207 
       
   208   /* make sure all messages are discarded */
       
   209   bus = gst_pipeline_get_bus (GST_PIPELINE (b1));
       
   210   gst_bus_set_flushing (bus, TRUE);
       
   211   gst_object_unref (bus);
       
   212 
       
   213   b2 = gst_element_factory_make ("bin", NULL);
       
   214   sink = gst_element_factory_make ("fakesink", NULL);
       
   215 
       
   216   fail_unless (gst_bin_add (GST_BIN (b1), sink));
       
   217   fail_unless (gst_bin_add (GST_BIN (b1), b2));
       
   218 
       
   219   srcpad = gst_ghost_pad_new_no_target ("src", GST_PAD_SRC);
       
   220   fail_unless (srcpad != NULL);
       
   221   sinkpad = gst_element_get_pad (sink, "sink");
       
   222   fail_unless (sinkpad != NULL);
       
   223 
       
   224   ret = gst_pad_link (srcpad, sinkpad);
       
   225   fail_unless (ret == GST_PAD_LINK_OK);
       
   226 
       
   227   /* check if the peers are ok */
       
   228   peer = gst_pad_get_peer (srcpad);
       
   229   fail_unless (peer == sinkpad);
       
   230   gst_object_unref (peer);
       
   231 
       
   232   peer = gst_pad_get_peer (sinkpad);
       
   233   fail_unless (peer == srcpad);
       
   234   gst_object_unref (peer);
       
   235 
       
   236   /* check caps, untargetted pad should return ANY or the padtemplate caps 
       
   237    * when it was created from a template */
       
   238   caps = gst_pad_get_caps (srcpad);
       
   239   fail_unless (gst_caps_is_any (caps));
       
   240   gst_caps_unref (caps);
       
   241 
       
   242   /* unlink */
       
   243   bret = gst_pad_unlink (srcpad, sinkpad);
       
   244   fail_unless (bret == TRUE);
       
   245 
       
   246   /* cleanup */
       
   247   gst_object_unref (srcpad);
       
   248   gst_object_unref (sinkpad);
       
   249   gst_object_unref (b1);
       
   250 	std_log(LOG_FILENAME_LINE, "Test Successful");
       
   251 	create_xml(0);
       
   252 }
       
   253 
       
   254 
       
   255 
       
   256 /* test if linking fails over different bins using a pipeline
       
   257  * like this:
       
   258  *
       
   259  * fakesrc num_buffers=10 ! ( fakesink )
       
   260  *
       
   261  */
       
   262 void test_link()
       
   263 {
       
   264   GstElement *b1, *b2, *src, *sink;
       
   265   GstPad *srcpad, *sinkpad, *gpad;
       
   266   GstPadLinkReturn ret;
       
   267 	xmlfile = "gstghostpad_test_link";
       
   268   std_log(LOG_FILENAME_LINE, "Test Started test_link");  
       
   269   b1 = gst_element_factory_make ("pipeline", NULL);
       
   270   b2 = gst_element_factory_make ("bin", NULL);
       
   271   src = gst_element_factory_make ("fakesrc", NULL);
       
   272   sink = gst_element_factory_make ("fakesink", NULL);
       
   273 
       
   274   fail_unless (gst_bin_add (GST_BIN (b2), sink));
       
   275   fail_unless (gst_bin_add (GST_BIN (b1), src));
       
   276   fail_unless (gst_bin_add (GST_BIN (b1), b2));
       
   277 
       
   278   srcpad = gst_element_get_pad (src, "src");
       
   279   fail_unless (srcpad != NULL);
       
   280   sinkpad = gst_element_get_pad (sink, "sink");
       
   281   fail_unless (sinkpad != NULL);
       
   282 
       
   283   /* linking in different hierarchies should fail */
       
   284   ret = gst_pad_link (srcpad, sinkpad);
       
   285   fail_unless (ret == GST_PAD_LINK_WRONG_HIERARCHY);
       
   286 
       
   287   /* now setup a ghostpad */
       
   288   gpad = gst_ghost_pad_new ("sink", sinkpad);
       
   289   gst_object_unref (sinkpad);
       
   290   /* need to ref as _add_pad takes ownership */
       
   291   gst_object_ref (gpad);
       
   292   gst_element_add_pad (b2, gpad);
       
   293 
       
   294   /* our new sinkpad */
       
   295   sinkpad = gpad;
       
   296 
       
   297   /* and linking should work now */
       
   298   ret = gst_pad_link (srcpad, sinkpad);
       
   299   fail_unless (ret == GST_PAD_LINK_OK);
       
   300 
       
   301   /* flush the message, dropping the b1 refcount to 1 */
       
   302   gst_element_set_state (b1, GST_STATE_READY);
       
   303   gst_element_set_state (b1, GST_STATE_NULL);
       
   304   ASSERT_OBJECT_REFCOUNT (b1, "pipeline", 1);
       
   305 
       
   306   gst_object_unref (srcpad);
       
   307   gst_object_unref (sinkpad);
       
   308   gst_object_unref (b1);
       
   309   std_log(LOG_FILENAME_LINE, "Test Successful");
       
   310 	create_xml(0);
       
   311 }
       
   312 
       
   313 
       
   314 
       
   315 /* test if ghostpads are created automagically when using
       
   316  * gst_element_link_pads.
       
   317  *
       
   318  * fakesrc num_buffers=10 ! ( identity ) ! fakesink
       
   319  */
       
   320 void test_ghost_pads()
       
   321 {
       
   322   GstElement *b1, *b2, *src, *i1, *sink;
       
   323   GstPad *gsink, *gsrc, *gisrc, *gisink, *isink, *isrc, *fsrc, *fsink;
       
   324   GstStateChangeReturn ret;
       
   325 	xmlfile = "gstghostpad_test_ghost_pads";
       
   326 	std_log(LOG_FILENAME_LINE, "Test Started test_ghost_pads");  
       
   327   b1 = gst_element_factory_make ("pipeline", NULL);
       
   328   b2 = gst_element_factory_make ("bin", NULL);
       
   329   src = gst_element_factory_make ("fakesrc", NULL);
       
   330   g_object_set (src, "num-buffers", (int) 10, NULL);
       
   331   i1 = gst_element_factory_make ("identity", NULL);
       
   332   sink = gst_element_factory_make ("fakesink", NULL);
       
   333 
       
   334   fail_unless (gst_bin_add (GST_BIN (b2), i1));
       
   335   fail_unless (gst_bin_add (GST_BIN (b1), src));
       
   336   fail_unless (gst_bin_add (GST_BIN (b1), b2));
       
   337   fail_unless (gst_bin_add (GST_BIN (b1), sink));
       
   338   fail_unless (gst_element_link_pads (src, NULL, i1, NULL));
       
   339   fail_unless (gst_element_link_pads (i1, NULL, sink, NULL));
       
   340   GST_OBJECT_LOCK (b2);
       
   341   fail_unless (b2->numsinkpads == 1);
       
   342   fail_unless (GST_IS_GHOST_PAD (b2->sinkpads->data));
       
   343   fail_unless (b2->numsrcpads == 1);
       
   344   fail_unless (GST_IS_GHOST_PAD (b2->srcpads->data));
       
   345   GST_OBJECT_UNLOCK (b2);
       
   346 
       
   347   fsrc = gst_element_get_pad (src, "src");
       
   348   fail_unless (fsrc != NULL);
       
   349   gsink = GST_PAD (gst_object_ref (b2->sinkpads->data));
       
   350   fail_unless (gsink != NULL);
       
   351   gsrc = GST_PAD (gst_object_ref (b2->srcpads->data));
       
   352   fail_unless (gsrc != NULL);
       
   353   fsink = gst_element_get_pad (sink, "sink");
       
   354   fail_unless (fsink != NULL);
       
   355 
       
   356   isink = gst_element_get_pad (i1, "sink");
       
   357   fail_unless (isink != NULL);
       
   358   isrc = gst_element_get_pad (i1, "src");
       
   359   fail_unless (isrc != NULL);
       
   360   gisrc = gst_pad_get_peer (isink);
       
   361   fail_unless (gisrc != NULL);
       
   362   gisink = gst_pad_get_peer (isrc);
       
   363   fail_unless (gisink != NULL);
       
   364 
       
   365   /* all objects above have one refcount owned by us as well */
       
   366 
       
   367   ASSERT_OBJECT_REFCOUNT (fsrc, "fsrc", 3);     /* parent and gisrc */
       
   368   ASSERT_OBJECT_REFCOUNT (gsink, "gsink", 2);   /* parent */
       
   369   ASSERT_OBJECT_REFCOUNT (gsrc, "gsrc", 2);     /* parent */
       
   370   ASSERT_OBJECT_REFCOUNT (fsink, "fsink", 3);   /* parent and gisink */
       
   371 
       
   372   ASSERT_OBJECT_REFCOUNT (gisrc, "gisrc", 2);   /* parent */
       
   373   ASSERT_OBJECT_REFCOUNT (isink, "isink", 3);   /* parent and gsink */
       
   374   ASSERT_OBJECT_REFCOUNT (gisink, "gisink", 2); /* parent */
       
   375   ASSERT_OBJECT_REFCOUNT (isrc, "isrc", 3);     /* parent and gsrc */
       
   376 
       
   377   ret = gst_element_set_state (b1, GST_STATE_PLAYING);
       
   378   ret = gst_element_get_state (b1, NULL, NULL, GST_CLOCK_TIME_NONE);
       
   379   fail_unless (ret == GST_STATE_CHANGE_SUCCESS);
       
   380 
       
   381   ret = gst_element_set_state (b1, GST_STATE_NULL);
       
   382   ret = gst_element_get_state (b1, NULL, NULL, GST_CLOCK_TIME_NONE);
       
   383   fail_unless (ret == GST_STATE_CHANGE_SUCCESS);
       
   384 
       
   385   gst_object_unref (b1);
       
   386   /* unreffing the bin will unref all elements, which will unlink and unparent
       
   387    * all pads */
       
   388 
       
   389   /* wait for thread to settle down */
       
   390   while (GST_OBJECT_REFCOUNT_VALUE (fsrc) > 2)
       
   391     THREAD_SWITCH ();
       
   392 
       
   393   ASSERT_OBJECT_REFCOUNT (fsrc, "fsrc", 1);
       
   394   ASSERT_OBJECT_REFCOUNT (gsink, "gsink", 1);
       
   395   ASSERT_OBJECT_REFCOUNT (gsrc, "gsink", 1);
       
   396   ASSERT_OBJECT_REFCOUNT (fsink, "fsink", 1);
       
   397 
       
   398   ASSERT_OBJECT_REFCOUNT (gisrc, "gisrc", 2);   /* gsink */
       
   399   ASSERT_OBJECT_REFCOUNT (isink, "isink", 2);   /* gsink */
       
   400   ASSERT_OBJECT_REFCOUNT (gisink, "gisink", 2); /* gsrc */
       
   401   ASSERT_OBJECT_REFCOUNT (isrc, "isrc", 2);     /* gsrc */
       
   402 
       
   403   gst_object_unref (gsink);
       
   404   ASSERT_OBJECT_REFCOUNT (isink, "isink", 1);
       
   405   ASSERT_OBJECT_REFCOUNT (gisrc, "gisrc", 1);
       
   406   ASSERT_OBJECT_REFCOUNT (fsrc, "fsrc", 1);
       
   407   gst_object_unref (gisrc);
       
   408   ASSERT_OBJECT_REFCOUNT (fsrc, "fsrc", 1);
       
   409 
       
   410   gst_object_unref (gsrc);
       
   411   ASSERT_OBJECT_REFCOUNT (isrc, "isrc", 1);
       
   412   ASSERT_OBJECT_REFCOUNT (gisink, "gisink", 1);
       
   413   ASSERT_OBJECT_REFCOUNT (fsink, "fsink", 1);
       
   414   gst_object_unref (gisink);
       
   415   ASSERT_OBJECT_REFCOUNT (fsink, "fsink", 1);
       
   416 
       
   417   gst_object_unref (fsrc);
       
   418   gst_object_unref (isrc);
       
   419   gst_object_unref (isink);
       
   420   gst_object_unref (fsink);
       
   421   std_log(LOG_FILENAME_LINE, "Test Successful");
       
   422 	create_xml(0);
       
   423 }
       
   424 
       
   425 
       
   426 
       
   427 void test_ghost_pads_bin()
       
   428 {
       
   429   GstBin *pipeline;
       
   430   GstBin *srcbin;
       
   431   GstBin *sinkbin;
       
   432   GstElement *src;
       
   433   GstElement *sink;
       
   434   GstPad *srcpad, *srcghost, *target;
       
   435   GstPad *sinkpad, *sinkghost;
       
   436 	xmlfile = "gstghostpad_test_ghost_pads_bin";
       
   437   std_log(LOG_FILENAME_LINE, "Test Started test_ghost_pads_bin");  
       
   438   pipeline = GST_BIN (gst_pipeline_new ("pipe"));
       
   439   ASSERT_OBJECT_REFCOUNT (pipeline, "pipeline", 1);
       
   440 
       
   441   srcbin = GST_BIN (gst_bin_new ("srcbin"));
       
   442   gst_bin_add (pipeline, GST_ELEMENT (srcbin));
       
   443   ASSERT_OBJECT_REFCOUNT (pipeline, "pipeline", 1);
       
   444 
       
   445   sinkbin = GST_BIN (gst_bin_new ("sinkbin"));
       
   446   gst_bin_add (pipeline, GST_ELEMENT (sinkbin));
       
   447   ASSERT_OBJECT_REFCOUNT (pipeline, "pipeline", 1);
       
   448 
       
   449   src = gst_element_factory_make ("fakesrc", "src");
       
   450   gst_bin_add (srcbin, src);
       
   451   srcpad = gst_element_get_pad (src, "src");
       
   452   srcghost = gst_ghost_pad_new ("src", srcpad);
       
   453   gst_object_unref (srcpad);
       
   454   gst_element_add_pad (GST_ELEMENT (srcbin), srcghost);
       
   455 
       
   456   sink = gst_element_factory_make ("fakesink", "sink");
       
   457   gst_bin_add (sinkbin, sink);
       
   458   sinkpad = gst_element_get_pad (sink, "sink");
       
   459   sinkghost = gst_ghost_pad_new ("sink", sinkpad);
       
   460   gst_object_unref (sinkpad);
       
   461   gst_element_add_pad (GST_ELEMENT (sinkbin), sinkghost);
       
   462 
       
   463   gst_element_link (GST_ELEMENT (srcbin), GST_ELEMENT (sinkbin));
       
   464 
       
   465   fail_unless (GST_PAD_PEER (srcghost) != NULL);
       
   466   fail_unless (GST_PAD_PEER (sinkghost) != NULL);
       
   467   target = gst_ghost_pad_get_target (GST_GHOST_PAD (srcghost));
       
   468   fail_unless (GST_PAD_PEER (target) != NULL);
       
   469   gst_object_unref (target);
       
   470   target = gst_ghost_pad_get_target (GST_GHOST_PAD (sinkghost));
       
   471   fail_unless (GST_PAD_PEER (target) != NULL);
       
   472   gst_object_unref (target);
       
   473 
       
   474   ASSERT_OBJECT_REFCOUNT (pipeline, "pipeline", 1);
       
   475 
       
   476   gst_object_unref (pipeline);
       
   477   std_log(LOG_FILENAME_LINE, "Test Successful");
       
   478 	create_xml(0);
       
   479 }
       
   480 
       
   481 
       
   482 
       
   483 typedef struct
       
   484 {
       
   485   GMutex *mutex;
       
   486   GCond *cond;
       
   487 } BlockData;
       
   488 
       
   489 static void
       
   490 block_callback (GstPad * pad, gboolean blocked, gpointer user_data)
       
   491 {
       
   492   BlockData *block_data = (BlockData *) user_data;
       
   493 
       
   494   g_mutex_lock (block_data->mutex);
       
   495   GST_DEBUG ("blocked\n");
       
   496   g_cond_signal (block_data->cond);
       
   497   g_mutex_unlock (block_data->mutex);
       
   498 }
       
   499 
       
   500 void test_ghost_pads_block()
       
   501 {
       
   502   GstBin *pipeline;
       
   503   GstBin *srcbin;
       
   504   GstElement *src;
       
   505   GstPad *srcpad;
       
   506   GstPad *srcghost;
       
   507   BlockData block_data;
       
   508 	xmlfile = "gstghostpad_test_ghost_pads_block";
       
   509   std_log(LOG_FILENAME_LINE, "Test Started test_ghost_pads_block");  
       
   510   pipeline = GST_BIN (gst_pipeline_new ("pipeline"));
       
   511 
       
   512   srcbin = GST_BIN (gst_bin_new ("srcbin"));
       
   513   gst_bin_add (pipeline, GST_ELEMENT (srcbin));
       
   514 
       
   515   src = gst_element_factory_make ("fakesrc", "src");
       
   516   gst_bin_add (srcbin, src);
       
   517   srcpad = gst_element_get_pad (src, "src");
       
   518   srcghost = gst_ghost_pad_new ("src", srcpad);
       
   519   gst_element_add_pad (GST_ELEMENT (srcbin), srcghost);
       
   520   gst_object_unref (srcpad);
       
   521 
       
   522   block_data.mutex = g_mutex_new ();
       
   523   block_data.cond = g_cond_new ();
       
   524 
       
   525   g_mutex_lock (block_data.mutex);
       
   526   gst_pad_set_blocked_async (srcghost, TRUE, block_callback, &block_data);
       
   527   gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PLAYING);
       
   528   /* and wait now */
       
   529   g_cond_wait (block_data.cond, block_data.mutex);
       
   530   gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_NULL);
       
   531   g_mutex_unlock (block_data.mutex);
       
   532 
       
   533   g_mutex_free (block_data.mutex);
       
   534   g_cond_free (block_data.cond);
       
   535 
       
   536   ASSERT_OBJECT_REFCOUNT (pipeline, "pipeline", 1);
       
   537   gst_object_unref (pipeline);
       
   538   std_log(LOG_FILENAME_LINE, "Test Successful");
       
   539 	create_xml(0);
       
   540 }
       
   541 
       
   542 
       
   543 
       
   544 void test_ghost_pads_probes()
       
   545 {
       
   546   GstBin *pipeline;
       
   547   GstBin *srcbin;
       
   548   GstElement *src;
       
   549   GstPad *srcpad;
       
   550   GstPad *srcghost;
       
   551   BlockData block_data;
       
   552 	xmlfile = "gstghostpad_test_ghost_pads_probes";
       
   553   std_log(LOG_FILENAME_LINE, "Test Started test_ghost_pads_probes");  
       
   554   pipeline = GST_BIN (gst_pipeline_new ("pipeline"));
       
   555 
       
   556   srcbin = GST_BIN (gst_bin_new ("srcbin"));
       
   557   gst_bin_add (pipeline, GST_ELEMENT (srcbin));
       
   558 
       
   559   src = gst_element_factory_make ("fakesrc", "src");
       
   560   gst_bin_add (srcbin, src);
       
   561   srcpad = gst_element_get_pad (src, "src");
       
   562   srcghost = gst_ghost_pad_new ("src", srcpad);
       
   563   gst_element_add_pad (GST_ELEMENT (srcbin), srcghost);
       
   564   gst_object_unref (srcpad);
       
   565 
       
   566   block_data.mutex = g_mutex_new ();
       
   567   block_data.cond = g_cond_new ();
       
   568 
       
   569   g_mutex_lock (block_data.mutex);
       
   570   gst_pad_set_blocked_async (srcghost, TRUE, block_callback, &block_data);
       
   571   gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PLAYING);
       
   572   /* and wait now */
       
   573   g_cond_wait (block_data.cond, block_data.mutex);
       
   574   gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_NULL);
       
   575   g_mutex_unlock (block_data.mutex);
       
   576 
       
   577   g_mutex_free (block_data.mutex);
       
   578   g_cond_free (block_data.cond);
       
   579 
       
   580   ASSERT_OBJECT_REFCOUNT (pipeline, "pipeline", 1);
       
   581   gst_object_unref (pipeline);
       
   582   std_log(LOG_FILENAME_LINE, "Test Successful");
       
   583 	create_xml(0);
       
   584 }
       
   585 
       
   586 
       
   587 
       
   588 void test_ghost_pads_new_from_template()
       
   589 {
       
   590   GstPad *sinkpad, *ghostpad;
       
   591   GstPadTemplate *padtempl, *ghosttempl;
       
   592   GstCaps *padcaps, *ghostcaps, *newcaps;
       
   593 	xmlfile = "gstghostpad_test_ghost_pads_new_from_template";
       
   594   std_log(LOG_FILENAME_LINE, "Test Started test_ghost_pads_new_from_template");  
       
   595   padcaps = gst_caps_from_string ("some/caps");
       
   596   fail_unless (padcaps != NULL);
       
   597   ghostcaps = gst_caps_from_string ("some/caps;some/other-caps");
       
   598   fail_unless (ghostcaps != NULL);
       
   599 
       
   600   padtempl = gst_pad_template_new ("padtempl", GST_PAD_SINK,
       
   601       GST_PAD_ALWAYS, padcaps);
       
   602   fail_unless (padtempl != NULL);
       
   603   ghosttempl = gst_pad_template_new ("ghosttempl", GST_PAD_SINK,
       
   604       GST_PAD_ALWAYS, ghostcaps);
       
   605 
       
   606   sinkpad = gst_pad_new_from_template (padtempl, "sinkpad");
       
   607   fail_unless (sinkpad != NULL);
       
   608 
       
   609   ghostpad = gst_ghost_pad_new_from_template ("ghostpad", sinkpad, ghosttempl);
       
   610   fail_unless (ghostpad != NULL);
       
   611 
       
   612   /* check template is properly set */
       
   613   fail_unless (GST_PAD_PAD_TEMPLATE (ghostpad) == ghosttempl);
       
   614 
       
   615   /* check ghostpad caps are from the sinkpad */
       
   616   newcaps = gst_pad_get_caps (ghostpad);
       
   617   fail_unless (newcaps != NULL);
       
   618   fail_unless (gst_caps_is_equal (newcaps, padcaps));
       
   619   gst_caps_unref (newcaps);
       
   620   gst_caps_unref (padcaps);
       
   621   std_log(LOG_FILENAME_LINE, "Test Successful");
       
   622 	create_xml(0);
       
   623 }
       
   624 
       
   625 
       
   626 
       
   627 void test_ghost_pads_new_no_target_from_template()
       
   628 {
       
   629   GstPad *sinkpad, *ghostpad;
       
   630   GstPadTemplate *padtempl, *ghosttempl;
       
   631   GstCaps *padcaps, *ghostcaps, *newcaps;
       
   632 	xmlfile = "gstghostpad_test_ghost_pads_new_no_target_from_template";
       
   633   std_log(LOG_FILENAME_LINE, "Test Started test_ghost_pads_new_no_target_from_template");  
       
   634   padcaps = gst_caps_from_string ("some/caps");
       
   635   fail_unless (padcaps != NULL);
       
   636   ghostcaps = gst_caps_from_string ("some/caps;some/other-caps");
       
   637   fail_unless (ghostcaps != NULL);
       
   638 
       
   639   padtempl = gst_pad_template_new ("padtempl", GST_PAD_SINK,
       
   640       GST_PAD_ALWAYS, padcaps);
       
   641   fail_unless (padtempl != NULL);
       
   642   ghosttempl = gst_pad_template_new ("ghosttempl", GST_PAD_SINK,
       
   643       GST_PAD_ALWAYS, ghostcaps);
       
   644 
       
   645   sinkpad = gst_pad_new_from_template (padtempl, "sinkpad");
       
   646   fail_unless (sinkpad != NULL);
       
   647 
       
   648   ghostpad = gst_ghost_pad_new_no_target_from_template ("ghostpad", ghosttempl);
       
   649   fail_unless (ghostpad != NULL);
       
   650 
       
   651   /* check template is properly set */
       
   652   fail_unless (GST_PAD_PAD_TEMPLATE (ghostpad) == ghosttempl);
       
   653 
       
   654   /* check ghostpad caps are from the ghostpad template */
       
   655   newcaps = gst_pad_get_caps (ghostpad);
       
   656   fail_unless (newcaps != NULL);
       
   657   fail_unless (gst_caps_is_equal (newcaps, ghostcaps));
       
   658   gst_caps_unref (newcaps);
       
   659 
       
   660   fail_unless (gst_ghost_pad_set_target ((GstGhostPad *) ghostpad, sinkpad));
       
   661 
       
   662   /* check ghostpad caps are now from the target pad */
       
   663   newcaps = gst_pad_get_caps (ghostpad);
       
   664   fail_unless (newcaps != NULL);
       
   665   fail_unless (gst_caps_is_equal (newcaps, padcaps));
       
   666   gst_caps_unref (newcaps);
       
   667   std_log(LOG_FILENAME_LINE, "Test Successful");
       
   668 	create_xml(0);
       
   669 }
       
   670 
       
   671 #if 1
       
   672 void (*fn[10]) (void) = {
       
   673 	  			test_remove1,
       
   674 				test_remove2,
       
   675 				test_ghost_pads_notarget,
       
   676 				test_link,
       
   677 				test_ghost_pads,
       
   678 		   		test_ghost_pads_bin,
       
   679 				test_ghost_pads_block,
       
   680         			test_ghost_pads_probes,
       
   681         			test_ghost_pads_new_from_template,
       
   682         			test_ghost_pads_new_no_target_from_template
       
   683 };
       
   684 
       
   685 char *args[] = {
       
   686 				"test_remove1",
       
   687 				"test_remove2",
       
   688 				"test_ghost_pads_notarget",
       
   689 				"test_link",
       
   690 				"test_ghost_pads",
       
   691 				"test_ghost_pads_bin",
       
   692 				"test_ghost_pads_block",
       
   693        				"test_ghost_pads_probes",
       
   694       		    		"test_ghost_pads_new_from_template",
       
   695       		   		"test_ghost_pads_new_no_target_from_template"
       
   696 };
       
   697 
       
   698 
       
   699 
       
   700 GST_CHECK_MAIN (gst_ghost_pad);
       
   701 #endif
       
   702 
       
   703 
       
   704 #if 0
       
   705 int main()
       
   706 {
       
   707     
       
   708     
       
   709 	gst_check_init (NULL, NULL);
       
   710 	test_remove1();
       
   711 	test_remove2();
       
   712 	test_ghost_pads_notarget();
       
   713  	test_link();
       
   714 	test_ghost_pads();
       
   715  	test_ghost_pads_bin();
       
   716  	test_ghost_pads_block();
       
   717  	test_ghost_pads_probes();
       
   718  	test_ghost_pads_new_from_template();
       
   719  	test_ghost_pads_new_no_target_from_template();
       
   720   	
       
   721 
       
   722 }
       
   723 #endif
       
   724 
       
   725 
       
   726 
       
   727 
       
   728 
       
   729