annotate libmpdemux/realrtsp/rtsp.c @ 17440:de9a36b1082c

MPLAYER_VERBOSE, new enviorment variable to control verbosity before init
author ods15
date Fri, 20 Jan 2006 20:38:46 +0000
parents 88adbc28f60b
children 492f442c11af
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9922
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
1 /*
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
2 * This file was ported to MPlayer from xine CVS rtsp.c,v 1.9 2003/04/10 02:30:48
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
3 */
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
4
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
5 /*
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
6 * Copyright (C) 2000-2002 the xine project
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
7 *
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
8 * This file is part of xine, a free video player.
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
9 *
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
10 * xine is free software; you can redistribute it and/or modify
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
11 * it under the terms of the GNU General Public License as published by
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
12 * the Free Software Foundation; either version 2 of the License, or
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
13 * (at your option) any later version.
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
14 *
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
15 * xine is distributed in the hope that it will be useful,
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
18 * GNU General Public License for more details.
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
19 *
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
20 * You should have received a copy of the GNU General Public License
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
21 * along with this program; if not, write to the Free Software
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
23 *
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
24 *
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
25 * a minimalistic implementation of rtsp protocol,
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
26 * *not* RFC 2326 compilant yet.
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
27 */
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
28
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
29 #include <unistd.h>
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
30 #include <stdio.h>
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
31 #include <assert.h>
10281
54bcbf28698a Networking support under MinGW.
diego
parents: 10206
diff changeset
32 #include "config.h"
54bcbf28698a Networking support under MinGW.
diego
parents: 10206
diff changeset
33 #ifndef HAVE_WINSOCK2
54bcbf28698a Networking support under MinGW.
diego
parents: 10206
diff changeset
34 #define closesocket close
9922
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
35 #include <sys/socket.h>
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
36 #include <netinet/in.h>
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
37 #include <netdb.h>
10281
54bcbf28698a Networking support under MinGW.
diego
parents: 10206
diff changeset
38 #else
54bcbf28698a Networking support under MinGW.
diego
parents: 10206
diff changeset
39 #include <winsock2.h>
54bcbf28698a Networking support under MinGW.
diego
parents: 10206
diff changeset
40 #endif
9922
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
41 #include <string.h>
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
42 #include <sys/stat.h>
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
43 #include <fcntl.h>
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
44 #include <errno.h>
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
45 #include <stdlib.h>
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
46 #include <time.h>
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
47 #include <sys/time.h>
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
48 #include <sys/types.h>
9939
6b88f67564ce Fix compilation for *BSD, Mac OS X and maybe others (info by Steven M. Schultz and Dan Christiansen)
rtognimp
parents: 9922
diff changeset
49 #include <inttypes.h>
9922
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
50
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
51 #include "rtsp.h"
15585
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15172
diff changeset
52 #include "../stream.h"
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15172
diff changeset
53 #include "../demuxer.h"
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15172
diff changeset
54 #include "rtsp_session.h"
17092
rathann
parents: 17032
diff changeset
55 #include "osdep/timer.h"
9922
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
56
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
57 /*
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
58 #define LOG
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
59 */
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
60
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
61 #define BUF_SIZE 4096
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
62 #define HEADER_SIZE 1024
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
63 #define MAX_FIELDS 256
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
64
15585
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15172
diff changeset
65 extern int network_bandwidth;
9922
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
66 struct rtsp_s {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
67
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
68 int s;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
69
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
70 char *host;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
71 int port;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
72 char *path;
11506
fff1b6f1a9cc Real rtsp Range parameter (Start and End) support.
rtognimp
parents: 11000
diff changeset
73 char *param;
9922
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
74 char *mrl;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
75 char *user_agent;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
76
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
77 char *server;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
78 unsigned int server_state;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
79 uint32_t server_caps;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
80
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
81 unsigned int cseq;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
82 char *session;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
83
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
84 char *answers[MAX_FIELDS]; /* data of last message */
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
85 char *scheduled[MAX_FIELDS]; /* will be sent with next message */
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
86 };
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
87
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
88 /*
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
89 * constants
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
90 */
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
91
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
92 const char rtsp_protocol_version[]="RTSP/1.0";
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
93
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
94 /* server states */
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
95 #define RTSP_CONNECTED 1
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
96 #define RTSP_INIT 2
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
97 #define RTSP_READY 4
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
98 #define RTSP_PLAYING 8
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
99 #define RTSP_RECORDING 16
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
100
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
101 /* server capabilities */
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
102 #define RTSP_OPTIONS 0x001
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
103 #define RTSP_DESCRIBE 0x002
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
104 #define RTSP_ANNOUNCE 0x004
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
105 #define RTSP_SETUP 0x008
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
106 #define RTSP_GET_PARAMETER 0x010
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
107 #define RTSP_SET_PARAMETER 0x020
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
108 #define RTSP_TEARDOWN 0x040
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
109 #define RTSP_PLAY 0x080
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
110 #define RTSP_RECORD 0x100
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
111
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
112 /*
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
113 * network utilities
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
114 */
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
115
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
116 static int host_connect_attempt(struct in_addr ia, int port) {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
117
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
118 int s;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
119 struct sockaddr_in sin;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
120
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
121 s = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
122 if (s == -1) {
15626
941b1a71351f printf converted to mp_msg; made static many unnecessarily global symbols
nicodvb
parents: 15585
diff changeset
123 mp_msg(MSGT_OPEN, MSGL_ERR, "rtsp: socket(): %s\n", strerror(errno));
9922
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
124 return -1;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
125 }
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
126
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
127 sin.sin_family = AF_INET;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
128 sin.sin_addr = ia;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
129 sin.sin_port = htons(port);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
130
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
131 if (connect(s, (struct sockaddr *)&sin, sizeof(sin))==-1
10281
54bcbf28698a Networking support under MinGW.
diego
parents: 10206
diff changeset
132 #ifndef HAVE_WINSOCK2
9922
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
133 && errno != EINPROGRESS) {
10281
54bcbf28698a Networking support under MinGW.
diego
parents: 10206
diff changeset
134 #else
54bcbf28698a Networking support under MinGW.
diego
parents: 10206
diff changeset
135 && WSAGetLastError() == WSAEINPROGRESS) {
54bcbf28698a Networking support under MinGW.
diego
parents: 10206
diff changeset
136 #endif
15626
941b1a71351f printf converted to mp_msg; made static many unnecessarily global symbols
nicodvb
parents: 15585
diff changeset
137 mp_msg(MSGT_OPEN, MSGL_ERR, "rtsp: connect(): %s\n", strerror(errno));
10281
54bcbf28698a Networking support under MinGW.
diego
parents: 10206
diff changeset
138 closesocket(s);
9922
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
139 return -1;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
140 }
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
141
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
142 return s;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
143 }
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
144
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
145 static int host_connect(const char *host, int port) {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
146
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
147 struct hostent *h;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
148 int i, s;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
149
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
150 h = gethostbyname(host);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
151 if (h == NULL) {
15626
941b1a71351f printf converted to mp_msg; made static many unnecessarily global symbols
nicodvb
parents: 15585
diff changeset
152 mp_msg(MSGT_OPEN, MSGL_ERR, "rtsp: unable to resolve '%s'.\n", host);
9922
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
153 return -1;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
154 }
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
155
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
156 for (i = 0; h->h_addr_list[i]; i++) {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
157 struct in_addr ia;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
158
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
159 memcpy (&ia, h->h_addr_list[i], 4);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
160 s = host_connect_attempt(ia, port);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
161 if(s != -1)
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
162 return s;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
163 }
15626
941b1a71351f printf converted to mp_msg; made static many unnecessarily global symbols
nicodvb
parents: 15585
diff changeset
164 mp_msg(MSGT_OPEN, MSGL_ERR, "rtsp: unable to connect to '%s'.\n", host);
9922
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
165 return -1;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
166 }
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
167
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
168 static int write_stream(int s, const char *buf, int len) {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
169 int total, timeout;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
170
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
171 total = 0; timeout = 30;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
172 while (total < len){
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
173 int n;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
174
10206
35e306346e59 Using recv/send instead read/write for proper MinGW support (it's a 4.2BSD standard). Patch by FloDt <flodt8@yahoo.de>
alex
parents: 9939
diff changeset
175 n = send (s, &buf[total], len - total, 0);
9922
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
176
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
177 if (n > 0)
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
178 total += n;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
179 else if (n < 0) {
10281
54bcbf28698a Networking support under MinGW.
diego
parents: 10206
diff changeset
180 #ifndef HAVE_WINSOCK2
9922
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
181 if ((timeout>0) && ((errno == EAGAIN) || (errno == EINPROGRESS))) {
10281
54bcbf28698a Networking support under MinGW.
diego
parents: 10206
diff changeset
182 #else
54bcbf28698a Networking support under MinGW.
diego
parents: 10206
diff changeset
183 if ((timeout>0) && ((errno == EAGAIN) || (WSAGetLastError() == WSAEINPROGRESS))) {
54bcbf28698a Networking support under MinGW.
diego
parents: 10206
diff changeset
184 #endif
16372
b313a38c69cb replace sleep with usec_sleep, required for recent mingw versions, patch by Robert Swain <robert.swain at gmail.com>
faust3
parents: 15797
diff changeset
185 usec_sleep (1000000); timeout--;
9922
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
186 } else
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
187 return -1;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
188 }
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
189 }
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
190
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
191 return total;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
192 }
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
193
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
194 static ssize_t read_stream(int fd, void *buf, size_t count) {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
195
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
196 ssize_t ret, total;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
197
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
198 total = 0;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
199
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
200 while (total < count) {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
201
10206
35e306346e59 Using recv/send instead read/write for proper MinGW support (it's a 4.2BSD standard). Patch by FloDt <flodt8@yahoo.de>
alex
parents: 9939
diff changeset
202 ret=recv (fd, ((uint8_t*)buf)+total, count-total, 0);
9922
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
203
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
204 if (ret<0) {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
205 if(errno == EAGAIN) {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
206 fd_set rset;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
207 struct timeval timeout;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
208
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
209 FD_ZERO (&rset);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
210 FD_SET (fd, &rset);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
211
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
212 timeout.tv_sec = 30;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
213 timeout.tv_usec = 0;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
214
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
215 if (select (fd+1, &rset, NULL, NULL, &timeout) <= 0) {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
216 return -1;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
217 }
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
218 continue;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
219 }
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
220
15626
941b1a71351f printf converted to mp_msg; made static many unnecessarily global symbols
nicodvb
parents: 15585
diff changeset
221 mp_msg(MSGT_OPEN, MSGL_ERR, "rtsp: read error.\n");
9922
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
222 return ret;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
223 } else
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
224 total += ret;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
225
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
226 /* end of stream */
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
227 if (!ret) break;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
228 }
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
229
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
230 return total;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
231 }
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
232
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
233 /*
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
234 * debugging utilities
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
235 */
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
236 #if 0
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
237 static void hexdump (char *buf, int length) {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
238
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
239 int i;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
240
15626
941b1a71351f printf converted to mp_msg; made static many unnecessarily global symbols
nicodvb
parents: 15585
diff changeset
241 mp_msg(MSGT_OPEN, MSGL_INFO, "rtsp: ascii>");
9922
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
242 for (i = 0; i < length; i++) {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
243 unsigned char c = buf[i];
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
244
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
245 if ((c >= 32) && (c <= 128))
15626
941b1a71351f printf converted to mp_msg; made static many unnecessarily global symbols
nicodvb
parents: 15585
diff changeset
246 mp_msg(MSGT_OPEN, MSGL_INFO, "%c", c);
9922
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
247 else
15626
941b1a71351f printf converted to mp_msg; made static many unnecessarily global symbols
nicodvb
parents: 15585
diff changeset
248 mp_msg(MSGT_OPEN, MSGL_INFO, ".");
9922
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
249 }
15626
941b1a71351f printf converted to mp_msg; made static many unnecessarily global symbols
nicodvb
parents: 15585
diff changeset
250 mp_msg(MSGT_OPEN, MSGL_INFO, "\n");
9922
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
251
15626
941b1a71351f printf converted to mp_msg; made static many unnecessarily global symbols
nicodvb
parents: 15585
diff changeset
252 mp_msg(MSGT_OPEN, MSGL_INFO, "rtsp: hexdump> ");
9922
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
253 for (i = 0; i < length; i++) {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
254 unsigned char c = buf[i];
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
255
15626
941b1a71351f printf converted to mp_msg; made static many unnecessarily global symbols
nicodvb
parents: 15585
diff changeset
256 mp_msg(MSGT_OPEN, MSGL_INFO, "%02x", c);
9922
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
257
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
258 if ((i % 16) == 15)
15626
941b1a71351f printf converted to mp_msg; made static many unnecessarily global symbols
nicodvb
parents: 15585
diff changeset
259 mp_msg(MSGT_OPEN, MSGL_INFO, "\nrtsp: ");
9922
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
260
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
261 if ((i % 2) == 1)
15626
941b1a71351f printf converted to mp_msg; made static many unnecessarily global symbols
nicodvb
parents: 15585
diff changeset
262 mp_msg(MSGT_OPEN, MSGL_INFO, " ");
9922
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
263
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
264 }
15626
941b1a71351f printf converted to mp_msg; made static many unnecessarily global symbols
nicodvb
parents: 15585
diff changeset
265 mp_msg(MSGT_OPEN, MSGL_INFO, "\n");
9922
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
266 }
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
267 #endif
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
268
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
269 /*
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
270 * rtsp_get gets a line from stream
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
271 * and returns a null terminated string.
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
272 */
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
273
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
274 static char *rtsp_get(rtsp_t *s) {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
275
15797
06a9914af502 fix illegal memory accesses
reimar
parents: 15626
diff changeset
276 int n=1;
12271
4adb4a3b52a2 More bounds checking fixes (thnaks to Miguel Freitas)
rtognimp
parents: 11663
diff changeset
277 char *buffer = malloc(BUF_SIZE);
4adb4a3b52a2 More bounds checking fixes (thnaks to Miguel Freitas)
rtognimp
parents: 11663
diff changeset
278 char *string = NULL;
9922
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
279
15797
06a9914af502 fix illegal memory accesses
reimar
parents: 15626
diff changeset
280 read_stream(s->s, buffer, 1);
9922
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
281 while (n<BUF_SIZE) {
12271
4adb4a3b52a2 More bounds checking fixes (thnaks to Miguel Freitas)
rtognimp
parents: 11663
diff changeset
282 read_stream(s->s, &(buffer[n]), 1);
4adb4a3b52a2 More bounds checking fixes (thnaks to Miguel Freitas)
rtognimp
parents: 11663
diff changeset
283 if ((buffer[n-1]==0x0d)&&(buffer[n]==0x0a)) break;
9922
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
284 n++;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
285 }
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
286
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
287 if (n>=BUF_SIZE) {
15626
941b1a71351f printf converted to mp_msg; made static many unnecessarily global symbols
nicodvb
parents: 15585
diff changeset
288 mp_msg(MSGT_OPEN, MSGL_FATAL, "librtsp: buffer overflow in rtsp_get\n");
9922
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
289 exit(1);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
290 }
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
291 string=malloc(sizeof(char)*n);
12271
4adb4a3b52a2 More bounds checking fixes (thnaks to Miguel Freitas)
rtognimp
parents: 11663
diff changeset
292 memcpy(string,buffer,n-1);
9922
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
293 string[n-1]=0;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
294
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
295 #ifdef LOG
15626
941b1a71351f printf converted to mp_msg; made static many unnecessarily global symbols
nicodvb
parents: 15585
diff changeset
296 mp_msg(MSGT_OPEN, MSGL_INFO, "librtsp: << '%s'\n", string);
9922
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
297 #endif
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
298
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
299
12271
4adb4a3b52a2 More bounds checking fixes (thnaks to Miguel Freitas)
rtognimp
parents: 11663
diff changeset
300 free(buffer);
9922
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
301 return string;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
302 }
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
303
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
304 /*
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
305 * rtsp_put puts a line on stream
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
306 */
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
307
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
308 static void rtsp_put(rtsp_t *s, const char *string) {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
309
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
310 int len=strlen(string);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
311 char *buf=malloc(sizeof(char)*len+2);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
312
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
313 #ifdef LOG
15626
941b1a71351f printf converted to mp_msg; made static many unnecessarily global symbols
nicodvb
parents: 15585
diff changeset
314 mp_msg(MSGT_OPEN, MSGL_INFO, "librtsp: >> '%s'", string);
9922
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
315 #endif
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
316
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
317 memcpy(buf,string,len);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
318 buf[len]=0x0d;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
319 buf[len+1]=0x0a;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
320
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
321 write_stream(s->s, buf, len+2);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
322
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
323 #ifdef LOG
15626
941b1a71351f printf converted to mp_msg; made static many unnecessarily global symbols
nicodvb
parents: 15585
diff changeset
324 mp_msg(MSGT_OPEN, MSGL_INFO, " done.\n");
9922
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
325 #endif
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
326
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
327 free(buf);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
328 }
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
329
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
330 /*
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
331 * extract server status code
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
332 */
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
333
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
334 static int rtsp_get_code(const char *string) {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
335
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
336 char buf[4];
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
337 int code=0;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
338
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
339 if (!strncmp(string, rtsp_protocol_version, strlen(rtsp_protocol_version)))
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
340 {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
341 memcpy(buf, string+strlen(rtsp_protocol_version)+1, 3);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
342 buf[3]=0;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
343 code=atoi(buf);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
344 } else if (!strncmp(string, "SET_PARAMETER",8))
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
345 {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
346 return RTSP_STATUS_SET_PARAMETER;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
347 }
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
348
15626
941b1a71351f printf converted to mp_msg; made static many unnecessarily global symbols
nicodvb
parents: 15585
diff changeset
349 if(code != 200) mp_msg(MSGT_OPEN, MSGL_INFO, "librtsp: server responds: '%s'\n",string);
9922
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
350
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
351 return code;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
352 }
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
353
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
354 /*
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
355 * send a request
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
356 */
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
357
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
358 static void rtsp_send_request(rtsp_t *s, const char *type, const char *what) {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
359
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
360 char **payload=s->scheduled;
12271
4adb4a3b52a2 More bounds checking fixes (thnaks to Miguel Freitas)
rtognimp
parents: 11663
diff changeset
361 char *buf;
4adb4a3b52a2 More bounds checking fixes (thnaks to Miguel Freitas)
rtognimp
parents: 11663
diff changeset
362
4adb4a3b52a2 More bounds checking fixes (thnaks to Miguel Freitas)
rtognimp
parents: 11663
diff changeset
363 buf = malloc(strlen(type)+strlen(what)+strlen(rtsp_protocol_version)+3);
4adb4a3b52a2 More bounds checking fixes (thnaks to Miguel Freitas)
rtognimp
parents: 11663
diff changeset
364
4adb4a3b52a2 More bounds checking fixes (thnaks to Miguel Freitas)
rtognimp
parents: 11663
diff changeset
365 sprintf(buf,"%s %s %s",type, what, rtsp_protocol_version);
4adb4a3b52a2 More bounds checking fixes (thnaks to Miguel Freitas)
rtognimp
parents: 11663
diff changeset
366 rtsp_put(s,buf);
4adb4a3b52a2 More bounds checking fixes (thnaks to Miguel Freitas)
rtognimp
parents: 11663
diff changeset
367 free(buf);
9922
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
368 if (payload)
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
369 while (*payload) {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
370 rtsp_put(s,*payload);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
371 payload++;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
372 }
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
373 rtsp_put(s,"");
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
374 rtsp_unschedule_all(s);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
375 }
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
376
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
377 /*
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
378 * schedule standard fields
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
379 */
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
380
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
381 static void rtsp_schedule_standard(rtsp_t *s) {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
382
12271
4adb4a3b52a2 More bounds checking fixes (thnaks to Miguel Freitas)
rtognimp
parents: 11663
diff changeset
383 char tmp[16];
4adb4a3b52a2 More bounds checking fixes (thnaks to Miguel Freitas)
rtognimp
parents: 11663
diff changeset
384
4adb4a3b52a2 More bounds checking fixes (thnaks to Miguel Freitas)
rtognimp
parents: 11663
diff changeset
385 snprintf(tmp, 16, "Cseq: %u", s->cseq);
4adb4a3b52a2 More bounds checking fixes (thnaks to Miguel Freitas)
rtognimp
parents: 11663
diff changeset
386 rtsp_schedule_field(s, tmp);
4adb4a3b52a2 More bounds checking fixes (thnaks to Miguel Freitas)
rtognimp
parents: 11663
diff changeset
387
9922
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
388 if (s->session) {
12271
4adb4a3b52a2 More bounds checking fixes (thnaks to Miguel Freitas)
rtognimp
parents: 11663
diff changeset
389 char *buf;
4adb4a3b52a2 More bounds checking fixes (thnaks to Miguel Freitas)
rtognimp
parents: 11663
diff changeset
390 buf = malloc(strlen(s->session)+15);
4adb4a3b52a2 More bounds checking fixes (thnaks to Miguel Freitas)
rtognimp
parents: 11663
diff changeset
391 sprintf(buf, "Session: %s", s->session);
4adb4a3b52a2 More bounds checking fixes (thnaks to Miguel Freitas)
rtognimp
parents: 11663
diff changeset
392 rtsp_schedule_field(s, buf);
4adb4a3b52a2 More bounds checking fixes (thnaks to Miguel Freitas)
rtognimp
parents: 11663
diff changeset
393 free(buf);
9922
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
394 }
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
395 }
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
396 /*
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
397 * get the answers, if server responses with something != 200, return NULL
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
398 */
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
399
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
400 static int rtsp_get_answers(rtsp_t *s) {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
401
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
402 char *answer=NULL;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
403 unsigned int answer_seq;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
404 char **answer_ptr=s->answers;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
405 int code;
15172
56541efe420b Fix potential buffer overflow if server answers with too many lines
rtognimp
parents: 13677
diff changeset
406 int ans_count = 0;
9922
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
407
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
408 answer=rtsp_get(s);
12271
4adb4a3b52a2 More bounds checking fixes (thnaks to Miguel Freitas)
rtognimp
parents: 11663
diff changeset
409 if (!answer)
4adb4a3b52a2 More bounds checking fixes (thnaks to Miguel Freitas)
rtognimp
parents: 11663
diff changeset
410 return 0;
9922
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
411 code=rtsp_get_code(answer);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
412 free(answer);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
413
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
414 rtsp_free_answers(s);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
415
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
416 do { /* while we get answer lines */
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
417
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
418 answer=rtsp_get(s);
12271
4adb4a3b52a2 More bounds checking fixes (thnaks to Miguel Freitas)
rtognimp
parents: 11663
diff changeset
419 if (!answer)
4adb4a3b52a2 More bounds checking fixes (thnaks to Miguel Freitas)
rtognimp
parents: 11663
diff changeset
420 return 0;
9922
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
421
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
422 if (!strncmp(answer,"Cseq:",5)) {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
423 sscanf(answer,"Cseq: %u",&answer_seq);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
424 if (s->cseq != answer_seq) {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
425 #ifdef LOG
15626
941b1a71351f printf converted to mp_msg; made static many unnecessarily global symbols
nicodvb
parents: 15585
diff changeset
426 mp_msg(MSGT_OPEN, MSGL_WARN, "librtsp: warning: Cseq mismatch. got %u, assumed %u", answer_seq, s->cseq);
9922
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
427 #endif
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
428 s->cseq=answer_seq;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
429 }
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
430 }
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
431 if (!strncmp(answer,"Server:",7)) {
12271
4adb4a3b52a2 More bounds checking fixes (thnaks to Miguel Freitas)
rtognimp
parents: 11663
diff changeset
432 char *buf = malloc(strlen(answer));
4adb4a3b52a2 More bounds checking fixes (thnaks to Miguel Freitas)
rtognimp
parents: 11663
diff changeset
433 sscanf(answer,"Server: %s",buf);
9922
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
434 if (s->server) free(s->server);
12271
4adb4a3b52a2 More bounds checking fixes (thnaks to Miguel Freitas)
rtognimp
parents: 11663
diff changeset
435 s->server=strdup(buf);
4adb4a3b52a2 More bounds checking fixes (thnaks to Miguel Freitas)
rtognimp
parents: 11663
diff changeset
436 free(buf);
9922
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
437 }
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
438 if (!strncmp(answer,"Session:",8)) {
12271
4adb4a3b52a2 More bounds checking fixes (thnaks to Miguel Freitas)
rtognimp
parents: 11663
diff changeset
439 char *buf = calloc(1, strlen(answer));
4adb4a3b52a2 More bounds checking fixes (thnaks to Miguel Freitas)
rtognimp
parents: 11663
diff changeset
440 sscanf(answer,"Session: %s",buf);
9922
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
441 if (s->session) {
12271
4adb4a3b52a2 More bounds checking fixes (thnaks to Miguel Freitas)
rtognimp
parents: 11663
diff changeset
442 if (strcmp(buf, s->session)) {
15626
941b1a71351f printf converted to mp_msg; made static many unnecessarily global symbols
nicodvb
parents: 15585
diff changeset
443 mp_msg(MSGT_OPEN, MSGL_WARN, "rtsp: warning: setting NEW session: %s\n", buf);
9922
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
444 free(s->session);
12271
4adb4a3b52a2 More bounds checking fixes (thnaks to Miguel Freitas)
rtognimp
parents: 11663
diff changeset
445 s->session=strdup(buf);
9922
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
446 }
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
447 } else
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
448 {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
449 #ifdef LOG
15626
941b1a71351f printf converted to mp_msg; made static many unnecessarily global symbols
nicodvb
parents: 15585
diff changeset
450 mp_msg(MSGT_OPEN, MSGL_INFO, "rtsp: setting session id to: %s\n", buf);
9922
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
451 #endif
12271
4adb4a3b52a2 More bounds checking fixes (thnaks to Miguel Freitas)
rtognimp
parents: 11663
diff changeset
452 s->session=strdup(buf);
9922
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
453 }
12271
4adb4a3b52a2 More bounds checking fixes (thnaks to Miguel Freitas)
rtognimp
parents: 11663
diff changeset
454 free(buf);
9922
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
455 }
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
456 *answer_ptr=answer;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
457 answer_ptr++;
15172
56541efe420b Fix potential buffer overflow if server answers with too many lines
rtognimp
parents: 13677
diff changeset
458 } while ((strlen(answer)!=0) && (++ans_count < MAX_FIELDS));
9922
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
459
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
460 s->cseq++;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
461
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
462 *answer_ptr=NULL;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
463 rtsp_schedule_standard(s);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
464
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
465 return code;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
466 }
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
467
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
468 /*
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
469 * send an ok message
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
470 */
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
471
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
472 int rtsp_send_ok(rtsp_t *s) {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
473 char cseq[16];
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
474
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
475 rtsp_put(s, "RTSP/1.0 200 OK");
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
476 sprintf(cseq,"CSeq: %u", s->cseq);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
477 rtsp_put(s, cseq);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
478 rtsp_put(s, "");
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
479 return 0;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
480 }
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
481
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
482 /*
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
483 * implementation of must-have rtsp requests; functions return
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
484 * server status code.
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
485 */
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
486
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
487 int rtsp_request_options(rtsp_t *s, const char *what) {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
488
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
489 char *buf;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
490
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
491 if (what) {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
492 buf=strdup(what);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
493 } else
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
494 {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
495 buf=malloc(sizeof(char)*(strlen(s->host)+16));
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
496 sprintf(buf,"rtsp://%s:%i", s->host, s->port);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
497 }
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
498 rtsp_send_request(s,"OPTIONS",buf);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
499 free(buf);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
500
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
501 return rtsp_get_answers(s);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
502 }
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
503
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
504 int rtsp_request_describe(rtsp_t *s, const char *what) {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
505
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
506 char *buf;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
507
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
508 if (what) {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
509 buf=strdup(what);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
510 } else
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
511 {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
512 buf=malloc(sizeof(char)*(strlen(s->host)+strlen(s->path)+16));
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
513 sprintf(buf,"rtsp://%s:%i/%s", s->host, s->port, s->path);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
514 }
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
515 rtsp_send_request(s,"DESCRIBE",buf);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
516 free(buf);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
517
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
518 return rtsp_get_answers(s);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
519 }
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
520
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
521 int rtsp_request_setup(rtsp_t *s, const char *what) {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
522
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
523 rtsp_send_request(s,"SETUP",what);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
524
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
525 return rtsp_get_answers(s);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
526 }
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
527
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
528 int rtsp_request_setparameter(rtsp_t *s, const char *what) {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
529
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
530 char *buf;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
531
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
532 if (what) {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
533 buf=strdup(what);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
534 } else
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
535 {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
536 buf=malloc(sizeof(char)*(strlen(s->host)+strlen(s->path)+16));
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
537 sprintf(buf,"rtsp://%s:%i/%s", s->host, s->port, s->path);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
538 }
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
539 rtsp_send_request(s,"SET_PARAMETER",buf);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
540 free(buf);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
541
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
542 return rtsp_get_answers(s);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
543 }
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
544
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
545 int rtsp_request_play(rtsp_t *s, const char *what) {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
546
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
547 char *buf;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
548
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
549 if (what) {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
550 buf=strdup(what);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
551 } else
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
552 {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
553 buf=malloc(sizeof(char)*(strlen(s->host)+strlen(s->path)+16));
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
554 sprintf(buf,"rtsp://%s:%i/%s", s->host, s->port, s->path);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
555 }
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
556 rtsp_send_request(s,"PLAY",buf);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
557 free(buf);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
558
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
559 return rtsp_get_answers(s);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
560 }
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
561
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
562 int rtsp_request_tearoff(rtsp_t *s, const char *what) {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
563
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
564 rtsp_send_request(s,"TEAROFF",what);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
565
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
566 return rtsp_get_answers(s);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
567 }
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
568
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
569 /*
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
570 * read opaque data from stream
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
571 */
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
572
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
573 int rtsp_read_data(rtsp_t *s, char *buffer, unsigned int size) {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
574
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
575 int i,seq;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
576
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
577 if (size>=4) {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
578 i=read_stream(s->s, buffer, 4);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
579 if (i<4) return i;
17032
7d0773bb1e42 Ignore OPTIONS rtsp command during playback. Fixes
rtognimp
parents: 16372
diff changeset
580 if (((buffer[0]=='S')&&(buffer[1]=='E')&&(buffer[2]=='T')&&(buffer[3]=='_')) ||
7d0773bb1e42 Ignore OPTIONS rtsp command during playback. Fixes
rtognimp
parents: 16372
diff changeset
581 ((buffer[0]=='O')&&(buffer[1]=='P')&&(buffer[2]=='T')&&(buffer[3]=='I'))) // OPTIONS
9922
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
582 {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
583 char *rest=rtsp_get(s);
12271
4adb4a3b52a2 More bounds checking fixes (thnaks to Miguel Freitas)
rtognimp
parents: 11663
diff changeset
584 if (!rest)
4adb4a3b52a2 More bounds checking fixes (thnaks to Miguel Freitas)
rtognimp
parents: 11663
diff changeset
585 return -1;
4adb4a3b52a2 More bounds checking fixes (thnaks to Miguel Freitas)
rtognimp
parents: 11663
diff changeset
586
9922
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
587 seq=-1;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
588 do {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
589 free(rest);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
590 rest=rtsp_get(s);
12271
4adb4a3b52a2 More bounds checking fixes (thnaks to Miguel Freitas)
rtognimp
parents: 11663
diff changeset
591 if (!rest)
4adb4a3b52a2 More bounds checking fixes (thnaks to Miguel Freitas)
rtognimp
parents: 11663
diff changeset
592 return -1;
9922
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
593 if (!strncmp(rest,"Cseq:",5))
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
594 sscanf(rest,"Cseq: %u",&seq);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
595 } while (strlen(rest)!=0);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
596 free(rest);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
597 if (seq<0) {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
598 #ifdef LOG
15626
941b1a71351f printf converted to mp_msg; made static many unnecessarily global symbols
nicodvb
parents: 15585
diff changeset
599 mp_msg(MSGT_OPEN, MSGL_WARN, "rtsp: warning: cseq not recognized!\n");
9922
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
600 #endif
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
601 seq=1;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
602 }
11000
6e35326c742f many small typo and grammar fixes
gabucino
parents: 10281
diff changeset
603 /* let's make the server happy */
9922
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
604 rtsp_put(s, "RTSP/1.0 451 Parameter Not Understood");
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
605 rest=malloc(sizeof(char)*16);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
606 sprintf(rest,"CSeq: %u", seq);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
607 rtsp_put(s, rest);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
608 rtsp_put(s, "");
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
609 i=read_stream(s->s, buffer, size);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
610 } else
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
611 {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
612 i=read_stream(s->s, buffer+4, size-4);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
613 i+=4;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
614 }
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
615 } else
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
616 i=read_stream(s->s, buffer, size);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
617 #ifdef LOG
15626
941b1a71351f printf converted to mp_msg; made static many unnecessarily global symbols
nicodvb
parents: 15585
diff changeset
618 mp_msg(MSGT_OPEN, MSGL_INFO, "librtsp: << %d of %d bytes\n", i, size);
9922
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
619 #endif
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
620
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
621 return i;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
622 }
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
623
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
624 /*
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
625 * connect to a rtsp server
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
626 */
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
627
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
628 //rtsp_t *rtsp_connect(const char *mrl, const char *user_agent) {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
629 rtsp_t *rtsp_connect(int fd, char* mrl, char *path, char *host, int port, char *user_agent) {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
630
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
631 rtsp_t *s=malloc(sizeof(rtsp_t));
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
632 int i;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
633
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
634 for (i=0; i<MAX_FIELDS; i++) {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
635 s->answers[i]=NULL;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
636 s->scheduled[i]=NULL;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
637 }
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
638
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
639 s->server=NULL;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
640 s->server_state=0;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
641 s->server_caps=0;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
642
12678
9cdff452833b cseq starts from 1 according to the standard, patch by Yoshinori Sato
alex
parents: 12271
diff changeset
643 s->cseq=1;
9922
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
644 s->session=NULL;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
645
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
646 if (user_agent)
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
647 s->user_agent=strdup(user_agent);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
648 else
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
649 s->user_agent=strdup("User-Agent: RealMedia Player Version 6.0.9.1235 (linux-2.0-libc6-i386-gcc2.95)");
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
650
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
651 s->mrl = strdup(mrl);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
652 s->host = strdup(host);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
653 s->port = port;
11663
d700a93ab34c 10l let path behave like before the start/stop patch
rtognimp
parents: 11506
diff changeset
654 s->path = strdup(path);
11506
fff1b6f1a9cc Real rtsp Range parameter (Start and End) support.
rtognimp
parents: 11000
diff changeset
655 while (*path == '/')
fff1b6f1a9cc Real rtsp Range parameter (Start and End) support.
rtognimp
parents: 11000
diff changeset
656 path++;
fff1b6f1a9cc Real rtsp Range parameter (Start and End) support.
rtognimp
parents: 11000
diff changeset
657 if ((s->param = strchr(s->path, '?')) != NULL)
fff1b6f1a9cc Real rtsp Range parameter (Start and End) support.
rtognimp
parents: 11000
diff changeset
658 s->param++;
15626
941b1a71351f printf converted to mp_msg; made static many unnecessarily global symbols
nicodvb
parents: 15585
diff changeset
659 //mp_msg(MSGT_OPEN, MSGL_INFO, "path=%s\n", s->path);
941b1a71351f printf converted to mp_msg; made static many unnecessarily global symbols
nicodvb
parents: 15585
diff changeset
660 //mp_msg(MSGT_OPEN, MSGL_INFO, "param=%s\n", s->param ? s->param : "NULL");
9922
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
661 s->s = fd;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
662
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
663 if (s->s < 0) {
15626
941b1a71351f printf converted to mp_msg; made static many unnecessarily global symbols
nicodvb
parents: 15585
diff changeset
664 mp_msg(MSGT_OPEN, MSGL_ERR, "rtsp: failed to connect to '%s'\n", s->host);
9922
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
665 rtsp_close(s);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
666 return NULL;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
667 }
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
668
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
669 s->server_state=RTSP_CONNECTED;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
670
11000
6e35326c742f many small typo and grammar fixes
gabucino
parents: 10281
diff changeset
671 /* now let's send an options request. */
9922
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
672 rtsp_schedule_field(s, "CSeq: 1");
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
673 rtsp_schedule_field(s, s->user_agent);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
674 rtsp_schedule_field(s, "ClientChallenge: 9e26d33f2984236010ef6253fb1887f7");
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
675 rtsp_schedule_field(s, "PlayerStarttime: [28/03/2003:22:50:23 00:00]");
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
676 rtsp_schedule_field(s, "CompanyID: KnKV4M4I/B2FjJ1TToLycw==");
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
677 rtsp_schedule_field(s, "GUID: 00000000-0000-0000-0000-000000000000");
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
678 rtsp_schedule_field(s, "RegionData: 0");
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
679 rtsp_schedule_field(s, "ClientID: Linux_2.4_6.0.9.1235_play32_RN01_EN_586");
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
680 /*rtsp_schedule_field(s, "Pragma: initiate-session");*/
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
681 rtsp_request_options(s, NULL);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
682
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
683 return s;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
684 }
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
685
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
686
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
687 /*
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
688 * closes an rtsp connection
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
689 */
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
690
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
691 void rtsp_close(rtsp_t *s) {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
692
10281
54bcbf28698a Networking support under MinGW.
diego
parents: 10206
diff changeset
693 if (s->server_state) closesocket(s->s); /* TODO: send a TEAROFF */
9922
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
694 if (s->path) free(s->path);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
695 if (s->host) free(s->host);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
696 if (s->mrl) free(s->mrl);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
697 if (s->session) free(s->session);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
698 if (s->user_agent) free(s->user_agent);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
699 rtsp_free_answers(s);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
700 rtsp_unschedule_all(s);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
701 free(s);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
702 }
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
703
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
704 /*
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
705 * search in answers for tags. returns a pointer to the content
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
706 * after the first matched tag. returns NULL if no match found.
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
707 */
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
708
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
709 char *rtsp_search_answers(rtsp_t *s, const char *tag) {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
710
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
711 char **answer;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
712 char *ptr;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
713
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
714 if (!s->answers) return NULL;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
715 answer=s->answers;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
716
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
717 while (*answer) {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
718 if (!strncasecmp(*answer,tag,strlen(tag))) {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
719 ptr=strchr(*answer,':');
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
720 ptr++;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
721 while(*ptr==' ') ptr++;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
722 return ptr;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
723 }
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
724 answer++;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
725 }
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
726
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
727 return NULL;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
728 }
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
729
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
730 /*
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
731 * session id management
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
732 */
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
733
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
734 void rtsp_set_session(rtsp_t *s, const char *id) {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
735
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
736 if (s->session) free(s->session);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
737
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
738 s->session=strdup(id);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
739
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
740 }
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
741
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
742 char *rtsp_get_session(rtsp_t *s) {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
743
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
744 return s->session;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
745
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
746 }
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
747
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
748 char *rtsp_get_mrl(rtsp_t *s) {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
749
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
750 return s->mrl;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
751
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
752 }
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
753
11506
fff1b6f1a9cc Real rtsp Range parameter (Start and End) support.
rtognimp
parents: 11000
diff changeset
754 char *rtsp_get_param(rtsp_t *s, char *p) {
fff1b6f1a9cc Real rtsp Range parameter (Start and End) support.
rtognimp
parents: 11000
diff changeset
755 int len;
fff1b6f1a9cc Real rtsp Range parameter (Start and End) support.
rtognimp
parents: 11000
diff changeset
756 char *param;
fff1b6f1a9cc Real rtsp Range parameter (Start and End) support.
rtognimp
parents: 11000
diff changeset
757 if (!s->param)
fff1b6f1a9cc Real rtsp Range parameter (Start and End) support.
rtognimp
parents: 11000
diff changeset
758 return NULL;
fff1b6f1a9cc Real rtsp Range parameter (Start and End) support.
rtognimp
parents: 11000
diff changeset
759 if (!p)
fff1b6f1a9cc Real rtsp Range parameter (Start and End) support.
rtognimp
parents: 11000
diff changeset
760 return strdup(s->param);
fff1b6f1a9cc Real rtsp Range parameter (Start and End) support.
rtognimp
parents: 11000
diff changeset
761 len = strlen(p);
fff1b6f1a9cc Real rtsp Range parameter (Start and End) support.
rtognimp
parents: 11000
diff changeset
762 param = s->param;
fff1b6f1a9cc Real rtsp Range parameter (Start and End) support.
rtognimp
parents: 11000
diff changeset
763 while (param && *param) {
fff1b6f1a9cc Real rtsp Range parameter (Start and End) support.
rtognimp
parents: 11000
diff changeset
764 char *nparam = strchr(param, '&');
fff1b6f1a9cc Real rtsp Range parameter (Start and End) support.
rtognimp
parents: 11000
diff changeset
765 if (strncmp(param, p, len) == 0 && param[len] == '=') {
fff1b6f1a9cc Real rtsp Range parameter (Start and End) support.
rtognimp
parents: 11000
diff changeset
766 param += len + 1;
fff1b6f1a9cc Real rtsp Range parameter (Start and End) support.
rtognimp
parents: 11000
diff changeset
767 len = nparam ? nparam - param : strlen(param);
fff1b6f1a9cc Real rtsp Range parameter (Start and End) support.
rtognimp
parents: 11000
diff changeset
768 nparam = malloc(len + 1);
fff1b6f1a9cc Real rtsp Range parameter (Start and End) support.
rtognimp
parents: 11000
diff changeset
769 memcpy(nparam, param, len);
fff1b6f1a9cc Real rtsp Range parameter (Start and End) support.
rtognimp
parents: 11000
diff changeset
770 nparam[len] = 0;
fff1b6f1a9cc Real rtsp Range parameter (Start and End) support.
rtognimp
parents: 11000
diff changeset
771 return nparam;
fff1b6f1a9cc Real rtsp Range parameter (Start and End) support.
rtognimp
parents: 11000
diff changeset
772 }
fff1b6f1a9cc Real rtsp Range parameter (Start and End) support.
rtognimp
parents: 11000
diff changeset
773 param = nparam ? nparam + 1 : NULL;
fff1b6f1a9cc Real rtsp Range parameter (Start and End) support.
rtognimp
parents: 11000
diff changeset
774 }
fff1b6f1a9cc Real rtsp Range parameter (Start and End) support.
rtognimp
parents: 11000
diff changeset
775 return NULL;
fff1b6f1a9cc Real rtsp Range parameter (Start and End) support.
rtognimp
parents: 11000
diff changeset
776 }
fff1b6f1a9cc Real rtsp Range parameter (Start and End) support.
rtognimp
parents: 11000
diff changeset
777
9922
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
778 /*
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
779 * schedules a field for transmission
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
780 */
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
781
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
782 void rtsp_schedule_field(rtsp_t *s, const char *string) {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
783
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
784 int i=0;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
785
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
786 if (!string) return;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
787
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
788 while(s->scheduled[i]) {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
789 i++;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
790 }
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
791 s->scheduled[i]=strdup(string);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
792 }
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
793
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
794 /*
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
795 * removes the first scheduled field which prefix matches string.
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
796 */
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
797
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
798 void rtsp_unschedule_field(rtsp_t *s, const char *string) {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
799
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
800 char **ptr=s->scheduled;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
801
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
802 if (!string) return;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
803
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
804 while(*ptr) {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
805 if (!strncmp(*ptr, string, strlen(string)))
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
806 break;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
807 }
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
808 if (*ptr) free(*ptr);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
809 ptr++;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
810 do {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
811 *(ptr-1)=*ptr;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
812 } while(*ptr);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
813 }
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
814
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
815 /*
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
816 * unschedule all fields
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
817 */
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
818
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
819 void rtsp_unschedule_all(rtsp_t *s) {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
820
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
821 char **ptr;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
822
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
823 if (!s->scheduled) return;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
824 ptr=s->scheduled;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
825
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
826 while (*ptr) {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
827 free(*ptr);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
828 *ptr=NULL;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
829 ptr++;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
830 }
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
831 }
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
832 /*
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
833 * free answers
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
834 */
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
835
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
836 void rtsp_free_answers(rtsp_t *s) {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
837
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
838 char **answer;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
839
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
840 if (!s->answers) return;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
841 answer=s->answers;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
842
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
843 while (*answer) {
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
844 free(*answer);
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
845 *answer=NULL;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
846 answer++;
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
847 }
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents:
diff changeset
848 }
15585
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15172
diff changeset
849
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15172
diff changeset
850 static int realrtsp_streaming_read( int fd, char *buffer, int size, streaming_ctrl_t *stream_ctrl ) {
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15172
diff changeset
851 return rtsp_session_read(stream_ctrl->data, buffer, size);
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15172
diff changeset
852 }
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15172
diff changeset
853
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15172
diff changeset
854
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15172
diff changeset
855 static int realrtsp_streaming_start( stream_t *stream ) {
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15172
diff changeset
856 int fd;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15172
diff changeset
857 rtsp_session_t *rtsp;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15172
diff changeset
858 char *mrl;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15172
diff changeset
859 char *file;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15172
diff changeset
860 int port;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15172
diff changeset
861 int redirected, temp;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15172
diff changeset
862 if( stream==NULL ) return -1;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15172
diff changeset
863
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15172
diff changeset
864 temp = 5; // counter so we don't get caught in infinite redirections (you never know)
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15172
diff changeset
865
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15172
diff changeset
866 do {
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15172
diff changeset
867 redirected = 0;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15172
diff changeset
868
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15172
diff changeset
869 fd = connect2Server( stream->streaming_ctrl->url->hostname,
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15172
diff changeset
870 port = (stream->streaming_ctrl->url->port ? stream->streaming_ctrl->url->port : 554),1 );
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15172
diff changeset
871 if(fd<0 && !stream->streaming_ctrl->url->port)
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15172
diff changeset
872 fd = connect2Server(stream->streaming_ctrl->url->hostname, port = 7070, 1);
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15172
diff changeset
873 if(fd<0) return -1;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15172
diff changeset
874
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15172
diff changeset
875 file = stream->streaming_ctrl->url->file;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15172
diff changeset
876 if (file[0] == '/')
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15172
diff changeset
877 file++;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15172
diff changeset
878 mrl = malloc(sizeof(char)*(strlen(stream->streaming_ctrl->url->hostname)+strlen(file)+16));
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15172
diff changeset
879 sprintf(mrl,"rtsp://%s:%i/%s",stream->streaming_ctrl->url->hostname,port,file);
17332
88adbc28f60b This patch makes real rtsp tell the server to deliver data at specified
rtognimp
parents: 17092
diff changeset
880 rtsp = rtsp_session_start(fd,&mrl, file, stream->streaming_ctrl->url->hostname, port, &redirected, stream->streaming_ctrl->bandwidth);
15585
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15172
diff changeset
881
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15172
diff changeset
882 if( redirected == 1) {
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15172
diff changeset
883 url_free(stream->streaming_ctrl->url);
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15172
diff changeset
884 stream->streaming_ctrl->url = url_new(mrl);
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15172
diff changeset
885 closesocket(fd);
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15172
diff changeset
886 }
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15172
diff changeset
887
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15172
diff changeset
888 free(mrl);
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15172
diff changeset
889 temp--;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15172
diff changeset
890 } while( (redirected != 0) && (temp > 0) );
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15172
diff changeset
891
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15172
diff changeset
892 if(!rtsp) return -1;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15172
diff changeset
893
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15172
diff changeset
894 stream->fd=fd;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15172
diff changeset
895 stream->streaming_ctrl->data=rtsp;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15172
diff changeset
896
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15172
diff changeset
897 stream->streaming_ctrl->streaming_read = realrtsp_streaming_read;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15172
diff changeset
898 //stream->streaming_ctrl->streaming_seek = nop_streaming_seek;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15172
diff changeset
899 stream->streaming_ctrl->prebuffer_size = 128*1024; // 8 KBytes
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15172
diff changeset
900 stream->streaming_ctrl->buffering = 1;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15172
diff changeset
901 stream->streaming_ctrl->status = streaming_playing_e;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15172
diff changeset
902 return 0;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15172
diff changeset
903 }
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15172
diff changeset
904
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15172
diff changeset
905
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15172
diff changeset
906 static int open_s(stream_t *stream,int mode, void* opts, int* file_format) {
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15172
diff changeset
907 URL_t *url;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15172
diff changeset
908
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15172
diff changeset
909 mp_msg(MSGT_OPEN, MSGL_INFO, "STREAM_RTSP, URL: %s\n", stream->url);
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15172
diff changeset
910 stream->streaming_ctrl = streaming_ctrl_new();
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15172
diff changeset
911 if( stream->streaming_ctrl==NULL )
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15172
diff changeset
912 return STREAM_ERROR;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15172
diff changeset
913
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15172
diff changeset
914 stream->streaming_ctrl->bandwidth = network_bandwidth;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15172
diff changeset
915 url = url_new(stream->url);
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15172
diff changeset
916 stream->streaming_ctrl->url = check4proxies(url);
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15172
diff changeset
917 //url_free(url);
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15172
diff changeset
918
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15172
diff changeset
919 stream->fd = -1;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15172
diff changeset
920 if(realrtsp_streaming_start( stream ) < 0) {
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15172
diff changeset
921 streaming_ctrl_free(stream->streaming_ctrl);
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15172
diff changeset
922 stream->streaming_ctrl = NULL;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15172
diff changeset
923 return STREAM_UNSUPORTED;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15172
diff changeset
924 }
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15172
diff changeset
925
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15172
diff changeset
926 fixup_network_stream_cache(stream);
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15172
diff changeset
927 stream->type = STREAMTYPE_STREAM;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15172
diff changeset
928 return STREAM_OK;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15172
diff changeset
929 }
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15172
diff changeset
930
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15172
diff changeset
931
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15172
diff changeset
932 stream_info_t stream_info_rtsp = {
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15172
diff changeset
933 "RealNetworks rtsp streaming",
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15172
diff changeset
934 "realrtsp",
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15172
diff changeset
935 "Roberto Togni, xine team",
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15172
diff changeset
936 "ported from xine",
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15172
diff changeset
937 open_s,
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15172
diff changeset
938 {"rtsp", NULL},
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15172
diff changeset
939 NULL,
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15172
diff changeset
940 0 // Urls are an option string
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15172
diff changeset
941 };