[FFmpeg-devel] RTSP marker-bit packet merging

Ronald S. Bultje rsbultje
Thu Jan 29 03:13:28 CET 2009


Hi Luca,

On Mon, Jan 26, 2009 at 5:59 AM, Luca Barbato <lu_zero at gentoo.org> wrote:
> Ronald S. Bultje wrote:
>> I've seen in several (QDM2, SV3V, X-QT and UDP RTSP/ASF) cases that
>> there is a reuse of packet merging code where packet data (minus some
>> small header) is merged and finished when the marker bit is set. Is it
>> OK if I add some generic code to rtpdec.c to handle this? It would
>> look like this:
>
> I think the new datatype is unnecessary beside that the function is
> useful ^^;

I think I agree on second thought. Attached patch OK to apply? I
modified my local tree to use it and it saves 10-20 LOC in 3
depayloaders (none of them completely integrated in SVN yet, but
ohwell).

Ronald
-------------- next part --------------
Index: ffmpeg-svn/libavformat/rtpdec.c
===================================================================
--- ffmpeg-svn.orig/libavformat/rtpdec.c	2009-01-25 18:42:23.000000000 -0500
+++ ffmpeg-svn/libavformat/rtpdec.c	2009-01-27 18:33:30.000000000 -0500
@@ -557,3 +557,22 @@
     }
     av_free(s);
 }
+
+int ff_rtp_merge_data_packet(const char *ibuf, int ilen, int ioff,
+                             char **obuf, int *olen, int flags)
+{
+    if (ioff == 0) {
+        av_freep(*obuf);
+        *olen = 0;
+        *obuf = av_malloc(ilen);
+    } else if (ioff == *olen) {
+        *obuf = av_realloc(*obuf, *olen + ilen);
+    } else {
+        av_freep(*obuf);
+        *olen = 0;
+        return -1;
+    }
+    memcpy(*obuf + *olen, ibuf, ilen);
+    *olen += ilen;
+    return !(flags & RTP_FLAG_MARKER);
+}
Index: ffmpeg-svn/libavformat/rtp.h
===================================================================
--- ffmpeg-svn.orig/libavformat/rtp.h	2009-01-28 13:15:55.000000000 -0500
+++ ffmpeg-svn/libavformat/rtp.h	2009-01-28 13:16:08.000000000 -0500
@@ -86,6 +86,23 @@
  */
 int rtp_check_and_send_back_rr(RTPDemuxContext *s, int count);
 
+/**
+ * Add RTP packet data into a collection buffer. The input data offset
+ * is checked against the existing data length to ensure packet integrity.
+ * @param ibuf input data buffer data, i.e. the RTP packet data minus header
+ * @param ilen length of the input data buffer
+ * @param ioff offset of the input data buffer against the start of the data.
+ *             olen will be checked against this value, and the function will
+ *             return an error if the two are not the same. -1 if unknown.
+ * @param obuf pointer to output data, may be re-allocated or discarded
+ * @param olen pointer to length of the output data, may be changed
+ * @param flags RTP packet flags, to check whether the RTP marker bit is set.
+ * @return 0 if the packet was completed (RTP marker bit was set), <0 on error
+ *         or 1 if more data is needed to complete the RTP packet.
+ */
+int ff_rtp_merge_data_packet(const char *ibuf, int ilen, int ioff,
+                             char **obuf, int *olen, int flags);
+
 #define RTP_PT_PRIVATE 96
 #define RTP_VERSION 2
 #define RTP_MAX_SDES 256   /**< maximum text length for SDES */



More information about the ffmpeg-devel mailing list