content/media/wmf/WMFSourceReaderCallback.cpp

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
michael@0 7 #include "WMFSourceReaderCallback.h"
michael@0 8 #include "WMFUtils.h"
michael@0 9
michael@0 10 namespace mozilla {
michael@0 11
michael@0 12 #ifdef PR_LOGGING
michael@0 13 static PRLogModuleInfo* gWMFSourceReaderCallbackLog = nullptr;
michael@0 14 #define WMF_CB_LOG(...) PR_LOG(gWMFSourceReaderCallbackLog, PR_LOG_DEBUG, (__VA_ARGS__))
michael@0 15 #else
michael@0 16 #define WMF_CB_LOG(...)
michael@0 17 #endif
michael@0 18
michael@0 19 // IUnknown Methods
michael@0 20 STDMETHODIMP
michael@0 21 WMFSourceReaderCallback::QueryInterface(REFIID aIId, void **aInterface)
michael@0 22 {
michael@0 23 WMF_CB_LOG("WMFSourceReaderCallback::QueryInterface %s", GetGUIDName(aIId).get());
michael@0 24
michael@0 25 if (aIId == IID_IMFSourceReaderCallback) {
michael@0 26 return DoGetInterface(static_cast<WMFSourceReaderCallback*>(this), aInterface);
michael@0 27 }
michael@0 28 if (aIId == IID_IUnknown) {
michael@0 29 return DoGetInterface(static_cast<WMFSourceReaderCallback*>(this), aInterface);
michael@0 30 }
michael@0 31
michael@0 32 *aInterface = nullptr;
michael@0 33 return E_NOINTERFACE;
michael@0 34 }
michael@0 35
michael@0 36 NS_IMPL_ADDREF(WMFSourceReaderCallback)
michael@0 37 NS_IMPL_RELEASE(WMFSourceReaderCallback)
michael@0 38
michael@0 39 WMFSourceReaderCallback::WMFSourceReaderCallback()
michael@0 40 : mMonitor("WMFSourceReaderCallback")
michael@0 41 , mResultStatus(S_OK)
michael@0 42 , mStreamFlags(0)
michael@0 43 , mTimestamp(0)
michael@0 44 , mSample(nullptr)
michael@0 45 , mReadFinished(false)
michael@0 46 {
michael@0 47 #ifdef PR_LOGGING
michael@0 48 if (!gWMFSourceReaderCallbackLog) {
michael@0 49 gWMFSourceReaderCallbackLog = PR_NewLogModule("WMFSourceReaderCallback");
michael@0 50 }
michael@0 51 #endif
michael@0 52 }
michael@0 53
michael@0 54 HRESULT
michael@0 55 WMFSourceReaderCallback::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 // Note: aSample can be nullptr on success if more data is required!
michael@0 62 ReentrantMonitorAutoEnter mon(mMonitor);
michael@0 63
michael@0 64 if (mSample) {
michael@0 65 // The WMFReader should have called Wait() to retrieve the last
michael@0 66 // sample returned by the last ReadSample() call, but if we're
michael@0 67 // aborting the read before Wait() is called the sample ref
michael@0 68 // can be non-null.
michael@0 69 mSample->Release();
michael@0 70 mSample = nullptr;
michael@0 71 }
michael@0 72
michael@0 73 if (SUCCEEDED(aReadStatus)) {
michael@0 74 if (aSample) {
michael@0 75 mTimestamp = aTimestamp;
michael@0 76 mSample = aSample;
michael@0 77 mSample->AddRef();
michael@0 78 }
michael@0 79 }
michael@0 80
michael@0 81 mResultStatus = aReadStatus;
michael@0 82 mStreamFlags = aStreamFlags;
michael@0 83
michael@0 84 // Set the sentinal value and notify the monitor, so that threads waiting
michael@0 85 // in Wait() are awoken.
michael@0 86 mReadFinished = true;
michael@0 87 mon.NotifyAll();
michael@0 88
michael@0 89 return S_OK;
michael@0 90 }
michael@0 91
michael@0 92 STDMETHODIMP
michael@0 93 WMFSourceReaderCallback::OnReadSample(HRESULT aReadStatus,
michael@0 94 DWORD aStreamIndex,
michael@0 95 DWORD aStreamFlags,
michael@0 96 LONGLONG aTimestamp,
michael@0 97 IMFSample *aSample)
michael@0 98 {
michael@0 99 WMF_CB_LOG("WMFSourceReaderCallback::OnReadSample() hr=0x%x flags=0x%x time=%lld sample=%p",
michael@0 100 aReadStatus, aStreamFlags, aTimestamp, aSample);
michael@0 101 return NotifyReadComplete(aReadStatus,
michael@0 102 aStreamIndex,
michael@0 103 aStreamFlags,
michael@0 104 aTimestamp,
michael@0 105 aSample);
michael@0 106 }
michael@0 107
michael@0 108 HRESULT
michael@0 109 WMFSourceReaderCallback::Cancel()
michael@0 110 {
michael@0 111 WMF_CB_LOG("WMFSourceReaderCallback::Cancel()");
michael@0 112 return NotifyReadComplete(E_ABORT,
michael@0 113 0,
michael@0 114 0,
michael@0 115 0,
michael@0 116 nullptr);
michael@0 117 }
michael@0 118
michael@0 119 STDMETHODIMP
michael@0 120 WMFSourceReaderCallback::OnEvent(DWORD, IMFMediaEvent *)
michael@0 121 {
michael@0 122 return S_OK;
michael@0 123 }
michael@0 124
michael@0 125 STDMETHODIMP
michael@0 126 WMFSourceReaderCallback::OnFlush(DWORD)
michael@0 127 {
michael@0 128 return S_OK;
michael@0 129 }
michael@0 130
michael@0 131 HRESULT
michael@0 132 WMFSourceReaderCallback::Wait(DWORD* aStreamFlags,
michael@0 133 LONGLONG* aTimeStamp,
michael@0 134 IMFSample** aSample)
michael@0 135 {
michael@0 136 ReentrantMonitorAutoEnter mon(mMonitor);
michael@0 137 WMF_CB_LOG("WMFSourceReaderCallback::Wait() starting wait");
michael@0 138 while (!mReadFinished) {
michael@0 139 mon.Wait();
michael@0 140 }
michael@0 141 mReadFinished = false;
michael@0 142 WMF_CB_LOG("WMFSourceReaderCallback::Wait() done waiting");
michael@0 143
michael@0 144 *aStreamFlags = mStreamFlags;
michael@0 145 *aTimeStamp = mTimestamp;
michael@0 146 *aSample = mSample;
michael@0 147 HRESULT hr = mResultStatus;
michael@0 148
michael@0 149 mSample = nullptr;
michael@0 150 mTimestamp = 0;
michael@0 151 mStreamFlags = 0;
michael@0 152 mResultStatus = S_OK;
michael@0 153
michael@0 154 return hr;
michael@0 155 }
michael@0 156
michael@0 157 } // namespace mozilla

mercurial