82 if (rbuf[idx] ==
'\r') {
84 }
else if (rbuf[idx] ==
'\n') {
90 }
while (idx < rbufsize);
96 const char *extracontent, uint16_t seq)
103 snprintf(message,
sizeof(message),
"RTSP/1.0 %d %s\r\n",
111 av_strlcatf(message,
sizeof(message),
"CSeq: %d\r\n", seq);
114 av_strlcat(message, extracontent,
sizeof(message));
116 av_dlog(s,
"Sending response:\n%s", message);
127 if (!session_id[0]) {
131 if (strcmp(session_id, request->
session_id)) {
148 ret =
read_line(s, rbuf,
sizeof(rbuf), &rbuflen);
152 av_dlog(s,
"Parsing[%d]: %s\n", rbuflen, rbuf);
155 }
while (rbuflen > 0);
156 if (request->
seq != rt->
seq + 1) {
161 if (rt->
session_id[0] && strcmp(method,
"OPTIONS")) {
192 "Unable to get complete SDP Description in ANNOUNCE\n");
205 "Content-Length header value exceeds sdp allocated buffer (4KB)\n");
207 "Content-Length exceeds buffer size", request.
seq);
224 "Public: ANNOUNCE, PAUSE, SETUP, TEARDOWN, RECORD\r\n",
236 char responseheaders[1024];
238 int transportidx = 0;
257 " protocol not supported (yet)\n");
263 "using first of all\n");
284 snprintf(responseheaders,
sizeof(responseheaders),
"Transport: " 285 "RTP/AVP/TCP;unicast;mode=receive;interleaved=%d-%d" 291 av_dlog(s,
"Opening: %s", url);
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",
324 av_strlcatf(responseheaders,
sizeof(responseheaders),
"Session: %s\r\n",
338 char responseheaders[1024];
347 snprintf(responseheaders,
sizeof(responseheaders),
"Session: %s\r\n",
356 int linelen,
char *uri,
int urisize,
357 char *method,
int methodsize,
361 const char *linept, *searchlinept;
362 linept = strchr(line,
' ');
363 if (linept - line > methodsize - 1) {
367 memcpy(method, line, linept - line);
368 method[linept - line] =
'\0';
370 if (!strcmp(method,
"ANNOUNCE"))
372 else if (!strcmp(method,
"OPTIONS"))
374 else if (!strcmp(method,
"RECORD"))
376 else if (!strcmp(method,
"SETUP"))
378 else if (!strcmp(method,
"PAUSE"))
380 else if (!strcmp(method,
"TEARDOWN"))
393 && (*methodcode !=
SETUP)) {
410 searchlinept = strchr(linept,
' ');
415 if (searchlinept - linept > urisize - 1) {
419 memcpy(uri, linept, searchlinept - linept);
420 uri[searchlinept - linept] =
'\0';
422 char host[128], path[512], auth[128];
424 char ctl_host[128], ctl_path[512], ctl_auth[128];
427 path,
sizeof(path), uri);
429 sizeof(ctl_host), &ctl_port, ctl_path,
sizeof(ctl_path),
431 if (strcmp(host, ctl_host))
434 if (strcmp(path, ctl_path) && *methodcode !=
SETUP)
436 " %s\n", path, ctl_path);
439 "Updating control URI to %s\n", uri);
444 linept = searchlinept + 1;
455 unsigned char rbuf[4096];
456 unsigned char method[10];
463 ret =
read_line(s, rbuf,
sizeof(rbuf), &rbuflen);
467 sizeof(method), &methodcode);
477 if (methodcode ==
PAUSE) {
481 }
else if (methodcode ==
OPTIONS) {
483 "Public: ANNOUNCE, PAUSE, SETUP, TEARDOWN, " 484 "RECORD\r\n", request.
seq);
485 }
else if (methodcode ==
TEARDOWN) {
522 snprintf(cmd,
sizeof(cmd),
523 "Range: npt=%"PRId64
".%03"PRId64
"-\r\n",
572 unsigned char *content =
NULL;
576 snprintf(cmd,
sizeof(cmd),
577 "Accept: application/sdp\r\n");
584 "Require: com.real.retain-entity-for-setup\r\n",
608 char host[128], path[512], auth[128];
612 unsigned char rbuf[4096];
613 unsigned char method[10];
641 ret =
read_line(s, rbuf,
sizeof(rbuf), &rbuflen);
645 sizeof(method), &methodcode);
654 }
else if (methodcode ==
OPTIONS) {
656 }
else if (methodcode ==
RECORD) {
660 }
else if (methodcode ==
SETUP)
721 av_dlog(s,
"tcp_read_packet:\n");
740 av_dlog(s,
"id=%d len=%d\n",
id, len);
741 if (len > buf_size || len < 12)
755 id <= rtsp_st->interleaved_max)
794 snprintf(cmd,
sizeof(cmd),
795 "Unsubscribe: %s\r\n",
806 int r, rule_nr, first = 1;
812 snprintf(cmd,
sizeof(cmd),
893 int64_t timestamp,
int flags)
937 .priv_class = &rtsp_demuxer_class,
int interleaved_min
interleave ids, if TCP transport; each TCP/RTSP data packet starts with a '$', stream length and stre...
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.
int rtp_port_min
Minimum and maximum local UDP ports.
Realmedia Data Transport.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
static int rtsp_read_options(AVFormatContext *s)
int ff_rtp_get_local_rtp_port(URLContext *h)
Return the local rtp port used by the RTP connection.
AVIOInterruptCB interrupt_callback
Custom interrupt callbacks for the I/O layer.
static const struct RTSPStatusMessage status_messages[]
static int rtsp_read_request(AVFormatContext *s, RTSPMessageHeader *request, const char *method)
static int rtsp_read_close(AVFormatContext *s)
#define AV_LOG_WARNING
Something somehow does not look correct.
char control_uri[1024]
some MS RTSP streams contain a URL in the SDP that we need to use for all subsequent RTSP requests...
static int rtsp_read_header(AVFormatContext *s)
int ffurl_write(URLContext *h, const unsigned char *buf, int size)
Write size bytes from buf to the resource accessed by h.
#define RTSP_DEFAULT_PORT
int64_t range_start_offset
int ff_rtsp_open_transport_ctx(AVFormatContext *s, RTSPStream *rtsp_st)
Open RTSP transport context.
static int read_seek(AVFormatContext *ctx, int stream_index, int64_t timestamp, int flags)
static int rtsp_probe(AVProbeData *p)
enum AVDiscard * real_setup
current stream setup.
static int resetup_tcp(AVFormatContext *s)
enum AVDiscard * real_setup_cache
stream setup during the last frame read.
int mode_record
transport set to record data
int ff_rtsp_setup_input_streams(AVFormatContext *s, RTSPMessageHeader *reply)
Get the description of the stream and set up the RTSPStream child objects.
void ff_network_close(void)
initialized and sending/receiving data
char real_challenge[64]
the "RealChallenge1:" field from the server
static int rtsp_read_pause(AVFormatContext *s)
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.
void ff_rdt_subscribe_rule(char *cmd, int size, int stream_nr, int rule_nr)
Add subscription information to Subscribe parameter string.
#define RTSP_FLAG_LISTEN
Wait for incoming connections.
char session_id[512]
copy of RTSPMessageHeader->session_id, i.e.
int64_t seek_timestamp
the seek value requested when calling av_seek_frame().
static int rtsp_send_reply(AVFormatContext *s, enum RTSPStatusCode code, const char *extracontent, uint16_t seq)
static int check_sessionid(AVFormatContext *s, RTSPMessageHeader *request)
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.
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
int ff_rtsp_connect(AVFormatContext *s)
Connect to the RTSP server and set up the individual media streams.
av_dlog(ac->avr, "%d samples - audio_convert: %s to %s (%s)\, 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)
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
static int rtsp_read_packet(AVFormatContext *s, AVPacket *pkt)
int get_parameter_supported
Whether the server supports the GET_PARAMETER method.
miscellaneous OS support macros and functions.
void ff_rtp_reset_packet_queue(RTPDemuxContext *s)
int id
Format-specific stream ID.
void ff_rtsp_parse_line(RTSPMessageHeader *reply, const char *buf, RTSPState *rt, const char *method)
int initial_timeout
Timeout to wait for incoming connections.
static int read_line(AVFormatContext *s, char *rbuf, const int rbufsize, int *rbuflen)
AVStream ** streams
A list of all streams in the file.
URLContext * rtsp_hd_out
Additional output handle, used when input and output are done separately, eg for HTTP tunneling...
Aggregate operation not allowed.
static int rtsp_read_setup(AVFormatContext *s, char *host, char *controlurl)
#define AVERROR_PROTOCOL_NOT_FOUND
Protocol not found.
Describe a single stream, as identified by a single m= line block in the SDP content.
#define AVERROR_EOF
End of file.
static av_cold int read_close(AVFormatContext *ctx)
#define AV_LOG_VERBOSE
Detailed information.
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)
Only aggregate operation allowed.
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
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.
Private data for the RTSP demuxer.
int64_t last_cmd_time
timestamp of the last RTSP command that we sent to the RTSP server.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
int timeout
copy of RTSPMessageHeader->timeout, i.e.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
const AVOption ff_rtsp_options[]
void av_log(void *avcl, int level, const char *fmt,...)
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.
static int parse_command_line(AVFormatContext *s, const char *line, int linelen, char *uri, int urisize, char *method, int methodsize, enum RTSPMethod *methodcode)
struct RTSPStream ** rtsp_streams
streams in this session
static int rtsp_read_record(AVFormatContext *s)
int stream_index
corresponding stream index, if any.
int seq
RTSP command sequence number.
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
char filename[1024]
input or output filename
int nb_rtsp_streams
number of items in the 'rtsp_streams' variable
int64_t first_rtcp_ntp_time
#define AV_TIME_BASE
Internal time base represented as integer.
char last_subscription[1024]
the last value of the "SET_PARAMETER Subscribe:" RTSP command.
int64_t last_rtcp_ntp_time
int stale
Auth ok, but needs to be resent with a new nonce.
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.
static int read_header(FFV1Context *f)
if(ac->has_optimized_func)
int64_t av_gettime(void)
Get the current time in microseconds.
int ff_url_join(char *str, int size, const char *proto, const char *authorization, const char *hostname, int port, const char *fmt,...)
enum RTSPLowerTransport lower_transport
the negotiated network layer transport protocol; e.g.
#define AV_LOG_INFO
Standard information.
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...
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
int64_t unwrapped_timestamp
enum RTSPTransport transport
the negotiated data/packet transport protocol; e.g.
static int read_packet(AVFormatContext *ctx, AVPacket *pkt)
#define AVIO_FLAG_READ_WRITE
read-write pseudo flag
#define AVERROR_BUG
Bug detected, please report the issue.
int rtsp_flags
Various option flags for the RTSP muxer/demuxer.
Describe the class of an AVClass context structure.
AVInputFormat ff_rtsp_demuxer
static int rtsp_listen(AVFormatContext *s)
size_t av_strlcatf(char *dst, size_t size, const char *fmt,...)
void ff_rtsp_close_streams(AVFormatContext *s)
Close and free all streams within the RTSP (de)muxer.
This structure contains the data a format has to probe a file.
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...
enum RTSPServerType server_type
brand of server that we're talking to; e.g.
int ffurl_close(URLContext *h)
Close the resource accessed by the URLContext h, and free the memory used by it.
RTSPStatusCode
RTSP handling.
enum RTSPClientState state
indicator of whether we are currently receiving data from the server.
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...
int av_strstart(const char *str, const char *pfx, const char **ptr)
Return non-zero if pfx is a prefix of str.
static const AVClass rtsp_demuxer_class
initialized, requesting a seek
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. ...
int need_subscription
The following are used for Real stream selection.
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...
static int rtsp_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)
initialized, but not receiving data
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.
TCP; interleaved in RTSP.
HTTPAuthState auth_state
authentication state
char control_url[1024]
url for this stream (from SDP)
void * priv_data
Format private data.
Method Not Valid in This State.
#define AVERROR_STREAM_NOT_FOUND
Stream not found.
uint64_t packets
The number of returned packets.
int lower_transport_mask
A mask with all requested transport methods.
static int rtsp_read_announce(AVFormatContext *s)
RTSP Version not supported.
unbuffered private I/O API
uint32_t av_get_random_seed(void)
Get random data.
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
enum AVDiscard discard
Selects which packets can be discarded at will and do not need to be demuxed.
int interleaved_min
interleave IDs; copies of RTSPTransportField->interleaved_min/max for the selected transport...
This structure stores compressed data.
void ff_rtsp_close_connections(AVFormatContext *s)
Close all connection handles within the RTSP (de)muxer.
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
URLContext * rtp_handle
RTP stream handle (if UDP)
#define AV_NOPTS_VALUE
Undefined timestamp value.
void * transport_priv
RTP/RDT parse context if input, RTP AVFormatContext if output.
int client_port_min
UDP client ports; these should be the local ports of the UDP RTP (and RTCP) sockets over which we rec...
int initial_pause
Do not begin to play the stream immediately.