Mercurial > mplayer.hg
annotate libmpcodecs/ve_qtvideo.c @ 9341:33974bf4870b
fixes
author | gabucino |
---|---|
date | Sat, 08 Feb 2003 13:26:18 +0000 |
parents | 420e2b2f8e5a |
children | 97b30b4b722f |
rev | line source |
---|---|
8471 | 1 /*qt video encoder using win32 libs |
2 released under gnu gpl | |
3 (C)Sascha Sommer */ | |
4 | |
5 #define MAX_IDSIZE 0x6F | |
6 | |
7 #include <stdio.h> | |
8 #include <stdlib.h> | |
9 #include <string.h> | |
10 | |
11 #include "../config.h" | |
12 #include "../mp_msg.h" | |
13 #include "../bswap.h" | |
14 | |
9217
420e2b2f8e5a
compiler warning fixes patch by Dominik Mierzejewski <dominik@rangers.eu.org>
arpi
parents:
9014
diff
changeset
|
15 #ifdef USE_WIN32DLL |
420e2b2f8e5a
compiler warning fixes patch by Dominik Mierzejewski <dominik@rangers.eu.org>
arpi
parents:
9014
diff
changeset
|
16 #include "ldt_keeper.h" |
420e2b2f8e5a
compiler warning fixes patch by Dominik Mierzejewski <dominik@rangers.eu.org>
arpi
parents:
9014
diff
changeset
|
17 #endif |
420e2b2f8e5a
compiler warning fixes patch by Dominik Mierzejewski <dominik@rangers.eu.org>
arpi
parents:
9014
diff
changeset
|
18 |
8471 | 19 #ifdef USE_QTX_CODECS |
20 #include "../loader/qtx/qtxsdk/components.h" | |
21 #include "wine/windef.h" | |
22 | |
8733
478561617705
compiler warning fixes by Dominik Mierzejewski <dominik@rangers.eu.org>
arpi
parents:
8585
diff
changeset
|
23 #ifdef USE_WIN32DLL |
478561617705
compiler warning fixes by Dominik Mierzejewski <dominik@rangers.eu.org>
arpi
parents:
8585
diff
changeset
|
24 #include "ldt_keeper.h" |
478561617705
compiler warning fixes by Dominik Mierzejewski <dominik@rangers.eu.org>
arpi
parents:
8585
diff
changeset
|
25 #endif |
478561617705
compiler warning fixes by Dominik Mierzejewski <dominik@rangers.eu.org>
arpi
parents:
8585
diff
changeset
|
26 |
8471 | 27 #include "codec-cfg.h" |
28 #include "stream.h" | |
29 #include "demuxer.h" | |
30 #include "stheader.h" | |
31 | |
8585 | 32 #include "muxer.h" |
8471 | 33 |
34 #include "img_format.h" | |
35 #include "mp_image.h" | |
36 #include "vf.h" | |
37 | |
38 HMODULE WINAPI LoadLibraryA(LPCSTR); | |
39 FARPROC WINAPI GetProcAddress(HMODULE,LPCSTR); | |
40 int WINAPI FreeLibrary(HMODULE); | |
41 static HMODULE handler; | |
42 | |
43 static OSErr (*FindCodec)(CodecType cType, | |
44 CodecComponent specCodec, | |
45 CompressorComponent * compressor, | |
46 DecompressorComponent * decompressor); | |
47 static OSErr (*InitializeQTML)(long flags); | |
48 static PixMapHandle (*GetGWorldPixMap)(GWorldPtr offscreenGWorld); | |
49 static OSErr (*QTNewGWorldFromPtr)(GWorldPtr *gw, | |
50 OSType pixelFormat, | |
51 const Rect *boundsRect, | |
52 CTabHandle cTable, | |
53 /*GDHandle*/void* aGDevice, /*unused anyway*/ | |
54 GWorldFlags flags, | |
55 void *baseAddr, | |
56 long rowBytes); | |
57 static OSErr (*NewHandleClear)(Size byteCount); | |
58 static OSErr (*CompressSequenceBegin) ( | |
59 ImageSequence *seqID, | |
60 PixMapHandle src, | |
61 PixMapHandle prev, | |
62 const Rect *srcRect, | |
63 const Rect *prevRect, | |
64 short colorDepth, | |
65 CodecType cType, | |
66 CompressorComponent codec, | |
67 CodecQ spatialQuality, | |
68 CodecQ temporalQuality, | |
69 long keyFrameRate, | |
70 CTabHandle ctable, | |
71 CodecFlags flags, | |
72 ImageDescriptionHandle desc ); | |
73 | |
74 static OSErr (*CompressSequenceFrame) ( | |
75 ImageSequence seqID, | |
76 PixMapHandle src, | |
77 const Rect *srcRect, | |
78 CodecFlags flags, | |
79 Ptr data, | |
80 long *dataSize, | |
81 UInt8 *similarity, | |
82 ICMCompletionProcRecordPtr asyncCompletionProc ); | |
83 | |
84 static OSErr (*GetMaxCompressionSize)(PixMapHandle src, | |
85 const Rect *srcRect, | |
86 short colorDepth, | |
87 CodecQ quality, | |
88 CodecType cType, | |
89 CompressorComponent codec, | |
90 long *size ); | |
91 static OSErr (*CDSequenceEnd)( ImageSequence seqID ); | |
92 static Component (*FindNextComponent)(Component prev,ComponentDescription* desc); | |
93 static long (*CountComponents)(ComponentDescription* desc); | |
94 static OSErr (*GetComponentInfo)(Component prev,ComponentDescription* desc,Handle h1,Handle h2,Handle h3); | |
95 | |
96 | |
97 | |
98 //static int format=mmioFOURCC('S','V','Q','1'); | |
99 static int format=mmioFOURCC('S','V','Q','3'); | |
100 | |
101 | |
102 | |
103 //static void *frame_in; //input frame | |
104 static void *frame_prev; //previous frame | |
105 static void *frame_comp; //compressed frame | |
106 static GWorldPtr frame_GWorld_in = NULL;//a GWorld is some kind of description for a drawing environment | |
107 static GWorldPtr frame_GWorld_prev = NULL; | |
108 static Rect FrameRect; | |
109 | |
110 static CompressorComponent compressor; | |
111 static DecompressorComponent decompressor; | |
112 static ImageDescriptionHandle desc; | |
113 static ImageSequence seq; | |
114 | |
115 | |
116 | |
117 | |
118 | |
119 struct vf_priv_s { | |
8585 | 120 muxer_stream_t* mux; |
8471 | 121 //dv_encoder_t* enc; |
122 | |
123 }; | |
124 #define mux_v (vf->priv->mux) | |
125 | |
126 //===========================================================================// | |
127 | |
128 static int config(struct vf_instance_s* vf, | |
129 int width, int height, int d_width, int d_height, | |
130 unsigned int flags, unsigned int outfmt){ | |
131 OSErr cres; | |
132 ComponentDescription cdesc; | |
133 mux_v->bih->biWidth=width; | |
134 mux_v->bih->biHeight=height; | |
135 mux_v->bih->biSizeImage=width*height*2; | |
136 | |
137 | |
138 | |
139 memset(&desc,0,sizeof(cdesc)); | |
140 cdesc.componentType= (((unsigned char)'i')<<24)| | |
141 (((unsigned char)'m')<<16)| | |
142 (((unsigned char)'c')<<8)| | |
143 (((unsigned char)'o')); | |
144 | |
145 cdesc.componentSubType=bswap_32(format); | |
146 cdesc.componentManufacturer=0; | |
147 cdesc.componentFlags=0; | |
148 cdesc.componentFlagsMask=0; | |
149 | |
150 | |
151 printf("Count = %d\n",CountComponents(&cdesc)); | |
152 compressor=FindNextComponent(NULL,&cdesc); | |
153 if(!compressor){ | |
154 printf("Cannot find requested component\n"); | |
155 return(0); | |
156 } | |
157 printf("Found it! ID = 0x%X\n",compressor); | |
158 | |
159 // cres= FindCodec (fourcc,anyCodec,&compressor,&decompressor ); | |
160 // printf("FindCodec returned:%i compressor: 0x%X decompressor: 0x%X\n",cres&0xFFFF,compressor,decompressor); | |
161 | |
162 return 1; | |
163 } | |
164 | |
165 static int control(struct vf_instance_s* vf, int request, void* data){ | |
166 | |
167 return CONTROL_UNKNOWN; | |
168 } | |
169 | |
170 static int query_format(struct vf_instance_s* vf, unsigned int fmt){ | |
171 if(fmt==IMGFMT_YUY2) return 3; | |
172 return 0; | |
173 } | |
174 | |
175 static int codec_inited = 0; | |
176 | |
177 static int put_image(struct vf_instance_s* vf, mp_image_t *mpi){ | |
178 | |
179 OSErr cres; | |
180 long framesizemax; | |
8511 | 181 UInt8 similarity=0; |
8471 | 182 long compressedsize; |
183 int in_format=kYUVSPixelFormat; | |
184 int width = mpi->width; | |
185 int height = mpi->height; | |
186 int stride = width*2; | |
187 if(!codec_inited){ | |
188 FrameRect.top=0; | |
189 FrameRect.left=0; | |
190 FrameRect.right=width; | |
191 FrameRect.bottom=height; | |
192 cres = QTNewGWorldFromPtr( | |
193 &frame_GWorld_in, | |
194 in_format, | |
195 &FrameRect, | |
196 0, | |
197 0, | |
198 0, | |
199 mpi->planes[0], | |
200 stride); | |
201 printf("NewGWorldFromPtr returned:%i\n",cres&0xFFFF); | |
202 //dunno what todo about this | |
203 frame_prev = malloc(stride * height); | |
204 cres = QTNewGWorldFromPtr( | |
205 &frame_GWorld_prev, | |
206 in_format, | |
207 &FrameRect, | |
208 0, | |
209 0, | |
210 0, | |
211 frame_prev, | |
212 stride); | |
213 printf("height:%i width:%i stride:%i\n",height,width,stride); | |
214 printf("NewGWorldFromPtr returned:%i\n",cres&0xFFFF); | |
215 cres= GetMaxCompressionSize ( | |
216 GetGWorldPixMap(frame_GWorld_in), | |
217 &FrameRect, | |
218 24, | |
219 codecNormalQuality, | |
220 bswap_32(format), | |
221 compressor, | |
222 &framesizemax ); | |
223 printf("GetMaxCompressionSize returned:%i : MaxSize:%i\n",cres&0xFFFF,framesizemax); | |
224 frame_comp=malloc(framesizemax); | |
8511 | 225 |
8471 | 226 desc = (ImageDescriptionHandle)NewHandleClear(MAX_IDSIZE); //memory where the desc will be stored |
227 (*desc)->idSize=MAX_IDSIZE; | |
228 | |
229 cres= CompressSequenceBegin ( | |
230 &seq, | |
231 GetGWorldPixMap( frame_GWorld_in), | |
232 GetGWorldPixMap( frame_GWorld_prev), | |
233 &FrameRect, | |
234 &FrameRect, | |
235 24, // color depth | |
236 bswap_32(format), // fourcc | |
237 compressor, // codec component | |
238 codecNormalQuality, //codecNormalQuality, | |
239 codecMaxQuality, //codecNormalQuality, | |
8511 | 240 10*30, // keyframe rate |
8471 | 241 0, |
242 0, | |
243 desc); | |
244 printf("CompressSequenceBegin returned:%i\n",cres&0xFFFF); | |
245 printf("Sequence ID:%i\n",seq); | |
246 | |
247 dump_ImageDescription(*desc); | |
248 codec_inited++; | |
249 } | |
250 cres = CompressSequenceFrame ( | |
251 seq, | |
252 GetGWorldPixMap(frame_GWorld_in), | |
253 &FrameRect, | |
254 0, | |
255 (char*)mux_v->buffer, | |
256 &compressedsize, | |
257 &similarity, | |
258 0); | |
259 | |
260 if(cres&0xFFFF)printf("CompressSequenceFrame returned:%i\n",cres&0xFFFF); | |
8511 | 261 #if 0 |
8471 | 262 printf("Size %i->%i \n",stride*height,compressedsize); |
263 printf("Ratio: %i:1\n",(stride*height)/compressedsize); | |
264 #endif | |
9014
c671e9adbe22
Cleanup of the muxer API, func parameters muxer & muxer_f eliminated.
arpi
parents:
8733
diff
changeset
|
265 muxer_write_chunk(mux_v, compressedsize , similarity?0:0x10); |
8471 | 266 |
267 if(((*desc)->idSize)>MAX_IDSIZE){ | |
268 printf("FATAL! idSize=%d too big, increase MAX_IDSIZE in ve_qtvideo.c!\n",((*desc)->idSize)); | |
269 } else { | |
270 // according to QT docs, imagedescription may be changed while encoding | |
271 // a frame (even its size may (and does!) change!) | |
272 memcpy(mux_v->bih+1,*desc,(*desc)->idSize); | |
273 } | |
274 | |
275 return 1; | |
276 } | |
277 | |
278 //===========================================================================// | |
279 | |
280 static int vf_open(vf_instance_t *vf, char* args){ | |
281 OSErr cres = 1; | |
282 vf->config=config; | |
283 vf->control=control; | |
284 vf->query_format=query_format; | |
285 vf->put_image=put_image; | |
286 vf->priv=malloc(sizeof(struct vf_priv_s)); | |
287 memset(vf->priv,0,sizeof(struct vf_priv_s)); | |
8585 | 288 vf->priv->mux=(muxer_stream_t*)args; |
8471 | 289 |
290 mux_v->bih=malloc(sizeof(BITMAPINFOHEADER)+MAX_IDSIZE); | |
291 mux_v->bih->biSize=sizeof(BITMAPINFOHEADER)+MAX_IDSIZE; | |
292 mux_v->bih->biWidth=0; | |
293 mux_v->bih->biHeight=0; | |
294 mux_v->bih->biCompression=format; | |
295 mux_v->bih->biPlanes=1; | |
296 mux_v->bih->biBitCount=24; | |
297 | |
298 | |
299 Setup_LDT_Keeper(); | |
300 handler = LoadLibraryA("qtmlClient.dll"); | |
8733
478561617705
compiler warning fixes by Dominik Mierzejewski <dominik@rangers.eu.org>
arpi
parents:
8585
diff
changeset
|
301 InitializeQTML = (OSErr (*)(long))GetProcAddress(handler, "InitializeQTML"); |
478561617705
compiler warning fixes by Dominik Mierzejewski <dominik@rangers.eu.org>
arpi
parents:
8585
diff
changeset
|
302 GetGWorldPixMap = (PixMapHandle (*)(GWorldPtr))GetProcAddress(handler, "GetGWorldPixMap"); |
478561617705
compiler warning fixes by Dominik Mierzejewski <dominik@rangers.eu.org>
arpi
parents:
8585
diff
changeset
|
303 QTNewGWorldFromPtr = (OSErr(*)(GWorldPtr *,OSType,const Rect *,CTabHandle,void*,GWorldFlags,void *,long))GetProcAddress(handler, "QTNewGWorldFromPtr"); |
478561617705
compiler warning fixes by Dominik Mierzejewski <dominik@rangers.eu.org>
arpi
parents:
8585
diff
changeset
|
304 NewHandleClear = (OSErr(*)(Size))GetProcAddress(handler, "NewHandleClear"); |
478561617705
compiler warning fixes by Dominik Mierzejewski <dominik@rangers.eu.org>
arpi
parents:
8585
diff
changeset
|
305 FindCodec = (OSErr (*)(CodecType,CodecComponent,CompressorComponent *,DecompressorComponent *))GetProcAddress(handler,"FindCodec"); |
478561617705
compiler warning fixes by Dominik Mierzejewski <dominik@rangers.eu.org>
arpi
parents:
8585
diff
changeset
|
306 CompressSequenceBegin = (OSErr(*)(ImageSequence *,PixMapHandle,PixMapHandle,const Rect *,const Rect *,short,CodecType,CompressorComponent,CodecQ,CodecQ,long,CTabHandle,CodecFlags,ImageDescriptionHandle))GetProcAddress(handler,"CompressSequenceBegin"); |
478561617705
compiler warning fixes by Dominik Mierzejewski <dominik@rangers.eu.org>
arpi
parents:
8585
diff
changeset
|
307 CompressSequenceFrame = (OSErr(*)(ImageSequence,PixMapHandle,const Rect *,CodecFlags,Ptr,long *,UInt8 *,ICMCompletionProcRecordPtr))GetProcAddress(handler,"CompressSequenceFrame"); |
478561617705
compiler warning fixes by Dominik Mierzejewski <dominik@rangers.eu.org>
arpi
parents:
8585
diff
changeset
|
308 GetMaxCompressionSize = (OSErr(*)(PixMapHandle,const Rect *,short,CodecQ,CodecType,CompressorComponent,long *))GetProcAddress(handler,"GetMaxCompressionSize"); |
478561617705
compiler warning fixes by Dominik Mierzejewski <dominik@rangers.eu.org>
arpi
parents:
8585
diff
changeset
|
309 CDSequenceEnd = (OSErr (*)(ImageSequence))GetProcAddress(handler,"CDSequenceEnd"); |
478561617705
compiler warning fixes by Dominik Mierzejewski <dominik@rangers.eu.org>
arpi
parents:
8585
diff
changeset
|
310 FindNextComponent = (Component (*)(Component,ComponentDescription*))GetProcAddress(handler, "FindNextComponent"); |
478561617705
compiler warning fixes by Dominik Mierzejewski <dominik@rangers.eu.org>
arpi
parents:
8585
diff
changeset
|
311 CountComponents = (long (*)(ComponentDescription*))GetProcAddress(handler, "CountComponents"); |
478561617705
compiler warning fixes by Dominik Mierzejewski <dominik@rangers.eu.org>
arpi
parents:
8585
diff
changeset
|
312 GetComponentInfo = (OSErr (*)(Component,ComponentDescription*,Handle,Handle,Handle))GetProcAddress(handler, "GetComponentInfo"); |
8471 | 313 if(!InitializeQTML ||!CompressSequenceBegin){ |
314 printf("invalid qt DLL!\n"); | |
315 return 0; | |
316 } | |
317 //printf("%i,%i,%i\n",mmioFOURCC('S','V','Q','1'),'SVQ1',bswap_32(mmioFOURCC('S','V','Q','1'))); | |
318 cres=InitializeQTML(6+16); | |
319 printf("InitializeQTML returned %i\n",cres); | |
320 return 1; | |
321 } | |
322 | |
323 vf_info_t ve_info_qtvideo = { | |
324 "Quicktime video encoder using win32 DLLs", | |
325 "qtvideo", | |
326 "Sascha Sommer", | |
327 "for internal use by mencoder", | |
328 vf_open | |
329 }; | |
330 | |
331 //===========================================================================// | |
332 #endif |