Mercurial > libavformat.hg
annotate rtsp.c @ 3959:ed6f6aa977ec libavformat
Remove access to rdt_data struct in functions called outside of the
DynamicProtocol* context. Doing so could lead to problems if we're accessing
Real servers serving non-RDT data (or the other way around). Temporarily,
this patch adds a _subscribe2() function which will soon be removed in one
of the subsequent commits. OK'ed by Luca in "Realmedia patch" thread on ML.
author | rbultje |
---|---|
date | Tue, 30 Sep 2008 13:23:33 +0000 |
parents | ab2d2bc3a6e7 |
children | 13e9b0d3a314 |
rev | line source |
---|---|
0 | 1 /* |
2 * RTSP/SDP client | |
3 * Copyright (c) 2002 Fabrice Bellard. | |
4 * | |
1358
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1169
diff
changeset
|
5 * This file is part of FFmpeg. |
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1169
diff
changeset
|
6 * |
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1169
diff
changeset
|
7 * FFmpeg is free software; you can redistribute it and/or |
0 | 8 * modify it under the terms of the GNU Lesser General Public |
9 * License as published by the Free Software Foundation; either | |
1358
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1169
diff
changeset
|
10 * version 2.1 of the License, or (at your option) any later version. |
0 | 11 * |
1358
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1169
diff
changeset
|
12 * FFmpeg is distributed in the hope that it will be useful, |
0 | 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 * Lesser General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU Lesser General Public | |
1358
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1169
diff
changeset
|
18 * License along with FFmpeg; if not, write to the Free Software |
896
edbe5c3717f9
Update licensing information: The FSF changed postal address.
diego
parents:
887
diff
changeset
|
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
0 | 20 */ |
3286 | 21 |
3722
68749aaea50f
ensure we get explicit definition of various _XOPEN_SOURCE functions we use
aurel
parents:
3714
diff
changeset
|
22 /* needed by inet_aton() */ |
68749aaea50f
ensure we get explicit definition of various _XOPEN_SOURCE functions we use
aurel
parents:
3714
diff
changeset
|
23 #define _SVID_SOURCE |
68749aaea50f
ensure we get explicit definition of various _XOPEN_SOURCE functions we use
aurel
parents:
3714
diff
changeset
|
24 |
3286 | 25 #include "libavutil/avstring.h" |
0 | 26 #include "avformat.h" |
27 | |
1808
572ce77d7333
Fix compilation on Mac OS X, patch by Marc Hoffman, mmh pleasantst com.
diego
parents:
1754
diff
changeset
|
28 #include <sys/time.h> |
3941
53c5b89b8dff
only include sys/select.h if present, fix mingw compilation
bcoudurier
parents:
3936
diff
changeset
|
29 #ifdef HAVE_SYS_SELECT_H |
3936
6154f62ef652
include sys/select.h instead of unistd.h to get select,
bcoudurier
parents:
3924
diff
changeset
|
30 #include <sys/select.h> |
3941
53c5b89b8dff
only include sys/select.h if present, fix mingw compilation
bcoudurier
parents:
3936
diff
changeset
|
31 #endif |
3714 | 32 #include <strings.h> |
1754 | 33 #include "network.h" |
2681
6037eb4919fb
Remove the inclusion of rtsp.h and rtp.h from avformat.h, and
lucabe
parents:
2408
diff
changeset
|
34 #include "rtsp.h" |
0 | 35 |
1419 | 36 #include "rtp_internal.h" |
3876
1026953d4ffe
Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
3861
diff
changeset
|
37 #include "rdt.h" |
1419 | 38 |
0 | 39 //#define DEBUG |
172 | 40 //#define DEBUG_RTP_TCP |
0 | 41 |
304
d58c8859ff8c
initial seek support - more generic play/pause support
bellard
parents:
294
diff
changeset
|
42 enum RTSPClientState { |
d58c8859ff8c
initial seek support - more generic play/pause support
bellard
parents:
294
diff
changeset
|
43 RTSP_STATE_IDLE, |
d58c8859ff8c
initial seek support - more generic play/pause support
bellard
parents:
294
diff
changeset
|
44 RTSP_STATE_PLAYING, |
d58c8859ff8c
initial seek support - more generic play/pause support
bellard
parents:
294
diff
changeset
|
45 RTSP_STATE_PAUSED, |
d58c8859ff8c
initial seek support - more generic play/pause support
bellard
parents:
294
diff
changeset
|
46 }; |
d58c8859ff8c
initial seek support - more generic play/pause support
bellard
parents:
294
diff
changeset
|
47 |
3854
8b2b84b5ef74
Implement RTSPServerType enum as a way to identify the flavour of RTSP that
rbultje
parents:
3853
diff
changeset
|
48 enum RTSPServerType { |
3924 | 49 RTSP_SERVER_RTP, /*< Standard-compliant RTP-server */ |
3923
83e51bcb03c2
Rename RTSP_SERVER_RDT to RTSP_SERVER_REAL, because RDT (the transport
rbultje
parents:
3920
diff
changeset
|
50 RTSP_SERVER_REAL, /*< Realmedia-style server */ |
3854
8b2b84b5ef74
Implement RTSPServerType enum as a way to identify the flavour of RTSP that
rbultje
parents:
3853
diff
changeset
|
51 RTSP_SERVER_LAST |
8b2b84b5ef74
Implement RTSPServerType enum as a way to identify the flavour of RTSP that
rbultje
parents:
3853
diff
changeset
|
52 }; |
8b2b84b5ef74
Implement RTSPServerType enum as a way to identify the flavour of RTSP that
rbultje
parents:
3853
diff
changeset
|
53 |
0 | 54 typedef struct RTSPState { |
55 URLContext *rtsp_hd; /* RTSP TCP connexion handle */ | |
294
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
229
diff
changeset
|
56 int nb_rtsp_streams; |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
229
diff
changeset
|
57 struct RTSPStream **rtsp_streams; |
885 | 58 |
304
d58c8859ff8c
initial seek support - more generic play/pause support
bellard
parents:
294
diff
changeset
|
59 enum RTSPClientState state; |
d58c8859ff8c
initial seek support - more generic play/pause support
bellard
parents:
294
diff
changeset
|
60 int64_t seek_timestamp; |
885 | 61 |
172 | 62 /* XXX: currently we use unbuffered input */ |
63 // ByteIOContext rtsp_gb; | |
0 | 64 int seq; /* RTSP command sequence number */ |
65 char session_id[512]; | |
3957
9f943bb755f9
Rename RTSPProtocol to RTSPLowerTransport, so that its name properly tells us
rbultje
parents:
3941
diff
changeset
|
66 enum RTSPLowerTransport lower_transport; |
3854
8b2b84b5ef74
Implement RTSPServerType enum as a way to identify the flavour of RTSP that
rbultje
parents:
3853
diff
changeset
|
67 enum RTSPServerType server_type; |
0 | 68 char last_reply[2048]; /* XXX: allocate ? */ |
294
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
229
diff
changeset
|
69 RTPDemuxContext *cur_rtp; |
3903
aeb79f68ba7e
Implement a RDT-specific SET_PARAMETER command that subscribes to the
rbultje
parents:
3877
diff
changeset
|
70 int need_subscription; |
0 | 71 } RTSPState; |
72 | |
73 typedef struct RTSPStream { | |
294
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
229
diff
changeset
|
74 URLContext *rtp_handle; /* RTP stream handle */ |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
229
diff
changeset
|
75 RTPDemuxContext *rtp_ctx; /* RTP parse context */ |
885 | 76 |
294
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
229
diff
changeset
|
77 int stream_index; /* corresponding stream index, if any. -1 if none (MPEG2TS case) */ |
0 | 78 int interleaved_min, interleaved_max; /* interleave ids, if TCP transport */ |
79 char control_url[1024]; /* url for this stream (from SDP) */ | |
80 | |
81 int sdp_port; /* port (from SDP content - not used in RTSP) */ | |
82 struct in_addr sdp_ip; /* IP address (from SDP content - not used in RTSP) */ | |
83 int sdp_ttl; /* IP TTL (from SDP content - not used in RTSP) */ | |
84 int sdp_payload_type; /* payload type - only used in SDP */ | |
774 | 85 rtp_payload_data_t rtp_payload_data; /* rtp payload parsing infos from SDP */ |
1419 | 86 |
87 RTPDynamicProtocolHandler *dynamic_handler; ///< Only valid if it's a dynamic protocol. (This is the handler structure) | |
88 void *dynamic_protocol_context; ///< Only valid if it's a dynamic protocol. (This is any private data associated with the dynamic protocol) | |
0 | 89 } RTSPStream; |
90 | |
304
d58c8859ff8c
initial seek support - more generic play/pause support
bellard
parents:
294
diff
changeset
|
91 static int rtsp_read_play(AVFormatContext *s); |
d58c8859ff8c
initial seek support - more generic play/pause support
bellard
parents:
294
diff
changeset
|
92 |
0 | 93 /* XXX: currently, the only way to change the protocols consists in |
94 changing this variable */ | |
95 | |
2884 | 96 #if LIBAVFORMAT_VERSION_INT < (53 << 16) |
3957
9f943bb755f9
Rename RTSPProtocol to RTSPLowerTransport, so that its name properly tells us
rbultje
parents:
3941
diff
changeset
|
97 int rtsp_default_protocols = (1 << RTSP_LOWER_TRANSPORT_UDP); |
2884 | 98 #endif |
0 | 99 |
100 static int rtsp_probe(AVProbeData *p) | |
101 { | |
2193
5ce5fad0dfac
replace the uses of old string functions that Reimar missed
mru
parents:
2189
diff
changeset
|
102 if (av_strstart(p->filename, "rtsp:", NULL)) |
0 | 103 return AVPROBE_SCORE_MAX; |
104 return 0; | |
105 } | |
106 | |
107 static int redir_isspace(int c) | |
108 { | |
3278 | 109 return c == ' ' || c == '\t' || c == '\n' || c == '\r'; |
0 | 110 } |
111 | |
112 static void skip_spaces(const char **pp) | |
113 { | |
114 const char *p; | |
115 p = *pp; | |
116 while (redir_isspace(*p)) | |
117 p++; | |
118 *pp = p; | |
119 } | |
120 | |
885 | 121 static void get_word_sep(char *buf, int buf_size, const char *sep, |
0 | 122 const char **pp) |
123 { | |
124 const char *p; | |
125 char *q; | |
126 | |
127 p = *pp; | |
774 | 128 if (*p == '/') |
129 p++; | |
0 | 130 skip_spaces(&p); |
131 q = buf; | |
132 while (!strchr(sep, *p) && *p != '\0') { | |
133 if ((q - buf) < buf_size - 1) | |
134 *q++ = *p; | |
135 p++; | |
136 } | |
137 if (buf_size > 0) | |
138 *q = '\0'; | |
139 *pp = p; | |
140 } | |
141 | |
142 static void get_word(char *buf, int buf_size, const char **pp) | |
143 { | |
144 const char *p; | |
145 char *q; | |
146 | |
147 p = *pp; | |
148 skip_spaces(&p); | |
149 q = buf; | |
150 while (!redir_isspace(*p) && *p != '\0') { | |
151 if ((q - buf) < buf_size - 1) | |
152 *q++ = *p; | |
153 p++; | |
154 } | |
155 if (buf_size > 0) | |
156 *q = '\0'; | |
157 *pp = p; | |
158 } | |
159 | |
160 /* parse the rtpmap description: <codec_name>/<clock_rate>[/<other | |
161 params>] */ | |
1419 | 162 static int sdp_parse_rtpmap(AVCodecContext *codec, RTSPStream *rtsp_st, int payload_type, const char *p) |
0 | 163 { |
164 char buf[256]; | |
774 | 165 int i; |
166 AVCodec *c; | |
1124
d3aff2c607f9
Add const to (mostly) char* and make some functions static, which aren't used
diego
parents:
1003
diff
changeset
|
167 const char *c_name; |
0 | 168 |
774 | 169 /* Loop into AVRtpDynamicPayloadTypes[] and AVRtpPayloadTypes[] and |
170 see if we can handle this kind of payload */ | |
0 | 171 get_word_sep(buf, sizeof(buf), "/", &p); |
774 | 172 if (payload_type >= RTP_PT_PRIVATE) { |
1419 | 173 RTPDynamicProtocolHandler *handler= RTPFirstDynamicPayloadHandler; |
174 while(handler) { | |
175 if (!strcmp(buf, handler->enc_name) && (codec->codec_type == handler->codec_type)) { | |
176 codec->codec_id = handler->codec_id; | |
177 rtsp_st->dynamic_handler= handler; | |
178 if(handler->open) { | |
179 rtsp_st->dynamic_protocol_context= handler->open(); | |
180 } | |
774 | 181 break; |
182 } | |
1419 | 183 handler= handler->next; |
184 } | |
774 | 185 } else { |
186 /* We are in a standard case ( from http://www.iana.org/assignments/rtp-parameters) */ | |
187 /* search into AVRtpPayloadTypes[] */ | |
2759
b252e318023a
Remove the "AVRtpPayloadTypes[i].pt == i" assumption from RTP and RTSP
lucabe
parents:
2711
diff
changeset
|
188 codec->codec_id = ff_rtp_codec_id(buf, codec->codec_type); |
774 | 189 } |
190 | |
191 c = avcodec_find_decoder(codec->codec_id); | |
192 if (c && c->name) | |
1124
d3aff2c607f9
Add const to (mostly) char* and make some functions static, which aren't used
diego
parents:
1003
diff
changeset
|
193 c_name = c->name; |
774 | 194 else |
195 c_name = (char *)NULL; | |
196 | |
197 if (c_name) { | |
198 get_word_sep(buf, sizeof(buf), "/", &p); | |
199 i = atoi(buf); | |
200 switch (codec->codec_type) { | |
201 case CODEC_TYPE_AUDIO: | |
202 av_log(codec, AV_LOG_DEBUG, " audio codec set to : %s\n", c_name); | |
203 codec->sample_rate = RTSP_DEFAULT_AUDIO_SAMPLERATE; | |
204 codec->channels = RTSP_DEFAULT_NB_AUDIO_CHANNELS; | |
205 if (i > 0) { | |
206 codec->sample_rate = i; | |
207 get_word_sep(buf, sizeof(buf), "/", &p); | |
208 i = atoi(buf); | |
209 if (i > 0) | |
210 codec->channels = i; | |
1431
2d8a17631520
fix more dynamic protocol stuff, needed by the forthcoming h264
gpoirier
parents:
1425
diff
changeset
|
211 // TODO: there is a bug here; if it is a mono stream, and less than 22000Hz, faad upconverts to stereo and twice the |
2d8a17631520
fix more dynamic protocol stuff, needed by the forthcoming h264
gpoirier
parents:
1425
diff
changeset
|
212 // frequency. No problem, but the sample rate is being set here by the sdp line. Upcoming patch forthcoming. (rdm) |
774 | 213 } |
214 av_log(codec, AV_LOG_DEBUG, " audio samplerate set to : %i\n", codec->sample_rate); | |
215 av_log(codec, AV_LOG_DEBUG, " audio channels set to : %i\n", codec->channels); | |
216 break; | |
217 case CODEC_TYPE_VIDEO: | |
218 av_log(codec, AV_LOG_DEBUG, " video codec set to : %s\n", c_name); | |
219 break; | |
220 default: | |
221 break; | |
222 } | |
0 | 223 return 0; |
224 } | |
774 | 225 |
226 return -1; | |
0 | 227 } |
228 | |
229 /* return the length and optionnaly the data */ | |
230 static int hex_to_data(uint8_t *data, const char *p) | |
231 { | |
232 int c, len, v; | |
233 | |
234 len = 0; | |
235 v = 1; | |
236 for(;;) { | |
237 skip_spaces(&p); | |
238 if (p == '\0') | |
239 break; | |
240 c = toupper((unsigned char)*p++); | |
241 if (c >= '0' && c <= '9') | |
242 c = c - '0'; | |
243 else if (c >= 'A' && c <= 'F') | |
244 c = c - 'A' + 10; | |
245 else | |
246 break; | |
247 v = (v << 4) | c; | |
248 if (v & 0x100) { | |
249 if (data) | |
250 data[len] = v; | |
251 len++; | |
252 v = 1; | |
253 } | |
254 } | |
255 return len; | |
256 } | |
257 | |
774 | 258 static void sdp_parse_fmtp_config(AVCodecContext *codec, char *attr, char *value) |
259 { | |
260 switch (codec->codec_id) { | |
261 case CODEC_ID_MPEG4: | |
1472
49d5a5ca2987
get rid of CODEC_ID_MPEG4AAC after next version bump, and change it to CODEC_ID_AAC where used
bcoudurier
parents:
1453
diff
changeset
|
262 case CODEC_ID_AAC: |
774 | 263 if (!strcmp(attr, "config")) { |
264 /* decode the hexa encoded parameter */ | |
265 int len = hex_to_data(NULL, value); | |
266 codec->extradata = av_mallocz(len + FF_INPUT_BUFFER_PADDING_SIZE); | |
267 if (!codec->extradata) | |
268 return; | |
269 codec->extradata_size = len; | |
270 hex_to_data(codec->extradata, value); | |
271 } | |
272 break; | |
273 default: | |
274 break; | |
275 } | |
276 return; | |
277 } | |
278 | |
279 typedef struct attrname_map | |
280 { | |
1124
d3aff2c607f9
Add const to (mostly) char* and make some functions static, which aren't used
diego
parents:
1003
diff
changeset
|
281 const char *str; |
774 | 282 uint16_t type; |
283 uint32_t offset; | |
284 } attrname_map_t; | |
285 | |
286 /* All known fmtp parmeters and the corresping RTPAttrTypeEnum */ | |
287 #define ATTR_NAME_TYPE_INT 0 | |
288 #define ATTR_NAME_TYPE_STR 1 | |
289 static attrname_map_t attr_names[]= | |
290 { | |
291 {"SizeLength", ATTR_NAME_TYPE_INT, offsetof(rtp_payload_data_t, sizelength)}, | |
292 {"IndexLength", ATTR_NAME_TYPE_INT, offsetof(rtp_payload_data_t, indexlength)}, | |
293 {"IndexDeltaLength", ATTR_NAME_TYPE_INT, offsetof(rtp_payload_data_t, indexdeltalength)}, | |
294 {"profile-level-id", ATTR_NAME_TYPE_INT, offsetof(rtp_payload_data_t, profile_level_id)}, | |
295 {"StreamType", ATTR_NAME_TYPE_INT, offsetof(rtp_payload_data_t, streamtype)}, | |
296 {"mode", ATTR_NAME_TYPE_STR, offsetof(rtp_payload_data_t, mode)}, | |
297 {NULL, -1, -1}, | |
298 }; | |
299 | |
1431
2d8a17631520
fix more dynamic protocol stuff, needed by the forthcoming h264
gpoirier
parents:
1425
diff
changeset
|
300 /** parse the attribute line from the fmtp a line of an sdp resonse. This is broken out as a function |
2d8a17631520
fix more dynamic protocol stuff, needed by the forthcoming h264
gpoirier
parents:
1425
diff
changeset
|
301 * because it is used in rtp_h264.c, which is forthcoming. |
2d8a17631520
fix more dynamic protocol stuff, needed by the forthcoming h264
gpoirier
parents:
1425
diff
changeset
|
302 */ |
2d8a17631520
fix more dynamic protocol stuff, needed by the forthcoming h264
gpoirier
parents:
1425
diff
changeset
|
303 int rtsp_next_attr_and_value(const char **p, char *attr, int attr_size, char *value, int value_size) |
2d8a17631520
fix more dynamic protocol stuff, needed by the forthcoming h264
gpoirier
parents:
1425
diff
changeset
|
304 { |
2d8a17631520
fix more dynamic protocol stuff, needed by the forthcoming h264
gpoirier
parents:
1425
diff
changeset
|
305 skip_spaces(p); |
2d8a17631520
fix more dynamic protocol stuff, needed by the forthcoming h264
gpoirier
parents:
1425
diff
changeset
|
306 if(**p) |
2d8a17631520
fix more dynamic protocol stuff, needed by the forthcoming h264
gpoirier
parents:
1425
diff
changeset
|
307 { |
2d8a17631520
fix more dynamic protocol stuff, needed by the forthcoming h264
gpoirier
parents:
1425
diff
changeset
|
308 get_word_sep(attr, attr_size, "=", p); |
2d8a17631520
fix more dynamic protocol stuff, needed by the forthcoming h264
gpoirier
parents:
1425
diff
changeset
|
309 if (**p == '=') |
2d8a17631520
fix more dynamic protocol stuff, needed by the forthcoming h264
gpoirier
parents:
1425
diff
changeset
|
310 (*p)++; |
2d8a17631520
fix more dynamic protocol stuff, needed by the forthcoming h264
gpoirier
parents:
1425
diff
changeset
|
311 get_word_sep(value, value_size, ";", p); |
2d8a17631520
fix more dynamic protocol stuff, needed by the forthcoming h264
gpoirier
parents:
1425
diff
changeset
|
312 if (**p == ';') |
2d8a17631520
fix more dynamic protocol stuff, needed by the forthcoming h264
gpoirier
parents:
1425
diff
changeset
|
313 (*p)++; |
2d8a17631520
fix more dynamic protocol stuff, needed by the forthcoming h264
gpoirier
parents:
1425
diff
changeset
|
314 return 1; |
2d8a17631520
fix more dynamic protocol stuff, needed by the forthcoming h264
gpoirier
parents:
1425
diff
changeset
|
315 } |
2d8a17631520
fix more dynamic protocol stuff, needed by the forthcoming h264
gpoirier
parents:
1425
diff
changeset
|
316 return 0; |
2d8a17631520
fix more dynamic protocol stuff, needed by the forthcoming h264
gpoirier
parents:
1425
diff
changeset
|
317 } |
2d8a17631520
fix more dynamic protocol stuff, needed by the forthcoming h264
gpoirier
parents:
1425
diff
changeset
|
318 |
774 | 319 /* parse a SDP line and save stream attributes */ |
320 static void sdp_parse_fmtp(AVStream *st, const char *p) | |
0 | 321 { |
322 char attr[256]; | |
323 char value[4096]; | |
774 | 324 int i; |
325 | |
326 RTSPStream *rtsp_st = st->priv_data; | |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
774
diff
changeset
|
327 AVCodecContext *codec = st->codec; |
774 | 328 rtp_payload_data_t *rtp_payload_data = &rtsp_st->rtp_payload_data; |
0 | 329 |
330 /* loop on each attribute */ | |
1514
958decd51c1f
remove duplicate code, patch by Ryan Martell rdm4 A martellventures P com
gpoirier
parents:
1472
diff
changeset
|
331 while(rtsp_next_attr_and_value(&p, attr, sizeof(attr), value, sizeof(value))) |
958decd51c1f
remove duplicate code, patch by Ryan Martell rdm4 A martellventures P com
gpoirier
parents:
1472
diff
changeset
|
332 { |
887 | 333 /* grab the codec extra_data from the config parameter of the fmtp line */ |
774 | 334 sdp_parse_fmtp_config(codec, attr, value); |
335 /* Looking for a known attribute */ | |
336 for (i = 0; attr_names[i].str; ++i) { | |
337 if (!strcasecmp(attr, attr_names[i].str)) { | |
338 if (attr_names[i].type == ATTR_NAME_TYPE_INT) | |
339 *(int *)((char *)rtp_payload_data + attr_names[i].offset) = atoi(value); | |
340 else if (attr_names[i].type == ATTR_NAME_TYPE_STR) | |
341 *(char **)((char *)rtp_payload_data + attr_names[i].offset) = av_strdup(value); | |
887 | 342 } |
0 | 343 } |
344 } | |
345 } | |
346 | |
1453
c0235bab9e92
Add support for getting duration of a RTP stream (for seeking in stream)
gpoirier
parents:
1431
diff
changeset
|
347 /** Parse a string \p in the form of Range:npt=xx-xx, and determine the start |
c0235bab9e92
Add support for getting duration of a RTP stream (for seeking in stream)
gpoirier
parents:
1431
diff
changeset
|
348 * and end time. |
c0235bab9e92
Add support for getting duration of a RTP stream (for seeking in stream)
gpoirier
parents:
1431
diff
changeset
|
349 * Used for seeking in the rtp stream. |
c0235bab9e92
Add support for getting duration of a RTP stream (for seeking in stream)
gpoirier
parents:
1431
diff
changeset
|
350 */ |
c0235bab9e92
Add support for getting duration of a RTP stream (for seeking in stream)
gpoirier
parents:
1431
diff
changeset
|
351 static void rtsp_parse_range_npt(const char *p, int64_t *start, int64_t *end) |
c0235bab9e92
Add support for getting duration of a RTP stream (for seeking in stream)
gpoirier
parents:
1431
diff
changeset
|
352 { |
c0235bab9e92
Add support for getting duration of a RTP stream (for seeking in stream)
gpoirier
parents:
1431
diff
changeset
|
353 char buf[256]; |
c0235bab9e92
Add support for getting duration of a RTP stream (for seeking in stream)
gpoirier
parents:
1431
diff
changeset
|
354 |
c0235bab9e92
Add support for getting duration of a RTP stream (for seeking in stream)
gpoirier
parents:
1431
diff
changeset
|
355 skip_spaces(&p); |
2193
5ce5fad0dfac
replace the uses of old string functions that Reimar missed
mru
parents:
2189
diff
changeset
|
356 if (!av_stristart(p, "npt=", &p)) |
1453
c0235bab9e92
Add support for getting duration of a RTP stream (for seeking in stream)
gpoirier
parents:
1431
diff
changeset
|
357 return; |
c0235bab9e92
Add support for getting duration of a RTP stream (for seeking in stream)
gpoirier
parents:
1431
diff
changeset
|
358 |
c0235bab9e92
Add support for getting duration of a RTP stream (for seeking in stream)
gpoirier
parents:
1431
diff
changeset
|
359 *start = AV_NOPTS_VALUE; |
c0235bab9e92
Add support for getting duration of a RTP stream (for seeking in stream)
gpoirier
parents:
1431
diff
changeset
|
360 *end = AV_NOPTS_VALUE; |
c0235bab9e92
Add support for getting duration of a RTP stream (for seeking in stream)
gpoirier
parents:
1431
diff
changeset
|
361 |
c0235bab9e92
Add support for getting duration of a RTP stream (for seeking in stream)
gpoirier
parents:
1431
diff
changeset
|
362 get_word_sep(buf, sizeof(buf), "-", &p); |
c0235bab9e92
Add support for getting duration of a RTP stream (for seeking in stream)
gpoirier
parents:
1431
diff
changeset
|
363 *start = parse_date(buf, 1); |
c0235bab9e92
Add support for getting duration of a RTP stream (for seeking in stream)
gpoirier
parents:
1431
diff
changeset
|
364 if (*p == '-') { |
c0235bab9e92
Add support for getting duration of a RTP stream (for seeking in stream)
gpoirier
parents:
1431
diff
changeset
|
365 p++; |
c0235bab9e92
Add support for getting duration of a RTP stream (for seeking in stream)
gpoirier
parents:
1431
diff
changeset
|
366 get_word_sep(buf, sizeof(buf), "-", &p); |
c0235bab9e92
Add support for getting duration of a RTP stream (for seeking in stream)
gpoirier
parents:
1431
diff
changeset
|
367 *end = parse_date(buf, 1); |
c0235bab9e92
Add support for getting duration of a RTP stream (for seeking in stream)
gpoirier
parents:
1431
diff
changeset
|
368 } |
c0235bab9e92
Add support for getting duration of a RTP stream (for seeking in stream)
gpoirier
parents:
1431
diff
changeset
|
369 // av_log(NULL, AV_LOG_DEBUG, "Range Start: %lld\n", *start); |
c0235bab9e92
Add support for getting duration of a RTP stream (for seeking in stream)
gpoirier
parents:
1431
diff
changeset
|
370 // av_log(NULL, AV_LOG_DEBUG, "Range End: %lld\n", *end); |
c0235bab9e92
Add support for getting duration of a RTP stream (for seeking in stream)
gpoirier
parents:
1431
diff
changeset
|
371 } |
c0235bab9e92
Add support for getting duration of a RTP stream (for seeking in stream)
gpoirier
parents:
1431
diff
changeset
|
372 |
0 | 373 typedef struct SDPParseState { |
374 /* SDP only */ | |
375 struct in_addr default_ip; | |
376 int default_ttl; | |
377 } SDPParseState; | |
378 | |
379 static void sdp_parse_line(AVFormatContext *s, SDPParseState *s1, | |
380 int letter, const char *buf) | |
381 { | |
294
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
229
diff
changeset
|
382 RTSPState *rt = s->priv_data; |
0 | 383 char buf1[64], st_type[64]; |
384 const char *p; | |
385 int codec_type, payload_type, i; | |
386 AVStream *st; | |
387 RTSPStream *rtsp_st; | |
388 struct in_addr sdp_ip; | |
389 int ttl; | |
390 | |
391 #ifdef DEBUG | |
392 printf("sdp: %c='%s'\n", letter, buf); | |
393 #endif | |
394 | |
395 p = buf; | |
396 switch(letter) { | |
397 case 'c': | |
398 get_word(buf1, sizeof(buf1), &p); | |
399 if (strcmp(buf1, "IN") != 0) | |
400 return; | |
401 get_word(buf1, sizeof(buf1), &p); | |
402 if (strcmp(buf1, "IP4") != 0) | |
403 return; | |
404 get_word_sep(buf1, sizeof(buf1), "/", &p); | |
405 if (inet_aton(buf1, &sdp_ip) == 0) | |
406 return; | |
407 ttl = 16; | |
408 if (*p == '/') { | |
409 p++; | |
410 get_word_sep(buf1, sizeof(buf1), "/", &p); | |
411 ttl = atoi(buf1); | |
412 } | |
413 if (s->nb_streams == 0) { | |
414 s1->default_ip = sdp_ip; | |
415 s1->default_ttl = ttl; | |
416 } else { | |
417 st = s->streams[s->nb_streams - 1]; | |
418 rtsp_st = st->priv_data; | |
419 rtsp_st->sdp_ip = sdp_ip; | |
420 rtsp_st->sdp_ttl = ttl; | |
421 } | |
422 break; | |
423 case 's': | |
2189 | 424 av_strlcpy(s->title, p, sizeof(s->title)); |
0 | 425 break; |
426 case 'i': | |
427 if (s->nb_streams == 0) { | |
2189 | 428 av_strlcpy(s->comment, p, sizeof(s->comment)); |
0 | 429 break; |
430 } | |
431 break; | |
432 case 'm': | |
433 /* new stream */ | |
434 get_word(st_type, sizeof(st_type), &p); | |
435 if (!strcmp(st_type, "audio")) { | |
436 codec_type = CODEC_TYPE_AUDIO; | |
437 } else if (!strcmp(st_type, "video")) { | |
438 codec_type = CODEC_TYPE_VIDEO; | |
439 } else { | |
440 return; | |
441 } | |
442 rtsp_st = av_mallocz(sizeof(RTSPStream)); | |
443 if (!rtsp_st) | |
444 return; | |
294
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
229
diff
changeset
|
445 rtsp_st->stream_index = -1; |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
229
diff
changeset
|
446 dynarray_add(&rt->rtsp_streams, &rt->nb_rtsp_streams, rtsp_st); |
0 | 447 |
448 rtsp_st->sdp_ip = s1->default_ip; | |
449 rtsp_st->sdp_ttl = s1->default_ttl; | |
450 | |
451 get_word(buf1, sizeof(buf1), &p); /* port */ | |
452 rtsp_st->sdp_port = atoi(buf1); | |
453 | |
454 get_word(buf1, sizeof(buf1), &p); /* protocol (ignored) */ | |
885 | 455 |
0 | 456 /* XXX: handle list of formats */ |
457 get_word(buf1, sizeof(buf1), &p); /* format list */ | |
458 rtsp_st->sdp_payload_type = atoi(buf1); | |
294
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
229
diff
changeset
|
459 |
2759
b252e318023a
Remove the "AVRtpPayloadTypes[i].pt == i" assumption from RTP and RTSP
lucabe
parents:
2711
diff
changeset
|
460 if (!strcmp(ff_rtp_enc_name(rtsp_st->sdp_payload_type), "MP2T")) { |
294
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
229
diff
changeset
|
461 /* no corresponding stream */ |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
229
diff
changeset
|
462 } else { |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
229
diff
changeset
|
463 st = av_new_stream(s, 0); |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
229
diff
changeset
|
464 if (!st) |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
229
diff
changeset
|
465 return; |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
229
diff
changeset
|
466 st->priv_data = rtsp_st; |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
229
diff
changeset
|
467 rtsp_st->stream_index = st->index; |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
774
diff
changeset
|
468 st->codec->codec_type = codec_type; |
774 | 469 if (rtsp_st->sdp_payload_type < RTP_PT_PRIVATE) { |
294
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
229
diff
changeset
|
470 /* if standard payload type, we can find the codec right now */ |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
774
diff
changeset
|
471 rtp_get_codec_info(st->codec, rtsp_st->sdp_payload_type); |
294
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
229
diff
changeset
|
472 } |
0 | 473 } |
474 /* put a default control url */ | |
2189 | 475 av_strlcpy(rtsp_st->control_url, s->filename, sizeof(rtsp_st->control_url)); |
0 | 476 break; |
477 case 'a': | |
2193
5ce5fad0dfac
replace the uses of old string functions that Reimar missed
mru
parents:
2189
diff
changeset
|
478 if (av_strstart(p, "control:", &p) && s->nb_streams > 0) { |
0 | 479 char proto[32]; |
480 /* get the control url */ | |
481 st = s->streams[s->nb_streams - 1]; | |
482 rtsp_st = st->priv_data; | |
885 | 483 |
0 | 484 /* XXX: may need to add full url resolution */ |
511
056991ab9f10
HTTP Authentication Patch by (Petr Doubek <doubek at vision dot ee dot ethz dot ch>)
michael
parents:
391
diff
changeset
|
485 url_split(proto, sizeof(proto), NULL, 0, NULL, 0, NULL, NULL, 0, p); |
0 | 486 if (proto[0] == '\0') { |
487 /* relative control URL */ | |
2189 | 488 av_strlcat(rtsp_st->control_url, "/", sizeof(rtsp_st->control_url)); |
489 av_strlcat(rtsp_st->control_url, p, sizeof(rtsp_st->control_url)); | |
0 | 490 } else { |
2189 | 491 av_strlcpy(rtsp_st->control_url, p, sizeof(rtsp_st->control_url)); |
0 | 492 } |
2193
5ce5fad0dfac
replace the uses of old string functions that Reimar missed
mru
parents:
2189
diff
changeset
|
493 } else if (av_strstart(p, "rtpmap:", &p)) { |
0 | 494 /* NOTE: rtpmap is only supported AFTER the 'm=' tag */ |
885 | 495 get_word(buf1, sizeof(buf1), &p); |
0 | 496 payload_type = atoi(buf1); |
497 for(i = 0; i < s->nb_streams;i++) { | |
498 st = s->streams[i]; | |
499 rtsp_st = st->priv_data; | |
500 if (rtsp_st->sdp_payload_type == payload_type) { | |
1419 | 501 sdp_parse_rtpmap(st->codec, rtsp_st, payload_type, p); |
0 | 502 } |
503 } | |
2193
5ce5fad0dfac
replace the uses of old string functions that Reimar missed
mru
parents:
2189
diff
changeset
|
504 } else if (av_strstart(p, "fmtp:", &p)) { |
0 | 505 /* NOTE: fmtp is only supported AFTER the 'a=rtpmap:xxx' tag */ |
885 | 506 get_word(buf1, sizeof(buf1), &p); |
0 | 507 payload_type = atoi(buf1); |
508 for(i = 0; i < s->nb_streams;i++) { | |
509 st = s->streams[i]; | |
510 rtsp_st = st->priv_data; | |
511 if (rtsp_st->sdp_payload_type == payload_type) { | |
1419 | 512 if(rtsp_st->dynamic_handler && rtsp_st->dynamic_handler->parse_sdp_a_line) { |
513 if(!rtsp_st->dynamic_handler->parse_sdp_a_line(st, rtsp_st->dynamic_protocol_context, buf)) { | |
514 sdp_parse_fmtp(st, p); | |
515 } | |
516 } else { | |
1424
1c39ce5c6a5d
indentation fix, patch by Ryan Martell % rdm4 A martellventures P com %
gpoirier
parents:
1419
diff
changeset
|
517 sdp_parse_fmtp(st, p); |
1419 | 518 } |
0 | 519 } |
520 } | |
2193
5ce5fad0dfac
replace the uses of old string functions that Reimar missed
mru
parents:
2189
diff
changeset
|
521 } else if(av_strstart(p, "framesize:", &p)) { |
1431
2d8a17631520
fix more dynamic protocol stuff, needed by the forthcoming h264
gpoirier
parents:
1425
diff
changeset
|
522 // let dynamic protocol handlers have a stab at the line. |
2d8a17631520
fix more dynamic protocol stuff, needed by the forthcoming h264
gpoirier
parents:
1425
diff
changeset
|
523 get_word(buf1, sizeof(buf1), &p); |
2d8a17631520
fix more dynamic protocol stuff, needed by the forthcoming h264
gpoirier
parents:
1425
diff
changeset
|
524 payload_type = atoi(buf1); |
2d8a17631520
fix more dynamic protocol stuff, needed by the forthcoming h264
gpoirier
parents:
1425
diff
changeset
|
525 for(i = 0; i < s->nb_streams;i++) { |
2d8a17631520
fix more dynamic protocol stuff, needed by the forthcoming h264
gpoirier
parents:
1425
diff
changeset
|
526 st = s->streams[i]; |
2d8a17631520
fix more dynamic protocol stuff, needed by the forthcoming h264
gpoirier
parents:
1425
diff
changeset
|
527 rtsp_st = st->priv_data; |
2d8a17631520
fix more dynamic protocol stuff, needed by the forthcoming h264
gpoirier
parents:
1425
diff
changeset
|
528 if (rtsp_st->sdp_payload_type == payload_type) { |
2d8a17631520
fix more dynamic protocol stuff, needed by the forthcoming h264
gpoirier
parents:
1425
diff
changeset
|
529 if(rtsp_st->dynamic_handler && rtsp_st->dynamic_handler->parse_sdp_a_line) { |
2d8a17631520
fix more dynamic protocol stuff, needed by the forthcoming h264
gpoirier
parents:
1425
diff
changeset
|
530 rtsp_st->dynamic_handler->parse_sdp_a_line(st, rtsp_st->dynamic_protocol_context, buf); |
2d8a17631520
fix more dynamic protocol stuff, needed by the forthcoming h264
gpoirier
parents:
1425
diff
changeset
|
531 } |
2d8a17631520
fix more dynamic protocol stuff, needed by the forthcoming h264
gpoirier
parents:
1425
diff
changeset
|
532 } |
2d8a17631520
fix more dynamic protocol stuff, needed by the forthcoming h264
gpoirier
parents:
1425
diff
changeset
|
533 } |
2193
5ce5fad0dfac
replace the uses of old string functions that Reimar missed
mru
parents:
2189
diff
changeset
|
534 } else if(av_strstart(p, "range:", &p)) { |
1453
c0235bab9e92
Add support for getting duration of a RTP stream (for seeking in stream)
gpoirier
parents:
1431
diff
changeset
|
535 int64_t start, end; |
c0235bab9e92
Add support for getting duration of a RTP stream (for seeking in stream)
gpoirier
parents:
1431
diff
changeset
|
536 |
c0235bab9e92
Add support for getting duration of a RTP stream (for seeking in stream)
gpoirier
parents:
1431
diff
changeset
|
537 // this is so that seeking on a streamed file can work. |
c0235bab9e92
Add support for getting duration of a RTP stream (for seeking in stream)
gpoirier
parents:
1431
diff
changeset
|
538 rtsp_parse_range_npt(p, &start, &end); |
c0235bab9e92
Add support for getting duration of a RTP stream (for seeking in stream)
gpoirier
parents:
1431
diff
changeset
|
539 s->start_time= start; |
c0235bab9e92
Add support for getting duration of a RTP stream (for seeking in stream)
gpoirier
parents:
1431
diff
changeset
|
540 s->duration= (end==AV_NOPTS_VALUE)?AV_NOPTS_VALUE:end-start; // AV_NOPTS_VALUE means live broadcast (and can't seek) |
3784
d370d80ad1df
Use RTPDynamicProtocol parse_sdp_a_line() handlers in case of unknown SDP
rbultje
parents:
3722
diff
changeset
|
541 } else if (s->nb_streams > 0) { |
d370d80ad1df
Use RTPDynamicProtocol parse_sdp_a_line() handlers in case of unknown SDP
rbultje
parents:
3722
diff
changeset
|
542 rtsp_st = s->streams[s->nb_streams - 1]->priv_data; |
d370d80ad1df
Use RTPDynamicProtocol parse_sdp_a_line() handlers in case of unknown SDP
rbultje
parents:
3722
diff
changeset
|
543 if (rtsp_st->dynamic_handler && |
d370d80ad1df
Use RTPDynamicProtocol parse_sdp_a_line() handlers in case of unknown SDP
rbultje
parents:
3722
diff
changeset
|
544 rtsp_st->dynamic_handler->parse_sdp_a_line) |
d370d80ad1df
Use RTPDynamicProtocol parse_sdp_a_line() handlers in case of unknown SDP
rbultje
parents:
3722
diff
changeset
|
545 rtsp_st->dynamic_handler->parse_sdp_a_line(s->streams[s->nb_streams - 1], |
d370d80ad1df
Use RTPDynamicProtocol parse_sdp_a_line() handlers in case of unknown SDP
rbultje
parents:
3722
diff
changeset
|
546 rtsp_st->dynamic_protocol_context, buf); |
0 | 547 } |
548 break; | |
549 } | |
550 } | |
551 | |
64 | 552 static int sdp_parse(AVFormatContext *s, const char *content) |
0 | 553 { |
554 const char *p; | |
555 int letter; | |
3860
d8fce96bb3ab
Some RTSP streams use SDP lines longer than 1024 bytes, so the SDP line
rbultje
parents:
3859
diff
changeset
|
556 char buf[2048], *q; |
0 | 557 SDPParseState sdp_parse_state, *s1 = &sdp_parse_state; |
885 | 558 |
0 | 559 memset(s1, 0, sizeof(SDPParseState)); |
560 p = content; | |
561 for(;;) { | |
562 skip_spaces(&p); | |
563 letter = *p; | |
564 if (letter == '\0') | |
565 break; | |
566 p++; | |
567 if (*p != '=') | |
568 goto next_line; | |
569 p++; | |
570 /* get the content */ | |
571 q = buf; | |
172 | 572 while (*p != '\n' && *p != '\r' && *p != '\0') { |
0 | 573 if ((q - buf) < sizeof(buf) - 1) |
574 *q++ = *p; | |
575 p++; | |
576 } | |
577 *q = '\0'; | |
578 sdp_parse_line(s, s1, letter, buf); | |
579 next_line: | |
580 while (*p != '\n' && *p != '\0') | |
581 p++; | |
582 if (*p == '\n') | |
583 p++; | |
584 } | |
585 return 0; | |
586 } | |
587 | |
588 static void rtsp_parse_range(int *min_ptr, int *max_ptr, const char **pp) | |
589 { | |
590 const char *p; | |
591 int v; | |
592 | |
593 p = *pp; | |
594 skip_spaces(&p); | |
595 v = strtol(p, (char **)&p, 10); | |
596 if (*p == '-') { | |
597 p++; | |
598 *min_ptr = v; | |
599 v = strtol(p, (char **)&p, 10); | |
600 *max_ptr = v; | |
601 } else { | |
602 *min_ptr = v; | |
603 *max_ptr = v; | |
604 } | |
605 *pp = p; | |
606 } | |
607 | |
608 /* XXX: only one transport specification is parsed */ | |
609 static void rtsp_parse_transport(RTSPHeader *reply, const char *p) | |
610 { | |
611 char transport_protocol[16]; | |
612 char profile[16]; | |
613 char lower_transport[16]; | |
614 char parameter[16]; | |
615 RTSPTransportField *th; | |
616 char buf[256]; | |
885 | 617 |
0 | 618 reply->nb_transports = 0; |
885 | 619 |
0 | 620 for(;;) { |
621 skip_spaces(&p); | |
622 if (*p == '\0') | |
623 break; | |
624 | |
625 th = &reply->transports[reply->nb_transports]; | |
626 | |
885 | 627 get_word_sep(transport_protocol, sizeof(transport_protocol), |
0 | 628 "/", &p); |
629 if (*p == '/') | |
630 p++; | |
2865
51aa1054528c
Real RTSP support, from Ronald S. Bultje rsbultje gmail - part 2 x-pn-tng support
lu_zero
parents:
2864
diff
changeset
|
631 if (!strcasecmp (transport_protocol, "rtp")) { |
2866
ccbca87ccd5e
Real RTSP support, from Ronald S. Bultje rsbultje gmail - part 3 Reindent
lu_zero
parents:
2865
diff
changeset
|
632 get_word_sep(profile, sizeof(profile), "/;,", &p); |
ccbca87ccd5e
Real RTSP support, from Ronald S. Bultje rsbultje gmail - part 3 Reindent
lu_zero
parents:
2865
diff
changeset
|
633 lower_transport[0] = '\0'; |
ccbca87ccd5e
Real RTSP support, from Ronald S. Bultje rsbultje gmail - part 3 Reindent
lu_zero
parents:
2865
diff
changeset
|
634 /* rtp/avp/<protocol> */ |
ccbca87ccd5e
Real RTSP support, from Ronald S. Bultje rsbultje gmail - part 3 Reindent
lu_zero
parents:
2865
diff
changeset
|
635 if (*p == '/') { |
ccbca87ccd5e
Real RTSP support, from Ronald S. Bultje rsbultje gmail - part 3 Reindent
lu_zero
parents:
2865
diff
changeset
|
636 p++; |
ccbca87ccd5e
Real RTSP support, from Ronald S. Bultje rsbultje gmail - part 3 Reindent
lu_zero
parents:
2865
diff
changeset
|
637 get_word_sep(lower_transport, sizeof(lower_transport), |
ccbca87ccd5e
Real RTSP support, from Ronald S. Bultje rsbultje gmail - part 3 Reindent
lu_zero
parents:
2865
diff
changeset
|
638 ";,", &p); |
ccbca87ccd5e
Real RTSP support, from Ronald S. Bultje rsbultje gmail - part 3 Reindent
lu_zero
parents:
2865
diff
changeset
|
639 } |
ccbca87ccd5e
Real RTSP support, from Ronald S. Bultje rsbultje gmail - part 3 Reindent
lu_zero
parents:
2865
diff
changeset
|
640 } else if (!strcasecmp (transport_protocol, "x-pn-tng")) { |
ccbca87ccd5e
Real RTSP support, from Ronald S. Bultje rsbultje gmail - part 3 Reindent
lu_zero
parents:
2865
diff
changeset
|
641 /* x-pn-tng/<protocol> */ |
2865
51aa1054528c
Real RTSP support, from Ronald S. Bultje rsbultje gmail - part 2 x-pn-tng support
lu_zero
parents:
2864
diff
changeset
|
642 get_word_sep(lower_transport, sizeof(lower_transport), "/;,", &p); |
51aa1054528c
Real RTSP support, from Ronald S. Bultje rsbultje gmail - part 2 x-pn-tng support
lu_zero
parents:
2864
diff
changeset
|
643 profile[0] = '\0'; |
0 | 644 } |
172 | 645 if (!strcasecmp(lower_transport, "TCP")) |
3957
9f943bb755f9
Rename RTSPProtocol to RTSPLowerTransport, so that its name properly tells us
rbultje
parents:
3941
diff
changeset
|
646 th->lower_transport = RTSP_LOWER_TRANSPORT_TCP; |
0 | 647 else |
3957
9f943bb755f9
Rename RTSPProtocol to RTSPLowerTransport, so that its name properly tells us
rbultje
parents:
3941
diff
changeset
|
648 th->lower_transport = RTSP_LOWER_TRANSPORT_UDP; |
885 | 649 |
0 | 650 if (*p == ';') |
651 p++; | |
652 /* get each parameter */ | |
653 while (*p != '\0' && *p != ',') { | |
654 get_word_sep(parameter, sizeof(parameter), "=;,", &p); | |
655 if (!strcmp(parameter, "port")) { | |
656 if (*p == '=') { | |
657 p++; | |
658 rtsp_parse_range(&th->port_min, &th->port_max, &p); | |
659 } | |
660 } else if (!strcmp(parameter, "client_port")) { | |
661 if (*p == '=') { | |
662 p++; | |
885 | 663 rtsp_parse_range(&th->client_port_min, |
0 | 664 &th->client_port_max, &p); |
665 } | |
666 } else if (!strcmp(parameter, "server_port")) { | |
667 if (*p == '=') { | |
668 p++; | |
885 | 669 rtsp_parse_range(&th->server_port_min, |
0 | 670 &th->server_port_max, &p); |
671 } | |
672 } else if (!strcmp(parameter, "interleaved")) { | |
673 if (*p == '=') { | |
674 p++; | |
885 | 675 rtsp_parse_range(&th->interleaved_min, |
0 | 676 &th->interleaved_max, &p); |
677 } | |
678 } else if (!strcmp(parameter, "multicast")) { | |
3957
9f943bb755f9
Rename RTSPProtocol to RTSPLowerTransport, so that its name properly tells us
rbultje
parents:
3941
diff
changeset
|
679 if (th->lower_transport == RTSP_LOWER_TRANSPORT_UDP) |
9f943bb755f9
Rename RTSPProtocol to RTSPLowerTransport, so that its name properly tells us
rbultje
parents:
3941
diff
changeset
|
680 th->lower_transport = RTSP_LOWER_TRANSPORT_UDP_MULTICAST; |
0 | 681 } else if (!strcmp(parameter, "ttl")) { |
682 if (*p == '=') { | |
683 p++; | |
684 th->ttl = strtol(p, (char **)&p, 10); | |
685 } | |
686 } else if (!strcmp(parameter, "destination")) { | |
687 struct in_addr ipaddr; | |
688 | |
689 if (*p == '=') { | |
690 p++; | |
691 get_word_sep(buf, sizeof(buf), ";,", &p); | |
885 | 692 if (inet_aton(buf, &ipaddr)) |
0 | 693 th->destination = ntohl(ipaddr.s_addr); |
694 } | |
695 } | |
696 while (*p != ';' && *p != '\0' && *p != ',') | |
697 p++; | |
698 if (*p == ';') | |
699 p++; | |
700 } | |
701 if (*p == ',') | |
702 p++; | |
703 | |
704 reply->nb_transports++; | |
705 } | |
706 } | |
707 | |
708 void rtsp_parse_line(RTSPHeader *reply, const char *buf) | |
709 { | |
710 const char *p; | |
711 | |
712 /* NOTE: we do case independent match for broken servers */ | |
713 p = buf; | |
2193
5ce5fad0dfac
replace the uses of old string functions that Reimar missed
mru
parents:
2189
diff
changeset
|
714 if (av_stristart(p, "Session:", &p)) { |
0 | 715 get_word_sep(reply->session_id, sizeof(reply->session_id), ";", &p); |
2193
5ce5fad0dfac
replace the uses of old string functions that Reimar missed
mru
parents:
2189
diff
changeset
|
716 } else if (av_stristart(p, "Content-Length:", &p)) { |
0 | 717 reply->content_length = strtol(p, NULL, 10); |
2193
5ce5fad0dfac
replace the uses of old string functions that Reimar missed
mru
parents:
2189
diff
changeset
|
718 } else if (av_stristart(p, "Transport:", &p)) { |
0 | 719 rtsp_parse_transport(reply, p); |
2193
5ce5fad0dfac
replace the uses of old string functions that Reimar missed
mru
parents:
2189
diff
changeset
|
720 } else if (av_stristart(p, "CSeq:", &p)) { |
0 | 721 reply->seq = strtol(p, NULL, 10); |
2193
5ce5fad0dfac
replace the uses of old string functions that Reimar missed
mru
parents:
2189
diff
changeset
|
722 } else if (av_stristart(p, "Range:", &p)) { |
1453
c0235bab9e92
Add support for getting duration of a RTP stream (for seeking in stream)
gpoirier
parents:
1431
diff
changeset
|
723 rtsp_parse_range_npt(p, &reply->range_start, &reply->range_end); |
3855 | 724 } else if (av_stristart(p, "RealChallenge1:", &p)) { |
725 skip_spaces(&p); | |
726 av_strlcpy(reply->real_challenge, p, sizeof(reply->real_challenge)); | |
0 | 727 } |
728 } | |
729 | |
391
1cf22651d33b
support url_read which reads less then requested patch by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
michael
parents:
370
diff
changeset
|
730 static int url_readbuf(URLContext *h, unsigned char *buf, int size) |
1cf22651d33b
support url_read which reads less then requested patch by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
michael
parents:
370
diff
changeset
|
731 { |
1cf22651d33b
support url_read which reads less then requested patch by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
michael
parents:
370
diff
changeset
|
732 int ret, len; |
1cf22651d33b
support url_read which reads less then requested patch by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
michael
parents:
370
diff
changeset
|
733 |
1cf22651d33b
support url_read which reads less then requested patch by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
michael
parents:
370
diff
changeset
|
734 len = 0; |
1cf22651d33b
support url_read which reads less then requested patch by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
michael
parents:
370
diff
changeset
|
735 while (len < size) { |
1cf22651d33b
support url_read which reads less then requested patch by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
michael
parents:
370
diff
changeset
|
736 ret = url_read(h, buf+len, size-len); |
1cf22651d33b
support url_read which reads less then requested patch by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
michael
parents:
370
diff
changeset
|
737 if (ret < 1) |
1cf22651d33b
support url_read which reads less then requested patch by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
michael
parents:
370
diff
changeset
|
738 return ret; |
1cf22651d33b
support url_read which reads less then requested patch by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
michael
parents:
370
diff
changeset
|
739 len += ret; |
1cf22651d33b
support url_read which reads less then requested patch by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
michael
parents:
370
diff
changeset
|
740 } |
1cf22651d33b
support url_read which reads less then requested patch by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
michael
parents:
370
diff
changeset
|
741 return len; |
1cf22651d33b
support url_read which reads less then requested patch by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
michael
parents:
370
diff
changeset
|
742 } |
1cf22651d33b
support url_read which reads less then requested patch by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
michael
parents:
370
diff
changeset
|
743 |
179 | 744 /* skip a RTP/TCP interleaved packet */ |
745 static void rtsp_skip_packet(AVFormatContext *s) | |
746 { | |
747 RTSPState *rt = s->priv_data; | |
748 int ret, len, len1; | |
749 uint8_t buf[1024]; | |
750 | |
391
1cf22651d33b
support url_read which reads less then requested patch by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
michael
parents:
370
diff
changeset
|
751 ret = url_readbuf(rt->rtsp_hd, buf, 3); |
179 | 752 if (ret != 3) |
753 return; | |
2222 | 754 len = AV_RB16(buf + 1); |
179 | 755 #ifdef DEBUG |
756 printf("skipping RTP packet len=%d\n", len); | |
757 #endif | |
758 /* skip payload */ | |
759 while (len > 0) { | |
760 len1 = len; | |
761 if (len1 > sizeof(buf)) | |
762 len1 = sizeof(buf); | |
391
1cf22651d33b
support url_read which reads less then requested patch by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
michael
parents:
370
diff
changeset
|
763 ret = url_readbuf(rt->rtsp_hd, buf, len1); |
179 | 764 if (ret != len1) |
765 return; | |
766 len -= len1; | |
767 } | |
768 } | |
0 | 769 |
885 | 770 static void rtsp_send_cmd(AVFormatContext *s, |
771 const char *cmd, RTSPHeader *reply, | |
0 | 772 unsigned char **content_ptr) |
773 { | |
774 RTSPState *rt = s->priv_data; | |
775 char buf[4096], buf1[1024], *q; | |
776 unsigned char ch; | |
777 const char *p; | |
778 int content_length, line_count; | |
779 unsigned char *content = NULL; | |
780 | |
781 memset(reply, 0, sizeof(RTSPHeader)); | |
782 | |
783 rt->seq++; | |
2189 | 784 av_strlcpy(buf, cmd, sizeof(buf)); |
172 | 785 snprintf(buf1, sizeof(buf1), "CSeq: %d\r\n", rt->seq); |
2189 | 786 av_strlcat(buf, buf1, sizeof(buf)); |
0 | 787 if (rt->session_id[0] != '\0' && !strstr(cmd, "\nIf-Match:")) { |
172 | 788 snprintf(buf1, sizeof(buf1), "Session: %s\r\n", rt->session_id); |
2189 | 789 av_strlcat(buf, buf1, sizeof(buf)); |
0 | 790 } |
2189 | 791 av_strlcat(buf, "\r\n", sizeof(buf)); |
0 | 792 #ifdef DEBUG |
793 printf("Sending:\n%s--\n", buf); | |
794 #endif | |
795 url_write(rt->rtsp_hd, buf, strlen(buf)); | |
796 | |
797 /* parse reply (XXX: use buffers) */ | |
798 line_count = 0; | |
799 rt->last_reply[0] = '\0'; | |
800 for(;;) { | |
801 q = buf; | |
802 for(;;) { | |
391
1cf22651d33b
support url_read which reads less then requested patch by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
michael
parents:
370
diff
changeset
|
803 if (url_readbuf(rt->rtsp_hd, &ch, 1) != 1) |
0 | 804 break; |
805 if (ch == '\n') | |
806 break; | |
179 | 807 if (ch == '$') { |
808 /* XXX: only parse it if first char on line ? */ | |
809 rtsp_skip_packet(s); | |
810 } else if (ch != '\r') { | |
0 | 811 if ((q - buf) < sizeof(buf) - 1) |
812 *q++ = ch; | |
813 } | |
814 } | |
815 *q = '\0'; | |
816 #ifdef DEBUG | |
817 printf("line='%s'\n", buf); | |
818 #endif | |
819 /* test if last line */ | |
820 if (buf[0] == '\0') | |
821 break; | |
822 p = buf; | |
823 if (line_count == 0) { | |
824 /* get reply code */ | |
825 get_word(buf1, sizeof(buf1), &p); | |
826 get_word(buf1, sizeof(buf1), &p); | |
827 reply->status_code = atoi(buf1); | |
828 } else { | |
829 rtsp_parse_line(reply, p); | |
2189 | 830 av_strlcat(rt->last_reply, p, sizeof(rt->last_reply)); |
831 av_strlcat(rt->last_reply, "\n", sizeof(rt->last_reply)); | |
0 | 832 } |
833 line_count++; | |
834 } | |
885 | 835 |
0 | 836 if (rt->session_id[0] == '\0' && reply->session_id[0] != '\0') |
2189 | 837 av_strlcpy(rt->session_id, reply->session_id, sizeof(rt->session_id)); |
885 | 838 |
0 | 839 content_length = reply->content_length; |
840 if (content_length > 0) { | |
841 /* leave some room for a trailing '\0' (useful for simple parsing) */ | |
842 content = av_malloc(content_length + 1); | |
391
1cf22651d33b
support url_read which reads less then requested patch by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
michael
parents:
370
diff
changeset
|
843 (void)url_readbuf(rt->rtsp_hd, content, content_length); |
0 | 844 content[content_length] = '\0'; |
845 } | |
846 if (content_ptr) | |
847 *content_ptr = content; | |
2263 | 848 else |
849 av_free(content); | |
0 | 850 } |
851 | |
852 | |
294
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
229
diff
changeset
|
853 /* close and free RTSP streams */ |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
229
diff
changeset
|
854 static void rtsp_close_streams(RTSPState *rt) |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
229
diff
changeset
|
855 { |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
229
diff
changeset
|
856 int i; |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
229
diff
changeset
|
857 RTSPStream *rtsp_st; |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
229
diff
changeset
|
858 |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
229
diff
changeset
|
859 for(i=0;i<rt->nb_rtsp_streams;i++) { |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
229
diff
changeset
|
860 rtsp_st = rt->rtsp_streams[i]; |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
229
diff
changeset
|
861 if (rtsp_st) { |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
229
diff
changeset
|
862 if (rtsp_st->rtp_ctx) |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
229
diff
changeset
|
863 rtp_parse_close(rtsp_st->rtp_ctx); |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
229
diff
changeset
|
864 if (rtsp_st->rtp_handle) |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
229
diff
changeset
|
865 url_close(rtsp_st->rtp_handle); |
1419 | 866 if (rtsp_st->dynamic_handler && rtsp_st->dynamic_protocol_context) |
867 rtsp_st->dynamic_handler->close(rtsp_st->dynamic_protocol_context); | |
294
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
229
diff
changeset
|
868 } |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
229
diff
changeset
|
869 } |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
229
diff
changeset
|
870 av_free(rt->rtsp_streams); |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
229
diff
changeset
|
871 } |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
229
diff
changeset
|
872 |
3919
1879eab34f88
Factorize out common code for opening of the RTP parsing context between
rbultje
parents:
3905
diff
changeset
|
873 static int |
1879eab34f88
Factorize out common code for opening of the RTP parsing context between
rbultje
parents:
3905
diff
changeset
|
874 rtsp_open_transport_ctx(AVFormatContext *s, RTSPStream *rtsp_st) |
1879eab34f88
Factorize out common code for opening of the RTP parsing context between
rbultje
parents:
3905
diff
changeset
|
875 { |
1879eab34f88
Factorize out common code for opening of the RTP parsing context between
rbultje
parents:
3905
diff
changeset
|
876 AVStream *st = NULL; |
1879eab34f88
Factorize out common code for opening of the RTP parsing context between
rbultje
parents:
3905
diff
changeset
|
877 |
3920
ae2d4ee06a94
Reindent after r15927, see discussion in "[PATCH] rtsp cleanup part 1:
rbultje
parents:
3919
diff
changeset
|
878 /* open the RTP context */ |
ae2d4ee06a94
Reindent after r15927, see discussion in "[PATCH] rtsp cleanup part 1:
rbultje
parents:
3919
diff
changeset
|
879 if (rtsp_st->stream_index >= 0) |
ae2d4ee06a94
Reindent after r15927, see discussion in "[PATCH] rtsp cleanup part 1:
rbultje
parents:
3919
diff
changeset
|
880 st = s->streams[rtsp_st->stream_index]; |
ae2d4ee06a94
Reindent after r15927, see discussion in "[PATCH] rtsp cleanup part 1:
rbultje
parents:
3919
diff
changeset
|
881 if (!st) |
ae2d4ee06a94
Reindent after r15927, see discussion in "[PATCH] rtsp cleanup part 1:
rbultje
parents:
3919
diff
changeset
|
882 s->ctx_flags |= AVFMTCTX_NOHEADER; |
ae2d4ee06a94
Reindent after r15927, see discussion in "[PATCH] rtsp cleanup part 1:
rbultje
parents:
3919
diff
changeset
|
883 rtsp_st->rtp_ctx = rtp_parse_open(s, st, rtsp_st->rtp_handle, rtsp_st->sdp_payload_type, &rtsp_st->rtp_payload_data); |
3919
1879eab34f88
Factorize out common code for opening of the RTP parsing context between
rbultje
parents:
3905
diff
changeset
|
884 |
3920
ae2d4ee06a94
Reindent after r15927, see discussion in "[PATCH] rtsp cleanup part 1:
rbultje
parents:
3919
diff
changeset
|
885 if (!rtsp_st->rtp_ctx) { |
ae2d4ee06a94
Reindent after r15927, see discussion in "[PATCH] rtsp cleanup part 1:
rbultje
parents:
3919
diff
changeset
|
886 return AVERROR(ENOMEM); |
ae2d4ee06a94
Reindent after r15927, see discussion in "[PATCH] rtsp cleanup part 1:
rbultje
parents:
3919
diff
changeset
|
887 } else { |
ae2d4ee06a94
Reindent after r15927, see discussion in "[PATCH] rtsp cleanup part 1:
rbultje
parents:
3919
diff
changeset
|
888 if(rtsp_st->dynamic_handler) { |
ae2d4ee06a94
Reindent after r15927, see discussion in "[PATCH] rtsp cleanup part 1:
rbultje
parents:
3919
diff
changeset
|
889 rtsp_st->rtp_ctx->dynamic_protocol_context= rtsp_st->dynamic_protocol_context; |
ae2d4ee06a94
Reindent after r15927, see discussion in "[PATCH] rtsp cleanup part 1:
rbultje
parents:
3919
diff
changeset
|
890 rtsp_st->rtp_ctx->parse_packet= rtsp_st->dynamic_handler->parse_packet; |
3919
1879eab34f88
Factorize out common code for opening of the RTP parsing context between
rbultje
parents:
3905
diff
changeset
|
891 } |
3920
ae2d4ee06a94
Reindent after r15927, see discussion in "[PATCH] rtsp cleanup part 1:
rbultje
parents:
3919
diff
changeset
|
892 } |
3919
1879eab34f88
Factorize out common code for opening of the RTP parsing context between
rbultje
parents:
3905
diff
changeset
|
893 |
1879eab34f88
Factorize out common code for opening of the RTP parsing context between
rbultje
parents:
3905
diff
changeset
|
894 return 0; |
1879eab34f88
Factorize out common code for opening of the RTP parsing context between
rbultje
parents:
3905
diff
changeset
|
895 } |
1879eab34f88
Factorize out common code for opening of the RTP parsing context between
rbultje
parents:
3905
diff
changeset
|
896 |
3147
91d65fdf91e1
Split the SETUP request into a separate function, as a prelude into allowing
rbultje
parents:
2884
diff
changeset
|
897 /** |
91d65fdf91e1
Split the SETUP request into a separate function, as a prelude into allowing
rbultje
parents:
2884
diff
changeset
|
898 * @returns 0 on success, <0 on error, 1 if protocol is unavailable. |
91d65fdf91e1
Split the SETUP request into a separate function, as a prelude into allowing
rbultje
parents:
2884
diff
changeset
|
899 */ |
91d65fdf91e1
Split the SETUP request into a separate function, as a prelude into allowing
rbultje
parents:
2884
diff
changeset
|
900 static int |
3876
1026953d4ffe
Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
3861
diff
changeset
|
901 make_setup_request (AVFormatContext *s, const char *host, int port, |
3957
9f943bb755f9
Rename RTSPProtocol to RTSPLowerTransport, so that its name properly tells us
rbultje
parents:
3941
diff
changeset
|
902 int lower_transport, const char *real_challenge) |
0 | 903 { |
904 RTSPState *rt = s->priv_data; | |
3147
91d65fdf91e1
Split the SETUP request into a separate function, as a prelude into allowing
rbultje
parents:
2884
diff
changeset
|
905 int j, i, err; |
0 | 906 RTSPStream *rtsp_st; |
3147
91d65fdf91e1
Split the SETUP request into a separate function, as a prelude into allowing
rbultje
parents:
2884
diff
changeset
|
907 RTSPHeader reply1, *reply = &reply1; |
91d65fdf91e1
Split the SETUP request into a separate function, as a prelude into allowing
rbultje
parents:
2884
diff
changeset
|
908 char cmd[2048]; |
3876
1026953d4ffe
Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
3861
diff
changeset
|
909 const char *trans_pref; |
1026953d4ffe
Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
3861
diff
changeset
|
910 |
3923
83e51bcb03c2
Rename RTSP_SERVER_RDT to RTSP_SERVER_REAL, because RDT (the transport
rbultje
parents:
3920
diff
changeset
|
911 if (rt->server_type == RTSP_SERVER_REAL) |
3876
1026953d4ffe
Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
3861
diff
changeset
|
912 trans_pref = "x-pn-tng"; |
1026953d4ffe
Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
3861
diff
changeset
|
913 else |
1026953d4ffe
Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
3861
diff
changeset
|
914 trans_pref = "RTP/AVP"; |
885 | 915 |
0 | 916 /* for each stream, make the setup request */ |
917 /* XXX: we assume the same server is used for the control of each | |
918 RTSP stream */ | |
774 | 919 |
920 for(j = RTSP_RTP_PORT_MIN, i = 0; i < rt->nb_rtsp_streams; ++i) { | |
0 | 921 char transport[2048]; |
922 | |
294
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
229
diff
changeset
|
923 rtsp_st = rt->rtsp_streams[i]; |
0 | 924 |
925 /* RTP/UDP */ | |
3957
9f943bb755f9
Rename RTSPProtocol to RTSPLowerTransport, so that its name properly tells us
rbultje
parents:
3941
diff
changeset
|
926 if (lower_transport == RTSP_LOWER_TRANSPORT_UDP) { |
0 | 927 char buf[256]; |
928 | |
929 /* first try in specified port range */ | |
774 | 930 if (RTSP_RTP_PORT_MIN != 0) { |
931 while(j <= RTSP_RTP_PORT_MAX) { | |
2711
0ff7c5289e68
Specify the server address when opening an rtp:// URL in rtsp.c, so
lucabe
parents:
2684
diff
changeset
|
932 snprintf(buf, sizeof(buf), "rtp://%s?localport=%d", host, j); |
2684
3dd4b622f4e3
If local port n is not available, try n + 2 instead of continuing to bind
lucabe
parents:
2681
diff
changeset
|
933 j += 2; /* we will use two port by rtp stream (rtp and rtcp) */ |
1425
00d9393a126f
make ffmpeg able to send back a RTCP receiver report.
gpoirier
parents:
1424
diff
changeset
|
934 if (url_open(&rtsp_st->rtp_handle, buf, URL_RDWR) == 0) { |
0 | 935 goto rtp_opened; |
774 | 936 } |
0 | 937 } |
938 } | |
939 | |
774 | 940 /* then try on any port |
941 ** if (url_open(&rtsp_st->rtp_handle, "rtp://", URL_RDONLY) < 0) { | |
942 ** err = AVERROR_INVALIDDATA; | |
943 ** goto fail; | |
944 ** } | |
945 */ | |
0 | 946 |
947 rtp_opened: | |
294
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
229
diff
changeset
|
948 port = rtp_get_local_port(rtsp_st->rtp_handle); |
3877
3e0c7ad2a675
Remove unused code that used to handle protocol concatenation, i.e. trying
rbultje
parents:
3876
diff
changeset
|
949 snprintf(transport, sizeof(transport) - 1, |
3958
ab2d2bc3a6e7
Send improper UDP SETUP request, which is what Realmedia servers expect.
rbultje
parents:
3957
diff
changeset
|
950 "%s/UDP;", trans_pref); |
ab2d2bc3a6e7
Send improper UDP SETUP request, which is what Realmedia servers expect.
rbultje
parents:
3957
diff
changeset
|
951 if (rt->server_type != RTSP_SERVER_REAL) |
ab2d2bc3a6e7
Send improper UDP SETUP request, which is what Realmedia servers expect.
rbultje
parents:
3957
diff
changeset
|
952 av_strlcat(transport, "unicast;", sizeof(transport)); |
ab2d2bc3a6e7
Send improper UDP SETUP request, which is what Realmedia servers expect.
rbultje
parents:
3957
diff
changeset
|
953 av_strlcatf(transport, sizeof(transport), |
ab2d2bc3a6e7
Send improper UDP SETUP request, which is what Realmedia servers expect.
rbultje
parents:
3957
diff
changeset
|
954 "client_port=%d", port); |
3876
1026953d4ffe
Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
3861
diff
changeset
|
955 if (rt->server_type == RTSP_SERVER_RTP) |
1026953d4ffe
Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
3861
diff
changeset
|
956 av_strlcatf(transport, sizeof(transport), "-%d", port + 1); |
0 | 957 } |
958 | |
959 /* RTP/TCP */ | |
3957
9f943bb755f9
Rename RTSPProtocol to RTSPLowerTransport, so that its name properly tells us
rbultje
parents:
3941
diff
changeset
|
960 else if (lower_transport == RTSP_LOWER_TRANSPORT_TCP) { |
3877
3e0c7ad2a675
Remove unused code that used to handle protocol concatenation, i.e. trying
rbultje
parents:
3876
diff
changeset
|
961 snprintf(transport, sizeof(transport) - 1, |
3876
1026953d4ffe
Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
3861
diff
changeset
|
962 "%s/TCP", trans_pref); |
0 | 963 } |
964 | |
3957
9f943bb755f9
Rename RTSPProtocol to RTSPLowerTransport, so that its name properly tells us
rbultje
parents:
3941
diff
changeset
|
965 else if (lower_transport == RTSP_LOWER_TRANSPORT_UDP_MULTICAST) { |
3877
3e0c7ad2a675
Remove unused code that used to handle protocol concatenation, i.e. trying
rbultje
parents:
3876
diff
changeset
|
966 snprintf(transport, sizeof(transport) - 1, |
3876
1026953d4ffe
Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
3861
diff
changeset
|
967 "%s/UDP;multicast", trans_pref); |
0 | 968 } |
3923
83e51bcb03c2
Rename RTSP_SERVER_RDT to RTSP_SERVER_REAL, because RDT (the transport
rbultje
parents:
3920
diff
changeset
|
969 if (rt->server_type == RTSP_SERVER_REAL) |
3876
1026953d4ffe
Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
3861
diff
changeset
|
970 av_strlcat(transport, ";mode=play", sizeof(transport)); |
885 | 971 snprintf(cmd, sizeof(cmd), |
172 | 972 "SETUP %s RTSP/1.0\r\n" |
973 "Transport: %s\r\n", | |
0 | 974 rtsp_st->control_url, transport); |
3923
83e51bcb03c2
Rename RTSP_SERVER_RDT to RTSP_SERVER_REAL, because RDT (the transport
rbultje
parents:
3920
diff
changeset
|
975 if (i == 0 && rt->server_type == RTSP_SERVER_REAL) { |
3876
1026953d4ffe
Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
3861
diff
changeset
|
976 char real_res[41], real_csum[9]; |
1026953d4ffe
Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
3861
diff
changeset
|
977 ff_rdt_calc_response_and_checksum(real_res, real_csum, |
1026953d4ffe
Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
3861
diff
changeset
|
978 real_challenge); |
1026953d4ffe
Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
3861
diff
changeset
|
979 av_strlcatf(cmd, sizeof(cmd), |
1026953d4ffe
Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
3861
diff
changeset
|
980 "If-Match: %s\r\n" |
1026953d4ffe
Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
3861
diff
changeset
|
981 "RealChallenge2: %s, sd=%s\r\n", |
1026953d4ffe
Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
3861
diff
changeset
|
982 rt->session_id, real_res, real_csum); |
1026953d4ffe
Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
3861
diff
changeset
|
983 } |
0 | 984 rtsp_send_cmd(s, cmd, reply, NULL); |
3149
5a7a7406ab1f
Allow cycling between different protocols (TCP, UDP or multicast) so that if
rbultje
parents:
3147
diff
changeset
|
985 if (reply->status_code == 461 /* Unsupported protocol */ && i == 0) { |
5a7a7406ab1f
Allow cycling between different protocols (TCP, UDP or multicast) so that if
rbultje
parents:
3147
diff
changeset
|
986 err = 1; |
5a7a7406ab1f
Allow cycling between different protocols (TCP, UDP or multicast) so that if
rbultje
parents:
3147
diff
changeset
|
987 goto fail; |
3151 | 988 } else if (reply->status_code != RTSP_STATUS_OK || |
989 reply->nb_transports != 1) { | |
0 | 990 err = AVERROR_INVALIDDATA; |
991 goto fail; | |
992 } | |
993 | |
994 /* XXX: same protocol for all streams is required */ | |
995 if (i > 0) { | |
3957
9f943bb755f9
Rename RTSPProtocol to RTSPLowerTransport, so that its name properly tells us
rbultje
parents:
3941
diff
changeset
|
996 if (reply->transports[0].lower_transport != rt->lower_transport) { |
0 | 997 err = AVERROR_INVALIDDATA; |
998 goto fail; | |
999 } | |
1000 } else { | |
3957
9f943bb755f9
Rename RTSPProtocol to RTSPLowerTransport, so that its name properly tells us
rbultje
parents:
3941
diff
changeset
|
1001 rt->lower_transport = reply->transports[0].lower_transport; |
0 | 1002 } |
1003 | |
1004 /* close RTP connection if not choosen */ | |
3957
9f943bb755f9
Rename RTSPProtocol to RTSPLowerTransport, so that its name properly tells us
rbultje
parents:
3941
diff
changeset
|
1005 if (reply->transports[0].lower_transport != RTSP_LOWER_TRANSPORT_UDP && |
9f943bb755f9
Rename RTSPProtocol to RTSPLowerTransport, so that its name properly tells us
rbultje
parents:
3941
diff
changeset
|
1006 (lower_transport == RTSP_LOWER_TRANSPORT_UDP)) { |
294
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
229
diff
changeset
|
1007 url_close(rtsp_st->rtp_handle); |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
229
diff
changeset
|
1008 rtsp_st->rtp_handle = NULL; |
0 | 1009 } |
1010 | |
3957
9f943bb755f9
Rename RTSPProtocol to RTSPLowerTransport, so that its name properly tells us
rbultje
parents:
3941
diff
changeset
|
1011 switch(reply->transports[0].lower_transport) { |
9f943bb755f9
Rename RTSPProtocol to RTSPLowerTransport, so that its name properly tells us
rbultje
parents:
3941
diff
changeset
|
1012 case RTSP_LOWER_TRANSPORT_TCP: |
0 | 1013 rtsp_st->interleaved_min = reply->transports[0].interleaved_min; |
1014 rtsp_st->interleaved_max = reply->transports[0].interleaved_max; | |
1015 break; | |
885 | 1016 |
3957
9f943bb755f9
Rename RTSPProtocol to RTSPLowerTransport, so that its name properly tells us
rbultje
parents:
3941
diff
changeset
|
1017 case RTSP_LOWER_TRANSPORT_UDP: |
0 | 1018 { |
1019 char url[1024]; | |
885 | 1020 |
0 | 1021 /* XXX: also use address if specified */ |
885 | 1022 snprintf(url, sizeof(url), "rtp://%s:%d", |
0 | 1023 host, reply->transports[0].server_port_min); |
294
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
229
diff
changeset
|
1024 if (rtp_set_remote_url(rtsp_st->rtp_handle, url) < 0) { |
0 | 1025 err = AVERROR_INVALIDDATA; |
1026 goto fail; | |
1027 } | |
1028 } | |
1029 break; | |
3957
9f943bb755f9
Rename RTSPProtocol to RTSPLowerTransport, so that its name properly tells us
rbultje
parents:
3941
diff
changeset
|
1030 case RTSP_LOWER_TRANSPORT_UDP_MULTICAST: |
0 | 1031 { |
1032 char url[1024]; | |
2246
6dade35dc9b3
rtsp multicast fix by Thijs Vermeir $1$2@gmail.com
lu_zero
parents:
2222
diff
changeset
|
1033 struct in_addr in; |
0 | 1034 |
2246
6dade35dc9b3
rtsp multicast fix by Thijs Vermeir $1$2@gmail.com
lu_zero
parents:
2222
diff
changeset
|
1035 in.s_addr = htonl(reply->transports[0].destination); |
3221 | 1036 snprintf(url, sizeof(url), "rtp://%s:%d?ttl=%d", |
2246
6dade35dc9b3
rtsp multicast fix by Thijs Vermeir $1$2@gmail.com
lu_zero
parents:
2222
diff
changeset
|
1037 inet_ntoa(in), |
6dade35dc9b3
rtsp multicast fix by Thijs Vermeir $1$2@gmail.com
lu_zero
parents:
2222
diff
changeset
|
1038 reply->transports[0].port_min, |
6dade35dc9b3
rtsp multicast fix by Thijs Vermeir $1$2@gmail.com
lu_zero
parents:
2222
diff
changeset
|
1039 reply->transports[0].ttl); |
1425
00d9393a126f
make ffmpeg able to send back a RTCP receiver report.
gpoirier
parents:
1424
diff
changeset
|
1040 if (url_open(&rtsp_st->rtp_handle, url, URL_RDWR) < 0) { |
0 | 1041 err = AVERROR_INVALIDDATA; |
1042 goto fail; | |
1043 } | |
1044 } | |
1045 break; | |
1046 } | |
774 | 1047 |
3919
1879eab34f88
Factorize out common code for opening of the RTP parsing context between
rbultje
parents:
3905
diff
changeset
|
1048 if ((err = rtsp_open_transport_ctx(s, rtsp_st))) |
294
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
229
diff
changeset
|
1049 goto fail; |
0 | 1050 } |
1051 | |
3923
83e51bcb03c2
Rename RTSP_SERVER_RDT to RTSP_SERVER_REAL, because RDT (the transport
rbultje
parents:
3920
diff
changeset
|
1052 if (rt->server_type == RTSP_SERVER_REAL) |
3903
aeb79f68ba7e
Implement a RDT-specific SET_PARAMETER command that subscribes to the
rbultje
parents:
3877
diff
changeset
|
1053 rt->need_subscription = 1; |
aeb79f68ba7e
Implement a RDT-specific SET_PARAMETER command that subscribes to the
rbultje
parents:
3877
diff
changeset
|
1054 |
3147
91d65fdf91e1
Split the SETUP request into a separate function, as a prelude into allowing
rbultje
parents:
2884
diff
changeset
|
1055 return 0; |
91d65fdf91e1
Split the SETUP request into a separate function, as a prelude into allowing
rbultje
parents:
2884
diff
changeset
|
1056 |
91d65fdf91e1
Split the SETUP request into a separate function, as a prelude into allowing
rbultje
parents:
2884
diff
changeset
|
1057 fail: |
3149
5a7a7406ab1f
Allow cycling between different protocols (TCP, UDP or multicast) so that if
rbultje
parents:
3147
diff
changeset
|
1058 for (i=0; i<rt->nb_rtsp_streams; i++) { |
5a7a7406ab1f
Allow cycling between different protocols (TCP, UDP or multicast) so that if
rbultje
parents:
3147
diff
changeset
|
1059 if (rt->rtsp_streams[i]->rtp_handle) { |
5a7a7406ab1f
Allow cycling between different protocols (TCP, UDP or multicast) so that if
rbultje
parents:
3147
diff
changeset
|
1060 url_close(rt->rtsp_streams[i]->rtp_handle); |
5a7a7406ab1f
Allow cycling between different protocols (TCP, UDP or multicast) so that if
rbultje
parents:
3147
diff
changeset
|
1061 rt->rtsp_streams[i]->rtp_handle = NULL; |
5a7a7406ab1f
Allow cycling between different protocols (TCP, UDP or multicast) so that if
rbultje
parents:
3147
diff
changeset
|
1062 } |
5a7a7406ab1f
Allow cycling between different protocols (TCP, UDP or multicast) so that if
rbultje
parents:
3147
diff
changeset
|
1063 } |
3147
91d65fdf91e1
Split the SETUP request into a separate function, as a prelude into allowing
rbultje
parents:
2884
diff
changeset
|
1064 return err; |
91d65fdf91e1
Split the SETUP request into a separate function, as a prelude into allowing
rbultje
parents:
2884
diff
changeset
|
1065 } |
91d65fdf91e1
Split the SETUP request into a separate function, as a prelude into allowing
rbultje
parents:
2884
diff
changeset
|
1066 |
91d65fdf91e1
Split the SETUP request into a separate function, as a prelude into allowing
rbultje
parents:
2884
diff
changeset
|
1067 static int rtsp_read_header(AVFormatContext *s, |
91d65fdf91e1
Split the SETUP request into a separate function, as a prelude into allowing
rbultje
parents:
2884
diff
changeset
|
1068 AVFormatParameters *ap) |
91d65fdf91e1
Split the SETUP request into a separate function, as a prelude into allowing
rbultje
parents:
2884
diff
changeset
|
1069 { |
91d65fdf91e1
Split the SETUP request into a separate function, as a prelude into allowing
rbultje
parents:
2884
diff
changeset
|
1070 RTSPState *rt = s->priv_data; |
91d65fdf91e1
Split the SETUP request into a separate function, as a prelude into allowing
rbultje
parents:
2884
diff
changeset
|
1071 char host[1024], path[1024], tcpname[1024], cmd[2048], *option_list, *option; |
91d65fdf91e1
Split the SETUP request into a separate function, as a prelude into allowing
rbultje
parents:
2884
diff
changeset
|
1072 URLContext *rtsp_hd; |
91d65fdf91e1
Split the SETUP request into a separate function, as a prelude into allowing
rbultje
parents:
2884
diff
changeset
|
1073 int port, ret, err; |
91d65fdf91e1
Split the SETUP request into a separate function, as a prelude into allowing
rbultje
parents:
2884
diff
changeset
|
1074 RTSPHeader reply1, *reply = &reply1; |
91d65fdf91e1
Split the SETUP request into a separate function, as a prelude into allowing
rbultje
parents:
2884
diff
changeset
|
1075 unsigned char *content = NULL; |
3957
9f943bb755f9
Rename RTSPProtocol to RTSPLowerTransport, so that its name properly tells us
rbultje
parents:
3941
diff
changeset
|
1076 int lower_transport_mask = 0; |
3856 | 1077 char real_challenge[64]; |
3147
91d65fdf91e1
Split the SETUP request into a separate function, as a prelude into allowing
rbultje
parents:
2884
diff
changeset
|
1078 |
91d65fdf91e1
Split the SETUP request into a separate function, as a prelude into allowing
rbultje
parents:
2884
diff
changeset
|
1079 /* extract hostname and port */ |
91d65fdf91e1
Split the SETUP request into a separate function, as a prelude into allowing
rbultje
parents:
2884
diff
changeset
|
1080 url_split(NULL, 0, NULL, 0, |
91d65fdf91e1
Split the SETUP request into a separate function, as a prelude into allowing
rbultje
parents:
2884
diff
changeset
|
1081 host, sizeof(host), &port, path, sizeof(path), s->filename); |
91d65fdf91e1
Split the SETUP request into a separate function, as a prelude into allowing
rbultje
parents:
2884
diff
changeset
|
1082 if (port < 0) |
91d65fdf91e1
Split the SETUP request into a separate function, as a prelude into allowing
rbultje
parents:
2884
diff
changeset
|
1083 port = RTSP_DEFAULT_PORT; |
91d65fdf91e1
Split the SETUP request into a separate function, as a prelude into allowing
rbultje
parents:
2884
diff
changeset
|
1084 |
91d65fdf91e1
Split the SETUP request into a separate function, as a prelude into allowing
rbultje
parents:
2884
diff
changeset
|
1085 /* search for options */ |
91d65fdf91e1
Split the SETUP request into a separate function, as a prelude into allowing
rbultje
parents:
2884
diff
changeset
|
1086 option_list = strchr(path, '?'); |
91d65fdf91e1
Split the SETUP request into a separate function, as a prelude into allowing
rbultje
parents:
2884
diff
changeset
|
1087 if (option_list) { |
91d65fdf91e1
Split the SETUP request into a separate function, as a prelude into allowing
rbultje
parents:
2884
diff
changeset
|
1088 /* remove the options from the path */ |
91d65fdf91e1
Split the SETUP request into a separate function, as a prelude into allowing
rbultje
parents:
2884
diff
changeset
|
1089 *option_list++ = 0; |
91d65fdf91e1
Split the SETUP request into a separate function, as a prelude into allowing
rbultje
parents:
2884
diff
changeset
|
1090 while(option_list) { |
91d65fdf91e1
Split the SETUP request into a separate function, as a prelude into allowing
rbultje
parents:
2884
diff
changeset
|
1091 /* move the option pointer */ |
91d65fdf91e1
Split the SETUP request into a separate function, as a prelude into allowing
rbultje
parents:
2884
diff
changeset
|
1092 option = option_list; |
91d65fdf91e1
Split the SETUP request into a separate function, as a prelude into allowing
rbultje
parents:
2884
diff
changeset
|
1093 option_list = strchr(option_list, '&'); |
91d65fdf91e1
Split the SETUP request into a separate function, as a prelude into allowing
rbultje
parents:
2884
diff
changeset
|
1094 if (option_list) |
91d65fdf91e1
Split the SETUP request into a separate function, as a prelude into allowing
rbultje
parents:
2884
diff
changeset
|
1095 *(option_list++) = 0; |
91d65fdf91e1
Split the SETUP request into a separate function, as a prelude into allowing
rbultje
parents:
2884
diff
changeset
|
1096 /* handle the options */ |
91d65fdf91e1
Split the SETUP request into a separate function, as a prelude into allowing
rbultje
parents:
2884
diff
changeset
|
1097 if (strcmp(option, "udp") == 0) |
3957
9f943bb755f9
Rename RTSPProtocol to RTSPLowerTransport, so that its name properly tells us
rbultje
parents:
3941
diff
changeset
|
1098 lower_transport_mask = (1<< RTSP_LOWER_TRANSPORT_UDP); |
3147
91d65fdf91e1
Split the SETUP request into a separate function, as a prelude into allowing
rbultje
parents:
2884
diff
changeset
|
1099 else if (strcmp(option, "multicast") == 0) |
3957
9f943bb755f9
Rename RTSPProtocol to RTSPLowerTransport, so that its name properly tells us
rbultje
parents:
3941
diff
changeset
|
1100 lower_transport_mask = (1<< RTSP_LOWER_TRANSPORT_UDP_MULTICAST); |
3147
91d65fdf91e1
Split the SETUP request into a separate function, as a prelude into allowing
rbultje
parents:
2884
diff
changeset
|
1101 else if (strcmp(option, "tcp") == 0) |
3957
9f943bb755f9
Rename RTSPProtocol to RTSPLowerTransport, so that its name properly tells us
rbultje
parents:
3941
diff
changeset
|
1102 lower_transport_mask = (1<< RTSP_LOWER_TRANSPORT_TCP); |
3147
91d65fdf91e1
Split the SETUP request into a separate function, as a prelude into allowing
rbultje
parents:
2884
diff
changeset
|
1103 } |
91d65fdf91e1
Split the SETUP request into a separate function, as a prelude into allowing
rbultje
parents:
2884
diff
changeset
|
1104 } |
91d65fdf91e1
Split the SETUP request into a separate function, as a prelude into allowing
rbultje
parents:
2884
diff
changeset
|
1105 |
3957
9f943bb755f9
Rename RTSPProtocol to RTSPLowerTransport, so that its name properly tells us
rbultje
parents:
3941
diff
changeset
|
1106 if (!lower_transport_mask) |
9f943bb755f9
Rename RTSPProtocol to RTSPLowerTransport, so that its name properly tells us
rbultje
parents:
3941
diff
changeset
|
1107 lower_transport_mask = (1 << RTSP_LOWER_TRANSPORT_LAST) - 1; |
3147
91d65fdf91e1
Split the SETUP request into a separate function, as a prelude into allowing
rbultje
parents:
2884
diff
changeset
|
1108 |
91d65fdf91e1
Split the SETUP request into a separate function, as a prelude into allowing
rbultje
parents:
2884
diff
changeset
|
1109 /* open the tcp connexion */ |
91d65fdf91e1
Split the SETUP request into a separate function, as a prelude into allowing
rbultje
parents:
2884
diff
changeset
|
1110 snprintf(tcpname, sizeof(tcpname), "tcp://%s:%d", host, port); |
91d65fdf91e1
Split the SETUP request into a separate function, as a prelude into allowing
rbultje
parents:
2884
diff
changeset
|
1111 if (url_open(&rtsp_hd, tcpname, URL_RDWR) < 0) |
91d65fdf91e1
Split the SETUP request into a separate function, as a prelude into allowing
rbultje
parents:
2884
diff
changeset
|
1112 return AVERROR(EIO); |
91d65fdf91e1
Split the SETUP request into a separate function, as a prelude into allowing
rbultje
parents:
2884
diff
changeset
|
1113 rt->rtsp_hd = rtsp_hd; |
91d65fdf91e1
Split the SETUP request into a separate function, as a prelude into allowing
rbultje
parents:
2884
diff
changeset
|
1114 rt->seq = 0; |
91d65fdf91e1
Split the SETUP request into a separate function, as a prelude into allowing
rbultje
parents:
2884
diff
changeset
|
1115 |
3856 | 1116 /* request options supported by the server; this also detects server type */ |
1117 for (rt->server_type = RTSP_SERVER_RTP;;) { | |
1118 snprintf(cmd, sizeof(cmd), | |
1119 "OPTIONS %s RTSP/1.0\r\n", s->filename); | |
3923
83e51bcb03c2
Rename RTSP_SERVER_RDT to RTSP_SERVER_REAL, because RDT (the transport
rbultje
parents:
3920
diff
changeset
|
1120 if (rt->server_type == RTSP_SERVER_REAL) |
3856 | 1121 av_strlcat(cmd, |
1122 /** | |
1123 * The following entries are required for proper | |
1124 * streaming from a Realmedia server. They are | |
1125 * interdependent in some way although we currently | |
1126 * don't quite understand how. Values were copied | |
1127 * from mplayer SVN r23589. | |
1128 * @param CompanyID is a 16-byte ID in base64 | |
1129 * @param ClientChallenge is a 16-byte ID in hex | |
1130 */ | |
1131 "ClientChallenge: 9e26d33f2984236010ef6253fb1887f7\r\n" | |
1132 "PlayerStarttime: [28/03/2003:22:50:23 00:00]\r\n" | |
1133 "CompanyID: KnKV4M4I/B2FjJ1TToLycw==\r\n" | |
1134 "GUID: 00000000-0000-0000-0000-000000000000\r\n", | |
1135 sizeof(cmd)); | |
1136 rtsp_send_cmd(s, cmd, reply, NULL); | |
1137 if (reply->status_code != RTSP_STATUS_OK) { | |
1138 err = AVERROR_INVALIDDATA; | |
1139 goto fail; | |
1140 } | |
1141 | |
1142 /* detect server type if not standard-compliant RTP */ | |
3923
83e51bcb03c2
Rename RTSP_SERVER_RDT to RTSP_SERVER_REAL, because RDT (the transport
rbultje
parents:
3920
diff
changeset
|
1143 if (rt->server_type != RTSP_SERVER_REAL && reply->real_challenge[0]) { |
83e51bcb03c2
Rename RTSP_SERVER_RDT to RTSP_SERVER_REAL, because RDT (the transport
rbultje
parents:
3920
diff
changeset
|
1144 rt->server_type = RTSP_SERVER_REAL; |
3856 | 1145 continue; |
3923
83e51bcb03c2
Rename RTSP_SERVER_RDT to RTSP_SERVER_REAL, because RDT (the transport
rbultje
parents:
3920
diff
changeset
|
1146 } else if (rt->server_type == RTSP_SERVER_REAL) { |
3856 | 1147 strcpy(real_challenge, reply->real_challenge); |
1148 } | |
1149 break; | |
1150 } | |
1151 | |
3147
91d65fdf91e1
Split the SETUP request into a separate function, as a prelude into allowing
rbultje
parents:
2884
diff
changeset
|
1152 /* describe the stream */ |
91d65fdf91e1
Split the SETUP request into a separate function, as a prelude into allowing
rbultje
parents:
2884
diff
changeset
|
1153 snprintf(cmd, sizeof(cmd), |
91d65fdf91e1
Split the SETUP request into a separate function, as a prelude into allowing
rbultje
parents:
2884
diff
changeset
|
1154 "DESCRIBE %s RTSP/1.0\r\n" |
91d65fdf91e1
Split the SETUP request into a separate function, as a prelude into allowing
rbultje
parents:
2884
diff
changeset
|
1155 "Accept: application/sdp\r\n", |
91d65fdf91e1
Split the SETUP request into a separate function, as a prelude into allowing
rbultje
parents:
2884
diff
changeset
|
1156 s->filename); |
3923
83e51bcb03c2
Rename RTSP_SERVER_RDT to RTSP_SERVER_REAL, because RDT (the transport
rbultje
parents:
3920
diff
changeset
|
1157 if (rt->server_type == RTSP_SERVER_REAL) { |
3859 | 1158 /** |
1159 * The Require: attribute is needed for proper streaming from | |
1160 * Realmedia servers. | |
1161 */ | |
1162 av_strlcat(cmd, | |
1163 "Require: com.real.retain-entity-for-setup\r\n", | |
1164 sizeof(cmd)); | |
1165 } | |
3147
91d65fdf91e1
Split the SETUP request into a separate function, as a prelude into allowing
rbultje
parents:
2884
diff
changeset
|
1166 rtsp_send_cmd(s, cmd, reply, &content); |
91d65fdf91e1
Split the SETUP request into a separate function, as a prelude into allowing
rbultje
parents:
2884
diff
changeset
|
1167 if (!content) { |
91d65fdf91e1
Split the SETUP request into a separate function, as a prelude into allowing
rbultje
parents:
2884
diff
changeset
|
1168 err = AVERROR_INVALIDDATA; |
91d65fdf91e1
Split the SETUP request into a separate function, as a prelude into allowing
rbultje
parents:
2884
diff
changeset
|
1169 goto fail; |
91d65fdf91e1
Split the SETUP request into a separate function, as a prelude into allowing
rbultje
parents:
2884
diff
changeset
|
1170 } |
91d65fdf91e1
Split the SETUP request into a separate function, as a prelude into allowing
rbultje
parents:
2884
diff
changeset
|
1171 if (reply->status_code != RTSP_STATUS_OK) { |
91d65fdf91e1
Split the SETUP request into a separate function, as a prelude into allowing
rbultje
parents:
2884
diff
changeset
|
1172 err = AVERROR_INVALIDDATA; |
91d65fdf91e1
Split the SETUP request into a separate function, as a prelude into allowing
rbultje
parents:
2884
diff
changeset
|
1173 goto fail; |
91d65fdf91e1
Split the SETUP request into a separate function, as a prelude into allowing
rbultje
parents:
2884
diff
changeset
|
1174 } |
91d65fdf91e1
Split the SETUP request into a separate function, as a prelude into allowing
rbultje
parents:
2884
diff
changeset
|
1175 |
91d65fdf91e1
Split the SETUP request into a separate function, as a prelude into allowing
rbultje
parents:
2884
diff
changeset
|
1176 /* now we got the SDP description, we parse it */ |
91d65fdf91e1
Split the SETUP request into a separate function, as a prelude into allowing
rbultje
parents:
2884
diff
changeset
|
1177 ret = sdp_parse(s, (const char *)content); |
91d65fdf91e1
Split the SETUP request into a separate function, as a prelude into allowing
rbultje
parents:
2884
diff
changeset
|
1178 av_freep(&content); |
91d65fdf91e1
Split the SETUP request into a separate function, as a prelude into allowing
rbultje
parents:
2884
diff
changeset
|
1179 if (ret < 0) { |
91d65fdf91e1
Split the SETUP request into a separate function, as a prelude into allowing
rbultje
parents:
2884
diff
changeset
|
1180 err = AVERROR_INVALIDDATA; |
91d65fdf91e1
Split the SETUP request into a separate function, as a prelude into allowing
rbultje
parents:
2884
diff
changeset
|
1181 goto fail; |
91d65fdf91e1
Split the SETUP request into a separate function, as a prelude into allowing
rbultje
parents:
2884
diff
changeset
|
1182 } |
91d65fdf91e1
Split the SETUP request into a separate function, as a prelude into allowing
rbultje
parents:
2884
diff
changeset
|
1183 |
3149
5a7a7406ab1f
Allow cycling between different protocols (TCP, UDP or multicast) so that if
rbultje
parents:
3147
diff
changeset
|
1184 do { |
3957
9f943bb755f9
Rename RTSPProtocol to RTSPLowerTransport, so that its name properly tells us
rbultje
parents:
3941
diff
changeset
|
1185 int lower_transport = ff_log2_tab[lower_transport_mask & ~(lower_transport_mask - 1)]; |
3149
5a7a7406ab1f
Allow cycling between different protocols (TCP, UDP or multicast) so that if
rbultje
parents:
3147
diff
changeset
|
1186 |
3957
9f943bb755f9
Rename RTSPProtocol to RTSPLowerTransport, so that its name properly tells us
rbultje
parents:
3941
diff
changeset
|
1187 err = make_setup_request(s, host, port, lower_transport, |
3923
83e51bcb03c2
Rename RTSP_SERVER_RDT to RTSP_SERVER_REAL, because RDT (the transport
rbultje
parents:
3920
diff
changeset
|
1188 rt->server_type == RTSP_SERVER_REAL ? |
3876
1026953d4ffe
Implement Realmedia/RTSP-compatible SETUP command. This includes calculation
rbultje
parents:
3861
diff
changeset
|
1189 real_challenge : NULL); |
3149
5a7a7406ab1f
Allow cycling between different protocols (TCP, UDP or multicast) so that if
rbultje
parents:
3147
diff
changeset
|
1190 if (err < 0) |
3151 | 1191 goto fail; |
3957
9f943bb755f9
Rename RTSPProtocol to RTSPLowerTransport, so that its name properly tells us
rbultje
parents:
3941
diff
changeset
|
1192 lower_transport_mask &= ~(1 << lower_transport); |
9f943bb755f9
Rename RTSPProtocol to RTSPLowerTransport, so that its name properly tells us
rbultje
parents:
3941
diff
changeset
|
1193 if (lower_transport_mask == 0 && err == 1) { |
3202
98e633b72d38
use FF_NETERROR to make winsock happy, patch from prossATxvidDoTorg
lu_zero
parents:
3151
diff
changeset
|
1194 err = AVERROR(FF_NETERROR(EPROTONOSUPPORT)); |
3149
5a7a7406ab1f
Allow cycling between different protocols (TCP, UDP or multicast) so that if
rbultje
parents:
3147
diff
changeset
|
1195 goto fail; |
5a7a7406ab1f
Allow cycling between different protocols (TCP, UDP or multicast) so that if
rbultje
parents:
3147
diff
changeset
|
1196 } |
5a7a7406ab1f
Allow cycling between different protocols (TCP, UDP or multicast) so that if
rbultje
parents:
3147
diff
changeset
|
1197 } while (err); |
3147
91d65fdf91e1
Split the SETUP request into a separate function, as a prelude into allowing
rbultje
parents:
2884
diff
changeset
|
1198 |
304
d58c8859ff8c
initial seek support - more generic play/pause support
bellard
parents:
294
diff
changeset
|
1199 rt->state = RTSP_STATE_IDLE; |
d58c8859ff8c
initial seek support - more generic play/pause support
bellard
parents:
294
diff
changeset
|
1200 rt->seek_timestamp = 0; /* default is to start stream at position |
d58c8859ff8c
initial seek support - more generic play/pause support
bellard
parents:
294
diff
changeset
|
1201 zero */ |
1003 | 1202 if (ap->initial_pause) { |
304
d58c8859ff8c
initial seek support - more generic play/pause support
bellard
parents:
294
diff
changeset
|
1203 /* do not start immediately */ |
d58c8859ff8c
initial seek support - more generic play/pause support
bellard
parents:
294
diff
changeset
|
1204 } else { |
d58c8859ff8c
initial seek support - more generic play/pause support
bellard
parents:
294
diff
changeset
|
1205 if (rtsp_read_play(s) < 0) { |
d58c8859ff8c
initial seek support - more generic play/pause support
bellard
parents:
294
diff
changeset
|
1206 err = AVERROR_INVALIDDATA; |
0 | 1207 goto fail; |
1208 } | |
1209 } | |
1210 return 0; | |
1211 fail: | |
294
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
229
diff
changeset
|
1212 rtsp_close_streams(rt); |
0 | 1213 av_freep(&content); |
1214 url_close(rt->rtsp_hd); | |
1215 return err; | |
1216 } | |
1217 | |
294
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
229
diff
changeset
|
1218 static int tcp_read_packet(AVFormatContext *s, RTSPStream **prtsp_st, |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
229
diff
changeset
|
1219 uint8_t *buf, int buf_size) |
0 | 1220 { |
1221 RTSPState *rt = s->priv_data; | |
172 | 1222 int id, len, i, ret; |
0 | 1223 RTSPStream *rtsp_st; |
1224 | |
172 | 1225 #ifdef DEBUG_RTP_TCP |
1226 printf("tcp_read_packet:\n"); | |
1227 #endif | |
0 | 1228 redo: |
1229 for(;;) { | |
391
1cf22651d33b
support url_read which reads less then requested patch by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
michael
parents:
370
diff
changeset
|
1230 ret = url_readbuf(rt->rtsp_hd, buf, 1); |
172 | 1231 #ifdef DEBUG_RTP_TCP |
1232 printf("ret=%d c=%02x [%c]\n", ret, buf[0], buf[0]); | |
1233 #endif | |
1234 if (ret != 1) | |
294
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
229
diff
changeset
|
1235 return -1; |
172 | 1236 if (buf[0] == '$') |
0 | 1237 break; |
1238 } | |
391
1cf22651d33b
support url_read which reads less then requested patch by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
michael
parents:
370
diff
changeset
|
1239 ret = url_readbuf(rt->rtsp_hd, buf, 3); |
172 | 1240 if (ret != 3) |
294
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
229
diff
changeset
|
1241 return -1; |
172 | 1242 id = buf[0]; |
2222 | 1243 len = AV_RB16(buf + 1); |
172 | 1244 #ifdef DEBUG_RTP_TCP |
1245 printf("id=%d len=%d\n", id, len); | |
1246 #endif | |
294
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
229
diff
changeset
|
1247 if (len > buf_size || len < 12) |
0 | 1248 goto redo; |
1249 /* get the data */ | |
391
1cf22651d33b
support url_read which reads less then requested patch by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
michael
parents:
370
diff
changeset
|
1250 ret = url_readbuf(rt->rtsp_hd, buf, len); |
172 | 1251 if (ret != len) |
294
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
229
diff
changeset
|
1252 return -1; |
885 | 1253 |
0 | 1254 /* find the matching stream */ |
294
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
229
diff
changeset
|
1255 for(i = 0; i < rt->nb_rtsp_streams; i++) { |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
229
diff
changeset
|
1256 rtsp_st = rt->rtsp_streams[i]; |
885 | 1257 if (id >= rtsp_st->interleaved_min && |
1258 id <= rtsp_st->interleaved_max) | |
0 | 1259 goto found; |
1260 } | |
1261 goto redo; | |
1262 found: | |
294
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
229
diff
changeset
|
1263 *prtsp_st = rtsp_st; |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
229
diff
changeset
|
1264 return len; |
0 | 1265 } |
1266 | |
885 | 1267 static int udp_read_packet(AVFormatContext *s, RTSPStream **prtsp_st, |
294
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
229
diff
changeset
|
1268 uint8_t *buf, int buf_size) |
0 | 1269 { |
294
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
229
diff
changeset
|
1270 RTSPState *rt = s->priv_data; |
0 | 1271 RTSPStream *rtsp_st; |
1272 fd_set rfds; | |
1273 int fd1, fd2, fd_max, n, i, ret; | |
1274 struct timeval tv; | |
1275 | |
1276 for(;;) { | |
179 | 1277 if (url_interrupt_cb()) |
2772
b43dc2901f83
Make av_read_frame with rtsp client return EINTR on interrupt
lu_zero
parents:
2771
diff
changeset
|
1278 return AVERROR(EINTR); |
0 | 1279 FD_ZERO(&rfds); |
1280 fd_max = -1; | |
294
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
229
diff
changeset
|
1281 for(i = 0; i < rt->nb_rtsp_streams; i++) { |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
229
diff
changeset
|
1282 rtsp_st = rt->rtsp_streams[i]; |
0 | 1283 /* currently, we cannot probe RTCP handle because of blocking restrictions */ |
294
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
229
diff
changeset
|
1284 rtp_get_file_handles(rtsp_st->rtp_handle, &fd1, &fd2); |
0 | 1285 if (fd1 > fd_max) |
1286 fd_max = fd1; | |
1287 FD_SET(fd1, &rfds); | |
1288 } | |
1289 tv.tv_sec = 0; | |
179 | 1290 tv.tv_usec = 100 * 1000; |
0 | 1291 n = select(fd_max + 1, &rfds, NULL, NULL, &tv); |
1292 if (n > 0) { | |
294
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
229
diff
changeset
|
1293 for(i = 0; i < rt->nb_rtsp_streams; i++) { |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
229
diff
changeset
|
1294 rtsp_st = rt->rtsp_streams[i]; |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
229
diff
changeset
|
1295 rtp_get_file_handles(rtsp_st->rtp_handle, &fd1, &fd2); |
0 | 1296 if (FD_ISSET(fd1, &rfds)) { |
294
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
229
diff
changeset
|
1297 ret = url_read(rtsp_st->rtp_handle, buf, buf_size); |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
229
diff
changeset
|
1298 if (ret > 0) { |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
229
diff
changeset
|
1299 *prtsp_st = rtsp_st; |
0 | 1300 return ret; |
1301 } | |
1302 } | |
1303 } | |
1304 } | |
1305 } | |
1306 } | |
1307 | |
1308 static int rtsp_read_packet(AVFormatContext *s, | |
1309 AVPacket *pkt) | |
1310 { | |
1311 RTSPState *rt = s->priv_data; | |
294
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
229
diff
changeset
|
1312 RTSPStream *rtsp_st; |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
229
diff
changeset
|
1313 int ret, len; |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
229
diff
changeset
|
1314 uint8_t buf[RTP_MAX_PACKET_LENGTH]; |
0 | 1315 |
3923
83e51bcb03c2
Rename RTSP_SERVER_RDT to RTSP_SERVER_REAL, because RDT (the transport
rbultje
parents:
3920
diff
changeset
|
1316 if (rt->server_type == RTSP_SERVER_REAL && rt->need_subscription) { |
3903
aeb79f68ba7e
Implement a RDT-specific SET_PARAMETER command that subscribes to the
rbultje
parents:
3877
diff
changeset
|
1317 int i; |
aeb79f68ba7e
Implement a RDT-specific SET_PARAMETER command that subscribes to the
rbultje
parents:
3877
diff
changeset
|
1318 RTSPHeader reply1, *reply = &reply1; |
aeb79f68ba7e
Implement a RDT-specific SET_PARAMETER command that subscribes to the
rbultje
parents:
3877
diff
changeset
|
1319 char cmd[1024]; |
aeb79f68ba7e
Implement a RDT-specific SET_PARAMETER command that subscribes to the
rbultje
parents:
3877
diff
changeset
|
1320 |
aeb79f68ba7e
Implement a RDT-specific SET_PARAMETER command that subscribes to the
rbultje
parents:
3877
diff
changeset
|
1321 snprintf(cmd, sizeof(cmd), |
aeb79f68ba7e
Implement a RDT-specific SET_PARAMETER command that subscribes to the
rbultje
parents:
3877
diff
changeset
|
1322 "SET_PARAMETER %s RTSP/1.0\r\n" |
aeb79f68ba7e
Implement a RDT-specific SET_PARAMETER command that subscribes to the
rbultje
parents:
3877
diff
changeset
|
1323 "Subscribe: ", |
aeb79f68ba7e
Implement a RDT-specific SET_PARAMETER command that subscribes to the
rbultje
parents:
3877
diff
changeset
|
1324 s->filename); |
aeb79f68ba7e
Implement a RDT-specific SET_PARAMETER command that subscribes to the
rbultje
parents:
3877
diff
changeset
|
1325 for (i = 0; i < rt->nb_rtsp_streams; i++) { |
aeb79f68ba7e
Implement a RDT-specific SET_PARAMETER command that subscribes to the
rbultje
parents:
3877
diff
changeset
|
1326 if (i != 0) av_strlcat(cmd, ",", sizeof(cmd)); |
3959
ed6f6aa977ec
Remove access to rdt_data struct in functions called outside of the
rbultje
parents:
3958
diff
changeset
|
1327 ff_rdt_subscribe_rule(cmd, sizeof(cmd), i, 0); |
ed6f6aa977ec
Remove access to rdt_data struct in functions called outside of the
rbultje
parents:
3958
diff
changeset
|
1328 ff_rdt_subscribe_rule2( |
3903
aeb79f68ba7e
Implement a RDT-specific SET_PARAMETER command that subscribes to the
rbultje
parents:
3877
diff
changeset
|
1329 rt->rtsp_streams[i]->rtp_ctx, |
aeb79f68ba7e
Implement a RDT-specific SET_PARAMETER command that subscribes to the
rbultje
parents:
3877
diff
changeset
|
1330 cmd, sizeof(cmd), i, 0); |
aeb79f68ba7e
Implement a RDT-specific SET_PARAMETER command that subscribes to the
rbultje
parents:
3877
diff
changeset
|
1331 } |
aeb79f68ba7e
Implement a RDT-specific SET_PARAMETER command that subscribes to the
rbultje
parents:
3877
diff
changeset
|
1332 av_strlcat(cmd, "\r\n", sizeof(cmd)); |
aeb79f68ba7e
Implement a RDT-specific SET_PARAMETER command that subscribes to the
rbultje
parents:
3877
diff
changeset
|
1333 rtsp_send_cmd(s, cmd, reply, NULL); |
aeb79f68ba7e
Implement a RDT-specific SET_PARAMETER command that subscribes to the
rbultje
parents:
3877
diff
changeset
|
1334 if (reply->status_code != RTSP_STATUS_OK) |
aeb79f68ba7e
Implement a RDT-specific SET_PARAMETER command that subscribes to the
rbultje
parents:
3877
diff
changeset
|
1335 return AVERROR_INVALIDDATA; |
aeb79f68ba7e
Implement a RDT-specific SET_PARAMETER command that subscribes to the
rbultje
parents:
3877
diff
changeset
|
1336 rt->need_subscription = 0; |
aeb79f68ba7e
Implement a RDT-specific SET_PARAMETER command that subscribes to the
rbultje
parents:
3877
diff
changeset
|
1337 |
aeb79f68ba7e
Implement a RDT-specific SET_PARAMETER command that subscribes to the
rbultje
parents:
3877
diff
changeset
|
1338 if (rt->state == RTSP_STATE_PLAYING) |
aeb79f68ba7e
Implement a RDT-specific SET_PARAMETER command that subscribes to the
rbultje
parents:
3877
diff
changeset
|
1339 rtsp_read_play (s); |
aeb79f68ba7e
Implement a RDT-specific SET_PARAMETER command that subscribes to the
rbultje
parents:
3877
diff
changeset
|
1340 } |
aeb79f68ba7e
Implement a RDT-specific SET_PARAMETER command that subscribes to the
rbultje
parents:
3877
diff
changeset
|
1341 |
294
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
229
diff
changeset
|
1342 /* get next frames from the same RTP packet */ |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
229
diff
changeset
|
1343 if (rt->cur_rtp) { |
3923
83e51bcb03c2
Rename RTSP_SERVER_RDT to RTSP_SERVER_REAL, because RDT (the transport
rbultje
parents:
3920
diff
changeset
|
1344 if (rt->server_type == RTSP_SERVER_REAL) |
3905
91987686113d
Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents:
3904
diff
changeset
|
1345 ret = ff_rdt_parse_packet(rt->cur_rtp, pkt, NULL, 0); |
91987686113d
Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents:
3904
diff
changeset
|
1346 else |
91987686113d
Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents:
3904
diff
changeset
|
1347 ret = rtp_parse_packet(rt->cur_rtp, pkt, NULL, 0); |
294
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
229
diff
changeset
|
1348 if (ret == 0) { |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
229
diff
changeset
|
1349 rt->cur_rtp = NULL; |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
229
diff
changeset
|
1350 return 0; |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
229
diff
changeset
|
1351 } else if (ret == 1) { |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
229
diff
changeset
|
1352 return 0; |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
229
diff
changeset
|
1353 } else { |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
229
diff
changeset
|
1354 rt->cur_rtp = NULL; |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
229
diff
changeset
|
1355 } |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
229
diff
changeset
|
1356 } |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
229
diff
changeset
|
1357 |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
229
diff
changeset
|
1358 /* read next RTP packet */ |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
229
diff
changeset
|
1359 redo: |
3957
9f943bb755f9
Rename RTSPProtocol to RTSPLowerTransport, so that its name properly tells us
rbultje
parents:
3941
diff
changeset
|
1360 switch(rt->lower_transport) { |
0 | 1361 default: |
3957
9f943bb755f9
Rename RTSPProtocol to RTSPLowerTransport, so that its name properly tells us
rbultje
parents:
3941
diff
changeset
|
1362 case RTSP_LOWER_TRANSPORT_TCP: |
294
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
229
diff
changeset
|
1363 len = tcp_read_packet(s, &rtsp_st, buf, sizeof(buf)); |
0 | 1364 break; |
3957
9f943bb755f9
Rename RTSPProtocol to RTSPLowerTransport, so that its name properly tells us
rbultje
parents:
3941
diff
changeset
|
1365 case RTSP_LOWER_TRANSPORT_UDP: |
9f943bb755f9
Rename RTSPProtocol to RTSPLowerTransport, so that its name properly tells us
rbultje
parents:
3941
diff
changeset
|
1366 case RTSP_LOWER_TRANSPORT_UDP_MULTICAST: |
294
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
229
diff
changeset
|
1367 len = udp_read_packet(s, &rtsp_st, buf, sizeof(buf)); |
2219
fa6c59a5ab0d
check udp_read_packet return value not to access uninitialized memory
benoit
parents:
2193
diff
changeset
|
1368 if (len >=0 && rtsp_st->rtp_ctx) |
1425
00d9393a126f
make ffmpeg able to send back a RTCP receiver report.
gpoirier
parents:
1424
diff
changeset
|
1369 rtp_check_and_send_back_rr(rtsp_st->rtp_ctx, len); |
0 | 1370 break; |
1371 } | |
294
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
229
diff
changeset
|
1372 if (len < 0) |
2775
1301147d9450
Make av_read_frame with rtsp client return EINTR on interrupt
lu_zero
parents:
2772
diff
changeset
|
1373 return len; |
3923
83e51bcb03c2
Rename RTSP_SERVER_RDT to RTSP_SERVER_REAL, because RDT (the transport
rbultje
parents:
3920
diff
changeset
|
1374 if (rt->server_type == RTSP_SERVER_REAL) |
3905
91987686113d
Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents:
3904
diff
changeset
|
1375 ret = ff_rdt_parse_packet(rtsp_st->rtp_ctx, pkt, buf, len); |
91987686113d
Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents:
3904
diff
changeset
|
1376 else |
91987686113d
Implement RDT-specific data parsing routines. After these changes, simple
rbultje
parents:
3904
diff
changeset
|
1377 ret = rtp_parse_packet(rtsp_st->rtp_ctx, pkt, buf, len); |
294
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
229
diff
changeset
|
1378 if (ret < 0) |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
229
diff
changeset
|
1379 goto redo; |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
229
diff
changeset
|
1380 if (ret == 1) { |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
229
diff
changeset
|
1381 /* more packets may follow, so we save the RTP context */ |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
229
diff
changeset
|
1382 rt->cur_rtp = rtsp_st->rtp_ctx; |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
229
diff
changeset
|
1383 } |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
229
diff
changeset
|
1384 return 0; |
0 | 1385 } |
1386 | |
304
d58c8859ff8c
initial seek support - more generic play/pause support
bellard
parents:
294
diff
changeset
|
1387 static int rtsp_read_play(AVFormatContext *s) |
179 | 1388 { |
304
d58c8859ff8c
initial seek support - more generic play/pause support
bellard
parents:
294
diff
changeset
|
1389 RTSPState *rt = s->priv_data; |
179 | 1390 RTSPHeader reply1, *reply = &reply1; |
1391 char cmd[1024]; | |
1392 | |
370
845f9de2c883
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
304
diff
changeset
|
1393 av_log(s, AV_LOG_DEBUG, "hello state=%d\n", rt->state); |
304
d58c8859ff8c
initial seek support - more generic play/pause support
bellard
parents:
294
diff
changeset
|
1394 |
3923
83e51bcb03c2
Rename RTSP_SERVER_RDT to RTSP_SERVER_REAL, because RDT (the transport
rbultje
parents:
3920
diff
changeset
|
1395 if (!(rt->server_type == RTSP_SERVER_REAL && rt->need_subscription)) { |
3904 | 1396 if (rt->state == RTSP_STATE_PAUSED) { |
1397 snprintf(cmd, sizeof(cmd), | |
1398 "PLAY %s RTSP/1.0\r\n", | |
1399 s->filename); | |
1400 } else { | |
1401 snprintf(cmd, sizeof(cmd), | |
1402 "PLAY %s RTSP/1.0\r\n" | |
1403 "Range: npt=%0.3f-\r\n", | |
1404 s->filename, | |
1405 (double)rt->seek_timestamp / AV_TIME_BASE); | |
1406 } | |
1407 rtsp_send_cmd(s, cmd, reply, NULL); | |
1408 if (reply->status_code != RTSP_STATUS_OK) { | |
1409 return -1; | |
1410 } | |
3903
aeb79f68ba7e
Implement a RDT-specific SET_PARAMETER command that subscribes to the
rbultje
parents:
3877
diff
changeset
|
1411 } |
3861
a0098594ab90
Remove useless "else" case in if X { A; return }; else { B }. See discussion
rbultje
parents:
3860
diff
changeset
|
1412 rt->state = RTSP_STATE_PLAYING; |
a0098594ab90
Remove useless "else" case in if X { A; return }; else { B }. See discussion
rbultje
parents:
3860
diff
changeset
|
1413 return 0; |
304
d58c8859ff8c
initial seek support - more generic play/pause support
bellard
parents:
294
diff
changeset
|
1414 } |
d58c8859ff8c
initial seek support - more generic play/pause support
bellard
parents:
294
diff
changeset
|
1415 |
d58c8859ff8c
initial seek support - more generic play/pause support
bellard
parents:
294
diff
changeset
|
1416 /* pause the stream */ |
d58c8859ff8c
initial seek support - more generic play/pause support
bellard
parents:
294
diff
changeset
|
1417 static int rtsp_read_pause(AVFormatContext *s) |
d58c8859ff8c
initial seek support - more generic play/pause support
bellard
parents:
294
diff
changeset
|
1418 { |
d58c8859ff8c
initial seek support - more generic play/pause support
bellard
parents:
294
diff
changeset
|
1419 RTSPState *rt = s->priv_data; |
d58c8859ff8c
initial seek support - more generic play/pause support
bellard
parents:
294
diff
changeset
|
1420 RTSPHeader reply1, *reply = &reply1; |
d58c8859ff8c
initial seek support - more generic play/pause support
bellard
parents:
294
diff
changeset
|
1421 char cmd[1024]; |
d58c8859ff8c
initial seek support - more generic play/pause support
bellard
parents:
294
diff
changeset
|
1422 |
179 | 1423 rt = s->priv_data; |
885 | 1424 |
304
d58c8859ff8c
initial seek support - more generic play/pause support
bellard
parents:
294
diff
changeset
|
1425 if (rt->state != RTSP_STATE_PLAYING) |
d58c8859ff8c
initial seek support - more generic play/pause support
bellard
parents:
294
diff
changeset
|
1426 return 0; |
3923
83e51bcb03c2
Rename RTSP_SERVER_RDT to RTSP_SERVER_REAL, because RDT (the transport
rbultje
parents:
3920
diff
changeset
|
1427 else if (!(rt->server_type == RTSP_SERVER_REAL && rt->need_subscription)) { |
3904 | 1428 snprintf(cmd, sizeof(cmd), |
1429 "PAUSE %s RTSP/1.0\r\n", | |
1430 s->filename); | |
1431 rtsp_send_cmd(s, cmd, reply, NULL); | |
1432 if (reply->status_code != RTSP_STATUS_OK) { | |
1433 return -1; | |
1434 } | |
3903
aeb79f68ba7e
Implement a RDT-specific SET_PARAMETER command that subscribes to the
rbultje
parents:
3877
diff
changeset
|
1435 } |
3861
a0098594ab90
Remove useless "else" case in if X { A; return }; else { B }. See discussion
rbultje
parents:
3860
diff
changeset
|
1436 rt->state = RTSP_STATE_PAUSED; |
a0098594ab90
Remove useless "else" case in if X { A; return }; else { B }. See discussion
rbultje
parents:
3860
diff
changeset
|
1437 return 0; |
179 | 1438 } |
1439 | |
885 | 1440 static int rtsp_read_seek(AVFormatContext *s, int stream_index, |
558 | 1441 int64_t timestamp, int flags) |
179 | 1442 { |
304
d58c8859ff8c
initial seek support - more generic play/pause support
bellard
parents:
294
diff
changeset
|
1443 RTSPState *rt = s->priv_data; |
885 | 1444 |
2408 | 1445 rt->seek_timestamp = av_rescale_q(timestamp, s->streams[stream_index]->time_base, AV_TIME_BASE_Q); |
304
d58c8859ff8c
initial seek support - more generic play/pause support
bellard
parents:
294
diff
changeset
|
1446 switch(rt->state) { |
d58c8859ff8c
initial seek support - more generic play/pause support
bellard
parents:
294
diff
changeset
|
1447 default: |
d58c8859ff8c
initial seek support - more generic play/pause support
bellard
parents:
294
diff
changeset
|
1448 case RTSP_STATE_IDLE: |
d58c8859ff8c
initial seek support - more generic play/pause support
bellard
parents:
294
diff
changeset
|
1449 break; |
d58c8859ff8c
initial seek support - more generic play/pause support
bellard
parents:
294
diff
changeset
|
1450 case RTSP_STATE_PLAYING: |
d58c8859ff8c
initial seek support - more generic play/pause support
bellard
parents:
294
diff
changeset
|
1451 if (rtsp_read_play(s) != 0) |
d58c8859ff8c
initial seek support - more generic play/pause support
bellard
parents:
294
diff
changeset
|
1452 return -1; |
d58c8859ff8c
initial seek support - more generic play/pause support
bellard
parents:
294
diff
changeset
|
1453 break; |
d58c8859ff8c
initial seek support - more generic play/pause support
bellard
parents:
294
diff
changeset
|
1454 case RTSP_STATE_PAUSED: |
d58c8859ff8c
initial seek support - more generic play/pause support
bellard
parents:
294
diff
changeset
|
1455 rt->state = RTSP_STATE_IDLE; |
d58c8859ff8c
initial seek support - more generic play/pause support
bellard
parents:
294
diff
changeset
|
1456 break; |
179 | 1457 } |
304
d58c8859ff8c
initial seek support - more generic play/pause support
bellard
parents:
294
diff
changeset
|
1458 return 0; |
179 | 1459 } |
1460 | |
0 | 1461 static int rtsp_read_close(AVFormatContext *s) |
1462 { | |
1463 RTSPState *rt = s->priv_data; | |
1464 RTSPHeader reply1, *reply = &reply1; | |
1465 char cmd[1024]; | |
1466 | |
172 | 1467 #if 0 |
0 | 1468 /* NOTE: it is valid to flush the buffer here */ |
3957
9f943bb755f9
Rename RTSPProtocol to RTSPLowerTransport, so that its name properly tells us
rbultje
parents:
3941
diff
changeset
|
1469 if (rt->lower_transport == RTSP_LOWER_TRANSPORT_TCP) { |
0 | 1470 url_fclose(&rt->rtsp_gb); |
1471 } | |
172 | 1472 #endif |
885 | 1473 snprintf(cmd, sizeof(cmd), |
172 | 1474 "TEARDOWN %s RTSP/1.0\r\n", |
0 | 1475 s->filename); |
1476 rtsp_send_cmd(s, cmd, reply, NULL); | |
1477 | |
294
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
229
diff
changeset
|
1478 rtsp_close_streams(rt); |
0 | 1479 url_close(rt->rtsp_hd); |
1480 return 0; | |
1481 } | |
1482 | |
2054 | 1483 #ifdef CONFIG_RTSP_DEMUXER |
1167 | 1484 AVInputFormat rtsp_demuxer = { |
0 | 1485 "rtsp", |
3424
7a0230981402
Make long_names in lavf/lavdev optional depending on CONFIG_SMALL.
diego
parents:
3286
diff
changeset
|
1486 NULL_IF_CONFIG_SMALL("RTSP input format"), |
0 | 1487 sizeof(RTSPState), |
1488 rtsp_probe, | |
1489 rtsp_read_header, | |
1490 rtsp_read_packet, | |
1491 rtsp_read_close, | |
304
d58c8859ff8c
initial seek support - more generic play/pause support
bellard
parents:
294
diff
changeset
|
1492 rtsp_read_seek, |
0 | 1493 .flags = AVFMT_NOFILE, |
304
d58c8859ff8c
initial seek support - more generic play/pause support
bellard
parents:
294
diff
changeset
|
1494 .read_play = rtsp_read_play, |
d58c8859ff8c
initial seek support - more generic play/pause support
bellard
parents:
294
diff
changeset
|
1495 .read_pause = rtsp_read_pause, |
0 | 1496 }; |
2054 | 1497 #endif |
0 | 1498 |
1499 static int sdp_probe(AVProbeData *p1) | |
1500 { | |
706
fc254f396f15
buffer overflow in sdp_probe() fix by (Gildas Bazin )gbazin altern org)
michael
parents:
587
diff
changeset
|
1501 const char *p = p1->buf, *p_end = p1->buf + p1->buf_size; |
0 | 1502 |
1503 /* we look for a line beginning "c=IN IP4" */ | |
706
fc254f396f15
buffer overflow in sdp_probe() fix by (Gildas Bazin )gbazin altern org)
michael
parents:
587
diff
changeset
|
1504 while (p < p_end && *p != '\0') { |
2193
5ce5fad0dfac
replace the uses of old string functions that Reimar missed
mru
parents:
2189
diff
changeset
|
1505 if (p + sizeof("c=IN IP4") - 1 < p_end && av_strstart(p, "c=IN IP4", NULL)) |
0 | 1506 return AVPROBE_SCORE_MAX / 2; |
706
fc254f396f15
buffer overflow in sdp_probe() fix by (Gildas Bazin )gbazin altern org)
michael
parents:
587
diff
changeset
|
1507 |
fc254f396f15
buffer overflow in sdp_probe() fix by (Gildas Bazin )gbazin altern org)
michael
parents:
587
diff
changeset
|
1508 while(p < p_end - 1 && *p != '\n') p++; |
fc254f396f15
buffer overflow in sdp_probe() fix by (Gildas Bazin )gbazin altern org)
michael
parents:
587
diff
changeset
|
1509 if (++p >= p_end) |
0 | 1510 break; |
1511 if (*p == '\r') | |
1512 p++; | |
1513 } | |
1514 return 0; | |
1515 } | |
1516 | |
1517 #define SDP_MAX_SIZE 8192 | |
1518 | |
1519 static int sdp_read_header(AVFormatContext *s, | |
1520 AVFormatParameters *ap) | |
1521 { | |
294
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
229
diff
changeset
|
1522 RTSPState *rt = s->priv_data; |
0 | 1523 RTSPStream *rtsp_st; |
1524 int size, i, err; | |
1525 char *content; | |
1526 char url[1024]; | |
1527 | |
1528 /* read the whole sdp file */ | |
1529 /* XXX: better loading */ | |
1530 content = av_malloc(SDP_MAX_SIZE); | |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2759
diff
changeset
|
1531 size = get_buffer(s->pb, content, SDP_MAX_SIZE - 1); |
0 | 1532 if (size <= 0) { |
1533 av_free(content); | |
1534 return AVERROR_INVALIDDATA; | |
1535 } | |
1536 content[size] ='\0'; | |
1537 | |
1538 sdp_parse(s, content); | |
1539 av_free(content); | |
1540 | |
1541 /* open each RTP stream */ | |
294
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
229
diff
changeset
|
1542 for(i=0;i<rt->nb_rtsp_streams;i++) { |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
229
diff
changeset
|
1543 rtsp_st = rt->rtsp_streams[i]; |
885 | 1544 |
3222 | 1545 snprintf(url, sizeof(url), "rtp://%s:%d?localport=%d&ttl=%d", |
885 | 1546 inet_ntoa(rtsp_st->sdp_ip), |
0 | 1547 rtsp_st->sdp_port, |
3222 | 1548 rtsp_st->sdp_port, |
0 | 1549 rtsp_st->sdp_ttl); |
1425
00d9393a126f
make ffmpeg able to send back a RTCP receiver report.
gpoirier
parents:
1424
diff
changeset
|
1550 if (url_open(&rtsp_st->rtp_handle, url, URL_RDWR) < 0) { |
0 | 1551 err = AVERROR_INVALIDDATA; |
1552 goto fail; | |
1553 } | |
3919
1879eab34f88
Factorize out common code for opening of the RTP parsing context between
rbultje
parents:
3905
diff
changeset
|
1554 if ((err = rtsp_open_transport_ctx(s, rtsp_st))) |
294
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
229
diff
changeset
|
1555 goto fail; |
0 | 1556 } |
1557 return 0; | |
1558 fail: | |
294
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
229
diff
changeset
|
1559 rtsp_close_streams(rt); |
0 | 1560 return err; |
1561 } | |
1562 | |
1563 static int sdp_read_packet(AVFormatContext *s, | |
1564 AVPacket *pkt) | |
1565 { | |
294
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
229
diff
changeset
|
1566 return rtsp_read_packet(s, pkt); |
0 | 1567 } |
1568 | |
1569 static int sdp_read_close(AVFormatContext *s) | |
1570 { | |
294
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
229
diff
changeset
|
1571 RTSPState *rt = s->priv_data; |
6091b76cfc2a
added MPEG2TS support in RTP, SDP and RTSP - replaced fake RTP demux by a specific API
bellard
parents:
229
diff
changeset
|
1572 rtsp_close_streams(rt); |
0 | 1573 return 0; |
1574 } | |
1575 | |
1169 | 1576 #ifdef CONFIG_SDP_DEMUXER |
1577 AVInputFormat sdp_demuxer = { | |
0 | 1578 "sdp", |
3424
7a0230981402
Make long_names in lavf/lavdev optional depending on CONFIG_SMALL.
diego
parents:
3286
diff
changeset
|
1579 NULL_IF_CONFIG_SMALL("SDP"), |
0 | 1580 sizeof(RTSPState), |
1581 sdp_probe, | |
1582 sdp_read_header, | |
1583 sdp_read_packet, | |
1584 sdp_read_close, | |
1585 }; | |
1169 | 1586 #endif |
0 | 1587 |
2053 | 1588 #ifdef CONFIG_REDIR_DEMUXER |
0 | 1589 /* dummy redirector format (used directly in av_open_input_file now) */ |
1590 static int redir_probe(AVProbeData *pd) | |
1591 { | |
1592 const char *p; | |
1593 p = pd->buf; | |
1594 while (redir_isspace(*p)) | |
1595 p++; | |
2193
5ce5fad0dfac
replace the uses of old string functions that Reimar missed
mru
parents:
2189
diff
changeset
|
1596 if (av_strstart(p, "http://", NULL) || |
5ce5fad0dfac
replace the uses of old string functions that Reimar missed
mru
parents:
2189
diff
changeset
|
1597 av_strstart(p, "rtsp://", NULL)) |
0 | 1598 return AVPROBE_SCORE_MAX; |
1599 return 0; | |
1600 } | |
1601 | |
2785
d3b3cfb538d8
Suppress the "redirector hack" from libavformat/utils.c:av_open_input_stream(),
lucabe
parents:
2775
diff
changeset
|
1602 static int redir_read_header(AVFormatContext *s, AVFormatParameters *ap) |
0 | 1603 { |
1604 char buf[4096], *q; | |
1605 int c; | |
1606 AVFormatContext *ic = NULL; | |
2785
d3b3cfb538d8
Suppress the "redirector hack" from libavformat/utils.c:av_open_input_stream(),
lucabe
parents:
2775
diff
changeset
|
1607 ByteIOContext *f = s->pb; |
0 | 1608 |
1609 /* parse each URL and try to open it */ | |
1610 c = url_fgetc(f); | |
1611 while (c != URL_EOF) { | |
1612 /* skip spaces */ | |
1613 for(;;) { | |
1614 if (!redir_isspace(c)) | |
1615 break; | |
1616 c = url_fgetc(f); | |
1617 } | |
1618 if (c == URL_EOF) | |
1619 break; | |
1620 /* record url */ | |
1621 q = buf; | |
1622 for(;;) { | |
1623 if (c == URL_EOF || redir_isspace(c)) | |
1624 break; | |
1625 if ((q - buf) < sizeof(buf) - 1) | |
1626 *q++ = c; | |
1627 c = url_fgetc(f); | |
1628 } | |
1629 *q = '\0'; | |
1630 //printf("URL='%s'\n", buf); | |
1631 /* try to open the media file */ | |
1632 if (av_open_input_file(&ic, buf, NULL, 0, NULL) == 0) | |
1633 break; | |
1634 } | |
1635 if (!ic) | |
2274
b21c2af60bc9
Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents:
2273
diff
changeset
|
1636 return AVERROR(EIO); |
2785
d3b3cfb538d8
Suppress the "redirector hack" from libavformat/utils.c:av_open_input_stream(),
lucabe
parents:
2775
diff
changeset
|
1637 |
d3b3cfb538d8
Suppress the "redirector hack" from libavformat/utils.c:av_open_input_stream(),
lucabe
parents:
2775
diff
changeset
|
1638 *s = *ic; |
d3b3cfb538d8
Suppress the "redirector hack" from libavformat/utils.c:av_open_input_stream(),
lucabe
parents:
2775
diff
changeset
|
1639 url_fclose(f); |
d3b3cfb538d8
Suppress the "redirector hack" from libavformat/utils.c:av_open_input_stream(),
lucabe
parents:
2775
diff
changeset
|
1640 |
d3b3cfb538d8
Suppress the "redirector hack" from libavformat/utils.c:av_open_input_stream(),
lucabe
parents:
2775
diff
changeset
|
1641 return 0; |
0 | 1642 } |
1643 | |
1167 | 1644 AVInputFormat redir_demuxer = { |
0 | 1645 "redir", |
3424
7a0230981402
Make long_names in lavf/lavdev optional depending on CONFIG_SMALL.
diego
parents:
3286
diff
changeset
|
1646 NULL_IF_CONFIG_SMALL("Redirector format"), |
0 | 1647 0, |
1648 redir_probe, | |
2785
d3b3cfb538d8
Suppress the "redirector hack" from libavformat/utils.c:av_open_input_stream(),
lucabe
parents:
2775
diff
changeset
|
1649 redir_read_header, |
0 | 1650 NULL, |
1651 NULL, | |
1652 }; | |
2053 | 1653 #endif |