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.

122 lines
3.4 KiB

  1. // Copyright (c) 1997 Microsoft Corporation. All Rights Reserved.
  2. #include "stdafx.h"
  3. #include "project.h"
  4. CAMMediaTypeSample::CAMMediaTypeSample() :
  5. m_pDataPointer(NULL),
  6. m_lSize(0),
  7. m_lActualDataLength(0),
  8. m_bIAllocatedThisBuffer(false)
  9. {};
  10. HRESULT CAMMediaTypeSample::Initialize(CAMMediaTypeStream *pStream, long lSize, BYTE *pData)
  11. {
  12. HRESULT hr = CSample::InitSample(pStream, false);
  13. if (SUCCEEDED(hr)) {
  14. hr = SetPointer(pData, lSize);
  15. }
  16. return hr;
  17. }
  18. CAMMediaTypeSample::~CAMMediaTypeSample()
  19. {
  20. if (m_bIAllocatedThisBuffer) {
  21. CoTaskMemFree(m_pDataPointer);
  22. }
  23. }
  24. HRESULT CAMMediaTypeSample::CopyFrom(IMediaSample *pSrcMediaSample)
  25. {
  26. AUTO_SAMPLE_LOCK;
  27. CSample::CopyFrom(pSrcMediaSample);
  28. BYTE * pBytes;
  29. HRESULT hr = pSrcMediaSample->GetPointer(&pBytes);
  30. if (SUCCEEDED(hr)) {
  31. LONG lCopySize = pSrcMediaSample->GetActualDataLength();
  32. if (lCopySize > m_lSize) {
  33. hr = HRESULT_FROM_WIN32(ERROR_MORE_DATA);
  34. lCopySize = m_lSize;
  35. }
  36. memcpy(m_pDataPointer, pBytes, lCopySize);
  37. }
  38. return hr;
  39. }
  40. STDMETHODIMP CAMMediaTypeSample::SetPointer(BYTE * pBuffer, LONG lSize)
  41. {
  42. AUTO_SAMPLE_LOCK;
  43. HRESULT hr = S_OK;
  44. if (m_bIAllocatedThisBuffer) {
  45. CoTaskMemFree(m_pDataPointer);
  46. m_bIAllocatedThisBuffer = false;
  47. }
  48. m_lSize = lSize;
  49. if (pBuffer) {
  50. m_pDataPointer = pBuffer;
  51. } else {
  52. m_pDataPointer = (BYTE *)CoTaskMemAlloc(lSize);
  53. if (!m_pDataPointer) {
  54. hr = E_OUTOFMEMORY;
  55. } else {
  56. m_bIAllocatedThisBuffer = true;
  57. }
  58. }
  59. m_lActualDataLength = 0;
  60. return hr;
  61. }
  62. #define STDMETHOD_FORWARD0(fctn) STDMETHODIMP CAMMediaTypeSample::fctn(void) { return m_pMediaSample->fctn(); }
  63. #define STDMETHOD_FORWARD1(fctn, t1) STDMETHODIMP CAMMediaTypeSample::fctn(t1 p1) { return m_pMediaSample->fctn(p1); }
  64. #define STDMETHOD_FORWARD2(fctn, t1, t2) STDMETHODIMP CAMMediaTypeSample::fctn(t1 p1, t2 p2) { return m_pMediaSample->fctn(p1, p2); }
  65. #define LONG_RET_VAL_FWD(fctn) STDMETHODIMP_(LONG) CAMMediaTypeSample::fctn(void) { return m_pMediaSample->fctn(); }
  66. STDMETHOD_FORWARD1(GetPointer, BYTE **)
  67. LONG_RET_VAL_FWD (GetSize)
  68. STDMETHOD_FORWARD2(GetTime, REFERENCE_TIME *, REFERENCE_TIME *)
  69. STDMETHOD_FORWARD2(SetTime, REFERENCE_TIME *, REFERENCE_TIME *)
  70. STDMETHOD_FORWARD0(IsSyncPoint)
  71. STDMETHOD_FORWARD1(SetSyncPoint, BOOL)
  72. STDMETHOD_FORWARD0(IsPreroll)
  73. STDMETHOD_FORWARD1(SetPreroll, BOOL)
  74. LONG_RET_VAL_FWD (GetActualDataLength)
  75. STDMETHOD_FORWARD1(SetActualDataLength, LONG)
  76. STDMETHOD_FORWARD1(GetMediaType, AM_MEDIA_TYPE **)
  77. STDMETHOD_FORWARD1(SetMediaType, AM_MEDIA_TYPE *)
  78. STDMETHOD_FORWARD0(IsDiscontinuity)
  79. STDMETHOD_FORWARD1(SetDiscontinuity, BOOL)
  80. STDMETHOD_FORWARD2(GetMediaTime, LONGLONG *, LONGLONG *)
  81. STDMETHOD_FORWARD2(SetMediaTime, LONGLONG *, LONGLONG *)
  82. HRESULT CAMMediaTypeSample::MSCallback_GetPointer(BYTE **ppBuffer)
  83. {
  84. *ppBuffer = m_pDataPointer;
  85. return S_OK;
  86. }
  87. LONG CAMMediaTypeSample::MSCallback_GetSize(void)
  88. {
  89. return m_lSize;
  90. }
  91. LONG CAMMediaTypeSample::MSCallback_GetActualDataLength(void) {
  92. return m_lActualDataLength;
  93. }
  94. HRESULT CAMMediaTypeSample::MSCallback_SetActualDataLength(LONG lActual)
  95. {
  96. if (lActual >= 0 && lActual <= m_lSize) {
  97. m_lActualDataLength = lActual;
  98. return S_OK;
  99. } else {
  100. return E_INVALIDARG;
  101. }
  102. }
  103. bool CAMMediaTypeSample::MSCallback_AllowSetMediaTypeOnMediaSample(void)
  104. {
  105. return true;
  106. }