Mercurial > mplayer.hg
annotate libmpdemux/realrtsp/rtsp_session.c @ 17332:88adbc28f60b
This patch makes real rtsp tell the server to deliver data at specified
bandwidth, if bandwidth cmdline option is given. Also, if that's given,
it uses it for sdp stream selection. If not given, the behavior is the
same as before.
It's used to implement something like turboplay in realplayer.
Patch by Tomas Janousek >>> tomi (At) nomi (.) cz <<<
author | rtognimp |
---|---|
date | Fri, 06 Jan 2006 14:39:10 +0000 |
parents | 929af3b49c8e |
children | 2518f4341587 |
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) { | |
17332
88adbc28f60b
This patch makes real rtsp tell the server to deliver data at specified
rtognimp
parents:
13676
diff
changeset
|
74 rtsp_session_t *rtsp_session_start(int fd, char **mrl, char *path, char *host, int port, int *redir, uint32_t bandwidth) { |
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 | |
12266 | 81 rtsp_session->recv = xbuffer_init(BUF_SIZE); |
82 | |
10199 | 83 //connect: |
84 *redir = 0; | |
9922 | 85 |
86 /* connect to server */ | |
10199 | 87 rtsp_session->s=rtsp_connect(fd,*mrl,path,host,port,NULL); |
9922 | 88 if (!rtsp_session->s) |
89 { | |
90 printf("rtsp_session: failed to connect to server %s\n", path); | |
12266 | 91 rtsp_session->recv = xbuffer_free(rtsp_session->recv); |
9922 | 92 free(rtsp_session); |
93 return NULL; | |
94 } | |
95 | |
96 /* looking for server type */ | |
97 if (rtsp_search_answers(rtsp_session->s,"Server")) | |
98 server=strdup(rtsp_search_answers(rtsp_session->s,"Server")); | |
99 else { | |
100 if (rtsp_search_answers(rtsp_session->s,"RealChallenge1")) | |
101 server=strdup("Real"); | |
102 else | |
103 server=strdup("unknown"); | |
104 } | |
10198 | 105 if (strstr(server,"Real") || strstr(server,"Helix")) |
9922 | 106 { |
107 /* we are talking to a real server ... */ | |
108 | |
109 h=real_setup_and_get_header(rtsp_session->s, bandwidth); | |
110 if (!h) { | |
111 /* got an redirect? */ | |
112 if (rtsp_search_answers(rtsp_session->s, "Location")) | |
113 { | |
114 free(mrl_line); | |
115 mrl_line=strdup(rtsp_search_answers(rtsp_session->s, "Location")); | |
116 printf("rtsp_session: redirected to %s\n", mrl_line); | |
117 rtsp_close(rtsp_session->s); | |
118 free(server); | |
10199 | 119 free(*mrl); |
120 free(rtsp_session); | |
121 /* tell the caller to redirect, return url to redirect to in mrl */ | |
122 *mrl = mrl_line; | |
123 *redir = 1; | |
124 return NULL; | |
125 // goto connect; /* *shudder* i made a design mistake somewhere */ | |
9922 | 126 } else |
127 { | |
128 printf("rtsp_session: session can not be established.\n"); | |
129 rtsp_close(rtsp_session->s); | |
12266 | 130 rtsp_session->recv = xbuffer_free(rtsp_session->recv); |
9922 | 131 free(rtsp_session); |
132 return NULL; | |
133 } | |
134 } | |
135 | |
136 rtsp_session->header_len=rmff_dump_header(h,rtsp_session->header,1024); | |
137 | |
12266 | 138 rtsp_session->recv = xbuffer_copyin(rtsp_session->recv, 0, rtsp_session->header, rtsp_session->header_len); |
9922 | 139 rtsp_session->recv_size = rtsp_session->header_len; |
140 rtsp_session->recv_read = 0; | |
141 | |
142 } else | |
143 { | |
12206
d572c605f665
Try Real rtsp, then live.com on every rtsp stream (remove extension
rtognimp
parents:
10281
diff
changeset
|
144 printf("rtsp_session: Not a Real server. Server type is '%s'.\n",server); |
9922 | 145 rtsp_close(rtsp_session->s); |
146 free(server); | |
12266 | 147 rtsp_session->recv = xbuffer_free(rtsp_session->recv); |
9922 | 148 free(rtsp_session); |
149 return NULL; | |
150 } | |
151 free(server); | |
152 | |
153 return rtsp_session; | |
154 } | |
155 | |
156 int rtsp_session_read (rtsp_session_t *this, char *data, int len) { | |
157 | |
158 int to_copy=len; | |
159 char *dest=data; | |
160 char *source=this->recv + this->recv_read; | |
161 int fill=this->recv_size - this->recv_read; | |
162 | |
163 if (len < 0) return 0; | |
164 while (to_copy > fill) { | |
165 | |
166 memcpy(dest, source, fill); | |
167 to_copy -= fill; | |
168 dest += fill; | |
169 this->recv_read = 0; | |
13187 | 170 this->recv_size = real_get_rdt_chunk (this->s, (char **)&(this->recv)); |
13676 | 171 if (this->recv_size < 0) |
172 return -1; | |
9922 | 173 source = this->recv; |
174 fill = this->recv_size; | |
175 | |
176 if (this->recv_size == 0) { | |
177 #ifdef LOG | |
178 printf ("librtsp: %d of %d bytes provided\n", len-to_copy, len); | |
179 #endif | |
180 return len-to_copy; | |
181 } | |
182 } | |
183 | |
184 memcpy(dest, source, to_copy); | |
185 this->recv_read += to_copy; | |
186 | |
187 #ifdef LOG | |
188 printf ("librtsp: %d bytes provided\n", len); | |
189 #endif | |
190 | |
191 return len; | |
192 } | |
193 | |
194 int rtsp_session_peek_header(rtsp_session_t *this, char *buf, int maxsize) { | |
195 | |
196 int len; | |
197 | |
198 len = (this->header_len < maxsize) ? this->header_len : maxsize; | |
199 | |
200 memcpy(buf, this->header, len); | |
201 return len; | |
202 } | |
203 | |
204 void rtsp_session_end(rtsp_session_t *session) { | |
205 | |
206 rtsp_close(session->s); | |
12266 | 207 session->recv = xbuffer_free(session->recv); |
9922 | 208 free(session); |
209 } |