1 /*
2 * RTP parser for loss tolerant payload format for MP3 audio (RFC 5219)
3 * Copyright (c) 2015 Gilles Chanteperdrix <gch@xenomai.org>
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
24
27
35 };
36
38 {
41 }
42
44 const uint8_t *buf,
int len,
45 unsigned *adu_size, unsigned *cont)
46 {
47 unsigned header_size;
48
52 }
53
54 *cont = !!(buf[0] & 0x80);
55 if (!(buf[0] & 0x40)) {
56 header_size = 1;
57 *adu_size = buf[0] & ~0xc0;
58 } else {
59 header_size = 2;
60 *adu_size =
AV_RB16(buf) & ~0xc000;
61 }
62
63 return header_size;
64 }
65
68 uint32_t *timestamp, const uint8_t *buf,
70 {
71 unsigned adu_size, continuation;
72 int err, header_size;
73
74 if (!buf) {
75 buf = &
data->split_buf[
data->split_pos];
77
79 &continuation);
80 if (header_size < 0) {
82 return header_size;
83 }
84 buf += header_size;
86
87 if (continuation || adu_size >
len) {
91 }
92
95 return err;
96 }
97
99 memcpy(
pkt->
data, buf, adu_size);
100
101 data->split_pos += header_size + adu_size;
102
103 if (
data->split_pos ==
data->split_buf_size) {
105 return 0;
106 }
107
108 return 1;
109 }
110
111
113 &continuation);
114 if (header_size < 0)
115 return header_size;
116
117 buf += header_size;
119
120 if (!continuation && adu_size <=
len) {
121 /* One or more complete frames */
122
125 return err;
126 }
127
129 memcpy(
pkt->
data, buf, adu_size);
130
131 buf += adu_size;
137 if (!
data->split_buf) {
141 }
142 memcpy(
data->split_buf, buf,
data->split_buf_size);
143 return 1;
144 }
145 return 0;
146 } else if (!continuation) { /* && adu_size > len */
147 /* First fragment */
149
150 data->adu_size = adu_size;
152 data->timestamp = *timestamp;
153
155 if (err < 0)
156 return err;
157
160 }
161 /* else continuation == 1 */
162
163 /* Fragment other than first */
164 if (!
data->fragment) {
166 "Received packet without a start fragment; dropping.\n");
168 }
169 if (adu_size !=
data->adu_size ||
170 data->timestamp != *timestamp) {
174 }
175
178
179 if (
data->cur_size <
data->adu_size)
181
183 if (err < 0) {
185 "Error occurred when getting fragment buffer.\n");
186 return err;
187 }
188
189 return 0;
190 }
191
200 };