Debian Codegraph @

plugins/libwin32/loader/dshow/outputpin.c

raw symbols SCIP
1
2 #include "wine/winerror.h"
3 #include "wine/windef.h"
4 #include "outputpin.h"
5 #include <stdio.h>
6 #include <string.h>
7 #include <stdlib.h>
8
9 /*
10 An object beyond interface IEnumMediaTypes.
11 Returned by COutputPin through call IPin::EnumMediaTypes().
12 */
13
14 static inline int output_unimplemented(const char* s, void* p)
15 {
16 Debug printf("%s(%p) called (UNIMPLEMENTED)", s, p);
17 return E_NOTIMPL;
18 }
19
20 typedef struct CEnumMediaTypes
21 {
22 IEnumMediaTypes_vt* vt;
23 DECLARE_IUNKNOWN();
24 AM_MEDIA_TYPE type;
25 GUID interfaces[2];
26 } CEnumMediaTypes;
27
28 struct _COutputMemPin
29 {
30 IMemInputPin_vt* vt;
31 DECLARE_IUNKNOWN();
32 char** frame_pointer;
33 long* frame_size_pointer;
34 MemAllocator* pAllocator;
35 COutputPin* parent;
36 };
37
38 static HRESULT STDCALL CEnumMediaTypes_Next(IEnumMediaTypes * This,
39 /* [in] */ ULONG cMediaTypes,
40 /* [size_is][out] */ AM_MEDIA_TYPE **ppMediaTypes,
41 /* [out] */ ULONG *pcFetched)
42 {
43 AM_MEDIA_TYPE* type = &((CEnumMediaTypes*)This)->type;
44 Debug printf("CEnumMediaTypes::Next(%p) called\n", This);
45 if (!ppMediaTypes)
46 return E_INVALIDARG;
47 if (!pcFetched && (cMediaTypes!=1))
48 return E_INVALIDARG;
49 if (cMediaTypes <= 0)
50 return 0;
51
52 if (pcFetched)
53 *pcFetched=1;
54 ppMediaTypes[0] = (AM_MEDIA_TYPE *)CoTaskMemAlloc(sizeof(AM_MEDIA_TYPE));
55 // copy structures - C can handle this...
56 **ppMediaTypes = *type;
57 if (ppMediaTypes[0]->pbFormat)
58 {
59 ppMediaTypes[0]->pbFormat=(char *)CoTaskMemAlloc(ppMediaTypes[0]->cbFormat);
60 memcpy(ppMediaTypes[0]->pbFormat, type->pbFormat, ppMediaTypes[0]->cbFormat);
61 }
62 if (cMediaTypes == 1)
63 return 0;
64 return 1;
65 }
66
67 /* I expect that these methods are unused. */
68 static HRESULT STDCALL CEnumMediaTypes_Skip(IEnumMediaTypes * This,
69 /* [in] */ ULONG cMediaTypes)
70 {
71 return output_unimplemented("CEnumMediaTypes::Skip", This);
72 }
73
74 static HRESULT STDCALL CEnumMediaTypes_Reset(IEnumMediaTypes * This)
75 {
76 Debug printf("CEnumMediaTypes::Reset(%p) called\n", This);
77 return 0;
78 }
79
80 static HRESULT STDCALL CEnumMediaTypes_Clone(IEnumMediaTypes * This,
81 /* [out] */ IEnumMediaTypes **ppEnum)
82 {
83 Debug printf("CEnumMediaTypes::Clone(%p) called\n", This);
84 return E_NOTIMPL;
85 }
86
87 static void CEnumMediaTypes_Destroy(CEnumMediaTypes* This)
88 {
89 free(This->vt);
90 free(This);
91 }
92
93 // IPin->IUnknown methods
94 IMPLEMENT_IUNKNOWN(CEnumMediaTypes)
95
96 static CEnumMediaTypes* CEnumMediaTypesCreate(const AM_MEDIA_TYPE* amt)
97 {
98 CEnumMediaTypes *This = (CEnumMediaTypes*) malloc(sizeof(CEnumMediaTypes)) ;
99
100 if (!This)
101 return NULL;
102
103 This->vt = (IEnumMediaTypes_vt*) malloc(sizeof(IEnumMediaTypes_vt));
104 if (!This->vt)
105 {
106 free(This);
107 return NULL;
108 }
109
110 This->refcount = 1;
111 This->type = *amt;
112
113 This->vt->QueryInterface = CEnumMediaTypes_QueryInterface;
114 This->vt->AddRef = CEnumMediaTypes_AddRef;
115 This->vt->Release = CEnumMediaTypes_Release;
116 This->vt->Next = CEnumMediaTypes_Next;
117 This->vt->Skip = CEnumMediaTypes_Skip;
118 This->vt->Reset = CEnumMediaTypes_Reset;
119 This->vt->Clone = CEnumMediaTypes_Clone;
120
121 This->interfaces[0] = IID_IUnknown;
122 This->interfaces[1] = IID_IEnumMediaTypes;
123
124 return This;
125 }
126
127
128 /*************
129 * COutputPin
130 *************/
131
132
133 static HRESULT STDCALL COutputPin_QueryInterface(IUnknown* This, const GUID* iid, void** ppv)
134 {
135 COutputPin* p = (COutputPin*) This;
136
137 Debug printf("COutputPin_QueryInterface(%p) called\n", This);
138 if (!ppv)
139 return E_INVALIDARG;
140
141 if (memcmp(iid, &IID_IUnknown, 16) == 0)
142 {
143 *ppv = p;
144 p->vt->AddRef(This);
145 return 0;
146 }
147 if (memcmp(iid, &IID_IMemInputPin, 16) == 0)
148 {
149 *ppv = p->mempin;
150 p->mempin->vt->AddRef((IUnknown*)*ppv);
151 return 0;
152 }
153
154 Debug printf("Unknown interface : %08x-%04x-%04x-%02x%02x-"
155 "%02x%02x%02x%02x%02x%02x\n",
156 iid->f1, iid->f2, iid->f3,
157 (unsigned char)iid->f4[1], (unsigned char)iid->f4[0],
158 (unsigned char)iid->f4[2], (unsigned char)iid->f4[3],
159 (unsigned char)iid->f4[4], (unsigned char)iid->f4[5],
160 (unsigned char)iid->f4[6], (unsigned char)iid->f4[7]);
161 return E_NOINTERFACE;
162 }
163
164 // IPin methods
165 static HRESULT STDCALL COutputPin_Connect(IPin * This,
166 /* [in] */ IPin *pReceivePin,
167 /* [in] */ /* const */ AM_MEDIA_TYPE *pmt)
168 {
169 Debug printf("COutputPin_Connect() called\n");
170 /*
171 *pmt=((COutputPin*)This)->type;
172 if(pmt->cbFormat>0)
173 {
174 pmt->pbFormat=CoTaskMemAlloc(pmt->cbFormat);
175 memcpy(pmt->pbFormat, ((COutputPin*)This)->type.pbFormat, pmt->cbFormat);
176 }
177 */
178 //return E_NOTIMPL;
179 return 0;// XXXXXXXXXXXXX CHECKME XXXXXXXXXXXXXXX
180 // if I put return 0; here, it crashes
181 }
182
183 static HRESULT STDCALL COutputPin_ReceiveConnection(IPin * This,
184 /* [in] */ IPin *pConnector,
185 /* [in] */ const AM_MEDIA_TYPE *pmt)
186 {
187 Debug printf("COutputPin_ReceiveConnection(%p) called\n", This);
188 ((COutputPin*)This)->remote = pConnector;
189 return 0;
190 }
191
192 static HRESULT STDCALL COutputPin_Disconnect(IPin * This)
193 {
194 Debug printf("COutputPin_Disconnect(%p) called\n", This);
195 return 1;
196 }
197
198 static HRESULT STDCALL COutputPin_ConnectedTo(IPin * This,
199 /* [out] */ IPin **pPin)
200 {
201 Debug printf("COutputPin_ConnectedTo(%p) called\n", This);
202 if (!pPin)
203 return E_INVALIDARG;
204 *pPin = ((COutputPin*)This)->remote;
205 return 0;
206 }
207
208 static HRESULT STDCALL COutputPin_ConnectionMediaType(IPin * This,
209 /* [out] */ AM_MEDIA_TYPE *pmt)
210 {
211 Debug printf("CInputPin::ConnectionMediaType() called\n");
212 if (!pmt)
213 return E_INVALIDARG;
214 *pmt = ((COutputPin*)This)->type;
215 if (pmt->cbFormat>0)
216 {
217 pmt->pbFormat=(char *)CoTaskMemAlloc(pmt->cbFormat);
218 memcpy(pmt->pbFormat, ((COutputPin*)This)->type.pbFormat, pmt->cbFormat);
219 }
220 return 0;
221 }
222
223 static HRESULT STDCALL COutputPin_QueryPinInfo(IPin * This,
224 /* [out] */ PIN_INFO *pInfo)
225 {
226 return output_unimplemented("COutputPin_QueryPinInfo", This);
227 }
228
229 static HRESULT STDCALL COutputPin_QueryDirection(IPin * This,
230 /* [out] */ PIN_DIRECTION *pPinDir)
231 {
232 Debug printf("COutputPin_QueryDirection(%p) called\n", This);
233 if (!pPinDir)
234 return E_INVALIDARG;
235 *pPinDir = PINDIR_INPUT;
236 return 0;
237 }
238
239 static HRESULT STDCALL COutputPin_QueryId(IPin * This,
240 /* [out] */ LPWSTR *Id)
241 {
242 return output_unimplemented("COutputPin_QueryId", This);
243 }
244
245 static HRESULT STDCALL COutputPin_QueryAccept(IPin * This,
246 /* [in] */ const AM_MEDIA_TYPE *pmt)
247 {
248 return output_unimplemented("COutputPin_QueryAccept", This);
249 }
250
251 static HRESULT STDCALL COutputPin_EnumMediaTypes(IPin * This,
252 /* [out] */ IEnumMediaTypes **ppEnum)
253 {
254 Debug printf("COutputPin_EnumMediaTypes() called\n");
255 if (!ppEnum)
256 return E_INVALIDARG;
257 *ppEnum = (IEnumMediaTypes*) CEnumMediaTypesCreate(&((COutputPin*)This)->type);
258 return 0;
259 }
260
261 static HRESULT STDCALL COutputPin_QueryInternalConnections(IPin * This,
262 /* [out] */ IPin **apPin,
263 /* [out][in] */ ULONG *nPin)
264 {
265 return output_unimplemented("COutputPin_QueryInternalConnections", This);
266 }
267
268 static HRESULT STDCALL COutputPin_EndOfStream(IPin * This)
269 {
270 return output_unimplemented("COutputPin_EndOfStream", This);
271 }
272
273 static HRESULT STDCALL COutputPin_BeginFlush(IPin * This)
274 {
275 return output_unimplemented("COutputPin_BeginFlush", This);
276 }
277
278 static HRESULT STDCALL COutputPin_EndFlush(IPin * This)
279 {
280 return output_unimplemented("COutputPin_EndFlush", This);
281 }
282
283 static HRESULT STDCALL COutputPin_NewSegment(IPin * This,
284 /* [in] */ REFERENCE_TIME tStart,
285 /* [in] */ REFERENCE_TIME tStop,
286 /* [in] */ double dRate)
287 {
288 Debug printf("COutputPin_NewSegment(%Ld,%Ld,%f) called\n",
289 tStart, tStop, dRate);
290 return 0;
291 }
292
293
294
295 // IMemInputPin->IUnknown methods
296
297 static HRESULT STDCALL COutputPin_M_QueryInterface(IUnknown* This, const GUID* iid, void** ppv)
298 {
299 COutputPin* p = (COutputPin*)This;
300
301 Debug printf("COutputPin_M_QueryInterface(%p) called\n", This);
302 if (!ppv)
303 return E_INVALIDARG;
304
305 if(!memcmp(iid, &IID_IUnknown, 16))
306 {
307 *ppv = p;
308 p->vt->AddRef(This);
309 return 0;
310 }
311 /*if(!memcmp(iid, &IID_IPin, 16))
312 {
313 COutputPin* ptr=(COutputPin*)(This-1);
314 *ppv=(void*)ptr;
315 AddRef((IUnknown*)ptr);
316 return 0;
317 }*/
318 if(!memcmp(iid, &IID_IMemInputPin, 16))
319 {
320 *ppv = p->mempin;
321 p->mempin->vt->AddRef(This);
322 return 0;
323 }
324 Debug printf("Unknown interface : %08x-%04x-%04x-%02x%02x-" \
325 "%02x%02x%02x%02x%02x%02x\n",
326 iid->f1, iid->f2, iid->f3,
327 (unsigned char)iid->f4[1], (unsigned char)iid->f4[0],
328 (unsigned char)iid->f4[2], (unsigned char)iid->f4[3],
329 (unsigned char)iid->f4[4], (unsigned char)iid->f4[5],
330 (unsigned char)iid->f4[6], (unsigned char)iid->f4[7]);
331 return E_NOINTERFACE;
332 }
333
334 // IMemInputPin methods
335
336 static HRESULT STDCALL COutputPin_GetAllocator(IMemInputPin* This,
337 /* [out] */ IMemAllocator** ppAllocator)
338 {
339 Debug printf("COutputPin_GetAllocator(%p, %p) called\n", This->vt, ppAllocator);
340 *ppAllocator = (IMemAllocator*) MemAllocatorCreate();
341 return 0;
342 }
343
344 static HRESULT STDCALL COutputPin_NotifyAllocator(IMemInputPin* This,
345 /* [in] */ IMemAllocator* pAllocator,
346 /* [in] */ int bReadOnly)
347 {
348 Debug printf("COutputPin_NotifyAllocator(%p, %p) called\n", This, pAllocator);
349 ((COutputMemPin*)This)->pAllocator = (MemAllocator*) pAllocator;
350 return 0;
351 }
352
353 static HRESULT STDCALL COutputPin_GetAllocatorRequirements(IMemInputPin* This,
354 /* [out] */ ALLOCATOR_PROPERTIES* pProps)
355 {
356 return output_unimplemented("COutputPin_GetAllocatorRequirements", This);
357 }
358
359 static HRESULT STDCALL COutputPin_Receive(IMemInputPin* This,
360 /* [in] */ IMediaSample* pSample)
361 {
362 COutputMemPin* mp = (COutputMemPin*)This;
363 char* pointer;
364 int len;
365
366 Debug printf("COutputPin_Receive(%p) called\n", This);
367 if (!pSample)
368 return E_INVALIDARG;
369 if (pSample->vt->GetPointer(pSample, (BYTE**) &pointer))
370 return -1;
371 len = pSample->vt->GetActualDataLength(pSample);
372 if (len == 0)
373 len = pSample->vt->GetSize(pSample);//for iv50
374 //if(me.frame_pointer)memcpy(me.frame_pointer, pointer, len);
375
376 if (mp->frame_pointer)
377 *(mp->frame_pointer) = pointer;
378 if (mp->frame_size_pointer)
379 *(mp->frame_size_pointer) = len;
380 /*
381 FILE* file=fopen("./uncompr.bmp", "wb");
382 char head[14]={0x42, 0x4D, 0x36, 0x10, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, 0x00};
383 *(int*)(&head[2])=len+0x36;
384 fwrite(head, 14, 1, file);
385 fwrite(&((VIDEOINFOHEADER*)me.type.pbFormat)->bmiHeader, sizeof(BITMAPINFOHEADER), 1, file);
386 fwrite(pointer, len, 1, file);
387 fclose(file);
388 */
389 // pSample->vt->Release((IUnknown*)pSample);
390
391 return 0;
392 }
393
394 static HRESULT STDCALL COutputPin_ReceiveMultiple(IMemInputPin * This,
395 /* [size_is][in] */ IMediaSample **pSamples,
396 /* [in] */ long nSamples,
397 /* [out] */ long *nSamplesProcessed)
398 {
399 return output_unimplemented("COutputPin_ReceiveMultiple", This);
400 }
401
402 static HRESULT STDCALL COutputPin_ReceiveCanBlock(IMemInputPin * This)
403 {
404 return output_unimplemented("COutputPin_ReceiveCanBlock", This);
405 }
406
407 static void COutputPin_SetFramePointer(COutputPin* This, char** z)
408 {
409 This->mempin->frame_pointer = z;
410 }
411
412 static void COutputPin_SetPointer2(COutputPin* This, char* p)
413 {
414 if (This->mempin->pAllocator)
415 // fixme
416 This->mempin->pAllocator->SetPointer(This->mempin->pAllocator, p);
417 }
418
419 static void COutputPin_SetFrameSizePointer(COutputPin* This, long* z)
420 {
421 This->mempin->frame_size_pointer = z;
422 }
423
424 static void COutputPin_SetNewFormat(COutputPin* This, const AM_MEDIA_TYPE* amt)
425 {
426 This->type = *amt;
427 }
428
429 static void COutputPin_Destroy(COutputPin* This)
430 {
431 if (This->mempin->vt)
432 free(This->mempin->vt);
433 if (This->mempin)
434 free(This->mempin);
435 if (This->vt)
436 free(This->vt);
437 free(This);
438 }
439
440 static HRESULT STDCALL COutputPin_AddRef(IUnknown* This)
441 {
442 Debug printf("COutputPin_AddRef(%p) called (%d)\n", This, ((COutputPin*)This)->refcount);
443 ((COutputPin*)This)->refcount++;
444 return 0;
445 }
446
447 static HRESULT STDCALL COutputPin_Release(IUnknown* This)
448 {
449 Debug printf("COutputPin_Release(%p) called (%d)\n", This, ((COutputPin*)This)->refcount);
450 if (--((COutputPin*)This)->refcount <= 0)
451 COutputPin_Destroy((COutputPin*)This);
452
453 return 0;
454 }
455
456 static HRESULT STDCALL COutputPin_M_AddRef(IUnknown* This)
457 {
458 COutputMemPin* p = (COutputMemPin*) This;
459 Debug printf("COutputPin_MAddRef(%p) called (%p, %d)\n", p, p->parent, p->parent->refcount);
460 p->parent->refcount++;
461 return 0;
462 }
463
464 static HRESULT STDCALL COutputPin_M_Release(IUnknown* This)
465 {
466 COutputMemPin* p = (COutputMemPin*) This;
467 Debug printf("COutputPin_MRelease(%p) called (%p, %d)\n",
468 p, p->parent, p->parent->refcount);
469 if (--p->parent->refcount <= 0)
470 COutputPin_Destroy(p->parent);
471 return 0;
472 }
473
474 COutputPin* COutputPinCreate(const AM_MEDIA_TYPE* amt)
475 {
476 COutputPin* This = (COutputPin*) malloc(sizeof(COutputPin));
477 IMemInputPin_vt* ivt;
478
479 if (!This)
480 return NULL;
481
482 This->vt = (IPin_vt*) malloc(sizeof(IPin_vt));
483 This->mempin = (COutputMemPin*) malloc(sizeof(COutputMemPin));
484 ivt = (IMemInputPin_vt*) malloc(sizeof(IMemInputPin_vt));
485
486 if (!This->vt || !This->mempin || !ivt)
487 {
488 COutputPin_Destroy(This);
489 return NULL;
490 }
491
492 This->mempin->vt = ivt;
493
494 This->refcount = 1;
495 This->remote = 0;
496 This->type = *amt;
497
498 This->vt->QueryInterface = COutputPin_QueryInterface;
499 This->vt->AddRef = COutputPin_AddRef;
500 This->vt->Release = COutputPin_Release;
501 This->vt->Connect = COutputPin_Connect;
502 This->vt->ReceiveConnection = COutputPin_ReceiveConnection;
503 This->vt->Disconnect = COutputPin_Disconnect;
504 This->vt->ConnectedTo = COutputPin_ConnectedTo;
505 This->vt->ConnectionMediaType = COutputPin_ConnectionMediaType;
506 This->vt->QueryPinInfo = COutputPin_QueryPinInfo;
507 This->vt->QueryDirection = COutputPin_QueryDirection;
508 This->vt->QueryId = COutputPin_QueryId;
509 This->vt->QueryAccept = COutputPin_QueryAccept;
510 This->vt->EnumMediaTypes = COutputPin_EnumMediaTypes;
511 This->vt->QueryInternalConnections = COutputPin_QueryInternalConnections;
512 This->vt->EndOfStream = COutputPin_EndOfStream;
513 This->vt->BeginFlush = COutputPin_BeginFlush;
514 This->vt->EndFlush = COutputPin_EndFlush;
515 This->vt->NewSegment = COutputPin_NewSegment;
516
517 This->mempin->vt->QueryInterface = COutputPin_M_QueryInterface;
518 This->mempin->vt->AddRef = COutputPin_M_AddRef;
519 This->mempin->vt->Release = COutputPin_M_Release;
520 This->mempin->vt->GetAllocator = COutputPin_GetAllocator;
521 This->mempin->vt->NotifyAllocator = COutputPin_NotifyAllocator;
522 This->mempin->vt->GetAllocatorRequirements = COutputPin_GetAllocatorRequirements;
523 This->mempin->vt->Receive = COutputPin_Receive;
524 This->mempin->vt->ReceiveMultiple = COutputPin_ReceiveMultiple;
525 This->mempin->vt->ReceiveCanBlock = COutputPin_ReceiveCanBlock;
526
527 This->mempin->frame_size_pointer = 0;
528 This->mempin->frame_pointer = 0;
529 This->mempin->pAllocator = 0;
530 This->mempin->refcount = 1;
531 This->mempin->parent = This;
532
533 This->SetPointer2 = COutputPin_SetPointer2;
534 This->SetFramePointer = COutputPin_SetFramePointer;
535 This->SetFrameSizePointer = COutputPin_SetFrameSizePointer;
536 This->SetNewFormat = COutputPin_SetNewFormat;
537
538 return This;
539 }