changeset 5560:e09092917f7e libavformat

Rename the RTP muxer sources so that the packetisation functions are in rtpenc_*.c files.
author lucabe
date Mon, 18 Jan 2010 13:44:12 +0000
parents acb3871f01c0
children 067c0af56a4c
files Makefile rtp_aac.c rtp_amr.c rtp_h263.c rtp_mpv.c rtpenc_aac.c rtpenc_amr.c rtpenc_h263.c rtpenc_mpv.c
diffstat 9 files changed, 354 insertions(+), 354 deletions(-) [+]
line wrap: on
line diff
--- a/Makefile	Mon Jan 18 11:18:25 2010 +0000
+++ b/Makefile	Mon Jan 18 13:44:12 2010 +0000
@@ -201,10 +201,10 @@
 OBJS-$(CONFIG_ROQ_MUXER)                 += raw.o
 OBJS-$(CONFIG_RPL_DEMUXER)               += rpl.o
 OBJS-$(CONFIG_RTP_MUXER)                 += rtp.o         \
-                                            rtp_aac.o     \
-                                            rtp_amr.o     \
-                                            rtp_h263.o    \
-                                            rtp_mpv.o     \
+                                            rtpenc_aac.o     \
+                                            rtpenc_amr.o     \
+                                            rtpenc_h263.o    \
+                                            rtpenc_mpv.o     \
                                             rtpenc.o      \
                                             rtpenc_h264.o \
                                             avc.o
