summaryrefslogtreecommitdiff
path: root/libavformat/rtpenc_aac.c
diff options
context:
space:
mode:
authorLuca Abeni <lucabe72@email.it>2010-01-18 13:44:12 +0000
committerLuca Abeni <lucabe72@email.it>2010-01-18 13:44:12 +0000
commit22c1f65fa6d03995be96c107a5bd3b9ee7e54cab (patch)
tree98f9f3ca0f82cd72dfeef3ae358d37e0ecf61761 /libavformat/rtpenc_aac.c
parentb6ef858ec711b077085dddfb6c4acb151a4ec5be (diff)
Rename the RTP muxer sources so that the packetisation functions are in
rtpenc_*.c files. Originally committed as revision 21284 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavformat/rtpenc_aac.c')
-rw-r--r--libavformat/rtpenc_aac.c85
1 files changed, 85 insertions, 0 deletions
diff --git a/libavformat/rtpenc_aac.c b/libavformat/rtpenc_aac.c
new file mode 100644
index 0000000000..e19b28697e
--- /dev/null
+++ b/libavformat/rtpenc_aac.c
@@ -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;
+ }
+ }
+}