From: <ra...@fr...> - 2004-09-27 23:14:32
|
CVS Root: /cvs/gstreamer Module: gst-sandbox Changes by: ramon Date: Mon Sep 27 2004 16:14:28 PDT Log message: More work on the test case (still fails) Modified files: rtpdec/test : test_mp3_rtp.c Links: http://freedesktop.org/cgi-bin/viewcvs.cgi/gstreamer/gst-sandbox/rtpdec/test/test_mp3_rtp.c.diff?r1=1.3&r2=1.4 ====Begin Diffs==== Index: test_mp3_rtp.c =================================================================== RCS file: /cvs/gstreamer/gst-sandbox/rtpdec/test/test_mp3_rtp.c,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- test_mp3_rtp.c 25 Sep 2004 22:59:03 -0000 1.3 +++ test_mp3_rtp.c 27 Sep 2004 23:14:16 -0000 1.4 @@ -14,6 +14,8 @@ static GList* get_replay(FILE *fs); +static void read_session(const GList* string_list, GString** session); + static void read_ports_from_response(const GList* replay, guint* data_port, guint* control_port); static void free_string_list(GList* string_list); @@ -64,6 +66,7 @@ FILE* fs; GList* replay; int error; + GString* session; s = socket(AF_INET, SOCK_STREAM, 0); error = connect(s, (struct sockaddr*) &(struct sockaddr_in) { .sin_family = AF_INET, @@ -77,12 +80,25 @@ return; } fs = fdopen(s, "r+"); - setbuf(fs, NULL); - char message[] = "SETUP rtsp://localhost:1554 RTSP/1.0\r\nCSeq: 1\r\n" + setvbuf(fs, NULL, _IONBF, 0); + char options_message[] = "OPTIONS rtps://localhost:1554 RTSP/1.0\r\n" + "CSeq: 1\r\n" + "Pragma: initiate-session\r\n\r\n"; + fwrite(options_message, 1, sizeof(options_message) - 1, fs); + replay = get_replay(fs); + read_session(replay, &session); + char setup_message_fmt[] = "SETUP rtsp://localhost:1554 RTSP/1.0\r\nCSeq: 1\r\n" "User-Agent: GSTreamer\r\n" "transport: RTP/AVP;unicast;client_port:5010-5011;mode=play\r\n" - "Session: 193411\r\n\r\n"; - fwrite(message, 1, sizeof(message), fs); + "Session: %s\r\n\r\n"; + GString* setup_message; + setup_message = g_string_new(0); + g_string_printf(setup_message, setup_message_fmt, session->str); + fwrite(setup_message->str, 1, setup_message->len, fs); + fflush(fs); + g_string_free(setup_message, TRUE); + free_string_list(replay); replay = get_replay(fs); read_ports_from_response(replay, data_port, control_port); free_string_list(replay); @@ -104,6 +120,7 @@ while(1) { line = NULL; num_read = getline(&line, &foo, fs); + num_read -= 2; /* remove \r\n */ if (num_read <= 1) { if (line) { free(line); @@ -122,12 +139,38 @@ return result; } +static void read_session(const GList* string_list, GString** session) +{ + *session = g_string_new(0); + const GList* element; + for (element = string_list; element != NULL; element = element->next) { + const GString* line = (GString*) element->data; + if (line->len >= sizeof("Session:") && + memcmp(line->str, "Session:", sizeof("Session:") - 1) == 0) { + char* ptr_n = line->str + sizeof("Session:") - 1; + while (ptr_n <= line->str + line->len - 1 && + *ptr_n == ' ') { + ptr_n++; + } + *ptr_n != ' ' && *ptr_n != ';') { + g_string_append_c(*session, *ptr_n); + return; + } + } + +} static void read_ports_from_response(const GList* string_list, guint* data_port, guint* control_port) { const GList* element; for (element = string_list; element != NULL; element = element->next) { const GString* line = (GString*) element->data; - if (memcmp(line->str, "Transport:", MIN(line->len, sizeof("Transport:"))) == 0) { + if (line->len >= sizeof("Transport:") - 1&& + memcmp(line->str, "Transport:", sizeof("Transport:") - 1) == 0) { /* sample line: Transport: RTP/AVP;unicast;client_port=6970-6971;server_port=23648-23649 */ const char* tp_start = strstr(line->str,": ") + 2; if (tp_start - line->str + 1 > line->len) { @@ -145,10 +188,10 @@ if (bf_next == NULL) { bf_next = line->str + line->len; } - if (bf_next - af_semicolon + 1 >= sizeof("server_port=") && - memcmp(af_semicolon, "server_port=", sizeof("server_port=")) == 0) { + if (bf_next - af_semicolon + 1 >= sizeof("server_port=") - 1 && + memcmp(af_semicolon, "server_port=", sizeof("server_port=") - 1) == 0) { const char* minus = strchr(af_semicolon,'-'); - *data_port = atoi(af_semicolon + sizeof("server_port=")); + *data_port = atoi(af_semicolon + sizeof("server_port=") - 1); *control_port = atoi(minus + 1); } @@ -169,9 +212,9 @@ slab = l; while (slab != NULL) { next = slab->next; - GString* s = (GString*) l->data; + GString* s = (GString*) slab->data; g_string_free(s, TRUE); - g_free(slab); + g_list_free_1(slab); slab = next; } |