2 * based on previous Real RTSP support from Roberto Togni and xine team.
4 * Copyright (C) 2006 Benjamin Zores
6 * This file is part of MPlayer.
8 * MPlayer is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * MPlayer is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
28 #include <sys/types.h>
32 #include <netinet/in.h>
33 #include <sys/socket.h>
34 #include <arpa/inet.h>
44 #include "librtsp/rtsp.h"
45 #include "librtsp/rtsp_session.h"
47 #define RTSP_DEFAULT_PORT 554
49 extern int network_bandwidth
;
52 rtsp_streaming_read (int fd
, char *buffer
,
53 int size
, streaming_ctrl_t
*stream_ctrl
)
55 return rtsp_session_read (stream_ctrl
->data
, buffer
, size
);
59 rtsp_streaming_start (stream_t
*stream
)
71 /* counter so we don't get caught in infinite redirections */
77 fd
= connect2Server (stream
->streaming_ctrl
->url
->hostname
,
78 port
= (stream
->streaming_ctrl
->url
->port
?
79 stream
->streaming_ctrl
->url
->port
:
80 RTSP_DEFAULT_PORT
), 1);
82 if (fd
< 0 && !stream
->streaming_ctrl
->url
->port
)
83 fd
= connect2Server (stream
->streaming_ctrl
->url
->hostname
,
89 file
= stream
->streaming_ctrl
->url
->file
;
93 mrl
= malloc (strlen (stream
->streaming_ctrl
->url
->hostname
)
94 + strlen (file
) + 16);
96 sprintf (mrl
, "rtsp://%s:%i/%s",
97 stream
->streaming_ctrl
->url
->hostname
, port
, file
);
99 rtsp
= rtsp_session_start (fd
, &mrl
, file
,
100 stream
->streaming_ctrl
->url
->hostname
,
102 stream
->streaming_ctrl
->bandwidth
,
103 stream
->streaming_ctrl
->url
->username
,
104 stream
->streaming_ctrl
->url
->password
);
108 url_free (stream
->streaming_ctrl
->url
);
109 stream
->streaming_ctrl
->url
= url_new (mrl
);
115 } while ((redirected
!= 0) && (temp
> 0));
121 stream
->streaming_ctrl
->data
= rtsp
;
123 stream
->streaming_ctrl
->streaming_read
= rtsp_streaming_read
;
124 stream
->streaming_ctrl
->streaming_seek
= NULL
;
125 stream
->streaming_ctrl
->prebuffer_size
= 128*1024; // 640 KBytes
126 stream
->streaming_ctrl
->buffering
= 1;
127 stream
->streaming_ctrl
->status
= streaming_playing_e
;
133 rtsp_streaming_close (struct stream
*s
)
135 rtsp_session_t
*rtsp
= NULL
;
137 rtsp
= (rtsp_session_t
*) s
->streaming_ctrl
->data
;
139 rtsp_session_end (rtsp
);
143 rtsp_streaming_open (stream_t
*stream
, int mode
, void *opts
, int *file_format
)
146 extern int index_mode
;
148 mp_msg (MSGT_OPEN
, MSGL_V
, "STREAM_RTSP, URL: %s\n", stream
->url
);
149 stream
->streaming_ctrl
= streaming_ctrl_new ();
150 if (!stream
->streaming_ctrl
)
153 stream
->streaming_ctrl
->bandwidth
= network_bandwidth
;
154 url
= url_new (stream
->url
);
155 stream
->streaming_ctrl
->url
= check4proxies (url
);
158 index_mode
= -1; /* prevent most RTSP streams from locking due to -idx */
159 if (rtsp_streaming_start (stream
) < 0)
161 streaming_ctrl_free (stream
->streaming_ctrl
);
162 stream
->streaming_ctrl
= NULL
;
163 return STREAM_UNSUPPORTED
;
166 fixup_network_stream_cache (stream
);
167 stream
->type
= STREAMTYPE_STREAM
;
168 stream
->close
= rtsp_streaming_close
;
173 const stream_info_t stream_info_rtsp
= {
176 "Benjamin Zores, Roberto Togni",
181 0 /* Urls are an option string */