Mercurial > libavformat.hg
annotate rtp_aac.c @ 5009:822a36d7ac0a libavformat
Cosmetics : Use dprintf instead of printf.
Patch by Peter Holik < $firstname @ $lastname . at >
author | jai_menon |
---|---|
date | Sat, 06 Jun 2009 17:32:59 +0000 |
parents | 04c546a9a3fd |
children |
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 |
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 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
|
26 { |
4388 | 27 RTPMuxContext *s = s1->priv_data; |
2550
e9c34ec665c6
Support for AAC streaming over RTP. Fragmentation is not implemented yet
lucabe
parents:
diff
changeset
|
28 int len, max_packet_size; |
e9c34ec665c6
Support for AAC streaming over RTP. Fragmentation is not implemented yet
lucabe
parents:
diff
changeset
|
29 uint8_t *p; |
4843
744f14413d22
AAC packetiser cleanup: use consts instead of #defines
lucabe
parents:
4842
diff
changeset
|
30 const int max_frames_per_packet = s->max_frames_per_packet ? s->max_frames_per_packet : 5; |
744f14413d22
AAC packetiser cleanup: use consts instead of #defines
lucabe
parents:
4842
diff
changeset
|
31 const int max_au_headers_size = 2 + 2 * max_frames_per_packet; |
2550
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 } |
4843
744f14413d22
AAC packetiser cleanup: use consts instead of #defines
lucabe
parents:
4842
diff
changeset
|
38 max_packet_size = s->max_payload_size - max_au_headers_size; |
2550
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); |
4843
744f14413d22
AAC packetiser cleanup: use consts instead of #defines
lucabe
parents:
4842
diff
changeset
|
42 if ((s->num_frames == max_frames_per_packet) || (len && (len + size) > s->max_payload_size)) { |
4380
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 |
4843
744f14413d22
AAC packetiser cleanup: use consts instead of #defines
lucabe
parents:
4842
diff
changeset
|
45 p = s->buf + max_au_headers_size - au_size - 2; |
2550
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) { |
4843
744f14413d22
AAC packetiser cleanup: use consts instead of #defines
lucabe
parents:
4842
diff
changeset
|
58 s->buf_ptr = s->buf + max_au_headers_size; |
2550
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 |
4841
94eb88d4ac0f
Fix two checks in the AAC packetiser, which were too conservative
lucabe
parents:
4389
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 { |
4970
04c546a9a3fd
Correctly set the "AU size" field in the payload header for
lucabe
parents:
4843
diff
changeset
|
69 int au_size = size; |
04c546a9a3fd
Correctly set the "AU size" field in the payload header for
lucabe
parents:
4843
diff
changeset
|
70 |
2551 | 71 max_packet_size = s->max_payload_size - 4; |
72 p = s->buf; | |
73 p[0] = 0; | |
74 p[1] = 16; | |
75 while (size > 0) { | |
76 len = FFMIN(size, max_packet_size); | |
4970
04c546a9a3fd
Correctly set the "AU size" field in the payload header for
lucabe
parents:
4843
diff
changeset
|
77 p[2] = au_size >> 5; |
04c546a9a3fd
Correctly set the "AU size" field in the payload header for
lucabe
parents:
4843
diff
changeset
|
78 p[3] = (au_size & 0x1F) << 3; |
2551 | 79 memcpy(p + 4, buff, len); |
80 ff_rtp_send_data(s1, p, len + 4, len == size); | |
81 size -= len; | |
82 buff += len; | |
83 } | |
2550
e9c34ec665c6
Support for AAC streaming over RTP. Fragmentation is not implemented yet
lucabe
parents:
diff
changeset
|
84 } |
e9c34ec665c6
Support for AAC streaming over RTP. Fragmentation is not implemented yet
lucabe
parents:
diff
changeset
|
85 } |