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>
25
35
46
48 16, 11, 10, 16, 24, 40, 51, 61,
49 12, 12, 14, 19, 26, 58, 60, 55,
50 14, 13, 16, 24, 40, 57, 69, 56,
51 14, 17, 22, 29, 51, 87, 80, 62,
52 18, 22, 37, 56, 68, 109, 103, 77,
53 24, 35, 55, 64, 81, 104, 113, 92,
54 49, 64, 78, 87, 103, 121, 120, 101,
55 72, 92, 95, 98, 112, 100, 103, 99
56 };
57
59 17, 18, 24, 47, 99, 99, 99, 99,
60 18, 21, 26, 66, 99, 99, 99, 99,
61 24, 26, 56, 99, 99, 99, 99, 99,
62 47, 66, 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 99, 99, 99, 99, 99, 99, 99, 99
67 };
68
69 /**
70 * @brief copy frame data from buffer to AVFrame, handling stride.
71 * @param f destination AVFrame
72 * @param src source buffer, does not use any line-stride
73 * @param width width of the video frame
74 * @param height height of the video frame
75 */
77 {
81 }
82
83 /**
84 * @brief extract quantization tables from codec data into our context
85 */
88 {
89 int i;
90 if (size < 2 * 64 * 4) {
93 }
94 for (i = 0; i < 64; i++, buf += 4)
96 for (i = 0; i < 64; i++, buf += 4)
98 return 0;
99 }
100
101 /**
102 * @brief set quantization tables from a quality value
103 */
105 {
106 int i;
107 quality =
FFMAX(quality, 1);
108 for (i = 0; i < 64; i++) {
111 }
112 }
113
115 int quality)
116 {
119
122 if (quality >= 0)
125 // also reserve space for a possible additional header
126 int buf_size = height * width * 3 / 2
129 if (buf_size > INT_MAX/8)
130 return -1;
136 buf_size);
139 "Can't allocate decompression buffer.\n");
141 }
144 return 1;
145 }
else if (quality != c->
quality)
147
148 return 0;
149 }
150
153 {
155 int buf_size = avpkt->
size;
158 int orig_size = buf_size;
160 int size_change = 0;
162 enum {
163 NUV_UNCOMPRESSED = '0',
164 NUV_RTJPEG = '1',
165 NUV_RTJPEG_IN_LZO = '2',
166 NUV_LZO = '3',
167 NUV_BLACK = 'N',
168 NUV_COPY_LAST = 'L'
169 } comptype;
170
171 if (buf_size < 12) {
174 }
175
176 // codec data (rtjpeg quant tables)
177 if (buf[0] == 'D' && buf[1] == 'R') {
179 // skip rest of the frameheader.
180 buf = &buf[12];
181 buf_size -= 12;
182 ret =
get_quant(avctx, c, buf, buf_size);
183 if (ret < 0)
186 return orig_size;
187 }
188
189 if (buf_size < 12 || buf[0] != 'V') {
192 }
193 comptype = buf[1];
194 switch (comptype) {
195 case NUV_RTJPEG_IN_LZO:
196 case NUV_RTJPEG:
197 keyframe = !buf[2];
198 break;
199 case NUV_COPY_LAST:
200 keyframe = 0;
201 break;
202 default:
203 keyframe = 1;
204 break;
205 }
206 retry:
207 // skip rest of the frameheader.
208 buf = &buf[12];
209 buf_size -= 12;
210 if (comptype == NUV_RTJPEG_IN_LZO || comptype == NUV_LZO) {
212 int inlen = buf_size;
216 }
220 }
222 int w, h, q;
226 }
227 // There seem to exist two variants of this header: one starts with 'V'
228 // and 5 bytes unknown, the other matches current MythTV and is 4 bytes size,
229 // 1 byte header size (== 12), 1 byte version (== 0)
230 if (buf[0] !=
'V' &&
AV_RL16(&buf[4]) != 0x000c) {
233 }
236 q = buf[10];
238 return result;
239 if (result) {
241 buf_size = avpkt->
size;
242 size_change = 1;
243 goto retry;
244 }
247 }
248
249 if (size_change || keyframe) {
251 init_frame = 1;
252 }
253
255 return result;
256 if (init_frame) {
260 }
261
264 // decompress/copy/whatever data
265 switch (comptype) {
266 case NUV_LZO:
267 case NUV_UNCOMPRESSED: {
269 if (buf_size < c->
width * height * 3 / 2) {
271 height = buf_size / c->
width / 3 * 2;
272 }
273 if(height > 0)
275 break;
276 }
277 case NUV_RTJPEG_IN_LZO:
278 case NUV_RTJPEG:
280 if (ret < 0)
282 break;
283 case NUV_BLACK:
287 break;
288 case NUV_COPY_LAST:
289 /* nothing more to do here */
290 break;
291 default:
294 }
295
297 return result;
298
299 *got_frame = 1;
300 return orig_size;
301 }
302
304 {
307
311
317
319
322
324
327
328 return 0;
329 }
330
332 {
334
337
338 return 0;
339 }
340
351 };