--- a/rtp_aac.c	Mon Jan 18 11:18:25 2010 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,85 +0,0 @@
-/*
- * copyright (c) 2007 Luca Abeni
- *
- * 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
- */
-
-#include "avformat.h"
-#include "rtpenc.h"
-
-
-void ff_rtp_send_aac(AVFormatContext *s1, const uint8_t *buff, int size)
-{
-    RTPMuxContext *s = s1->priv_data;
-    int len, max_packet_size;
-    uint8_t *p;
-    const int max_frames_per_packet = s->max_frames_per_packet ? s->max_frames_per_packet : 5;
-    const int max_au_headers_size = 2 + 2 * max_frames_per_packet;
-
-    /* skip ADTS header, if present */
-    if ((s1->streams[0]->codec->extradata_size) == 0) {
-        size -= 7;
-        buff += 7;
-    }
-    max_packet_size = s->max_payload_size - max_au_headers_size;
-
-    /* test if the packet must be sent */
-    len = (s->buf_ptr - s->buf);
-    if ((s->num_frames == max_frames_per_packet) || (len && (len + size) > s->max_payload_size)) {
-        int au_size = s->num_frames * 2;
-
-        p = s->buf + max_au_headers_size - au_size - 2;
-        if (p != s->buf) {
-            memmove(p + 2, s->buf + 2, au_size);
-        }
-        /* Write the AU header size */
-        p[0] = ((au_size * 8) & 0xFF) >> 8;
-        p[1] = (au_size * 8) & 0xFF;
-
-        ff_rtp_send_data(s1, p, s->buf_ptr - p, 1);
-
-        s->num_frames = 0;
-    }
-    if (s->num_frames == 0) {
-        s->buf_ptr = s->buf + max_au_headers_size;
-        s->timestamp = s->cur_timestamp;
-    }
-
-    if (size <= max_packet_size) {
-        p = s->buf + s->num_frames++ * 2 + 2;
-        *p++ = size >> 5;
-        *p = (size & 0x1F) << 3;
-        memcpy(s->buf_ptr, buff, size);
-        s->buf_ptr += size;
-    } else {
-        int au_size = size;
-
-        max_packet_size = s->max_payload_size - 4;
-        p = s->buf;
-        p[0] = 0;
-        p[1] = 16;
-        while (size > 0) {
-            len = FFMIN(size, max_packet_size);
-            p[2] = au_size >> 5;
-            p[3] = (au_size & 0x1F) << 3;
-            memcpy(p + 4, buff, len);
-            ff_rtp_send_data(s1, p, len + 4, len == size);
-            size -= len;
-            buff += len;
-        }
-    }
-}
--- a/rtp_amr.c	Mon Jan 18 11:18:25 2010 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,66 +0,0 @@
-/*
- * RTP packetization for AMR audio
- * Copyright (c) 2007 Luca Abeni
- * Copyright (c) 2009 Martin Storsjo
- *
- * 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
- */
-
-#include "avformat.h"
-#include "rtpenc.h"
-
-/**
- * Packetize AMR frames into RTP packets according to RFC 3267,
- * in octet-aligned mode.
- */
-void ff_rtp_send_amr(AVFormatContext *s1, const uint8_t *buff, int size)
-{
-    RTPMuxContext *s          = s1->priv_data;
-    int max_header_toc_size   = 1 + s->max_frames_per_packet;
-    uint8_t *p;
-    int len;
-
-    /* Test if the packet must be sent. */
-    len = s->buf_ptr - s->buf;
-    if (s->num_frames == s->max_frames_per_packet || (len && len + size - 1 > s->max_payload_size)) {
-        int header_size = s->num_frames + 1;
-        p = s->buf + max_header_toc_size - header_size;
-        if (p != s->buf)
-            memmove(p, s->buf, header_size);
-
-        ff_rtp_send_data(s1, p, s->buf_ptr - p, 1);
-
-        s->num_frames = 0;
-    }
-
-    if (!s->num_frames) {
-        s->buf[0]    = 0xf0;
-        s->buf_ptr   = s->buf + max_header_toc_size;
-        s->timestamp = s->cur_timestamp;
-    } else {
-        /* Mark the previous TOC entry as having more entries following. */
-        s->buf[1 + s->num_frames - 1] |= 0x80;
-    }
-
-    /* Copy the frame type and quality bits. */
-    s->buf[1 + s->num_frames++] = buff[0] & 0x7C;
-    buff++;
-    size--;
-    memcpy(s->buf_ptr, buff, size);
-    s->buf_ptr += size;
-}
-
--- a/rtp_h263.c	Mon Jan 18 11:18:25 2010 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,80 +0,0 @@
-/*
- * RTP packetization for H.263 video
- * Copyright (c) 2009 Luca Abeni
- * Copyright (c) 2009 Martin Storsjo
- *
- * 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
- */
-
-#include "avformat.h"
-#include "rtpenc.h"
-
-static const uint8_t *find_resync_marker_reverse(const uint8_t *restrict start,
-                                                 const uint8_t *restrict end)
-{
-    const uint8_t *p = end - 1;
-    start += 1; /* Make sure we never return the original start. */
-    for (; p > start; p -= 2) {
-        if (!*p) {
-            if      (!p[ 1] && p[2]) return p;
-            else if (!p[-1] && p[1]) return p - 1;
-        }
-    }
-    return end;
-}
-
-/**
- * Packetize H.263 frames into RTP packets according to RFC 4629
- */
-void ff_rtp_send_h263(AVFormatContext *s1, const uint8_t *buf1, int size)
-{
-    RTPMuxContext *s = s1->priv_data;
-    int len, max_packet_size;
-    uint8_t *q;
-
-    max_packet_size = s->max_payload_size;
-
-    while (size > 0) {
-        q = s->buf;
-        if ((buf1[0] == 0) && (buf1[1] == 0)) {
-            *q++ = 0x04;
-            buf1 += 2;
-            size -= 2;
-        } else {
-            *q++ = 0;
-        }
-        *q++ = 0;
-
-        len = FFMIN(max_packet_size - 2, size);
-
-        /* Look for a better place to split the frame into packets. */
-        if (len < size) {
-            const uint8_t *end = find_resync_marker_reverse(buf1, buf1 + len);
-            len = end - buf1;
-        }
-
-        memcpy(q, buf1, len);
-        q += len;
-
-        /* 90 KHz time stamp */
-        s->timestamp = s->cur_timestamp;
-        ff_rtp_send_data(s1, s->buf, q - s->buf, (len == size));
-
-        buf1 += len;
-        size -= len;
-    }
-}
--- a/rtp_mpv.c	Mon Jan 18 11:18:25 2010 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,119 +0,0 @@
-/*
- * RTP packetization for MPEG video
- * Copyright (c) 2002 Fabrice Bellard
- * Copyright (c) 2007 Luca Abeni
- *
- * 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
- */
-
-#include "libavcodec/mpegvideo.h"
-#include "avformat.h"
-#include "rtpenc.h"
-
-/* NOTE: a single frame must be passed with sequence header if
-   needed. XXX: use slices. */
-void ff_rtp_send_mpegvideo(AVFormatContext *s1, const uint8_t *buf1, int size)
-{
-    RTPMuxContext *s = s1->priv_data;
-    int len, h, max_packet_size;
-    uint8_t *q;
-    const uint8_t *end = buf1 + size;
-    int begin_of_slice, end_of_slice, frame_type, temporal_reference;
-
-    max_packet_size = s->max_payload_size;
-    begin_of_slice = 1;
-    end_of_slice = 0;
-    frame_type = 0;
-    temporal_reference = 0;
-
-    while (size > 0) {
-        int begin_of_sequence;
-
-        begin_of_sequence = 0;
-        len = max_packet_size - 4;
-
-        if (len >= size) {
-            len = size;
-            end_of_slice = 1;
-        } else {
-            const uint8_t *r, *r1;
-            int start_code;
-
-            r1 = buf1;
-            while (1) {
-                start_code = -1;
-                r = ff_find_start_code(r1, end, &start_code);
-                if((start_code & 0xFFFFFF00) == 0x100) {
-                    /* New start code found */
-                    if (start_code == 0x100) {
-                        frame_type = (r[1] & 0x38) >> 3;
-                        temporal_reference = (int)r[0] << 2 | r[1] >> 6;
-                    }
-                    if (start_code == 0x1B8) {
-                        begin_of_sequence = 1;
-                    }
-
-                    if (r - buf1 - 4 <= len) {
-                        /* The current slice fits in the packet */
-                        if (begin_of_slice == 0) {
-                            /* no slice at the beginning of the packet... */
-                            end_of_slice = 1;
-                            len = r - buf1 - 4;
-                            break;
-                        }
-                        r1 = r;
-                    } else {
-                        if ((r1 - buf1 > 4) && (r - r1 < max_packet_size)) {
-                            len = r1 - buf1 - 4;
-                            end_of_slice = 1;
-                        }
-                        break;
-                    }
-                } else {
-                    break;
-                }
-            }
-        }
-
-        h = 0;
-        h |= temporal_reference << 16;
-        h |= begin_of_sequence << 13;
-        h |= begin_of_slice << 12;
-        h |= end_of_slice << 11;
-        h |= frame_type << 8;
-
-        q = s->buf;
-        *q++ = h >> 24;
-        *q++ = h >> 16;
-        *q++ = h >> 8;
-        *q++ = h;
-
-        memcpy(q, buf1, len);
-        q += len;
-
-        /* 90kHz time stamp */
-        s->timestamp = s->cur_timestamp;
-        ff_rtp_send_data(s1, s->buf, q - s->buf, (len == size));
-
-        buf1 += len;
-        size -= len;
-        begin_of_slice = end_of_slice;
-        end_of_slice = 0;
-    }
-}
-
-
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/rtpenc_aac.c	Mon Jan 18 13:44:12 2010 +0000
@@ -0,0 +1,85 @@
+/*
+ * copyright (c) 2007 Luca Abeni
+ *
+ * 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
+ */
+
+#include "avformat.h"
+#include "rtpenc.h"
+
+
+void ff_rtp_send_aac(AVFormatContext *s1, const uint8_t *buff, int size)
+{
+    RTPMuxContext *s = s1->priv_data;
+    int len, max_packet_size;
+    uint8_t *p;
+    const int max_frames_per_packet = s->max_frames_per_packet ? s->max_frames_per_packet : 5;
+    const int max_au_headers_size = 2 + 2 * max_frames_per_packet;
+
+    /* skip ADTS header, if present */
+    if ((s1->streams[0]->codec->extradata_size) == 0) {
+        size -= 7;
+        buff += 7;
+    }
+    max_packet_size = s->max_payload_size - max_au_headers_size;
+
+    /* test if the packet must be sent */
+    len = (s->buf_ptr - s->buf);
+    if ((s->num_frames == max_frames_per_packet) || (len && (len + size) > s->max_payload_size)) {
+        int au_size = s->num_frames * 2;
+
+        p = s->buf + max_au_headers_size - au_size - 2;
+        if (p != s->buf) {
+            memmove(p + 2, s->buf + 2, au_size);
+        }
+        /* Write the AU header size */
+        p[0] = ((au_size * 8) & 0xFF) >> 8;
+        p[1] = (au_size * 8) & 0xFF;
+
+        ff_rtp_send_data(s1, p, s->buf_ptr - p, 1);
+
+        s->num_frames = 0;
+    }
+    if (s->num_frames == 0) {
+        s->buf_ptr = s->buf + max_au_headers_size;
+        s->timestamp = s->cur_timestamp;
+    }
+
+    if (size <= max_packet_size) {
+        p = s->buf + s->num_frames++ * 2 + 2;
+        *p++ = size >> 5;
+        *p = (size & 0x1F) << 3;
+        memcpy(s->buf_ptr, buff, size);
+        s->buf_ptr += size;
+    } else {
+        int au_size = size;
+
+        max_packet_size = s->max_payload_size - 4;
+        p = s->buf;
+        p[0] = 0;
+        p[1] = 16;
+        while (size > 0) {
+            len = FFMIN(size, max_packet_size);
+            p[2] = au_size >> 5;
+            p[3] = (au_size & 0x1F) << 3;
+            memcpy(p + 4, buff, len);
+            ff_rtp_send_data(s1, p, len + 4, len == size);
+            size -= len;
+            buff += len;
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/rtpenc_amr.c	Mon Jan 18 13:44:12 2010 +0000
@@ -0,0 +1,66 @@
+/*
+ * RTP packetization for AMR audio
+ * Copyright (c) 2007 Luca Abeni
+ * Copyright (c) 2009 Martin Storsjo
+ *
+ * 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
+ */
+
+#include "avformat.h"
+#include "rtpenc.h"
+
+/**
+ * Packetize AMR frames into RTP packets according to RFC 3267,
+ * in octet-aligned mode.
+ */
+void ff_rtp_send_amr(AVFormatContext *s1, const uint8_t *buff, int size)
+{
+    RTPMuxContext *s          = s1->priv_data;
+    int max_header_toc_size   = 1 + s->max_frames_per_packet;
+    uint8_t *p;
+    int len;
+
+    /* Test if the packet must be sent. */
+    len = s->buf_ptr - s->buf;
+    if (s->num_frames == s->max_frames_per_packet || (len && len + size - 1 > s->max_payload_size)) {
+        int header_size = s->num_frames + 1;
+        p = s->buf + max_header_toc_size - header_size;
+        if (p != s->buf)
+            memmove(p, s->buf, header_size);
+
+        ff_rtp_send_data(s1, p, s->buf_ptr - p, 1);
+
+        s->num_frames = 0;
+    }
+
+    if (!s->num_frames) {
+        s->buf[0]    = 0xf0;
+        s->buf_ptr   = s->buf + max_header_toc_size;
+        s->timestamp = s->cur_timestamp;
+    } else {
+        /* Mark the previous TOC entry as having more entries following. */
+        s->buf[1 + s->num_frames - 1] |= 0x80;
+    }
+
+    /* Copy the frame type and quality bits. */
+    s->buf[1 + s->num_frames++] = buff[0] & 0x7C;
+    buff++;
+    size--;
+    memcpy(s->buf_ptr, buff, size);
+    s->buf_ptr += size;
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/rtpenc_h263.c	Mon Jan 18 13:44:12 2010 +0000
@@ -0,0 +1,80 @@
+/*
+ * RTP packetization for H.263 video
+ * Copyright (c) 2009 Luca Abeni
+ * Copyright (c) 2009 Martin Storsjo
+ *
+ * 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
+ */
+
+#include "avformat.h"
+#include "rtpenc.h"
+
+static const uint8_t *find_resync_marker_reverse(const uint8_t *restrict start,
+                                                 const uint8_t *restrict end)
+{
+    const uint8_t *p = end - 1;
+    start += 1; /* Make sure we never return the original start. */
+    for (; p > start; p -= 2) {
+        if (!*p) {
+            if      (!p[ 1] && p[2]) return p;
+            else if (!p[-1] && p[1]) return p - 1;
+        }
+    }
+    return end;
+}
+
+/**
+ * Packetize H.263 frames into RTP packets according to RFC 4629
+ */
+void ff_rtp_send_h263(AVFormatContext *s1, const uint8_t *buf1, int size)
+{
+    RTPMuxContext *s = s1->priv_data;
+    int len, max_packet_size;
+    uint8_t *q;
+
+    max_packet_size = s->max_payload_size;
+
+    while (size > 0) {
+        q = s->buf;
+        if ((buf1[0] == 0) && (buf1[1] == 0)) {
+            *q++ = 0x04;
+            buf1 += 2;
+            size -= 2;
+        } else {
+            *q++ = 0;
+        }
+        *q++ = 0;
+
+        len = FFMIN(max_packet_size - 2, size);
+
+        /* Look for a better place to split the frame into packets. */
+        if (len < size) {
+            const uint8_t *end = find_resync_marker_reverse(buf1, buf1 + len);
+            len = end - buf1;
+        }
+
+        memcpy(q, buf1, len);
+        q += len;
+
+        /* 90 KHz time stamp */
+        s->timestamp = s->cur_timestamp;
+        ff_rtp_send_data(s1, s->buf, q - s->buf, (len == size));
+
+        buf1 += len;
+        size -= len;
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/rtpenc_mpv.c	Mon Jan 18 13:44:12 2010 +0000
@@ -0,0 +1,119 @@
+/*
+ * RTP packetization for MPEG video
+ * Copyright (c) 2002 Fabrice Bellard
+ * Copyright (c) 2007 Luca Abeni
+ *
+ * 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
+ */
+
+#include "libavcodec/mpegvideo.h"
+#include "avformat.h"
+#include "rtpenc.h"
+
+/* NOTE: a single frame must be passed with sequence header if
+   needed. XXX: use slices. */
+void ff_rtp_send_mpegvideo(AVFormatContext *s1, const uint8_t *buf1, int size)
+{
+    RTPMuxContext *s = s1->priv_data;
+    int len, h, max_packet_size;
+    uint8_t *q;
+    const uint8_t *end = buf1 + size;
+    int begin_of_slice, end_of_slice, frame_type, temporal_reference;
+
+    max_packet_size = s->max_payload_size;
+    begin_of_slice = 1;
+    end_of_slice = 0;
+    frame_type = 0;
+    temporal_reference = 0;
+
+    while (size > 0) {
+        int begin_of_sequence;
+
+        begin_of_sequence = 0;
+        len = max_packet_size - 4;
+
+        if (len >= size) {
+            len = size;
+            end_of_slice = 1;
+        } else {
+            const uint8_t *r, *r1;
+            int start_code;
+
+            r1 = buf1;
+            while (1) {
+                start_code = -1;
+                r = ff_find_start_code(r1, end, &start_code);
+                if((start_code & 0xFFFFFF00) == 0x100) {
+                    /* New start code found */
+                    if (start_code == 0x100) {
+                        frame_type = (r[1] & 0x38) >> 3;
+                        temporal_reference = (int)r[0] << 2 | r[1] >> 6;
+                    }
+                    if (start_code == 0x1B8) {
+                        begin_of_sequence = 1;
+                    }
+
+                    if (r - buf1 - 4 <= len) {
+                        /* The current slice fits in the packet */
+                        if (begin_of_slice == 0) {
+                            /* no slice at the beginning of the packet... */
+                            end_of_slice = 1;
+                            len = r - buf1 - 4;
+                            break;
+                        }
+                        r1 = r;
+                    } else {
+                        if ((r1 - buf1 > 4) && (r - r1 < max_packet_size)) {
+                            len = r1 - buf1 - 4;
+                            end_of_slice = 1;
+                        }
+                        break;
+                    }
+                } else {
+                    break;
+                }
+            }
+        }
+
+        h = 0;
+        h |= temporal_reference << 16;
+        h |= begin_of_sequence << 13;
+        h |= begin_of_slice << 12;
+        h |= end_of_slice << 11;
+        h |= frame_type << 8;
+
+        q = s->buf;
+        *q++ = h >> 24;
+        *q++ = h >> 16;
+        *q++ = h >> 8;
+        *q++ = h;
+
+        memcpy(q, buf1, len);
+        q += len;
+
+        /* 90kHz time stamp */
+        s->timestamp = s->cur_timestamp;
+        ff_rtp_send_data(s1, s->buf, q - s->buf, (len == size));
+
+        buf1 += len;
+        size -= len;
+        begin_of_slice = end_of_slice;
+        end_of_slice = 0;
+    }
+}
+
+