Originally committed as revision 6171 to svn://svn.ffmpeg.org/ffmpeg/trunk
Kostya Shishkov authored on 2006/09/05 13:37:14... | ... |
@@ -815,6 +815,7 @@ following image formats are supported: |
815 | 815 |
@item Smacker Video @tab @tab X @tab Video encoding used in Smacker. |
816 | 816 |
@item RTjpeg @tab @tab X @tab Video encoding used in NuppelVideo files. |
817 | 817 |
@item KMVC @tab @tab X @tab Codec used in Worms games. |
818 |
+@item VMware Video @tab @tab X @tab Codec used in videos captured by VMware. |
|
818 | 819 |
@end multitable |
819 | 820 |
|
820 | 821 |
@code{X} means that encoding (resp. decoding) is supported. |
... | ... |
@@ -120,6 +120,7 @@ OBJS-$(CONFIG_VCR1_DECODER) += vcr1.o |
120 | 120 |
OBJS-$(CONFIG_VCR1_ENCODER) += vcr1.o |
121 | 121 |
OBJS-$(CONFIG_VMDAUDIO_DECODER) += vmdav.o |
122 | 122 |
OBJS-$(CONFIG_VMDVIDEO_DECODER) += vmdav.o |
123 |
+OBJS-$(CONFIG_VMNC_DECODER) += vmnc.o |
|
123 | 124 |
OBJS-$(CONFIG_VORBIS_DECODER) += vorbis.o |
124 | 125 |
OBJS-$(CONFIG_VP3_DECODER) += vp3.o |
125 | 126 |
OBJS-$(CONFIG_VQA_DECODER) += vqavideo.o |
... | ... |
@@ -528,6 +528,9 @@ void avcodec_register_all(void) |
528 | 528 |
#ifdef CONFIG_FLASHSV_DECODER |
529 | 529 |
register_avcodec(&flashsv_decoder); |
530 | 530 |
#endif //CONFIG_FLASHSV_DECODER |
531 |
+#ifdef CONFIG_VMNC_DECODER |
|
532 |
+ register_avcodec(&vmnc_decoder); |
|
533 |
+#endif //CONFIG_VMNC_DECODER |
|
531 | 534 |
#endif /* CONFIG_DECODERS */ |
532 | 535 |
|
533 | 536 |
#if defined(CONFIG_AMR_NB) || defined(CONFIG_AMR_NB_FIXED) |
... | ... |
@@ -17,8 +17,8 @@ extern "C" { |
17 | 17 |
#define AV_STRINGIFY(s) AV_TOSTRING(s) |
18 | 18 |
#define AV_TOSTRING(s) #s |
19 | 19 |
|
20 |
-#define LIBAVCODEC_VERSION_INT ((51<<16)+(12<<8)+0) |
|
21 |
-#define LIBAVCODEC_VERSION 51.12.0 |
|
20 |
+#define LIBAVCODEC_VERSION_INT ((51<<16)+(13<<8)+0) |
|
21 |
+#define LIBAVCODEC_VERSION 51.13.0 |
|
22 | 22 |
#define LIBAVCODEC_BUILD LIBAVCODEC_VERSION_INT |
23 | 23 |
|
24 | 24 |
#define LIBAVCODEC_IDENT "Lavc" AV_STRINGIFY(LIBAVCODEC_VERSION) |
... | ... |
@@ -120,6 +120,7 @@ enum CodecID { |
120 | 120 |
CODEC_ID_FLASHSV, |
121 | 121 |
CODEC_ID_CAVS, |
122 | 122 |
CODEC_ID_JPEG2000, |
123 |
+ CODEC_ID_VMNC, |
|
123 | 124 |
|
124 | 125 |
/* various pcm "codecs" */ |
125 | 126 |
CODEC_ID_PCM_S16LE= 0x10000, |
... | ... |
@@ -2259,6 +2260,7 @@ extern AVCodec smackaud_decoder; |
2259 | 2259 |
extern AVCodec kmvc_decoder; |
2260 | 2260 |
extern AVCodec flashsv_decoder; |
2261 | 2261 |
extern AVCodec cavs_decoder; |
2262 |
+extern AVCodec vmnc_decoder; |
|
2262 | 2263 |
|
2263 | 2264 |
/* pcm codecs */ |
2264 | 2265 |
#define PCM_CODEC(id, name) \ |
2265 | 2266 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,326 @@ |
0 |
+/* |
|
1 |
+ * VMware Screen Codec (VMnc) decoder |
|
2 |
+ * Copyright (c) 2006 Konstantin Shishkov |
|
3 |
+ * |
|
4 |
+ * This library is free software; you can redistribute it and/or |
|
5 |
+ * modify it under the terms of the GNU Lesser General Public |
|
6 |
+ * License as published by the Free Software Foundation; either |
|
7 |
+ * version 2 of the License, or (at your option) any later version. |
|
8 |
+ * |
|
9 |
+ * This library is distributed in the hope that it will be useful, |
|
10 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
12 |
+ * Lesser General Public License for more details. |
|
13 |
+ * |
|
14 |
+ * You should have received a copy of the GNU Lesser General Public |
|
15 |
+ * License along with this library; if not, write to the Free Software |
|
16 |
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
17 |
+ * |
|
18 |
+ */ |
|
19 |
+ |
|
20 |
+/** |
|
21 |
+ * @file vmnc.c |
|
22 |
+ * VMware Screen Codec (VMnc) decoder |
|
23 |
+ * As Alex Beregszaszi discovered, this is effectively RFB data dump |
|
24 |
+ */ |
|
25 |
+ |
|
26 |
+#include <stdio.h> |
|
27 |
+#include <stdlib.h> |
|
28 |
+ |
|
29 |
+#include "common.h" |
|
30 |
+#include "avcodec.h" |
|
31 |
+ |
|
32 |
+#define MAGIC_WMVi 0x574D5669 |
|
33 |
+ |
|
34 |
+enum HexTile_Flags { |
|
35 |
+ HT_RAW = 1, // tile is raw |
|
36 |
+ HT_BKG = 2, // background color is present |
|
37 |
+ HT_FG = 4, // foreground color is present |
|
38 |
+ HT_SUB = 8, // subrects are present |
|
39 |
+ HT_CLR = 16 // each subrect has own color |
|
40 |
+}; |
|
41 |
+ |
|
42 |
+/* |
|
43 |
+ * Decoder context |
|
44 |
+ */ |
|
45 |
+typedef struct VmncContext { |
|
46 |
+ AVCodecContext *avctx; |
|
47 |
+ AVFrame pic; |
|
48 |
+ |
|
49 |
+ int bpp; |
|
50 |
+ int bpp2; |
|
51 |
+ int bigendian; |
|
52 |
+ uint8_t pal[768]; |
|
53 |
+ int width, height; |
|
54 |
+} VmncContext; |
|
55 |
+ |
|
56 |
+/* read pixel value from stream */ |
|
57 |
+static always_inline int vmnc_get_pixel(uint8_t* buf, int bpp, int be) { |
|
58 |
+ switch(bpp * 2 + be) { |
|
59 |
+ case 2: |
|
60 |
+ case 3: return *buf; |
|
61 |
+ case 4: return LE_16(buf); |
|
62 |
+ case 5: return BE_16(buf); |
|
63 |
+ case 8: return LE_32(buf); |
|
64 |
+ case 9: return BE_32(buf); |
|
65 |
+ default: return 0; |
|
66 |
+ } |
|
67 |
+} |
|
68 |
+ |
|
69 |
+/* fill rectangle with given colour */ |
|
70 |
+static always_inline void paint_rect(uint8_t *dst, int dx, int dy, int w, int h, int color, int bpp, int stride) |
|
71 |
+{ |
|
72 |
+ int i, j; |
|
73 |
+ dst += dx * bpp + dy * stride; |
|
74 |
+ if(bpp == 1){ |
|
75 |
+ for(j = 0; j < h; j++) { |
|
76 |
+ memset(dst, color, w); |
|
77 |
+ dst += stride; |
|
78 |
+ } |
|
79 |
+ }else if(bpp == 2){ |
|
80 |
+ uint16_t* dst2; |
|
81 |
+ for(j = 0; j < h; j++) { |
|
82 |
+ dst2 = (uint16_t*)dst; |
|
83 |
+ for(i = 0; i < w; i++) { |
|
84 |
+ *dst2++ = color; |
|
85 |
+ } |
|
86 |
+ dst += stride; |
|
87 |
+ } |
|
88 |
+ }else if(bpp == 4){ |
|
89 |
+ uint32_t* dst2; |
|
90 |
+ for(j = 0; j < h; j++) { |
|
91 |
+ dst2 = (uint32_t*)dst; |
|
92 |
+ for(i = 0; i < w; i++) { |
|
93 |
+ dst2[i] = color; |
|
94 |
+ } |
|
95 |
+ dst += stride; |
|
96 |
+ } |
|
97 |
+ } |
|
98 |
+} |
|
99 |
+ |
|
100 |
+static always_inline void paint_raw(uint8_t *dst, int w, int h, uint8_t* src, int bpp, int be, int stride) |
|
101 |
+{ |
|
102 |
+ int i, j, p; |
|
103 |
+ for(j = 0; j < h; j++) { |
|
104 |
+ for(i = 0; i < w; i++) { |
|
105 |
+ p = vmnc_get_pixel(src, bpp, be); |
|
106 |
+ src += bpp; |
|
107 |
+ memcpy(dst + i*bpp, &p, bpp); |
|
108 |
+ } |
|
109 |
+ dst += stride; |
|
110 |
+ } |
|
111 |
+} |
|
112 |
+ |
|
113 |
+static int decode_hextile(VmncContext *c, uint8_t* dst, uint8_t* src, int w, int h, int stride) |
|
114 |
+{ |
|
115 |
+ int i, j, k; |
|
116 |
+ int bg = 0, fg = 0, rects, color, flags, xy, wh; |
|
117 |
+ const int bpp = c->bpp2; |
|
118 |
+ uint8_t *dst2; |
|
119 |
+ int bw = 16, bh = 16; |
|
120 |
+ uint8_t *ssrc=src; |
|
121 |
+ |
|
122 |
+ for(j = 0; j < h; j += 16) { |
|
123 |
+ dst2 = dst; |
|
124 |
+ bw = 16; |
|
125 |
+ if(j + 16 > h) bh = h - j; |
|
126 |
+ for(i = 0; i < w; i += 16, dst2 += 16 * bpp) { |
|
127 |
+ if(i + 16 > w) bw = w - i; |
|
128 |
+ flags = *src++; |
|
129 |
+ if(flags & HT_RAW) { |
|
130 |
+ paint_raw(dst2, bw, bh, src, bpp, c->bigendian, stride); |
|
131 |
+ } else { |
|
132 |
+ if(flags & HT_BKG) { |
|
133 |
+ bg = vmnc_get_pixel(src, bpp, c->bigendian); src += bpp; |
|
134 |
+ } |
|
135 |
+ if(flags & HT_FG) { |
|
136 |
+ fg = vmnc_get_pixel(src, bpp, c->bigendian); src += bpp; |
|
137 |
+ } |
|
138 |
+ rects = 0; |
|
139 |
+ if(flags & HT_SUB) |
|
140 |
+ rects = *src++; |
|
141 |
+ color = (flags & HT_CLR); |
|
142 |
+ |
|
143 |
+ paint_rect(dst2, 0, 0, bw, bh, bg, bpp, stride); |
|
144 |
+ |
|
145 |
+ for(k = 0; k < rects; k++) { |
|
146 |
+ if(color) { |
|
147 |
+ fg = vmnc_get_pixel(src, bpp, c->bigendian); src += bpp; |
|
148 |
+ } |
|
149 |
+ xy = *src++; |
|
150 |
+ wh = *src++; |
|
151 |
+ paint_rect(dst2, xy >> 4, xy & 0xF, (wh>>4)+1, (wh & 0xF)+1, fg, bpp, stride); |
|
152 |
+ } |
|
153 |
+ } |
|
154 |
+ } |
|
155 |
+ dst += stride * 16; |
|
156 |
+ } |
|
157 |
+ return src - ssrc; |
|
158 |
+} |
|
159 |
+ |
|
160 |
+static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, uint8_t *buf, int buf_size) |
|
161 |
+{ |
|
162 |
+ VmncContext * const c = (VmncContext *)avctx->priv_data; |
|
163 |
+ uint8_t *outptr; |
|
164 |
+ uint8_t *src = buf; |
|
165 |
+ int t, dx, dy, w, h, enc, chunks, res; |
|
166 |
+ |
|
167 |
+ c->pic.reference = 1; |
|
168 |
+ c->pic.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE; |
|
169 |
+ if(avctx->reget_buffer(avctx, &c->pic) < 0){ |
|
170 |
+ av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n"); |
|
171 |
+ return -1; |
|
172 |
+ } |
|
173 |
+ |
|
174 |
+ t = BE_32(src); |
|
175 |
+ src += 4; |
|
176 |
+ |
|
177 |
+ chunks = t & 0xFF; |
|
178 |
+ if(chunks > 8) { |
|
179 |
+ av_log(avctx, AV_LOG_ERROR, "Frame decoding is not possible. Please report sample to developers.\n"); |
|
180 |
+ return -1; |
|
181 |
+ } |
|
182 |
+ if(chunks == 8) { |
|
183 |
+ int w, h, depth; |
|
184 |
+ c->pic.key_frame = 1; |
|
185 |
+ c->pic.pict_type = FF_I_TYPE; |
|
186 |
+ |
|
187 |
+ /* parse ServerInitialization struct */ |
|
188 |
+ src += 4; |
|
189 |
+ w = BE_16(src); src += 2; |
|
190 |
+ h = BE_16(src); src += 2; |
|
191 |
+ t = BE_32(src); src += 4; |
|
192 |
+ if(t != MAGIC_WMVi) { |
|
193 |
+ av_log(avctx, AV_LOG_INFO, "Invalid header: magic not found\n"); |
|
194 |
+ return -1; |
|
195 |
+ } |
|
196 |
+ depth = *src++; |
|
197 |
+ if(depth != c->bpp) { |
|
198 |
+ av_log(avctx, AV_LOG_INFO, "Depth mismatch. Container %i bpp, Frame data: %i bpp\n", c->bpp, depth); |
|
199 |
+ } |
|
200 |
+ src++; |
|
201 |
+ c->bigendian = *src++; |
|
202 |
+ if(c->bigendian & (~1)) { |
|
203 |
+ av_log(avctx, AV_LOG_INFO, "Invalid header: bigendian flag = %i\n", c->bigendian); |
|
204 |
+ return -1; |
|
205 |
+ } |
|
206 |
+ //skip pixel format data |
|
207 |
+ src += 13; |
|
208 |
+ chunks = 1; // there should be one chunk with the whole frame, rest could be ignored |
|
209 |
+ } else { |
|
210 |
+ c->pic.key_frame = 0; |
|
211 |
+ c->pic.pict_type = FF_P_TYPE; |
|
212 |
+ } |
|
213 |
+ while(chunks--) { |
|
214 |
+ // decode FramebufferUpdate struct |
|
215 |
+ dx = BE_16(src); src += 2; |
|
216 |
+ dy = BE_16(src); src += 2; |
|
217 |
+ w = BE_16(src); src += 2; |
|
218 |
+ h = BE_16(src); src += 2; |
|
219 |
+ if((dx + w > c->width) || (dy + h > c->height)) { |
|
220 |
+ av_log(avctx, AV_LOG_ERROR, "Incorrect frame size: %ix%i+%ix%i of %ix%i\n", w, h, dx, dy, c->width, c->height); |
|
221 |
+ return -1; |
|
222 |
+ } |
|
223 |
+ enc = BE_32(src); src += 4; |
|
224 |
+ if(enc != 0x00000005) { |
|
225 |
+ av_log(avctx, AV_LOG_ERROR, "Only hextile decoding is supported for now\n"); |
|
226 |
+ switch(enc) { |
|
227 |
+ case 0: |
|
228 |
+ av_log(avctx, AV_LOG_INFO, "And this is raw encoding\n"); |
|
229 |
+ break; |
|
230 |
+ case 1: |
|
231 |
+ av_log(avctx, AV_LOG_INFO, "And this is CopyRect encoding\n"); |
|
232 |
+ break; |
|
233 |
+ case 2: |
|
234 |
+ av_log(avctx, AV_LOG_INFO, "And this is RRE encoding\n"); |
|
235 |
+ break; |
|
236 |
+ case 3: |
|
237 |
+ av_log(avctx, AV_LOG_INFO, "And this is CoRRE encoding\n"); |
|
238 |
+ break; |
|
239 |
+ default: |
|
240 |
+ av_log(avctx, AV_LOG_INFO, "And this is unknown encoding (%i)\n", enc); |
|
241 |
+ } |
|
242 |
+ return -1; |
|
243 |
+ } |
|
244 |
+ outptr = c->pic.data[0] + dx * c->bpp2 + dy * c->pic.linesize[0]; |
|
245 |
+ res = decode_hextile(c, outptr, src, w, h, c->pic.linesize[0]); |
|
246 |
+ if(res < 0) |
|
247 |
+ return -1; |
|
248 |
+ src += res; |
|
249 |
+ } |
|
250 |
+ *data_size = sizeof(AVFrame); |
|
251 |
+ *(AVFrame*)data = c->pic; |
|
252 |
+ |
|
253 |
+ /* always report that the buffer was completely consumed */ |
|
254 |
+ return buf_size; |
|
255 |
+} |
|
256 |
+ |
|
257 |
+ |
|
258 |
+ |
|
259 |
+/* |
|
260 |
+ * |
|
261 |
+ * Init VMnc decoder |
|
262 |
+ * |
|
263 |
+ */ |
|
264 |
+static int decode_init(AVCodecContext *avctx) |
|
265 |
+{ |
|
266 |
+ VmncContext * const c = (VmncContext *)avctx->priv_data; |
|
267 |
+ |
|
268 |
+ c->avctx = avctx; |
|
269 |
+ avctx->has_b_frames = 0; |
|
270 |
+ |
|
271 |
+ c->pic.data[0] = NULL; |
|
272 |
+ c->width = avctx->width; |
|
273 |
+ c->height = avctx->height; |
|
274 |
+ |
|
275 |
+ if (avcodec_check_dimensions(avctx, avctx->height, avctx->width) < 0) { |
|
276 |
+ return 1; |
|
277 |
+ } |
|
278 |
+ c->bpp = avctx->bits_per_sample; |
|
279 |
+ c->bpp2 = c->bpp/8; |
|
280 |
+ |
|
281 |
+ switch(c->bpp){ |
|
282 |
+ case 8: |
|
283 |
+ avctx->pix_fmt = PIX_FMT_PAL8; |
|
284 |
+ break; |
|
285 |
+ case 16: |
|
286 |
+ avctx->pix_fmt = PIX_FMT_RGB555; |
|
287 |
+ break; |
|
288 |
+ case 32: |
|
289 |
+ avctx->pix_fmt = PIX_FMT_RGB32; |
|
290 |
+ break; |
|
291 |
+ default: |
|
292 |
+ av_log(avctx, AV_LOG_ERROR, "Unsupported bitdepth %i\n", c->bpp); |
|
293 |
+ } |
|
294 |
+ |
|
295 |
+ return 0; |
|
296 |
+} |
|
297 |
+ |
|
298 |
+ |
|
299 |
+ |
|
300 |
+/* |
|
301 |
+ * |
|
302 |
+ * Uninit VMnc decoder |
|
303 |
+ * |
|
304 |
+ */ |
|
305 |
+static int decode_end(AVCodecContext *avctx) |
|
306 |
+{ |
|
307 |
+ VmncContext * const c = (VmncContext *)avctx->priv_data; |
|
308 |
+ |
|
309 |
+ if (c->pic.data[0]) |
|
310 |
+ avctx->release_buffer(avctx, &c->pic); |
|
311 |
+ |
|
312 |
+ return 0; |
|
313 |
+} |
|
314 |
+ |
|
315 |
+AVCodec vmnc_decoder = { |
|
316 |
+ "VMware video", |
|
317 |
+ CODEC_TYPE_VIDEO, |
|
318 |
+ CODEC_ID_VMNC, |
|
319 |
+ sizeof(VmncContext), |
|
320 |
+ decode_init, |
|
321 |
+ NULL, |
|
322 |
+ decode_end, |
|
323 |
+ decode_frame |
|
324 |
+}; |
|
325 |
+ |
... | ... |
@@ -155,6 +155,7 @@ const CodecTag codec_bmp_tags[] = { |
155 | 155 |
{ CODEC_ID_KMVC, MKTAG('K', 'M', 'V', 'C') }, |
156 | 156 |
{ CODEC_ID_CAVS, MKTAG('C', 'A', 'V', 'S') }, |
157 | 157 |
{ CODEC_ID_JPEG2000, MKTAG('M', 'J', '2', 'C') }, |
158 |
+ { CODEC_ID_VMNC, MKTAG('V', 'M', 'n', 'c') }, |
|
158 | 159 |
{ CODEC_ID_RAWVIDEO, 0 }, |
159 | 160 |
{ CODEC_ID_NONE, 0 }, |
160 | 161 |
}; |