Give better name to Inverse_Table_6_9
[mplayer/glamo.git] / stream / stream_rtsp.c
blob591fc1765a20b13cbb6ca3adc8409a111182f843
1 /*
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.
23 #include <stdlib.h>
24 #include <string.h>
25 #include <unistd.h>
26 #include <stdlib.h>
27 #include <stdio.h>
28 #include <sys/types.h>
29 #include <ctype.h>
30 #include "config.h"
31 #if !HAVE_WINSOCK2_H
32 #include <netinet/in.h>
33 #include <sys/socket.h>
34 #include <arpa/inet.h>
35 #else
36 #include <winsock2.h>
37 #include <ws2tcpip.h>
38 #endif
39 #include <errno.h>
41 #include "network.h"
42 #include "stream.h"
43 #include "tcp.h"
44 #include "librtsp/rtsp.h"
45 #include "librtsp/rtsp_session.h"
47 #define RTSP_DEFAULT_PORT 554
49 extern int network_bandwidth;
51 static int
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);
58 static int
59 rtsp_streaming_start (stream_t *stream)
61 int fd;
62 rtsp_session_t *rtsp;
63 char *mrl;
64 char *file;
65 int port;
66 int redirected, temp;
68 if (!stream)
69 return -1;
71 /* counter so we don't get caught in infinite redirections */
72 temp = 5;
74 do {
75 redirected = 0;
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,
84 port = 7070, 1);
86 if (fd < 0)
87 return -1;
89 file = stream->streaming_ctrl->url->file;
90 if (file[0] == '/')
91 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,
101 port, &redirected,
102 stream->streaming_ctrl->bandwidth,
103 stream->streaming_ctrl->url->username,
104 stream->streaming_ctrl->url->password);
106 if (redirected == 1)
108 url_free (stream->streaming_ctrl->url);
109 stream->streaming_ctrl->url = url_new (mrl);
110 closesocket (fd);
113 free (mrl);
114 temp--;
115 } while ((redirected != 0) && (temp > 0));
117 if (!rtsp)
118 return -1;
120 stream->fd = fd;
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;
129 return 0;
132 static void
133 rtsp_streaming_close (struct stream_st *s)
135 rtsp_session_t *rtsp = NULL;
137 rtsp = (rtsp_session_t *) s->streaming_ctrl->data;
138 if (rtsp)
139 rtsp_session_end (rtsp);
142 static int
143 rtsp_streaming_open (stream_t *stream, int mode, void *opts, int *file_format)
145 URL_t *url;
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)
151 return STREAM_ERROR;
153 stream->streaming_ctrl->bandwidth = network_bandwidth;
154 url = url_new (stream->url);
155 stream->streaming_ctrl->url = check4proxies (url);
157 stream->fd = -1;
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;
170 return STREAM_OK;
173 const stream_info_t stream_info_rtsp = {
174 "RTSP streaming",
175 "rtsp",
176 "Benjamin Zores, Roberto Togni",
177 "ported from xine",
178 rtsp_streaming_open,
179 {"rtsp", NULL},
180 NULL,
181 0 /* Urls are an option string */