1 /*
2 * RTP H.263 Depacketizer, RFC 2190
3 * Copyright (c) 2012 Martin Storsjo
4 * Based on the GStreamer H.263 Depayloder:
5 * Copyright 2005 Wim Taymans
6 * Copyright 2007 Edward Hervey
7 * Copyright 2007 Nokia Corporation
8 * Copyright 2007 Collabora Ltd, Philippe Kalaf
9 * Copyright 2010 Mark Nauwelaerts
10 *
11 * This file is part of Libav.
12 *
13 * Libav is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU Lesser General Public
15 * License as published by the Free Software Foundation; either
16 * version 2.1 of the License, or (at your option) any later version.
17 *
18 * Libav is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 * Lesser General Public License for more details.
22 *
23 * You should have received a copy of the GNU Lesser General Public
24 * License along with Libav; if not, write to the Free Software
25 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
26 */
27
33
40 };
41
43 {
45 }
46
48 {
49 if (!data)
50 return;
55 }
57 }
58
60 {
61 if (st_index < 0)
62 return 0;
64 return 0;
65 }
66
71 {
72 /* Corresponding to header fields in the RFC */
73 int f, p, i, sbit, ebit,
src,
r;
75
78 seq, flags);
79
81 /* Dropping old buffered, unfinished data */
86 }
87
88 if (len < 4) {
91 }
92
93 f = buf[0] & 0x80;
94 p = buf[0] & 0x40;
95 if (!f) {
96 /* Mode A */
97 header_size = 4;
98 i = buf[1] & 0x10;
99 r = ((buf[1] & 0x01) << 3) | ((buf[2] & 0xe0) >> 5);
100 } else if (!p) {
101 /* Mode B */
102 header_size = 8;
103 if (len < header_size) {
105 "Too short H.263 RTP packet: %d bytes, %d header bytes\n",
106 len, header_size);
108 }
109 r = buf[3] & 0x03;
110 i = buf[4] & 0x80;
111 } else {
112 /* Mode C */
113 header_size = 12;
114 if (len < header_size) {
116 "Too short H.263 RTP packet: %d bytes, %d header bytes\n",
117 len, header_size);
119 }
120 r = buf[3] & 0x03;
121 i = buf[4] & 0x80;
122 }
123 sbit = (buf[0] >> 3) & 0x7;
124 ebit = buf[0] & 0x7;
125 src = (buf[1] & 0xe0) >> 5;
126 if (!(buf[0] & 0xf8)) { /* Reserved bits in RFC 2429/4629 are zero */
127 if ((src == 0 || src >= 6) &&
r) {
128 /* Invalid src for this format, and bits that should be zero
129 * according to RFC 2190 aren't zero. */
131 "Interpreting H263 RTP data as RFC 2429/4629 even though "
132 "signalled with a static payload type.\n");
135 len, seq, flags);
136 }
137 }
138
139 buf += header_size;
140 len -= header_size;
141
143 /* Check the picture start code, only start buffering a new frame
144 * if this is correct */
145 if (len > 4 &&
AV_RB32(buf) >> 10 == 0x20) {
147 if (ret < 0)
150 } else {
151 /* Frame not started yet, skipping */
153 }
154 }
155
158 data->
endbyte |= buf[0] & (0xff >> sbit);
160 buf++;
161 len--;
163 } else {
164 /* Start/end skip bits not matching - missed packets? */
171 }
178 ebit = 0;
179 len = 0;
180 }
181 }
182 if (ebit) {
183 if (len > 0)
186 data->
endbyte = buf[len - 1] & (0xff << ebit);
187 } else {
189 }
190
193
197
199 if (ret < 0)
201 if (!i)
203
204 return 0;
205 }
206
214 .static_payload_id = 34,
215 };