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 FFmpeg.
12 *
13 * FFmpeg 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 * FFmpeg 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 FFmpeg; if not, write to the Free Software
25 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
26 */
27
34
41 };
42
44 {
46 }
47
50 const uint8_t *buf,
int len, uint16_t seq,
52 {
53 /* Corresponding to header fields in the RFC */
54 int f, p,
i, sbit, ebit,
src,
r;
56
60
61 if (
data->buf &&
data->timestamp != *timestamp) {
62 /* Dropping old buffered, unfinished data */
64 data->endbyte_bits = 0;
65 }
66
70 }
71
73 p = buf[0] & 0x40;
75 /* Mode A */
76 header_size = 4;
78 r = ((buf[1] & 0x01) << 3) | ((buf[2] & 0xe0) >> 5);
79 } else if (!p) {
80 /* Mode B */
81 header_size = 8;
82 if (
len < header_size) {
84 "Too short H.263 RTP packet: %d bytes, %d header bytes\n",
87 }
90 } else {
91 /* Mode C */
92 header_size = 12;
93 if (
len < header_size) {
95 "Too short H.263 RTP packet: %d bytes, %d header bytes\n",
98 }
101 }
102 sbit = (buf[0] >> 3) & 0x7;
103 ebit = buf[0] & 0x7;
104 src = (buf[1] & 0xe0) >> 5;
105 if (!(buf[0] & 0xf8)) { /* Reserved bits in RFC 2429/4629 are zero */
106 if ((
src == 0 ||
src >= 6) &&
r) {
107 /* Invalid src for this format, and bits that should be zero
108 * according to RFC 2190 aren't zero. */
110 "Interpreting H.263 RTP data as RFC 2429/4629 even though "
111 "signalled with a static payload type.\n");
115 }
116 }
117
118 buf += header_size;
120
122 /* Check the picture start code, only start buffering a new frame
123 * if this is correct */
128 data->timestamp = *timestamp;
129 } else {
130 /* Frame not started yet, skipping */
132 }
133 }
134
135 if (
data->endbyte_bits || sbit) {
136 if (
data->endbyte_bits == sbit) {
137 data->endbyte |= buf[0] & (0xff >> sbit);
138 data->endbyte_bits = 0;
139 buf++;
142 } else {
143 /* Start/end skip bits not matching - missed packets? */
149 if (
data->endbyte_bits) {
152 }
156 if (
data->endbyte_bits)
158 (8 -
data->endbyte_bits);
159 ebit = 0;
161 }
162 }
163 if (ebit) {
166 data->endbyte_bits = 8 - ebit;
167 data->endbyte = buf[
len - 1] & (0xff << ebit);
168 } else {
170 }
171
174
175 if (
data->endbyte_bits)
177 data->endbyte_bits = 0;
178
184
185 return 0;
186 }
187
195 .static_payload_id = 34,
196 };