[FFmpeg-cvslog] rtsp: add allowed_media_types option

John Brooks git at videolan.org
Thu Nov 3 02:23:11 CET 2011


ffmpeg | branch: master | John Brooks <john.brooks at bluecherry.net> | Sat Oct 29 15:41:24 2011 -0600| [f011fcd67edf27d2b1f6fcdff0b4c19da36176e9] | committer: Martin Storsjö

rtsp: add allowed_media_types option

Streams from RTSP or SDP that do not match an allowed type will
be skipped entirely, which allows video-only or audio-only
streaming from servers that provide both.

Signed-off-by: Martin Storsjö <martin at martin.st>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=f011fcd67edf27d2b1f6fcdff0b4c19da36176e9
---

 libavformat/rtsp.c |   12 +++++++++++-
 libavformat/rtsp.h |    5 +++++
 2 files changed, 16 insertions(+), 1 deletions(-)

diff --git a/libavformat/rtsp.c b/libavformat/rtsp.c
index 5aadc44..b9ef0bf 100644
--- a/libavformat/rtsp.c
+++ b/libavformat/rtsp.c
@@ -65,6 +65,12 @@
     { 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" }
 
+#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" }, \
+    { "video", "Video", 0, AV_OPT_TYPE_CONST, {1 << AVMEDIA_TYPE_VIDEO}, 0, 0, DEC, "allowed_media_types" }, \
+    { "audio", "Audio", 0, AV_OPT_TYPE_CONST, {1 << AVMEDIA_TYPE_AUDIO}, 0, 0, DEC, "allowed_media_types" }, \
+    { "data", "Data", 0, AV_OPT_TYPE_CONST, {1 << AVMEDIA_TYPE_DATA}, 0, 0, DEC, "allowed_media_types" }
+
 const AVOption ff_rtsp_options[] = {
     { "initial_pause",  "Don't start playing the stream immediately", OFFSET(initial_pause), AV_OPT_TYPE_INT, {0}, 0, 1, DEC },
     FF_RTP_FLAG_OPTS(RTSPState, rtp_muxer_flags),
@@ -74,11 +80,13 @@ const AVOption ff_rtsp_options[] = {
     { "udp_multicast", "UDP multicast", 0, AV_OPT_TYPE_CONST, {1 << RTSP_LOWER_TRANSPORT_UDP_MULTICAST}, 0, 0, DEC, "rtsp_transport" },
     { "http", "HTTP tunneling", 0, AV_OPT_TYPE_CONST, {(1 << RTSP_LOWER_TRANSPORT_HTTP)}, 0, 0, DEC, "rtsp_transport" },
     RTSP_FLAG_OPTS("rtsp_flags", "RTSP flags"),
+    RTSP_MEDIATYPE_OPTS("allowed_media_types", "Media types to accept from the server"),
     { NULL },
 };
 
 static const AVOption sdp_options[] = {
     RTSP_FLAG_OPTS("sdp_flags", "SDP flags"),
+    RTSP_MEDIATYPE_OPTS("allowed_media_types", "Media types to accept from the server"),
     { NULL },
 };
 
@@ -325,6 +333,7 @@ static void sdp_parse_line(AVFormatContext *s, SDPParseState *s1,
     case 'm':
         /* new stream */
         s1->skip_media = 0;
+        codec_type = AVMEDIA_TYPE_UNKNOWN;
         get_word(st_type, sizeof(st_type), &p);
         if (!strcmp(st_type, "audio")) {
             codec_type = AVMEDIA_TYPE_AUDIO;
@@ -332,7 +341,8 @@ static void sdp_parse_line(AVFormatContext *s, SDPParseState *s1,
             codec_type = AVMEDIA_TYPE_VIDEO;
         } else if (!strcmp(st_type, "application")) {
             codec_type = AVMEDIA_TYPE_DATA;
-        } else {
+        }
+        if (codec_type == AVMEDIA_TYPE_UNKNOWN || !(rt->media_type_mask & (1 << codec_type))) {
             s1->skip_media = 1;
             return;
         }
diff --git a/libavformat/rtsp.h b/libavformat/rtsp.h
index 7143acb..45b0032 100644
--- a/libavformat/rtsp.h
+++ b/libavformat/rtsp.h
@@ -354,6 +354,11 @@ typedef struct RTSPState {
      * Various option flags for the RTSP muxer/demuxer.
      */
     int rtsp_flags;
+
+    /**
+     * Mask of all requested media types
+     */
+    int media_type_mask;
 } RTSPState;
 
 #define RTSP_FLAG_FILTER_SRC  0x1    /**< Filter incoming UDP packets -



More information about the ffmpeg-cvslog mailing list