1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/media/wmf/WMFSourceReaderCallback.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,83 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* vim:set ts=2 sw=2 sts=2 et cindent: */ 1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 +#if !defined(WMFSourceReaderCallback_h_) 1.10 +#define WMFSourceReaderCallback_h_ 1.11 + 1.12 +#include "WMF.h" 1.13 +#include "mozilla/ReentrantMonitor.h" 1.14 +#include "mozilla/RefPtr.h" 1.15 +#include "nsISupportsImpl.h" 1.16 + 1.17 +namespace mozilla { 1.18 + 1.19 +// A listener which we pass into the IMFSourceReader upon creation which is 1.20 +// notified when an asynchronous call to IMFSourceReader::ReadSample() 1.21 +// completes. This allows us to abort ReadSample() operations when the 1.22 +// WMFByteStream's underlying MediaResource is closed. This ensures that 1.23 +// the decode threads don't get stuck in a synchronous ReadSample() call 1.24 +// when the MediaResource is unexpectedly shutdown. 1.25 +class WMFSourceReaderCallback MOZ_FINAL : public IMFSourceReaderCallback 1.26 +{ 1.27 +public: 1.28 + WMFSourceReaderCallback(); 1.29 + 1.30 + // IUnknown Methods. 1.31 + STDMETHODIMP QueryInterface(REFIID aIId, LPVOID *aInterface); 1.32 + STDMETHODIMP_(ULONG) AddRef(); 1.33 + STDMETHODIMP_(ULONG) Release(); 1.34 + 1.35 + // IMFSourceReaderCallback methods 1.36 + STDMETHODIMP OnReadSample(HRESULT hrStatus, 1.37 + DWORD dwStreamIndex, 1.38 + DWORD dwStreamFlags, 1.39 + LONGLONG llTimestamp, 1.40 + IMFSample *pSample); 1.41 + STDMETHODIMP OnEvent(DWORD, IMFMediaEvent *); 1.42 + STDMETHODIMP OnFlush(DWORD); 1.43 + 1.44 + // Causes the calling thread to block waiting for the 1.45 + // IMFSourceReader::ReadSample() result callback to occur, or for the 1.46 + // WMFByteStream to be closed. 1.47 + HRESULT Wait(DWORD* aStreamFlags, 1.48 + LONGLONG* aTimeStamp, 1.49 + IMFSample** aSample); 1.50 + 1.51 + // Cancels Wait() calls. 1.52 + HRESULT Cancel(); 1.53 + 1.54 +private: 1.55 + 1.56 + // Sets state to record the result of a read, and awake threads 1.57 + // waiting in Wait(). 1.58 + HRESULT NotifyReadComplete(HRESULT aReadStatus, 1.59 + DWORD aStreamIndex, 1.60 + DWORD aStreamFlags, 1.61 + LONGLONG aTimestamp, 1.62 + IMFSample *aSample); 1.63 + 1.64 + // Synchronizes all member data in this class, and Wait() blocks on 1.65 + // and NotifyReadComplete() notifies this monitor. 1.66 + ReentrantMonitor mMonitor; 1.67 + 1.68 + // Read result data. 1.69 + HRESULT mResultStatus; 1.70 + DWORD mStreamFlags; 1.71 + LONGLONG mTimestamp; 1.72 + IMFSample* mSample; 1.73 + 1.74 + // Sentinal. Set to true when a read result is returned. Wait() won't exit 1.75 + // until this is set to true. 1.76 + bool mReadFinished; 1.77 + 1.78 + // IUnknown ref counting. 1.79 + ThreadSafeAutoRefCnt mRefCnt; 1.80 + NS_DECL_OWNINGTHREAD 1.81 + 1.82 +}; 1.83 + 1.84 +} // namespace mozilla 1.85 + 1.86 +#endif // WMFSourceReaderCallback_h_