Mercurial > mplayer.hg
comparison stream/stream_rtsp.c @ 19271:64d82a45a05d
introduce new 'stream' directory for all stream layer related components and split them from libmpdemux
author | ben |
---|---|
date | Mon, 31 Jul 2006 17:39:17 +0000 |
parents | libmpdemux/stream_rtsp.c@188225d6ba3f |
children | 2a9d669e5ff6 |
comparison
equal
deleted
inserted
replaced
19270:7d39b911f0bd | 19271:64d82a45a05d |
---|---|
1 /* | |
2 * Copyright (C) 2006 Benjamin Zores | |
3 * based on previous Real RTSP support from Roberto Togni and xine team. | |
4 * | |
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. | |
9 * | |
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. | |
14 * | |
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 | |
18 */ | |
19 | |
20 #include <stdlib.h> | |
21 #include <string.h> | |
22 #include <unistd.h> | |
23 #include <stdlib.h> | |
24 #include <stdio.h> | |
25 #include <sys/types.h> | |
26 #include <ctype.h> | |
27 #include "config.h" | |
28 #ifndef HAVE_WINSOCK2 | |
29 #include <netinet/in.h> | |
30 #include <sys/socket.h> | |
31 #include <arpa/inet.h> | |
32 #define closesocket close | |
33 #else | |
34 #include <winsock2.h> | |
35 #include <ws2tcpip.h> | |
36 #endif | |
37 #include <errno.h> | |
38 | |
39 #include "stream.h" | |
40 #include "librtsp/rtsp.h" | |
41 #include "librtsp/rtsp_session.h" | |
42 | |
43 #define RTSP_DEFAULT_PORT 554 | |
44 | |
45 extern int network_bandwidth; | |
46 | |
47 static int | |
48 rtsp_streaming_read (int fd, char *buffer, | |
49 int size, streaming_ctrl_t *stream_ctrl) | |
50 { | |
51 return rtsp_session_read (stream_ctrl->data, buffer, size); | |
52 } | |
53 | |
54 static int | |
55 rtsp_streaming_start (stream_t *stream) | |
56 { | |
57 int fd; | |
58 rtsp_session_t *rtsp; | |
59 char *mrl; | |
60 char *file; | |
61 int port; | |
62 int redirected, temp; | |
63 | |
64 if (!stream) | |
65 return -1; | |
66 | |
67 /* counter so we don't get caught in infinite redirections */ | |
68 temp = 5; | |
69 | |
70 do { | |
71 redirected = 0; | |
72 | |
73 fd = connect2Server (stream->streaming_ctrl->url->hostname, | |
74 port = (stream->streaming_ctrl->url->port ? | |
75 stream->streaming_ctrl->url->port : | |
76 RTSP_DEFAULT_PORT), 1); | |
77 | |
78 if (fd < 0 && !stream->streaming_ctrl->url->port) | |
79 fd = connect2Server (stream->streaming_ctrl->url->hostname, | |
80 port = 7070, 1); | |
81 | |
82 if (fd < 0) | |
83 return -1; | |
84 | |
85 file = stream->streaming_ctrl->url->file; | |
86 if (file[0] == '/') | |
87 file++; | |
88 | |
89 mrl = malloc (strlen (stream->streaming_ctrl->url->hostname) | |
90 + strlen (file) + 16); | |
91 | |
92 sprintf (mrl, "rtsp://%s:%i/%s", | |
93 stream->streaming_ctrl->url->hostname, port, file); | |
94 | |
95 rtsp = rtsp_session_start (fd, &mrl, file, | |
96 stream->streaming_ctrl->url->hostname, | |
97 port, &redirected, | |
98 stream->streaming_ctrl->bandwidth); | |
99 | |
100 if (redirected == 1) | |
101 { | |
102 url_free (stream->streaming_ctrl->url); | |
103 stream->streaming_ctrl->url = url_new (mrl); | |
104 closesocket (fd); | |
105 } | |
106 | |
107 free (mrl); | |
108 temp--; | |
109 } while ((redirected != 0) && (temp > 0)); | |
110 | |
111 if (!rtsp) | |
112 return -1; | |
113 | |
114 stream->fd = fd; | |
115 stream->streaming_ctrl->data = rtsp; | |
116 | |
117 stream->streaming_ctrl->streaming_read = rtsp_streaming_read; | |
118 stream->streaming_ctrl->streaming_seek = NULL; | |
119 stream->streaming_ctrl->prebuffer_size = 128*1024; // 640 KBytes | |
120 stream->streaming_ctrl->buffering = 1; | |
121 stream->streaming_ctrl->status = streaming_playing_e; | |
122 | |
123 return 0; | |
124 } | |
125 | |
126 static void | |
127 rtsp_streaming_close (struct stream_st *s) | |
128 { | |
129 rtsp_session_t *rtsp = NULL; | |
130 | |
131 rtsp = (rtsp_session_t *) s->streaming_ctrl->data; | |
132 if (rtsp) | |
133 rtsp_session_end (rtsp); | |
134 } | |
135 | |
136 static int | |
137 rtsp_streaming_open (stream_t *stream, int mode, void *opts, int *file_format) | |
138 { | |
139 URL_t *url; | |
140 extern int index_mode; | |
141 | |
142 mp_msg (MSGT_OPEN, MSGL_INFO, "STREAM_RTSP, URL: %s\n", stream->url); | |
143 stream->streaming_ctrl = streaming_ctrl_new (); | |
144 if (!stream->streaming_ctrl) | |
145 return STREAM_ERROR; | |
146 | |
147 stream->streaming_ctrl->bandwidth = network_bandwidth; | |
148 url = url_new (stream->url); | |
149 stream->streaming_ctrl->url = check4proxies (url); | |
150 | |
151 stream->fd = -1; | |
152 index_mode = -1; /* prevent most RTSP streams from locking due to -idx */ | |
153 if (rtsp_streaming_start (stream) < 0) | |
154 { | |
155 streaming_ctrl_free (stream->streaming_ctrl); | |
156 stream->streaming_ctrl = NULL; | |
157 return STREAM_UNSUPORTED; | |
158 } | |
159 | |
160 fixup_network_stream_cache (stream); | |
161 stream->type = STREAMTYPE_STREAM; | |
162 stream->close = rtsp_streaming_close; | |
163 | |
164 return STREAM_OK; | |
165 } | |
166 | |
167 stream_info_t stream_info_rtsp = { | |
168 "RTSP streaming", | |
169 "rtsp", | |
170 "Benjamin Zores, Roberto Togni", | |
171 "ported from xine", | |
172 rtsp_streaming_open, | |
173 {"rtsp", NULL}, | |
174 NULL, | |
175 0 /* Urls are an option string */ | |
176 }; |