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.

187 lines
5.6 KiB

  1. // Copyright (c) 1997 - 1998 Microsoft Corporation. All Rights Reserved.
  2. #ifndef __SAMPLE_H_
  3. #define __SAMPLE_H_
  4. #include "resource.h" // main symbols
  5. #include "stream.h"
  6. //
  7. // Samples don't use their own critical sections -- They always take the critical section of their
  8. // stream. This avoids all sorts of deadlocks, and reduces the number of locks we take. These
  9. // macros are helpers.
  10. //
  11. #define LOCK_SAMPLE m_pStream->Lock();
  12. #define UNLOCK_SAMPLE m_pStream->Unlock();
  13. #define AUTO_SAMPLE_LOCK CAutoObjectLock lck(m_pStream);
  14. class CSample;
  15. class CMediaSample : public IMediaSample
  16. {
  17. public:
  18. CMediaSample(CSample *pSample);
  19. virtual ~CMediaSample();
  20. //
  21. // IUnknown
  22. //
  23. STDMETHODIMP QueryInterface(REFIID riid, void **ppv);
  24. STDMETHODIMP_(ULONG) AddRef();
  25. STDMETHODIMP_(ULONG) Release();
  26. //
  27. // IMediaSample
  28. //
  29. STDMETHODIMP GetPointer(BYTE ** ppBuffer);
  30. STDMETHODIMP_(LONG) GetSize(void);
  31. STDMETHODIMP GetTime(REFERENCE_TIME * pTimeStart, REFERENCE_TIME * pTimeEnd);
  32. STDMETHODIMP SetTime(REFERENCE_TIME * pTimeStart, REFERENCE_TIME * pTimeEnd);
  33. STDMETHODIMP IsSyncPoint(void);
  34. STDMETHODIMP SetSyncPoint(BOOL bIsSyncPoint);
  35. STDMETHODIMP IsPreroll(void);
  36. STDMETHODIMP SetPreroll(BOOL bIsPreroll);
  37. STDMETHODIMP_(LONG) GetActualDataLength(void);
  38. STDMETHODIMP SetActualDataLength(LONG lActual);
  39. STDMETHODIMP GetMediaType(AM_MEDIA_TYPE **ppMediaType);
  40. STDMETHODIMP SetMediaType(AM_MEDIA_TYPE *pMediaType);
  41. STDMETHODIMP IsDiscontinuity(void);
  42. STDMETHODIMP SetDiscontinuity(BOOL bDiscontinuity);
  43. STDMETHODIMP GetMediaTime(LONGLONG * pTimeStart, LONGLONG * pTimeEnd);
  44. STDMETHODIMP SetMediaTime(LONGLONG * pTimeStart, LONGLONG * pTimeEnd);
  45. // Set the pointer
  46. HRESULT SetSizeAndPointer(PBYTE pbData, LONG lActual, LONG lSize);
  47. public:
  48. CSample *m_pSample;
  49. BOOL m_bIsPreroll;
  50. DWORD m_dwFlags;
  51. long m_cRef;
  52. AM_MEDIA_TYPE *m_pMediaType;
  53. /// Stream time
  54. REFERENCE_TIME m_rtStartTime;
  55. REFERENCE_TIME m_rtEndTime;
  56. };
  57. /////////////////////////////////////////////////////////////////////////////
  58. // CSample
  59. class ATL_NO_VTABLE CSample :
  60. public CComObjectRootEx<CComMultiThreadModel>,
  61. public IStreamSample
  62. {
  63. public:
  64. //
  65. // METHODS
  66. //
  67. CSample();
  68. HRESULT InitSample(CStream *pStream, bool bIsInternalSample);
  69. virtual ~CSample();
  70. DECLARE_GET_CONTROLLING_UNKNOWN()
  71. //
  72. // IStreamSample
  73. //
  74. STDMETHODIMP GetMediaStream(
  75. /* [in] */ IMediaStream **ppMediaStream);
  76. STDMETHODIMP GetSampleTimes(
  77. /* [optional][out] */ STREAM_TIME *pStartTime,
  78. /* [optional][out] */ STREAM_TIME *pEndTime,
  79. /* [optional][out] */ STREAM_TIME *pCurrentTime);
  80. STDMETHODIMP SetSampleTimes(
  81. /* [optional][in] */ const STREAM_TIME *pStartTime,
  82. /* [optional][in] */ const STREAM_TIME *pEndTime);
  83. STDMETHODIMP Update(
  84. /* [in] */ DWORD dwFlags,
  85. /* [optional][in] */ HANDLE hEvent,
  86. /* [optional][in] */ PAPCFUNC pfnAPC,
  87. /* [optional][in] */ DWORD_PTR dwAPCData);
  88. STDMETHODIMP CompletionStatus(
  89. /* [in] */ DWORD dwFlags,
  90. /* [optional][in] */ DWORD dwMilliseconds);
  91. //
  92. // Forwarding functions for various Media Sample interfaces that can be
  93. //
  94. virtual HRESULT MSCallback_GetPointer(BYTE ** ppBuffer) = 0;
  95. virtual LONG MSCallback_GetSize(void) = 0;
  96. virtual LONG MSCallback_GetActualDataLength(void) = 0;
  97. virtual HRESULT MSCallback_SetActualDataLength(LONG lActual) = 0;
  98. virtual bool MSCallback_AllowSetMediaTypeOnMediaSample(void) {return false;}
  99. //
  100. // ATL class methods
  101. //
  102. void FinalRelease(void);
  103. //
  104. // Internal methods
  105. //
  106. virtual void FinalMediaSampleRelease(void);
  107. virtual HRESULT SetCompletionStatus(HRESULT hrCompletionStatus);
  108. void CopyFrom(CSample *pSrcSample);
  109. void CopyFrom(IMediaSample *pSrcMediaSample);
  110. virtual HRESULT InternalUpdate(
  111. DWORD dwFlags,
  112. HANDLE hEvent,
  113. PAPCFUNC pfnAPC,
  114. DWORD_PTR dwAPCData);
  115. // Temp?
  116. bool IsTemp() { return m_bTemp; }
  117. // Set the pointer?
  118. virtual HRESULT SetSizeAndPointer(PBYTE pbData, LONG lActual, LONG lSize)
  119. {
  120. return E_FAIL;
  121. }
  122. BEGIN_COM_MAP(CSample)
  123. COM_INTERFACE_ENTRY(IStreamSample)
  124. END_COM_MAP()
  125. public:
  126. //
  127. // MEMBER VARIABLES
  128. //
  129. CMediaSample * m_pMediaSample;
  130. bool m_bReceived;
  131. bool m_bWantAbort;
  132. bool m_bContinuous;
  133. bool m_bModified;
  134. bool m_bInternal;
  135. bool m_bTemp;
  136. bool m_bWaited;
  137. CStream *m_pStream;
  138. CSample *m_pNextFree;
  139. CSample *m_pPrevFree;
  140. HANDLE m_hUserHandle;
  141. PAPCFUNC m_UserAPC;
  142. DWORD_PTR m_dwUserAPCData;
  143. HRESULT m_Status;
  144. HRESULT m_MediaSampleIoStatus;
  145. HANDLE m_hCompletionEvent;
  146. };
  147. #endif //__SAMPLE_H_