CodeVis.com SourceForge.net Logo

CVDShowUtil.cpp

Go to the documentation of this file.
00001 
00002 
00003 #include "CVDShowUtil.h"
00004 
00005 // GetUnconnectedPin
00006 //    Finds an unconnected pin on a filter in the desired direction
00007 HRESULT GetUnconnectedPin(
00008     IBaseFilter *pFilter,   // Pointer to the filter.
00009     PIN_DIRECTION PinDir,   // Direction of the pin to find.
00010     IPin **ppPin)           // Receives a pointer to the pin.
00011 {
00012     *ppPin = 0;
00013     IEnumPins *pEnum = 0;
00014     IPin *pPin = 0;
00015     HRESULT hr = pFilter->EnumPins(&pEnum);
00016     if (FAILED(hr))
00017     {
00018         return hr;
00019     }
00020     while (pEnum->Next(1, &pPin, NULL) == S_OK)
00021     {
00022         PIN_DIRECTION ThisPinDir;
00023         pPin->QueryDirection(&ThisPinDir);
00024         if (ThisPinDir == PinDir)
00025         {
00026             IPin *pTmp = 0;
00027             hr = pPin->ConnectedTo(&pTmp);
00028             if (SUCCEEDED(hr))  // Already connected, not the pin we want.
00029             {
00030                 pTmp->Release();
00031             }
00032             else  // Unconnected, this is the pin we want.
00033             {
00034                 pEnum->Release();
00035                 *ppPin = pPin;
00036                 return S_OK;
00037             }
00038         }
00039         pPin->Release();
00040     }
00041     pEnum->Release();
00042     // Did not find a matching pin.
00043     return E_FAIL;
00044 }
00045 
00046 // Disconnect any connections to the filter.
00047 HRESULT DisconnectPins(IBaseFilter *pFilter)
00048 {
00049     IEnumPins *pEnum = 0;
00050     IPin *pPin = 0;
00051     HRESULT hr = pFilter->EnumPins(&pEnum);
00052     if (FAILED(hr))
00053     {
00054         return hr;
00055     }
00056     
00057     while (pEnum->Next(1, &pPin, NULL) == S_OK)
00058     {
00059       pPin->Disconnect();
00060       pPin->Release();
00061     }
00062     pEnum->Release();
00063     
00064     // Did not find a matching pin.
00065     return S_OK;
00066 }
00067 
00068 // ConnectFilters
00069 //    Connects a pin of an upstream filter to the pDest downstream filter
00070 HRESULT ConnectFilters(
00071     IGraphBuilder *pGraph, // Filter Graph Manager.
00072     IPin *pOut,            // Output pin on the upstream filter.
00073     IBaseFilter *pDest)    // Downstream filter.
00074 {
00075     if ((pGraph == NULL) || (pOut == NULL) || (pDest == NULL))
00076     {
00077         return E_POINTER;
00078     }
00079 #ifdef debug
00080         PIN_DIRECTION PinDir;
00081         pOut->QueryDirection(&PinDir);
00082         _ASSERTE(PinDir == PINDIR_OUTPUT);
00083 #endif
00084 
00085     // Find an input pin on the downstream filter.
00086     IPin *pIn = 0;
00087     HRESULT hr = GetUnconnectedPin(pDest, PINDIR_INPUT, &pIn);
00088     if (FAILED(hr))
00089     {
00090         return hr;
00091     }
00092     // Try to connect them.
00093     hr = pGraph->Connect(pOut, pIn);
00094     pIn->Release();
00095     return hr;
00096 }
00097 
00098 
00099 
00100 // ConnectFilters
00101 //    Connects two filters
00102 HRESULT ConnectFilters(
00103     IGraphBuilder *pGraph, 
00104     IBaseFilter *pSrc, 
00105     IBaseFilter *pDest)
00106 {
00107     if ((pGraph == NULL) || (pSrc == NULL) || (pDest == NULL))
00108     {
00109         return E_POINTER;
00110     }
00111 
00112     // Find an output pin on the first filter.
00113     IPin *pOut = 0;
00114     HRESULT hr = GetUnconnectedPin(pSrc, PINDIR_OUTPUT, &pOut);
00115     if (FAILED(hr)) 
00116     {
00117         return hr;
00118     }
00119     hr = ConnectFilters(pGraph, pOut, pDest);
00120     pOut->Release();
00121     return hr;
00122 }
00123 
00124 // LocalFreeMediaType
00125 //    Free the format buffer in the media type
00126 void LocalFreeMediaType(AM_MEDIA_TYPE& mt)
00127 {
00128     if (mt.cbFormat != 0)
00129     {
00130         CoTaskMemFree((PVOID)mt.pbFormat);
00131         mt.cbFormat = 0;
00132         mt.pbFormat = NULL;
00133     }
00134     if (mt.pUnk != NULL)
00135     {
00136         // Unecessary because pUnk should not be used, but safest.
00137         mt.pUnk->Release();
00138         mt.pUnk = NULL;
00139     }
00140 }
00141 
00142 // LocalDeleteMediaType
00143 //    Free the format buffer in the media type, 
00144 //    then delete the MediaType ptr itself
00145 void LocalDeleteMediaType(AM_MEDIA_TYPE *pmt)
00146 {
00147     if (pmt != NULL)
00148     {
00149         LocalFreeMediaType(*pmt); // See FreeMediaType for the implementation.
00150         CoTaskMemFree(pmt);
00151     }
00152 }
00153 

Generated on Mon Mar 1 13:27:11 2004 for VidCapture Library by doxygen 1.3.3
CodeVis VidCapture 0.2 Copyright © 2003-2004 by Michael Ellison.