gst_plugins_base/tsrc/check/pipelines/streamheader/src/streamheader.c
changeset 0 0e761a78d257
child 8 4a7fac7dd34a
child 29 567bb019e3e3
equal deleted inserted replaced
-1:000000000000 0:0e761a78d257
       
     1 /* GStreamer
       
     2  *
       
     3  * unit test for streamheader handling
       
     4  *
       
     5  * Copyright (C) 2007 Thomas Vander Stichele <thomas at apestaart dot org>
       
     6  *
       
     7  * This library is free software; you can redistribute it and/or
       
     8  * modify it under the terms of the GNU Library General Public
       
     9  * License as published by the Free Software Foundation; either
       
    10  * version 2 of the License, or (at your option) any later version.
       
    11  *
       
    12  * This library is distributed in the hope that it will be useful,
       
    13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
       
    15  * Library General Public License for more details.
       
    16  *
       
    17  * You should have received a copy of the GNU Library General Public
       
    18  * License along with this library; if not, write to the
       
    19  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
       
    20  * Boston, MA 02111-1307, USA.
       
    21  */
       
    22 
       
    23 
       
    24 #ifdef HAVE_CONFIG_H
       
    25 #include "config.h"
       
    26 #endif
       
    27 
       
    28 
       
    29 #include <gst/gst_global.h>
       
    30 #include <unistd.h>
       
    31 #include <gst/check/gstcheck.h>
       
    32 
       
    33 #include <fcntl.h>
       
    34 
       
    35 #define LOG_FILE "c:\\logs\\streamheader_logs.txt" 
       
    36 #include "std_log_result.h" 
       
    37 #define LOG_FILENAME_LINE __FILE__, __LINE__
       
    38 
       
    39 void create_xml(int result)
       
    40 {
       
    41     if(result)
       
    42         assert_failed = 1;
       
    43     
       
    44     testResultXml(xmlfile);
       
    45     close_log_file();
       
    46 }
       
    47 
       
    48 #if EMULATOR
       
    49 static GET_GLOBAL_VAR_FROM_TLS(raised_critical,gstcheck,gboolean)
       
    50 #define _gst_check_raised_critical (*GET_GSTREAMER_WSD_VAR_NAME(raised_critical,gstcheck,g)())
       
    51 #else 
       
    52 extern gboolean _gst_check_raised_critical;
       
    53 #endif
       
    54 //gboolean _gst_check_raised_warning = FALSE;
       
    55 #if EMULATOR
       
    56 static GET_GLOBAL_VAR_FROM_TLS(raised_warning,gstcheck,gboolean)
       
    57 #define _gst_check_raised_warning (*GET_GSTREAMER_WSD_VAR_NAME(raised_warning,gstcheck,g)())
       
    58 #else 
       
    59 extern gboolean _gst_check_raised_warning;
       
    60 #endif
       
    61 //gboolean _gst_check_expecting_log = FALSE;
       
    62 #if EMULATOR
       
    63 static GET_GLOBAL_VAR_FROM_TLS(expecting_log,gstcheck,gboolean)
       
    64 #define _gst_check_expecting_log (*GET_GSTREAMER_WSD_VAR_NAME(expecting_log,gstcheck,g)())
       
    65 #else 
       
    66 extern gboolean _gst_check_expecting_log;
       
    67 #endif
       
    68 
       
    69 //gboolean _gst_check_expecting_log = FALSE;
       
    70 #if EMULATOR
       
    71 static GET_GLOBAL_VAR_FROM_TLS(threads_running,gstcheck,gboolean)
       
    72 #define _gst_check_threads_running (*GET_GSTREAMER_WSD_VAR_NAME(threads_running,gstcheck,g)())
       
    73 #else 
       
    74 extern gboolean _gst_check_threads_running;
       
    75 #endif
       
    76 
       
    77 
       
    78 
       
    79 #include <gst/check/gstbufferstraw.h>
       
    80 
       
    81 #ifndef GST_DISABLE_PARSE
       
    82 
       
    83 /* this tests a gdp-serialized tag from audiotestsrc being sent only once
       
    84  * to clients of multifdsink */
       
    85 
       
    86 static int n_tags = 0;
       
    87 
       
    88 static gboolean
       
    89 tag_event_probe_cb (GstPad * pad, GstEvent * event, GMainLoop * loop)
       
    90 {
       
    91   switch (GST_EVENT_TYPE (event)) {
       
    92     case GST_EVENT_TAG:
       
    93     {
       
    94       ++n_tags;
       
    95       fail_if (n_tags > 1, "More than 1 tag received");
       
    96       break;
       
    97     }
       
    98     case GST_EVENT_EOS:
       
    99     {
       
   100       g_main_loop_quit (loop);
       
   101       break;
       
   102     }
       
   103     default:
       
   104       break;
       
   105   }
       
   106 
       
   107   return TRUE;
       
   108 }
       
   109 
       
   110 #if 0 
       
   111 void test_multifdsink_gdp_tag()
       
   112 {
       
   113   GstElement *p1, *p2;
       
   114   GstElement *src, *sink, *depay;
       
   115   GstPad *pad;
       
   116   GMainLoop *loop;
       
   117   int pfd[2];
       
   118   
       
   119   std_log(LOG_FILENAME_LINE, "Test Started test_multifdsink_gdp_tag");
       
   120   
       
   121   loop = g_main_loop_new (NULL, FALSE);
       
   122   
       
   123   p1 = gst_parse_launch ("audiotestsrc num-buffers=10 ! gdppay"
       
   124       " ! multifdsink name=p1sink", NULL);
       
   125   
       
   126 /*      
       
   127   p1 = gst_parse_launch ("audiotestsrc  ! gdppay"
       
   128       " ! multifdsink name=p1sink", NULL);
       
   129 */ 
       
   130   
       
   131   fail_if (p1 == NULL);
       
   132   p2 = gst_parse_launch ("fdsrc name=p2src ! gdpdepay name=depay"
       
   133       " ! fakesink name=p2sink signal-handoffs=True", NULL);
       
   134   fail_if (p2 == NULL);
       
   135 
       
   136    
       
   137   fail_if (pipe (pfd) == -1);
       
   138 
       
   139 
       
   140   gst_element_set_state (p1, GST_STATE_READY);
       
   141 
       
   142   sink = gst_bin_get_by_name (GST_BIN (p1), "p1sink");
       
   143   g_signal_emit_by_name (sink, "add", pfd[1], NULL);
       
   144   gst_object_unref (sink);
       
   145   
       
   146   src = gst_bin_get_by_name (GST_BIN (p2), "p2src");
       
   147   g_object_set (G_OBJECT (src), "fd", pfd[0], NULL);
       
   148   gst_object_unref (src);
       
   149 
       
   150   depay = gst_bin_get_by_name (GST_BIN (p2), "depay");
       
   151   fail_if (depay == NULL);
       
   152 
       
   153   pad = gst_element_get_pad (depay, "src");
       
   154   fail_unless (pad != NULL, "Could not get pad out of depay");
       
   155   gst_object_unref (depay);
       
   156 
       
   157   gst_pad_add_event_probe (pad, G_CALLBACK (tag_event_probe_cb), loop);
       
   158 
       
   159   gst_element_set_state (p1, GST_STATE_PLAYING);
       
   160   gst_element_set_state (p2, GST_STATE_PLAYING);
       
   161 
       
   162   g_main_loop_run (loop);
       
   163 
       
   164   assert_equals_int (n_tags, 1);
       
   165   
       
   166   std_log(LOG_FILENAME_LINE, "Test Successful");
       
   167   create_xml(0);
       
   168 }
       
   169 #endif
       
   170 
       
   171 void test_multifdsink_gdp_tag()
       
   172 {
       
   173   GstElement *p1, *p2, *audiotest,*depay1,*depay2,*multifd,*fakesink,*fdsrc;
       
   174   GstElement *src, *sink, *depay;
       
   175   GstPad *pad;
       
   176   GMainLoop *loop;
       
   177   int pfd[2];
       
   178   
       
   179   std_log(LOG_FILENAME_LINE, "Test Started test_multifdsink_gdp_tag");
       
   180   
       
   181   loop = g_main_loop_new (NULL, FALSE);
       
   182   
       
   183   p1 = gst_pipeline_new("first");
       
   184   fail_if (p1 == NULL);
       
   185   audiotest = gst_element_factory_make("audiotestsrc","audiotest");
       
   186   g_object_set(audiotest,"num-buffers",10,NULL);
       
   187   depay1 = gst_element_factory_make("gdppay","gdppay");
       
   188   multifd= gst_element_factory_make("multifdsink","p1sink");
       
   189   gst_bin_add_many(GST_BIN(p1),audiotest,depay1,multifd,NULL);
       
   190   gst_element_link_many(audiotest,depay1,multifd,NULL);
       
   191 
       
   192   
       
   193 /*  
       
   194   p1 = gst_parse_launch ("audiotestsrc num-buffers=10 ! gdppay"
       
   195       " ! multifdsink name=p1sink", NULL);
       
   196 */
       
   197   
       
   198 /*      
       
   199   p1 = gst_parse_launch ("audiotestsrc  ! gdppay"
       
   200       " ! multifdsink name=p1sink", NULL);
       
   201 */ 
       
   202   
       
   203   
       
   204   /*
       
   205   
       
   206   p2 = gst_parse_launch ("fdsrc name=p2src ! gdpdepay name=depay"
       
   207       " ! fakesink name=p2sink signal-handoffs=True", NULL);
       
   208   */
       
   209   p2 = gst_pipeline_new("second");
       
   210   fail_if (p2 == NULL);
       
   211   fdsrc = gst_element_factory_make("fdsrc","p2src");
       
   212   depay2 = gst_element_factory_make("gdpdepay","depay");
       
   213   fakesink= gst_element_factory_make("fakesink","p2sink");
       
   214   g_object_set(fakesink,"signal-handoffs",1,NULL);
       
   215   gst_bin_add_many(GST_BIN(p2),fdsrc,depay2,fakesink,NULL);
       
   216   gst_element_link_many(fdsrc,depay2,fakesink,NULL);
       
   217 
       
   218   fail_if (pipe (pfd) == -1);
       
   219 
       
   220 
       
   221   gst_element_set_state (p1, GST_STATE_READY);
       
   222 
       
   223   sink = gst_bin_get_by_name (GST_BIN (p1), "p1sink");
       
   224   g_signal_emit_by_name (sink, "add", pfd[1], NULL);
       
   225   gst_object_unref (sink);
       
   226   
       
   227   src = gst_bin_get_by_name (GST_BIN (p2), "p2src");
       
   228   g_object_set (G_OBJECT (src), "fd", pfd[0], NULL);
       
   229   gst_object_unref (src);
       
   230 
       
   231   depay = gst_bin_get_by_name (GST_BIN (p2), "depay");
       
   232   fail_if (depay == NULL);
       
   233 
       
   234   pad = gst_element_get_pad (depay, "src");
       
   235   fail_unless (pad != NULL, "Could not get pad out of depay");
       
   236   gst_object_unref (depay);
       
   237 
       
   238   gst_pad_add_event_probe (pad, G_CALLBACK (tag_event_probe_cb), loop);
       
   239 
       
   240   gst_element_set_state (p1, GST_STATE_PLAYING);
       
   241   gst_element_set_state (p2, GST_STATE_PLAYING);
       
   242 
       
   243   g_main_loop_run (loop);
       
   244 
       
   245   assert_equals_int (n_tags, 1);
       
   246   
       
   247   std_log(LOG_FILENAME_LINE, "Test Successful");
       
   248   create_xml(0);
       
   249 }
       
   250 
       
   251 /* this tests gdp-serialized Vorbis header pages being sent only once
       
   252  * to clients of multifdsink; the gdp depayloader should deserialize
       
   253  * exactly three in_caps buffers for the three header packets */
       
   254 
       
   255 #if 0 
       
   256 
       
   257 static int n_in_caps = 0;
       
   258 
       
   259 static gboolean
       
   260 buffer_probe_cb (GstPad * pad, GstBuffer * buffer)
       
   261 {
       
   262   if (GST_BUFFER_FLAG_IS_SET (buffer, GST_BUFFER_FLAG_IN_CAPS)) {
       
   263     GstCaps *caps;
       
   264     GstStructure *s;
       
   265     const GValue *sh;
       
   266     GArray *buffers;
       
   267     GstBuffer *buf;
       
   268     int i;
       
   269     gboolean found = FALSE;
       
   270 
       
   271     n_in_caps++;
       
   272 
       
   273     caps = gst_buffer_get_caps (buffer);
       
   274     s = gst_caps_get_structure (caps, 0);
       
   275     fail_unless (gst_structure_has_field (s, "streamheader"));
       
   276     sh = gst_structure_get_value (s, "streamheader");
       
   277     buffers = g_value_peek_pointer (sh);
       
   278     assert_equals_int (buffers->len, 3);
       
   279 
       
   280 
       
   281     for (i = 0; i < 3; ++i) {
       
   282       GValue *val;
       
   283 
       
   284       val = &g_array_index (buffers, GValue, i);
       
   285       buf = g_value_peek_pointer (val);
       
   286       fail_unless (GST_IS_BUFFER (buf));
       
   287       if (GST_BUFFER_SIZE (buf) == GST_BUFFER_SIZE (buffer)) {
       
   288         if (memcmp (GST_BUFFER_DATA (buf), GST_BUFFER_DATA (buffer),
       
   289                 GST_BUFFER_SIZE (buffer)) == 0) {
       
   290           found = TRUE;
       
   291         }
       
   292       }
       
   293     }
       
   294     fail_unless (found, "Did not find incoming IN_CAPS buffer %p on caps",
       
   295         buffer);
       
   296   }
       
   297 
       
   298   return TRUE;
       
   299 }
       
   300 
       
   301 void test_multifdsink_gdp_vorbisenc()
       
   302 {
       
   303   GstElement *p1, *p2;
       
   304   GstElement *src, *sink, *depay;
       
   305   GstPad *pad;
       
   306   GMainLoop *loop;
       
   307   int pfd[2];
       
   308 
       
   309   loop = g_main_loop_new (NULL, FALSE);
       
   310 
       
   311   p1 = gst_parse_launch ("audiotestsrc num-buffers=1 ! audioconvert "
       
   312       " ! vorbisenc ! gdppay ! multifdsink name=p1sink", NULL);
       
   313   fail_if (p1 == NULL);
       
   314   p2 = gst_parse_launch ("fdsrc name=p2src ! gdpdepay name=depay"
       
   315       " ! fakesink name=p2sink signal-handoffs=True", NULL);
       
   316   fail_if (p2 == NULL);
       
   317 
       
   318   fail_if (pipe (pfd) == -1);
       
   319 
       
   320 
       
   321   gst_element_set_state (p1, GST_STATE_READY);
       
   322 
       
   323   sink = gst_bin_get_by_name (GST_BIN (p1), "p1sink");
       
   324   g_signal_emit_by_name (sink, "add", pfd[1], NULL);
       
   325   gst_object_unref (sink);
       
   326 
       
   327   src = gst_bin_get_by_name (GST_BIN (p2), "p2src");
       
   328   g_object_set (G_OBJECT (src), "fd", pfd[0], NULL);
       
   329   gst_object_unref (src);
       
   330 
       
   331   depay = gst_bin_get_by_name (GST_BIN (p2), "depay");
       
   332   fail_if (depay == NULL);
       
   333 
       
   334   pad = gst_element_get_pad (depay, "src");
       
   335   fail_unless (pad != NULL, "Could not get pad out of depay");
       
   336   gst_object_unref (depay);
       
   337 
       
   338   gst_pad_add_event_probe (pad, G_CALLBACK (tag_event_probe_cb), loop);
       
   339   gst_pad_add_buffer_probe (pad, G_CALLBACK (buffer_probe_cb), NULL);
       
   340 
       
   341   gst_element_set_state (p1, GST_STATE_PLAYING);
       
   342   gst_element_set_state (p2, GST_STATE_PLAYING);
       
   343 
       
   344   g_main_loop_run (loop);
       
   345 
       
   346   assert_equals_int (n_in_caps, 3);
       
   347 }
       
   348 #endif
       
   349 
       
   350 
       
   351 
       
   352 #endif /* #ifndef GST_DISABLE_PARSE */
       
   353 
       
   354 /*void
       
   355 streamheader_suite (void)
       
   356 {
       
   357 test_multifdsink_gdp_tag();
       
   358 test_multifdsink_gdp_vorbisenc();
       
   359 }*/
       
   360 
       
   361 void (*fn[]) (void) = {
       
   362 test_multifdsink_gdp_tag,
       
   363 //test_multifdsink_gdp_vorbisenc    // Droping test case Because it involves "vorbisenc", which is not supported on Symbian 
       
   364 };
       
   365 
       
   366 char *args[] = {
       
   367 "test_multifdsink_gdp_tag",
       
   368 //"test_multifdsink_gdp_vorbisenc"      // Droping test case Because it involves "vorbisenc", which is not supported on Symbian 
       
   369 };
       
   370 
       
   371 GST_CHECK_MAIN (streamheader);
       
   372 
       
   373 #if 0
       
   374 int main(int argc,char** argv)
       
   375 {
       
   376 	gst_check_init(&argc,&argv);
       
   377 	test_multifdsink_gdp_tag();
       
   378 }
       
   379 #endif