Mercurial > mplayer.hg
annotate libmpdemux/realrtsp/rtsp_session.c @ 15246:849a6f39964f
use the documented default video device /dev/video0 instead of /dev/video that is missing on most systems
author | iive |
---|---|
date | Sat, 23 Apr 2005 21:23:58 +0000 |
parents | 929af3b49c8e |
children | 88adbc28f60b |
rev | line source |
---|---|
9922 | 1 /* |
2 * This file was ported to MPlayer from xine CVS rtsp_session.c,v 1.9 2003/02/11 16:20:40 | |
3 */ | |
4 | |
5 /* | |
6 * Copyright (C) 2000-2002 the xine project | |
7 * | |
8 * This file is part of xine, a free video player. | |
9 * | |
10 * xine is free software; you can redistribute it and/or modify | |
11 * it under the terms of the GNU General Public License as published by | |
12 * the Free Software Foundation; either version 2 of the License, or | |
13 * (at your option) any later version. | |
14 * | |
15 * xine is distributed in the hope that it will be useful, | |
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 * GNU General Public License for more details. | |
19 * | |
20 * You should have received a copy of the GNU General Public License | |
21 * along with this program; if not, write to the Free Software | |
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA | |
23 * | |
24 * | |
25 * high level interface to rtsp servers. | |
26 */ | |
27 | |
28 #include <sys/types.h> | |
10281 | 29 #include "config.h" |
30 #ifndef HAVE_WINSOCK2 | |
9922 | 31 #include <sys/socket.h> |
32 #include <netinet/in.h> | |
33 #include <netdb.h> | |
10281 | 34 #else |
35 #include <winsock2.h> | |
36 #endif | |
9922 | 37 #include <unistd.h> |
38 #include <stdio.h> | |
39 #include <fcntl.h> | |
40 #include <stdlib.h> | |
41 #include <string.h> | |
42 | |
43 #include "rtsp.h" | |
44 #include "rtsp_session.h" | |
45 #include "real.h" | |
46 #include "rmff.h" | |
47 #include "asmrp.h" | |
12266 | 48 #include "xbuffer.h" |
9922 | 49 |
50 /* | |
51 #define LOG | |
52 */ | |
53 | |
54 #define BUF_SIZE 4096 | |
55 #define HEADER_SIZE 4096 | |
56 | |
57 struct rtsp_session_s { | |
58 | |
59 rtsp_t *s; | |
60 | |
61 /* receive buffer */ | |
12266 | 62 uint8_t *recv; |
9922 | 63 int recv_size; |
64 int recv_read; | |
65 | |
66 /* header buffer */ | |
67 uint8_t header[HEADER_SIZE]; | |
68 int header_len; | |
69 int header_read; | |
70 | |
71 }; | |
72 | |
73 //rtsp_session_t *rtsp_session_start(char *mrl) { | |
10199 | 74 rtsp_session_t *rtsp_session_start(int fd, char **mrl, char *path, char *host, int port, int *redir) { |
9922 | 75 |
76 rtsp_session_t *rtsp_session=malloc(sizeof(rtsp_session_t)); | |
77 char *server; | |
78 char *mrl_line = NULL; | |
79 rmff_header_t *h; | |
80 uint32_t bandwidth=10485800; | |
81 | |
12266 | 82 rtsp_session->recv = xbuffer_init(BUF_SIZE); |
83 | |
10199 | 84 //connect: |
85 *redir = 0; | |
9922 | 86 |
87 /* connect to server */ | |
10199 | 88 rtsp_session->s=rtsp_connect(fd,*mrl,path,host,port,NULL); |
9922 | 89 if (!rtsp_session->s) |
90 { | |
91 printf("rtsp_session: failed to connect to server %s\n", path); | |
12266 | 92 rtsp_session->recv = xbuffer_free(rtsp_session->recv); |
9922 | 93 free(rtsp_session); |
94 return NULL; | |
95 } | |
96 | |
97 /* looking for server type */ | |
98 if (rtsp_search_answers(rtsp_session->s,"Server")) | |
99 server=strdup(rtsp_search_answers(rtsp_session->s,"Server")); | |
100 else { | |
101 if (rtsp_search_answers(rtsp_session->s,"RealChallenge1")) | |
102 server=strdup("Real"); | |
103 else | |
104 server=strdup("unknown"); | |
105 } | |
10198 | 106 if (strstr(server,"Real") || strstr(server,"Helix")) |
9922 | 107 { |
108 /* we are talking to a real server ... */ | |
109 | |
110 h=real_setup_and_get_header(rtsp_session->s, bandwidth); | |
111 if (!h) { | |
112 /* got an redirect? */ | |
113 if (rtsp_search_answers(rtsp_session->s, "Location")) | |
114 { | |
115 free(mrl_line); | |
116 mrl_line=strdup(rtsp_search_answers(rtsp_session->s, "Location")); | |
117 printf("rtsp_session: redirected to %s\n", mrl_line); | |
118 rtsp_close(rtsp_session->s); | |
119 free(server); | |
10199 | 120 free(*mrl); |
121 free(rtsp_session); | |
122 /* tell the caller to redirect, return url to redirect to in mrl */ | |
123 *mrl = mrl_line; | |
124 *redir = 1; | |
125 return NULL; | |
126 // goto connect; /* *shudder* i made a design mistake somewhere */ | |
9922 | 127 } else |
128 { | |
129 printf("rtsp_session: session can not be established.\n"); | |
130 rtsp_close(rtsp_session->s); | |
12266 | 131 rtsp_session->recv = xbuffer_free(rtsp_session->recv); |
9922 | 132 free(rtsp_session); |
133 return NULL; | |
134 } | |
135 } | |
136 | |
137 rtsp_session->header_len=rmff_dump_header(h,rtsp_session->header,1024); | |
138 | |
12266 | 139 rtsp_session->recv = xbuffer_copyin(rtsp_session->recv, 0, rtsp_session->header, rtsp_session->header_len); |
9922 | 140 rtsp_session->recv_size = rtsp_session->header_len; |
141 rtsp_session->recv_read = 0; | |
142 | |
143 } else | |
144 { | |
12206
d572c605f665
Try Real rtsp, then live.com on every rtsp stream (remove extension
rtognimp
parents:
10281
diff
changeset
|
145 printf("rtsp_session: Not a Real server. Server type is '%s'.\n",server); |
9922 | 146 rtsp_close(rtsp_session->s); |
147 free(server); | |
12266 | 148 rtsp_session->recv = xbuffer_free(rtsp_session->recv); |
9922 | 149 free(rtsp_session); |
150 return NULL; | |
151 } | |
152 free(server); | |
153 | |
154 return rtsp_session; | |
155 } | |
156 | |
157 int rtsp_session_read (rtsp_session_t *this, char *data, int len) { | |
158 | |
159 int to_copy=len; | |
160 char *dest=data; | |
161 char *source=this->recv + this->recv_read; | |
162 int fill=this->recv_size - this->recv_read; | |
163 | |
164 if (len < 0) return 0; | |
165 while (to_copy > fill) { | |
166 | |
167 memcpy(dest, source, fill); | |
168 to_copy -= fill; | |
169 dest += fill; | |
170 this->recv_read = 0; | |
13187 | 171 this->recv_size = real_get_rdt_chunk (this->s, (char **)&(this->recv)); |
13676 | 172 if (this->recv_size < 0) |
173 return -1; | |
9922 | 174 source = this->recv; |
175 fill = this->recv_size; | |
176 | |
177 if (this->recv_size == 0) { | |
178 #ifdef LOG | |
179 printf ("librtsp: %d of %d bytes provided\n", len-to_copy, len); | |
180 #endif | |
181 return len-to_copy; | |
182 } | |
183 } | |
184 | |
185 memcpy(dest, source, to_copy); | |
186 this->recv_read += to_copy; | |
187 | |
188 #ifdef LOG | |
189 printf ("librtsp: %d bytes provided\n", len); | |
190 #endif | |
191 | |
192 return len; | |
193 } | |
194 | |
195 int rtsp_session_peek_header(rtsp_session_t *this, char *buf, int maxsize) { | |
196 | |
197 int len; | |
198 | |
199 len = (this->header_len < maxsize) ? this->header_len : maxsize; | |
200 | |
201 memcpy(buf, this->header, len); | |
202 return len; | |
203 } | |
204 | |
205 void rtsp_session_end(rtsp_session_t *session) { | |
206 | |
207 rtsp_close(session->s); | |
12266 | 208 session->recv = xbuffer_free(session->recv); |
9922 | 209 free(session); |
210 } |