libmoldeo (Moldeo 1.0 Core)  1.0
libmoldeo es el conjunto de objetos y funciones, que permiten ejecutar las operaciones básicas de la plataforma Moldeo, y que compone su núcleo.
 Todo Clases Namespaces Archivos Funciones Variables 'typedefs' Enumeraciones Valores de enumeraciones Amigas 'defines' Grupos Páginas
moDsGraph.cpp
Ir a la documentación de este archivo.
1 /*******************************************************************************
2 
3  moDsGraph.cpp
4 
5  ****************************************************************************
6  * *
7  * This source is free software; you can redistribute it and/or modify *
8  * it under the terms of the GNU General Public License as published by *
9  * the Free Software Foundation; either version 2 of the License, or *
10  * (at your option) any later version. *
11  * *
12  * This code is distributed in the hope that it will be useful, but *
13  * WITHOUT ANY WARRANTY; without even the implied warranty of *
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
15  * General Public License for more details. *
16  * *
17  * A copy of the GNU General Public License is available on the World *
18  * Wide Web at <http://www.gnu.org/copyleft/gpl.html>. You can also *
19  * obtain it by writing to the Free Software Foundation, *
20  * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
21  * *
22  ****************************************************************************
23 
24  Copyright(C) 2006 Fabricio Costa
25 
26  Authors:
27  Fabricio Costa
28 
29 
30 *******************************************************************************/
31 
32 #include "moDsGraph.h"
33 
34 
35 #ifdef MO_DIRECTSHOW
36 
37 
38 //===========================================
39 //
40 // Class: moDsFramewwork
41 //
42 //===========================================
43 
44 moDsFramework::moDsFramework() {
45  m_pDevEnum = NULL;
46  m_pEnum = NULL;
47 }
48 
49 
50 moDsFramework::~moDsFramework() {
51 
52  if (m_pDevEnum!=NULL) {
53  m_pDevEnum->Release();
54  m_pDevEnum = NULL;
55  }
56 
57  if (m_pEnum!=NULL) {
58  m_pEnum->Release();
59  m_pEnum = NULL;
60  }
61 
62 }
63 
64 bool
65 moDsFramework::ShowError( HRESULT hr ) {
66  if(FAILED(hr))
67  {
68  TCHAR szErr[MAX_ERROR_TEXT_LEN];
69  DWORD res = AMGetErrorText(hr, szErr, MAX_ERROR_TEXT_LEN);
70  if(res == 0)
71  {
72  wsprintf(szErr, "Unknown Error: 0x%2x", hr);
73  }
74  MessageBox(0, szErr, TEXT("Error!"), MB_OK | MB_ICONERROR);
75  return false;
76  } else return true;
77 }
78 
79 
80 moCaptureDevices* moDsFramework::LoadCaptureDevices() {
81 
82  //DIRECT SHOW TEST//
83  HRESULT hr;
84 
85  // Create the System Device Enumerator.
86  if(m_pDevEnum==NULL) {
87  HRESULT hr = CoCreateInstance(CLSID_SystemDeviceEnum, NULL,
88  CLSCTX_INPROC_SERVER, IID_ICreateDevEnum,
89  reinterpret_cast<void**>(&m_pDevEnum));
90 
91  if(SUCCEEDED(hr) && m_pEnum==NULL)
92  {
93  // Create an enumerator for the video capture category.
94  hr = m_pDevEnum->CreateClassEnumerator(
95  CLSID_VideoInputDeviceCategory,
96  &m_pEnum, 0);
97  } else {
98  ShowError(hr);
99  return &m_CaptureDevices;
100  }
101  }
102 
103  if( m_pEnum )
104  {
105  m_pEnum->Reset();
106 
107  printf("Capture devices: \n");
108  IMoniker *pMoniker = NULL;
109  while(m_pEnum->Next(1, &pMoniker, NULL) == S_OK)
110  {
111  IPropertyBag *pPropBag;
112  hr = pMoniker->BindToStorage(0, 0, IID_IPropertyBag,
113  (void**)(&pPropBag));
114  if(FAILED(hr)) {
115  pMoniker->Release();
116  continue; // Skip this one, maybe the next one will work.
117  }
118  // Find the description or friendly name.
119  moText FriendlyName = "";
120  moText Description = "";
121  moText DevicePath = "";
122 
123  VARIANT varFriendlyName;
124  VARIANT varDescription;
125  VARIANT varDevicePath;
126 
127  VariantInit(&varFriendlyName);
128  VariantInit(&varDescription);
129  VariantInit(&varDevicePath);
130 
131  hr = pPropBag->Read(L"FriendlyName", &varFriendlyName, 0);
132  if(SUCCEEDED(hr)) FriendlyName =(short*)varFriendlyName.bstrVal;
133 
134  hr = pPropBag->Read(L"Description", &varDescription, 0);
135  if(SUCCEEDED(hr)) Description =(short*)varDescription.bstrVal;
136 
137  hr = pPropBag->Read(L"DevicePath", &varDevicePath, 0);
138  if(SUCCEEDED(hr)) DevicePath =(short*)varDevicePath.bstrVal;
139 
140  moCaptureDevice CapDev( FriendlyName, Description, DevicePath );
141  CapDev.Present(true);
142 
143  m_CaptureDevices.Add( CapDev );
144 
145  pPropBag->Release();
146  pMoniker->Release();
147  }
148  } else {
149  printf("WARNING: No capture devices available...\n");
150  return &m_CaptureDevices;
151  }
152 
153  return &m_CaptureDevices;
154 
155 }
156 
157 
158 
159 moCaptureDevices* moDsFramework::UpdateCaptureDevices() {
160 
161  HRESULT hr;
162  MOuint K;
163  moCaptureDevice CapDev;
164 
165  for( K=0; K < m_CaptureDevices.Count(); K++) {
166  CapDev = m_CaptureDevices.GetRef(K);
167  CapDev.Present( false );
168  m_CaptureDevices.Set( K , CapDev );
169  }
170 
171  if (m_pEnum) {
172  m_pEnum->Release();
173  m_pEnum = NULL;
174  }
175 
176  if (m_pDevEnum) {
177  hr = m_pDevEnum->CreateClassEnumerator(
178  CLSID_VideoInputDeviceCategory,
179  &m_pEnum, 0);
180  }
181 
182  if( m_pEnum )
183  {
184  m_pEnum->Reset();
185 
186  IMoniker *pMoniker = NULL;
187  while(m_pEnum->Next(1, &pMoniker, NULL) == S_OK)
188  {
189  IPropertyBag *pPropBag;
190  hr = pMoniker->BindToStorage(0, 0, IID_IPropertyBag,
191  (void**)(&pPropBag));
192  if(FAILED(hr)) {
193  pMoniker->Release();
194  continue; // Skip this one, maybe the next one will work.
195  }
196  // Find the description or friendly name.
197  moText FriendlyName = "";
198  moText Description = "";
199  moText DevicePath = "";
200 
201  VARIANT varFriendlyName;
202  VARIANT varDescription;
203  VARIANT varDevicePath;
204 
205  VariantInit(&varFriendlyName);
206  VariantInit(&varDescription);
207  VariantInit(&varDevicePath);
208 
209  hr = pPropBag->Read(L"FriendlyName", &varFriendlyName, 0);
210  if(SUCCEEDED(hr)) FriendlyName =(short*)varFriendlyName.bstrVal;
211 
212  hr = pPropBag->Read(L"Description", &varDescription, 0);
213  if(SUCCEEDED(hr)) Description =(short*)varDescription.bstrVal;
214 
215  hr = pPropBag->Read(L"DevicePath", &varDevicePath, 0);
216  if(SUCCEEDED(hr)) DevicePath =(short*)varDevicePath.bstrVal;
217 
218  bool CapDevFounded = false;
219  for( K=0; K < m_CaptureDevices.Count(); K++) {
220  if ( m_CaptureDevices.Get(K).GetPath() == DevicePath ) {
221  //AN OLD ONE... :-D CONFIRMS HIS PRESENCE
222  CapDev = m_CaptureDevices.GetRef(K);
223  CapDev.Present( true );
224  m_CaptureDevices.Set( K , CapDev );
225  CapDevFounded = true;
226  }
227  }
228 
229  if (!CapDevFounded) {
230  //A NEW ONE!!!!
231  m_CaptureDevices.Add( moCaptureDevice( FriendlyName, Description, DevicePath ) );
232  }
233 
234  pPropBag->Release();
235  pMoniker->Release();
236  }
237  } else {
238  //printf("WARNING: No capture devices available...\n");
239  return &m_CaptureDevices;
240  }
241 
242  return &m_CaptureDevices;
243 
244 }
245 
246 
247 bool
248 moDsFramework::CheckCaptureDevice( int i ) {
249 
250  HRESULT hr;
251 
252  if (m_pEnum) {
253  m_pEnum->Release();
254  m_pEnum = NULL;
255  }
256 
257 
258  if (m_pDevEnum) {
259  hr = m_pDevEnum->CreateClassEnumerator(
260  CLSID_VideoInputDeviceCategory,
261  &m_pEnum, 0);
262  }
263 
264  if( m_pEnum )
265  {
266  m_pEnum->Reset();
267 
268  IMoniker *pMoniker = NULL;
269  while(m_pEnum->Next(1, &pMoniker, NULL) == S_OK)
270  {
271  IPropertyBag *pPropBag;
272  hr = pMoniker->BindToStorage(0, 0, IID_IPropertyBag,
273  (void**)(&pPropBag));
274  if(FAILED(hr)) {
275  pMoniker->Release();
276  continue; // Skip this one, maybe the next one will work.
277  }
278  // Find the description or friendly name.
279  moText FriendlyName = "";
280  moText Description = "";
281  moText DevicePath = "";
282 
283  VARIANT varFriendlyName;
284  VARIANT varDescription;
285  VARIANT varDevicePath;
286 
287  VariantInit(&varFriendlyName);
288  VariantInit(&varDescription);
289  VariantInit(&varDevicePath);
290 
291  hr = pPropBag->Read(L"FriendlyName", &varFriendlyName, 0);
292  if(SUCCEEDED(hr)) FriendlyName =(short*)varFriendlyName.bstrVal;
293 
294  hr = pPropBag->Read(L"Description", &varDescription, 0);
295  if(SUCCEEDED(hr)) Description =(short*)varDescription.bstrVal;
296 
297  hr = pPropBag->Read(L"DevicePath", &varDevicePath, 0);
298  if(SUCCEEDED(hr)) DevicePath =(short*)varDevicePath.bstrVal;
299 
300  pPropBag->Release();
301  pMoniker->Release();
302  if ( DevicePath == m_CaptureDevices.Get(i).GetPath() )
303  return true;
304  }
305  } else {
306  return false;
307  }
308 
309  return false;
310 
311 }
312 
313 //===========================================
314 //
315 // Class: moDsGraph
316 //
317 //===========================================
318 
319 moDsGraph::moDsGraph() {
320 
321  m_pFilterGraph = NULL;
322  m_pMediaControl = NULL;
323  m_pMediaSeeking = NULL;
324 
325 //PREFERRED FILTERS:
326  m_pQuicktimeFilter = NULL;
327  m_pColorSpaceConverter = NULL;
328  m_pCaptureFilter = NULL;
329  m_pSourceFilter = NULL;
330  m_pFileSourceFilter = NULL;
331  m_pAviSplitter = NULL;
332  m_pSplitter = NULL;
333 
334  //QUICKTIME ALTERNATIVE
335  m_pQuicktimeDecoder = NULL;
336 
337  //FFDSHOW
338  m_pFfdshowFilter = NULL;
339 
340  //DV
341  m_pDVDecoderFilter = NULL;
342  //WEBCAM AVI
343  m_pAVIDecompressorFilter = NULL;
344 
345  //COMMON
346  m_pSampleGrabberBase = NULL;
347  m_pSampleGrabber = NULL;
348  m_pNullRenderer = NULL;
349 
350 //
351 
352 }
353 
354 moDsGraph::~moDsGraph() {
355  //last try to release objects
356  FinishGraph();
357 }
358 
359  //INIT METHODS
360 bool
361 moDsGraph::InitGraph() {
362 
363  HRESULT hr = S_OK;
364 
365  if(!m_pFilterGraph) {
366 
367  hr = CoCreateInstance(CLSID_FilterGraph, 0, CLSCTX_INPROC_SERVER,
368  IID_IGraphBuilder,(void**)&m_pFilterGraph);
369 
370  if(SUCCEEDED(hr)) {
371  hr = m_pFilterGraph->QueryInterface(IID_IMediaControl,(void**)&m_pMediaControl);
372  if(SUCCEEDED(hr)) {
373  hr = m_pFilterGraph->QueryInterface(IID_IMediaSeeking,(void**)&m_pMediaSeeking);
374  if(FAILED(hr))
375  ShowError(hr);
376  } else ShowError(hr);
377  } else ShowError(hr);
378  }
379 
380  return(m_pFilterGraph!=NULL);
381 }
382 
383 
384 bool
385 moDsGraph::FinishGraph() {
386 
387  ULONG rc;
388 
389  if (IsRunning()) {
390  Stop();
391  }
392 
393  if(m_pSampleGrabberBase) {
394  if(m_pSampleGrabber) {
395  HRESULT hr;
396  //Cancel Callback
397  hr = m_pSampleGrabber->SetCallback( NULL , 1 );
398  if(FAILED(hr))
399  return ShowError(hr);
400  }
401  rc = m_pSampleGrabberBase->Release();
402  m_pSampleGrabberBase = NULL;
403  m_pSampleGrabber = NULL;
404  }
405 
406  if(m_pCaptureFilter) {
407  rc = 1;
408  rc = m_pCaptureFilter->Release();
409  m_pCaptureFilter = NULL;
410  }
411 
412  if (m_pFileSourceFilter) {
413  rc = m_pFileSourceFilter->Release();
414  m_pFileSourceFilter = NULL;
415  }
416 
417  if(m_pSourceFilter) {
418  rc = m_pSourceFilter->Release();
419  m_pSourceFilter = NULL;
420  }
421 
422  if(m_pQuicktimeDecoder) {
423  rc = m_pQuicktimeDecoder->Release();
424  m_pQuicktimeDecoder = NULL;
425  }
426 
427  if(m_pFfdshowFilter) {
428  rc = m_pFfdshowFilter->Release();
429  m_pFfdshowFilter = NULL;
430  }
431 
432  if(m_pDVDecoderFilter) {
433  rc = m_pDVDecoderFilter->Release();
434  m_pDVDecoderFilter = NULL;
435  }
436 
437  if(m_pAVIDecompressorFilter) {
438  rc = m_pAVIDecompressorFilter->Release();
439  m_pAVIDecompressorFilter = NULL;
440  }
441 
442  if(m_pNullRenderer) {
443  rc = m_pNullRenderer->Release();
444  m_pNullRenderer = NULL;
445  }
446 
447  if(m_pAviSplitter) {
448  rc = m_pAviSplitter->Release();
449  m_pAviSplitter = NULL;
450  }
451 
452  if(m_pSplitter) {
453  rc = m_pSplitter->Release();
454  m_pSplitter = NULL;
455  }
456 
457  if(m_pMediaControl) {
458  rc = m_pMediaControl->Release();
459  m_pMediaControl = NULL;
460  }
461 
462  if(m_pMediaSeeking) {
463  rc = m_pMediaSeeking->Release();
464  m_pMediaSeeking = NULL;
465  }
466 
467  if(m_pFilterGraph) {
468  rc = m_pFilterGraph->Release();
469  m_pFilterGraph = NULL;
470  }
471 
472  return !(m_pFilterGraph && m_pCaptureFilter && m_pSampleGrabberBase);
473 }
474 
475 
476 bool
477 moDsGraph::CreateCaptureDeviceByPath( moText p_Path, IBaseFilter **ppF ) {
478 
479  if (! ppF) return false;
480  *ppF = 0;
481  IBaseFilter *pF = 0;
482 
483  ICreateDevEnum *pDevEnum = NULL;
484  IEnumMoniker *pEnum = NULL;
485 
486  // Create the System Device Enumerator.
487  HRESULT hr = CoCreateInstance(CLSID_SystemDeviceEnum, NULL,
488  CLSCTX_INPROC_SERVER, IID_ICreateDevEnum,
489  reinterpret_cast<void**>(&pDevEnum));
490 
491  if(SUCCEEDED(hr))
492  {
493  // Create an enumerator for the video capture category.
494  hr = pDevEnum->CreateClassEnumerator(
495  CLSID_VideoInputDeviceCategory,
496  &pEnum, 0);
497  } else return ShowError(hr);
498 
499  if( pEnum )
500  {
501  printf("DirectShow filters: \n");
502  IMoniker *pMoniker = NULL;
503  while(pEnum->Next(1, &pMoniker, NULL) == S_OK)
504  {
505  IPropertyBag *pPropBag;
506  hr = pMoniker->BindToStorage(0, 0, IID_IPropertyBag,
507  (void**)(&pPropBag));
508  if(FAILED(hr)) {
509  pMoniker->Release();
510  continue; // Skip this one, maybe the next one will work.
511  }
512  // Find the description or friendly name.
513  VARIANT varName;
514  VariantInit(&varName);
515  hr = pPropBag->Read(L"DevicePath", &varName, 0);
516  if(SUCCEEDED(hr)) {
517  moText fname;
518  fname =(short*)varName.bstrVal;
519  // To create an instance of the filter, do the following:
520  if( fname==p_Path ) {
521  hr = pMoniker->BindToObject(NULL, NULL, IID_IBaseFilter,(void**)ppF);
522  if(FAILED(hr)) {
523  pPropBag->Release();
524  pMoniker->Release();
525  pEnum->Release();
526  pDevEnum->Release();
527  return ShowError(hr);
528  } else {
529  pPropBag->Release();
530  pMoniker->Release();
531  pEnum->Release();
532  pDevEnum->Release();
533  return true;
534  }
535  }
536  }
537  pPropBag->Release();
538  pMoniker->Release();
539  }
540  pEnum->Release();
541  pDevEnum->Release();
542  } else {
543  printf("WARNING: No filter found with that path...\n");
544  pDevEnum->Release();
545  return false;
546  }
547 
548  return false;
549 
550 }
551 
552 bool
553 moDsGraph::CreateFilterByName( moText p_Name, IBaseFilter **ppF ) // Receives a pointer to the filter.
554 {
555  if (! ppF) return false;
556  *ppF = 0;
557  IBaseFilter *pF = 0;
558 
559  ICreateDevEnum *pDevEnum = NULL;
560  IEnumMoniker *pEnum = NULL;
561 
562  // Create the System Device Enumerator.
563  HRESULT hr = CoCreateInstance(CLSID_SystemDeviceEnum, NULL,
564  CLSCTX_INPROC_SERVER, IID_ICreateDevEnum,
565  reinterpret_cast<void**>(&pDevEnum));
566 
567  if(SUCCEEDED(hr))
568  {
569  // Create an enumerator for the video capture category.
570  hr = pDevEnum->CreateClassEnumerator(
571  CLSID_LegacyAmFilterCategory,
572  &pEnum, 0);
573  } else return ShowError(hr);
574 
575  if( pEnum )
576  {
577  printf("DirectShow filters: \n");
578  IMoniker *pMoniker = NULL;
579  while(pEnum->Next(1, &pMoniker, NULL) == S_OK)
580  {
581  IPropertyBag *pPropBag;
582  hr = pMoniker->BindToStorage(0, 0, IID_IPropertyBag,
583  (void**)(&pPropBag));
584  if(FAILED(hr)) {
585  pMoniker->Release();
586  continue; // Skip this one, maybe the next one will work.
587  }
588  // Find the description or friendly name.
589  VARIANT varName;
590  VariantInit(&varName);
591  hr = pPropBag->Read(L"Description", &varName, 0);
592  if(FAILED(hr)) {
593  hr = pPropBag->Read(L"FriendlyName", &varName, 0);
594  printf( "FriendlyName: " );
595  //wprintf((const wchar_t *)varName.bstrVal);
596  printf( "\n" );
597  } else {
598  printf( "Description: " );
599  //wprintf((const wchar_t *)varName.bstrVal);
600  printf( "\n" );
601  }
602  if(SUCCEEDED(hr)) {
603  moText fname;
604  fname =(short*)varName.bstrVal;
605  // To create an instance of the f.ilter, do the following:
606  if( fname==p_Name ) {
607  hr = pMoniker->BindToObject(NULL, NULL, IID_IBaseFilter,(void**)ppF);
608  if(FAILED(hr)) {
609  pPropBag->Release();
610  pMoniker->Release();
611  pEnum->Release();
612  pDevEnum->Release();
613  return ShowError(hr);
614  } else {
615  pPropBag->Release();
616  pMoniker->Release();
617  pEnum->Release();
618  pDevEnum->Release();
619  return true;
620  }
621  }
622  }
623  pPropBag->Release();
624  pMoniker->Release();
625  }
626  pEnum->Release();
627  pDevEnum->Release();
628  } else {
629  printf("WARNING: No filter found with that name...\n");
630  pDevEnum->Release();
631  return false;
632  }
633 
634  return false;
635 }
636 
637 //FILTER METHODS
638 bool
639 moDsGraph::SetCaptureDevice( moText deviceport, MOint idevice) {
640 
641  ICreateDevEnum *pDevEnum = NULL;
642  IEnumMoniker *pEnum = NULL;
643  int ndevice = 0;
644 
645  //DIRECT SHOW TEST//
646 
647  // Create the System Device Enumerator.
648  HRESULT hr = CoCreateInstance(CLSID_SystemDeviceEnum, NULL,
649  CLSCTX_INPROC_SERVER, IID_ICreateDevEnum,
650  reinterpret_cast<void**>(&pDevEnum));
651 
652  if(SUCCEEDED(hr))
653  {
654  // Create an enumerator for the video capture category.
655  hr = pDevEnum->CreateClassEnumerator(
656  CLSID_VideoInputDeviceCategory,
657  &pEnum, 0);
658  } else return ShowError(hr);
659 
660  if( pEnum )
661  {
662  printf("Capture devices: \n");
663  IMoniker *pMoniker = NULL;
664  while(pEnum->Next(1, &pMoniker, NULL) == S_OK)
665  {
666  IPropertyBag *pPropBag;
667  hr = pMoniker->BindToStorage(0, 0, IID_IPropertyBag,
668  (void**)(&pPropBag));
669  if(FAILED(hr)) {
670  pMoniker->Release();
671  continue; // Skip this one, maybe the next one will work.
672  }
673  // Find the description or friendly name.
674  VARIANT varName;
675  VariantInit(&varName);
676  hr = pPropBag->Read(L"Description", &varName, 0);
677  if(FAILED(hr)) {
678  hr = pPropBag->Read(L"FriendlyName", &varName, 0);
679  printf( "FriendlyName: " );
680  //wprintf_s((const wchar_t *)varName.bstrVal);
681  printf( "\n" );
682  } else {
683  printf( "Description: " );
684  //wprintf_s((const wchar_t *)varName.bstrVal);
685  printf( "\n" );
686  }
687  if(SUCCEEDED(hr)) {
688  moText fname;
689  fname =(short*)varName.bstrVal;
690  // To create an instance of the filter, do the following:
691  hr = pMoniker->BindToObject(NULL, NULL, IID_IBaseFilter,(void**)&m_pCaptureFilter);
692  if(FAILED(hr)) {
693  pPropBag->Release();
694  pMoniker->Release();
695  pEnum->Release();
696  pDevEnum->Release();
697  return ShowError(hr);
698  } else {
699  pPropBag->Release();
700  pMoniker->Release();
701  pEnum->Release();
702  pDevEnum->Release();
703  return true;
704  }
705  /*
706  if((fname=="Microsoft DV Camera and VCR" || fname=="Sony DV Device" || fname=="Canon DV Device") &&(deviceport=="IEEE1394") ) {
707  if(ndevice==idevice) {
708  hr = pMoniker->BindToObject(NULL, NULL, IID_IBaseFilter,(void**)&m_pCaptureFilter);
709  if(FAILED(hr)) {
710  pPropBag->Release();
711  pMoniker->Release();
712  return ShowError(hr);
713  } else {
714  pPropBag->Release();
715  pMoniker->Release();
716  return true;
717  }
718 
719  } else ndevice++;
720  } else if((fname=="D-Link VGA Webcam" || fname=="VideoCAM Messenger" || fname=="Acer OrbiCam") &&(deviceport=="WEBCAM") ) {
721  if(ndevice==idevice) {
722  hr = pMoniker->BindToObject(NULL, NULL, IID_IBaseFilter,(void**)&m_pCaptureFilter);
723  if(FAILED(hr)) {
724  pPropBag->Release();
725  pMoniker->Release();
726  return ShowError(hr);
727  } else {
728  pPropBag->Release();
729  pMoniker->Release();
730  return true;
731  }
732  } else ndevice++;
733  }
734  */
735  }
736  pPropBag->Release();
737  pMoniker->Release();
738  }
739  pEnum->Release();
740  pDevEnum->Release();
741  } else {
742  printf("WARNING: No capture devices available...\n");
743  pDevEnum->Release();
744  return false;
745  }
746 
747  return false;
748 }
749 
750 //Displaying a Filter's Property Pages
751 void
752 moDsGraph::ShowConfigureDialog(IBaseFilter *pFilter) {
753 
754  /* Obtain the filter's IBaseFilter interface. (Not shown) */
755  ISpecifyPropertyPages *pProp;
756  HRESULT hr = pFilter->QueryInterface(IID_ISpecifyPropertyPages, (void **)&pProp);
757  if (SUCCEEDED(hr))
758  {
759  // Get the filter's name and IUnknown pointer.
760  FILTER_INFO FilterInfo;
761  hr = pFilter->QueryFilterInfo(&FilterInfo);
762  IUnknown *pFilterUnk;
763  pFilter->QueryInterface(IID_IUnknown, (void **)&pFilterUnk);
764 
765  // Show the page.
766  CAUUID caGUID;
767  pProp->GetPages(&caGUID);
768  pProp->Release();
769  OleCreatePropertyFrame(
770  NULL, // Parent window
771  0, 0, // Reserved
772  FilterInfo.achName, // Caption for the dialog box
773  1, // Number of objects (just the filter)
774  &pFilterUnk, // Array of object pointers.
775  caGUID.cElems, // Number of property pages
776  caGUID.pElems, // Array of property page CLSIDs
777  0, // Locale identifier
778  0, NULL // Reserved
779  );
780 
781  // Clean up.
782  pFilterUnk->Release();
783  FilterInfo.pGraph->Release();
784  CoTaskMemFree(caGUID.pElems);
785  }
786 
787 
788 
789 
790 }
791 
792 bool
793 moDsGraph::BuildLiveGraph( moBucketsPool *pBucketsPool, moCaptureDevice p_capdev) {
794 
795  HRESULT hr;
796 
797  IPin* pPinSource;
798  IPin* pPinDecoderIn;
799  IPin* pPinDecoderOut;
800  IPin* pGrabPinIn;
801  IPin* pGrabPinOut;
802  IPin* pRendererPin;
803 
804  //media type enumaration
805  IEnumMediaTypes* ppEnum;
806  AM_MEDIA_TYPE* pMediaTypes;
807 
808 
809 
810  //SOURCE
811  if ( p_capdev.GetPath() != "" ) {
812 
813  if(CreateCaptureDeviceByPath( p_capdev.GetPath(), &m_pCaptureFilter )) {
814  hr = m_pFilterGraph->AddFilter(m_pCaptureFilter, L"Capture Device");
815 
816  //ShowConfigureDialog(m_pCaptureFilter);
817 
818  if(SUCCEEDED(hr)) {
819 
820  pPinSource = GetOutPin( m_pCaptureFilter ,0 );
821 
822  } else return ShowError(hr);
823  } else return false;
824 
825  } else return false;
826 
827  //CHEQUEAMOS EL FORMATO DEL PIN
828  bool isdv = false;
829 
830  AM_MEDIA_TYPE MTPreferredResolution;
831  AM_MEDIA_TYPE MTDefaultResolution;
832 
833  MTDefaultResolution.majortype = GUID_NULL;
834  MTPreferredResolution.majortype = GUID_NULL;
835 
836  moVideoFormat LastFormat;
837  hr = pPinSource->EnumMediaTypes( &ppEnum);
838 
839  if(SUCCEEDED(hr)) {
840 
841  while( ppEnum->Next( 1, &pMediaTypes, NULL) == S_OK ) {
842 
843  if ( pMediaTypes->majortype == MEDIATYPE_Video ) { //VIDEO
844 
845  if ( pMediaTypes->subtype == MEDIASUBTYPE_dvsl ||
846  pMediaTypes->subtype == MEDIASUBTYPE_dvsd ||
847  pMediaTypes->subtype == MEDIASUBTYPE_dvhd ) {
848 
849  isdv = true;
850 
851  SetVideoFormat( pMediaTypes );
852 
853  if (MTDefaultResolution.majortype == GUID_NULL)
854  MTDefaultResolution = (*pMediaTypes);
855 
856  if (p_capdev.GetVideoFormat().m_Width > 0) {
857  if ( p_capdev.GetVideoFormat().m_Width == m_VideoFormat.m_Width &&
858  p_capdev.GetVideoFormat().m_Height == m_VideoFormat.m_Height &&
859  p_capdev.GetVideoFormat().m_BitCount == m_VideoFormat.m_BitCount ) {
860 
861  MTPreferredResolution = (*pMediaTypes);
862 
863  }
864  }
865 
866  LastFormat = m_VideoFormat;
867  //continuamos hasta terminar...
868  } else {//EVERYTHING ELSE MAY BE UNCOMPRESSED
869  if ( pMediaTypes->formattype == FORMAT_VideoInfo ) {
870 
871  SetVideoFormat( pMediaTypes );
872 
873  if (MTDefaultResolution.majortype == GUID_NULL)
874  MTDefaultResolution = (*pMediaTypes);
875 
876  if (p_capdev.GetVideoFormat().m_Width > 0) {
877  if ( p_capdev.GetVideoFormat().m_Width == m_VideoFormat.m_Width &&
878  p_capdev.GetVideoFormat().m_Height == m_VideoFormat.m_Height &&
879  p_capdev.GetVideoFormat().m_BitCount == m_VideoFormat.m_BitCount ) {
880 
881  MTPreferredResolution = (*pMediaTypes);
882 
883  }
884  }
885 
886  LastFormat = m_VideoFormat;
887  }
888  }
889  }
890  }
891  }
892  ppEnum->Release();
893 
894  //FORMATO DV
895  if ( isdv ) {
896 
897  //DV DECODER
898  if(!m_pDVDecoderFilter) {
899  hr = CoCreateInstance(CLSID_DVVideoCodec, NULL, CLSCTX_INPROC_SERVER,
900  IID_IBaseFilter,(void**)&m_pDVDecoderFilter);
901  if(SUCCEEDED(hr)) {
902  hr = m_pFilterGraph->AddFilter(m_pDVDecoderFilter, L"DV Decoder");
903  if(SUCCEEDED(hr)) {
904  //mostrar la pagina de configuracion del fitro
905  //sacar pines
906  pPinDecoderIn = GetInPin( m_pDVDecoderFilter ,0 );
907  pPinDecoderOut = GetOutPin( m_pDVDecoderFilter ,0 );
908 
909  hr = m_pFilterGraph->Connect( pPinSource , pPinDecoderIn );
910 
911  if(FAILED(hr))
912  return ShowError(hr);
913  } else return ShowError(hr);
914  } else return ShowError(hr);
915  } else return ShowError(hr);
916 
917  } else {
918 
919  //AVI DECOMPRESSOR
920  if(!m_pAVIDecompressorFilter) {
921  hr = CoCreateInstance(CLSID_AVIDec, NULL, CLSCTX_INPROC_SERVER,
922  IID_IBaseFilter,(void**)&m_pAVIDecompressorFilter);
923  if(SUCCEEDED(hr)) {
924  hr = m_pFilterGraph->AddFilter(m_pAVIDecompressorFilter, L"AVI Decompressor");
925  if(SUCCEEDED(hr)) {
926  //mostrar la pagina de configuracion del fitro
927  //sacar pines
928  pPinDecoderIn = GetInPin( m_pAVIDecompressorFilter ,0 );
929  pPinDecoderOut = GetOutPin( m_pAVIDecompressorFilter ,0 );
930 
931  //hr = m_pFilterGraph->Connect( pPinSource , pPinDecoderIn );
932 
933  if ( MTPreferredResolution.majortype != GUID_NULL ) {
934  hr = pPinSource->Connect( pPinDecoderIn , &MTPreferredResolution );
935  if (SUCCEEDED(hr)) {
936  SetVideoFormat( &MTPreferredResolution );
937  } else {
938  hr = pPinSource->Connect( pPinDecoderIn , &MTDefaultResolution );
939  if (SUCCEEDED(hr)) {
940  SetVideoFormat( &MTDefaultResolution );
941  } else {
942  hr = m_pFilterGraph->Connect( pPinSource, pPinDecoderIn );
943  if (SUCCEEDED(hr)) {
944  AM_MEDIA_TYPE mt;
945  if ( pPinDecoderIn->ConnectionMediaType(&mt) == S_OK ) {
946  SetVideoFormat( &mt );
947  }
948  }
949  }
950  }
951  } else {
952  hr = m_pFilterGraph->Connect( pPinSource, pPinDecoderIn );
953  //hr = pPinSource->Connect( pPinDecoderIn , &MTDefaultResolution );
954  //SetVideoFormat( &MTDefaultResolution );
955  }
956 
957  if(FAILED(hr))
958  return ShowError(hr);
959  } else return ShowError(hr);
960  } else return ShowError(hr);
961  } else return ShowError(hr);
962  }
963 
964  //FRAME GRABBER
965  if(!m_pSampleGrabberBase) {
966  hr = CoCreateInstance(CLSID_SampleGrabber, NULL, CLSCTX_INPROC_SERVER,
967  IID_IBaseFilter,(void**)&m_pSampleGrabberBase);
968  if(SUCCEEDED(hr)) {
969  hr = m_pFilterGraph->AddFilter(m_pSampleGrabberBase, L"Sample Grabber");
970  if(SUCCEEDED(hr)) {
971 
972  pGrabPinIn = GetInPin( m_pSampleGrabberBase ,0 );
973  pGrabPinOut = GetOutPin( m_pSampleGrabberBase ,0 );
974  m_pSampleGrabberBase->QueryInterface(IID_ISampleGrabber,(void**)&m_pSampleGrabber);
975 
976  //SET RGB24 BEFORE CONNECTING SampleGrabber
977  CMediaType GrabType;
978  GrabType.SetType( &MEDIATYPE_Video );
979  GrabType.SetSubtype( &MEDIASUBTYPE_RGB24 );
980  hr = m_pSampleGrabber->SetMediaType( &GrabType );
981  if(FAILED(hr))
982  return ShowError(hr);
983  hr = m_pSampleGrabber->SetBufferSamples(FALSE);
984  if(FAILED(hr))
985  return ShowError(hr);
986 
987  //set the pool receiving the samples
988  m_CB.SetBucketsPool( pBucketsPool );
989 
990  hr = m_pSampleGrabber->SetCallback( &m_CB, 1 );
991  if(FAILED(hr))
992  return ShowError(hr);
993  hr = m_pFilterGraph->Connect( pPinDecoderOut , pGrabPinIn );
994  if(FAILED(hr))
995  return ShowError(hr);
996  } else return ShowError(hr);
997  } else return ShowError(hr);
998  } else return ShowError(hr);
999 
1000  //NULL RENDERER
1001  if(!m_pNullRenderer) {
1002  hr = CoCreateInstance(CLSID_NullRenderer, NULL, CLSCTX_INPROC_SERVER,
1003  IID_IBaseFilter,(void**)&m_pNullRenderer);
1004  if(SUCCEEDED(hr)) {
1005  hr = m_pFilterGraph->AddFilter(m_pNullRenderer, L"Null Renderer");
1006  if(SUCCEEDED(hr)) {
1007  pRendererPin = GetInPin( m_pNullRenderer, 0);
1008 
1009  hr = m_pFilterGraph->Connect( pGrabPinOut, pRendererPin);
1010  if(FAILED(hr))
1011  return ShowError(hr);
1012  else {
1013  AM_MEDIA_TYPE mt;
1014  if ( pRendererPin->ConnectionMediaType(&mt) == S_OK ) {
1015  SetVideoFormat( &mt );
1016  }
1017  return true;
1018  }
1019  } else return ShowError(hr);
1020  } else return ShowError(hr);
1021  } else return ShowError(hr);
1022 
1023  return false;
1024 }
1025 
1026 
1027 bool
1028 moDsGraph::BuildLiveDVGraph( moBucketsPool *pBucketsPool, MOint idevice) {
1029 
1030  HRESULT hr;
1031 
1032  IPin* pPinSource;
1033  IPin* pPinDecoderIn;
1034  IPin* pPinDecoderOut;
1035  IPin* pGrabPinIn;
1036  IPin* pGrabPinOut;
1037  IPin* pRendererPin;
1038 
1039  //SOURCE
1040  if( SetCaptureDevice( "IEEE1394", idevice ) ) {
1041  hr = m_pFilterGraph->AddFilter(m_pCaptureFilter, L"DV Cam");
1042  if(SUCCEEDED(hr)) {
1043  pPinSource = GetOutPin( m_pCaptureFilter ,0 );
1044  } else return ShowError(hr);
1045  } else return false;
1046 
1047 
1048  //DV DECODER
1049  if(!m_pDVDecoderFilter) {
1050  hr = CoCreateInstance(CLSID_DVVideoCodec, NULL, CLSCTX_INPROC_SERVER,
1051  IID_IBaseFilter,(void**)&m_pDVDecoderFilter);
1052  if(SUCCEEDED(hr)) {
1053  hr = m_pFilterGraph->AddFilter(m_pDVDecoderFilter, L"DV Decoder");
1054  if(SUCCEEDED(hr)) {
1055  //mostrar la pagina de configuracion del fitro
1056  //sacar pines
1057  pPinDecoderIn = GetInPin( m_pDVDecoderFilter ,0 );
1058  pPinDecoderOut = GetOutPin( m_pDVDecoderFilter ,0 );
1059 
1060  hr = m_pFilterGraph->Connect( pPinSource , pPinDecoderIn );
1061 
1062  if(FAILED(hr))
1063  return ShowError(hr);
1064  } else return ShowError(hr);
1065  } else return ShowError(hr);
1066  } else return ShowError(hr);
1067 
1068 
1069  //FRAME GRABBER
1070  if(!m_pSampleGrabberBase) {
1071  hr = CoCreateInstance(CLSID_SampleGrabber, NULL, CLSCTX_INPROC_SERVER,
1072  IID_IBaseFilter,(void**)&m_pSampleGrabberBase);
1073  if(SUCCEEDED(hr)) {
1074  hr = m_pFilterGraph->AddFilter(m_pSampleGrabberBase, L"Sample Grabber");
1075  if(SUCCEEDED(hr)) {
1076 
1077  pGrabPinIn = GetInPin( m_pSampleGrabberBase ,0 );
1078  pGrabPinOut = GetOutPin( m_pSampleGrabberBase ,0 );
1079  m_pSampleGrabberBase->QueryInterface(IID_ISampleGrabber,(void**)&m_pSampleGrabber);
1080 
1081  //SET RGB24 BEFORE CONNECTING SampleGrabber
1082  CMediaType GrabType;
1083  GrabType.SetType( &MEDIATYPE_Video );
1084  GrabType.SetSubtype( &MEDIASUBTYPE_RGB24 );
1085  hr = m_pSampleGrabber->SetMediaType( &GrabType );
1086  if(FAILED(hr)) ShowError(hr);
1087  hr = m_pSampleGrabber->SetBufferSamples(FALSE);
1088  if(FAILED(hr)) ShowError(hr);
1089 
1090  //set the pool receiving the samples
1091  m_CB.SetBucketsPool( pBucketsPool );
1092 
1093  hr = m_pSampleGrabber->SetCallback( &m_CB, 1 );
1094  if(FAILED(hr)) ShowError(hr);
1095  hr = m_pFilterGraph->Connect( pPinDecoderOut , pGrabPinIn );
1096  if(FAILED(hr))
1097  return ShowError(hr);
1098  } else return ShowError(hr);
1099  } else return ShowError(hr);
1100  } else return ShowError(hr);
1101 
1102  //NULL RENDERER
1103  if(!m_pNullRenderer) {
1104  hr = CoCreateInstance(CLSID_NullRenderer, NULL, CLSCTX_INPROC_SERVER,
1105  IID_IBaseFilter,(void**)&m_pNullRenderer);
1106  if(SUCCEEDED(hr)) {
1107  hr = m_pFilterGraph->AddFilter(m_pNullRenderer, L"Null Renderer");
1108  if(SUCCEEDED(hr)) {
1109  pRendererPin = GetInPin( m_pNullRenderer, 0);
1110 
1111  hr = m_pFilterGraph->Connect( pGrabPinOut, pRendererPin);
1112  if(FAILED(hr))
1113  return ShowError(hr);
1114  } else return ShowError(hr);
1115  } else return ShowError(hr);
1116  } else return ShowError(hr);
1117 
1118  AM_MEDIA_TYPE mt;
1119  if ( pRendererPin->ConnectionMediaType(&mt) == S_OK ) {
1120  SetVideoFormat( &mt );
1121  }
1122 
1123  return true;
1124 }
1125 
1126 
1127 
1128 bool
1129 moDsGraph::BuildLiveWebcamGraph( moBucketsPool *pBucketsPool, MOint idevice) {
1130 
1131  HRESULT hr;
1132 
1133  IPin* pPinSource;
1134  IPin* pPinDecoderIn;
1135  IPin* pPinDecoderOut;
1136  IPin* pGrabPinIn;
1137  IPin* pGrabPinOut;
1138  IPin* pRendererPin;
1139 
1140  //SOURCE
1141  if( SetCaptureDevice("WEBCAM", idevice) ) {
1142  hr = m_pFilterGraph->AddFilter(m_pCaptureFilter, L"Web Cam");
1143  if(SUCCEEDED(hr)) {
1144  pPinSource = GetOutPin( m_pCaptureFilter ,0 );
1145  } else return ShowError(hr);
1146  } else return false;
1147 
1148 
1149  //AVI DECOMPRESSOR
1150  if(!m_pAVIDecompressorFilter) {
1151  hr = CoCreateInstance(CLSID_AVIDec, NULL, CLSCTX_INPROC_SERVER,
1152  IID_IBaseFilter,(void**)&m_pAVIDecompressorFilter);
1153  if(SUCCEEDED(hr)) {
1154  hr = m_pFilterGraph->AddFilter(m_pAVIDecompressorFilter, L"AVI Decompressor");
1155  if(SUCCEEDED(hr)) {
1156  //mostrar la pagina de configuracion del fitro
1157  //sacar pines
1158  pPinDecoderIn = GetInPin( m_pAVIDecompressorFilter ,0 );
1159  pPinDecoderOut = GetOutPin( m_pAVIDecompressorFilter ,0 );
1160 
1161  hr = m_pFilterGraph->Connect( pPinSource , pPinDecoderIn );
1162 
1163  if(FAILED(hr))
1164  return ShowError(hr);
1165  } else return ShowError(hr);
1166  } else return ShowError(hr);
1167  } else return ShowError(hr);
1168 
1169 
1170  //FRAME GRABBER
1171  if(!m_pSampleGrabberBase) {
1172  hr = CoCreateInstance(CLSID_SampleGrabber, NULL, CLSCTX_INPROC_SERVER,
1173  IID_IBaseFilter,(void**)&m_pSampleGrabberBase);
1174  if(SUCCEEDED(hr)) {
1175  hr = m_pFilterGraph->AddFilter(m_pSampleGrabberBase, L"Sample Grabber");
1176  if(SUCCEEDED(hr)) {
1177 
1178  pGrabPinIn = GetInPin( m_pSampleGrabberBase ,0 );
1179  pGrabPinOut = GetOutPin( m_pSampleGrabberBase ,0 );
1180  m_pSampleGrabberBase->QueryInterface(IID_ISampleGrabber,(void**)&m_pSampleGrabber);
1181 
1182  //SET RGB24 BEFORE CONNECTING SampleGrabber
1183  CMediaType GrabType;
1184  GrabType.SetType( &MEDIATYPE_Video );
1185  GrabType.SetSubtype( &MEDIASUBTYPE_RGB24 );
1186  hr = m_pSampleGrabber->SetMediaType( &GrabType );
1187  if(FAILED(hr))
1188  return ShowError(hr);
1189  hr = m_pSampleGrabber->SetBufferSamples(FALSE);
1190  if(FAILED(hr))
1191  return ShowError(hr);
1192 
1193  //set the pool receiving the samples
1194  m_CB.SetBucketsPool( pBucketsPool );
1195 
1196  hr = m_pSampleGrabber->SetCallback( &m_CB, 1 );
1197  if(FAILED(hr))
1198  return ShowError(hr);
1199  hr = m_pFilterGraph->Connect( pPinDecoderOut , pGrabPinIn );
1200  if(FAILED(hr))
1201  return ShowError(hr);
1202  } else return ShowError(hr);
1203  } else return ShowError(hr);
1204  } else return ShowError(hr);
1205 
1206  //NULL RENDERER
1207  if(!m_pNullRenderer) {
1208  hr = CoCreateInstance(CLSID_NullRenderer, NULL, CLSCTX_INPROC_SERVER,
1209  IID_IBaseFilter,(void**)&m_pNullRenderer);
1210  if(SUCCEEDED(hr)) {
1211  hr = m_pFilterGraph->AddFilter(m_pNullRenderer, L"Null Renderer");
1212  if(SUCCEEDED(hr)) {
1213  pRendererPin = GetInPin( m_pNullRenderer, 0);
1214 
1215  hr = m_pFilterGraph->Connect( pGrabPinOut, pRendererPin);
1216  if(FAILED(hr))
1217  return ShowError(hr);
1218  } else return ShowError(hr);
1219  } else return ShowError(hr);
1220  } else return ShowError(hr);
1221 
1222 
1223  return true;
1224 }
1225 
1226 bool moDsGraph::BuildLiveQTVideoGraph( moText filename , moBucketsPool *pBucketsPool ) {
1227 
1228  HRESULT hr;
1229 
1230  IPin* pPinSource;
1231  IPin* pPinDecoderIn;
1232  IPin* pPinDecoderOut;
1233  IPin* pGrabPinIn;
1234  IPin* pGrabPinOut;
1235  IPin* pRendererPin;
1236 
1237  bool bQTAlternative;
1238  moText QTFilter = "";
1239 
1240  //QUICKTIME....CYBERLINK QT ALTERNATIVE
1241  if( !m_pQuicktimeFilter ) {
1242  //QT ALTERNATIVE 1.3 QT 6
1243  QTFilter = "CyberLink QuickTime Source Filter";
1244  bQTAlternative = CreateFilterByName( QTFilter, &m_pQuicktimeFilter );
1245 
1246  //QT ALTERNATIVE 1.7 QT 7
1247  /*
1248  if (!bQTAlternative) {
1249  QTFilter = "Nero Digital Parser";
1250  bQTAlternative = CreateFilterByName( QTFilter, &m_pQuicktimeFilter );
1251  }
1252  */
1253 
1254  if ( bQTAlternative ) {
1255  hr = m_pQuicktimeFilter->QueryInterface(IID_IFileSourceFilter,(void**)&m_pFileSourceFilter);
1256  if(SUCCEEDED(hr)) {
1257  WCHAR wFileName[MAX_PATH];
1258  MultiByteToWideChar(CP_ACP, 0, filename, -1, wFileName, MAX_PATH);
1259  //(LPCOLESTR)filename
1260  hr = m_pFileSourceFilter->Load( wFileName, NULL );
1261  if(SUCCEEDED(hr)) {
1262  hr = m_pFilterGraph->AddFilter(m_pQuicktimeFilter, L"File Source");
1263  if(SUCCEEDED(hr)) {
1264  pPinSource = GetOutPin( m_pQuicktimeFilter ,0 );
1265  } else return ShowError(hr);
1266  } else return ShowError(hr);
1267  }
1268  } else return false;
1269  }
1270 
1271  //CHECK MEDIA TYPE:for debugging
1272  //CheckMediaType( pPinSource );
1273 
1274  if (QTFilter == "CyberLink QuickTime Source Filter") {
1275  //COLOR SPACE CONVERTER
1276  if(!m_pColorSpaceConverter) {
1277  hr = CoCreateInstance( CLSID_Colour, NULL, CLSCTX_INPROC_SERVER,
1278  IID_IBaseFilter,(void**)&m_pColorSpaceConverter);
1279  if( SUCCEEDED(hr) ) {
1280  hr = m_pFilterGraph->AddFilter( m_pColorSpaceConverter, L"Color Space Converter");
1281  if( SUCCEEDED(hr) ) {
1282  //mostrar la pagina de configuracion del fitro
1283  //sacar pines
1284  pPinDecoderIn = GetInPin( m_pColorSpaceConverter ,0 );
1285  pPinDecoderOut = GetOutPin( m_pColorSpaceConverter ,0 );
1286 
1287  hr = m_pFilterGraph->Connect( pPinSource , pPinDecoderIn );
1288 
1289  if( FAILED(hr) )
1290  return ShowError(hr);
1291 
1292  } else return ShowError(hr);
1293  } else return ShowError(hr);
1294  } else return ShowError(hr);
1295  } else {
1296  if (!m_pQuicktimeDecoder) {
1297  if ( CreateFilterByName( moText("Nero QuickTime(tm) Video Decoder"), &m_pQuicktimeDecoder ) ) {
1298  hr = m_pFilterGraph->AddFilter( m_pQuicktimeDecoder, L"Nero QuickTime(tm) Video Decoder");
1299  if( SUCCEEDED(hr) ) {
1300  //mostrar la pagina de configuracion del fitro
1301  //sacar pines
1302  pPinDecoderIn = GetInPin( m_pQuicktimeDecoder ,0 );
1303  pPinDecoderOut = GetOutPin( m_pQuicktimeDecoder ,0 );
1304 
1305  hr = m_pFilterGraph->Connect( pPinSource , pPinDecoderIn );
1306 
1307  if( FAILED(hr) )
1308  return ShowError(hr);
1309 
1310  } else return ShowError(hr);
1311  } else return false;
1312  }
1313 
1314  }
1315 
1316  //FRAME GRABBER
1317  if(!m_pSampleGrabberBase) {
1318  hr = CoCreateInstance(CLSID_SampleGrabber, NULL, CLSCTX_INPROC_SERVER,
1319  IID_IBaseFilter,(void**)&m_pSampleGrabberBase);
1320  if(SUCCEEDED(hr)) {
1321  hr = m_pFilterGraph->AddFilter(m_pSampleGrabberBase, L"Sample Grabber");
1322  if(SUCCEEDED(hr)) {
1323 
1324  pGrabPinIn = GetInPin( m_pSampleGrabberBase ,0 );
1325  pGrabPinOut = GetOutPin( m_pSampleGrabberBase ,0 );
1326  m_pSampleGrabberBase->QueryInterface(IID_ISampleGrabber,(void**)&m_pSampleGrabber);
1327 
1328  //SET RGB24 BEFORE CONNECTING SampleGrabber
1329  CMediaType GrabType;
1330  GrabType.SetType( &MEDIATYPE_Video );
1331  GrabType.SetSubtype( &MEDIASUBTYPE_RGB24 );
1332  hr = m_pSampleGrabber->SetMediaType( &GrabType );
1333  if(FAILED(hr))
1334  return ShowError(hr);
1335  hr = m_pSampleGrabber->SetBufferSamples(FALSE);
1336  if(FAILED(hr))
1337  return ShowError(hr);
1338 
1339  //set the pool receiving the samples
1340  m_CB.SetBucketsPool( pBucketsPool );
1341 
1342  hr = m_pSampleGrabber->SetCallback( &m_CB, 1 );
1343  if(FAILED(hr))
1344  return ShowError(hr);
1345  hr = m_pFilterGraph->Connect( pPinDecoderOut , pGrabPinIn );
1346  if(FAILED(hr))
1347  return ShowError(hr);
1348  } else return ShowError(hr);
1349  } else return ShowError(hr);
1350  } else return ShowError(hr);
1351 
1352  //NULL RENDERER
1353  if(!m_pNullRenderer) {
1354  hr = CoCreateInstance(CLSID_NullRenderer, NULL, CLSCTX_INPROC_SERVER,
1355  IID_IBaseFilter,(void**)&m_pNullRenderer);
1356  if(SUCCEEDED(hr)) {
1357  hr = m_pFilterGraph->AddFilter(m_pNullRenderer, L"Null Renderer");
1358  if(SUCCEEDED(hr)) {
1359  pRendererPin = GetInPin( m_pNullRenderer, 0);
1360  hr = m_pFilterGraph->Connect( pGrabPinOut, pRendererPin);
1361  if(FAILED(hr))
1362  return ShowError(hr);
1363  } else return ShowError(hr);
1364  } else return ShowError(hr);
1365  } else return ShowError(hr);
1366 
1367  AM_MEDIA_TYPE mt;
1368  if ( pRendererPin->ConnectionMediaType(&mt) == S_OK ) {
1369  SetVideoFormat( &mt );
1370  }
1371 
1372  return true;
1373 
1374 
1375 }
1376 
1377 bool moDsGraph::BuildLiveVideoGraph( moText filename , moBucketsPool *pBucketsPool ) {
1378 
1379  HRESULT hr;
1380 
1381  IPin* pPinSource;
1382  IPin* pPinSplitterIn;
1383  IPin* pPinSplitterOut;
1384  IPin* pPinDecoderIn;
1385  IPin* pPinDecoderOut;
1386  IPin* pGrabPinIn;
1387  IPin* pGrabPinOut;
1388  IPin* pRendererPin;
1389 
1390  //media type enumaration
1391  IEnumMediaTypes* ppEnum;
1392  AM_MEDIA_TYPE* pMediaTypes;
1393 
1394  //AVI OR MPEG
1395  if( !m_pSourceFilter ) {
1396  hr = CoCreateInstance(CLSID_AsyncReader, NULL, CLSCTX_INPROC_SERVER,
1397  IID_IBaseFilter,(void**)&m_pSourceFilter );
1398  if(SUCCEEDED(hr)) {
1399  hr = m_pSourceFilter->QueryInterface(IID_IFileSourceFilter,(void**)&m_pFileSourceFilter);
1400  if(SUCCEEDED(hr)) {
1401  WCHAR wFileName[MAX_PATH];
1402  MultiByteToWideChar(CP_ACP, 0, filename, -1, wFileName, MAX_PATH);
1403  //(LPCOLESTR)filename
1404  hr = m_pFileSourceFilter->Load( wFileName, NULL );
1405  if(SUCCEEDED(hr)) {
1406  hr = m_pFilterGraph->AddFilter(m_pSourceFilter, L"File Source");
1407  if(SUCCEEDED(hr)) {
1408  pPinSource = GetOutPin( m_pSourceFilter ,0 );
1409  } else return ShowError(hr);
1410  } else return ShowError(hr);
1411  } else return ShowError(hr);
1412  } else return ShowError(hr);
1413  } else return false;
1414 
1415 
1416  //CHEQUEAMOS EL FORMATO DEL PIN
1417  hr = pPinSource->EnumMediaTypes( &ppEnum);
1418  if(SUCCEEDED(hr)) {
1419  while( ppEnum->Next( 1, &pMediaTypes, NULL) == S_OK ) {
1420  if ( pMediaTypes->majortype == MEDIATYPE_Stream ) { //ALL STREAMS
1421 
1422  bool passed = false;
1423 
1424  if ( pMediaTypes->subtype == MEDIASUBTYPE_Avi ) {
1425  //put the AviSplitter
1426  if(!m_pSplitter) {
1427  hr = CoCreateInstance( CLSID_AviSplitter, NULL, CLSCTX_INPROC_SERVER,
1428  IID_IBaseFilter,(void**)&m_pSplitter);
1429  if (SUCCEEDED(hr)) passed = true;
1430  } else return ShowError(hr);
1431  } else if ( pMediaTypes->subtype == MEDIASUBTYPE_MPEG1Video ||
1432  pMediaTypes->subtype == MEDIASUBTYPE_MPEG1System ||
1433  pMediaTypes->subtype == MEDIASUBTYPE_MPEG1VideoCD) {
1434  if(!m_pSplitter) {
1435  hr = CoCreateInstance( CLSID_MPEG1Splitter, NULL, CLSCTX_INPROC_SERVER,
1436  IID_IBaseFilter,(void**)&m_pSplitter);
1437  if (SUCCEEDED(hr)) passed = true;
1438  } else return ShowError(hr);
1439  } else if ( pMediaTypes->subtype == MEDIASUBTYPE_MPEG2_PROGRAM ) {
1440  return false;
1441  }
1442 
1443  if (passed) {
1444  if (m_pSplitter) {
1445  if( SUCCEEDED(hr) ) {
1446  hr = m_pFilterGraph->AddFilter( m_pSplitter, L"Splitter");
1447  if( SUCCEEDED(hr) ) {
1448  //sacar pines
1449  pPinSplitterIn = GetInPin( m_pSplitter ,0 );
1450 
1451  hr = m_pFilterGraph->Connect( pPinSource , pPinSplitterIn );
1452 
1453  if( FAILED(hr) )
1454  return ShowError(hr);
1455  else
1456  pPinSplitterOut = GetOutPin( m_pSplitter ,0 );
1457 
1458  } else return ShowError(hr);
1459  } else return ShowError(hr);
1460  }
1461  break;
1462  }
1463  }
1464  }
1465  }
1466  ppEnum->Release();
1467 
1468  bool isdv = false;
1469  if (pPinSplitterOut) {
1470  hr = pPinSplitterOut->EnumMediaTypes( &ppEnum);
1471  if(SUCCEEDED(hr)) {
1472  while( ppEnum->Next( 1, &pMediaTypes, NULL) == S_OK ) {
1473  if (pMediaTypes->majortype == MEDIATYPE_Video) {
1474  if ( pMediaTypes->subtype == MEDIASUBTYPE_dvsd ||
1475  pMediaTypes->subtype == MEDIASUBTYPE_dvsl ||
1476  pMediaTypes->subtype == MEDIASUBTYPE_dvhd ) {
1477  isdv = true;
1478  SetVideoFormat( pMediaTypes );
1479  break;
1480  } else if ( pMediaTypes->formattype == FORMAT_MPEGVideo ) {
1481  SetVideoFormat( pMediaTypes );
1482  break;
1483  } else if ( pMediaTypes->formattype == FORMAT_MPEG2Video ) {
1484  SetVideoFormat( pMediaTypes );
1485  break;
1486  } else if ( pMediaTypes->formattype == FORMAT_VideoInfo ||
1487  pMediaTypes->formattype == FORMAT_VideoInfo2 ) {
1488  SetVideoFormat( pMediaTypes );
1489  break;
1490  }
1491  }
1492  }
1493  }
1494  ppEnum->Release();
1495  } else return false;
1496 
1497  //ELEGIMOS EL CODEC...
1498  //aqui debemos agregar segun el nivel de calidad deseado
1499  //y el decoder de DV elegido o bien el AVI decompressor
1500  bool bHighQuality = true;
1501 
1502  if ( isdv ) {
1503  //DV DECODER
1504  if(!m_pDVDecoderFilter) {
1505  if (bHighQuality) {
1506  hr = CoCreateInstance(CLSID_AVIDec, NULL, CLSCTX_INPROC_SERVER,
1507  IID_IBaseFilter,(void**)&m_pDVDecoderFilter);
1508  } else {
1509  hr = CoCreateInstance( CLSID_DVVideoCodec, NULL, CLSCTX_INPROC_SERVER,
1510  IID_IBaseFilter,(void**)&m_pDVDecoderFilter);
1511  }
1512  if( SUCCEEDED(hr) ) {
1513  hr = m_pFilterGraph->AddFilter( m_pDVDecoderFilter, L"DV Decoder");
1514  if( SUCCEEDED(hr) ) {
1515  //mostrar la pagina de configuracion del fitro
1516  //sacar pines
1517  pPinDecoderIn = GetInPin( m_pDVDecoderFilter ,0 );
1518  pPinDecoderOut = GetOutPin( m_pDVDecoderFilter ,0 );
1519 
1520  hr = m_pFilterGraph->Connect( pPinSplitterOut , pPinDecoderIn );
1521 
1522  if( FAILED(hr) )
1523  return ShowError(hr);
1524 
1525  } else return ShowError(hr);
1526  } else return ShowError(hr);
1527  } else return ShowError(hr);
1528 
1529  } else {
1530  //ALL OTHERS TRY TO OPEN WITH FFDSHOW
1531  //if ( CreateFilterByName(moText("ffdshow MPEG-4 Video Decoder"), &m_pFfdshowFilter) ) {
1532  hr = CoCreateInstance(CLSID_AVIDec, NULL, CLSCTX_INPROC_SERVER, IID_IBaseFilter,(void**)&m_pFfdshowFilter);
1533  if (SUCCEEDED(hr)) {
1534 
1535  hr = m_pFilterGraph->AddFilter( m_pFfdshowFilter, L"ffdshow MPEG-4 Video Decoder");
1536 
1537  if( SUCCEEDED(hr) ) {
1538  //mostrar la pagina de configuracion del fitro
1539  //sacar pines
1540  pPinDecoderIn = GetInPin( m_pFfdshowFilter ,0 );
1541  pPinDecoderOut = GetOutPin( m_pFfdshowFilter ,0 );
1542 
1543  hr = m_pFilterGraph->Connect( pPinSplitterOut , pPinDecoderIn );
1544 
1545  if( FAILED(hr) ) {
1546 
1547  hr = m_pFilterGraph->RemoveFilter( m_pFfdshowFilter );
1548 
1549  m_pFfdshowFilter->Release();
1550  m_pFfdshowFilter = NULL;
1551 
1552  pPinDecoderIn->Release();
1553  pPinDecoderIn = NULL;
1554 
1555  pPinDecoderOut->Release();
1556  pPinDecoderOut = NULL;
1557 
1558  if (CreateFilterByName(moText("ffdshow MPEG-4 Video Decoder"), &m_pFfdshowFilter)) {
1559  hr = m_pFilterGraph->AddFilter( m_pFfdshowFilter, L"ffdshow MPEG-4 Video Decoder");
1560  } else {
1561  printf("ffdshow Filter not found\n");
1562  _flushall();
1563  return false;
1564  }
1565  if( FAILED(hr) )
1566  return ShowError(hr);
1567  }
1568 
1569  } else return ShowError(hr);
1570 
1571  } else {
1572  printf("Filter not found\n");
1573  return false;
1574  }
1575  }
1576 
1577  //FRAME GRABBER
1578  if(!m_pSampleGrabberBase) {
1579  hr = CoCreateInstance(CLSID_SampleGrabber, NULL, CLSCTX_INPROC_SERVER,
1580  IID_IBaseFilter,(void**)&m_pSampleGrabberBase);
1581  if(SUCCEEDED(hr)) {
1582  hr = m_pFilterGraph->AddFilter(m_pSampleGrabberBase, L"Sample Grabber");
1583  if(SUCCEEDED(hr)) {
1584 
1585  pGrabPinIn = GetInPin( m_pSampleGrabberBase ,0 );
1586  pGrabPinOut = GetOutPin( m_pSampleGrabberBase ,0 );
1587  m_pSampleGrabberBase->QueryInterface(IID_ISampleGrabber,(void**)&m_pSampleGrabber);
1588 
1589  //SET RGB24 BEFORE CONNECTING SampleGrabber
1590  CMediaType GrabType;
1591  GrabType.SetType( &MEDIATYPE_Video );
1592  GrabType.SetSubtype( &MEDIASUBTYPE_RGB24 );
1593  hr = m_pSampleGrabber->SetMediaType( &GrabType );
1594  if(FAILED(hr))
1595  return ShowError(hr);
1596  hr = m_pSampleGrabber->SetBufferSamples(FALSE);
1597  if(FAILED(hr))
1598  return ShowError(hr);
1599 
1600  //set the pool receiving the samples
1601  m_CB.SetBucketsPool( pBucketsPool );
1602 
1603  hr = m_pSampleGrabber->SetCallback( &m_CB, 1 );
1604  if(FAILED(hr))
1605  return ShowError(hr);
1606  hr = m_pFilterGraph->Connect( pPinDecoderOut , pGrabPinIn );
1607  if(FAILED(hr))
1608  return ShowError(hr);
1609  } else return ShowError(hr);
1610  } else return ShowError(hr);
1611  } else return ShowError(hr);
1612 
1613  //NULL RENDERER
1614  if(!m_pNullRenderer) {
1615  hr = CoCreateInstance(CLSID_NullRenderer, NULL, CLSCTX_INPROC_SERVER,
1616  IID_IBaseFilter,(void**)&m_pNullRenderer);
1617  if(SUCCEEDED(hr)) {
1618  hr = m_pFilterGraph->AddFilter(m_pNullRenderer, L"Null Renderer");
1619  if(SUCCEEDED(hr)) {
1620  pRendererPin = GetInPin( m_pNullRenderer, 0);
1621  hr = m_pFilterGraph->Connect( pGrabPinOut, pRendererPin);
1622  if(FAILED(hr))
1623  return ShowError(hr);
1624  } else return ShowError(hr);
1625  } else return ShowError(hr);
1626  } else return ShowError(hr);
1627 
1628  AM_MEDIA_TYPE mt;
1629  if ( pRendererPin->ConnectionMediaType(&mt) == S_OK ) {
1630  SetVideoFormat( &mt );
1631  }
1632 
1633  return true;
1634 
1635 }
1636 
1637 
1638 //CONTROL METHODS
1639 void
1640 moDsGraph::Play() {
1641  HRESULT hr;
1642 
1643  if(m_pFilterGraph) {
1644  if(m_pMediaControl) {
1645  hr = m_pMediaControl->Run();
1646  if(FAILED(hr))
1647  ShowError(hr);
1648  }
1649  }
1650 }
1651 
1652 void
1653 moDsGraph::Stop() {
1654  HRESULT hr;
1655  if(m_pFilterGraph) {
1656  if(m_pMediaControl) {
1657  hr = m_pMediaControl->Stop();
1658  if(FAILED(hr))
1659  ShowError(hr);
1660  }
1661  }
1662 }
1663 
1664 void
1665 moDsGraph::Pause() {
1666  HRESULT hr;
1667  if(m_pFilterGraph) {
1668  if(m_pMediaControl) {
1669  hr = m_pMediaControl->Pause();
1670  if(FAILED(hr))
1671  ShowError(hr);
1672  }
1673  }
1674 }
1675 
1676 void
1677 moDsGraph::Seek( MOuint frame ) {
1678  HRESULT hr;
1679  if(m_pFilterGraph) {
1680  if(m_pMediaControl) {
1681  if(m_pMediaSeeking) {
1682  hr = m_pMediaSeeking->IsFormatSupported(&TIME_FORMAT_FRAME);
1683  if( hr == S_OK ) {
1684  hr = m_pMediaSeeking->SetTimeFormat(&TIME_FORMAT_FRAME);
1685  if(SUCCEEDED(hr))
1686  {
1687  // Seek to frame number 20.
1688  LONGLONG rtNow = frame;
1689  hr = m_pMediaSeeking->SetPositions(
1690  &rtNow, AM_SEEKING_AbsolutePositioning,
1691  NULL, AM_SEEKING_NoPositioning);
1692  }
1693  if(FAILED(hr))
1694  ShowError(hr);
1695  } else if ( hr == S_FALSE ) {
1696  if (frame>10) {
1697  //skip
1698  hr = S_OK;
1699 
1700  }
1701  hr = m_pMediaSeeking->IsFormatSupported(&TIME_FORMAT_MEDIA_TIME);
1702  if ( hr == S_OK ) {
1703  hr = m_pMediaSeeking->SetTimeFormat(&TIME_FORMAT_MEDIA_TIME);
1704  if(SUCCEEDED(hr))
1705  {
1706  // Seek to frame number 20.
1707  LONGLONG rtNow = frame;
1708 
1709  rtNow = rtNow * m_VideoFormat.m_TimePerFrame;
1710  /*
1711  if ( m_VideoFormat.m_VideoMode == PAL ) {
1712  rtNow = rtNow * 400000; //en cuadros
1713  } else if ( m_VideoMode == moDsGraph::NTSC ) {
1714  rtNow = rtNow * 333667; //en cuadros
1715  }
1716  */
1717  hr = m_pMediaSeeking->SetPositions(
1718  &rtNow, AM_SEEKING_AbsolutePositioning,
1719  NULL, AM_SEEKING_NoPositioning);
1720  }
1721  if(FAILED(hr))
1722  ShowError(hr);
1723  } else ShowError(hr);
1724  } else ShowError(hr);
1725  }
1726  }
1727  }
1728 }
1729 
1730 MOulong
1731 moDsGraph::GetFramesLength() {
1732  HRESULT hr;
1733  LONGLONG dur = 0;
1734  if(m_pFilterGraph) {
1735  if(m_pMediaControl) {
1736  hr = m_pMediaSeeking->IsFormatSupported(&TIME_FORMAT_FRAME);
1737  if( hr == S_OK ) {
1738  hr = m_pMediaSeeking->SetTimeFormat(&TIME_FORMAT_FRAME);
1739  if(SUCCEEDED(hr))
1740  {
1741  if(m_pMediaSeeking) {
1742  hr = m_pMediaSeeking->GetDuration(&dur);
1743  if(SUCCEEDED(hr))
1744  return dur;
1745  else ShowError(hr);
1746  }
1747  } else ShowError(hr);
1748  } else if (hr==S_FALSE) {
1749  hr = m_pMediaSeeking->IsFormatSupported(&TIME_FORMAT_MEDIA_TIME);
1750  if( hr == S_OK ) {
1751  hr = m_pMediaSeeking->SetTimeFormat(&TIME_FORMAT_MEDIA_TIME);
1752  if(SUCCEEDED(hr))
1753  {
1754  if(m_pMediaSeeking) {
1755  hr = m_pMediaSeeking->GetDuration(&dur);
1756  if(SUCCEEDED(hr)) {
1757  dur = dur / m_VideoFormat.m_TimePerFrame; //en cuadros
1758  /*
1759  if ( m_VideoMode == moDsGraph::PAL ) {
1760  dur = dur / 400000; //en cuadros
1761  } else if ( m_VideoMode == moDsGraph::NTSC ) {
1762  dur = dur / 333667; //en cuadros
1763  }
1764  */
1765  return dur;
1766  } else ShowError(hr);
1767  }
1768  } else ShowError(hr);
1769  } else ShowError(hr);
1770  } else ShowError(hr);
1771  }
1772  }
1773  return dur;
1774 }
1775 
1776 bool
1777 moDsGraph::IsRunning() {
1778  HRESULT hr;
1779  if(m_pFilterGraph) {
1780  if(m_pMediaControl) {
1781  OAFilterState filterstate;
1782  hr = m_pMediaControl->GetState( 12, &filterstate);
1783  if(SUCCEEDED(hr)) {
1784  hr = m_pMediaControl->Pause();
1785  if(SUCCEEDED(hr)) {
1786  hr = m_pMediaControl->Run();
1787  } else return false;
1788  if(SUCCEEDED(hr)) {
1789  return(filterstate == State_Running);
1790  } return false;
1791  } else ShowError(hr);
1792  }
1793  }
1794  return false;
1795 }
1796 
1797 MObyte *
1798 moDsGraph::GetFrameBuffer( MOlong *size ) {
1799  /*
1800  HRESULT hr;
1801  MObyte *pbuf = NULL;
1802 
1803 
1804  if(m_pSampleGrabber) {
1805  hr = m_pSampleGrabber->GetCurrentBuffer( size, NULL);
1806  if(SUCCEEDED(hr)) {
1807  if((*size)>0) {
1808  pbuf = new MObyte [(*size)];
1809  hr = m_pSampleGrabber->GetCurrentBuffer( size, pbuf);
1810  if(FAILED(hr)) ShowError(hr);
1811  return pbuf;
1812  }
1813  } else ShowError(hr);
1814  }
1815  */
1816  return NULL;
1817 }
1818 
1819 bool
1820 moDsGraph::ShowError( HRESULT hr ) {
1821  if(FAILED(hr))
1822  {
1823  TCHAR szErr[MAX_ERROR_TEXT_LEN];
1824  DWORD res = AMGetErrorText(hr, szErr, MAX_ERROR_TEXT_LEN);
1825  if(res == 0)
1826  {
1827  wsprintf(szErr, "Unknown Error: 0x%2x", hr);
1828  }
1829  MessageBox(0, szErr, TEXT("Error!"), MB_OK | MB_ICONERROR);
1830  return false;
1831  } else return true;
1832 }
1833 
1834 void
1835 moDsGraph::SetVideoFormat( AM_MEDIA_TYPE * pmt ) {
1836 
1837  if (pmt->cbFormat >= sizeof(VIDEOINFOHEADER)) {
1838 
1839  if ( pmt->formattype == FORMAT_VideoInfo ) {
1840 
1841  VIDEOINFOHEADER *pVih = reinterpret_cast<VIDEOINFOHEADER*>(pmt->pbFormat);
1842 
1843  m_VideoFormat.m_Width = pVih->bmiHeader.biWidth;
1844  m_VideoFormat.m_Height = pVih->bmiHeader.biHeight;
1845  m_VideoFormat.m_BitCount = pVih->bmiHeader.biBitCount;
1846  m_VideoFormat.m_BitRate = pVih->dwBitRate;
1847  m_VideoFormat.m_TimePerFrame = pVih->AvgTimePerFrame;
1848  m_VideoFormat.m_BufferSize = pmt->lSampleSize;
1849  m_VideoFormat.SetVideoMode();
1850 
1851  } else if (pmt->formattype == FORMAT_MPEGVideo) {
1852  MPEG1VIDEOINFO *pMh = reinterpret_cast<MPEG1VIDEOINFO*>(pmt->pbFormat);
1853  VIDEOINFOHEADER *pVih = &(pMh->hdr);
1854 
1855  m_VideoFormat.m_Width = pVih->bmiHeader.biWidth;
1856  m_VideoFormat.m_Height = pVih->bmiHeader.biHeight;
1857  m_VideoFormat.m_BitCount = pVih->bmiHeader.biBitCount;
1858  m_VideoFormat.m_BitRate = pVih->dwBitRate;
1859  m_VideoFormat.m_TimePerFrame = pVih->AvgTimePerFrame;
1860  m_VideoFormat.m_BufferSize = pVih->bmiHeader.biWidth * pVih->bmiHeader.biHeight * 3;
1861  m_VideoFormat.SetVideoMode();
1862 
1863  } else if (pmt->formattype == FORMAT_MPEG2Video) {
1864 
1865  MPEG2VIDEOINFO *pMh = reinterpret_cast<MPEG2VIDEOINFO*>(pmt->pbFormat);
1866  VIDEOINFOHEADER2 *pVih = &(pMh->hdr);
1867 
1868  m_VideoFormat.m_Width = pVih->bmiHeader.biWidth;
1869  m_VideoFormat.m_Height = pVih->bmiHeader.biHeight;
1870  m_VideoFormat.m_BitCount = pVih->bmiHeader.biBitCount;
1871  m_VideoFormat.m_BitRate = pVih->dwBitRate;
1872  m_VideoFormat.m_TimePerFrame = pVih->AvgTimePerFrame;
1873  m_VideoFormat.m_BufferSize = pVih->bmiHeader.biWidth * pVih->bmiHeader.biHeight * 3;
1874  m_VideoFormat.SetVideoMode();
1875 
1876  }
1877 
1878  }
1879 
1880 }
1881 
1882 IPin * moDsGraph::GetInPin( IBaseFilter * pFilter, int nPin )
1883 {
1884  IPin* pComPin=NULL;
1885  GetPin(pFilter, PINDIR_INPUT, nPin, &pComPin);
1886  return pComPin;
1887 }
1888 
1889 
1890 IPin * moDsGraph::GetOutPin( IBaseFilter * pFilter, int nPin )
1891 {
1892  IPin* pComPin=NULL;
1893  GetPin(pFilter, PINDIR_OUTPUT, nPin, &pComPin);
1894  return pComPin;
1895 }
1896 
1897 HRESULT
1898 moDsGraph::GetPin( IBaseFilter * pFilter, PIN_DIRECTION dirrequired, int iNum, IPin **ppPin)
1899 {
1900  IEnumPins* pEnum;
1901  *ppPin = NULL;
1902 
1903  HRESULT hr = pFilter->EnumPins(&pEnum);
1904  if(FAILED(hr))
1905  return hr;
1906 
1907  ULONG ulFound;
1908  IPin *pPin;
1909  hr = E_FAIL;
1910 
1911  while(S_OK == pEnum->Next(1, &pPin, &ulFound))
1912  {
1913  PIN_DIRECTION pindir =(PIN_DIRECTION)3;
1914 
1915  pPin->QueryDirection(&pindir);
1916  if(pindir == dirrequired)
1917  {
1918  if(iNum == 0)
1919  {
1920  *ppPin = pPin; // Return the pin's interface
1921  hr = S_OK; // Found requested pin, so clear error
1922  break;
1923  }
1924  iNum--;
1925  }
1926 
1927  pPin->Release();
1928  }
1929 
1930  return hr;
1931 }
1932 
1933 
1934 void
1935 moDsGraph::CheckMediaType( IPin* p_Pin ) {
1936 
1937  HRESULT hr;
1938  IEnumMediaTypes* ppEnum;
1939  AM_MEDIA_TYPE* pMediaTypes;
1940 
1941 
1942  hr = p_Pin->EnumMediaTypes( &ppEnum);
1943 
1944  if(SUCCEEDED(hr)) {
1945 
1946  while( ppEnum->Next( 1, &pMediaTypes, NULL) == S_OK ) {
1947  if ( pMediaTypes->majortype == MEDIATYPE_Video ) { //VIDEO
1948  if ( pMediaTypes->formattype == FORMAT_VideoInfo ) {
1949 
1950  VIDEOINFOHEADER *pVih = reinterpret_cast<VIDEOINFOHEADER*>(pMediaTypes->pbFormat);
1951  m_VideoFormat.m_Width = pVih->bmiHeader.biWidth;
1952  m_VideoFormat.m_Height = pVih->bmiHeader.biHeight;
1953  m_VideoFormat.m_BitCount = pVih->bmiHeader.biBitCount;
1954  m_VideoFormat.m_BitRate = pVih->dwBitRate;
1955  m_VideoFormat.m_TimePerFrame = pVih->AvgTimePerFrame;
1956  m_VideoFormat.m_BufferSize = pMediaTypes->lSampleSize;
1957  m_VideoFormat.SetVideoMode();
1958  }
1959  }
1960  }
1961  }
1962  ppEnum->Release();
1963 }
1964 
1965 #endif
#define MOulong
Definition: moTypes.h:392
#define MObyte
Definition: moTypes.h:400
moVideoFormat & GetVideoFormat()
Devuelve el formato de video del dispositivo.
Definition: moVideoGraph.h:400
clase de para manejar textos
Definition: moText.h:75
#define MOlong
Definition: moTypes.h:391
moTypes MOint moText moParamIndex moParamReference int iRow int int i int i
Definition: all_f.js:18
moText0 moText
Definition: moText.h:291
void Present(bool p=true)
Fija la presencia del dispositivo.
Definition: moVideoGraph.h:413
#define MOint
Definition: moTypes.h:388
Administrador de moBucket 's.
Definition: moBuckets.h:152
const moText & GetPath() const
Devuelve el camino al dispositivo.
Definition: moVideoGraph.h:390
function L
Definition: jquery.js:16
Definición de un dispositivo de video, generalmente uno de captura de video, o camara.
Definition: moVideoGraph.h:336
#define MOuint
Definition: moTypes.h:387
MOuint m_BitCount
Definition: moVideoGraph.h:207
Formato de video.
Definition: moVideoGraph.h:155