annotate rtp_aac.c @ 2550:e9c34ec665c6 libavformat

Support for AAC streaming over RTP. Fragmentation is not implemented yet
author lucabe
date Fri, 14 Sep 2007 08:17:06 +0000
parents
children be9b08eba612
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2550
e9c34ec665c6 Support for AAC streaming over RTP. Fragmentation is not implemented yet
lucabe
parents:
diff changeset
1 /*
e9c34ec665c6 Support for AAC streaming over RTP. Fragmentation is not implemented yet
lucabe
parents:
diff changeset
2 * copyright (c) 2007 Luca Abeni
e9c34ec665c6 Support for AAC streaming over RTP. Fragmentation is not implemented yet
lucabe
parents:
diff changeset
3 *
e9c34ec665c6 Support for AAC streaming over RTP. Fragmentation is not implemented yet
lucabe
parents:
diff changeset
4 * This file is part of FFmpeg.
e9c34ec665c6 Support for AAC streaming over RTP. Fragmentation is not implemented yet
lucabe
parents:
diff changeset
5 *
e9c34ec665c6 Support for AAC streaming over RTP. Fragmentation is not implemented yet
lucabe
parents:
diff changeset
6 * FFmpeg is free software; you can redistribute it and/or
e9c34ec665c6 Support for AAC streaming over RTP. Fragmentation is not implemented yet
lucabe
parents:
diff changeset
7 * modify it under the terms of the GNU Lesser General Public
e9c34ec665c6 Support for AAC streaming over RTP. Fragmentation is not implemented yet
lucabe
parents:
diff changeset
8 * License as published by the Free Software Foundation; either
e9c34ec665c6 Support for AAC streaming over RTP. Fragmentation is not implemented yet
lucabe
parents:
diff changeset
9 * version 2.1 of the License, or (at your option) any later version.
e9c34ec665c6 Support for AAC streaming over RTP. Fragmentation is not implemented yet
lucabe
parents:
diff changeset
10 *
e9c34ec665c6 Support for AAC streaming over RTP. Fragmentation is not implemented yet
lucabe
parents:
diff changeset
11 * FFmpeg is distributed in the hope that it will be useful,
e9c34ec665c6 Support for AAC streaming over RTP. Fragmentation is not implemented yet
lucabe
parents:
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
e9c34ec665c6 Support for AAC streaming over RTP. Fragmentation is not implemented yet
lucabe
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
e9c34ec665c6 Support for AAC streaming over RTP. Fragmentation is not implemented yet
lucabe
parents:
diff changeset
14 * Lesser General Public License for more details.
e9c34ec665c6 Support for AAC streaming over RTP. Fragmentation is not implemented yet
lucabe
parents:
diff changeset
15 *
e9c34ec665c6 Support for AAC streaming over RTP. Fragmentation is not implemented yet
lucabe
parents:
diff changeset
16 * You should have received a copy of the GNU Lesser General Public
e9c34ec665c6 Support for AAC streaming over RTP. Fragmentation is not implemented yet
lucabe
parents:
diff changeset
17 * License along with FFmpeg; if not, write to the Free Software
e9c34ec665c6 Support for AAC streaming over RTP. Fragmentation is not implemented yet
lucabe
parents:
diff changeset
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
e9c34ec665c6 Support for AAC streaming over RTP. Fragmentation is not implemented yet
lucabe
parents:
diff changeset
19 */
e9c34ec665c6 Support for AAC streaming over RTP. Fragmentation is not implemented yet
lucabe
parents:
diff changeset
20
e9c34ec665c6 Support for AAC streaming over RTP. Fragmentation is not implemented yet
lucabe
parents:
diff changeset
21 #include "avformat.h"
e9c34ec665c6 Support for AAC streaming over RTP. Fragmentation is not implemented yet
lucabe
parents:
diff changeset
22 #include "rtp_aac.h"
e9c34ec665c6 Support for AAC streaming over RTP. Fragmentation is not implemented yet
lucabe
parents:
diff changeset
23 #include "rtp_internal.h"
e9c34ec665c6 Support for AAC streaming over RTP. Fragmentation is not implemented yet
lucabe
parents:
diff changeset
24
e9c34ec665c6 Support for AAC streaming over RTP. Fragmentation is not implemented yet
lucabe
parents:
diff changeset
25 #define MAX_FRAMES_PER_PACKET 5
e9c34ec665c6 Support for AAC streaming over RTP. Fragmentation is not implemented yet
lucabe
parents:
diff changeset
26 #define MAX_AU_HEADERS_SIZE (2 + 2 * MAX_FRAMES_PER_PACKET)
e9c34ec665c6 Support for AAC streaming over RTP. Fragmentation is not implemented yet
lucabe
parents:
diff changeset
27
e9c34ec665c6 Support for AAC streaming over RTP. Fragmentation is not implemented yet
lucabe
parents:
diff changeset
28 void ff_rtp_send_aac(AVFormatContext *s1, const uint8_t *buff, int size)
e9c34ec665c6 Support for AAC streaming over RTP. Fragmentation is not implemented yet
lucabe
parents:
diff changeset
29 {
e9c34ec665c6 Support for AAC streaming over RTP. Fragmentation is not implemented yet
lucabe
parents:
diff changeset
30 RTPDemuxContext *s = s1->priv_data;
e9c34ec665c6 Support for AAC streaming over RTP. Fragmentation is not implemented yet
lucabe
parents:
diff changeset
31 int len, max_packet_size;
e9c34ec665c6 Support for AAC streaming over RTP. Fragmentation is not implemented yet
lucabe
parents:
diff changeset
32 uint8_t *p;
e9c34ec665c6 Support for AAC streaming over RTP. Fragmentation is not implemented yet
lucabe
parents:
diff changeset
33
e9c34ec665c6 Support for AAC streaming over RTP. Fragmentation is not implemented yet
lucabe
parents:
diff changeset
34 /* skip ADTS header, if present */
e9c34ec665c6 Support for AAC streaming over RTP. Fragmentation is not implemented yet
lucabe
parents:
diff changeset
35 if ((s1->streams[0]->codec->extradata_size) == 0) {
e9c34ec665c6 Support for AAC streaming over RTP. Fragmentation is not implemented yet
lucabe
parents:
diff changeset
36 size -= 7;
e9c34ec665c6 Support for AAC streaming over RTP. Fragmentation is not implemented yet
lucabe
parents:
diff changeset
37 buff += 7;
e9c34ec665c6 Support for AAC streaming over RTP. Fragmentation is not implemented yet
lucabe
parents:
diff changeset
38 }
e9c34ec665c6 Support for AAC streaming over RTP. Fragmentation is not implemented yet
lucabe
parents:
diff changeset
39 max_packet_size = s->max_payload_size - MAX_AU_HEADERS_SIZE;
e9c34ec665c6 Support for AAC streaming over RTP. Fragmentation is not implemented yet
lucabe
parents:
diff changeset
40
e9c34ec665c6 Support for AAC streaming over RTP. Fragmentation is not implemented yet
lucabe
parents:
diff changeset
41 /* test if the packet must be sent */
e9c34ec665c6 Support for AAC streaming over RTP. Fragmentation is not implemented yet
lucabe
parents:
diff changeset
42 len = (s->buf_ptr - s->buf);
e9c34ec665c6 Support for AAC streaming over RTP. Fragmentation is not implemented yet
lucabe
parents:
diff changeset
43 if ((s->read_buf_index == MAX_FRAMES_PER_PACKET) || (len && (len + size) > max_packet_size)) {
e9c34ec665c6 Support for AAC streaming over RTP. Fragmentation is not implemented yet
lucabe
parents:
diff changeset
44 int au_size = s->read_buf_index * 2;
e9c34ec665c6 Support for AAC streaming over RTP. Fragmentation is not implemented yet
lucabe
parents:
diff changeset
45
e9c34ec665c6 Support for AAC streaming over RTP. Fragmentation is not implemented yet
lucabe
parents:
diff changeset
46 p = s->buf + MAX_AU_HEADERS_SIZE - au_size - 2;
e9c34ec665c6 Support for AAC streaming over RTP. Fragmentation is not implemented yet
lucabe
parents:
diff changeset
47 if (p != s->buf) {
e9c34ec665c6 Support for AAC streaming over RTP. Fragmentation is not implemented yet
lucabe
parents:
diff changeset
48 memmove(p + 2, s->buf + 2, au_size);
e9c34ec665c6 Support for AAC streaming over RTP. Fragmentation is not implemented yet
lucabe
parents:
diff changeset
49 }
e9c34ec665c6 Support for AAC streaming over RTP. Fragmentation is not implemented yet
lucabe
parents:
diff changeset
50 /* Write the AU header size */
e9c34ec665c6 Support for AAC streaming over RTP. Fragmentation is not implemented yet
lucabe
parents:
diff changeset
51 p[0] = ((au_size * 8) & 0xFF) >> 8;
e9c34ec665c6 Support for AAC streaming over RTP. Fragmentation is not implemented yet
lucabe
parents:
diff changeset
52 p[1] = (au_size * 8) & 0xFF;
e9c34ec665c6 Support for AAC streaming over RTP. Fragmentation is not implemented yet
lucabe
parents:
diff changeset
53
e9c34ec665c6 Support for AAC streaming over RTP. Fragmentation is not implemented yet
lucabe
parents:
diff changeset
54 ff_rtp_send_data(s1, p, s->buf_ptr - p, 1);
e9c34ec665c6 Support for AAC streaming over RTP. Fragmentation is not implemented yet
lucabe
parents:
diff changeset
55
e9c34ec665c6 Support for AAC streaming over RTP. Fragmentation is not implemented yet
lucabe
parents:
diff changeset
56 s->read_buf_index = 0;
e9c34ec665c6 Support for AAC streaming over RTP. Fragmentation is not implemented yet
lucabe
parents:
diff changeset
57 }
e9c34ec665c6 Support for AAC streaming over RTP. Fragmentation is not implemented yet
lucabe
parents:
diff changeset
58 if (s->read_buf_index == 0) {
e9c34ec665c6 Support for AAC streaming over RTP. Fragmentation is not implemented yet
lucabe
parents:
diff changeset
59 s->buf_ptr = s->buf + MAX_AU_HEADERS_SIZE;
e9c34ec665c6 Support for AAC streaming over RTP. Fragmentation is not implemented yet
lucabe
parents:
diff changeset
60 s->timestamp = s->cur_timestamp;
e9c34ec665c6 Support for AAC streaming over RTP. Fragmentation is not implemented yet
lucabe
parents:
diff changeset
61 }
e9c34ec665c6 Support for AAC streaming over RTP. Fragmentation is not implemented yet
lucabe
parents:
diff changeset
62
e9c34ec665c6 Support for AAC streaming over RTP. Fragmentation is not implemented yet
lucabe
parents:
diff changeset
63 if (size < max_packet_size) {
e9c34ec665c6 Support for AAC streaming over RTP. Fragmentation is not implemented yet
lucabe
parents:
diff changeset
64 p = s->buf + s->read_buf_index++ * 2 + 2;
e9c34ec665c6 Support for AAC streaming over RTP. Fragmentation is not implemented yet
lucabe
parents:
diff changeset
65 *p++ = size >> 5;
e9c34ec665c6 Support for AAC streaming over RTP. Fragmentation is not implemented yet
lucabe
parents:
diff changeset
66 *p = (size & 0x1F) << 3;
e9c34ec665c6 Support for AAC streaming over RTP. Fragmentation is not implemented yet
lucabe
parents:
diff changeset
67 memcpy(s->buf_ptr, buff, size);
e9c34ec665c6 Support for AAC streaming over RTP. Fragmentation is not implemented yet
lucabe
parents:
diff changeset
68 s->buf_ptr += size;
e9c34ec665c6 Support for AAC streaming over RTP. Fragmentation is not implemented yet
lucabe
parents:
diff changeset
69 } else {
e9c34ec665c6 Support for AAC streaming over RTP. Fragmentation is not implemented yet
lucabe
parents:
diff changeset
70 av_log(s1, AV_LOG_ERROR, "Unsupported!\n");
e9c34ec665c6 Support for AAC streaming over RTP. Fragmentation is not implemented yet
lucabe
parents:
diff changeset
71 }
e9c34ec665c6 Support for AAC streaming over RTP. Fragmentation is not implemented yet
lucabe
parents:
diff changeset
72 }