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