PageRenderTime 51ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/Core/Dependencies/Media SDK 2012/samples/sample_dshow_plugins/custom_evr_presenter/presenter.h

https://bitbucket.org/barakianc/nvidia-physx-and-apex-in-gge
C Header | 263 lines | 144 code | 48 blank | 71 comment | 7 complexity | aafa889356f81847d6937db9bdf6f84a MD5 | raw file
  1. /*//////////////////////////////////////////////////////////////////////////////
  2. //
  3. // INTEL CORPORATION PROPRIETARY INFORMATION
  4. // This software is supplied under the terms of a license agreement or
  5. // nondisclosure agreement with Intel Corporation and may not be copied
  6. // or disclosed except mtIn accordance with the terms of that agreement.
  7. // Copyright(c) 2003-2011 Intel Corporation. All Rights Reserved.
  8. //
  9. */
  10. //////////////////////////////////////////////////////////////////////////
  11. //
  12. // Presenter.h : Defines the presenter object.
  13. //
  14. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
  15. // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
  16. // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  17. // PARTICULAR PURPOSE.
  18. //
  19. // Copyright (c) Microsoft Corporation. All rights reserved.
  20. //
  21. //
  22. //////////////////////////////////////////////////////////////////////////
  23. #pragma once
  24. // RENDER_STATE: Defines the state of the presenter.
  25. enum RENDER_STATE
  26. {
  27. RENDER_STATE_STARTED = 1,
  28. RENDER_STATE_STOPPED,
  29. RENDER_STATE_PAUSED,
  30. RENDER_STATE_SHUTDOWN, // Initial state.
  31. // State transitions:
  32. // InitServicePointers -> STOPPED
  33. // ReleaseServicePointers -> SHUTDOWN
  34. // IMFClockStateSink::OnClockStart -> STARTED
  35. // IMFClockStateSink::OnClockRestart -> STARTED
  36. // IMFClockStateSink::OnClockPause -> PAUSED
  37. // IMFClockStateSink::OnClockStop -> STOPPED
  38. };
  39. // FRAMESTEP_STATE: Defines the presenter's state with respect to frame-stepping.
  40. enum FRAMESTEP_STATE
  41. {
  42. FRAMESTEP_NONE, // Not frame stepping.
  43. FRAMESTEP_WAITING_START, // Frame stepping, but the clock is not started.
  44. FRAMESTEP_PENDING, // Clock is started. Waiting for samples.
  45. FRAMESTEP_SCHEDULED, // Submitted a sample for rendering.
  46. FRAMESTEP_COMPLETE // Sample was rendered.
  47. // State transitions:
  48. // MFVP_MESSAGE_STEP -> WAITING_START
  49. // OnClockStart/OnClockRestart -> PENDING
  50. // MFVP_MESSAGE_PROCESSINPUTNOTIFY -> SUBMITTED
  51. // OnSampleFree -> COMPLETE
  52. // MFVP_MESSAGE_CANCEL -> NONE
  53. // OnClockStop -> NONE
  54. // OnClockSetRate( non-zero ) -> NONE
  55. };
  56. //-----------------------------------------------------------------------------
  57. // EVRCustomPresenter class
  58. // Description: Implements the custom presenter.
  59. //-----------------------------------------------------------------------------
  60. class EVRCustomPresenter :
  61. BaseObject,
  62. RefCountedObject,
  63. // COM interfaces:
  64. public IMFVideoDeviceID,
  65. public IMFVideoPresenter, // Inherits IMFClockStateSink
  66. public IMFRateSupport,
  67. public IMFGetService,
  68. public IMFTopologyServiceLookupClient,
  69. public IMFVideoDisplayControl
  70. {
  71. public:
  72. static HRESULT CreateInstance(IUnknown *pUnkOuter, REFIID iid, void **ppv);
  73. // IUnknown methods
  74. STDMETHOD(QueryInterface)(REFIID riid, void ** ppv);
  75. STDMETHOD_(ULONG, AddRef)();
  76. STDMETHOD_(ULONG, Release)();
  77. // IMFGetService methods
  78. STDMETHOD(GetService)(REFGUID guidService, REFIID riid, LPVOID *ppvObject);
  79. // IMFVideoPresenter methods
  80. STDMETHOD(ProcessMessage)(MFVP_MESSAGE_TYPE eMessage, ULONG_PTR ulParam);
  81. STDMETHOD(GetCurrentMediaType)(IMFVideoMediaType** ppMediaType);
  82. // IMFClockStateSink methods
  83. STDMETHOD(OnClockStart)(MFTIME hnsSystemTime, LONGLONG llClockStartOffset);
  84. STDMETHOD(OnClockStop)(MFTIME hnsSystemTime);
  85. STDMETHOD(OnClockPause)(MFTIME hnsSystemTime);
  86. STDMETHOD(OnClockRestart)(MFTIME hnsSystemTime);
  87. STDMETHOD(OnClockSetRate)(MFTIME hnsSystemTime, float flRate);
  88. // IMFRateSupport methods
  89. STDMETHOD(GetSlowestRate)(MFRATE_DIRECTION eDirection, BOOL bThin, float *pflRate);
  90. STDMETHOD(GetFastestRate)(MFRATE_DIRECTION eDirection, BOOL bThin, float *pflRate);
  91. STDMETHOD(IsRateSupported)(BOOL bThin, float flRate, float *pflNearestSupportedRate);
  92. // IMFVideoDeviceID methods
  93. STDMETHOD(GetDeviceID)(IID* pDeviceID);
  94. // IMFTopologyServiceLookupClient methods
  95. STDMETHOD(InitServicePointers)(IMFTopologyServiceLookup *pLookup);
  96. STDMETHOD(ReleaseServicePointers)();
  97. // IMFVideoDisplayControl methods
  98. STDMETHOD(GetNativeVideoSize)(SIZE* pszVideo, SIZE* pszARVideo) { return E_NOTIMPL; }
  99. STDMETHOD(GetIdealVideoSize)(SIZE* pszMin, SIZE* pszMax) { return E_NOTIMPL; }
  100. STDMETHOD(SetVideoPosition)(const MFVideoNormalizedRect* pnrcSource, const LPRECT prcDest);
  101. STDMETHOD(GetVideoPosition)(MFVideoNormalizedRect* pnrcSource, LPRECT prcDest);
  102. STDMETHOD(SetAspectRatioMode)(DWORD dwAspectRatioMode) { return E_NOTIMPL; }
  103. STDMETHOD(GetAspectRatioMode)(DWORD* pdwAspectRatioMode) { return E_NOTIMPL; }
  104. STDMETHOD(SetVideoWindow)(HWND hwndVideo);
  105. STDMETHOD(GetVideoWindow)(HWND* phwndVideo);
  106. STDMETHOD(RepaintVideo)();
  107. STDMETHOD(GetCurrentImage)(BITMAPINFOHEADER* pBih, BYTE** pDib, DWORD* pcbDib, LONGLONG* pTimeStamp) { return E_NOTIMPL; }
  108. STDMETHOD(SetBorderColor)(COLORREF Clr) { return E_NOTIMPL; }
  109. STDMETHOD(GetBorderColor)(COLORREF* pClr) { return E_NOTIMPL; }
  110. STDMETHOD(SetRenderingPrefs)(DWORD dwRenderFlags) { return E_NOTIMPL; }
  111. STDMETHOD(GetRenderingPrefs)(DWORD* pdwRenderFlags) { return E_NOTIMPL; }
  112. STDMETHOD(SetFullscreen)(BOOL bFullscreen) { return E_NOTIMPL; }
  113. STDMETHOD(GetFullscreen)(BOOL* pbFullscreen) { return E_NOTIMPL; }
  114. protected:
  115. EVRCustomPresenter(HRESULT& hr);
  116. virtual ~EVRCustomPresenter();
  117. // CheckShutdown:
  118. // Returns MF_E_SHUTDOWN if the presenter is shutdown.
  119. // Call this at the start of any methods that should fail after shutdown.
  120. inline HRESULT CheckShutdown() const
  121. {
  122. if (m_RenderState == RENDER_STATE_SHUTDOWN)
  123. {
  124. return MF_E_SHUTDOWN;
  125. }
  126. else
  127. {
  128. return S_OK;
  129. }
  130. }
  131. // IsActive: The "active" state is started or paused.
  132. inline BOOL IsActive() const
  133. {
  134. return ((m_RenderState == RENDER_STATE_STARTED) || (m_RenderState == RENDER_STATE_PAUSED));
  135. }
  136. // IsScrubbing: Scrubbing occurs when the frame rate is 0.
  137. inline BOOL IsScrubbing() const { return m_fRate == 0.0f; }
  138. // NotifyEvent: Send an event to the EVR through its IMediaEventSink interface.
  139. void NotifyEvent(long EventCode, LONG_PTR Param1, LONG_PTR Param2)
  140. {
  141. if (m_pMediaEventSink)
  142. {
  143. m_pMediaEventSink->Notify(EventCode, Param1, Param2);
  144. }
  145. }
  146. float GetMaxRate(BOOL bThin);
  147. // Mixer operations
  148. HRESULT ConfigureMixer(IMFTransform *pMixer);
  149. // Formats
  150. HRESULT CreateOptimalVideoType(IMFMediaType* pProposed, IMFMediaType **ppOptimal);
  151. HRESULT CalculateOutputRectangle(IMFMediaType *pProposed, RECT *prcOutput);
  152. HRESULT SetMediaType(IMFMediaType *pMediaType);
  153. HRESULT IsMediaTypeSupported(IMFMediaType *pMediaType);
  154. // Message handlers
  155. HRESULT Flush();
  156. HRESULT RenegotiateMediaType();
  157. HRESULT ProcessInputNotify();
  158. HRESULT BeginStreaming();
  159. HRESULT EndStreaming();
  160. HRESULT CheckEndOfStream();
  161. // Managing samples
  162. void ProcessOutputLoop();
  163. HRESULT ProcessOutput();
  164. HRESULT DeliverSample(IMFSample *pSample, BOOL bRepaint);
  165. HRESULT TrackSample(IMFSample *pSample);
  166. void ReleaseResources();
  167. // Frame-stepping
  168. HRESULT PrepareFrameStep(DWORD cSteps);
  169. HRESULT StartFrameStep();
  170. HRESULT DeliverFrameStepSample(IMFSample *pSample);
  171. HRESULT CompleteFrameStep(IMFSample *pSample);
  172. HRESULT CancelFrameStep();
  173. // Callbacks
  174. // Callback when a video sample is released.
  175. HRESULT OnSampleFree(IMFAsyncResult *pResult);
  176. AsyncCallback<EVRCustomPresenter> m_SampleFreeCB;
  177. protected:
  178. // FrameStep: Holds information related to frame-stepping.
  179. // Note: The purpose of this structure is simply to organize the data in one variable.
  180. struct FrameStep
  181. {
  182. FrameStep() : state(FRAMESTEP_NONE), steps(0), pSampleNoRef(NULL)
  183. {
  184. }
  185. FRAMESTEP_STATE state; // Current frame-step state.
  186. VideoSampleList samples; // List of pending samples for frame-stepping.
  187. DWORD steps; // Number of steps left.
  188. DWORD_PTR pSampleNoRef; // Identifies the frame-step sample.
  189. };
  190. protected:
  191. RENDER_STATE m_RenderState; // Rendering state.
  192. FrameStep m_FrameStep; // Frame-stepping information.
  193. CritSec m_ObjectLock; // Serializes our public methods.
  194. // Samples and scheduling
  195. Scheduler m_scheduler; // Manages scheduling of samples.
  196. SamplePool m_SamplePool; // Pool of allocated samples.
  197. DWORD m_TokenCounter; // Counter. Incremented whenever we create new samples.
  198. // Rendering state
  199. BOOL m_bSampleNotify; // Did the mixer signal it has an input sample?
  200. BOOL m_bRepaint; // Do we need to repaint the last sample?
  201. BOOL m_bPrerolled; // Have we presented at least one sample?
  202. BOOL m_bEndStreaming; // Did we reach the end of the stream (EOS)?
  203. MFVideoNormalizedRect m_nrcSource; // Source rectangle.
  204. float m_fRate; // Playback rate.
  205. // Deletable objects.
  206. D3DPresentEngine *m_pD3DPresentEngine; // Rendering engine. (Never null if the constructor succeeds.)
  207. // COM interfaces.
  208. IMFClock *m_pClock; // The EVR's clock.
  209. IMFTransform *m_pMixer; // The mixer.
  210. IMediaEventSink *m_pMediaEventSink; // The EVR's event-sink interface.
  211. IMFMediaType *m_pMediaType; // Output media type
  212. private: // disallow copy and assign
  213. EVRCustomPresenter(const EVRCustomPresenter&);
  214. void operator=(const EVRCustomPresenter&);
  215. };