michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-*/ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this file, michael@0: * You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "CameraPreviewMediaStream.h" michael@0: michael@0: using namespace mozilla::layers; michael@0: using namespace mozilla::dom; michael@0: michael@0: namespace mozilla { michael@0: michael@0: CameraPreviewMediaStream::CameraPreviewMediaStream(DOMMediaStream* aWrapper) michael@0: : MediaStream(aWrapper) michael@0: , mMutex("mozilla::camera::CameraPreviewMediaStream") michael@0: , mFrameCallback(nullptr) michael@0: { michael@0: SetGraphImpl(MediaStreamGraph::GetInstance()); michael@0: mIsConsumed = false; michael@0: } michael@0: michael@0: void michael@0: CameraPreviewMediaStream::AddAudioOutput(void* aKey) michael@0: { michael@0: } michael@0: michael@0: void michael@0: CameraPreviewMediaStream::SetAudioOutputVolume(void* aKey, float aVolume) michael@0: { michael@0: } michael@0: michael@0: void michael@0: CameraPreviewMediaStream::RemoveAudioOutput(void* aKey) michael@0: { michael@0: } michael@0: michael@0: void michael@0: CameraPreviewMediaStream::AddVideoOutput(VideoFrameContainer* aContainer) michael@0: { michael@0: MutexAutoLock lock(mMutex); michael@0: nsRefPtr container = aContainer; michael@0: AddVideoOutputImpl(container.forget()); michael@0: michael@0: if (mVideoOutputs.Length() > 1) { michael@0: return; michael@0: } michael@0: MediaStreamGraph* gm = MediaStreamGraph::GetInstance(); michael@0: mIsConsumed = true; michael@0: for (uint32_t j = 0; j < mListeners.Length(); ++j) { michael@0: MediaStreamListener* l = mListeners[j]; michael@0: l->NotifyConsumptionChanged(gm, MediaStreamListener::CONSUMED); michael@0: } michael@0: } michael@0: michael@0: void michael@0: CameraPreviewMediaStream::RemoveVideoOutput(VideoFrameContainer* aContainer) michael@0: { michael@0: MutexAutoLock lock(mMutex); michael@0: RemoveVideoOutputImpl(aContainer); michael@0: michael@0: if (!mVideoOutputs.IsEmpty()) { michael@0: return; michael@0: } michael@0: MediaStreamGraph* gm = MediaStreamGraph::GetInstance(); michael@0: mIsConsumed = false; michael@0: for (uint32_t j = 0; j < mListeners.Length(); ++j) { michael@0: MediaStreamListener* l = mListeners[j]; michael@0: l->NotifyConsumptionChanged(gm, MediaStreamListener::NOT_CONSUMED); michael@0: } michael@0: } michael@0: michael@0: void michael@0: CameraPreviewMediaStream::ChangeExplicitBlockerCount(int32_t aDelta) michael@0: { michael@0: } michael@0: michael@0: void michael@0: CameraPreviewMediaStream::AddListener(MediaStreamListener* aListener) michael@0: { michael@0: MutexAutoLock lock(mMutex); michael@0: michael@0: MediaStreamGraph* gm = MediaStreamGraph::GetInstance(); michael@0: MediaStreamListener* listener = *mListeners.AppendElement() = aListener; michael@0: listener->NotifyBlockingChanged(gm, MediaStreamListener::UNBLOCKED); michael@0: } michael@0: michael@0: void michael@0: CameraPreviewMediaStream::RemoveListener(MediaStreamListener* aListener) michael@0: { michael@0: MutexAutoLock lock(mMutex); michael@0: michael@0: MediaStreamGraph* gm = MediaStreamGraph::GetInstance(); michael@0: nsRefPtr listener(aListener); michael@0: mListeners.RemoveElement(aListener); michael@0: listener->NotifyRemoved(gm); michael@0: } michael@0: michael@0: void michael@0: CameraPreviewMediaStream::Destroy() michael@0: { michael@0: MutexAutoLock lock(mMutex); michael@0: DestroyImpl(); michael@0: } michael@0: michael@0: void michael@0: CameraPreviewMediaStream::SetCurrentFrame(const gfxIntSize& aIntrinsicSize, Image* aImage) michael@0: { michael@0: MutexAutoLock lock(mMutex); michael@0: michael@0: TimeStamp now = TimeStamp::Now(); michael@0: for (uint32_t i = 0; i < mVideoOutputs.Length(); ++i) { michael@0: VideoFrameContainer* output = mVideoOutputs[i]; michael@0: output->SetCurrentFrame(aIntrinsicSize, aImage, now); michael@0: nsCOMPtr event = michael@0: NS_NewRunnableMethod(output, &VideoFrameContainer::Invalidate); michael@0: NS_DispatchToMainThread(event, NS_DISPATCH_NORMAL); michael@0: } michael@0: michael@0: if (mFrameCallback) { michael@0: mFrameCallback->OnNewFrame(aIntrinsicSize, aImage); michael@0: } michael@0: } michael@0: michael@0: void michael@0: CameraPreviewMediaStream::ClearCurrentFrame() michael@0: { michael@0: MutexAutoLock lock(mMutex); michael@0: michael@0: for (uint32_t i = 0; i < mVideoOutputs.Length(); ++i) { michael@0: VideoFrameContainer* output = mVideoOutputs[i]; michael@0: output->ClearCurrentFrame(); michael@0: nsCOMPtr event = michael@0: NS_NewRunnableMethod(output, &VideoFrameContainer::Invalidate); michael@0: NS_DispatchToMainThread(event, NS_DISPATCH_NORMAL); michael@0: } michael@0: } michael@0: michael@0: }