annotate rtp_aac.c @ 3811:0daa9773c9c3 libavformat

cosmetics
author bcoudurier
date Sat, 30 Aug 2008 22:45:49 +0000
parents d751acab2622
children f49e5d92ab26
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
2587
d751acab2622 Allow to set the maximum number of frames per RTP packet (and add support for
lucabe
parents: 2551
diff changeset
25 #define MAX_FRAMES_PER_PACKET (s->max_frames_per_packet ? s->max_frames_per_packet : 5)
2550
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 {
2551
be9b08eba612 Support fragmentation for AAC frames
lucabe
parents: 2550
diff changeset
70 if (s->buf_ptr != s->buf + MAX_AU_HEADERS_SIZE) {
be9b08eba612 Support fragmentation for AAC frames
lucabe
parents: 2550
diff changeset
71 av_log(s1, AV_LOG_ERROR, "Strange...\n");
be9b08eba612 Support fragmentation for AAC frames
lucabe
parents: 2550
diff changeset
72 av_abort();
be9b08eba612 Support fragmentation for AAC frames
lucabe
parents: 2550
diff changeset
73 }
be9b08eba612 Support fragmentation for AAC frames
lucabe
parents: 2550
diff changeset
74 max_packet_size = s->max_payload_size - 4;
be9b08eba612 Support fragmentation for AAC frames
lucabe
parents: 2550
diff changeset
75 p = s->buf;
be9b08eba612 Support fragmentation for AAC frames
lucabe
parents: 2550
diff changeset
76 p[0] = 0;
be9b08eba612 Support fragmentation for AAC frames
lucabe
parents: 2550
diff changeset
77 p[1] = 16;
be9b08eba612 Support fragmentation for AAC frames
lucabe
parents: 2550
diff changeset
78 while (size > 0) {
be9b08eba612 Support fragmentation for AAC frames
lucabe
parents: 2550
diff changeset
79 len = FFMIN(size, max_packet_size);
be9b08eba612 Support fragmentation for AAC frames
lucabe
parents: 2550
diff changeset
80 p[2] = len >> 5;
be9b08eba612 Support fragmentation for AAC frames
lucabe
parents: 2550
diff changeset
81 p[3] = (size & 0x1F) << 3;
be9b08eba612 Support fragmentation for AAC frames
lucabe
parents: 2550
diff changeset
82 memcpy(p + 4, buff, len);
be9b08eba612 Support fragmentation for AAC frames
lucabe
parents: 2550
diff changeset
83 ff_rtp_send_data(s1, p, len + 4, len == size);
be9b08eba612 Support fragmentation for AAC frames
lucabe
parents: 2550
diff changeset
84 size -= len;
be9b08eba612 Support fragmentation for AAC frames
lucabe
parents: 2550
diff changeset
85 buff += len;
be9b08eba612 Support fragmentation for AAC frames
lucabe
parents: 2550
diff changeset
86 }
2550
e9c34ec665c6 Support for AAC streaming over RTP. Fragmentation is not implemented yet
lucabe
parents:
diff changeset
87 }
e9c34ec665c6 Support for AAC streaming over RTP. Fragmentation is not implemented yet
lucabe
parents:
diff changeset
88 }