content/media/wmf/WMFSourceReaderCallback.h

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* vim:set ts=2 sw=2 sts=2 et cindent: */
michael@0 3 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 6 #if !defined(WMFSourceReaderCallback_h_)
michael@0 7 #define WMFSourceReaderCallback_h_
michael@0 8
michael@0 9 #include "WMF.h"
michael@0 10 #include "mozilla/ReentrantMonitor.h"
michael@0 11 #include "mozilla/RefPtr.h"
michael@0 12 #include "nsISupportsImpl.h"
michael@0 13
michael@0 14 namespace mozilla {
michael@0 15
michael@0 16 // A listener which we pass into the IMFSourceReader upon creation which is
michael@0 17 // notified when an asynchronous call to IMFSourceReader::ReadSample()
michael@0 18 // completes. This allows us to abort ReadSample() operations when the
michael@0 19 // WMFByteStream's underlying MediaResource is closed. This ensures that
michael@0 20 // the decode threads don't get stuck in a synchronous ReadSample() call
michael@0 21 // when the MediaResource is unexpectedly shutdown.
michael@0 22 class WMFSourceReaderCallback MOZ_FINAL : public IMFSourceReaderCallback
michael@0 23 {
michael@0 24 public:
michael@0 25 WMFSourceReaderCallback();
michael@0 26
michael@0 27 // IUnknown Methods.
michael@0 28 STDMETHODIMP QueryInterface(REFIID aIId, LPVOID *aInterface);
michael@0 29 STDMETHODIMP_(ULONG) AddRef();
michael@0 30 STDMETHODIMP_(ULONG) Release();
michael@0 31
michael@0 32 // IMFSourceReaderCallback methods
michael@0 33 STDMETHODIMP OnReadSample(HRESULT hrStatus,
michael@0 34 DWORD dwStreamIndex,
michael@0 35 DWORD dwStreamFlags,
michael@0 36 LONGLONG llTimestamp,
michael@0 37 IMFSample *pSample);
michael@0 38 STDMETHODIMP OnEvent(DWORD, IMFMediaEvent *);
michael@0 39 STDMETHODIMP OnFlush(DWORD);
michael@0 40
michael@0 41 // Causes the calling thread to block waiting for the
michael@0 42 // IMFSourceReader::ReadSample() result callback to occur, or for the
michael@0 43 // WMFByteStream to be closed.
michael@0 44 HRESULT Wait(DWORD* aStreamFlags,
michael@0 45 LONGLONG* aTimeStamp,
michael@0 46 IMFSample** aSample);
michael@0 47
michael@0 48 // Cancels Wait() calls.
michael@0 49 HRESULT Cancel();
michael@0 50
michael@0 51 private:
michael@0 52
michael@0 53 // Sets state to record the result of a read, and awake threads
michael@0 54 // waiting in Wait().
michael@0 55 HRESULT NotifyReadComplete(HRESULT aReadStatus,
michael@0 56 DWORD aStreamIndex,
michael@0 57 DWORD aStreamFlags,
michael@0 58 LONGLONG aTimestamp,
michael@0 59 IMFSample *aSample);
michael@0 60
michael@0 61 // Synchronizes all member data in this class, and Wait() blocks on
michael@0 62 // and NotifyReadComplete() notifies this monitor.
michael@0 63 ReentrantMonitor mMonitor;
michael@0 64
michael@0 65 // Read result data.
michael@0 66 HRESULT mResultStatus;
michael@0 67 DWORD mStreamFlags;
michael@0 68 LONGLONG mTimestamp;
michael@0 69 IMFSample* mSample;
michael@0 70
michael@0 71 // Sentinal. Set to true when a read result is returned. Wait() won't exit
michael@0 72 // until this is set to true.
michael@0 73 bool mReadFinished;
michael@0 74
michael@0 75 // IUnknown ref counting.
michael@0 76 ThreadSafeAutoRefCnt mRefCnt;
michael@0 77 NS_DECL_OWNINGTHREAD
michael@0 78
michael@0 79 };
michael@0 80
michael@0 81 } // namespace mozilla
michael@0 82
michael@0 83 #endif // WMFSourceReaderCallback_h_

mercurial