This source file includes following definitions.
- SafeRelease
#ifndef GRAYSCALE_H
#define GRAYSCALE_H
#include <new>
#include <mfapi.h>
#include <mftransform.h>
#include <mfidl.h>
#include <mferror.h>
#include <strsafe.h>
#include <assert.h>
#include <wrl\implements.h>
#include <wrl\module.h>
#include <windows.media.h>
#include "OcvImageManipulations.h"
DEFINE_GUID(CLSID_GrayscaleMFT,
0x2f3dbc05, 0xc011, 0x4a8f, 0xb2, 0x64, 0xe4, 0x2e, 0x35, 0xc6, 0x7b, 0xf4);
DEFINE_GUID(OCV_IMAGE_EFFECT,
0x698649be, 0x8eae, 0x4551, 0xa4, 0xcb, 0x3e, 0xc9, 0x8f, 0xbd, 0x3d, 0x86);
enum ProcessingType
{
Preview,
GrayScale,
Canny,
Sobel,
Histogram,
InvalidEffect
};
template <class T> void SafeRelease(T **ppT)
{
if (*ppT)
{
(*ppT)->Release();
*ppT = NULL;
}
}
class OcvImageManipulations
: public Microsoft::WRL::RuntimeClass<
Microsoft::WRL::RuntimeClassFlags< Microsoft::WRL::RuntimeClassType::WinRtClassicComMix >,
ABI::Windows::Media::IMediaExtension,
IMFTransform >
{
InspectableClass(RuntimeClass_OcvTransform_OcvImageManipulations, BaseTrust)
public:
OcvImageManipulations();
~OcvImageManipulations();
STDMETHOD(RuntimeClassInitialize)();
STDMETHODIMP SetProperties(ABI::Windows::Foundation::Collections::IPropertySet *pConfiguration);
STDMETHODIMP GetStreamLimits(
DWORD *pdwInputMinimum,
DWORD *pdwInputMaximum,
DWORD *pdwOutputMinimum,
DWORD *pdwOutputMaximum
);
STDMETHODIMP GetStreamCount(
DWORD *pcInputStreams,
DWORD *pcOutputStreams
);
STDMETHODIMP GetStreamIDs(
DWORD dwInputIDArraySize,
DWORD *pdwInputIDs,
DWORD dwOutputIDArraySize,
DWORD *pdwOutputIDs
);
STDMETHODIMP GetInputStreamInfo(
DWORD dwInputStreamID,
MFT_INPUT_STREAM_INFO * pStreamInfo
);
STDMETHODIMP GetOutputStreamInfo(
DWORD dwOutputStreamID,
MFT_OUTPUT_STREAM_INFO * pStreamInfo
);
STDMETHODIMP GetAttributes(IMFAttributes** pAttributes);
STDMETHODIMP GetInputStreamAttributes(
DWORD dwInputStreamID,
IMFAttributes **ppAttributes
);
STDMETHODIMP GetOutputStreamAttributes(
DWORD dwOutputStreamID,
IMFAttributes **ppAttributes
);
STDMETHODIMP DeleteInputStream(DWORD dwStreamID);
STDMETHODIMP AddInputStreams(
DWORD cStreams,
DWORD *adwStreamIDs
);
STDMETHODIMP GetInputAvailableType(
DWORD dwInputStreamID,
DWORD dwTypeIndex,
IMFMediaType **ppType
);
STDMETHODIMP GetOutputAvailableType(
DWORD dwOutputStreamID,
DWORD dwTypeIndex,
IMFMediaType **ppType
);
STDMETHODIMP SetInputType(
DWORD dwInputStreamID,
IMFMediaType *pType,
DWORD dwFlags
);
STDMETHODIMP SetOutputType(
DWORD dwOutputStreamID,
IMFMediaType *pType,
DWORD dwFlags
);
STDMETHODIMP GetInputCurrentType(
DWORD dwInputStreamID,
IMFMediaType **ppType
);
STDMETHODIMP GetOutputCurrentType(
DWORD dwOutputStreamID,
IMFMediaType **ppType
);
STDMETHODIMP GetInputStatus(
DWORD dwInputStreamID,
DWORD *pdwFlags
);
STDMETHODIMP GetOutputStatus(DWORD *pdwFlags);
STDMETHODIMP SetOutputBounds(
LONGLONG hnsLowerBound,
LONGLONG hnsUpperBound
);
STDMETHODIMP ProcessEvent(
DWORD dwInputStreamID,
IMFMediaEvent *pEvent
);
STDMETHODIMP ProcessMessage(
MFT_MESSAGE_TYPE eMessage,
ULONG_PTR ulParam
);
STDMETHODIMP ProcessInput(
DWORD dwInputStreamID,
IMFSample *pSample,
DWORD dwFlags
);
STDMETHODIMP ProcessOutput(
DWORD dwFlags,
DWORD cOutputBufferCount,
MFT_OUTPUT_DATA_BUFFER *pOutputSamples,
DWORD *pdwStatus
);
private:
BOOL HasPendingOutput() const { return m_pSample != NULL; }
BOOL IsValidInputStream(DWORD dwInputStreamID) const
{
return dwInputStreamID == 0;
}
BOOL IsValidOutputStream(DWORD dwOutputStreamID) const
{
return dwOutputStreamID == 0;
}
HRESULT OnGetPartialType(DWORD dwTypeIndex, IMFMediaType **ppmt);
HRESULT OnCheckInputType(IMFMediaType *pmt);
HRESULT OnCheckOutputType(IMFMediaType *pmt);
HRESULT OnCheckMediaType(IMFMediaType *pmt);
void OnSetInputType(IMFMediaType *pmt);
void OnSetOutputType(IMFMediaType *pmt);
HRESULT BeginStreaming();
HRESULT EndStreaming();
HRESULT OnProcessOutput(IMFMediaBuffer *pIn, IMFMediaBuffer *pOut);
HRESULT OnFlush();
HRESULT UpdateFormatInfo();
CRITICAL_SECTION m_critSec;
ProcessingType m_TransformType;
bool m_bStreamingInitialized;
IMFSample *m_pSample;
IMFMediaType *m_pInputType;
IMFMediaType *m_pOutputType;
UINT32 m_imageWidthInPixels;
UINT32 m_imageHeightInPixels;
DWORD m_cbImageSize;
IMFAttributes *m_pAttributes;
};
#endif