michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim:set ts=2 sw=2 sts=2 et cindent: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: #if !defined(WMFSourceReaderCallback_h_) michael@0: #define WMFSourceReaderCallback_h_ michael@0: michael@0: #include "WMF.h" michael@0: #include "mozilla/ReentrantMonitor.h" michael@0: #include "mozilla/RefPtr.h" michael@0: #include "nsISupportsImpl.h" michael@0: michael@0: namespace mozilla { michael@0: michael@0: // A listener which we pass into the IMFSourceReader upon creation which is michael@0: // notified when an asynchronous call to IMFSourceReader::ReadSample() michael@0: // completes. This allows us to abort ReadSample() operations when the michael@0: // WMFByteStream's underlying MediaResource is closed. This ensures that michael@0: // the decode threads don't get stuck in a synchronous ReadSample() call michael@0: // when the MediaResource is unexpectedly shutdown. michael@0: class WMFSourceReaderCallback MOZ_FINAL : public IMFSourceReaderCallback michael@0: { michael@0: public: michael@0: WMFSourceReaderCallback(); michael@0: michael@0: // IUnknown Methods. michael@0: STDMETHODIMP QueryInterface(REFIID aIId, LPVOID *aInterface); michael@0: STDMETHODIMP_(ULONG) AddRef(); michael@0: STDMETHODIMP_(ULONG) Release(); michael@0: michael@0: // IMFSourceReaderCallback methods michael@0: STDMETHODIMP OnReadSample(HRESULT hrStatus, michael@0: DWORD dwStreamIndex, michael@0: DWORD dwStreamFlags, michael@0: LONGLONG llTimestamp, michael@0: IMFSample *pSample); michael@0: STDMETHODIMP OnEvent(DWORD, IMFMediaEvent *); michael@0: STDMETHODIMP OnFlush(DWORD); michael@0: michael@0: // Causes the calling thread to block waiting for the michael@0: // IMFSourceReader::ReadSample() result callback to occur, or for the michael@0: // WMFByteStream to be closed. michael@0: HRESULT Wait(DWORD* aStreamFlags, michael@0: LONGLONG* aTimeStamp, michael@0: IMFSample** aSample); michael@0: michael@0: // Cancels Wait() calls. michael@0: HRESULT Cancel(); michael@0: michael@0: private: michael@0: michael@0: // Sets state to record the result of a read, and awake threads michael@0: // waiting in Wait(). michael@0: HRESULT NotifyReadComplete(HRESULT aReadStatus, michael@0: DWORD aStreamIndex, michael@0: DWORD aStreamFlags, michael@0: LONGLONG aTimestamp, michael@0: IMFSample *aSample); michael@0: michael@0: // Synchronizes all member data in this class, and Wait() blocks on michael@0: // and NotifyReadComplete() notifies this monitor. michael@0: ReentrantMonitor mMonitor; michael@0: michael@0: // Read result data. michael@0: HRESULT mResultStatus; michael@0: DWORD mStreamFlags; michael@0: LONGLONG mTimestamp; michael@0: IMFSample* mSample; michael@0: michael@0: // Sentinal. Set to true when a read result is returned. Wait() won't exit michael@0: // until this is set to true. michael@0: bool mReadFinished; michael@0: michael@0: // IUnknown ref counting. michael@0: ThreadSafeAutoRefCnt mRefCnt; michael@0: NS_DECL_OWNINGTHREAD michael@0: michael@0: }; michael@0: michael@0: } // namespace mozilla michael@0: michael@0: #endif // WMFSourceReaderCallback_h_