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.

109 lines
2.6 KiB

  1. // Copyright (c) 1999 Microsoft Corporation. All Rights Reserved.
  2. //
  3. // dmort.cpp - DMO runtime misc.
  4. //
  5. #include <windows.h>
  6. #include "mediaobj.h"
  7. #include "dmort.h"
  8. //
  9. // Mediatype stuff
  10. //
  11. STDAPI MoInitMediaType(DMO_MEDIA_TYPE *pmt, ULONG cbFormat) {
  12. if (!pmt)
  13. return E_POINTER;
  14. pmt->pUnk = NULL;
  15. if (cbFormat) {
  16. pmt->pbFormat = (PBYTE)CoTaskMemAlloc(cbFormat);
  17. if (!pmt->pbFormat)
  18. return E_OUTOFMEMORY;
  19. }
  20. else
  21. pmt->pbFormat = NULL;
  22. pmt->cbFormat = cbFormat;
  23. return NOERROR;
  24. }
  25. STDAPI MoFreeMediaType(DMO_MEDIA_TYPE *pmt) {
  26. if (!pmt)
  27. return E_POINTER;
  28. if (pmt->pUnk) {
  29. pmt->pUnk->Release();
  30. pmt->pUnk = NULL;
  31. }
  32. if (pmt->pbFormat) {
  33. CoTaskMemFree(pmt->pbFormat);
  34. pmt->pbFormat = NULL;
  35. }
  36. return NOERROR;
  37. }
  38. // everything has been allocated - just copy
  39. void CopyMediaTypeInternal(DMO_MEDIA_TYPE *pmtDest, DMO_MEDIA_TYPE const *pmtSrc) {
  40. if (pmtDest->cbFormat)
  41. memcpy(pmtDest->pbFormat, pmtSrc->pbFormat, pmtDest->cbFormat);
  42. if (pmtSrc->pUnk) {
  43. pmtSrc->pUnk->AddRef();
  44. pmtDest->pUnk = pmtSrc->pUnk;
  45. }
  46. pmtDest->majortype = pmtSrc->majortype;
  47. pmtDest->subtype = pmtSrc->subtype;
  48. pmtDest->bFixedSizeSamples = pmtSrc->bFixedSizeSamples;
  49. pmtDest->bTemporalCompression = pmtSrc->bTemporalCompression;
  50. pmtDest->lSampleSize = pmtSrc->lSampleSize;
  51. pmtDest->formattype = pmtSrc->formattype;
  52. }
  53. STDAPI MoCopyMediaType(DMO_MEDIA_TYPE *pmtDest, DMO_MEDIA_TYPE const *pmtSrc) {
  54. if ((!pmtDest) || (!pmtSrc))
  55. return E_POINTER;
  56. ULONG cbFormat = pmtSrc->pbFormat ? pmtSrc->cbFormat : 0;
  57. HRESULT hr = MoInitMediaType(pmtDest, cbFormat);
  58. if (FAILED(hr))
  59. return hr;
  60. CopyMediaTypeInternal(pmtDest, pmtSrc);
  61. return NOERROR;
  62. }
  63. STDAPI MoCreateMediaType(DMO_MEDIA_TYPE **ppmt, ULONG cbFormat) {
  64. if (!ppmt)
  65. return E_POINTER;
  66. *ppmt = (DMO_MEDIA_TYPE*) CoTaskMemAlloc(sizeof(DMO_MEDIA_TYPE));
  67. if (!*ppmt)
  68. return E_OUTOFMEMORY;
  69. HRESULT hr = MoInitMediaType(*ppmt, cbFormat);
  70. if (FAILED(hr)) {
  71. CoTaskMemFree(*ppmt);
  72. *ppmt = NULL;
  73. }
  74. return hr;
  75. }
  76. STDAPI MoDeleteMediaType(DMO_MEDIA_TYPE *pmt) {
  77. if (!pmt)
  78. return E_POINTER;
  79. HRESULT hr = MoFreeMediaType(pmt);
  80. CoTaskMemFree(pmt);
  81. return hr;
  82. }
  83. STDAPI MoDuplicateMediaType(DMO_MEDIA_TYPE **ppmtDest, DMO_MEDIA_TYPE const *pmtSrc) {
  84. if (!ppmtDest || !pmtSrc)
  85. return E_POINTER;
  86. ULONG cbFormat = pmtSrc->pbFormat ? pmtSrc->cbFormat : 0;
  87. HRESULT hr = MoCreateMediaType(ppmtDest, cbFormat);
  88. if (FAILED(hr))
  89. return hr;
  90. CopyMediaTypeInternal(*ppmtDest, pmtSrc);
  91. return NOERROR;
  92. }