Mercurial > mplayer.hg
comparison libmpdemux/librtsp/rtsp_session.c @ 18799:e16345b97dab
moved generic rtsp related files from realrtsp to librtsp
author | ben |
---|---|
date | Fri, 23 Jun 2006 21:38:28 +0000 |
parents | libmpdemux/realrtsp/rtsp_session.c@a738f1e0224f |
children | a48dead7424a |
comparison
equal
deleted
inserted
replaced
18798:a738f1e0224f | 18799:e16345b97dab |
---|---|
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> | |
29 #include "config.h" | |
30 #ifndef HAVE_WINSOCK2 | |
31 #include <sys/socket.h> | |
32 #include <netinet/in.h> | |
33 #include <netdb.h> | |
34 #else | |
35 #include <winsock2.h> | |
36 #endif | |
37 #include <unistd.h> | |
38 #include <stdio.h> | |
39 #include <fcntl.h> | |
40 #include <stdlib.h> | |
41 #include <string.h> | |
42 #include <inttypes.h> | |
43 | |
44 #include "mp_msg.h" | |
45 #include "rtsp.h" | |
46 #include "rtsp_session.h" | |
47 #include "../realrtsp/real.h" | |
48 #include "../realrtsp/rmff.h" | |
49 #include "../realrtsp/asmrp.h" | |
50 #include "../realrtsp/xbuffer.h" | |
51 | |
52 /* | |
53 #define LOG | |
54 */ | |
55 | |
56 struct rtsp_session_s { | |
57 rtsp_t *s; | |
58 struct real_rtsp_session_t* real_session; | |
59 }; | |
60 | |
61 //rtsp_session_t *rtsp_session_start(char *mrl) { | |
62 rtsp_session_t *rtsp_session_start(int fd, char **mrl, char *path, char *host, int port, int *redir, uint32_t bandwidth) { | |
63 | |
64 rtsp_session_t *rtsp_session = NULL; | |
65 char *server; | |
66 char *mrl_line = NULL; | |
67 rmff_header_t *h; | |
68 | |
69 rtsp_session = malloc (sizeof (rtsp_session_t)); | |
70 rtsp_session->s = NULL; | |
71 rtsp_session->real_session = NULL; | |
72 | |
73 //connect: | |
74 *redir = 0; | |
75 | |
76 /* connect to server */ | |
77 rtsp_session->s=rtsp_connect(fd,*mrl,path,host,port,NULL); | |
78 if (!rtsp_session->s) | |
79 { | |
80 mp_msg (MSGT_OPEN, MSGL_ERR,"rtsp_session: failed to connect to server %s\n", path); | |
81 free(rtsp_session); | |
82 return NULL; | |
83 } | |
84 | |
85 /* looking for server type */ | |
86 if (rtsp_search_answers(rtsp_session->s,"Server")) | |
87 server=strdup(rtsp_search_answers(rtsp_session->s,"Server")); | |
88 else { | |
89 if (rtsp_search_answers(rtsp_session->s,"RealChallenge1")) | |
90 server=strdup("Real"); | |
91 else | |
92 server=strdup("unknown"); | |
93 } | |
94 if (strstr(server,"Real") || strstr(server,"Helix")) | |
95 { | |
96 /* we are talking to a real server ... */ | |
97 | |
98 h=real_setup_and_get_header(rtsp_session->s, bandwidth); | |
99 if (!h) { | |
100 /* got an redirect? */ | |
101 if (rtsp_search_answers(rtsp_session->s, "Location")) | |
102 { | |
103 free(mrl_line); | |
104 mrl_line=strdup(rtsp_search_answers(rtsp_session->s, "Location")); | |
105 mp_msg (MSGT_OPEN, MSGL_INFO,"rtsp_session: redirected to %s\n", mrl_line); | |
106 rtsp_close(rtsp_session->s); | |
107 free(server); | |
108 free(*mrl); | |
109 free(rtsp_session); | |
110 /* tell the caller to redirect, return url to redirect to in mrl */ | |
111 *mrl = mrl_line; | |
112 *redir = 1; | |
113 return NULL; | |
114 // goto connect; /* *shudder* i made a design mistake somewhere */ | |
115 } else | |
116 { | |
117 mp_msg (MSGT_OPEN, MSGL_ERR,"rtsp_session: session can not be established.\n"); | |
118 rtsp_close(rtsp_session->s); | |
119 free (server); | |
120 free(rtsp_session); | |
121 return NULL; | |
122 } | |
123 } | |
124 | |
125 rtsp_session->real_session = init_real_rtsp_session (); | |
126 rtsp_session->real_session->header_len = | |
127 rmff_dump_header (h, (char *) rtsp_session->real_session->header, 1024); | |
128 | |
129 rtsp_session->real_session->recv = | |
130 xbuffer_copyin (rtsp_session->real_session->recv, 0, | |
131 rtsp_session->real_session->header, | |
132 rtsp_session->real_session->header_len); | |
133 | |
134 rtsp_session->real_session->recv_size = | |
135 rtsp_session->real_session->header_len; | |
136 rtsp_session->real_session->recv_read = 0; | |
137 } else | |
138 { | |
139 mp_msg (MSGT_OPEN, MSGL_ERR,"rtsp_session: Not a Real server. Server type is '%s'.\n",server); | |
140 rtsp_close(rtsp_session->s); | |
141 free(server); | |
142 free(rtsp_session); | |
143 return NULL; | |
144 } | |
145 free(server); | |
146 | |
147 return rtsp_session; | |
148 } | |
149 | |
150 int rtsp_session_read (rtsp_session_t *this, char *data, int len) { | |
151 | |
152 if (this->real_session) { | |
153 int to_copy=len; | |
154 char *dest=data; | |
155 char *source = | |
156 (char *) (this->real_session->recv + this->real_session->recv_read); | |
157 int fill = this->real_session->recv_size - this->real_session->recv_read; | |
158 | |
159 if (len < 0) return 0; | |
160 while (to_copy > fill) { | |
161 | |
162 memcpy(dest, source, fill); | |
163 to_copy -= fill; | |
164 dest += fill; | |
165 this->real_session->recv_read = 0; | |
166 this->real_session->recv_size = | |
167 real_get_rdt_chunk (this->s, (char **)&(this->real_session->recv)); | |
168 if (this->real_session->recv_size < 0) | |
169 return -1; | |
170 source = (char *) this->real_session->recv; | |
171 fill = this->real_session->recv_size; | |
172 | |
173 if (this->real_session->recv_size == 0) { | |
174 #ifdef LOG | |
175 mp_msg (MSGT_OPEN, MSGL_INFO, "librtsp: %d of %d bytes provided\n", len-to_copy, len); | |
176 #endif | |
177 return len-to_copy; | |
178 } | |
179 } | |
180 | |
181 memcpy(dest, source, to_copy); | |
182 this->real_session->recv_read += to_copy; | |
183 | |
184 #ifdef LOG | |
185 mp_msg (MSGT_OPEN, MSGL_INFO, "librtsp: %d bytes provided\n", len); | |
186 #endif | |
187 | |
188 return len; | |
189 } | |
190 | |
191 return 0; | |
192 } | |
193 | |
194 void rtsp_session_end(rtsp_session_t *session) { | |
195 | |
196 rtsp_close(session->s); | |
197 if (session->real_session) | |
198 free_real_rtsp_session (session->real_session); | |
199 free(session); | |
200 } |