1 /*
2 * NuppelVideo decoder
3 * Copyright (c) 2006 Reimar Doeffinger
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
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <limits.h>
25
33
41 uint32_t lq[64], cq[64];
45
47 16, 11, 10, 16, 24, 40, 51, 61,
48 12, 12, 14, 19, 26, 58, 60, 55,
49 14, 13, 16, 24, 40, 57, 69, 56,
50 14, 17, 22, 29, 51, 87, 80, 62,
51 18, 22, 37, 56, 68, 109, 103, 77,
52 24, 35, 55, 64, 81, 104, 113, 92,
53 49, 64, 78, 87, 103, 121, 120, 101,
54 72, 92, 95, 98, 112, 100, 103, 99
55 };
56
58 17, 18, 24, 47, 99, 99, 99, 99,
59 18, 21, 26, 66, 99, 99, 99, 99,
60 24, 26, 56, 99, 99, 99, 99, 99,
61 47, 66, 99, 99, 99, 99, 99, 99,
62 99, 99, 99, 99, 99, 99, 99, 99,
63 99, 99, 99, 99, 99, 99, 99, 99,
64 99, 99, 99, 99, 99, 99, 99, 99,
65 99, 99, 99, 99, 99, 99, 99, 99
66 };
67
68 /**
69 * @brief copy frame data from buffer to AVFrame, handling stride.
70 * @param f destination AVFrame
71 * @param src source buffer, does not use any line-stride
72 * @param width width of the video frame
73 * @param height height of the video frame
74 */
76 {
80 }
81
82 /**
83 * @brief extract quantization tables from codec data into our context
84 */
87 {
88 int i;
89 if (size < 2 * 64 * 4) {
92 }
93 for (i = 0; i < 64; i++, buf += 4)
95 for (i = 0; i < 64; i++, buf += 4)
97 return 0;
98 }
99
100 /**
101 * @brief set quantization tables from a quality value
102 */
104 {
105 int i;
106 quality =
FFMAX(quality, 1);
107 for (i = 0; i < 64; i++) {
110 }
111 }
112
114 int quality)
115 {
118
121 if (quality >= 0)
124 // also reserve space for a possible additional header
125 int buf_size = height * width * 3 / 2
128 if (buf_size > INT_MAX/8)
129 return -1;
135 buf_size);
138 "Can't allocate decompression buffer.\n");
140 }
144 return 1;
145 }
else if (quality != c->
quality)
148
149 return 0;
150 }
151
154 {
156 int buf_size = avpkt->
size;
159 int orig_size = buf_size;
161 int size_change = 0;
163 enum {
164 NUV_UNCOMPRESSED = '0',
165 NUV_RTJPEG = '1',
166 NUV_RTJPEG_IN_LZO = '2',
167 NUV_LZO = '3',
168 NUV_BLACK = 'N',
169 NUV_COPY_LAST = 'L'
170 } comptype;
171
172 if (buf_size < 12) {
175 }
176
177 // codec data (rtjpeg quant tables)
178 if (buf[0] == 'D' && buf[1] == 'R') {
180 // skip rest of the frameheader.
181 buf = &buf[12];
182 buf_size -= 12;
183 ret =
get_quant(avctx, c, buf, buf_size);
184 if (ret < 0)
188 return orig_size;
189 }
190
191 if (buf_size < 12 || buf[0] != 'V') {
194 }
195 comptype = buf[1];
196 switch (comptype) {
197 case NUV_RTJPEG_IN_LZO:
198 case NUV_RTJPEG:
199 keyframe = !buf[2];
200 break;
201 case NUV_COPY_LAST:
202 keyframe = 0;
203 break;
204 default:
205 keyframe = 1;
206 break;
207 }
208 retry:
209 // skip rest of the frameheader.
210 buf = &buf[12];
211 buf_size -= 12;
212 if (comptype == NUV_RTJPEG_IN_LZO || comptype == NUV_LZO) {
214 int inlen = buf_size;
218 }
221 }
223 int w, h, q;
227 }
228 // There seem to exist two variants of this header: one starts with 'V'
229 // and 5 bytes unknown, the other matches current MythTV and is 4 bytes size,
230 // 1 byte header size (== 12), 1 byte version (== 0)
231 if (buf[0] !=
'V' &&
AV_RL16(&buf[4]) != 0x000c) {
234 }
237 q = buf[10];
239 return result;
240 if (result) {
242 buf_size = avpkt->
size;
243 size_change = 1;
244 goto retry;
245 }
248 }
249
250 if (size_change || keyframe) {
252 init_frame = 1;
253 }
254
256 return result;
257 if (init_frame) {
261 }
262
265 // decompress/copy/whatever data
266 switch (comptype) {
267 case NUV_LZO:
268 case NUV_UNCOMPRESSED: {
270 if (buf_size < c->
width * height * 3 / 2) {
272 height = buf_size / c->
width / 3 * 2;
273 }
274 if(height > 0)
276 break;
277 }
278 case NUV_RTJPEG_IN_LZO:
279 case NUV_RTJPEG:
281 if (ret < 0)
283 break;
284 case NUV_BLACK:
288 break;
289 case NUV_COPY_LAST:
290 /* nothing more to do here */
291 break;
292 default:
295 }
296
298 return result;
299
300 *got_frame = 1;
301 return orig_size;
302 }
303
305 {
308
312
318
320
323
325
328
329 return 0;
330 }
331
333 {
335
338
339 return 0;
340 }
341
352 };