Mercurial > mplayer.hg
annotate libmpdemux/librtsp/rtsp_session.c @ 18823:ef667dd373e2
new imported library in libmpdemux: freesdp (will be used by native rtsp demuxer)
author | ben |
---|---|
date | Mon, 26 Jun 2006 17:37:55 +0000 |
parents | a48dead7424a |
children | 317e0fd394c5 |
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> | |
17351
2518f4341587
OS X compilation fix: Include inttypes.h so that uint32_t is not undefined.
diego
parents:
17332
diff
changeset
|
42 #include <inttypes.h> |
9922 | 43 |
18793 | 44 #include "mp_msg.h" |
9922 | 45 #include "rtsp.h" |
46 #include "rtsp_session.h" | |
18799
e16345b97dab
moved generic rtsp related files from realrtsp to librtsp
ben
parents:
18798
diff
changeset
|
47 #include "../realrtsp/real.h" |
e16345b97dab
moved generic rtsp related files from realrtsp to librtsp
ben
parents:
18798
diff
changeset
|
48 #include "../realrtsp/rmff.h" |
e16345b97dab
moved generic rtsp related files from realrtsp to librtsp
ben
parents:
18798
diff
changeset
|
49 #include "../realrtsp/asmrp.h" |
e16345b97dab
moved generic rtsp related files from realrtsp to librtsp
ben
parents:
18798
diff
changeset
|
50 #include "../realrtsp/xbuffer.h" |
9922 | 51 |
52 /* | |
53 #define LOG | |
54 */ | |
55 | |
18822 | 56 #define RTSP_OPTIONS_SERVER "Server" |
57 #define RTSP_OPTIONS_LOCATION "Location" | |
58 #define RTSP_OPTIONS_REAL "RealChallenge1" | |
59 #define RTSP_SERVER_TYPE_REAL "Real" | |
60 #define RTSP_SERVER_TYPE_HELIX "Helix" | |
61 #define RTSP_SERVER_TYPE_UNKNOWN "unknown" | |
62 | |
9922 | 63 struct rtsp_session_s { |
64 rtsp_t *s; | |
18792
6a015ba5bf45
move real_rtsp init/uninit code to its dedicated place to simplify a bit rtsp session demuxer
ben
parents:
17351
diff
changeset
|
65 struct real_rtsp_session_t* real_session; |
9922 | 66 }; |
67 | |
68 //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
|
69 rtsp_session_t *rtsp_session_start(int fd, char **mrl, char *path, char *host, int port, int *redir, uint32_t bandwidth) { |
9922 | 70 |
18792
6a015ba5bf45
move real_rtsp init/uninit code to its dedicated place to simplify a bit rtsp session demuxer
ben
parents:
17351
diff
changeset
|
71 rtsp_session_t *rtsp_session = NULL; |
9922 | 72 char *server; |
73 char *mrl_line = NULL; | |
74 rmff_header_t *h; | |
75 | |
18792
6a015ba5bf45
move real_rtsp init/uninit code to its dedicated place to simplify a bit rtsp session demuxer
ben
parents:
17351
diff
changeset
|
76 rtsp_session = malloc (sizeof (rtsp_session_t)); |
6a015ba5bf45
move real_rtsp init/uninit code to its dedicated place to simplify a bit rtsp session demuxer
ben
parents:
17351
diff
changeset
|
77 rtsp_session->s = NULL; |
6a015ba5bf45
move real_rtsp init/uninit code to its dedicated place to simplify a bit rtsp session demuxer
ben
parents:
17351
diff
changeset
|
78 rtsp_session->real_session = NULL; |
6a015ba5bf45
move real_rtsp init/uninit code to its dedicated place to simplify a bit rtsp session demuxer
ben
parents:
17351
diff
changeset
|
79 |
10199 | 80 //connect: |
81 *redir = 0; | |
9922 | 82 |
83 /* connect to server */ | |
10199 | 84 rtsp_session->s=rtsp_connect(fd,*mrl,path,host,port,NULL); |
9922 | 85 if (!rtsp_session->s) |
86 { | |
18793 | 87 mp_msg (MSGT_OPEN, MSGL_ERR,"rtsp_session: failed to connect to server %s\n", path); |
9922 | 88 free(rtsp_session); |
89 return NULL; | |
90 } | |
91 | |
92 /* looking for server type */ | |
18822 | 93 if (rtsp_search_answers(rtsp_session->s,RTSP_OPTIONS_SERVER)) |
94 server=strdup(rtsp_search_answers(rtsp_session->s,RTSP_OPTIONS_SERVER)); | |
9922 | 95 else { |
18822 | 96 if (rtsp_search_answers(rtsp_session->s,RTSP_OPTIONS_REAL)) |
97 server=strdup(RTSP_SERVER_TYPE_REAL); | |
9922 | 98 else |
18822 | 99 server=strdup(RTSP_SERVER_TYPE_UNKNOWN); |
9922 | 100 } |
18822 | 101 if (strstr(server,RTSP_SERVER_TYPE_REAL) || strstr(server,RTSP_SERVER_TYPE_HELIX)) |
9922 | 102 { |
103 /* we are talking to a real server ... */ | |
104 | |
105 h=real_setup_and_get_header(rtsp_session->s, bandwidth); | |
106 if (!h) { | |
107 /* got an redirect? */ | |
18822 | 108 if (rtsp_search_answers(rtsp_session->s, RTSP_OPTIONS_LOCATION)) |
9922 | 109 { |
110 free(mrl_line); | |
18822 | 111 mrl_line=strdup(rtsp_search_answers(rtsp_session->s, RTSP_OPTIONS_LOCATION)); |
18793 | 112 mp_msg (MSGT_OPEN, MSGL_INFO,"rtsp_session: redirected to %s\n", mrl_line); |
9922 | 113 rtsp_close(rtsp_session->s); |
114 free(server); | |
10199 | 115 free(*mrl); |
116 free(rtsp_session); | |
117 /* tell the caller to redirect, return url to redirect to in mrl */ | |
118 *mrl = mrl_line; | |
119 *redir = 1; | |
120 return NULL; | |
121 // goto connect; /* *shudder* i made a design mistake somewhere */ | |
9922 | 122 } else |
123 { | |
18793 | 124 mp_msg (MSGT_OPEN, MSGL_ERR,"rtsp_session: session can not be established.\n"); |
9922 | 125 rtsp_close(rtsp_session->s); |
18792
6a015ba5bf45
move real_rtsp init/uninit code to its dedicated place to simplify a bit rtsp session demuxer
ben
parents:
17351
diff
changeset
|
126 free (server); |
9922 | 127 free(rtsp_session); |
128 return NULL; | |
129 } | |
130 } | |
131 | |
18792
6a015ba5bf45
move real_rtsp init/uninit code to its dedicated place to simplify a bit rtsp session demuxer
ben
parents:
17351
diff
changeset
|
132 rtsp_session->real_session = init_real_rtsp_session (); |
6a015ba5bf45
move real_rtsp init/uninit code to its dedicated place to simplify a bit rtsp session demuxer
ben
parents:
17351
diff
changeset
|
133 rtsp_session->real_session->header_len = |
6a015ba5bf45
move real_rtsp init/uninit code to its dedicated place to simplify a bit rtsp session demuxer
ben
parents:
17351
diff
changeset
|
134 rmff_dump_header (h, (char *) rtsp_session->real_session->header, 1024); |
9922 | 135 |
18792
6a015ba5bf45
move real_rtsp init/uninit code to its dedicated place to simplify a bit rtsp session demuxer
ben
parents:
17351
diff
changeset
|
136 rtsp_session->real_session->recv = |
6a015ba5bf45
move real_rtsp init/uninit code to its dedicated place to simplify a bit rtsp session demuxer
ben
parents:
17351
diff
changeset
|
137 xbuffer_copyin (rtsp_session->real_session->recv, 0, |
6a015ba5bf45
move real_rtsp init/uninit code to its dedicated place to simplify a bit rtsp session demuxer
ben
parents:
17351
diff
changeset
|
138 rtsp_session->real_session->header, |
6a015ba5bf45
move real_rtsp init/uninit code to its dedicated place to simplify a bit rtsp session demuxer
ben
parents:
17351
diff
changeset
|
139 rtsp_session->real_session->header_len); |
6a015ba5bf45
move real_rtsp init/uninit code to its dedicated place to simplify a bit rtsp session demuxer
ben
parents:
17351
diff
changeset
|
140 |
6a015ba5bf45
move real_rtsp init/uninit code to its dedicated place to simplify a bit rtsp session demuxer
ben
parents:
17351
diff
changeset
|
141 rtsp_session->real_session->recv_size = |
6a015ba5bf45
move real_rtsp init/uninit code to its dedicated place to simplify a bit rtsp session demuxer
ben
parents:
17351
diff
changeset
|
142 rtsp_session->real_session->header_len; |
6a015ba5bf45
move real_rtsp init/uninit code to its dedicated place to simplify a bit rtsp session demuxer
ben
parents:
17351
diff
changeset
|
143 rtsp_session->real_session->recv_read = 0; |
9922 | 144 } else |
145 { | |
18793 | 146 mp_msg (MSGT_OPEN, MSGL_ERR,"rtsp_session: Not a Real server. Server type is '%s'.\n",server); |
9922 | 147 rtsp_close(rtsp_session->s); |
148 free(server); | |
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 | |
18792
6a015ba5bf45
move real_rtsp init/uninit code to its dedicated place to simplify a bit rtsp session demuxer
ben
parents:
17351
diff
changeset
|
159 if (this->real_session) { |
9922 | 160 int to_copy=len; |
161 char *dest=data; | |
18792
6a015ba5bf45
move real_rtsp init/uninit code to its dedicated place to simplify a bit rtsp session demuxer
ben
parents:
17351
diff
changeset
|
162 char *source = |
6a015ba5bf45
move real_rtsp init/uninit code to its dedicated place to simplify a bit rtsp session demuxer
ben
parents:
17351
diff
changeset
|
163 (char *) (this->real_session->recv + this->real_session->recv_read); |
6a015ba5bf45
move real_rtsp init/uninit code to its dedicated place to simplify a bit rtsp session demuxer
ben
parents:
17351
diff
changeset
|
164 int fill = this->real_session->recv_size - this->real_session->recv_read; |
9922 | 165 |
166 if (len < 0) return 0; | |
167 while (to_copy > fill) { | |
168 | |
169 memcpy(dest, source, fill); | |
170 to_copy -= fill; | |
171 dest += fill; | |
18792
6a015ba5bf45
move real_rtsp init/uninit code to its dedicated place to simplify a bit rtsp session demuxer
ben
parents:
17351
diff
changeset
|
172 this->real_session->recv_read = 0; |
6a015ba5bf45
move real_rtsp init/uninit code to its dedicated place to simplify a bit rtsp session demuxer
ben
parents:
17351
diff
changeset
|
173 this->real_session->recv_size = |
6a015ba5bf45
move real_rtsp init/uninit code to its dedicated place to simplify a bit rtsp session demuxer
ben
parents:
17351
diff
changeset
|
174 real_get_rdt_chunk (this->s, (char **)&(this->real_session->recv)); |
6a015ba5bf45
move real_rtsp init/uninit code to its dedicated place to simplify a bit rtsp session demuxer
ben
parents:
17351
diff
changeset
|
175 if (this->real_session->recv_size < 0) |
13676 | 176 return -1; |
18792
6a015ba5bf45
move real_rtsp init/uninit code to its dedicated place to simplify a bit rtsp session demuxer
ben
parents:
17351
diff
changeset
|
177 source = (char *) this->real_session->recv; |
6a015ba5bf45
move real_rtsp init/uninit code to its dedicated place to simplify a bit rtsp session demuxer
ben
parents:
17351
diff
changeset
|
178 fill = this->real_session->recv_size; |
9922 | 179 |
18792
6a015ba5bf45
move real_rtsp init/uninit code to its dedicated place to simplify a bit rtsp session demuxer
ben
parents:
17351
diff
changeset
|
180 if (this->real_session->recv_size == 0) { |
9922 | 181 #ifdef LOG |
18793 | 182 mp_msg (MSGT_OPEN, MSGL_INFO, "librtsp: %d of %d bytes provided\n", len-to_copy, len); |
9922 | 183 #endif |
184 return len-to_copy; | |
185 } | |
186 } | |
187 | |
188 memcpy(dest, source, to_copy); | |
18792
6a015ba5bf45
move real_rtsp init/uninit code to its dedicated place to simplify a bit rtsp session demuxer
ben
parents:
17351
diff
changeset
|
189 this->real_session->recv_read += to_copy; |
9922 | 190 |
191 #ifdef LOG | |
18793 | 192 mp_msg (MSGT_OPEN, MSGL_INFO, "librtsp: %d bytes provided\n", len); |
9922 | 193 #endif |
194 | |
195 return len; | |
18792
6a015ba5bf45
move real_rtsp init/uninit code to its dedicated place to simplify a bit rtsp session demuxer
ben
parents:
17351
diff
changeset
|
196 } |
6a015ba5bf45
move real_rtsp init/uninit code to its dedicated place to simplify a bit rtsp session demuxer
ben
parents:
17351
diff
changeset
|
197 |
6a015ba5bf45
move real_rtsp init/uninit code to its dedicated place to simplify a bit rtsp session demuxer
ben
parents:
17351
diff
changeset
|
198 return 0; |
9922 | 199 } |
200 | |
201 void rtsp_session_end(rtsp_session_t *session) { | |
202 | |
203 rtsp_close(session->s); | |
18792
6a015ba5bf45
move real_rtsp init/uninit code to its dedicated place to simplify a bit rtsp session demuxer
ben
parents:
17351
diff
changeset
|
204 if (session->real_session) |
6a015ba5bf45
move real_rtsp init/uninit code to its dedicated place to simplify a bit rtsp session demuxer
ben
parents:
17351
diff
changeset
|
205 free_real_rtsp_session (session->real_session); |
9922 | 206 free(session); |
207 } |