2 * Copyright (C) 2006 Benjamin Zores
3 * based on previous Real RTSP support from Roberto Togni and xine team.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25 #include <sys/types.h>
29 #include <netinet/in.h>
30 #include <sys/socket.h>
31 #include <arpa/inet.h>
32 #define closesocket close
41 #include "librtsp/rtsp.h"
42 #include "librtsp/rtsp_session.h"
44 #define RTSP_DEFAULT_PORT 554
46 extern int network_bandwidth
;
49 rtsp_streaming_read (int fd
, char *buffer
,
50 int size
, streaming_ctrl_t
*stream_ctrl
)
52 return rtsp_session_read (stream_ctrl
->data
, buffer
, size
);
56 rtsp_streaming_start (stream_t
*stream
)
68 /* counter so we don't get caught in infinite redirections */
74 fd
= connect2Server (stream
->streaming_ctrl
->url
->hostname
,
75 port
= (stream
->streaming_ctrl
->url
->port
?
76 stream
->streaming_ctrl
->url
->port
:
77 RTSP_DEFAULT_PORT
), 1);
79 if (fd
< 0 && !stream
->streaming_ctrl
->url
->port
)
80 fd
= connect2Server (stream
->streaming_ctrl
->url
->hostname
,
86 file
= stream
->streaming_ctrl
->url
->file
;
90 mrl
= malloc (strlen (stream
->streaming_ctrl
->url
->hostname
)
91 + strlen (file
) + 16);
93 sprintf (mrl
, "rtsp://%s:%i/%s",
94 stream
->streaming_ctrl
->url
->hostname
, port
, file
);
96 rtsp
= rtsp_session_start (fd
, &mrl
, file
,
97 stream
->streaming_ctrl
->url
->hostname
,
99 stream
->streaming_ctrl
->bandwidth
,
100 stream
->streaming_ctrl
->url
->username
,
101 stream
->streaming_ctrl
->url
->password
);
105 url_free (stream
->streaming_ctrl
->url
);
106 stream
->streaming_ctrl
->url
= url_new (mrl
);
112 } while ((redirected
!= 0) && (temp
> 0));
118 stream
->streaming_ctrl
->data
= rtsp
;
120 stream
->streaming_ctrl
->streaming_read
= rtsp_streaming_read
;
121 stream
->streaming_ctrl
->streaming_seek
= NULL
;
122 stream
->streaming_ctrl
->prebuffer_size
= 128*1024; // 640 KBytes
123 stream
->streaming_ctrl
->buffering
= 1;
124 stream
->streaming_ctrl
->status
= streaming_playing_e
;
130 rtsp_streaming_close (struct stream
*s
)
132 rtsp_session_t
*rtsp
= NULL
;
134 rtsp
= (rtsp_session_t
*) s
->streaming_ctrl
->data
;
136 rtsp_session_end (rtsp
);
140 rtsp_streaming_open (stream_t
*stream
, int mode
, void *opts
, int *file_format
)
143 extern int index_mode
;
145 mp_msg (MSGT_OPEN
, MSGL_V
, "STREAM_RTSP, URL: %s\n", stream
->url
);
146 stream
->streaming_ctrl
= streaming_ctrl_new ();
147 if (!stream
->streaming_ctrl
)
150 stream
->streaming_ctrl
->bandwidth
= network_bandwidth
;
151 url
= url_new (stream
->url
);
152 stream
->streaming_ctrl
->url
= check4proxies (url
);
155 index_mode
= -1; /* prevent most RTSP streams from locking due to -idx */
156 if (rtsp_streaming_start (stream
) < 0)
158 streaming_ctrl_free (stream
->streaming_ctrl
);
159 stream
->streaming_ctrl
= NULL
;
160 return STREAM_UNSUPPORTED
;
163 fixup_network_stream_cache (stream
);
164 stream
->type
= STREAMTYPE_STREAM
;
165 stream
->close
= rtsp_streaming_close
;
170 const stream_info_t stream_info_rtsp
= {
173 "Benjamin Zores, Roberto Togni",
178 0 /* Urls are an option string */