Bug 1058452 - Use FakeMediaStreamGraph r=mikeh

This commit is contained in:
Sotaro Ikeda 2014-09-09 06:27:24 -07:00
parent 4f9b3c595c
commit bb9e6a0bc7
3 changed files with 32 additions and 9 deletions

View File

@ -1188,7 +1188,7 @@ public:
* Should only be called during MediaStreamListener callbacks or during * Should only be called during MediaStreamListener callbacks or during
* ProcessedMediaStream::ProcessInput(). * ProcessedMediaStream::ProcessInput().
*/ */
void DispatchToMainThreadAfterStreamStateUpdate(already_AddRefed<nsIRunnable> aRunnable) virtual void DispatchToMainThreadAfterStreamStateUpdate(already_AddRefed<nsIRunnable> aRunnable)
{ {
*mPendingUpdateRunnables.AppendElement() = aRunnable; *mPendingUpdateRunnables.AppendElement() = aRunnable;
} }

View File

@ -19,6 +19,13 @@ using namespace mozilla::dom;
namespace mozilla { namespace mozilla {
void
FakeMediaStreamGraph::DispatchToMainThreadAfterStreamStateUpdate(already_AddRefed<nsIRunnable> aRunnable)
{
nsRefPtr<nsIRunnable> task = aRunnable;
NS_DispatchToMainThread(task);
}
CameraPreviewMediaStream::CameraPreviewMediaStream(DOMMediaStream* aWrapper) CameraPreviewMediaStream::CameraPreviewMediaStream(DOMMediaStream* aWrapper)
: MediaStream(aWrapper) : MediaStream(aWrapper)
, mMutex("mozilla::camera::CameraPreviewMediaStream") , mMutex("mozilla::camera::CameraPreviewMediaStream")
@ -27,6 +34,7 @@ CameraPreviewMediaStream::CameraPreviewMediaStream(DOMMediaStream* aWrapper)
, mRateLimit(false) , mRateLimit(false)
{ {
SetGraphImpl(MediaStreamGraph::GetInstance()); SetGraphImpl(MediaStreamGraph::GetInstance());
mFakeMediaStreamGraph = new FakeMediaStreamGraph();
mIsConsumed = false; mIsConsumed = false;
} }
@ -55,11 +63,10 @@ CameraPreviewMediaStream::AddVideoOutput(VideoFrameContainer* aContainer)
if (mVideoOutputs.Length() > 1) { if (mVideoOutputs.Length() > 1) {
return; return;
} }
MediaStreamGraph* gm = MediaStreamGraph::GetInstance();
mIsConsumed = true; mIsConsumed = true;
for (uint32_t j = 0; j < mListeners.Length(); ++j) { for (uint32_t j = 0; j < mListeners.Length(); ++j) {
MediaStreamListener* l = mListeners[j]; MediaStreamListener* l = mListeners[j];
l->NotifyConsumptionChanged(gm, MediaStreamListener::CONSUMED); l->NotifyConsumptionChanged(mFakeMediaStreamGraph, MediaStreamListener::CONSUMED);
} }
} }
@ -72,11 +79,10 @@ CameraPreviewMediaStream::RemoveVideoOutput(VideoFrameContainer* aContainer)
if (!mVideoOutputs.IsEmpty()) { if (!mVideoOutputs.IsEmpty()) {
return; return;
} }
MediaStreamGraph* gm = MediaStreamGraph::GetInstance();
mIsConsumed = false; mIsConsumed = false;
for (uint32_t j = 0; j < mListeners.Length(); ++j) { for (uint32_t j = 0; j < mListeners.Length(); ++j) {
MediaStreamListener* l = mListeners[j]; MediaStreamListener* l = mListeners[j];
l->NotifyConsumptionChanged(gm, MediaStreamListener::NOT_CONSUMED); l->NotifyConsumptionChanged(mFakeMediaStreamGraph, MediaStreamListener::NOT_CONSUMED);
} }
} }
@ -90,9 +96,9 @@ CameraPreviewMediaStream::AddListener(MediaStreamListener* aListener)
{ {
MutexAutoLock lock(mMutex); MutexAutoLock lock(mMutex);
MediaStreamGraph* gm = MediaStreamGraph::GetInstance();
MediaStreamListener* listener = *mListeners.AppendElement() = aListener; MediaStreamListener* listener = *mListeners.AppendElement() = aListener;
listener->NotifyBlockingChanged(gm, MediaStreamListener::UNBLOCKED); listener->NotifyBlockingChanged(mFakeMediaStreamGraph, MediaStreamListener::UNBLOCKED);
listener->NotifyHasCurrentData(mFakeMediaStreamGraph);
} }
void void
@ -100,10 +106,9 @@ CameraPreviewMediaStream::RemoveListener(MediaStreamListener* aListener)
{ {
MutexAutoLock lock(mMutex); MutexAutoLock lock(mMutex);
MediaStreamGraph* gm = MediaStreamGraph::GetInstance();
nsRefPtr<MediaStreamListener> listener(aListener); nsRefPtr<MediaStreamListener> listener(aListener);
mListeners.RemoveElement(aListener); mListeners.RemoveElement(aListener);
listener->NotifyEvent(gm, MediaStreamListener::EVENT_REMOVED); listener->NotifyEvent(mFakeMediaStreamGraph, MediaStreamListener::EVENT_REMOVED);
} }
void void

View File

@ -11,6 +11,23 @@
namespace mozilla { namespace mozilla {
class FakeMediaStreamGraph : public MediaStreamGraph
{
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(FakeMediaStreamGraph)
public:
FakeMediaStreamGraph()
: MediaStreamGraph()
{
}
virtual void
DispatchToMainThreadAfterStreamStateUpdate(already_AddRefed<nsIRunnable> aRunnable) MOZ_OVERRIDE;
protected:
~FakeMediaStreamGraph()
{}
};
/** /**
* This is a stream for camera preview. * This is a stream for camera preview.
* *
@ -50,6 +67,7 @@ protected:
int32_t mInvalidatePending; int32_t mInvalidatePending;
uint32_t mDiscardedFrames; uint32_t mDiscardedFrames;
bool mRateLimit; bool mRateLimit;
nsRefPtr<FakeMediaStreamGraph> mFakeMediaStreamGraph;
}; };
} }