// // Copyright (C) Microsoft Corporation. All rights reserved. // #ifndef SIMPLEMEDIASTREAM_H #define SIMPLEMEDIASTREAM_H #include "SimpleMediaSource.h" namespace winrt::WindowsSample::implementation { struct SimpleMediaStream : winrt::implements { friend struct SimpleMediaSource; public: // IMFMediaEventGenerator IFACEMETHODIMP BeginGetEvent(IMFAsyncCallback* pCallback, IUnknown* punkState) override; IFACEMETHODIMP EndGetEvent(IMFAsyncResult* pResult, IMFMediaEvent** ppEvent) override; IFACEMETHODIMP GetEvent(DWORD dwFlags, IMFMediaEvent** ppEvent) override; IFACEMETHODIMP QueueEvent(MediaEventType met, REFGUID guidExtendedType, HRESULT hrStatus, const PROPVARIANT* pvValue) override; // IMFMediaStream IFACEMETHODIMP GetMediaSource(IMFMediaSource** ppMediaSource) override; IFACEMETHODIMP GetStreamDescriptor(IMFStreamDescriptor** ppStreamDescriptor) override; IFACEMETHODIMP RequestSample(IUnknown* pToken) override; // IMFMediaStream2 IFACEMETHODIMP SetStreamState(_In_ MF_STREAM_STATE state) override; IFACEMETHODIMP GetStreamState(_Out_ MF_STREAM_STATE* pState) override; // Non-interface methods. HRESULT Initialize(_In_ SimpleMediaSource* pSource, _In_ DWORD streamId, _In_ MFSampleAllocatorUsage allocatorUsage); HRESULT Start(); HRESULT Stop(); HRESULT Shutdown(); HRESULT SetSampleAllocator(_In_ IMFVideoSampleAllocator* pAllocator); DWORD Id() const { return m_dwStreamId; } MFSampleAllocatorUsage SampleAlloactorUsage() const { return m_allocatorUsage; } void SetRGBMask(ULONG rgbMask) { winrt::slim_lock_guard lock(m_Lock); m_rgbMask = rgbMask; } ULONG GetRGBMask() { winrt::slim_lock_guard lock(m_Lock); return m_rgbMask; } protected: HRESULT _CheckShutdownRequiresLock(); HRESULT _SetStreamAttributes(IMFAttributes* pAttributeStore); HRESULT _SetStreamDescriptorAttributes(IMFAttributes* pAttributeStore); private: winrt::slim_mutex m_Lock; wil::com_ptr_nothrow m_parent; wil::com_ptr_nothrow m_spEventQueue; wil::com_ptr_nothrow m_spAttributes; wil::com_ptr_nothrow m_spStreamDesc; wil::com_ptr_nothrow m_spSampleAllocator; wistd::unique_ptr m_spFrameGenerator; bool m_bIsShutdown = false; MF_STREAM_STATE m_streamState = MF_STREAM_STATE_STOPPED; ULONG m_rgbMask = KSPROPERTY_SIMPLEMEDIASOURCE_CUSTOMCONTROL_COLORMODE_BLUE; DWORD m_dwStreamId; MFSampleAllocatorUsage m_allocatorUsage; }; } #endif