1 /*
2 * RTP Depacketization of QCELP/PureVoice, RFC 2658
3 * Copyright (c) 2010 Martin Storsjo
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
23
25 1, 4, 8, 17, 35
26 };
27
31 /* The largest frame is 35 bytes, only 10 frames are allowed per
32 * packet, and we return the first one immediately, so allocate
33 * space for 9 frames */
36
42
43 /* The maximum packet size, 10 frames of 35 bytes each, and one
44 * packet header byte. */
48 };
49
51 {
53 }
54
56 {
58 }
59
63
67 {
68 int interleave_size, interleave_index;
71
72 if (len < 2)
74
75 interleave_size = buf[0] >> 3 & 7;
76 interleave_index = buf[0] & 7;
77
78 if (interleave_size > 5) {
80 interleave_size);
82 }
83 if (interleave_index > interleave_size) {
85 interleave_index, interleave_size);
87 }
89 int i;
90 /* First packet, or changed interleave size */
93 for (i = 0; i < 6; i++)
95 }
96
97 if (interleave_index < data->interleave_index) {
98 /* Wrapped around - missed the last packet of the previous group. */
100 /* No more data in the packets in this interleaving group, just
101 * start processing the next one */
103 } else {
104 /* Stash away the current packet, emit everything we have of the
105 * previous group. */
109
116
119 }
120 }
122 /* We missed a packet */
126 }
128
132 if (1 + frame_size > len)
134
135 if (len - 1 - frame_size >
sizeof(data->
group[0].
data))
137
140 memcpy(pkt->
data, &buf[1], frame_size);
142
146 memcpy(ip->
data, &buf[1 + frame_size], ip->
size);
147 /* Each packet must contain the same number of frames according to the
148 * RFC. If there's no data left in this packet, there shouldn't be any
149 * in any of the other frames in the interleaving group either. */
151
152 if (interleave_index == interleave_size) {
155 } else {
157 return 0;
158 }
159 }
160
164 {
167
174 }
175
177 /* No stored data for this interleave block, output an empty packet */
180 pkt->
data[0] = 0;
// Blank - could also be 14, Erasure
181 } else {
187 if (ip->
pos + frame_size > ip->
size)
189
193
196 }
198
202 return 1;
203 else
205 } else {
207 return 1;
208 }
209 }
210
215 {
216 if (buf)
217 return store_packet(ctx, data, st, pkt, timestamp, buf, len);
218 else
220 }
221
226 .static_payload_id = 12,
230 };