annotate vmnc.c @ 3679:2702eec8c8b9 libavcodec

Try to handle all chunks, previous scheme was not correct.
author kostya
date Tue, 05 Sep 2006 07:31:53 +0000
parents 93a961e40d65
children 9f77f4f577b4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3677
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
1 /*
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
2 * VMware Screen Codec (VMnc) decoder
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
3 * Copyright (c) 2006 Konstantin Shishkov
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
4 *
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
5 * This library is free software; you can redistribute it and/or
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
6 * modify it under the terms of the GNU Lesser General Public
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
7 * License as published by the Free Software Foundation; either
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
8 * version 2 of the License, or (at your option) any later version.
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
9 *
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
10 * This library is distributed in the hope that it will be useful,
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
13 * Lesser General Public License for more details.
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
14 *
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
15 * You should have received a copy of the GNU Lesser General Public
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
16 * License along with this library; if not, write to the Free Software
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
18 *
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
19 */
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
20
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
21 /**
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
22 * @file vmnc.c
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
23 * VMware Screen Codec (VMnc) decoder
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
24 * As Alex Beregszaszi discovered, this is effectively RFB data dump
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
25 */
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
26
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
27 #include <stdio.h>
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
28 #include <stdlib.h>
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
29
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
30 #include "common.h"
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
31 #include "avcodec.h"
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
32
3679
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
33 enum EncTypes {
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
34 MAGIC_WMVd = 0x574D5664,
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
35 MAGIC_WMVe,
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
36 MAGIC_WMVf,
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
37 MAGIC_WMVg,
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
38 MAGIC_WMVh,
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
39 MAGIC_WMVi,
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
40 MAGIC_WMVj
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
41 };
3677
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
42
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
43 enum HexTile_Flags {
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
44 HT_RAW = 1, // tile is raw
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
45 HT_BKG = 2, // background color is present
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
46 HT_FG = 4, // foreground color is present
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
47 HT_SUB = 8, // subrects are present
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
48 HT_CLR = 16 // each subrect has own color
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
49 };
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
50
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
51 /*
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
52 * Decoder context
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
53 */
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
54 typedef struct VmncContext {
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
55 AVCodecContext *avctx;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
56 AVFrame pic;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
57
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
58 int bpp;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
59 int bpp2;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
60 int bigendian;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
61 uint8_t pal[768];
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
62 int width, height;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
63 } VmncContext;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
64
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
65 /* read pixel value from stream */
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
66 static always_inline int vmnc_get_pixel(uint8_t* buf, int bpp, int be) {
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
67 switch(bpp * 2 + be) {
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
68 case 2:
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
69 case 3: return *buf;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
70 case 4: return LE_16(buf);
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
71 case 5: return BE_16(buf);
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
72 case 8: return LE_32(buf);
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
73 case 9: return BE_32(buf);
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
74 default: return 0;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
75 }
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
76 }
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
77
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
78 /* fill rectangle with given colour */
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
79 static always_inline void paint_rect(uint8_t *dst, int dx, int dy, int w, int h, int color, int bpp, int stride)
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
80 {
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
81 int i, j;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
82 dst += dx * bpp + dy * stride;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
83 if(bpp == 1){
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
84 for(j = 0; j < h; j++) {
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
85 memset(dst, color, w);
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
86 dst += stride;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
87 }
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
88 }else if(bpp == 2){
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
89 uint16_t* dst2;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
90 for(j = 0; j < h; j++) {
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
91 dst2 = (uint16_t*)dst;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
92 for(i = 0; i < w; i++) {
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
93 *dst2++ = color;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
94 }
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
95 dst += stride;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
96 }
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
97 }else if(bpp == 4){
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
98 uint32_t* dst2;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
99 for(j = 0; j < h; j++) {
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
100 dst2 = (uint32_t*)dst;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
101 for(i = 0; i < w; i++) {
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
102 dst2[i] = color;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
103 }
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
104 dst += stride;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
105 }
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
106 }
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
107 }
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
108
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
109 static always_inline void paint_raw(uint8_t *dst, int w, int h, uint8_t* src, int bpp, int be, int stride)
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
110 {
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
111 int i, j, p;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
112 for(j = 0; j < h; j++) {
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
113 for(i = 0; i < w; i++) {
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
114 p = vmnc_get_pixel(src, bpp, be);
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
115 src += bpp;
3678
93a961e40d65 Handle raw blocks correctly (both updating pointer and storing to memory)
kostya
parents: 3677
diff changeset
116 switch(bpp){
93a961e40d65 Handle raw blocks correctly (both updating pointer and storing to memory)
kostya
parents: 3677
diff changeset
117 case 1:
93a961e40d65 Handle raw blocks correctly (both updating pointer and storing to memory)
kostya
parents: 3677
diff changeset
118 dst[i] = p;
93a961e40d65 Handle raw blocks correctly (both updating pointer and storing to memory)
kostya
parents: 3677
diff changeset
119 break;
93a961e40d65 Handle raw blocks correctly (both updating pointer and storing to memory)
kostya
parents: 3677
diff changeset
120 case 2:
93a961e40d65 Handle raw blocks correctly (both updating pointer and storing to memory)
kostya
parents: 3677
diff changeset
121 ((uint16_t*)dst)[i] = p;
93a961e40d65 Handle raw blocks correctly (both updating pointer and storing to memory)
kostya
parents: 3677
diff changeset
122 break;
93a961e40d65 Handle raw blocks correctly (both updating pointer and storing to memory)
kostya
parents: 3677
diff changeset
123 case 4:
93a961e40d65 Handle raw blocks correctly (both updating pointer and storing to memory)
kostya
parents: 3677
diff changeset
124 ((uint32_t*)dst)[i] = p;
93a961e40d65 Handle raw blocks correctly (both updating pointer and storing to memory)
kostya
parents: 3677
diff changeset
125 break;
93a961e40d65 Handle raw blocks correctly (both updating pointer and storing to memory)
kostya
parents: 3677
diff changeset
126 }
3677
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
127 }
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
128 dst += stride;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
129 }
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
130 }
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
131
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
132 static int decode_hextile(VmncContext *c, uint8_t* dst, uint8_t* src, int w, int h, int stride)
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
133 {
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
134 int i, j, k;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
135 int bg = 0, fg = 0, rects, color, flags, xy, wh;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
136 const int bpp = c->bpp2;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
137 uint8_t *dst2;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
138 int bw = 16, bh = 16;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
139 uint8_t *ssrc=src;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
140
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
141 for(j = 0; j < h; j += 16) {
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
142 dst2 = dst;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
143 bw = 16;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
144 if(j + 16 > h) bh = h - j;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
145 for(i = 0; i < w; i += 16, dst2 += 16 * bpp) {
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
146 if(i + 16 > w) bw = w - i;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
147 flags = *src++;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
148 if(flags & HT_RAW) {
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
149 paint_raw(dst2, bw, bh, src, bpp, c->bigendian, stride);
3678
93a961e40d65 Handle raw blocks correctly (both updating pointer and storing to memory)
kostya
parents: 3677
diff changeset
150 src += bw * bh * bpp;
3677
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
151 } else {
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
152 if(flags & HT_BKG) {
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
153 bg = vmnc_get_pixel(src, bpp, c->bigendian); src += bpp;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
154 }
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
155 if(flags & HT_FG) {
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
156 fg = vmnc_get_pixel(src, bpp, c->bigendian); src += bpp;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
157 }
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
158 rects = 0;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
159 if(flags & HT_SUB)
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
160 rects = *src++;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
161 color = (flags & HT_CLR);
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
162
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
163 paint_rect(dst2, 0, 0, bw, bh, bg, bpp, stride);
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
164
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
165 for(k = 0; k < rects; k++) {
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
166 if(color) {
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
167 fg = vmnc_get_pixel(src, bpp, c->bigendian); src += bpp;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
168 }
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
169 xy = *src++;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
170 wh = *src++;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
171 paint_rect(dst2, xy >> 4, xy & 0xF, (wh>>4)+1, (wh & 0xF)+1, fg, bpp, stride);
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
172 }
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
173 }
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
174 }
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
175 dst += stride * 16;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
176 }
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
177 return src - ssrc;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
178 }
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
179
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
180 static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, uint8_t *buf, int buf_size)
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
181 {
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
182 VmncContext * const c = (VmncContext *)avctx->priv_data;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
183 uint8_t *outptr;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
184 uint8_t *src = buf;
3679
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
185 int dx, dy, w, h, depth, enc, chunks, res;
3677
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
186
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
187 c->pic.reference = 1;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
188 c->pic.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
189 if(avctx->reget_buffer(avctx, &c->pic) < 0){
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
190 av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n");
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
191 return -1;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
192 }
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
193
3679
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
194 c->pic.key_frame = 0;
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
195 c->pic.pict_type = FF_P_TYPE;
3677
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
196
3679
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
197 src += 2;
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
198 chunks = BE_16(src); src += 2;
3677
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
199 while(chunks--) {
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
200 dx = BE_16(src); src += 2;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
201 dy = BE_16(src); src += 2;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
202 w = BE_16(src); src += 2;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
203 h = BE_16(src); src += 2;
3679
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
204 enc = BE_32(src); src += 4;
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
205 switch(enc) {
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
206 case MAGIC_WMVd: // unknown
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
207 src += 2;
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
208 src += w * h * 8; // skip this data for now
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
209 break;
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
210 case MAGIC_WMVe: // unknown
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
211 src += 2;
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
212 break;
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
213 case MAGIC_WMVf: // unknown and empty
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
214 break;
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
215 case MAGIC_WMVi: // ServerInitialization struct
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
216 c->pic.key_frame = 1;
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
217 c->pic.pict_type = FF_I_TYPE;
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
218 depth = *src++;
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
219 if(depth != c->bpp) {
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
220 av_log(avctx, AV_LOG_INFO, "Depth mismatch. Container %i bpp, Frame data: %i bpp\n", c->bpp, depth);
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
221 }
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
222 src++;
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
223 c->bigendian = *src++;
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
224 if(c->bigendian & (~1)) {
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
225 av_log(avctx, AV_LOG_INFO, "Invalid header: bigendian flag = %i\n", c->bigendian);
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
226 return -1;
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
227 }
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
228 //skip the rest of pixel format data
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
229 src += 13;
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
230 break;
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
231 case 0x00000000: // raw rectangle data
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
232 if((dx + w > c->width) || (dy + h > c->height)) {
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
233 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);
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
234 return -1;
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
235 }
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
236 outptr = c->pic.data[0] + dx * c->bpp2 + dy * c->pic.linesize[0];
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
237 paint_raw(outptr, w, h, src, c->bpp2, c->bigendian, c->pic.linesize[0]);
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
238 src += w * h * c->bpp2;
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
239 break;
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
240 case 0x00000005: // HexTile encoded rectangle
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
241 if((dx + w > c->width) || (dy + h > c->height)) {
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
242 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);
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
243 return -1;
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
244 }
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
245 outptr = c->pic.data[0] + dx * c->bpp2 + dy * c->pic.linesize[0];
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
246 res = decode_hextile(c, outptr, src, w, h, c->pic.linesize[0]);
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
247 if(res < 0)
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
248 return -1;
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
249 src += res;
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
250 break;
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
251 default:
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
252 av_log(avctx, AV_LOG_ERROR, "Unsupported block type 0x%08X\n", enc);
2702eec8c8b9 Try to handle all chunks, previous scheme was not correct.
kostya
parents: 3678
diff changeset
253 chunks = 0; // leave chunks decoding loop
3677
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
254 }
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
255 }
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
256 *data_size = sizeof(AVFrame);
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
257 *(AVFrame*)data = c->pic;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
258
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
259 /* always report that the buffer was completely consumed */
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
260 return buf_size;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
261 }
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
262
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
263
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
264
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
265 /*
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
266 *
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
267 * Init VMnc decoder
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
268 *
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
269 */
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
270 static int decode_init(AVCodecContext *avctx)
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
271 {
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
272 VmncContext * const c = (VmncContext *)avctx->priv_data;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
273
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
274 c->avctx = avctx;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
275 avctx->has_b_frames = 0;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
276
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
277 c->pic.data[0] = NULL;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
278 c->width = avctx->width;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
279 c->height = avctx->height;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
280
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
281 if (avcodec_check_dimensions(avctx, avctx->height, avctx->width) < 0) {
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
282 return 1;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
283 }
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
284 c->bpp = avctx->bits_per_sample;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
285 c->bpp2 = c->bpp/8;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
286
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
287 switch(c->bpp){
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
288 case 8:
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
289 avctx->pix_fmt = PIX_FMT_PAL8;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
290 break;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
291 case 16:
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
292 avctx->pix_fmt = PIX_FMT_RGB555;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
293 break;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
294 case 32:
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
295 avctx->pix_fmt = PIX_FMT_RGB32;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
296 break;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
297 default:
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
298 av_log(avctx, AV_LOG_ERROR, "Unsupported bitdepth %i\n", c->bpp);
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
299 }
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
300
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
301 return 0;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
302 }
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
303
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
304
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
305
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
306 /*
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
307 *
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
308 * Uninit VMnc decoder
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
309 *
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
310 */
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
311 static int decode_end(AVCodecContext *avctx)
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
312 {
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
313 VmncContext * const c = (VmncContext *)avctx->priv_data;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
314
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
315 if (c->pic.data[0])
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
316 avctx->release_buffer(avctx, &c->pic);
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
317
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
318 return 0;
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
319 }
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
320
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
321 AVCodec vmnc_decoder = {
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
322 "VMware video",
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
323 CODEC_TYPE_VIDEO,
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
324 CODEC_ID_VMNC,
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
325 sizeof(VmncContext),
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
326 decode_init,
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
327 NULL,
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
328 decode_end,
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
329 decode_frame
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
330 };
18b13b923616 VMware Video decoder (fourcc: VMnc)
kostya
parents:
diff changeset
331