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.

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

mercurial