dom/camera/CameraPreviewMediaStream.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 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
michael@0 4 * You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #include "CameraPreviewMediaStream.h"
michael@0 7
michael@0 8 using namespace mozilla::layers;
michael@0 9 using namespace mozilla::dom;
michael@0 10
michael@0 11 namespace mozilla {
michael@0 12
michael@0 13 CameraPreviewMediaStream::CameraPreviewMediaStream(DOMMediaStream* aWrapper)
michael@0 14 : MediaStream(aWrapper)
michael@0 15 , mMutex("mozilla::camera::CameraPreviewMediaStream")
michael@0 16 , mFrameCallback(nullptr)
michael@0 17 {
michael@0 18 SetGraphImpl(MediaStreamGraph::GetInstance());
michael@0 19 mIsConsumed = false;
michael@0 20 }
michael@0 21
michael@0 22 void
michael@0 23 CameraPreviewMediaStream::AddAudioOutput(void* aKey)
michael@0 24 {
michael@0 25 }
michael@0 26
michael@0 27 void
michael@0 28 CameraPreviewMediaStream::SetAudioOutputVolume(void* aKey, float aVolume)
michael@0 29 {
michael@0 30 }
michael@0 31
michael@0 32 void
michael@0 33 CameraPreviewMediaStream::RemoveAudioOutput(void* aKey)
michael@0 34 {
michael@0 35 }
michael@0 36
michael@0 37 void
michael@0 38 CameraPreviewMediaStream::AddVideoOutput(VideoFrameContainer* aContainer)
michael@0 39 {
michael@0 40 MutexAutoLock lock(mMutex);
michael@0 41 nsRefPtr<VideoFrameContainer> container = aContainer;
michael@0 42 AddVideoOutputImpl(container.forget());
michael@0 43
michael@0 44 if (mVideoOutputs.Length() > 1) {
michael@0 45 return;
michael@0 46 }
michael@0 47 MediaStreamGraph* gm = MediaStreamGraph::GetInstance();
michael@0 48 mIsConsumed = true;
michael@0 49 for (uint32_t j = 0; j < mListeners.Length(); ++j) {
michael@0 50 MediaStreamListener* l = mListeners[j];
michael@0 51 l->NotifyConsumptionChanged(gm, MediaStreamListener::CONSUMED);
michael@0 52 }
michael@0 53 }
michael@0 54
michael@0 55 void
michael@0 56 CameraPreviewMediaStream::RemoveVideoOutput(VideoFrameContainer* aContainer)
michael@0 57 {
michael@0 58 MutexAutoLock lock(mMutex);
michael@0 59 RemoveVideoOutputImpl(aContainer);
michael@0 60
michael@0 61 if (!mVideoOutputs.IsEmpty()) {
michael@0 62 return;
michael@0 63 }
michael@0 64 MediaStreamGraph* gm = MediaStreamGraph::GetInstance();
michael@0 65 mIsConsumed = false;
michael@0 66 for (uint32_t j = 0; j < mListeners.Length(); ++j) {
michael@0 67 MediaStreamListener* l = mListeners[j];
michael@0 68 l->NotifyConsumptionChanged(gm, MediaStreamListener::NOT_CONSUMED);
michael@0 69 }
michael@0 70 }
michael@0 71
michael@0 72 void
michael@0 73 CameraPreviewMediaStream::ChangeExplicitBlockerCount(int32_t aDelta)
michael@0 74 {
michael@0 75 }
michael@0 76
michael@0 77 void
michael@0 78 CameraPreviewMediaStream::AddListener(MediaStreamListener* aListener)
michael@0 79 {
michael@0 80 MutexAutoLock lock(mMutex);
michael@0 81
michael@0 82 MediaStreamGraph* gm = MediaStreamGraph::GetInstance();
michael@0 83 MediaStreamListener* listener = *mListeners.AppendElement() = aListener;
michael@0 84 listener->NotifyBlockingChanged(gm, MediaStreamListener::UNBLOCKED);
michael@0 85 }
michael@0 86
michael@0 87 void
michael@0 88 CameraPreviewMediaStream::RemoveListener(MediaStreamListener* aListener)
michael@0 89 {
michael@0 90 MutexAutoLock lock(mMutex);
michael@0 91
michael@0 92 MediaStreamGraph* gm = MediaStreamGraph::GetInstance();
michael@0 93 nsRefPtr<MediaStreamListener> listener(aListener);
michael@0 94 mListeners.RemoveElement(aListener);
michael@0 95 listener->NotifyRemoved(gm);
michael@0 96 }
michael@0 97
michael@0 98 void
michael@0 99 CameraPreviewMediaStream::Destroy()
michael@0 100 {
michael@0 101 MutexAutoLock lock(mMutex);
michael@0 102 DestroyImpl();
michael@0 103 }
michael@0 104
michael@0 105 void
michael@0 106 CameraPreviewMediaStream::SetCurrentFrame(const gfxIntSize& aIntrinsicSize, Image* aImage)
michael@0 107 {
michael@0 108 MutexAutoLock lock(mMutex);
michael@0 109
michael@0 110 TimeStamp now = TimeStamp::Now();
michael@0 111 for (uint32_t i = 0; i < mVideoOutputs.Length(); ++i) {
michael@0 112 VideoFrameContainer* output = mVideoOutputs[i];
michael@0 113 output->SetCurrentFrame(aIntrinsicSize, aImage, now);
michael@0 114 nsCOMPtr<nsIRunnable> event =
michael@0 115 NS_NewRunnableMethod(output, &VideoFrameContainer::Invalidate);
michael@0 116 NS_DispatchToMainThread(event, NS_DISPATCH_NORMAL);
michael@0 117 }
michael@0 118
michael@0 119 if (mFrameCallback) {
michael@0 120 mFrameCallback->OnNewFrame(aIntrinsicSize, aImage);
michael@0 121 }
michael@0 122 }
michael@0 123
michael@0 124 void
michael@0 125 CameraPreviewMediaStream::ClearCurrentFrame()
michael@0 126 {
michael@0 127 MutexAutoLock lock(mMutex);
michael@0 128
michael@0 129 for (uint32_t i = 0; i < mVideoOutputs.Length(); ++i) {
michael@0 130 VideoFrameContainer* output = mVideoOutputs[i];
michael@0 131 output->ClearCurrentFrame();
michael@0 132 nsCOMPtr<nsIRunnable> event =
michael@0 133 NS_NewRunnableMethod(output, &VideoFrameContainer::Invalidate);
michael@0 134 NS_DispatchToMainThread(event, NS_DISPATCH_NORMAL);
michael@0 135 }
michael@0 136 }
michael@0 137
michael@0 138 }

mercurial