gst_plugins_base/tsrc/check/libs/rtp/src/rtp.c
branchRCL_3
changeset 30 7e817e7e631c
parent 29 567bb019e3e3
equal deleted inserted replaced
29:567bb019e3e3 30:7e817e7e631c
    26 #include <gst/check/gstcheck.h>
    26 #include <gst/check/gstcheck.h>
    27 #include <glib_global.h>
    27 #include <glib_global.h>
    28 
    28 
    29 
    29 
    30 
    30 
    31 #define LOG_FILE "c:\\logs\\gstrtp_logs.txt" 
    31 #define LOG_FILE "c:\\logs\\gstpad_logs.txt" 
    32 #include "std_log_result.h" 
    32 #include "std_log_result.h" 
    33 #define LOG_FILENAME_LINE __FILE__, __LINE__
    33 #define LOG_FILENAME_LINE __FILE__, __LINE__
    34 
    34 
    35 
    35 
    36 void create_xml(int result)
    36 void create_xml(int result)
    37 {
    37 {
    38 
       
    39     if(result)
    38     if(result)
    40     {
       
    41         assert_failed = 1;
    39         assert_failed = 1;
    42     } 
    40     
    43 
       
    44     testResultXml(xmlfile);
    41     testResultXml(xmlfile);
    45     close_log_file();
    42     close_log_file();
    46 
       
    47     if(result)
       
    48     {
       
    49         exit (-1);
       
    50     }    
       
    51 
       
    52 }
    43 }
    53 
    44 
    54 #include "libgstreamer_wsd_solution.h" 
    45 #include "libgstreamer_wsd_solution.h" 
    55 
    46 
    56 #include <gst/rtp/gstrtpbuffer.h>
    47 #include <gst/rtp/gstrtpbuffer.h>
    57 #include <gst/rtp/gstrtcpbuffer.h>
       
    58 #include <string.h>
    48 #include <string.h>
    59 
    49 
    60 #if EMULATOR
    50 #if EMULATOR
    61 static GET_GLOBAL_VAR_FROM_TLS(raised_critical,gstcheck,gboolean)
    51 static GET_GLOBAL_VAR_FROM_TLS(raised_critical,gstcheck,gboolean)
    62 #define _gst_check_raised_critical (*GET_GSTREAMER_WSD_VAR_NAME(raised_critical,gstcheck,g)())
    52 #define _gst_check_raised_critical (*GET_GSTREAMER_WSD_VAR_NAME(raised_critical,gstcheck,g)())
    63 #else 
    53 #else 
    64 IMPORT_C extern gboolean _gst_check_raised_critical;
    54 extern gboolean _gst_check_raised_critical;
    65 #endif
       
    66 
       
    67 #if EMULATOR
       
    68 static GET_GLOBAL_VAR_FROM_TLS(raised_warning,gstcheck,gboolean)
       
    69 #define _gst_check_raised_warning (*GET_GSTREAMER_WSD_VAR_NAME(raised_warning,gstcheck,g)())
       
    70 #else 
       
    71 IMPORT_C extern gboolean _gst_check_raised_warning;
       
    72 #endif
    55 #endif
    73 
    56 
    74 #if EMULATOR
    57 #if EMULATOR
    75 static GET_GLOBAL_VAR_FROM_TLS(expecting_log,gstcheck,gboolean)
    58 static GET_GLOBAL_VAR_FROM_TLS(expecting_log,gstcheck,gboolean)
    76 #define _gst_check_expecting_log (*GET_GSTREAMER_WSD_VAR_NAME(expecting_log,gstcheck,g)())
    59 #define _gst_check_expecting_log (*GET_GSTREAMER_WSD_VAR_NAME(expecting_log,gstcheck,g)())
    77 #else 
    60 #else 
    78 IMPORT_C extern gboolean _gst_check_expecting_log;
    61 extern gboolean _gst_check_expecting_log;
    79 #endif
    62 #endif
    80 
    63 
    81 
    64 
    82 #define RTP_HEADER_LEN 12
    65 #define RTP_HEADER_LEN 12
    83 
    66 
   202   /* check GstRTPHeader structure alignment and packing */
   185   /* check GstRTPHeader structure alignment and packing */
   203   buf = (GstBuffer *) gst_rtp_buffer_new_allocate ((guint)4, (guint8)0, (guint8)0);
   186   buf = (GstBuffer *) gst_rtp_buffer_new_allocate ((guint)4, (guint8)0, (guint8)0);
   204   data = GST_BUFFER_DATA (buf);
   187   data = GST_BUFFER_DATA (buf);
   205 
   188 
   206   /* should be impossible to set the extension data */
   189   /* should be impossible to set the extension data */
   207   ASSERT_WARNING (fail_unless (gst_rtp_buffer_set_extension_data (buf, 0, 4) == FALSE));
   190   fail_unless (gst_rtp_buffer_set_extension_data (buf, 0, 4) == FALSE);
   208   fail_unless (gst_rtp_buffer_get_extension (buf) == FALSE);
   191   fail_unless (gst_rtp_buffer_get_extension (buf) == TRUE);
   209 
   192 
   210   /* should be possible to set the extension data */
   193   /* should be possible to set the extension data */
   211   fail_unless (gst_rtp_buffer_set_extension_data (buf, 270, 0) == TRUE);
   194   fail_unless (gst_rtp_buffer_set_extension_data (buf, 270, 0) == TRUE);
   212   fail_unless (gst_rtp_buffer_get_extension (buf) == TRUE);
   195   fail_unless (gst_rtp_buffer_get_extension (buf) == TRUE);
   213   gst_rtp_buffer_get_extension_data (buf, &bits, &pointer, &size);
   196   gst_rtp_buffer_get_extension_data (buf, &bits, &pointer, &size);
   232   gst_buffer_unref (buf);
   215   gst_buffer_unref (buf);
   233     std_log(LOG_FILENAME_LINE, "Test Successful");
   216     std_log(LOG_FILENAME_LINE, "Test Successful");
   234       create_xml(0);
   217       create_xml(0);
   235 }
   218 }
   236 
   219 
   237 void test_rtp_seqnum_compare()
   220 
   238 {
   221 
   239     xmlfile = "test_rtp_seqnum_compare";
   222 void
   240     std_log(LOG_FILENAME_LINE, "Test Started test_rtp_seqnum_compare");
   223 rtp_suite (void)
   241     
   224 {
   242 #define ASSERT_COMP(a,b,c) fail_unless (gst_rtp_buffer_compare_seqnum ((guint16)a,(guint16)b) == c);
   225 test_rtp_buffer();
   243   ASSERT_COMP (0xfffe, 0xfffd, -1);
   226 test_rtp_buffer_set_extension_data();
   244   ASSERT_COMP (0xffff, 0xfffe, -1);
   227 }
   245   ASSERT_COMP (0x0000, 0xffff, -1);
       
   246   ASSERT_COMP (0x0001, 0x0000, -1);
       
   247   ASSERT_COMP (0x0002, 0x0001, -1);
       
   248 
       
   249   ASSERT_COMP (0xffff, 0xfffd, -2);
       
   250   ASSERT_COMP (0x0000, 0xfffd, -3);
       
   251   ASSERT_COMP (0x0001, 0xfffd, -4);
       
   252   ASSERT_COMP (0x0002, 0xfffd, -5);
       
   253 
       
   254   ASSERT_COMP (0x7ffe, 0x7ffd, -1);
       
   255   ASSERT_COMP (0x7fff, 0x7ffe, -1);
       
   256   ASSERT_COMP (0x8000, 0x7fff, -1);
       
   257   ASSERT_COMP (0x8001, 0x8000, -1);
       
   258   ASSERT_COMP (0x8002, 0x8001, -1);
       
   259 
       
   260   ASSERT_COMP (0x7fff, 0x7ffd, -2);
       
   261   ASSERT_COMP (0x8000, 0x7ffd, -3);
       
   262   ASSERT_COMP (0x8001, 0x7ffd, -4);
       
   263   ASSERT_COMP (0x8002, 0x7ffd, -5);
       
   264 
       
   265   ASSERT_COMP (0x7ffd, 0xffff, -0x7ffe);
       
   266   ASSERT_COMP (0x7ffe, 0x0000, -0x7ffe);
       
   267   ASSERT_COMP (0x7fff, 0x0001, -0x7ffe);
       
   268   ASSERT_COMP (0x7fff, 0x0000, -0x7fff);
       
   269   ASSERT_COMP (0x8000, 0x0001, -0x7fff);
       
   270   ASSERT_COMP (0x8001, 0x0002, -0x7fff);
       
   271 
       
   272   ASSERT_COMP (0xfffd, 0x7ffe, -0x7fff);
       
   273   ASSERT_COMP (0xfffe, 0x7fff, -0x7fff);
       
   274   ASSERT_COMP (0xffff, 0x8000, -0x7fff);
       
   275   ASSERT_COMP (0x0000, 0x8001, -0x7fff);
       
   276   ASSERT_COMP (0x0001, 0x8002, -0x7fff);
       
   277 
       
   278   ASSERT_COMP (0xfffe, 0x7ffe, -0x8000);
       
   279   ASSERT_COMP (0xffff, 0x7fff, -0x8000);
       
   280   ASSERT_COMP (0x0000, 0x8000, -0x8000);
       
   281   ASSERT_COMP (0x0001, 0x8001, -0x8000);
       
   282 
       
   283   ASSERT_COMP (0x7ffe, 0xfffe, -0x8000);
       
   284   ASSERT_COMP (0x7fff, 0xffff, -0x8000);
       
   285   ASSERT_COMP (0x8000, 0x0000, -0x8000);
       
   286   ASSERT_COMP (0x8001, 0x0001, -0x8000);
       
   287 
       
   288   ASSERT_COMP (0x0001, 0x0002, 1);
       
   289   ASSERT_COMP (0x0000, 0x0001, 1);
       
   290   ASSERT_COMP (0xffff, 0x0000, 1);
       
   291   ASSERT_COMP (0xfffe, 0xffff, 1);
       
   292   ASSERT_COMP (0xfffd, 0xfffe, 1);
       
   293 
       
   294   ASSERT_COMP (0x0000, 0x0002, 2);
       
   295   ASSERT_COMP (0xffff, 0x0002, 3);
       
   296   ASSERT_COMP (0xfffe, 0x0002, 4);
       
   297   ASSERT_COMP (0xfffd, 0x0002, 5);
       
   298 
       
   299   ASSERT_COMP (0x8001, 0x8002, 1);
       
   300   ASSERT_COMP (0x8000, 0x8001, 1);
       
   301   ASSERT_COMP (0x7fff, 0x8000, 1);
       
   302   ASSERT_COMP (0x7ffe, 0x7fff, 1);
       
   303   ASSERT_COMP (0x7ffd, 0x7ffe, 1);
       
   304 
       
   305   ASSERT_COMP (0x8000, 0x8002, 2);
       
   306   ASSERT_COMP (0x7fff, 0x8002, 3);
       
   307   ASSERT_COMP (0x7ffe, 0x8002, 4);
       
   308   ASSERT_COMP (0x7ffd, 0x8002, 5);
       
   309 
       
   310   ASSERT_COMP (0xfffe, 0x7ffd, 0x7fff);
       
   311   ASSERT_COMP (0xffff, 0x7ffe, 0x7fff);
       
   312   ASSERT_COMP (0x0000, 0x7fff, 0x7fff);
       
   313   ASSERT_COMP (0x0001, 0x8000, 0x7fff);
       
   314   ASSERT_COMP (0x0002, 0x8001, 0x7fff);
       
   315 
       
   316   ASSERT_COMP (0x7ffe, 0xfffd, 0x7fff);
       
   317   ASSERT_COMP (0x7fff, 0xfffe, 0x7fff);
       
   318   ASSERT_COMP (0x8000, 0xffff, 0x7fff);
       
   319   ASSERT_COMP (0x8001, 0x0000, 0x7fff);
       
   320   ASSERT_COMP (0x8002, 0x0001, 0x7fff);
       
   321 #undef ASSERT_COMP
       
   322   
       
   323   std_log(LOG_FILENAME_LINE, "Test Successful");
       
   324     create_xml(0);
       
   325 }
       
   326 
       
   327 
       
   328 void test_rtcp_buffer()
       
   329 {
       
   330   GstBuffer *buf;
       
   331   GstRTCPPacket packet;
       
   332   guint8 *data;
       
   333   
       
   334   xmlfile = "test_rtcp_buffer";
       
   335   std_log(LOG_FILENAME_LINE, "Test Started test_rtcp_buffer");
       
   336 
       
   337   buf = gst_rtcp_buffer_new (1400);
       
   338   fail_unless (buf != NULL);
       
   339   fail_unless_equals_int (GST_BUFFER_SIZE (buf), 1400);
       
   340   data = GST_BUFFER_DATA (buf);
       
   341 
       
   342   fail_unless (gst_rtcp_buffer_get_first_packet (buf, &packet) == FALSE);
       
   343   fail_unless (gst_rtcp_buffer_get_packet_count (buf) == 0);
       
   344   fail_unless (gst_rtcp_buffer_validate (buf) == FALSE);
       
   345 
       
   346   /* add an SR packet */
       
   347   fail_unless (gst_rtcp_buffer_add_packet (buf, GST_RTCP_TYPE_SR,
       
   348           &packet) == TRUE);
       
   349 
       
   350   fail_unless (gst_rtcp_packet_get_padding (&packet) == 0);
       
   351   fail_unless (gst_rtcp_packet_get_count (&packet) == 0);
       
   352   fail_unless (gst_rtcp_packet_get_type (&packet) == GST_RTCP_TYPE_SR);
       
   353   fail_unless (gst_rtcp_packet_get_length (&packet) == 6);
       
   354 
       
   355   gst_rtcp_packet_sr_set_sender_info (&packet, 0x44556677,
       
   356       G_GUINT64_CONSTANT (1), 0x11111111, 101, 123456);
       
   357   {
       
   358     guint32 ssrc;
       
   359     guint64 ntptime;
       
   360     guint32 rtptime;
       
   361     guint32 packet_count;
       
   362     guint32 octet_count;
       
   363 
       
   364     gst_rtcp_packet_sr_get_sender_info (&packet, &ssrc, &ntptime, &rtptime,
       
   365         &packet_count, &octet_count);
       
   366 
       
   367     fail_unless (ssrc == 0x44556677);
       
   368     fail_unless (ntptime == G_GUINT64_CONSTANT (1));
       
   369     fail_unless (rtptime == 0x11111111);
       
   370     fail_unless (packet_count == 101);
       
   371     fail_unless (octet_count == 123456);
       
   372   }
       
   373 
       
   374   /* go to first packet, this should be the packet we just added */
       
   375   fail_unless (gst_rtcp_buffer_get_first_packet (buf, &packet) == TRUE);
       
   376 
       
   377   fail_unless (gst_rtcp_packet_get_padding (&packet) == 0);
       
   378   fail_unless (gst_rtcp_packet_get_count (&packet) == 0);
       
   379   fail_unless (gst_rtcp_packet_get_type (&packet) == GST_RTCP_TYPE_SR);
       
   380   fail_unless (gst_rtcp_packet_get_length (&packet) == 6);
       
   381 
       
   382   fail_unless (gst_rtcp_packet_move_to_next (&packet) == FALSE);
       
   383 
       
   384   /* add some SDES */
       
   385   fail_unless (gst_rtcp_buffer_add_packet (buf, GST_RTCP_TYPE_SDES,
       
   386           &packet) == TRUE);
       
   387   fail_unless (gst_rtcp_packet_sdes_add_item (&packet, 0xff658743) == TRUE);
       
   388   fail_unless (gst_rtcp_packet_sdes_add_entry (&packet, GST_RTCP_SDES_CNAME,
       
   389           sizeof ("test@foo.bar"), (guint8 *) "test@foo.bar") == TRUE);
       
   390 
       
   391   /* add some BYE */
       
   392   fail_unless (gst_rtcp_buffer_add_packet (buf, GST_RTCP_TYPE_BYE,
       
   393           &packet) == TRUE);
       
   394   fail_unless (gst_rtcp_packet_bye_add_ssrc (&packet, 0x5613212f) == TRUE);
       
   395   fail_unless (gst_rtcp_packet_bye_add_ssrc (&packet, 0x00112233) == TRUE);
       
   396   fail_unless (gst_rtcp_packet_bye_get_ssrc_count (&packet) == 2);
       
   397 
       
   398   fail_unless (gst_rtcp_packet_get_padding (&packet) == 0);
       
   399   fail_unless (gst_rtcp_packet_get_count (&packet) == 2);
       
   400   fail_unless (gst_rtcp_packet_get_type (&packet) == GST_RTCP_TYPE_BYE);
       
   401   fail_unless (gst_rtcp_packet_get_length (&packet) == 2);
       
   402 
       
   403   /* move to SDES */
       
   404   fail_unless (gst_rtcp_buffer_get_first_packet (buf, &packet) == TRUE);
       
   405   fail_unless (gst_rtcp_packet_move_to_next (&packet) == TRUE);
       
   406 
       
   407   fail_unless (gst_rtcp_packet_get_padding (&packet) == 0);
       
   408   fail_unless (gst_rtcp_packet_get_count (&packet) == 1);
       
   409   fail_unless (gst_rtcp_packet_get_type (&packet) == GST_RTCP_TYPE_SDES);
       
   410   fail_unless (gst_rtcp_packet_get_length (&packet) == 5);
       
   411 
       
   412   /* remove the SDES */
       
   413   fail_unless (gst_rtcp_packet_remove (&packet) == TRUE);
       
   414 
       
   415   /* we are now at the BYE packet */
       
   416   fail_unless (gst_rtcp_packet_get_padding (&packet) == 0);
       
   417   fail_unless (gst_rtcp_packet_get_count (&packet) == 2);
       
   418   fail_unless (gst_rtcp_packet_get_type (&packet) == GST_RTCP_TYPE_BYE);
       
   419   fail_unless (gst_rtcp_packet_get_length (&packet) == 2);
       
   420 
       
   421   /* close and validate */
       
   422   gst_rtcp_buffer_end (buf);
       
   423   fail_unless (gst_rtcp_buffer_validate (buf) == TRUE);
       
   424   gst_buffer_unref (buf);
       
   425   
       
   426   std_log(LOG_FILENAME_LINE, "Test Successful");
       
   427     create_xml(0);
       
   428 }
       
   429 
       
   430 void test_rtp_buffer_validate_corrupt()
       
   431 {
       
   432   GstBuffer *buf;
       
   433   guint8 corrupt_rtp_packet[58] = {
       
   434     0x90, 0x7a, 0xbf, 0x28, 0x3a, 0x8a, 0x0a, 0xf4, 0x69, 0x6b, 0x76, 0xc0,
       
   435     0x21, 0xe0, 0xe0, 0x60, 0x81, 0x10, 0x84, 0x30, 0x21, 0x52, 0x06, 0xc2,
       
   436     0xb8, 0x30, 0x10, 0x4c, 0x08, 0x62, 0x67, 0xc2, 0x6e, 0x1a, 0x53, 0x3f,
       
   437     0xaf, 0xd6, 0x1b, 0x29, 0x40, 0xe0, 0xa5, 0x83, 0x01, 0x4b, 0x04, 0x02,
       
   438     0xb0, 0x97, 0x63, 0x08, 0x10, 0x4b, 0x43, 0x85, 0x37, 0x2c
       
   439   };
       
   440 
       
   441   xmlfile = "test_rtp_buffer_validate_corrupt";
       
   442   std_log(LOG_FILENAME_LINE, "Test Started test_rtp_buffer_validate_corrupt");
       
   443   buf = gst_buffer_new ();
       
   444   GST_BUFFER_DATA (buf) = corrupt_rtp_packet;
       
   445   GST_BUFFER_SIZE (buf) = sizeof (corrupt_rtp_packet);
       
   446   fail_if (gst_rtp_buffer_validate (buf));
       
   447   gst_buffer_unref (buf);
       
   448   
       
   449   std_log(LOG_FILENAME_LINE, "Test Successful");
       
   450     create_xml(0);
       
   451 }
       
   452 
       
   453 
       
   454 void test_rtp_buffer_list()
       
   455 {
       
   456   GstBuffer *rtp_header;
       
   457   GstBuffer *rtp_payload;
       
   458   GstBufferList *list = NULL;
       
   459   GstBufferListIterator *it;
       
   460   guint i;
       
   461 
       
   462   xmlfile = "test_rtp_buffer_list";
       
   463   std_log(LOG_FILENAME_LINE, "Test Started test_rtp_buffer_list");
       
   464   
       
   465   list = gst_buffer_list_new ();
       
   466   it = gst_buffer_list_iterate (list);
       
   467 
       
   468   /* Creating a list of two RTP packages */
       
   469 
       
   470   /* Create first group to hold the rtp header and the payload */
       
   471   gst_buffer_list_iterator_add_group (it);
       
   472   rtp_header = gst_rtp_buffer_new_allocate (0, 0, 0);
       
   473   gst_buffer_list_iterator_add (it, rtp_header);
       
   474   rtp_payload = gst_buffer_new_and_alloc (42);
       
   475   gst_buffer_list_iterator_add (it, rtp_payload);
       
   476 
       
   477   /* Create second group to hold an rtp header and a payload */
       
   478   gst_buffer_list_iterator_add_group (it);
       
   479   rtp_header = gst_rtp_buffer_new_allocate (0, 0, 0);
       
   480   gst_buffer_list_iterator_add (it, rtp_header);
       
   481   rtp_payload = gst_buffer_new_and_alloc (42);
       
   482   gst_buffer_list_iterator_add (it, rtp_payload);
       
   483 
       
   484   gst_buffer_list_iterator_free (it);
       
   485 
       
   486   /* Test SEQ number */
       
   487   i = gst_rtp_buffer_list_set_seq (list, 1024);
       
   488   fail_if (1026 != i);
       
   489   fail_if (!gst_rtp_buffer_list_validate (list));
       
   490 
       
   491   /* Timestamp */
       
   492   gst_rtp_buffer_list_set_timestamp (list, 432191);
       
   493   fail_unless_equals_int (gst_rtp_buffer_list_get_timestamp (list), 432191);
       
   494 
       
   495   /* SSRC */
       
   496   gst_rtp_buffer_list_set_ssrc (list, 0xf04043C2);
       
   497   fail_unless_equals_int (gst_rtp_buffer_list_get_ssrc (list),
       
   498       (gint) 0xf04043c2);
       
   499 
       
   500   /* Payload type */
       
   501   gst_rtp_buffer_list_set_payload_type (list, 127);
       
   502   fail_unless_equals_int (gst_rtp_buffer_list_get_payload_type (list), 127);
       
   503 
       
   504   gst_buffer_list_unref (list);
       
   505   
       
   506   std_log(LOG_FILENAME_LINE, "Test Successful");
       
   507     create_xml(0);
       
   508 }
       
   509 
       
   510 
   228 
   511 void (*fn[]) (void) = {
   229 void (*fn[]) (void) = {
   512 test_rtp_buffer,
   230 test_rtp_buffer,
   513 test_rtp_buffer_set_extension_data,
   231 test_rtp_buffer_set_extension_data
   514 test_rtp_buffer_validate_corrupt,
       
   515 test_rtp_seqnum_compare,
       
   516 test_rtp_buffer_list,
       
   517 test_rtcp_buffer
       
   518 };
   232 };
   519 
   233 
   520 char *args[] = {
   234 char *args[] = {
   521 "test_rtp_buffer",
   235 "test_rtp_buffer",
   522 "test_rtp_buffer_set_extension_data",
   236 "test_rtp_buffer_set_extension_data"
   523 "test_rtp_buffer_validate_corrupt",
       
   524 "test_rtp_seqnum_compare",
       
   525 "test_rtp_buffer_list",
       
   526 "test_rtcp_buffer"
       
   527 };
   237 };
   528 
   238 
   529 GST_CHECK_MAIN (gst_rtp);
   239 GST_CHECK_MAIN (gst_rtp);
   530 
       
   531 
   240 
   532 #if 0
   241 #if 0
   533 void main()
   242 void main()
   534     {
   243     {
   535     gst_check_init (NULL, NULL);
   244     gst_check_init (NULL, NULL);