Mercurial > libavformat.hg
annotate rtp_aac.c @ 4722:639c428c8b23 libavformat
typo in the mail, the 4am commit is always the worst
author | bcoudurier |
---|---|
date | Sun, 15 Mar 2009 10:53:12 +0000 |
parents | 25430a31705d |
children | 94eb88d4ac0f |
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" |
4388 | 22 #include "rtpenc.h" |
2550
e9c34ec665c6
Support for AAC streaming over RTP. Fragmentation is not implemented yet
lucabe
parents:
diff
changeset
|
23 |
2587
d751acab2622
Allow to set the maximum number of frames per RTP packet (and add support for
lucabe
parents:
2551
diff
changeset
|
24 #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
|
25 #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
|
26 |
e9c34ec665c6
Support for AAC streaming over RTP. Fragmentation is not implemented yet
lucabe
parents:
diff
changeset
|
27 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
|
28 { |
4388 | 29 RTPMuxContext *s = s1->priv_data; |
2550
e9c34ec665c6
Support for AAC streaming over RTP. Fragmentation is not implemented yet
lucabe
parents:
diff
changeset
|
30 int len, max_packet_size; |
e9c34ec665c6
Support for AAC streaming over RTP. Fragmentation is not implemented yet
lucabe
parents:
diff
changeset
|
31 uint8_t *p; |
e9c34ec665c6
Support for AAC streaming over RTP. Fragmentation is not implemented yet
lucabe
parents:
diff
changeset
|
32 |
e9c34ec665c6
Support for AAC streaming over RTP. Fragmentation is not implemented yet
lucabe
parents:
diff
changeset
|
33 /* skip ADTS header, if present */ |
e9c34ec665c6
Support for AAC streaming over RTP. Fragmentation is not implemented yet
lucabe
parents:
diff
changeset
|
34 if ((s1->streams[0]->codec->extradata_size) == 0) { |
e9c34ec665c6
Support for AAC streaming over RTP. Fragmentation is not implemented yet
lucabe
parents:
diff
changeset
|
35 size -= 7; |
e9c34ec665c6
Support for AAC streaming over RTP. Fragmentation is not implemented yet
lucabe
parents:
diff
changeset
|
36 buff += 7; |
e9c34ec665c6
Support for AAC streaming over RTP. Fragmentation is not implemented yet
lucabe
parents:
diff
changeset
|
37 } |
e9c34ec665c6
Support for AAC streaming over RTP. Fragmentation is not implemented yet
lucabe
parents:
diff
changeset
|
38 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
|
39 |
e9c34ec665c6
Support for AAC streaming over RTP. Fragmentation is not implemented yet
lucabe
parents:
diff
changeset
|
40 /* test if the packet must be sent */ |
e9c34ec665c6
Support for AAC streaming over RTP. Fragmentation is not implemented yet
lucabe
parents:
diff
changeset
|
41 len = (s->buf_ptr - s->buf); |
4380
1b695f013cd3
Introduce a new num_frames field in RTPDemuxContext so that rtp_aac.c
lucabe
parents:
4291
diff
changeset
|
42 if ((s->num_frames == MAX_FRAMES_PER_PACKET) || (len && (len + size) > max_packet_size)) { |
1b695f013cd3
Introduce a new num_frames field in RTPDemuxContext so that rtp_aac.c
lucabe
parents:
4291
diff
changeset
|
43 int au_size = s->num_frames * 2; |
2550
e9c34ec665c6
Support for AAC streaming over RTP. Fragmentation is not implemented yet
lucabe
parents:
diff
changeset
|
44 |
e9c34ec665c6
Support for AAC streaming over RTP. Fragmentation is not implemented yet
lucabe
parents:
diff
changeset
|
45 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
|
46 if (p != s->buf) { |
e9c34ec665c6
Support for AAC streaming over RTP. Fragmentation is not implemented yet
lucabe
parents:
diff
changeset
|
47 memmove(p + 2, s->buf + 2, au_size); |
e9c34ec665c6
Support for AAC streaming over RTP. Fragmentation is not implemented yet
lucabe
parents:
diff
changeset
|
48 } |
e9c34ec665c6
Support for AAC streaming over RTP. Fragmentation is not implemented yet
lucabe
parents:
diff
changeset
|
49 /* Write the AU header size */ |
e9c34ec665c6
Support for AAC streaming over RTP. Fragmentation is not implemented yet
lucabe
parents:
diff
changeset
|
50 p[0] = ((au_size * 8) & 0xFF) >> 8; |
e9c34ec665c6
Support for AAC streaming over RTP. Fragmentation is not implemented yet
lucabe
parents:
diff
changeset
|
51 p[1] = (au_size * 8) & 0xFF; |
e9c34ec665c6
Support for AAC streaming over RTP. Fragmentation is not implemented yet
lucabe
parents:
diff
changeset
|
52 |
e9c34ec665c6
Support for AAC streaming over RTP. Fragmentation is not implemented yet
lucabe
parents:
diff
changeset
|
53 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
|
54 |
4380
1b695f013cd3
Introduce a new num_frames field in RTPDemuxContext so that rtp_aac.c
lucabe
parents:
4291
diff
changeset
|
55 s->num_frames = 0; |
2550
e9c34ec665c6
Support for AAC streaming over RTP. Fragmentation is not implemented yet
lucabe
parents:
diff
changeset
|
56 } |
4380
1b695f013cd3
Introduce a new num_frames field in RTPDemuxContext so that rtp_aac.c
lucabe
parents:
4291
diff
changeset
|
57 if (s->num_frames == 0) { |
2550
e9c34ec665c6
Support for AAC streaming over RTP. Fragmentation is not implemented yet
lucabe
parents:
diff
changeset
|
58 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
|
59 s->timestamp = s->cur_timestamp; |
e9c34ec665c6
Support for AAC streaming over RTP. Fragmentation is not implemented yet
lucabe
parents:
diff
changeset
|
60 } |
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 if (size < max_packet_size) { |
4380
1b695f013cd3
Introduce a new num_frames field in RTPDemuxContext so that rtp_aac.c
lucabe
parents:
4291
diff
changeset
|
63 p = s->buf + s->num_frames++ * 2 + 2; |
2550
e9c34ec665c6
Support for AAC streaming over RTP. Fragmentation is not implemented yet
lucabe
parents:
diff
changeset
|
64 *p++ = size >> 5; |
e9c34ec665c6
Support for AAC streaming over RTP. Fragmentation is not implemented yet
lucabe
parents:
diff
changeset
|
65 *p = (size & 0x1F) << 3; |
e9c34ec665c6
Support for AAC streaming over RTP. Fragmentation is not implemented yet
lucabe
parents:
diff
changeset
|
66 memcpy(s->buf_ptr, buff, size); |
e9c34ec665c6
Support for AAC streaming over RTP. Fragmentation is not implemented yet
lucabe
parents:
diff
changeset
|
67 s->buf_ptr += size; |
e9c34ec665c6
Support for AAC streaming over RTP. Fragmentation is not implemented yet
lucabe
parents:
diff
changeset
|
68 } else { |
2551 | 69 if (s->buf_ptr != s->buf + MAX_AU_HEADERS_SIZE) { |
70 av_log(s1, AV_LOG_ERROR, "Strange...\n"); | |
71 av_abort(); | |
72 } | |
73 max_packet_size = s->max_payload_size - 4; | |
74 p = s->buf; | |
75 p[0] = 0; | |
76 p[1] = 16; | |
77 while (size > 0) { | |
78 len = FFMIN(size, max_packet_size); | |
79 p[2] = len >> 5; | |
80 p[3] = (size & 0x1F) << 3; | |
81 memcpy(p + 4, buff, len); | |
82 ff_rtp_send_data(s1, p, len + 4, len == size); | |
83 size -= len; | |
84 buff += len; | |
85 } | |
2550
e9c34ec665c6
Support for AAC streaming over RTP. Fragmentation is not implemented yet
lucabe
parents:
diff
changeset
|
86 } |
e9c34ec665c6
Support for AAC streaming over RTP. Fragmentation is not implemented yet
lucabe
parents:
diff
changeset
|
87 } |