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