1 /*****************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
12 #ifdef HAVE_SYS_SOCKET_H
13 # include <sys/socket.h>
15 #ifdef HAVE_NETINET_IN_H
16 # include <netinet/in.h>
21 #ifdef HAVE_ARPA_INET_H
22 # include <arpa/inet.h>
24 #ifdef HAVE_SYS_STAT_H
25 # include <sys/stat.h>
31 #include <curl/mprintf.h>
35 #define RTP_PKT_CHANNEL(p) ((int)((unsigned char)((p)[1])))
37 #define RTP_PKT_LENGTH(p) ((((int)((unsigned char)((p)[2]))) << 8) | \
38 ((int)((unsigned char)((p)[3]))))
40 #define RTP_DATA_SIZE 12
41 static const char *RTP_DATA = "$_1234\n\0asdf";
43 static int rtp_packet_count = 0;
45 static size_t rtp_write(void *ptr, size_t size, size_t nmemb, void *stream) {
46 char *data = (char *)ptr;
47 int channel = RTP_PKT_CHANNEL(data);
48 int message_size = (int)(size * nmemb) - 4;
49 int coded_size = RTP_PKT_LENGTH(data);
50 size_t failure = (size * nmemb) ? 0 : 1;
54 printf("RTP: message size %d, channel %d\n", message_size, channel);
55 if(message_size != coded_size) {
56 printf("RTP embedded size (%d) does not match the write size (%d).\n",
57 coded_size, message_size);
62 for(i = 0; i < message_size; i+= RTP_DATA_SIZE) {
63 if(message_size - i > RTP_DATA_SIZE) {
64 if(memcmp(RTP_DATA, data + i, RTP_DATA_SIZE) != 0) {
65 printf("RTP PAYLOAD CORRUPTED [%s]\n", data + i);
69 if (memcmp(RTP_DATA, data + i, message_size - i) != 0) {
70 printf("RTP PAYLOAD END CORRUPTED (%d), [%s]\n",
71 message_size - i, data + i);
78 fprintf(stderr, "packet count is %d\n", rtp_packet_count);
83 /* build request url */
84 static char *suburl(const char *base, int i)
86 return curl_maprintf("%s%.4d", base, i);
93 char *stream_uri = NULL;
95 FILE *protofile = NULL;
97 protofile = fopen(libtest_arg2, "wb");
98 if(protofile == NULL) {
99 fprintf(stderr, "Couldn't open the protocol dump file\n");
100 return TEST_ERR_MAJOR_BAD;
103 if (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
104 fprintf(stderr, "curl_global_init() failed\n");
106 return TEST_ERR_MAJOR_BAD;
109 if ((curl = curl_easy_init()) == NULL) {
110 fprintf(stderr, "curl_easy_init() failed\n");
112 curl_global_cleanup();
113 return TEST_ERR_MAJOR_BAD;
115 test_setopt(curl, CURLOPT_URL, URL);
117 if((stream_uri = suburl(URL, request++)) == NULL) {
118 res = TEST_ERR_MAJOR_BAD;
121 test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri);
125 test_setopt(curl, CURLOPT_INTERLEAVEFUNCTION, rtp_write);
126 test_setopt(curl, CURLOPT_TIMEOUT, 3);
127 test_setopt(curl, CURLOPT_VERBOSE, 1L);
128 test_setopt(curl, CURLOPT_WRITEDATA, protofile);
130 test_setopt(curl, CURLOPT_RTSP_TRANSPORT, "RTP/AVP/TCP;interleaved=0-1");
131 test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_SETUP);
133 res = curl_easy_perform(curl);
137 /* This PLAY starts the interleave */
138 if((stream_uri = suburl(URL, request++)) == NULL) {
139 res = TEST_ERR_MAJOR_BAD;
142 test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri);
145 test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_PLAY);
147 res = curl_easy_perform(curl);
151 /* The DESCRIBE request will try to consume data after the Content */
152 if((stream_uri = suburl(URL, request++)) == NULL) {
153 res = TEST_ERR_MAJOR_BAD;
156 test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri);
159 test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_DESCRIBE);
161 res = curl_easy_perform(curl);
165 if((stream_uri = suburl(URL, request++)) == NULL) {
166 res = TEST_ERR_MAJOR_BAD;
169 test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri);
172 test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_PLAY);
174 res = curl_easy_perform(curl);
178 fprintf(stderr, "PLAY COMPLETE\n");
180 /* Use Receive to get the rest of the data */
181 while(!res && rtp_packet_count < 13) {
182 fprintf(stderr, "LOOPY LOOP!\n");
183 test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_RECEIVE);
184 res = curl_easy_perform(curl);
195 curl_easy_cleanup(curl);
196 curl_global_cleanup();