ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

enum_mediatypes.cpp
Go to the documentation of this file.
00001 /*
00002  * COPYRIGHT:       See COPYING in the top level directory
00003  * PROJECT:         ReactOS Network Provider for MPEG2 based networks
00004  * FILE:            dll/directx/msdvbnp/enum_mediatypes.cpp
00005  * PURPOSE:         IEnumMediaTypes interface
00006  *
00007  * PROGRAMMERS:     Johannes Anderwald (janderwald@reactos.org)
00008  */
00009 #include "precomp.h"
00010 
00011 class CEnumMediaTypes : public IEnumMediaTypes
00012 {
00013 public:
00014     STDMETHODIMP QueryInterface( REFIID InterfaceId, PVOID* Interface);
00015 
00016     STDMETHODIMP_(ULONG) AddRef()
00017     {
00018         InterlockedIncrement(&m_Ref);
00019         return m_Ref;
00020     }
00021     STDMETHODIMP_(ULONG) Release()
00022     {
00023         InterlockedDecrement(&m_Ref);
00024         if (!m_Ref)
00025         {
00026             delete this;
00027             return 0;
00028         }
00029         return m_Ref;
00030     }
00031 
00032     HRESULT STDMETHODCALLTYPE Next(ULONG cMediaTypes, AM_MEDIA_TYPE **ppMediaTypes, ULONG *pcFetched);
00033     HRESULT STDMETHODCALLTYPE Skip(ULONG cMediaTypes);
00034     HRESULT STDMETHODCALLTYPE Reset();
00035     HRESULT STDMETHODCALLTYPE Clone(IEnumMediaTypes **ppEnum);
00036 
00037 
00038     CEnumMediaTypes(ULONG MediaTypeCount, AM_MEDIA_TYPE * MediaTypes) : m_Ref(0), m_MediaTypeCount(MediaTypeCount), m_MediaTypes(MediaTypes), m_Index(0){};
00039     virtual ~CEnumMediaTypes(){};
00040 
00041 protected:
00042     LONG m_Ref;
00043     ULONG m_MediaTypeCount;
00044     AM_MEDIA_TYPE * m_MediaTypes;
00045     ULONG m_Index;
00046 };
00047 
00048 HRESULT
00049 STDMETHODCALLTYPE
00050 CEnumMediaTypes::QueryInterface(
00051     IN  REFIID refiid,
00052     OUT PVOID* Output)
00053 {
00054     if (IsEqualGUID(refiid, IID_IUnknown))
00055     {
00056         *Output = PVOID(this);
00057         reinterpret_cast<IUnknown*>(*Output)->AddRef();
00058         return NOERROR;
00059     }
00060     if (IsEqualGUID(refiid, IID_IEnumMediaTypes))
00061     {
00062         *Output = (IEnumMediaTypes*)(this);
00063         reinterpret_cast<IEnumMediaTypes*>(*Output)->AddRef();
00064         return NOERROR;
00065     }
00066 
00067     return E_NOINTERFACE;
00068 }
00069 
00070 //-------------------------------------------------------------------
00071 // IEnumMediaTypes
00072 //
00073 
00074 HRESULT
00075 STDMETHODCALLTYPE
00076 CEnumMediaTypes::Next(
00077     ULONG cMediaTypes,
00078     AM_MEDIA_TYPE **ppMediaTypes,
00079     ULONG *pcFetched)
00080 {
00081     ULONG i = 0;
00082     AM_MEDIA_TYPE * MediaType;
00083 
00084     if (!ppMediaTypes)
00085         return E_POINTER;
00086 
00087     if (cMediaTypes > 1 && !pcFetched)
00088         return E_INVALIDARG;
00089 
00090     while(i < cMediaTypes)
00091     {
00092         if (m_Index + i >= m_MediaTypeCount)
00093             break;
00094 
00095         MediaType = (AM_MEDIA_TYPE*)CoTaskMemAlloc(sizeof(AM_MEDIA_TYPE));
00096         if (!MediaType)
00097             break;
00098 
00099         if (m_MediaTypes[m_Index + i].cbFormat)
00100         {
00101             LPBYTE pFormat = (LPBYTE)CoTaskMemAlloc(m_MediaTypes[m_Index + i].cbFormat);
00102             if (!pFormat)
00103             {
00104                 CoTaskMemFree(MediaType);
00105                 break;
00106             }
00107 
00108             CopyMemory(MediaType, &m_MediaTypes[m_Index + i], sizeof(AM_MEDIA_TYPE));
00109             MediaType->pbFormat = pFormat;
00110             CopyMemory(MediaType->pbFormat, m_MediaTypes[m_Index + i].pbFormat, m_MediaTypes[m_Index + i].cbFormat);
00111             MediaType->pUnk = (IUnknown *)this;
00112             MediaType->pUnk->AddRef();
00113         }
00114         else
00115         {
00116             CopyMemory(MediaType, &m_MediaTypes[m_Index + i], sizeof(AM_MEDIA_TYPE));
00117         }
00118 
00119         if (MediaType->pUnk)
00120         {
00121             MediaType->pUnk->AddRef();
00122         }
00123 
00124         ppMediaTypes[i] = MediaType;
00125         i++;
00126     }
00127 
00128     if (pcFetched)
00129     {
00130         *pcFetched = i;
00131     }
00132 
00133     m_Index += i;
00134     if (i < cMediaTypes)
00135         return S_FALSE;
00136     else
00137         return S_OK;
00138 }
00139 
00140 HRESULT
00141 STDMETHODCALLTYPE
00142 CEnumMediaTypes::Skip(
00143     ULONG cMediaTypes)
00144 {
00145     if (cMediaTypes + m_Index >= m_MediaTypeCount)
00146     {
00147         return S_FALSE;
00148     }
00149 
00150     m_Index += cMediaTypes;
00151     return S_OK;
00152 }
00153 
00154 HRESULT
00155 STDMETHODCALLTYPE
00156 CEnumMediaTypes::Reset()
00157 {
00158     m_Index = 0;
00159     return S_OK;
00160 }
00161 
00162 HRESULT
00163 STDMETHODCALLTYPE
00164 CEnumMediaTypes::Clone(
00165     IEnumMediaTypes **ppEnum)
00166 {
00167 #ifdef KSPROXY_TRACE
00168     OutputDebugStringW(L"CEnumMediaTypes::Clone : NotImplemented\n");
00169 #endif
00170     return E_NOTIMPL;
00171 }
00172 
00173 HRESULT
00174 WINAPI
00175 CEnumMediaTypes_fnConstructor(
00176     ULONG MediaTypeCount,
00177     AM_MEDIA_TYPE * MediaTypes,
00178     REFIID riid,
00179     LPVOID * ppv)
00180 {
00181     CEnumMediaTypes * handler = new CEnumMediaTypes(MediaTypeCount, MediaTypes);
00182 
00183 #ifdef KSPROXY_TRACE
00184     WCHAR Buffer[MAX_PATH];
00185     LPOLESTR lpstr;
00186     StringFromCLSID(riid, &lpstr);
00187     swprintf(Buffer, L"CEnumMediaTypes_fnConstructor riid %s\n", lpstr);
00188     OutputDebugStringW(Buffer);
00189 #endif
00190 
00191     if (!handler)
00192     {
00193         CoTaskMemFree(MediaTypes);
00194         return E_OUTOFMEMORY;
00195     }
00196 
00197     if (FAILED(handler->QueryInterface(riid, ppv)))
00198     {
00199         /* not supported */
00200         delete handler;
00201         return E_NOINTERFACE;
00202     }
00203 
00204     return NOERROR;
00205 }
00206 

Generated on Sat May 26 2012 04:20:22 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.