[FFmpeg-devel] [PATCH] RTSP-MS 10/15: ASF header parsing

Ronald S. Bultje rsbultje
Sun Feb 1 04:26:30 CET 2009


Hi,

On Sat, Jan 31, 2009 at 7:51 PM, Michael Niedermayer <michaelni at gmx.at> wrote:
> asf_gb_pos is unused as well

I'll remove that line from this patch, I'll add it when it gets needed
(4 patches later).

> and setting pb to NULL is of course better than not doing it.

Right, so my question was: will that sufficiently address your concern
over the free'ed buffer leaving a "floating" (?) pb pointer in the
AVFormatContext?

See attached patch, just because I like to attach patches.

Ronald
-------------- next part --------------
Index: ffmpeg-svn/libavformat/Makefile
===================================================================
--- ffmpeg-svn.orig/libavformat/Makefile	2009-01-31 11:21:13.000000000 -0500
+++ ffmpeg-svn/libavformat/Makefile	2009-01-31 22:22:30.000000000 -0500
@@ -161,6 +161,7 @@
 OBJS-$(CONFIG_RPL_DEMUXER)               += rpl.o
 OBJS-$(CONFIG_RTP_MUXER)                 += rtp.o         \
                                             rtp_aac.o     \
+                                            rtp_asf.o     \
                                             rtp_mpv.o     \
                                             rtpenc.o      \
                                             rtpenc_h264.o \
Index: ffmpeg-svn/libavformat/rtp_asf.c
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ ffmpeg-svn/libavformat/rtp_asf.c	2009-01-31 22:24:46.000000000 -0500
@@ -0,0 +1,52 @@
+/*
+ * Microsoft RTP/ASF support.
+ * Copyright (c) 2008 Ronald S. Bultje
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file rtp-asf.c
+ * @brief Microsoft RTP/ASF support
+ * @author Ronald S. Bultje <rbultje at ronald.bitfreak.net>
+ */
+
+#include <libavutil/base64.h>
+#include <libavutil/avstring.h>
+#include "rtp_asf.h"
+#include "rtsp.h"
+#include "asf.h"
+
+void ff_wms_parse_sdp_a_line(AVFormatContext *s, const char *p)
+{
+    if (av_strstart(p, "pgmpu:data:application/vnd.ms.wms-hdr.asfv1;base64,", &p)) {
+        ByteIOContext gb;
+        RTSPState *rt = s->priv_data;
+        int len = strlen(p) * 6 / 8;
+        char *buf = av_mallocz(len);
+        av_base64_decode(buf, p, len);
+
+        init_put_byte(&gb, buf, len, 0, NULL, NULL, NULL, NULL);
+        if (rt->asf_ctx) {
+            av_close_input_stream(rt->asf_ctx);
+            rt->asf_ctx = NULL;
+        }
+        av_open_input_stream(&rt->asf_ctx, &gb, "", &asf_demuxer, NULL);
+        av_free(buf);
+        rt->asf_ctx->pb = NULL;
+    }
+}
Index: ffmpeg-svn/libavformat/rtp_asf.h
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ ffmpeg-svn/libavformat/rtp_asf.h	2009-01-31 22:22:30.000000000 -0500
@@ -0,0 +1,35 @@
+/*
+ * Microsoft RTP/ASF support.
+ * Copyright (c) 2008 Ronald S. Bultje
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVFORMAT_RTP_ASF_H
+#define AVFORMAT_RTP_ASF_H
+
+#include "avformat.h"
+
+/**
+ * Parse a Windows Media Server-specific SDP line
+ *
+ * @param s RTSP demux context
+ * @param line the SDP line to be parsed
+ */
+void ff_wms_parse_sdp_a_line(AVFormatContext *s, const char *p);
+
+#endif /* AVFORMAT_RTP_ASF_H */
Index: ffmpeg-svn/libavformat/rtsp.c
===================================================================
--- ffmpeg-svn.orig/libavformat/rtsp.c	2009-01-31 22:22:29.000000000 -0500
+++ ffmpeg-svn/libavformat/rtsp.c	2009-01-31 22:24:47.000000000 -0500
@@ -36,6 +36,7 @@
 
 #include "rtp_internal.h"
 #include "rdt.h"
+#include "rtp_asf.h"
 
 //#define DEBUG
 //#define DEBUG_RTP_TCP
@@ -496,7 +497,10 @@
         } else if (av_strstart(p, "IsRealDataType:integer;",&p)) {
             if (atoi(p) == 1)
                 rt->transport = RTSP_TRANSPORT_RDT;
-        } else if (s->nb_streams > 0) {
+        } else {
+            if (rt->server_type == RTSP_SERVER_WMS)
+                ff_wms_parse_sdp_a_line(s, p);
+            if (s->nb_streams > 0) {
             if (rt->server_type == RTSP_SERVER_REAL)
                 ff_real_parse_sdp_a_line(s, s->nb_streams - 1, p);
 
@@ -505,6 +509,7 @@
                 rtsp_st->dynamic_handler->parse_sdp_a_line)
                 rtsp_st->dynamic_handler->parse_sdp_a_line(s, s->nb_streams - 1,
                     rtsp_st->dynamic_protocol_context, buf);
+            }
         }
         break;
     }
@@ -1549,6 +1554,10 @@
 
     rtsp_close_streams(rt);
     url_close(rt->rtsp_hd);
+    if (rt->asf_ctx) {
+        av_close_input_stream (rt->asf_ctx);
+        rt->asf_ctx = NULL;
+    }
     return 0;
 }
 
Index: ffmpeg-svn/libavformat/rtsp.h
===================================================================
--- ffmpeg-svn.orig/libavformat/rtsp.h	2009-01-31 11:21:13.000000000 -0500
+++ ffmpeg-svn/libavformat/rtsp.h	2009-01-31 22:24:46.000000000 -0500
@@ -108,6 +108,9 @@
     int need_subscription;
     enum AVDiscard real_setup_cache[MAX_STREAMS];
     char last_subscription[1024];
+
+    /** Windows Media-specific entries */
+    AVFormatContext *asf_ctx;
 } RTSPState;
 
 typedef struct RTSPStream {



More information about the ffmpeg-devel mailing list