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