OcvTransform.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. // Defines the transform class.
  2. //
  3. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
  4. // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
  5. // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  6. // PARTICULAR PURPOSE.
  7. //
  8. // Copyright (c) Microsoft Corporation. All rights reserved.
  9. #ifndef GRAYSCALE_H
  10. #define GRAYSCALE_H
  11. #include <new>
  12. #include <mfapi.h>
  13. #include <mftransform.h>
  14. #include <mfidl.h>
  15. #include <mferror.h>
  16. #include <strsafe.h>
  17. #include <assert.h>
  18. #include <wrl\implements.h>
  19. #include <wrl\module.h>
  20. #include <windows.media.h>
  21. #include "OcvImageManipulations.h"
  22. // CLSID of the MFT.
  23. DEFINE_GUID(CLSID_GrayscaleMFT,
  24. 0x2f3dbc05, 0xc011, 0x4a8f, 0xb2, 0x64, 0xe4, 0x2e, 0x35, 0xc6, 0x7b, 0xf4);
  25. //
  26. // * IMPORTANT: If you implement your own MFT, create a new GUID for the CLSID. *
  27. //
  28. // Configuration attributes
  29. // {698649BE-8EAE-4551-A4CB-3EC98FBD3D86}
  30. DEFINE_GUID(OCV_IMAGE_EFFECT,
  31. 0x698649be, 0x8eae, 0x4551, 0xa4, 0xcb, 0x3e, 0xc9, 0x8f, 0xbd, 0x3d, 0x86);
  32. enum ProcessingType
  33. {
  34. Preview,
  35. GrayScale,
  36. Canny,
  37. Sobel,
  38. Histogram,
  39. InvalidEffect
  40. };
  41. template <class T> void SafeRelease(T **ppT)
  42. {
  43. if (*ppT)
  44. {
  45. (*ppT)->Release();
  46. *ppT = NULL;
  47. }
  48. }
  49. // OcvImageManipulations class:
  50. // Implements a grayscale video effect.
  51. class OcvImageManipulations
  52. : public Microsoft::WRL::RuntimeClass<
  53. Microsoft::WRL::RuntimeClassFlags< Microsoft::WRL::RuntimeClassType::WinRtClassicComMix >,
  54. ABI::Windows::Media::IMediaExtension,
  55. IMFTransform >
  56. {
  57. InspectableClass(RuntimeClass_OcvTransform_OcvImageManipulations, BaseTrust)
  58. public:
  59. OcvImageManipulations();
  60. ~OcvImageManipulations();
  61. STDMETHOD(RuntimeClassInitialize)();
  62. // IMediaExtension
  63. STDMETHODIMP SetProperties(ABI::Windows::Foundation::Collections::IPropertySet *pConfiguration);
  64. // IMFTransform
  65. STDMETHODIMP GetStreamLimits(
  66. DWORD *pdwInputMinimum,
  67. DWORD *pdwInputMaximum,
  68. DWORD *pdwOutputMinimum,
  69. DWORD *pdwOutputMaximum
  70. );
  71. STDMETHODIMP GetStreamCount(
  72. DWORD *pcInputStreams,
  73. DWORD *pcOutputStreams
  74. );
  75. STDMETHODIMP GetStreamIDs(
  76. DWORD dwInputIDArraySize,
  77. DWORD *pdwInputIDs,
  78. DWORD dwOutputIDArraySize,
  79. DWORD *pdwOutputIDs
  80. );
  81. STDMETHODIMP GetInputStreamInfo(
  82. DWORD dwInputStreamID,
  83. MFT_INPUT_STREAM_INFO * pStreamInfo
  84. );
  85. STDMETHODIMP GetOutputStreamInfo(
  86. DWORD dwOutputStreamID,
  87. MFT_OUTPUT_STREAM_INFO * pStreamInfo
  88. );
  89. STDMETHODIMP GetAttributes(IMFAttributes** pAttributes);
  90. STDMETHODIMP GetInputStreamAttributes(
  91. DWORD dwInputStreamID,
  92. IMFAttributes **ppAttributes
  93. );
  94. STDMETHODIMP GetOutputStreamAttributes(
  95. DWORD dwOutputStreamID,
  96. IMFAttributes **ppAttributes
  97. );
  98. STDMETHODIMP DeleteInputStream(DWORD dwStreamID);
  99. STDMETHODIMP AddInputStreams(
  100. DWORD cStreams,
  101. DWORD *adwStreamIDs
  102. );
  103. STDMETHODIMP GetInputAvailableType(
  104. DWORD dwInputStreamID,
  105. DWORD dwTypeIndex, // 0-based
  106. IMFMediaType **ppType
  107. );
  108. STDMETHODIMP GetOutputAvailableType(
  109. DWORD dwOutputStreamID,
  110. DWORD dwTypeIndex, // 0-based
  111. IMFMediaType **ppType
  112. );
  113. STDMETHODIMP SetInputType(
  114. DWORD dwInputStreamID,
  115. IMFMediaType *pType,
  116. DWORD dwFlags
  117. );
  118. STDMETHODIMP SetOutputType(
  119. DWORD dwOutputStreamID,
  120. IMFMediaType *pType,
  121. DWORD dwFlags
  122. );
  123. STDMETHODIMP GetInputCurrentType(
  124. DWORD dwInputStreamID,
  125. IMFMediaType **ppType
  126. );
  127. STDMETHODIMP GetOutputCurrentType(
  128. DWORD dwOutputStreamID,
  129. IMFMediaType **ppType
  130. );
  131. STDMETHODIMP GetInputStatus(
  132. DWORD dwInputStreamID,
  133. DWORD *pdwFlags
  134. );
  135. STDMETHODIMP GetOutputStatus(DWORD *pdwFlags);
  136. STDMETHODIMP SetOutputBounds(
  137. LONGLONG hnsLowerBound,
  138. LONGLONG hnsUpperBound
  139. );
  140. STDMETHODIMP ProcessEvent(
  141. DWORD dwInputStreamID,
  142. IMFMediaEvent *pEvent
  143. );
  144. STDMETHODIMP ProcessMessage(
  145. MFT_MESSAGE_TYPE eMessage,
  146. ULONG_PTR ulParam
  147. );
  148. STDMETHODIMP ProcessInput(
  149. DWORD dwInputStreamID,
  150. IMFSample *pSample,
  151. DWORD dwFlags
  152. );
  153. STDMETHODIMP ProcessOutput(
  154. DWORD dwFlags,
  155. DWORD cOutputBufferCount,
  156. MFT_OUTPUT_DATA_BUFFER *pOutputSamples, // one per stream
  157. DWORD *pdwStatus
  158. );
  159. private:
  160. // HasPendingOutput: Returns TRUE if the MFT is holding an input sample.
  161. BOOL HasPendingOutput() const { return m_pSample != NULL; }
  162. // IsValidInputStream: Returns TRUE if dwInputStreamID is a valid input stream identifier.
  163. BOOL IsValidInputStream(DWORD dwInputStreamID) const
  164. {
  165. return dwInputStreamID == 0;
  166. }
  167. // IsValidOutputStream: Returns TRUE if dwOutputStreamID is a valid output stream identifier.
  168. BOOL IsValidOutputStream(DWORD dwOutputStreamID) const
  169. {
  170. return dwOutputStreamID == 0;
  171. }
  172. HRESULT OnGetPartialType(DWORD dwTypeIndex, IMFMediaType **ppmt);
  173. HRESULT OnCheckInputType(IMFMediaType *pmt);
  174. HRESULT OnCheckOutputType(IMFMediaType *pmt);
  175. HRESULT OnCheckMediaType(IMFMediaType *pmt);
  176. void OnSetInputType(IMFMediaType *pmt);
  177. void OnSetOutputType(IMFMediaType *pmt);
  178. HRESULT BeginStreaming();
  179. HRESULT EndStreaming();
  180. HRESULT OnProcessOutput(IMFMediaBuffer *pIn, IMFMediaBuffer *pOut);
  181. HRESULT OnFlush();
  182. HRESULT UpdateFormatInfo();
  183. CRITICAL_SECTION m_critSec;
  184. // Transformation parameters
  185. ProcessingType m_TransformType;
  186. // Streaming
  187. bool m_bStreamingInitialized;
  188. IMFSample *m_pSample; // Input sample.
  189. IMFMediaType *m_pInputType; // Input media type.
  190. IMFMediaType *m_pOutputType; // Output media type.
  191. // Fomat information
  192. UINT32 m_imageWidthInPixels;
  193. UINT32 m_imageHeightInPixels;
  194. DWORD m_cbImageSize; // Image size, in bytes.
  195. IMFAttributes *m_pAttributes;
  196. };
  197. #endif