1 /***************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * Copyright (C) 1998 - 2012, Daniel Stenberg, <daniel@haxx.se>, et al.
10 * This software is licensed as described in the file COPYING, which
11 * you should have received as part of this distribution. The terms
12 * are also available at http://curl.haxx.se/docs/copyright.html.
14 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15 * copies of the Software, and permit persons to whom the Software is
16 * furnished to do so, under the terms of the COPYING file.
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
21 ***************************************************************************/
24 #ifdef HAVE_NETINET_IN_H
25 # include <netinet/in.h>
30 #ifdef HAVE_ARPA_INET_H
31 # include <arpa/inet.h>
33 #ifdef HAVE_SYS_STAT_H
34 # include <sys/stat.h>
40 #include <curl/mprintf.h>
45 #define RTP_PKT_CHANNEL(p) ((int)((unsigned char)((p)[1])))
47 #define RTP_PKT_LENGTH(p) ((((int)((unsigned char)((p)[2]))) << 8) | \
48 ((int)((unsigned char)((p)[3]))))
50 #define RTP_DATA_SIZE 12
51 static const char *RTP_DATA = "$_1234\n\0asdf";
53 static int rtp_packet_count = 0;
55 static size_t rtp_write(void *ptr, size_t size, size_t nmemb, void *stream) {
56 char *data = (char *)ptr;
57 int channel = RTP_PKT_CHANNEL(data);
59 int coded_size = RTP_PKT_LENGTH(data);
60 size_t failure = (size * nmemb) ? 0 : 1;
64 message_size = curlx_uztosi(size * nmemb) - 4;
66 printf("RTP: message size %d, channel %d\n", message_size, channel);
67 if(message_size != coded_size) {
68 printf("RTP embedded size (%d) does not match the write size (%d).\n",
69 coded_size, message_size);
74 for(i = 0; i < message_size; i+= RTP_DATA_SIZE) {
75 if(message_size - i > RTP_DATA_SIZE) {
76 if(memcmp(RTP_DATA, data + i, RTP_DATA_SIZE) != 0) {
77 printf("RTP PAYLOAD CORRUPTED [%s]\n", data + i);
81 if (memcmp(RTP_DATA, data + i, message_size - i) != 0) {
82 printf("RTP PAYLOAD END CORRUPTED (%d), [%s]\n",
83 message_size - i, data + i);
90 fprintf(stderr, "packet count is %d\n", rtp_packet_count);
95 /* build request url */
96 static char *suburl(const char *base, int i)
98 return curl_maprintf("%s%.4d", base, i);
105 char *stream_uri = NULL;
107 FILE *protofile = NULL;
109 protofile = fopen(libtest_arg2, "wb");
110 if(protofile == NULL) {
111 fprintf(stderr, "Couldn't open the protocol dump file\n");
112 return TEST_ERR_MAJOR_BAD;
115 if (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
116 fprintf(stderr, "curl_global_init() failed\n");
118 return TEST_ERR_MAJOR_BAD;
121 if ((curl = curl_easy_init()) == NULL) {
122 fprintf(stderr, "curl_easy_init() failed\n");
124 curl_global_cleanup();
125 return TEST_ERR_MAJOR_BAD;
127 test_setopt(curl, CURLOPT_URL, URL);
129 if((stream_uri = suburl(URL, request++)) == NULL) {
130 res = TEST_ERR_MAJOR_BAD;
133 test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri);
137 test_setopt(curl, CURLOPT_INTERLEAVEFUNCTION, rtp_write);
138 test_setopt(curl, CURLOPT_TIMEOUT, 3);
139 test_setopt(curl, CURLOPT_VERBOSE, 1L);
140 test_setopt(curl, CURLOPT_WRITEDATA, protofile);
142 test_setopt(curl, CURLOPT_RTSP_TRANSPORT, "RTP/AVP/TCP;interleaved=0-1");
143 test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_SETUP);
145 res = curl_easy_perform(curl);
149 /* This PLAY starts the interleave */
150 if((stream_uri = suburl(URL, request++)) == NULL) {
151 res = TEST_ERR_MAJOR_BAD;
154 test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri);
157 test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_PLAY);
159 res = curl_easy_perform(curl);
163 /* The DESCRIBE request will try to consume data after the Content */
164 if((stream_uri = suburl(URL, request++)) == NULL) {
165 res = TEST_ERR_MAJOR_BAD;
168 test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri);
171 test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_DESCRIBE);
173 res = curl_easy_perform(curl);
177 if((stream_uri = suburl(URL, request++)) == NULL) {
178 res = TEST_ERR_MAJOR_BAD;
181 test_setopt(curl, CURLOPT_RTSP_STREAM_URI, stream_uri);
184 test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_PLAY);
186 res = curl_easy_perform(curl);
190 fprintf(stderr, "PLAY COMPLETE\n");
192 /* Use Receive to get the rest of the data */
193 while(!res && rtp_packet_count < 13) {
194 fprintf(stderr, "LOOPY LOOP!\n");
195 test_setopt(curl, CURLOPT_RTSP_REQUEST, CURL_RTSPREQ_RECEIVE);
196 res = curl_easy_perform(curl);
207 curl_easy_cleanup(curl);
208 curl_global_cleanup();