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