Commit a8ad6ffa authored by Jordi Ortiz's avatar Jordi Ortiz Committed by Martin Storsjö

rtsp: Add listen mode

This makes the RTSP demuxer act as a server, listening for an
incoming connection.
Signed-off-by: 's avatarMartin Storsjö <martin@martin.st>
parent 6e71c120
...@@ -31,6 +31,7 @@ version <next>: ...@@ -31,6 +31,7 @@ version <next>:
- join audio filter - join audio filter
- audio channel mapping filter - audio channel mapping filter
- Microsoft ATC Screen decoder - Microsoft ATC Screen decoder
- RTSP listen mode
version 0.8: version 0.8:
......
...@@ -347,6 +347,8 @@ Flags for @code{rtsp_flags}: ...@@ -347,6 +347,8 @@ Flags for @code{rtsp_flags}:
@table @option @table @option
@item filter_src @item filter_src
Accept packets only from negotiated peer address and port. Accept packets only from negotiated peer address and port.
@item listen
Act as a server, listening for an incoming connection.
@end table @end table
When receiving data over UDP, the demuxer tries to reorder received packets When receiving data over UDP, the demuxer tries to reorder received packets
...@@ -379,6 +381,12 @@ To send a stream in realtime to a RTSP server, for others to watch: ...@@ -379,6 +381,12 @@ To send a stream in realtime to a RTSP server, for others to watch:
avconv -re -i @var{input} -f rtsp -muxdelay 0.1 rtsp://server/live.sdp avconv -re -i @var{input} -f rtsp -muxdelay 0.1 rtsp://server/live.sdp
@end example @end example
To receive a stream in realtime:
@example
avconv -rtsp_flags listen -i rtsp://ownaddress/live.sdp @var{output}
@end example
@section sap @section sap
Session Announcement Protocol (RFC 2974). This is not technically a Session Announcement Protocol (RFC 2974). This is not technically a
......
...@@ -63,7 +63,8 @@ ...@@ -63,7 +63,8 @@
#define RTSP_FLAG_OPTS(name, longname) \ #define RTSP_FLAG_OPTS(name, longname) \
{ name, longname, OFFSET(rtsp_flags), AV_OPT_TYPE_FLAGS, {0}, INT_MIN, INT_MAX, DEC, "rtsp_flags" }, \ { name, longname, OFFSET(rtsp_flags), AV_OPT_TYPE_FLAGS, {0}, INT_MIN, INT_MAX, DEC, "rtsp_flags" }, \
{ "filter_src", "Only receive packets from the negotiated peer IP", 0, AV_OPT_TYPE_CONST, {RTSP_FLAG_FILTER_SRC}, 0, 0, DEC, "rtsp_flags" } { "filter_src", "Only receive packets from the negotiated peer IP", 0, AV_OPT_TYPE_CONST, {RTSP_FLAG_FILTER_SRC}, 0, 0, DEC, "rtsp_flags" }, \
{ "listen", "Wait for incoming connections", 0, AV_OPT_TYPE_CONST, {RTSP_FLAG_LISTEN}, 0, 0, DEC, "rtsp_flags" }
#define RTSP_MEDIATYPE_OPTS(name, longname) \ #define RTSP_MEDIATYPE_OPTS(name, longname) \
{ name, longname, OFFSET(media_type_mask), AV_OPT_TYPE_FLAGS, { (1 << (AVMEDIA_TYPE_DATA+1)) - 1 }, INT_MIN, INT_MAX, DEC, "allowed_media_types" }, \ { name, longname, OFFSET(media_type_mask), AV_OPT_TYPE_FLAGS, { (1 << (AVMEDIA_TYPE_DATA+1)) - 1 }, INT_MIN, INT_MAX, DEC, "allowed_media_types" }, \
...@@ -83,6 +84,7 @@ const AVOption ff_rtsp_options[] = { ...@@ -83,6 +84,7 @@ const AVOption ff_rtsp_options[] = {
RTSP_MEDIATYPE_OPTS("allowed_media_types", "Media types to accept from the server"), RTSP_MEDIATYPE_OPTS("allowed_media_types", "Media types to accept from the server"),
{ "min_port", "Minimum local UDP port", OFFSET(rtp_port_min), AV_OPT_TYPE_INT, {RTSP_RTP_PORT_MIN}, 0, 65535, DEC|ENC }, { "min_port", "Minimum local UDP port", OFFSET(rtp_port_min), AV_OPT_TYPE_INT, {RTSP_RTP_PORT_MIN}, 0, 65535, DEC|ENC },
{ "max_port", "Maximum local UDP port", OFFSET(rtp_port_max), AV_OPT_TYPE_INT, {RTSP_RTP_PORT_MAX}, 0, 65535, DEC|ENC }, { "max_port", "Maximum local UDP port", OFFSET(rtp_port_max), AV_OPT_TYPE_INT, {RTSP_RTP_PORT_MAX}, 0, 65535, DEC|ENC },
{ "timeout", "Maximum timeout (in seconds) to wait for incoming connections. -1 is infinite. Implies flag listen", OFFSET(initial_timeout), AV_OPT_TYPE_INT, {-1}, INT_MIN, INT_MAX, DEC },
{ NULL }, { NULL },
}; };
...@@ -1714,14 +1716,24 @@ static int udp_read_packet(AVFormatContext *s, RTSPStream **prtsp_st, ...@@ -1714,14 +1716,24 @@ static int udp_read_packet(AVFormatContext *s, RTSPStream **prtsp_st,
} }
#if CONFIG_RTSP_DEMUXER #if CONFIG_RTSP_DEMUXER
if (tcp_fd != -1 && p[0].revents & POLLIN) { if (tcp_fd != -1 && p[0].revents & POLLIN) {
RTSPMessageHeader reply; if (rt->rtsp_flags & RTSP_FLAG_LISTEN) {
if (rt->state == RTSP_STATE_STREAMING) {
ret = ff_rtsp_read_reply(s, &reply, NULL, 0, NULL); if (!ff_rtsp_parse_streaming_commands(s))
if (ret < 0) return AVERROR_EOF;
return ret; else
/* XXX: parse message */ av_log(s, AV_LOG_WARNING,
if (rt->state != RTSP_STATE_STREAMING) "Unable to answer to TEARDOWN\n");
return 0; } else
return 0;
} else {
RTSPMessageHeader reply;
ret = ff_rtsp_read_reply(s, &reply, NULL, 0, NULL);
if (ret < 0)
return ret;
/* XXX: parse message */
if (rt->state != RTSP_STATE_STREAMING)
return 0;
}
} }
#endif #endif
} else if (n == 0 && ++timeout_cnt >= MAX_TIMEOUTS) { } else if (n == 0 && ++timeout_cnt >= MAX_TIMEOUTS) {
......
...@@ -372,11 +372,17 @@ typedef struct RTSPState { ...@@ -372,11 +372,17 @@ typedef struct RTSPState {
* Minimum and maximum local UDP ports. * Minimum and maximum local UDP ports.
*/ */
int rtp_port_min, rtp_port_max; int rtp_port_min, rtp_port_max;
/**
* Timeout to wait for incoming connections.
*/
int initial_timeout;
} RTSPState; } RTSPState;
#define RTSP_FLAG_FILTER_SRC 0x1 /**< Filter incoming UDP packets - #define RTSP_FLAG_FILTER_SRC 0x1 /**< Filter incoming UDP packets -
receive packets only from the right receive packets only from the right
source address and port. */ source address and port. */
#define RTSP_FLAG_LISTEN 0x2 /**< Wait for incoming connections. */
/** /**
* Describe a single stream, as identified by a single m= line block in the * Describe a single stream, as identified by a single m= line block in the
...@@ -528,6 +534,12 @@ int ff_rtsp_setup_input_streams(AVFormatContext *s, RTSPMessageHeader *reply); ...@@ -528,6 +534,12 @@ int ff_rtsp_setup_input_streams(AVFormatContext *s, RTSPMessageHeader *reply);
*/ */
int ff_rtsp_setup_output_streams(AVFormatContext *s, const char *addr); int ff_rtsp_setup_output_streams(AVFormatContext *s, const char *addr);
/**
* Parse RTSP commands (OPTIONS, PAUSE and TEARDOWN) during streaming in
* listen mode.
*/
int ff_rtsp_parse_streaming_commands(AVFormatContext *s);
/** /**
* Parse an SDP description of streams by populating an RTSPState struct * Parse an SDP description of streams by populating an RTSPState struct
* within the AVFormatContext; also allocate the RTP streams and the * within the AVFormatContext; also allocate the RTP streams and the
......
...@@ -37,4 +37,18 @@ RTSP_STATUS_SERVICE =503, /**< Service Unavailable */ ...@@ -37,4 +37,18 @@ RTSP_STATUS_SERVICE =503, /**< Service Unavailable */
RTSP_STATUS_VERSION =505, /**< RTSP Version not supported */ RTSP_STATUS_VERSION =505, /**< RTSP Version not supported */
}; };
enum RTSPMethod {
DESCRIBE,
ANNOUNCE,
OPTIONS,
SETUP,
PLAY,
PAUSE,
TEARDOWN,
GET_PARAMETER,
SET_PARAMETER,
REDIRECT,
RECORD,
UNKNOWN = -1,
};
#endif /* AVFORMAT_RTSPCODES_H */ #endif /* AVFORMAT_RTSPCODES_H */
This diff is collapsed.
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
#include "libavutil/avutil.h" #include "libavutil/avutil.h"
#define LIBAVFORMAT_VERSION_MAJOR 54 #define LIBAVFORMAT_VERSION_MAJOR 54
#define LIBAVFORMAT_VERSION_MINOR 6 #define LIBAVFORMAT_VERSION_MINOR 7
#define LIBAVFORMAT_VERSION_MICRO 0 #define LIBAVFORMAT_VERSION_MICRO 0
#define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \ #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment