6 #if defined(USE_QTX_CODECS) || defined(MACOSX)
7 #include "wine/windef.h"
10 #include "vd_internal.h"
13 #include "ldt_keeper.h"
16 static vd_info_t info
= {
17 "Quicktime Video decoder",
29 #include <QuickTime/ImageCodec.h>
30 #define dump_ImageDescription(x)
32 #include "qtx/qtxsdk/components.h"
36 //#include "wine/windef.h"
38 HMODULE WINAPI
LoadLibraryA(LPCSTR
);
39 FARPROC WINAPI
GetProcAddress(HMODULE
,LPCSTR
);
40 int WINAPI
FreeLibrary(HMODULE
);
43 //static ComponentDescription desc; // for FindNextComponent()
44 static ComponentInstance ci
=NULL
; // codec handle
45 //static CodecInfo cinfo; // for ImageCodecGetCodecInfo()
46 //Component prev=NULL;
47 //ComponentResult cres; //
48 static CodecCapabilities codeccap
; // for decpar
49 static CodecDecompressParams decpar
; // for ImageCodecPreDecompress()
50 //static ImageSubCodecDecompressCapabilities icap; // for ImageCodecInitialize()
51 static Rect OutBufferRect
; //the dimensions of our GWorld
53 static GWorldPtr OutBufferGWorld
= NULL
;//a GWorld is some kind of description for a drawing environment
54 static ImageDescriptionHandle framedescHandle
;
55 //static HINSTANCE qtml_dll;
56 static HMODULE handler
;
59 static Component (*FindNextComponent
)(Component prev
,ComponentDescription
* desc
);
60 static OSErr (*GetComponentInfo
)(Component prev
,ComponentDescription
* desc
,Handle h1
,Handle h2
,Handle h3
);
61 static long (*CountComponents
)(ComponentDescription
* desc
);
62 static OSErr (*InitializeQTML
)(long flags
);
63 static OSErr (*EnterMovies
)(void);
64 static ComponentInstance (*OpenComponent
)(Component c
);
65 static ComponentResult (*ImageCodecInitialize
)(ComponentInstance ci
,
66 ImageSubCodecDecompressCapabilities
* cap
);
67 static ComponentResult (*ImageCodecBeginBand
)(ComponentInstance ci
,
68 CodecDecompressParams
* params
,
69 ImageSubCodecDecompressRecord
* drp
,
71 static ComponentResult (*ImageCodecDrawBand
)(ComponentInstance ci
,
72 ImageSubCodecDecompressRecord
* drp
);
73 static ComponentResult (*ImageCodecEndBand
)(ComponentInstance ci
,
74 ImageSubCodecDecompressRecord
* drp
,
77 static ComponentResult (*ImageCodecGetCodecInfo
)(ComponentInstance ci
,
79 static ComponentResult (*ImageCodecPreDecompress
)(ComponentInstance ci
,
80 CodecDecompressParams
* params
);
81 static ComponentResult (*ImageCodecBandDecompress
)(ComponentInstance ci
,
82 CodecDecompressParams
* params
);
83 static PixMapHandle (*GetGWorldPixMap
)(GWorldPtr offscreenGWorld
);
84 static OSErr (*QTNewGWorldFromPtr
)(GWorldPtr
*gw
,
86 const Rect
*boundsRect
,
88 /*GDHandle*/void* aGDevice
, //unused anyway
92 static OSErr (*NewHandleClear
)(Size byteCount
);
95 // to set/get/query special features/parameters
96 static int control(sh_video_t
*sh
,int cmd
,void* arg
,...){
97 return CONTROL_UNKNOWN
;
100 static int codec_inited
=0;
103 static int init(sh_video_t
*sh
){
105 ComponentResult cres
;
106 ComponentDescription desc
;
108 CodecInfo cinfo
; // for ImageCodecGetCodecInfo()
109 ImageSubCodecDecompressCapabilities icap
; // for ImageCodecInitialize()
119 handler
= LoadLibraryA("qtmlClient.dll");
121 mp_msg(MSGT_DECVIDEO
,MSGL_ERR
,"unable to load qtmlClient.dll\n");
125 InitializeQTML
= (OSErr (*)(long))GetProcAddress(handler
, "InitializeQTML");
126 EnterMovies
= (OSErr (*)(void))GetProcAddress(handler
, "EnterMovies");
127 FindNextComponent
= (Component (*)(Component
,ComponentDescription
*))GetProcAddress(handler
, "FindNextComponent");
128 CountComponents
= (long (*)(ComponentDescription
*))GetProcAddress(handler
, "CountComponents");
129 GetComponentInfo
= (OSErr (*)(Component
,ComponentDescription
*,Handle
,Handle
,Handle
))GetProcAddress(handler
, "GetComponentInfo");
130 OpenComponent
= (ComponentInstance (*)(Component
))GetProcAddress(handler
, "OpenComponent");
131 ImageCodecInitialize
= (ComponentResult (*)(ComponentInstance
,ImageSubCodecDecompressCapabilities
*))GetProcAddress(handler
, "ImageCodecInitialize");
132 ImageCodecGetCodecInfo
= (ComponentResult (*)(ComponentInstance
,CodecInfo
*))GetProcAddress(handler
, "ImageCodecGetCodecInfo");
133 ImageCodecBeginBand
= (ComponentResult (*)(ComponentInstance
,CodecDecompressParams
*,ImageSubCodecDecompressRecord
*,long))GetProcAddress(handler
, "ImageCodecBeginBand");
134 ImageCodecPreDecompress
= (ComponentResult (*)(ComponentInstance
,CodecDecompressParams
*))GetProcAddress(handler
, "ImageCodecPreDecompress");
135 ImageCodecBandDecompress
= (ComponentResult (*)(ComponentInstance
,CodecDecompressParams
*))GetProcAddress(handler
, "ImageCodecBandDecompress");
136 GetGWorldPixMap
= (PixMapHandle (*)(GWorldPtr
))GetProcAddress(handler
, "GetGWorldPixMap");
137 QTNewGWorldFromPtr
= (OSErr(*)(GWorldPtr
*,OSType
,const Rect
*,CTabHandle
,void*,GWorldFlags
,void *,long))GetProcAddress(handler
, "QTNewGWorldFromPtr");
138 NewHandleClear
= (OSErr(*)(Size
))GetProcAddress(handler
, "NewHandleClear");
139 // = GetProcAddress(handler, "");
141 if(!InitializeQTML
|| !EnterMovies
|| !FindNextComponent
|| !ImageCodecBandDecompress
){
142 mp_msg(MSGT_DECVIDEO
,MSGL_ERR
,"invalid qtmlClient.dll!\n");
146 result
=InitializeQTML(6+16);
147 // result=InitializeQTML(0);
148 mp_msg(MSGT_DECVIDEO
,MSGL_DBG2
,"InitializeQTML returned %i\n",result
);
149 // result=EnterMovies();
150 // printf("EnterMovies->%d\n",result);
154 memset(&desc
,0,sizeof(desc
));
155 while((prev
=FindNextComponent(prev
,&desc
))){
156 ComponentDescription desc2
;
157 unsigned char* c1
=&desc2
.componentType
;
158 unsigned char* c2
=&desc2
.componentSubType
;
159 memset(&desc2
,0,sizeof(desc2
));
160 // printf("juhee %p (%p)\n",prev,&desc);
161 GetComponentInfo(prev
,&desc2
,NULL
,NULL
,NULL
);
162 mp_msg(MSGT_DECVIDEO
,MSGL_DGB2
,"DESC: %c%c%c%c/%c%c%c%c [0x%X/0x%X] 0x%X\n",
163 c1
[3],c1
[2],c1
[1],c1
[0],
164 c2
[3],c2
[2],c2
[1],c2
[0],
165 desc2
.componentType
,desc2
.componentSubType
,
166 desc2
.componentFlags
);
171 memset(&desc
,0,sizeof(desc
));
172 desc
.componentType
= (((unsigned char)'i')<<24)|
173 (((unsigned char)'m')<<16)|
174 (((unsigned char)'d')<<8)|
175 (((unsigned char)'c'));
177 desc
.componentSubType
=
178 (((unsigned char)'S'<<24))|
179 (((unsigned char)'V')<<16)|
180 (((unsigned char)'Q')<<8)|
181 (((unsigned char)'3'));
183 desc
.componentSubType
= bswap_32(sh
->format
);
185 desc
.componentManufacturer
=0;
186 desc
.componentFlags
=0;
187 desc
.componentFlagsMask
=0;
189 mp_msg(MSGT_DECVIDEO
,MSGL_DBG2
,"Count = %d\n",CountComponents(&desc
));
190 prev
=FindNextComponent(NULL
,&desc
);
192 mp_msg(MSGT_DECVIDEO
,MSGL_ERR
,"Cannot find requested component\n");
195 mp_msg(MSGT_DECVIDEO
,MSGL_DBG2
,"Found it! ID = 0x%X\n",prev
);
197 ci
=OpenComponent(prev
);
198 mp_msg(MSGT_DECVIDEO
,MSGL_DBG2
,"ci=%p\n",ci
);
200 memset(&icap
,0,sizeof(icap
));
201 cres
=ImageCodecInitialize(ci
,&icap
);
202 mp_msg(MSGT_DECVIDEO
,MSGL_DBG2
,"ImageCodecInitialize->%p size=%d (%d)\n",cres
,icap
.recordSize
,icap
.decompressRecordSize
);
204 memset(&cinfo
,0,sizeof(cinfo
));
205 cres
=ImageCodecGetCodecInfo(ci
,&cinfo
);
206 mp_msg(MSGT_DECVIDEO
,MSGL_DBG2
,"Flags: compr: 0x%X decomp: 0x%X format: 0x%X\n",
207 cinfo
.compressFlags
, cinfo
.decompressFlags
, cinfo
.formatFlags
);
208 mp_msg(MSGT_DECVIDEO
,MSGL_DBG2
,"Codec name: %.*s\n",((unsigned char*)&cinfo
.typeName
)[0],
209 ((unsigned char*)&cinfo
.typeName
)+1);
213 OutBufferRect
.left
=0;
214 OutBufferRect
.right
=sh
->disp_w
;
215 OutBufferRect
.bottom
=sh
->disp_h
;
217 //Fill the imagedescription for our SVQ3 frame
218 //we can probably get this from Demuxer
220 framedescHandle
=(ImageDescriptionHandle
)NewHandleClear(sizeof(ImageDescription
)+200);
221 printf("framedescHandle=%p *p=%p\n",framedescHandle
,*framedescHandle
);
222 { FILE* f
=fopen("/root/.wine/fake_windows/IDesc","r");
223 if(!f
) printf("filenot found: IDesc\n");
224 fread(*framedescHandle
,sizeof(ImageDescription
)+200,1,f
);
228 if(!sh
->ImageDesc
) sh
->ImageDesc
=(sh
->bih
+1); // hack for SVQ3-in-AVI
229 mp_msg(MSGT_DECVIDEO
,MSGL_DBG2
,"ImageDescription size: %d\n",((ImageDescription
*)(sh
->ImageDesc
))->idSize
);
230 framedescHandle
=(ImageDescriptionHandle
)NewHandleClear(((ImageDescription
*)(sh
->ImageDesc
))->idSize
);
231 memcpy(*framedescHandle
,sh
->ImageDesc
,((ImageDescription
*)(sh
->ImageDesc
))->idSize
);
232 dump_ImageDescription(*framedescHandle
);
234 //Find codecscomponent for video decompression
235 // result = FindCodec ('SVQ1',anyCodec,&compressor,&decompressor );
236 // printf("FindCodec SVQ1 returned:%i compressor: 0x%X decompressor: 0x%X\n",result,compressor,decompressor);
238 sh
->context
= (void *)kYUVSPixelFormat
;
241 int imgfmt
= sh
->codec
->outfmt
[sh
->outfmtidx
];
246 qt_imgfmt
= kYUVSPixelFormat
;
249 qt_imgfmt
= 0x73797639; //kYVU9PixelFormat;
252 qt_imgfmt
= 0x79343230;
255 qt_imgfmt
= kUYVY422PixelFormat
;
258 qt_imgfmt
= kYVYU422PixelFormat
;
259 imgfmt
= IMGFMT_YUY2
;
262 qt_imgfmt
= k16LE555PixelFormat
;
265 qt_imgfmt
= k24BGRPixelFormat
;
268 qt_imgfmt
= k32BGRAPixelFormat
;
271 qt_imgfmt
= k32RGBAPixelFormat
;
274 mp_msg(MSGT_DECVIDEO
,MSGL_ERR
,"Unknown requested csp\n");
277 mp_msg(MSGT_DECVIDEO
,MSGL_DBG2
,"imgfmt: %s qt_imgfmt: %.4s\n", vo_format_name(imgfmt
), &qt_imgfmt
);
278 sh
->context
= (void *)qt_imgfmt
;
279 if(!mpcodecs_config_vo(sh
,sh
->disp_w
,sh
->disp_h
,imgfmt
)) return 0;
282 if(!mpcodecs_config_vo(sh
,sh
->disp_w
,sh
->disp_h
,IMGFMT_YUY2
)) return 0;
289 static void uninit(sh_video_t
*sh
){
296 static mp_image_t
* decode(sh_video_t
*sh
,void* data
,int len
,int flags
){
300 ComponentResult cres
;
302 if(len
<=0) return NULL
; // skipped frame
304 mpi
=mpcodecs_get_image(sh
, MP_IMGTYPE_STATIC
, MP_IMGFLAG_PRESERVE
,
305 sh
->disp_w
, sh
->disp_h
);
306 if(!mpi
) return NULL
;
308 decpar
.data
= (char*)data
;
309 decpar
.bufferSize
= len
;
310 (**framedescHandle
).dataSize
=len
;
313 result
= QTNewGWorldFromPtr(
315 // kYUVSPixelFormat, //pixel format of new GWorld == YUY2
317 &OutBufferRect
, //we should benchmark if yvu9 is faster for svq3, too
323 mp_msg(MSGT_DECVIDEO
,MSGL_DBG2
,"NewGWorldFromPtr returned:%d\n",65536-(result
&0xffff));
324 // if (65536-(result&0xFFFF) != 10000)
327 // printf("IDesc=%d\n",sizeof(ImageDescription));
329 decpar
.imageDescription
= framedescHandle
;
331 decpar
.stopLine
=(**framedescHandle
).height
;
332 decpar
.frameNumber
= 1; //1
333 // decpar.conditionFlags=0xFFD; // first
334 // decpar.callerFlags=0x2001; // first
335 decpar
.matrixFlags
= 0;
336 decpar
.matrixType
= 0;
338 decpar
.capabilities
=&codeccap
;
339 // decpar.accuracy = 0x1680000; //codecNormalQuality;
340 decpar
.accuracy
= codecNormalQuality
;
341 // decpar.port = OutBufferGWorld;
342 // decpar.preferredOffscreenPixelSize=17207;
344 // decpar.sequenceID=malloc(1000);
345 // memset(decpar.sequenceID,0,1000);
347 // SrcRect.top=17207;
349 // SrcRect.right=0;//image_width;
350 // SrcRect.bottom=0;//image_height;
352 // decpar.srcRect = SrcRect;
353 decpar
.srcRect
= OutBufferRect
;
355 decpar
.transferMode
= srcCopy
;
356 decpar
.dstPixMap
= **GetGWorldPixMap( OutBufferGWorld
);//destPixmap;
358 cres
=ImageCodecPreDecompress(ci
,&decpar
);
359 mp_msg(MSGT_DECVIDEO
,MSGL_DBG2
,"ImageCodecPreDecompress cres=0x%X\n",cres
);
361 if(decpar
.wantedDestinationPixelTypes
)
362 { OSType
*p
=*(decpar
.wantedDestinationPixelTypes
);
364 mp_msg(MSGT_DECVIDEO
,MSGL_DBG2
,"supported csp: 0x%08X %.4s\n",*p
,p
);
370 // decpar.conditionFlags=0x10FFF; // first
371 // decpar.preferredOffscreenPixelSize=17207;
373 // decpar.conditionFlags=0x10FFD; // first
375 // cres=ImageCodecPreDecompress(ci,&decpar);
376 // printf("ImageCodecPreDecompress cres=0x%X\n",cres);
383 if(decpar
.frameNumber
==124){
384 decpar
.frameNumber
=1;
385 cres
=ImageCodecPreDecompress(ci
,&decpar
);
386 mp_msg(MSGT_DECVIDEO
,MSGL_DBG2
,"ImageCodecPreDecompress cres=0x%X\n",cres
);
390 cres
=ImageCodecBandDecompress(ci
,&decpar
);
392 ++decpar
.frameNumber
;
395 mp_msg(MSGT_DECVIDEO
,MSGL_DBG2
,"ImageCodecBandDecompress cres=0x%X (-0x%X) %d\n",cres
,-cres
,cres
);
400 // printf("img_base[%d]=%p\n",i,((int*)decpar.dstPixMap.baseAddr)[i]);
402 if((int)sh
->context
==0x73797639){ // Sorenson 16-bit YUV -> std YVU9
404 short *src0
=(short *)((char*)decpar
.dstPixMap
.baseAddr
+0x20);
406 for(i
=0;i
<mpi
->h
;i
++){
408 unsigned char* dst
=mpi
->planes
[0]+i
*mpi
->stride
[0];
409 unsigned short* src
=src0
+i
*((mpi
->w
+15)&(~15));
410 for(x
=0;x
<mpi
->w
;x
++) dst
[x
]=src
[x
];
412 src0
+=((mpi
->w
+15)&(~15))*((mpi
->h
+15)&(~15));
413 for(i
=0;i
<mpi
->h
/4;i
++){
415 unsigned char* dst
=mpi
->planes
[1]+i
*mpi
->stride
[1];
416 unsigned short* src
=src0
+i
*(((mpi
->w
+63)&(~63))/4);
417 for(x
=0;x
<mpi
->w
/4;x
++) dst
[x
]=src
[x
];
418 src
+=((mpi
->w
+63)&(~63))/4;
420 src0
+=(((mpi
->w
+63)&(~63))/4)*(((mpi
->h
+63)&(~63))/4);
421 for(i
=0;i
<mpi
->h
/4;i
++){
423 unsigned char* dst
=mpi
->planes
[2]+i
*mpi
->stride
[2];
424 unsigned short* src
=src0
+i
*(((mpi
->w
+63)&(~63))/4);
425 for(x
=0;x
<mpi
->w
/4;x
++) dst
[x
]=src
[x
];
426 src
+=((mpi
->w
+63)&(~63))/4;