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
25
28
36 };
37
39 {
42 }
43
45 const uint8_t *buf,
int len,
46 unsigned *adu_size, unsigned *cont)
47 {
48 unsigned header_size;
49
53 }
54
55 *cont = !!(buf[0] & 0x80);
56 if (!(buf[0] & 0x40)) {
57 header_size = 1;
58 *adu_size = buf[0] & ~0xc0;
59 } else {
60 header_size = 2;
61 *adu_size =
AV_RB16(buf) & ~0xc000;
62 }
63
64 return header_size;
65 }
66
69 uint32_t *timestamp, const uint8_t *buf,
71 {
72 unsigned adu_size, continuation;
73 int err, header_size;
74
75 if (!buf) {
76 buf = &
data->split_buf[
data->split_pos];
78
80 &continuation);
81 if (header_size < 0) {
83 return header_size;
84 }
85 buf += header_size;
87
88 if (continuation || adu_size >
len) {
92 }
93
96 return err;
97 }
98
100 memcpy(
pkt->
data, buf, adu_size);
101
102 data->split_pos += header_size + adu_size;
103
104 if (
data->split_pos ==
data->split_buf_size) {
106 return 0;
107 }
108
109 return 1;
110 }
111
112
114 &continuation);
115 if (header_size < 0)
116 return header_size;
117
118 buf += header_size;
120
121 if (!continuation && adu_size <=
len) {
122 /* One or more complete frames */
123
126 return err;
127 }
128
130 memcpy(
pkt->
data, buf, adu_size);
131
132 buf += adu_size;
138 if (!
data->split_buf) {
142 }
143 memcpy(
data->split_buf, buf,
data->split_buf_size);
144 return 1;
145 }
146 return 0;
147 } else if (!continuation) { /* && adu_size > len */
148 /* First fragment */
150
151 data->adu_size = adu_size;
153 data->timestamp = *timestamp;
154
156 if (err < 0)
157 return err;
158
161 }
162 /* else continuation == 1 */
163
164 /* Fragment other than first */
165 if (!
data->fragment) {
167 "Received packet without a start fragment; dropping.\n");
169 }
170 if (adu_size !=
data->adu_size ||
171 data->timestamp != *timestamp) {
175 }
176
179
180 if (
data->cur_size <
data->adu_size)
182
184 if (err < 0) {
186 "Error occurred when getting fragment buffer.\n");
187 return err;
188 }
189
190 return 0;
191 }
192
201 };