Source code of Windows XP (NT5)
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.

73 lines
1.6 KiB

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