lib571.c
Go to the documentation of this file.
00001 /***************************************************************************
00002  *                                  _   _ ____  _
00003  *  Project                     ___| | | |  _ \| |
00004  *                             / __| | | | |_) | |
00005  *                            | (__| |_| |  _ <| |___
00006  *                             \___|\___/|_| \_\_____|
00007  *
00008  * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
00009  *
00010  * This software is licensed as described in the file COPYING, which
00011  * you should have received as part of this distribution. The terms
00012  * are also available at https://curl.haxx.se/docs/copyright.html.
00013  *
00014  * You may opt to use, copy, modify, merge, publish, distribute and/or sell
00015  * copies of the Software, and permit persons to whom the Software is
00016  * furnished to do so, under the terms of the COPYING file.
00017  *
00018  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
00019  * KIND, either express or implied.
00020  *
00021  ***************************************************************************/
00022 #include "test.h"
00023 
00024 #ifdef HAVE_NETINET_IN_H
00025 #  include <netinet/in.h>
00026 #endif
00027 #ifdef HAVE_NETDB_H
00028 #  include <netdb.h>
00029 #endif
00030 #ifdef HAVE_ARPA_INET_H
00031 #  include <arpa/inet.h>
00032 #endif
00033 #ifdef HAVE_SYS_STAT_H
00034 #  include <sys/stat.h>
00035 #endif
00036 #ifdef HAVE_FCNTL_H
00037 #  include <fcntl.h>
00038 #endif
00039 
00040 #include "warnless.h"
00041 #include "memdebug.h"
00042 
00043 #define RTP_PKT_CHANNEL(p)   ((int)((unsigned char)((p)[1])))
00044 
00045 #define RTP_PKT_LENGTH(p)  ((((int)((unsigned char)((p)[2]))) << 8) | \
00046                              ((int)((unsigned char)((p)[3]))))
00047 
00048 #define RTP_DATA_SIZE 12
00049 static const char *RTP_DATA = "$_1234\n\0asdf";
00050 
00051 static int rtp_packet_count = 0;
00052 
00053 static size_t rtp_write(void *ptr, size_t size, size_t nmemb, void *stream)
00054 {
00055   char *data = (char *)ptr;
00056   int channel = RTP_PKT_CHANNEL(data);
00057   int message_size;
00058   int coded_size = RTP_PKT_LENGTH(data);
00059   size_t failure = (size * nmemb) ? 0 : 1;
00060   int i;
00061   (void)stream;
00062 
00063   message_size = curlx_uztosi(size * nmemb) - 4;
00064 
00065   printf("RTP: message size %d, channel %d\n", message_size, channel);
00066   if(message_size != coded_size) {
00067     printf("RTP embedded size (%d) does not match the write size (%d).\n",
00068            coded_size, message_size);
00069     return failure;
00070   }
00071 
00072   data += 4;
00073   for(i = 0; i < message_size; i+= RTP_DATA_SIZE) {
00074     if(message_size - i > RTP_DATA_SIZE) {
00075       if(memcmp(RTP_DATA, data + i, RTP_DATA_SIZE) != 0) {
00076         printf("RTP PAYLOAD CORRUPTED [%s]\n", data + i);
00077         return failure;
00078       }
00079     }
00080     else {
00081       if(memcmp(RTP_DATA, data + i, message_size - i) != 0) {
00082         printf("RTP PAYLOAD END CORRUPTED (%d), [%s]\n",
00083                message_size - i, data + i);
00084         return failure;
00085       }
00086     }
00087   }
00088 
00089   rtp_packet_count++;
00090   fprintf(stderr, "packet count is %d\n", rtp_packet_count);
00091 
00092   return size * nmemb;
00093 }
00094 
00095 /* build request url */
00096 static char *suburl(const char *base, int i)
00097 {
00098   return curl_maprintf("%s%.4d", base, i);
00099 }
00100 
00101 int test(char *URL)
00102 {
00103   int res;
00104   CURL *curl;
00105   char *stream_uri = NULL;
00106   int request=1;
00107   FILE *protofile = NULL;
00108 
00109   protofile = fopen(libtest_arg2, "wb");
00110   if(protofile == NULL) {
00111     fprintf(stderr, "Couldn't open the protocol dump file\n");
00112     return TEST_ERR_MAJOR_BAD;
00113   }
00114 
00115   if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
00116     fprintf(stderr, "curl_global_init() failed\n");
00117     fclose(protofile);
00118     return TEST_ERR_MAJOR_BAD;
00119   }
00120 
00121   curl = curl_easy_init();
00122   if(!curl) {
00123     fprintf(stderr, "curl_easy_init() failed\n");
00124     fclose(protofile);
00125     curl_global_cleanup();
00126     return TEST_ERR_MAJOR_BAD;
00127   }
00128   test_setopt(curl, CURLOPT_URL, URL);
00129 
00130   stream_uri = suburl(URL, request++);
00131   if(!stream_uri) {
00132     res = TEST_ERR_MAJOR_BAD;
00133     goto test_cleanup;
00134   }
00135   test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri);
00136   free(stream_uri);
00137   stream_uri = NULL;
00138 
00139   test_setopt(curl, CURLOPT_INTERLEAVEFUNCTION, rtp_write);
00140   test_setopt(curl, CURLOPT_TIMEOUT, 3L);
00141   test_setopt(curl, CURLOPT_VERBOSE, 1L);
00142   test_setopt(curl, CURLOPT_WRITEDATA, protofile);
00143 
00144   test_setopt(curl, CURLOPT_RTSP_TRANSPORT, "RTP/AVP/TCP;interleaved=0-1");
00145   test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_SETUP);
00146 
00147   res = curl_easy_perform(curl);
00148   if(res)
00149     goto test_cleanup;
00150 
00151   /* This PLAY starts the interleave */
00152   stream_uri = suburl(URL, request++);
00153   if(!stream_uri) {
00154     res = TEST_ERR_MAJOR_BAD;
00155     goto test_cleanup;
00156   }
00157   test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri);
00158   free(stream_uri);
00159   stream_uri = NULL;
00160   test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_PLAY);
00161 
00162   res = curl_easy_perform(curl);
00163   if(res)
00164     goto test_cleanup;
00165 
00166   /* The DESCRIBE request will try to consume data after the Content */
00167   stream_uri = suburl(URL, request++);
00168   if(!stream_uri) {
00169     res = TEST_ERR_MAJOR_BAD;
00170     goto test_cleanup;
00171   }
00172   test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri);
00173   free(stream_uri);
00174   stream_uri = NULL;
00175   test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_DESCRIBE);
00176 
00177   res = curl_easy_perform(curl);
00178   if(res)
00179     goto test_cleanup;
00180 
00181   stream_uri = suburl(URL, request++);
00182   if(!stream_uri) {
00183     res = TEST_ERR_MAJOR_BAD;
00184     goto test_cleanup;
00185   }
00186   test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri);
00187   free(stream_uri);
00188   stream_uri = NULL;
00189   test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_PLAY);
00190 
00191   res = curl_easy_perform(curl);
00192   if(res)
00193     goto test_cleanup;
00194 
00195   fprintf(stderr, "PLAY COMPLETE\n");
00196 
00197   /* Use Receive to get the rest of the data */
00198   while(!res && rtp_packet_count < 13) {
00199     fprintf(stderr, "LOOPY LOOP!\n");
00200     test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_RECEIVE);
00201     res = curl_easy_perform(curl);
00202   }
00203 
00204 test_cleanup:
00205   free(stream_uri);
00206 
00207   if(protofile)
00208     fclose(protofile);
00209 
00210   curl_easy_cleanup(curl);
00211   curl_global_cleanup();
00212 
00213   return res;
00214 }
00215 


rc_visard_driver
Author(s): Heiko Hirschmueller , Christian Emmerich , Felix Ruess
autogenerated on Thu Jun 6 2019 20:43:05