Mercurial > mplayer.hg
annotate libmpcodecs/vd_qtvideo.c @ 8287:c3eb28f300d0
.align -> .balign
patch by Bj«Órn Sandell <biorn@dce.chalmers.se>
author | arpi |
---|---|
date | Mon, 25 Nov 2002 20:37:12 +0000 |
parents | b2c8b627d598 |
children | d867439e3940 |
rev | line source |
---|---|
8160 | 1 #include <stdio.h> |
2 #include <stdlib.h> | |
3 | |
4 #include "config.h" | |
5 | |
6 #ifdef USE_QTX_CODECS | |
7 | |
8 #include "mp_msg.h" | |
9 #include "vd_internal.h" | |
10 | |
11 static vd_info_t info = { | |
12 "Quicktime Video decoder", | |
13 "qtvideo", | |
14 "A'rpi", | |
15 "Faust3", | |
16 "win32" | |
17 }; | |
18 | |
19 LIBVD_EXTERN(qtvideo) | |
20 | |
8282 | 21 #include "../bswap.h" |
8270 | 22 #include "qtx/qtxsdk/components.h" |
8160 | 23 |
24 //#include "wine/windef.h" | |
25 | |
26 HMODULE WINAPI LoadLibraryA(LPCSTR); | |
27 FARPROC WINAPI GetProcAddress(HMODULE,LPCSTR); | |
28 int WINAPI FreeLibrary(HMODULE); | |
29 | |
30 //static ComponentDescription desc; // for FindNextComponent() | |
31 static ComponentInstance ci=NULL; // codec handle | |
32 //static CodecInfo cinfo; // for ImageCodecGetCodecInfo() | |
33 //Component prev=NULL; | |
34 //ComponentResult cres; // | |
35 static CodecCapabilities codeccap; // for decpar | |
36 static CodecDecompressParams decpar; // for ImageCodecPreDecompress() | |
37 //static ImageSubCodecDecompressCapabilities icap; // for ImageCodecInitialize() | |
38 static Rect OutBufferRect; //the dimensions of our GWorld | |
39 | |
40 static GWorldPtr OutBufferGWorld = NULL;//a GWorld is some kind of description for a drawing environment | |
41 static ImageDescriptionHandle framedescHandle; | |
42 //static HINSTANCE qtml_dll; | |
43 static HMODULE handler; | |
44 | |
45 static Component (*FindNextComponent)(Component prev,ComponentDescription* desc); | |
46 static OSErr (*GetComponentInfo)(Component prev,ComponentDescription* desc,Handle h1,Handle h2,Handle h3); | |
47 static long (*CountComponents)(ComponentDescription* desc); | |
48 static OSErr (*InitializeQTML)(long flags); | |
49 static OSErr (*EnterMovies)(void); | |
50 static ComponentInstance (*OpenComponent)(Component c); | |
51 static ComponentResult (*ImageCodecInitialize)(ComponentInstance ci, | |
52 ImageSubCodecDecompressCapabilities * cap); | |
53 static ComponentResult (*ImageCodecBeginBand)(ComponentInstance ci, | |
54 CodecDecompressParams * params, | |
55 ImageSubCodecDecompressRecord * drp, | |
56 long flags); | |
57 static ComponentResult (*ImageCodecDrawBand)(ComponentInstance ci, | |
58 ImageSubCodecDecompressRecord * drp); | |
59 static ComponentResult (*ImageCodecEndBand)(ComponentInstance ci, | |
60 ImageSubCodecDecompressRecord * drp, | |
61 OSErr result, | |
62 long flags); | |
63 static ComponentResult (*ImageCodecGetCodecInfo)(ComponentInstance ci, | |
64 CodecInfo * info); | |
65 static ComponentResult (*ImageCodecPreDecompress)(ComponentInstance ci, | |
66 CodecDecompressParams * params); | |
67 static ComponentResult (*ImageCodecBandDecompress)(ComponentInstance ci, | |
68 CodecDecompressParams * params); | |
69 static PixMapHandle (*GetGWorldPixMap)(GWorldPtr offscreenGWorld); | |
70 static OSErr (*QTNewGWorldFromPtr)(GWorldPtr *gw, | |
71 OSType pixelFormat, | |
72 const Rect *boundsRect, | |
73 CTabHandle cTable, | |
74 /*GDHandle*/void* aGDevice, //unused anyway | |
75 GWorldFlags flags, | |
76 void *baseAddr, | |
77 long rowBytes); | |
78 static OSErr (*NewHandleClear)(Size byteCount); | |
79 | |
80 | |
81 // to set/get/query special features/parameters | |
82 static int control(sh_video_t *sh,int cmd,void* arg,...){ | |
83 return CONTROL_UNKNOWN; | |
84 } | |
85 | |
86 static int codec_inited=0; | |
87 | |
88 // init driver | |
89 static int init(sh_video_t *sh){ | |
90 long result = 1; | |
91 ComponentResult cres; | |
92 ComponentDescription desc; | |
93 Component prev=NULL; | |
94 CodecInfo cinfo; // for ImageCodecGetCodecInfo() | |
95 ImageSubCodecDecompressCapabilities icap; // for ImageCodecInitialize() | |
96 | |
8270 | 97 #ifdef USE_WIN32DLL |
98 Setup_LDT_Keeper(); | |
99 #endif | |
100 | |
8160 | 101 handler = LoadLibraryA("qtmlClient.dll"); |
102 | |
103 InitializeQTML = GetProcAddress(handler, "InitializeQTML"); | |
104 EnterMovies = GetProcAddress(handler, "EnterMovies"); | |
105 FindNextComponent = GetProcAddress(handler, "FindNextComponent"); | |
106 CountComponents = GetProcAddress(handler, "CountComponents"); | |
107 GetComponentInfo = GetProcAddress(handler, "GetComponentInfo"); | |
108 OpenComponent = GetProcAddress(handler, "OpenComponent"); | |
109 ImageCodecInitialize = GetProcAddress(handler, "ImageCodecInitialize"); | |
110 ImageCodecGetCodecInfo = GetProcAddress(handler, "ImageCodecGetCodecInfo"); | |
111 ImageCodecBeginBand = GetProcAddress(handler, "ImageCodecBeginBand"); | |
112 ImageCodecPreDecompress = GetProcAddress(handler, "ImageCodecPreDecompress"); | |
113 ImageCodecBandDecompress = GetProcAddress(handler, "ImageCodecBandDecompress"); | |
114 GetGWorldPixMap = GetProcAddress(handler, "GetGWorldPixMap"); | |
115 QTNewGWorldFromPtr = GetProcAddress(handler, "QTNewGWorldFromPtr"); | |
116 NewHandleClear = GetProcAddress(handler, "NewHandleClear"); | |
117 // = GetProcAddress(handler, ""); | |
118 | |
119 if(!InitializeQTML || !EnterMovies || !FindNextComponent || !ImageCodecBandDecompress){ | |
120 printf("invalid qt DLL!\n"); | |
121 return 0; | |
122 } | |
123 | |
8162
98951b7331e1
no need to EnterMovies(), do minimal InitializeQTML only
arpi
parents:
8160
diff
changeset
|
124 result=InitializeQTML(6+16); |
98951b7331e1
no need to EnterMovies(), do minimal InitializeQTML only
arpi
parents:
8160
diff
changeset
|
125 // result=InitializeQTML(0); |
8160 | 126 printf("InitializeQTML returned %i\n",result); |
8162
98951b7331e1
no need to EnterMovies(), do minimal InitializeQTML only
arpi
parents:
8160
diff
changeset
|
127 // result=EnterMovies(); |
98951b7331e1
no need to EnterMovies(), do minimal InitializeQTML only
arpi
parents:
8160
diff
changeset
|
128 // printf("EnterMovies->%d\n",result); |
8160 | 129 |
130 memset(&desc,0,sizeof(desc)); | |
131 desc.componentType= (((unsigned char)'i')<<24)| | |
132 (((unsigned char)'m')<<16)| | |
133 (((unsigned char)'d')<<8)| | |
134 (((unsigned char)'c')); | |
8282 | 135 #if 0 |
8160 | 136 desc.componentSubType= |
137 (((unsigned char)'S'<<24))| | |
138 (((unsigned char)'V')<<16)| | |
139 (((unsigned char)'Q')<<8)| | |
140 (((unsigned char)'3')); | |
8282 | 141 #else |
142 desc.componentSubType = bswap_32(sh->format); | |
143 #endif | |
8160 | 144 desc.componentManufacturer=0; |
145 desc.componentFlags=0; | |
146 desc.componentFlagsMask=0; | |
147 | |
148 printf("Count = %d\n",CountComponents(&desc)); | |
149 #if 0 | |
150 memset(&desc,0,sizeof(desc)); | |
151 while((prev=FindNextComponent(prev,&desc))){ | |
8282 | 152 ComponentDescription desc2; |
8160 | 153 unsigned char* c1=&desc2.componentType; |
154 unsigned char* c2=&desc2.componentSubType; | |
155 memset(&desc2,0,sizeof(desc2)); | |
156 printf("juhee %p (%p)\n",prev,&desc); | |
157 GetComponentInfo(prev,&desc2,NULL,NULL,NULL); | |
158 printf("DESC: %c%c%c%c/%c%c%c%c [0x%X/0x%X] 0x%X\n", | |
159 c1[3],c1[2],c1[1],c1[0], | |
160 c2[3],c2[2],c2[1],c2[0], | |
161 desc2.componentType,desc2.componentSubType, | |
162 desc2.componentFlags); | |
163 } | |
164 #endif | |
165 | |
166 prev=FindNextComponent(NULL,&desc); | |
167 if(!prev){ | |
168 printf("Cannot find requested component\n"); | |
8282 | 169 return(0); |
8160 | 170 } |
171 printf("Found it! ID = 0x%X\n",prev); | |
172 | |
173 ci=OpenComponent(prev); | |
174 printf("ci=%p\n",ci); | |
175 | |
176 memset(&icap,0,sizeof(icap)); | |
177 cres=ImageCodecInitialize(ci,&icap); | |
178 printf("ImageCodecInitialize->%p size=%d (%d)\n",cres,icap.recordSize,icap.decompressRecordSize); | |
179 | |
180 memset(&cinfo,0,sizeof(cinfo)); | |
181 cres=ImageCodecGetCodecInfo(ci,&cinfo); | |
182 printf("Flags: compr: 0x%X decomp: 0x%X format: 0x%X\n", | |
183 cinfo.compressFlags, cinfo.decompressFlags, cinfo.formatFlags); | |
184 printf("Codec name: %.*s\n",((unsigned char*)&cinfo.typeName)[0], | |
185 ((unsigned char*)&cinfo.typeName)+1); | |
186 | |
187 //make a yuy2 gworld | |
188 OutBufferRect.top=0; | |
189 OutBufferRect.left=0; | |
190 OutBufferRect.right=sh->disp_w; | |
191 OutBufferRect.bottom=sh->disp_h; | |
192 | |
193 //Fill the imagedescription for our SVQ3 frame | |
194 //we can probably get this from Demuxer | |
195 #if 0 | |
196 framedescHandle=(ImageDescriptionHandle)NewHandleClear(sizeof(ImageDescription)+200); | |
197 printf("framedescHandle=%p *p=%p\n",framedescHandle,*framedescHandle); | |
198 { FILE* f=fopen("/root/.wine/fake_windows/IDesc","r"); | |
199 if(!f) printf("filenot found: IDesc\n"); | |
200 fread(*framedescHandle,sizeof(ImageDescription)+200,1,f); | |
201 fclose(f); | |
202 } | |
203 #else | |
204 framedescHandle=&(sh->ImageDesc); | |
205 #endif | |
206 //Find codecscomponent for video decompression | |
207 // result = FindCodec ('SVQ1',anyCodec,&compressor,&decompressor ); | |
208 // printf("FindCodec SVQ1 returned:%i compressor: 0x%X decompressor: 0x%X\n",result,compressor,decompressor); | |
209 | |
8282 | 210 sh->context = kYUVSPixelFormat; |
211 #if 0 | |
212 { | |
213 int imgfmt = sh->codec->outfmt[sh->outfmtidx]; | |
214 int qt_imgfmt; | |
215 switch(imgfmt) | |
216 { | |
217 case IMGFMT_YUY2: | |
218 qt_imgfmt = kYUVSPixelFormat; | |
219 break; | |
220 case IMGFMT_YVU9: | |
221 qt_imgfmt = kYVU9PixelFormat; | |
222 break; | |
223 case IMGFMT_UYVY: | |
224 qt_imgfmt = kUYVY422PixelFormat; | |
225 break; | |
226 case IMGFMT_YVYU: | |
227 qt_imgfmt = kYVYU422PixelFormat; | |
228 imgfmt = IMGFMT_YUY2; | |
229 break; | |
230 case IMGFMT_RGB16: | |
231 qt_imgfmt = k16LE555PixelFormat; | |
232 break; | |
233 case IMGFMT_BGR24: | |
234 qt_imgfmt = k24BGRPixelFormat; | |
235 break; | |
236 case IMGFMT_BGR32: | |
237 qt_imgfmt = k32BGRAPixelFormat; | |
238 break; | |
239 case IMGFMT_RGB32: | |
240 qt_imgfmt = k32RGBAPixelFormat; | |
241 break; | |
242 default: | |
243 printf("Unknown requested csp\n"); | |
244 return(0); | |
245 } | |
246 printf("imgfmt: %s qt_imgfmt: %.4s\n", vo_format_name(imgfmt), &qt_imgfmt); | |
247 sh->context = qt_imgfmt; | |
248 if(!mpcodecs_config_vo(sh,sh->disp_w,sh->disp_h,imgfmt)) return 0; | |
249 } | |
250 #else | |
8160 | 251 if(!mpcodecs_config_vo(sh,sh->disp_w,sh->disp_h,IMGFMT_YUY2)) return 0; |
8282 | 252 #endif |
8160 | 253 |
254 return 1; | |
255 } | |
256 | |
257 // uninit driver | |
258 static void uninit(sh_video_t *sh){ | |
259 } | |
260 | |
261 // decode a frame | |
262 static mp_image_t* decode(sh_video_t *sh,void* data,int len,int flags){ | |
263 long result = 1; | |
264 mp_image_t* mpi; | |
265 ComponentResult cres; | |
266 | |
267 mpi=mpcodecs_get_image(sh, MP_IMGTYPE_STATIC, MP_IMGFLAG_PRESERVE, | |
268 sh->disp_w, sh->disp_h); | |
269 if(!mpi) return NULL; | |
270 | |
271 decpar.data = (char*)data; | |
272 decpar.bufferSize = len; | |
273 (**framedescHandle).dataSize=len; | |
274 | |
275 if(!codec_inited){ | |
276 result = QTNewGWorldFromPtr( | |
277 &OutBufferGWorld, | |
8282 | 278 // kYUVSPixelFormat, //pixel format of new GWorld == YUY2 |
279 sh->context, | |
8160 | 280 &OutBufferRect, //we should benchmark if yvu9 is faster for svq3, too |
281 0, | |
282 0, | |
283 0, | |
284 mpi->planes[0], | |
285 mpi->stride[0]); | |
8282 | 286 printf("NewGWorldFromPtr returned:%d\n",65536-(result&0xffff)); |
287 // if (65536-(result&0xFFFF) != 10000) | |
288 // return NULL; | |
8160 | 289 |
290 // printf("IDesc=%d\n",sizeof(ImageDescription)); | |
291 | |
292 decpar.imageDescription = framedescHandle; | |
293 decpar.startLine=0; | |
294 decpar.stopLine=(**framedescHandle).height; | |
295 decpar.frameNumber = 1; //1 | |
296 // decpar.conditionFlags=0xFFD; // first | |
297 // decpar.callerFlags=0x2001; // first | |
298 decpar.matrixFlags = 0; | |
299 decpar.matrixType = 0; | |
300 decpar.matrix = 0; | |
301 decpar.capabilities=&codeccap; | |
302 // decpar.accuracy = 0x1680000; //codecNormalQuality; | |
303 decpar.accuracy = codecNormalQuality; | |
304 decpar.port = OutBufferGWorld; | |
305 // decpar.preferredOffscreenPixelSize=17207; | |
306 | |
307 // decpar.sequenceID=malloc(1000); | |
308 // memset(decpar.sequenceID,0,1000); | |
309 | |
310 // SrcRect.top=17207; | |
311 // SrcRect.left=0; | |
312 // SrcRect.right=0;//image_width; | |
313 // SrcRect.bottom=0;//image_height; | |
314 | |
315 // decpar.srcRect = SrcRect; | |
316 decpar.srcRect = OutBufferRect; | |
317 | |
318 decpar.transferMode = srcCopy; | |
319 decpar.dstPixMap = **GetGWorldPixMap( OutBufferGWorld);//destPixmap; | |
320 | |
321 cres=ImageCodecPreDecompress(ci,&decpar); | |
322 printf("ImageCodecPreDecompress cres=0x%X\n",cres); | |
323 | |
324 // decpar.conditionFlags=0x10FFF; // first | |
325 // decpar.preferredOffscreenPixelSize=17207; | |
326 | |
327 // decpar.conditionFlags=0x10FFD; // first | |
328 | |
329 // cres=ImageCodecPreDecompress(ci,&decpar); | |
330 // printf("ImageCodecPreDecompress cres=0x%X\n",cres); | |
331 | |
332 | |
333 codec_inited=1; | |
334 } | |
335 | |
336 #if 0 | |
337 if(decpar.frameNumber==124){ | |
338 decpar.frameNumber=1; | |
339 cres=ImageCodecPreDecompress(ci,&decpar); | |
340 printf("ImageCodecPreDecompress cres=0x%X\n",cres); | |
341 } | |
342 #endif | |
343 | |
344 cres=ImageCodecBandDecompress(ci,&decpar); | |
8188 | 345 if(cres&0xFFFF) printf("ImageCodecBandDecompress cres=0x%X (-0x%X) %d\n",cres,-cres,cres); |
8160 | 346 |
347 ++decpar.frameNumber; | |
348 | |
349 return mpi; | |
350 } | |
351 #endif |