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