Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

78 lines
1.6 KiB

  1. /*
  2. Copyright (c) 1998-1999 Microsoft Corporation
  3. */
  4. #include "stdafx.h"
  5. CMediaTypeEnum::CMediaTypeEnum() :
  6. m_cCurrentPos(0),
  7. m_pStream(NULL)
  8. {
  9. }
  10. void CMediaTypeEnum::Initialize(CStream *pStream, ULONG cCurPos)
  11. {
  12. m_pStream = pStream;
  13. m_pStream->GetControllingUnknown()->AddRef();
  14. m_cCurrentPos = cCurPos;
  15. }
  16. CMediaTypeEnum::~CMediaTypeEnum()
  17. {
  18. m_pStream->GetControllingUnknown()->Release();
  19. }
  20. STDMETHODIMP CMediaTypeEnum::Next(ULONG cNumToFetch, AM_MEDIA_TYPE **ppMediaTypes, ULONG *pcFetched)
  21. {
  22. if (pcFetched == NULL) {
  23. return E_POINTER;
  24. }
  25. HRESULT hr = S_OK;
  26. *pcFetched = 0;
  27. for (; cNumToFetch > 0; ) {
  28. if (S_OK == hr) {
  29. hr = m_pStream->GetMediaType(m_cCurrentPos, ppMediaTypes);
  30. if (S_OK != hr) {
  31. *ppMediaTypes = NULL;
  32. } else {
  33. m_cCurrentPos++;
  34. (*pcFetched)++;
  35. }
  36. }
  37. ppMediaTypes++;
  38. cNumToFetch--;
  39. }
  40. return hr;
  41. }
  42. STDMETHODIMP CMediaTypeEnum::Skip(ULONG cSkip)
  43. {
  44. m_cCurrentPos += cSkip;
  45. return NOERROR;
  46. }
  47. STDMETHODIMP CMediaTypeEnum::Reset()
  48. {
  49. m_cCurrentPos = 0;
  50. return NOERROR;
  51. }
  52. STDMETHODIMP CMediaTypeEnum::Clone(IEnumMediaTypes **ppEnumMediaTypes)
  53. {
  54. HRESULT hr = S_OK;
  55. CMediaTypeEnum *pNewEnum = new CComObject<CMediaTypeEnum>;
  56. if (pNewEnum == NULL) {
  57. hr = E_OUTOFMEMORY;
  58. } else {
  59. pNewEnum->Initialize(m_pStream, m_cCurrentPos);
  60. }
  61. pNewEnum->GetControllingUnknown()->QueryInterface(IID_IEnumMediaTypes, (void **)ppEnumMediaTypes);
  62. return hr;
  63. }