Browse code

Support for AAC streaming over RTP. Fragmentation is not implemented yet

Originally committed as revision 10491 to svn://svn.ffmpeg.org/ffmpeg/trunk

Luca Abeni authored on 2007/09/14 17:17:06
Showing 4 changed files
... ...
@@ -122,7 +122,7 @@ OBJS-$(CONFIG_RM_DEMUXER)                += rmdec.o
122 122
 OBJS-$(CONFIG_RM_MUXER)                  += rmenc.o
123 123
 OBJS-$(CONFIG_ROQ_DEMUXER)               += idroq.o
124 124
 OBJS-$(CONFIG_ROQ_MUXER)                 += raw.o
125
-OBJS-$(CONFIG_RTP_MUXER)                 += rtp.o rtp_h264.o rtp_mpv.o
125
+OBJS-$(CONFIG_RTP_MUXER)                 += rtp.o rtp_h264.o rtp_mpv.o rtp_aac.o
126 126
 OBJS-$(CONFIG_RTSP_DEMUXER)              += rtsp.o
127 127
 OBJS-$(CONFIG_SDP_DEMUXER)               += rtsp.o
128 128
 OBJS-$(CONFIG_SEGAFILM_DEMUXER)          += segafilm.o
... ...
@@ -28,6 +28,7 @@
28 28
 #include "rtp_internal.h"
29 29
 #include "rtp_h264.h"
30 30
 #include "rtp_mpv.h"
31
+#include "rtp_aac.h"
31 32
 
32 33
 //#define DEBUG
33 34
 
... ...
@@ -762,6 +763,8 @@ static int rtp_write_header(AVFormatContext *s1)
762 762
         s->max_payload_size = n * TS_PACKET_SIZE;
763 763
         s->buf_ptr = s->buf;
764 764
         break;
765
+    case CODEC_ID_AAC:
766
+        s->read_buf_index = 0;
765 767
     default:
766 768
         if (st->codec->codec_type == CODEC_TYPE_AUDIO) {
767 769
             av_set_pts_info(st, 32, 1, st->codec->sample_rate);
... ...
@@ -993,6 +996,9 @@ static int rtp_write_packet(AVFormatContext *s1, AVPacket *pkt)
993 993
     case CODEC_ID_MPEG1VIDEO:
994 994
         ff_rtp_send_mpegvideo(s1, buf1, size);
995 995
         break;
996
+    case CODEC_ID_AAC:
997
+        ff_rtp_send_aac(s1, buf1, size);
998
+        break;
996 999
     case CODEC_ID_MPEG2TS:
997 1000
         rtp_send_mpegts_raw(s1, buf1, size);
998 1001
         break;
999 1002
new file mode 100644
... ...
@@ -0,0 +1,72 @@
0
+/*
1
+ * copyright (c) 2007 Luca Abeni
2
+ *
3
+ * This file is part of FFmpeg.
4
+ *
5
+ * FFmpeg is free software; you can redistribute it and/or
6
+ * modify it under the terms of the GNU Lesser General Public
7
+ * License as published by the Free Software Foundation; either
8
+ * version 2.1 of the License, or (at your option) any later version.
9
+ *
10
+ * FFmpeg is distributed in the hope that it will be useful,
11
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
+ * Lesser General Public License for more details.
14
+ *
15
+ * You should have received a copy of the GNU Lesser General Public
16
+ * License along with FFmpeg; if not, write to the Free Software
17
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
+ */
19
+
20
+#include "avformat.h"
21
+#include "rtp_aac.h"
22
+#include "rtp_internal.h"
23
+
24
+#define MAX_FRAMES_PER_PACKET 5
25
+#define MAX_AU_HEADERS_SIZE (2 + 2 * MAX_FRAMES_PER_PACKET)
26
+
27
+void ff_rtp_send_aac(AVFormatContext *s1, const uint8_t *buff, int size)
28
+{
29
+    RTPDemuxContext *s = s1->priv_data;
30
+    int len, max_packet_size;
31
+    uint8_t *p;
32
+
33
+    /* skip ADTS header, if present */
34
+    if ((s1->streams[0]->codec->extradata_size) == 0) {
35
+        size -= 7;
36
+        buff += 7;
37
+    }
38
+    max_packet_size = s->max_payload_size - MAX_AU_HEADERS_SIZE;
39
+
40
+    /* test if the packet must be sent */
41
+    len = (s->buf_ptr - s->buf);
42
+    if ((s->read_buf_index == MAX_FRAMES_PER_PACKET) || (len && (len + size) > max_packet_size)) {
43
+        int au_size = s->read_buf_index * 2;
44
+
45
+        p = s->buf + MAX_AU_HEADERS_SIZE - au_size - 2;
46
+        if (p != s->buf) {
47
+            memmove(p + 2, s->buf + 2, au_size);
48
+        }
49
+        /* Write the AU header size */
50
+        p[0] = ((au_size * 8) & 0xFF) >> 8;
51
+        p[1] = (au_size * 8) & 0xFF;
52
+
53
+        ff_rtp_send_data(s1, p, s->buf_ptr - p, 1);
54
+
55
+        s->read_buf_index = 0;
56
+    }
57
+    if (s->read_buf_index == 0) {
58
+        s->buf_ptr = s->buf + MAX_AU_HEADERS_SIZE;
59
+        s->timestamp = s->cur_timestamp;
60
+    }
61
+
62
+    if (size < max_packet_size) {
63
+        p = s->buf + s->read_buf_index++ * 2 + 2;
64
+        *p++ = size >> 5;
65
+        *p = (size & 0x1F) << 3;
66
+        memcpy(s->buf_ptr, buff, size);
67
+        s->buf_ptr += size;
68
+    } else {
69
+        av_log(s1, AV_LOG_ERROR, "Unsupported!\n");
70
+    }
71
+}
0 72
new file mode 100644
... ...
@@ -0,0 +1,25 @@
0
+/*
1
+ * RTP definitions
2
+ *
3
+ * This file is part of FFmpeg.
4
+ *
5
+ * FFmpeg is free software; you can redistribute it and/or
6
+ * modify it under the terms of the GNU Lesser General Public
7
+ * License as published by the Free Software Foundation; either
8
+ * version 2.1 of the License, or (at your option) any later version.
9
+ *
10
+ * FFmpeg is distributed in the hope that it will be useful,
11
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
+ * Lesser General Public License for more details.
14
+ *
15
+ * You should have received a copy of the GNU Lesser General Public
16
+ * License along with FFmpeg; if not, write to the Free Software
17
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
+ */
19
+#ifndef RTP_AAC_H
20
+#define RTP_AAC_H
21
+
22
+void ff_rtp_send_aac(AVFormatContext *s1, const uint8_t *buff, int size);
23
+
24
+#endif /* RTP_AAC_H */