FFmpeg  2.6.3
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
rtspdec.c
Go to the documentation of this file.
1 /*
2  * RTSP demuxer
3  * Copyright (c) 2002 Fabrice Bellard
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
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
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 #include "libavutil/avstring.h"
23 #include "libavutil/intreadwrite.h"
24 #include "libavutil/mathematics.h"
25 #include "libavutil/random_seed.h"
26 #include "libavutil/time.h"
27 #include "avformat.h"
28 
29 #include "internal.h"
30 #include "network.h"
31 #include "os_support.h"
32 #include "rtpproto.h"
33 #include "rtsp.h"
34 #include "rdt.h"
35 #include "url.h"
36 
37 static const struct RTSPStatusMessage {
39  const char *message;
40 } status_messages[] = {
41  { RTSP_STATUS_OK, "OK" },
42  { RTSP_STATUS_METHOD, "Method Not Allowed" },
43  { RTSP_STATUS_BANDWIDTH, "Not Enough Bandwidth" },
44  { RTSP_STATUS_SESSION, "Session Not Found" },
45  { RTSP_STATUS_STATE, "Method Not Valid in This State" },
46  { RTSP_STATUS_AGGREGATE, "Aggregate operation not allowed" },
47  { RTSP_STATUS_ONLY_AGGREGATE, "Only aggregate operation allowed" },
48  { RTSP_STATUS_TRANSPORT, "Unsupported transport" },
49  { RTSP_STATUS_INTERNAL, "Internal Server Error" },
50  { RTSP_STATUS_SERVICE, "Service Unavailable" },
51  { RTSP_STATUS_VERSION, "RTSP Version not supported" },
52  { 0, "NULL" }
53 };
54 
56 {
57  RTSPState *rt = s->priv_data;
58 
59  if (!(rt->rtsp_flags & RTSP_FLAG_LISTEN))
60  ff_rtsp_send_cmd_async(s, "TEARDOWN", rt->control_uri, NULL);
61 
65  rt->real_setup = NULL;
67  return 0;
68 }
69 
70 static inline int read_line(AVFormatContext *s, char *rbuf, const int rbufsize,
71  int *rbuflen)
72 {
73  RTSPState *rt = s->priv_data;
74  int idx = 0;
75  int ret = 0;
76  *rbuflen = 0;
77 
78  do {
79  ret = ffurl_read_complete(rt->rtsp_hd, rbuf + idx, 1);
80  if (ret <= 0)
81  return ret ? ret : AVERROR_EOF;
82  if (rbuf[idx] == '\r') {
83  /* Ignore */
84  } else if (rbuf[idx] == '\n') {
85  rbuf[idx] = '\0';
86  *rbuflen = idx;
87  return 0;
88  } else
89  idx++;
90  } while (idx < rbufsize);
91  av_log(s, AV_LOG_ERROR, "Message too long\n");
92  return AVERROR(EIO);
93 }
94 
96  const char *extracontent, uint16_t seq)
97 {
98  RTSPState *rt = s->priv_data;
99  char message[4096];
100  int index = 0;
101  while (status_messages[index].code) {
102  if (status_messages[index].code == code) {
103  snprintf(message, sizeof(message), "RTSP/1.0 %d %s\r\n",
104  code, status_messages[index].message);
105  break;
106  }
107  index++;
108  }
109  if (!status_messages[index].code)
110  return AVERROR(EINVAL);
111  av_strlcatf(message, sizeof(message), "CSeq: %d\r\n", seq);
112  av_strlcatf(message, sizeof(message), "Server: %s\r\n", LIBAVFORMAT_IDENT);
113  if (extracontent)
114  av_strlcat(message, extracontent, sizeof(message));
115  av_strlcat(message, "\r\n", sizeof(message));
116  av_dlog(s, "Sending response:\n%s", message);
117  ffurl_write(rt->rtsp_hd_out, message, strlen(message));
118 
119  return 0;
120 }
121 
122 static inline int check_sessionid(AVFormatContext *s,
123  RTSPMessageHeader *request)
124 {
125  RTSPState *rt = s->priv_data;
126  unsigned char *session_id = rt->session_id;
127  if (!session_id[0]) {
128  av_log(s, AV_LOG_WARNING, "There is no session-id at the moment\n");
129  return 0;
130  }
131  if (strcmp(session_id, request->session_id)) {
132  av_log(s, AV_LOG_ERROR, "Unexpected session-id %s\n",
133  request->session_id);
136  }
137  return 0;
138 }
139 
141  RTSPMessageHeader *request,
142  const char *method)
143 {
144  RTSPState *rt = s->priv_data;
145  char rbuf[1024];
146  int rbuflen, ret;
147  do {
148  ret = read_line(s, rbuf, sizeof(rbuf), &rbuflen);
149  if (ret)
150  return ret;
151  if (rbuflen > 1) {
152  av_dlog(s, "Parsing[%d]: %s\n", rbuflen, rbuf);
153  ff_rtsp_parse_line(request, rbuf, rt, method);
154  }
155  } while (rbuflen > 0);
156  if (request->seq != rt->seq + 1) {
157  av_log(s, AV_LOG_ERROR, "Unexpected Sequence number %d\n",
158  request->seq);
159  return AVERROR(EINVAL);
160  }
161  if (rt->session_id[0] && strcmp(method, "OPTIONS")) {
162  ret = check_sessionid(s, request);
163  if (ret)
164  return ret;
165  }
166 
167  return 0;
168 }
169 
171 {
172  RTSPState *rt = s->priv_data;
173  RTSPMessageHeader request = { 0 };
174  char sdp[4096];
175  int ret;
176 
177  ret = rtsp_read_request(s, &request, "ANNOUNCE");
178  if (ret)
179  return ret;
180  rt->seq++;
181  if (strcmp(request.content_type, "application/sdp")) {
182  av_log(s, AV_LOG_ERROR, "Unexpected content type %s\n",
183  request.content_type);
186  }
187  if (request.content_length && request.content_length < sizeof(sdp) - 1) {
188  /* Read SDP */
189  if (ffurl_read_complete(rt->rtsp_hd, sdp, request.content_length)
190  < request.content_length) {
191  av_log(s, AV_LOG_ERROR,
192  "Unable to get complete SDP Description in ANNOUNCE\n");
194  return AVERROR(EIO);
195  }
196  sdp[request.content_length] = '\0';
197  av_log(s, AV_LOG_VERBOSE, "SDP: %s\n", sdp);
198  ret = ff_sdp_parse(s, sdp);
199  if (ret)
200  return ret;
201  rtsp_send_reply(s, RTSP_STATUS_OK, NULL, request.seq);
202  return 0;
203  }
204  av_log(s, AV_LOG_ERROR,
205  "Content-Length header value exceeds sdp allocated buffer (4KB)\n");
207  "Content-Length exceeds buffer size", request.seq);
208  return AVERROR(EIO);
209 }
210 
212 {
213  RTSPState *rt = s->priv_data;
214  RTSPMessageHeader request = { 0 };
215  int ret = 0;
216 
217  /* Parsing headers */
218  ret = rtsp_read_request(s, &request, "OPTIONS");
219  if (ret)
220  return ret;
221  rt->seq++;
222  /* Send Reply */
224  "Public: ANNOUNCE, PAUSE, SETUP, TEARDOWN, RECORD\r\n",
225  request.seq);
226  return 0;
227 }
228 
229 static int rtsp_read_setup(AVFormatContext *s, char* host, char *controlurl)
230 {
231  RTSPState *rt = s->priv_data;
232  RTSPMessageHeader request = { 0 };
233  int ret = 0;
234  char url[1024];
235  RTSPStream *rtsp_st;
236  char responseheaders[1024];
237  int localport = -1;
238  int transportidx = 0;
239  int streamid = 0;
240 
241  ret = rtsp_read_request(s, &request, "SETUP");
242  if (ret)
243  return ret;
244  rt->seq++;
245  if (!request.nb_transports) {
246  av_log(s, AV_LOG_ERROR, "No transport defined in SETUP\n");
247  return AVERROR_INVALIDDATA;
248  }
249  for (transportidx = 0; transportidx < request.nb_transports;
250  transportidx++) {
251  if (!request.transports[transportidx].mode_record ||
252  (request.transports[transportidx].lower_transport !=
254  request.transports[transportidx].lower_transport !=
256  av_log(s, AV_LOG_ERROR, "mode=record/receive not set or transport"
257  " protocol not supported (yet)\n");
258  return AVERROR_INVALIDDATA;
259  }
260  }
261  if (request.nb_transports > 1)
262  av_log(s, AV_LOG_WARNING, "More than one transport not supported, "
263  "using first of all\n");
264  for (streamid = 0; streamid < rt->nb_rtsp_streams; streamid++) {
265  if (!strcmp(rt->rtsp_streams[streamid]->control_url,
266  controlurl))
267  break;
268  }
269  if (streamid == rt->nb_rtsp_streams) {
270  av_log(s, AV_LOG_ERROR, "Unable to find requested track\n");
272  }
273  rtsp_st = rt->rtsp_streams[streamid];
274  localport = rt->rtp_port_min;
275 
278  if ((ret = ff_rtsp_open_transport_ctx(s, rtsp_st))) {
280  return ret;
281  }
282  rtsp_st->interleaved_min = request.transports[0].interleaved_min;
283  rtsp_st->interleaved_max = request.transports[0].interleaved_max;
284  snprintf(responseheaders, sizeof(responseheaders), "Transport: "
285  "RTP/AVP/TCP;unicast;mode=receive;interleaved=%d-%d"
286  "\r\n", request.transports[0].interleaved_min,
287  request.transports[0].interleaved_max);
288  } else {
289  do {
290  ff_url_join(url, sizeof(url), "rtp", NULL, host, localport, NULL);
291  av_dlog(s, "Opening: %s", url);
292  ret = ffurl_open(&rtsp_st->rtp_handle, url, AVIO_FLAG_READ_WRITE,
293  &s->interrupt_callback, NULL);
294  if (ret)
295  localport += 2;
296  } while (ret || localport > rt->rtp_port_max);
297  if (localport > rt->rtp_port_max) {
299  return ret;
300  }
301 
302  av_dlog(s, "Listening on: %d",
304  if ((ret = ff_rtsp_open_transport_ctx(s, rtsp_st))) {
306  return ret;
307  }
308 
309  localport = ff_rtp_get_local_rtp_port(rtsp_st->rtp_handle);
310  snprintf(responseheaders, sizeof(responseheaders), "Transport: "
311  "RTP/AVP/UDP;unicast;mode=receive;source=%s;"
312  "client_port=%d-%d;server_port=%d-%d\r\n",
313  host, request.transports[0].client_port_min,
314  request.transports[0].client_port_max, localport,
315  localport + 1);
316  }
317 
318  /* Establish sessionid if not previously set */
319  /* Put this in a function? */
320  /* RFC 2326: session id must be at least 8 digits */
321  while (strlen(rt->session_id) < 8)
322  av_strlcatf(rt->session_id, 512, "%u", av_get_random_seed());
323 
324  av_strlcatf(responseheaders, sizeof(responseheaders), "Session: %s\r\n",
325  rt->session_id);
326  /* Send Reply */
327  rtsp_send_reply(s, RTSP_STATUS_OK, responseheaders, request.seq);
328 
329  rt->state = RTSP_STATE_PAUSED;
330  return 0;
331 }
332 
334 {
335  RTSPState *rt = s->priv_data;
336  RTSPMessageHeader request = { 0 };
337  int ret = 0;
338  char responseheaders[1024];
339 
340  ret = rtsp_read_request(s, &request, "RECORD");
341  if (ret)
342  return ret;
343  ret = check_sessionid(s, &request);
344  if (ret)
345  return ret;
346  rt->seq++;
347  snprintf(responseheaders, sizeof(responseheaders), "Session: %s\r\n",
348  rt->session_id);
349  rtsp_send_reply(s, RTSP_STATUS_OK, responseheaders, request.seq);
350 
352  return 0;
353 }
354 
355 static inline int parse_command_line(AVFormatContext *s, const char *line,
356  int linelen, char *uri, int urisize,
357  char *method, int methodsize,
358  enum RTSPMethod *methodcode)
359 {
360  RTSPState *rt = s->priv_data;
361  const char *linept, *searchlinept;
362  linept = strchr(line, ' ');
363 
364  if (!linept) {
365  av_log(s, AV_LOG_ERROR, "Error parsing method string\n");
366  return AVERROR_INVALIDDATA;
367  }
368 
369  if (linept - line > methodsize - 1) {
370  av_log(s, AV_LOG_ERROR, "Method string too long\n");
371  return AVERROR(EIO);
372  }
373  memcpy(method, line, linept - line);
374  method[linept - line] = '\0';
375  linept++;
376  if (!strcmp(method, "ANNOUNCE"))
377  *methodcode = ANNOUNCE;
378  else if (!strcmp(method, "OPTIONS"))
379  *methodcode = OPTIONS;
380  else if (!strcmp(method, "RECORD"))
381  *methodcode = RECORD;
382  else if (!strcmp(method, "SETUP"))
383  *methodcode = SETUP;
384  else if (!strcmp(method, "PAUSE"))
385  *methodcode = PAUSE;
386  else if (!strcmp(method, "TEARDOWN"))
387  *methodcode = TEARDOWN;
388  else
389  *methodcode = UNKNOWN;
390  /* Check method with the state */
391  if (rt->state == RTSP_STATE_IDLE) {
392  if ((*methodcode != ANNOUNCE) && (*methodcode != OPTIONS)) {
393  av_log(s, AV_LOG_ERROR, "Unexpected command in Idle State %s\n",
394  line);
396  }
397  } else if (rt->state == RTSP_STATE_PAUSED) {
398  if ((*methodcode != OPTIONS) && (*methodcode != RECORD)
399  && (*methodcode != SETUP)) {
400  av_log(s, AV_LOG_ERROR, "Unexpected command in Paused State %s\n",
401  line);
403  }
404  } else if (rt->state == RTSP_STATE_STREAMING) {
405  if ((*methodcode != PAUSE) && (*methodcode != OPTIONS)
406  && (*methodcode != TEARDOWN)) {
407  av_log(s, AV_LOG_ERROR, "Unexpected command in Streaming State"
408  " %s\n", line);
410  }
411  } else {
412  av_log(s, AV_LOG_ERROR, "Unexpected State [%d]\n", rt->state);
413  return AVERROR_BUG;
414  }
415 
416  searchlinept = strchr(linept, ' ');
417  if (!searchlinept) {
418  av_log(s, AV_LOG_ERROR, "Error parsing message URI\n");
419  return AVERROR_INVALIDDATA;
420  }
421  if (searchlinept - linept > urisize - 1) {
422  av_log(s, AV_LOG_ERROR, "uri string length exceeded buffer size\n");
423  return AVERROR(EIO);
424  }
425  memcpy(uri, linept, searchlinept - linept);
426  uri[searchlinept - linept] = '\0';
427  if (strcmp(rt->control_uri, uri)) {
428  char host[128], path[512], auth[128];
429  int port;
430  char ctl_host[128], ctl_path[512], ctl_auth[128];
431  int ctl_port;
432  av_url_split(NULL, 0, auth, sizeof(auth), host, sizeof(host), &port,
433  path, sizeof(path), uri);
434  av_url_split(NULL, 0, ctl_auth, sizeof(ctl_auth), ctl_host,
435  sizeof(ctl_host), &ctl_port, ctl_path, sizeof(ctl_path),
436  rt->control_uri);
437  if (strcmp(host, ctl_host))
438  av_log(s, AV_LOG_INFO, "Host %s differs from expected %s\n",
439  host, ctl_host);
440  if (strcmp(path, ctl_path) && *methodcode != SETUP)
441  av_log(s, AV_LOG_WARNING, "WARNING: Path %s differs from expected"
442  " %s\n", path, ctl_path);
443  if (*methodcode == ANNOUNCE) {
444  av_log(s, AV_LOG_INFO,
445  "Updating control URI to %s\n", uri);
446  av_strlcpy(rt->control_uri, uri, sizeof(rt->control_uri));
447  }
448  }
449 
450  linept = searchlinept + 1;
451  if (!av_strstart(linept, "RTSP/1.0", NULL)) {
452  av_log(s, AV_LOG_ERROR, "Error parsing protocol or version\n");
454  }
455  return 0;
456 }
457 
459 {
460  RTSPState *rt = s->priv_data;
461  unsigned char rbuf[4096];
462  unsigned char method[10];
463  char uri[500];
464  int ret;
465  int rbuflen = 0;
466  RTSPMessageHeader request = { 0 };
467  enum RTSPMethod methodcode;
468 
469  ret = read_line(s, rbuf, sizeof(rbuf), &rbuflen);
470  if (ret < 0)
471  return ret;
472  ret = parse_command_line(s, rbuf, rbuflen, uri, sizeof(uri), method,
473  sizeof(method), &methodcode);
474  if (ret) {
475  av_log(s, AV_LOG_ERROR, "RTSP: Unexpected Command\n");
476  return ret;
477  }
478 
479  ret = rtsp_read_request(s, &request, method);
480  if (ret)
481  return ret;
482  rt->seq++;
483  if (methodcode == PAUSE) {
484  rt->state = RTSP_STATE_PAUSED;
485  ret = rtsp_send_reply(s, RTSP_STATUS_OK, NULL , request.seq);
486  // TODO: Missing date header in response
487  } else if (methodcode == OPTIONS) {
489  "Public: ANNOUNCE, PAUSE, SETUP, TEARDOWN, "
490  "RECORD\r\n", request.seq);
491  } else if (methodcode == TEARDOWN) {
492  rt->state = RTSP_STATE_IDLE;
493  ret = rtsp_send_reply(s, RTSP_STATUS_OK, NULL , request.seq);
494  return 0;
495  }
496  return ret;
497 }
498 
500 {
501  RTSPState *rt = s->priv_data;
502  RTSPMessageHeader reply1, *reply = &reply1;
503  int i;
504  char cmd[1024];
505 
506  av_log(s, AV_LOG_DEBUG, "hello state=%d\n", rt->state);
507  rt->nb_byes = 0;
508 
510  for (i = 0; i < rt->nb_rtsp_streams; i++) {
511  RTSPStream *rtsp_st = rt->rtsp_streams[i];
512  /* Try to initialize the connection state in a
513  * potential NAT router by sending dummy packets.
514  * RTP/RTCP dummy packets are used for RDT, too.
515  */
516  if (rtsp_st->rtp_handle &&
517  !(rt->server_type == RTSP_SERVER_WMS && i > 1))
519  }
520  }
521  if (!(rt->server_type == RTSP_SERVER_REAL && rt->need_subscription)) {
522  if (rt->transport == RTSP_TRANSPORT_RTP) {
523  for (i = 0; i < rt->nb_rtsp_streams; i++) {
524  RTSPStream *rtsp_st = rt->rtsp_streams[i];
525  RTPDemuxContext *rtpctx = rtsp_st->transport_priv;
526  if (!rtpctx)
527  continue;
531  rtpctx->base_timestamp = 0;
532  rtpctx->timestamp = 0;
533  rtpctx->unwrapped_timestamp = 0;
534  rtpctx->rtcp_ts_offset = 0;
535  }
536  }
537  if (rt->state == RTSP_STATE_PAUSED) {
538  cmd[0] = 0;
539  } else {
540  snprintf(cmd, sizeof(cmd),
541  "Range: npt=%"PRId64".%03"PRId64"-\r\n",
543  rt->seek_timestamp / (AV_TIME_BASE / 1000) % 1000);
544  }
545  ff_rtsp_send_cmd(s, "PLAY", rt->control_uri, cmd, reply, NULL);
546  if (reply->status_code != RTSP_STATUS_OK) {
547  return ff_rtsp_averror(reply->status_code, -1);
548  }
549  if (rt->transport == RTSP_TRANSPORT_RTP &&
550  reply->range_start != AV_NOPTS_VALUE) {
551  for (i = 0; i < rt->nb_rtsp_streams; i++) {
552  RTSPStream *rtsp_st = rt->rtsp_streams[i];
553  RTPDemuxContext *rtpctx = rtsp_st->transport_priv;
554  AVStream *st = NULL;
555  if (!rtpctx || rtsp_st->stream_index < 0)
556  continue;
557 
558  st = s->streams[rtsp_st->stream_index];
559  rtpctx->range_start_offset =
561  st->time_base);
562  }
563  }
564  }
566  return 0;
567 }
568 
569 /* pause the stream */
571 {
572  RTSPState *rt = s->priv_data;
573  RTSPMessageHeader reply1, *reply = &reply1;
574 
575  if (rt->state != RTSP_STATE_STREAMING)
576  return 0;
577  else if (!(rt->server_type == RTSP_SERVER_REAL && rt->need_subscription)) {
578  ff_rtsp_send_cmd(s, "PAUSE", rt->control_uri, NULL, reply, NULL);
579  if (reply->status_code != RTSP_STATUS_OK) {
580  return ff_rtsp_averror(reply->status_code, -1);
581  }
582  }
583  rt->state = RTSP_STATE_PAUSED;
584  return 0;
585 }
586 
588 {
589  RTSPState *rt = s->priv_data;
590  char cmd[1024];
591  unsigned char *content = NULL;
592  int ret;
593 
594  /* describe the stream */
595  snprintf(cmd, sizeof(cmd),
596  "Accept: application/sdp\r\n");
597  if (rt->server_type == RTSP_SERVER_REAL) {
598  /**
599  * The Require: attribute is needed for proper streaming from
600  * Realmedia servers.
601  */
602  av_strlcat(cmd,
603  "Require: com.real.retain-entity-for-setup\r\n",
604  sizeof(cmd));
605  }
606  ff_rtsp_send_cmd(s, "DESCRIBE", rt->control_uri, cmd, reply, &content);
607  if (reply->status_code != RTSP_STATUS_OK) {
608  av_freep(&content);
610  }
611  if (!content)
612  return AVERROR_INVALIDDATA;
613 
614  av_log(s, AV_LOG_VERBOSE, "SDP:\n%s\n", content);
615  /* now we got the SDP description, we parse it */
616  ret = ff_sdp_parse(s, (const char *)content);
617  av_freep(&content);
618  if (ret < 0)
619  return ret;
620 
621  return 0;
622 }
623 
625 {
626  RTSPState *rt = s->priv_data;
627  char proto[128], host[128], path[512], auth[128];
628  char uri[500];
629  int port;
630  int default_port = RTSP_DEFAULT_PORT;
631  char tcpname[500];
632  const char *lower_proto = "tcp";
633  unsigned char rbuf[4096];
634  unsigned char method[10];
635  int rbuflen = 0;
636  int ret;
637  enum RTSPMethod methodcode;
638 
639  /* extract hostname and port */
640  av_url_split(proto, sizeof(proto), auth, sizeof(auth), host, sizeof(host),
641  &port, path, sizeof(path), s->filename);
642 
643  /* ff_url_join. No authorization by now (NULL) */
644  ff_url_join(rt->control_uri, sizeof(rt->control_uri), proto, NULL, host,
645  port, "%s", path);
646 
647  if (!strcmp(proto, "rtsps")) {
648  lower_proto = "tls";
649  default_port = RTSPS_DEFAULT_PORT;
650  }
651 
652  if (port < 0)
653  port = default_port;
654 
655  /* Create TCP connection */
656  ff_url_join(tcpname, sizeof(tcpname), lower_proto, NULL, host, port,
657  "?listen&listen_timeout=%d", rt->initial_timeout * 1000);
658 
659  if (ret = ffurl_open(&rt->rtsp_hd, tcpname, AVIO_FLAG_READ_WRITE,
660  &s->interrupt_callback, NULL)) {
661  av_log(s, AV_LOG_ERROR, "Unable to open RTSP for listening\n");
662  return ret;
663  }
664  rt->state = RTSP_STATE_IDLE;
665  rt->rtsp_hd_out = rt->rtsp_hd;
666  for (;;) { /* Wait for incoming RTSP messages */
667  ret = read_line(s, rbuf, sizeof(rbuf), &rbuflen);
668  if (ret < 0)
669  return ret;
670  ret = parse_command_line(s, rbuf, rbuflen, uri, sizeof(uri), method,
671  sizeof(method), &methodcode);
672  if (ret) {
673  av_log(s, AV_LOG_ERROR, "RTSP: Unexpected Command\n");
674  return ret;
675  }
676 
677  if (methodcode == ANNOUNCE) {
678  ret = rtsp_read_announce(s);
679  rt->state = RTSP_STATE_PAUSED;
680  } else if (methodcode == OPTIONS) {
681  ret = rtsp_read_options(s);
682  } else if (methodcode == RECORD) {
683  ret = rtsp_read_record(s);
684  if (!ret)
685  return 0; // We are ready for streaming
686  } else if (methodcode == SETUP)
687  ret = rtsp_read_setup(s, host, uri);
688  if (ret) {
689  ffurl_close(rt->rtsp_hd);
690  return AVERROR_INVALIDDATA;
691  }
692  }
693  return 0;
694 }
695 
696 static int rtsp_probe(AVProbeData *p)
697 {
698  if (
700  av_strstart(p->filename, "rtsps:", NULL) ||
701 #endif
702  av_strstart(p->filename, "rtsp:", NULL))
703  return AVPROBE_SCORE_MAX;
704  return 0;
705 }
706 
708 {
709  RTSPState *rt = s->priv_data;
710  int ret;
711 
712  if (rt->initial_timeout > 0)
714 
715  if (rt->rtsp_flags & RTSP_FLAG_LISTEN) {
716  ret = rtsp_listen(s);
717  if (ret)
718  return ret;
719  } else {
720  ret = ff_rtsp_connect(s);
721  if (ret)
722  return ret;
723 
724  rt->real_setup_cache = !s->nb_streams ? NULL :
725  av_mallocz_array(s->nb_streams, 2 * sizeof(*rt->real_setup_cache));
726  if (!rt->real_setup_cache && s->nb_streams)
727  return AVERROR(ENOMEM);
728  rt->real_setup = rt->real_setup_cache + s->nb_streams;
729 
730  if (rt->initial_pause) {
731  /* do not start immediately */
732  } else {
733  if ((ret = rtsp_read_play(s)) < 0) {
736  return ret;
737  }
738  }
739  }
740 
741  return 0;
742 }
743 
745  uint8_t *buf, int buf_size)
746 {
747  RTSPState *rt = s->priv_data;
748  int id, len, i, ret;
749  RTSPStream *rtsp_st;
750 
751  av_dlog(s, "tcp_read_packet:\n");
752 redo:
753  for (;;) {
754  RTSPMessageHeader reply;
755 
756  ret = ff_rtsp_read_reply(s, &reply, NULL, 1, NULL);
757  if (ret < 0)
758  return ret;
759  if (ret == 1) /* received '$' */
760  break;
761  /* XXX: parse message */
762  if (rt->state != RTSP_STATE_STREAMING)
763  return 0;
764  }
765  ret = ffurl_read_complete(rt->rtsp_hd, buf, 3);
766  if (ret != 3)
767  return -1;
768  id = buf[0];
769  len = AV_RB16(buf + 1);
770  av_dlog(s, "id=%d len=%d\n", id, len);
771  if (len > buf_size || len < 8)
772  goto redo;
773  /* get the data */
774  ret = ffurl_read_complete(rt->rtsp_hd, buf, len);
775  if (ret != len)
776  return -1;
777  if (rt->transport == RTSP_TRANSPORT_RDT &&
778  ff_rdt_parse_header(buf, len, &id, NULL, NULL, NULL, NULL) < 0)
779  return -1;
780 
781  /* find the matching stream */
782  for (i = 0; i < rt->nb_rtsp_streams; i++) {
783  rtsp_st = rt->rtsp_streams[i];
784  if (id >= rtsp_st->interleaved_min &&
785  id <= rtsp_st->interleaved_max)
786  goto found;
787  }
788  goto redo;
789 found:
790  *prtsp_st = rtsp_st;
791  return len;
792 }
793 
795 {
796  RTSPState *rt = s->priv_data;
797  char host[1024];
798  int port;
799 
800  av_url_split(NULL, 0, NULL, 0, host, sizeof(host), &port, NULL, 0,
801  s->filename);
802  ff_rtsp_undo_setup(s, 0);
804  rt->real_challenge);
805 }
806 
808 {
809  RTSPState *rt = s->priv_data;
810  int ret;
811  RTSPMessageHeader reply1, *reply = &reply1;
812  char cmd[1024];
813 
814 retry:
815  if (rt->server_type == RTSP_SERVER_REAL) {
816  int i;
817 
818  for (i = 0; i < s->nb_streams; i++)
819  rt->real_setup[i] = s->streams[i]->discard;
820 
821  if (!rt->need_subscription) {
822  if (memcmp (rt->real_setup, rt->real_setup_cache,
823  sizeof(enum AVDiscard) * s->nb_streams)) {
824  snprintf(cmd, sizeof(cmd),
825  "Unsubscribe: %s\r\n",
826  rt->last_subscription);
827  ff_rtsp_send_cmd(s, "SET_PARAMETER", rt->control_uri,
828  cmd, reply, NULL);
829  if (reply->status_code != RTSP_STATUS_OK)
831  rt->need_subscription = 1;
832  }
833  }
834 
835  if (rt->need_subscription) {
836  int r, rule_nr, first = 1;
837 
838  memcpy(rt->real_setup_cache, rt->real_setup,
839  sizeof(enum AVDiscard) * s->nb_streams);
840  rt->last_subscription[0] = 0;
841 
842  snprintf(cmd, sizeof(cmd),
843  "Subscribe: ");
844  for (i = 0; i < rt->nb_rtsp_streams; i++) {
845  rule_nr = 0;
846  for (r = 0; r < s->nb_streams; r++) {
847  if (s->streams[r]->id == i) {
848  if (s->streams[r]->discard != AVDISCARD_ALL) {
849  if (!first)
850  av_strlcat(rt->last_subscription, ",",
851  sizeof(rt->last_subscription));
853  rt->last_subscription,
854  sizeof(rt->last_subscription), i, rule_nr);
855  first = 0;
856  }
857  rule_nr++;
858  }
859  }
860  }
861  av_strlcatf(cmd, sizeof(cmd), "%s\r\n", rt->last_subscription);
862  ff_rtsp_send_cmd(s, "SET_PARAMETER", rt->control_uri,
863  cmd, reply, NULL);
864  if (reply->status_code != RTSP_STATUS_OK)
866  rt->need_subscription = 0;
867 
868  if (rt->state == RTSP_STATE_STREAMING)
869  rtsp_read_play (s);
870  }
871  }
872 
873  ret = ff_rtsp_fetch_packet(s, pkt);
874  if (ret < 0) {
875  if (ret == AVERROR(ETIMEDOUT) && !rt->packets) {
878  RTSPMessageHeader reply1, *reply = &reply1;
879  av_log(s, AV_LOG_WARNING, "UDP timeout, retrying with TCP\n");
880  if (rtsp_read_pause(s) != 0)
881  return -1;
882  // TEARDOWN is required on Real-RTSP, but might make
883  // other servers close the connection.
884  if (rt->server_type == RTSP_SERVER_REAL)
885  ff_rtsp_send_cmd(s, "TEARDOWN", rt->control_uri, NULL,
886  reply, NULL);
887  rt->session_id[0] = '\0';
888  if (resetup_tcp(s) == 0) {
889  rt->state = RTSP_STATE_IDLE;
890  rt->need_subscription = 1;
891  if (rtsp_read_play(s) != 0)
892  return -1;
893  goto retry;
894  }
895  }
896  }
897  return ret;
898  }
899  rt->packets++;
900 
901  if (!(rt->rtsp_flags & RTSP_FLAG_LISTEN)) {
902  /* send dummy request to keep TCP connection alive */
903  if ((av_gettime_relative() - rt->last_cmd_time) / 1000000 >= rt->timeout / 2 ||
904  rt->auth_state.stale) {
905  if (rt->server_type == RTSP_SERVER_WMS ||
906  (rt->server_type != RTSP_SERVER_REAL &&
908  ff_rtsp_send_cmd_async(s, "GET_PARAMETER", rt->control_uri, NULL);
909  } else {
910  ff_rtsp_send_cmd_async(s, "OPTIONS", rt->control_uri, NULL);
911  }
912  /* The stale flag should be reset when creating the auth response in
913  * ff_rtsp_send_cmd_async, but reset it here just in case we never
914  * called the auth code (if we didn't have any credentials set). */
915  rt->auth_state.stale = 0;
916  }
917  }
918 
919  return 0;
920 }
921 
922 static int rtsp_read_seek(AVFormatContext *s, int stream_index,
923  int64_t timestamp, int flags)
924 {
925  RTSPState *rt = s->priv_data;
926  int ret;
927 
928  rt->seek_timestamp = av_rescale_q(timestamp,
929  s->streams[stream_index]->time_base,
931  switch(rt->state) {
932  default:
933  case RTSP_STATE_IDLE:
934  break;
936  if ((ret = rtsp_read_pause(s)) != 0)
937  return ret;
939  if ((ret = rtsp_read_play(s)) != 0)
940  return ret;
941  break;
942  case RTSP_STATE_PAUSED:
943  rt->state = RTSP_STATE_IDLE;
944  break;
945  }
946  return 0;
947 }
948 
949 static const AVClass rtsp_demuxer_class = {
950  .class_name = "RTSP demuxer",
951  .item_name = av_default_item_name,
952  .option = ff_rtsp_options,
953  .version = LIBAVUTIL_VERSION_INT,
954 };
955 
957  .name = "rtsp",
958  .long_name = NULL_IF_CONFIG_SMALL("RTSP input"),
959  .priv_data_size = sizeof(RTSPState),
965  .flags = AVFMT_NOFILE,
966  .read_play = rtsp_read_play,
967  .read_pause = rtsp_read_pause,
968  .priv_class = &rtsp_demuxer_class,
969 };
int interleaved_min
interleave ids, if TCP transport; each TCP/RTSP data packet starts with a '$', stream length and stre...
Definition: rtsp.h:93
void av_url_split(char *proto, int proto_size, char *authorization, int authorization_size, char *hostname, int hostname_size, int *port_ptr, char *path, int path_size, const char *url)
Split a URL string into components.
Definition: utils.c:3873
int rtp_port_min
Minimum and maximum local UDP ports.
Definition: rtsp.h:387
#define NULL
Definition: coverity.c:32
const char * s
Definition: avisynth_c.h:669
Realmedia Data Transport.
Definition: rtsp.h:58
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
static int rtsp_read_options(AVFormatContext *s)
Definition: rtspdec.c:211
int ff_rtp_get_local_rtp_port(URLContext *h)
Return the local rtp port used by the RTP connection.
Definition: rtpproto.c:530
void ff_rtp_send_punch_packets(URLContext *rtp_handle)
Send a dummy packet on both port pairs to set up the connection state in potential NAT routers...
Definition: rtpdec.c:373
AVIOInterruptCB interrupt_callback
Custom interrupt callbacks for the I/O layer.
Definition: avformat.h:1461
static const struct RTSPStatusMessage status_messages[]
enum AVCodecID id
Definition: mxfenc.c:95
char content_type[64]
Content type header.
Definition: rtsp.h:187
static int rtsp_read_request(AVFormatContext *s, RTSPMessageHeader *request, const char *method)
Definition: rtspdec.c:140
static int rtsp_read_close(AVFormatContext *s)
Definition: rtspdec.c:55
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:181
#define LIBAVUTIL_VERSION_INT
Definition: version.h:62
const char * filename
Definition: avformat.h:402
char control_uri[1024]
some MS RTSP streams contain a URL in the SDP that we need to use for all subsequent RTSP requests...
Definition: rtsp.h:317
static int rtsp_read_header(AVFormatContext *s)
Definition: rtspdec.c:707
int ffurl_write(URLContext *h, const unsigned char *buf, int size)
Write size bytes from buf to the resource accessed by h.
Definition: avio.c:344
#define RTSP_DEFAULT_PORT
Definition: rtsp.h:72
Windows Media server.
Definition: rtsp.h:209
int64_t range_start_offset
Definition: rtpdec.h:159
int ff_rtsp_open_transport_ctx(AVFormatContext *s, RTSPStream *rtsp_st)
Open RTSP transport context.
Definition: rtsp.c:769
static int read_seek(AVFormatContext *ctx, int stream_index, int64_t timestamp, int flags)
Definition: libcdio.c:153
static int rtsp_probe(AVProbeData *p)
Definition: rtspdec.c:696
enum AVDiscard * real_setup
current stream setup.
Definition: rtsp.h:296
static int resetup_tcp(AVFormatContext *s)
Definition: rtspdec.c:794
enum AVDiscard * real_setup_cache
stream setup during the last frame read.
Definition: rtsp.h:292
int mode_record
transport set to record data
Definition: rtsp.h:112
int ff_rtsp_setup_input_streams(AVFormatContext *s, RTSPMessageHeader *reply)
Get the description of the stream and set up the RTSPStream child objects.
Definition: rtspdec.c:587
void ff_network_close(void)
Definition: network.c:179
UDP/unicast.
Definition: rtsp.h:38
int seq
sequence number
Definition: rtsp.h:144
initialized and sending/receiving data
Definition: rtsp.h:197
RTSPMethod
Definition: rtspcodes.h:129
char real_challenge[64]
the "RealChallenge1:" field from the server
Definition: rtsp.h:270
static int rtsp_read_pause(AVFormatContext *s)
Definition: rtspdec.c:570
const char * message
Definition: rtspdec.c:39
av_dlog(ac->avr,"%d samples - audio_convert: %s to %s (%s)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt), use_generic?ac->func_descr_generic:ac->func_descr)
int ff_rtsp_tcp_read_packet(AVFormatContext *s, RTSPStream **prtsp_st, uint8_t *buf, int buf_size)
Receive one RTP packet from an TCP interleaved RTSP stream.
Definition: rtspdec.c:744
discard all
Definition: avcodec.h:667
static AVPacket pkt
uint64_t last_rtcp_ntp_time
Definition: rtpdec.h:178
void ff_rdt_subscribe_rule(char *cmd, int size, int stream_nr, int rule_nr)
Add subscription information to Subscribe parameter string.
Definition: rdt.c:384
#define RTSP_FLAG_LISTEN
Wait for incoming connections.
Definition: rtsp.h:417
char session_id[512]
copy of RTSPMessageHeader->session_id, i.e.
Definition: rtsp.h:245
int64_t seek_timestamp
the seek value requested when calling av_seek_frame().
Definition: rtsp.h:239
static int rtsp_send_reply(AVFormatContext *s, enum RTSPStatusCode code, const char *extracontent, uint16_t seq)
Definition: rtspdec.c:95
static int check_sessionid(AVFormatContext *s, RTSPMessageHeader *request)
Definition: rtspdec.c:122
int ff_rtsp_make_setup_request(AVFormatContext *s, const char *host, int port, int lower_transport, const char *real_challenge)
Do the SETUP requests for each stream for the chosen lower transport mode.
enum RTSPLowerTransport lower_transport
network layer transport protocol; e.g.
Definition: rtsp.h:121
This describes the server response to each RTSP command.
Definition: rtsp.h:127
Definition: ftp.c:32
enum RTSPStatusCode code
Definition: rtspdec.c:38
RTSPTransportField transports[RTSP_MAX_TRANSPORTS]
describes the complete "Transport:" line of the server in response to a SETUP RTSP command by the cli...
Definition: rtsp.h:142
Format I/O context.
Definition: avformat.h:1214
int ff_rtsp_connect(AVFormatContext *s)
Connect to the RTSP server and set up the individual media streams.
#define CONFIG_TLS_PROTOCOL
Definition: config.h:1847
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:71
uint64_t first_rtcp_ntp_time
Definition: rtpdec.h:180
static int rtsp_read_packet(AVFormatContext *s, AVPacket *pkt)
Definition: rtspdec.c:807
int get_parameter_supported
Whether the server supports the GET_PARAMETER method.
Definition: rtsp.h:359
if()
Definition: avfilter.c:975
Standards-compliant RTP.
Definition: rtsp.h:57
uint8_t
char session_id[512]
the "Session:" field.
Definition: rtsp.h:148
miscellaneous OS support macros and functions.
void ff_rtp_reset_packet_queue(RTPDemuxContext *s)
Definition: rtpdec.c:677
int id
Format-specific stream ID.
Definition: avformat.h:802
void ff_rtsp_parse_line(RTSPMessageHeader *reply, const char *buf, RTSPState *rt, const char *method)
int initial_timeout
Timeout to wait for incoming connections.
Definition: rtsp.h:392
static int read_line(AVFormatContext *s, char *rbuf, const int rbufsize, int *rbuflen)
Definition: rtspdec.c:70
AVStream ** streams
A list of all streams in the file.
Definition: avformat.h:1282
URLContext * rtsp_hd_out
Additional output handle, used when input and output are done separately, eg for HTTP tunneling...
Definition: rtsp.h:328
static int rtsp_read_setup(AVFormatContext *s, char *host, char *controlurl)
Definition: rtspdec.c:229
#define AVERROR_PROTOCOL_NOT_FOUND
Protocol not found.
Definition: error.h:63
Describe a single stream, as identified by a single m= line block in the SDP content.
Definition: rtsp.h:434
enum RTSPStatusCode status_code
response code from server
Definition: rtsp.h:131
#define AVERROR_EOF
End of file.
Definition: error.h:55
static av_cold int read_close(AVFormatContext *ctx)
Definition: libcdio.c:145
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:191
int ff_rtsp_send_cmd(AVFormatContext *s, const char *method, const char *url, const char *headers, RTSPMessageHeader *reply, unsigned char **content_ptr)
Send a command to the RTSP server and wait for the reply.
static int rtsp_read_play(AVFormatContext *s)
Definition: rtspdec.c:499
static int ff_rtsp_averror(enum RTSPStatusCode status_code, int default_averror)
Definition: rtspcodes.h:144
#define av_log(a,...)
int nb_transports
number of items in the 'transports' variable below
Definition: rtsp.h:134
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
Definition: mathematics.c:140
int ff_sdp_parse(AVFormatContext *s, const char *content)
Parse an SDP description of streams by populating an RTSPState struct within the AVFormatContext; als...
int ff_rtsp_parse_streaming_commands(AVFormatContext *s)
Parse RTSP commands (OPTIONS, PAUSE and TEARDOWN) during streaming in listen mode.
Definition: rtspdec.c:458
Private data for the RTSP demuxer.
Definition: rtsp.h:218
int64_t last_cmd_time
timestamp of the last RTSP command that we sent to the RTSP server.
Definition: rtsp.h:255
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:175
int timeout
copy of RTSPMessageHeader->timeout, i.e.
Definition: rtsp.h:250
av_default_item_name
#define AV_RB16
Definition: intreadwrite.h:53
#define AVERROR(e)
Definition: error.h:43
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:180
const char * r
Definition: vf_curves.c:107
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:196
const AVOption ff_rtsp_options[]
Definition: rtsp.c:80
Definition: graph2dot.c:48
URLContext * rtsp_hd
Definition: rtsp.h:220
int64_t rtcp_ts_offset
Definition: rtpdec.h:182
size_t av_strlcpy(char *dst, const char *src, size_t size)
Copy the string src to dst, but no more than size - 1 bytes, and null-terminate dst.
Definition: avstring.c:83
static int parse_command_line(AVFormatContext *s, const char *line, int linelen, char *uri, int urisize, char *method, int methodsize, enum RTSPMethod *methodcode)
Definition: rtspdec.c:355
struct RTSPStream ** rtsp_streams
streams in this session
Definition: rtsp.h:225
static int rtsp_read_record(AVFormatContext *s)
Definition: rtspdec.c:333
uint32_t timestamp
Definition: rtpdec.h:155
int stream_index
corresponding stream index, if any.
Definition: rtsp.h:439
int seq
RTSP command sequence number.
Definition: rtsp.h:241
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
Definition: avformat.h:1270
#define LIBAVFORMAT_IDENT
Definition: version.h:44
char filename[1024]
input or output filename
Definition: avformat.h:1290
int nb_rtsp_streams
number of items in the 'rtsp_streams' variable
Definition: rtsp.h:223
#define AV_TIME_BASE
Internal time base represented as integer.
Definition: avutil.h:247
static int read_probe(AVProbeData *pd)
Definition: jvdec.c:55
int content_length
length of the data following this header
Definition: rtsp.h:129
ret
Definition: avfilter.c:974
char last_subscription[1024]
the last value of the "SET_PARAMETER Subscribe:" RTSP command.
Definition: rtsp.h:301
int stale
Auth ok, but needs to be resent with a new nonce.
Definition: httpauth.h:71
int ff_rdt_parse_header(const uint8_t *buf, int len, int *pset_id, int *pseq_no, int *pstream_id, int *pis_keyframe, uint32_t *ptimestamp)
Actual data handling.
Definition: rdt.c:190
static int read_header(FFV1Context *f)
Definition: ffv1dec.c:619
Stream structure.
Definition: avformat.h:795
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
Definition: avio_reading.c:42
int ff_url_join(char *str, int size, const char *proto, const char *authorization, const char *hostname, int port, const char *fmt,...)
Definition: url.c:36
int nb_byes
Definition: rtsp.h:336
enum RTSPLowerTransport lower_transport
the negotiated network layer transport protocol; e.g.
Definition: rtsp.h:262
#define AV_LOG_INFO
Standard information.
Definition: log.h:186
void ff_rtsp_undo_setup(AVFormatContext *s, int send_packets)
Undo the effect of ff_rtsp_make_setup_request, close the transport_priv and rtp_handle fields...
Definition: rtsp.c:699
int rtp_port_max
Definition: rtsp.h:387
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
Definition: avutil.h:253
int64_t unwrapped_timestamp
Definition: rtpdec.h:158
enum RTSPTransport transport
the negotiated data/packet transport protocol; e.g.
Definition: rtsp.h:258
void * buf
Definition: avisynth_c.h:595
#define RTSPS_DEFAULT_PORT
Definition: rtsp.h:73
#define AVIO_FLAG_READ_WRITE
read-write pseudo flag
Definition: avio.h:370
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
Definition: error.h:50
int rtsp_flags
Various option flags for the RTSP muxer/demuxer.
Definition: rtsp.h:377
int client_port_max
Definition: rtsp.h:101
Describe the class of an AVClass context structure.
Definition: log.h:66
AVInputFormat ff_rtsp_demuxer
Definition: rtspdec.c:956
int index
Definition: gxfenc.c:89
static int rtsp_listen(AVFormatContext *s)
Definition: rtspdec.c:624
not initialized
Definition: rtsp.h:196
size_t av_strlcatf(char *dst, size_t size, const char *fmt,...)
Definition: avstring.c:101
void ff_rtsp_close_streams(AVFormatContext *s)
Close and free all streams within the RTSP (de)muxer.
Definition: rtsp.c:733
#define snprintf
Definition: snprintf.h:34
This structure contains the data a format has to probe a file.
Definition: avformat.h:401
size_t av_strlcat(char *dst, const char *src, size_t size)
Append the string src to the string dst, but to a total length of no more than size - 1 bytes...
Definition: avstring.c:93
int interleaved_max
Definition: rtsp.h:93
int64_t av_gettime_relative(void)
Get the current time in microseconds since some unspecified starting point.
Definition: time.c:56
enum RTSPServerType server_type
brand of server that we're talking to; e.g.
Definition: rtsp.h:267
static int flags
Definition: cpu.c:47
int ffurl_close(URLContext *h)
Definition: avio.c:387
RTSPStatusCode
RTSP handling.
Definition: rtspcodes.h:31
int64_t range_start
Time range of the streams that the server will stream.
Definition: rtsp.h:138
enum RTSPClientState state
indicator of whether we are currently receiving data from the server.
Definition: rtsp.h:231
int ff_rtsp_fetch_packet(AVFormatContext *s, AVPacket *pkt)
Receive one packet from the RTSPStreams set up in the AVFormatContext (which should contain a RTSPSta...
#define AVPROBE_SCORE_MAX
maximum score
Definition: avformat.h:413
int av_strstart(const char *str, const char *pfx, const char **ptr)
Return non-zero if pfx is a prefix of str.
Definition: avstring.c:34
Main libavformat public API header.
static const AVClass rtsp_demuxer_class
Definition: rtspdec.c:949
initialized, requesting a seek
Definition: rtsp.h:199
#define AVFMT_NOFILE
Demuxer will use avio_open, no opened file should be provided by the caller.
Definition: avformat.h:418
int ffurl_open(URLContext **puc, const char *filename, int flags, const AVIOInterruptCB *int_cb, AVDictionary **options)
Create an URLContext for accessing to the resource indicated by url, and open it. ...
Definition: avio.c:269
int need_subscription
The following are used for Real stream selection.
Definition: rtsp.h:288
int ffurl_read_complete(URLContext *h, unsigned char *buf, int size)
Read as many bytes as possible (up to size), calling the read function multiple times if necessary...
Definition: avio.c:337
static int rtsp_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
Definition: rtspdec.c:922
uint32_t base_timestamp
Definition: rtpdec.h:156
initialized, but not receiving data
Definition: rtsp.h:198
int ff_rtsp_read_reply(AVFormatContext *s, RTSPMessageHeader *reply, unsigned char **content_ptr, int return_on_interleaved_data, const char *method)
Read a RTSP message from the server, or prepare to read data packets if we're reading data interleave...
int ff_rtsp_send_cmd_async(AVFormatContext *s, const char *method, const char *url, const char *headers)
Send a command to the RTSP server without waiting for the reply.
#define AVERROR_OPTION_NOT_FOUND
Option not found.
Definition: error.h:61
TCP; interleaved in RTSP.
Definition: rtsp.h:39
HTTPAuthState auth_state
authentication state
Definition: rtsp.h:276
int len
char control_url[1024]
url for this stream (from SDP)
Definition: rtsp.h:445
void * priv_data
Format private data.
Definition: avformat.h:1242
#define AVERROR_STREAM_NOT_FOUND
Stream not found.
Definition: error.h:65
uint64_t packets
The number of returned packets.
Definition: rtsp.h:349
AVDiscard
Definition: avcodec.h:658
static void * av_mallocz_array(size_t nmemb, size_t size)
Definition: mem.h:228
Realmedia-style server.
Definition: rtsp.h:208
int lower_transport_mask
A mask with all requested transport methods.
Definition: rtsp.h:344
static int rtsp_read_announce(AVFormatContext *s)
Definition: rtspdec.c:170
#define av_freep(p)
const char * name
A comma separated list of short names for the format.
Definition: avformat.h:581
unbuffered private I/O API
uint32_t av_get_random_seed(void)
Get a seed to use in conjunction with random functions.
Definition: random_seed.c:109
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
Definition: avformat.h:837
int interleaved_max
Definition: rtsp.h:443
enum AVDiscard discard
Selects which packets can be discarded at will and do not need to be demuxed.
Definition: avformat.h:860
int interleaved_min
interleave IDs; copies of RTSPTransportField->interleaved_min/max for the selected transport...
Definition: rtsp.h:443
This structure stores compressed data.
Definition: avcodec.h:1137
void ff_rtsp_close_connections(AVFormatContext *s)
Close all connection handles within the RTSP (de)muxer.
URLContext * rtp_handle
RTP stream handle (if UDP)
Definition: rtsp.h:435
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:241
void * transport_priv
RTP/RDT parse context if input, RTP AVFormatContext if output.
Definition: rtsp.h:436
int client_port_min
UDP client ports; these should be the local ports of the UDP RTP (and RTCP) sockets over which we rec...
Definition: rtsp.h:101
int initial_pause
Do not begin to play the stream immediately.
Definition: rtsp.h:364