1 /*
2 * copyright (c) 2007 Luca Abeni
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
22
25
26
28 {
31 const int max_au_headers_size = 2 + 2 *
s->max_frames_per_packet;
32 int len, max_packet_size =
s->max_payload_size - max_au_headers_size;
33 uint8_t *p;
34
35 /* skip ADTS header, if present */
36 if ((
s1->streams[0]->codecpar->extradata_size) == 0) {
38 buff += 7;
39 }
40
41 /* test if the packet must be sent */
42 len = (
s->buf_ptr -
s->buf);
44 (
s->num_frames ==
s->max_frames_per_packet ||
45 (
len +
size) >
s->max_payload_size ||
48 int au_size =
s->num_frames * 2;
49
50 p =
s->buf + max_au_headers_size - au_size - 2;
52 memmove(p + 2,
s->buf + 2, au_size);
53 }
54 /* Write the AU header size */
56
58
60 }
61 if (
s->num_frames == 0) {
62 s->buf_ptr =
s->buf + max_au_headers_size;
63 s->timestamp =
s->cur_timestamp;
64 }
65
66 if (
size <= max_packet_size) {
67 p =
s->buf +
s->num_frames++ * 2 + 2;
69 memcpy(
s->buf_ptr, buff,
size);
71 } else {
73
74 max_packet_size =
s->max_payload_size - 4;
80 memcpy(p + 4, buff,
len);
84 }
85 }
86 }