Bug 879717: Part 3: Fix camera preview stream and wake locks from lock screen. r=roc

This commit is contained in:
Andrew Osmond 2014-10-13 00:01:25 -04:00
parent a84b987246
commit c9016c13c8
5 changed files with 39 additions and 8 deletions

View File

@ -17,6 +17,8 @@
using namespace mozilla::layers;
using namespace mozilla::dom;
static const TrackID TRACK_VIDEO = 2;
namespace mozilla {
void
@ -32,6 +34,7 @@ CameraPreviewMediaStream::CameraPreviewMediaStream(DOMMediaStream* aWrapper)
, mInvalidatePending(0)
, mDiscardedFrames(0)
, mRateLimit(false)
, mTrackCreated(false)
{
SetGraphImpl(MediaStreamGraph::GetInstance());
mFakeMediaStreamGraph = new FakeMediaStreamGraph();
@ -111,6 +114,22 @@ CameraPreviewMediaStream::RemoveListener(MediaStreamListener* aListener)
listener->NotifyEvent(mFakeMediaStreamGraph, MediaStreamListener::EVENT_REMOVED);
}
void
CameraPreviewMediaStream::OnPreviewStateChange(bool aActive)
{
MutexAutoLock lock(mMutex);
if (!mTrackCreated && aActive) {
mTrackCreated = true;
VideoSegment tmpSegment;
uint32_t trackEvent = aActive ? MediaStreamListener::TRACK_EVENT_CREATED
: MediaStreamListener::TRACK_EVENT_ENDED;
for (uint32_t j = 0; j < mListeners.Length(); ++j) {
MediaStreamListener* l = mListeners[j];
l->NotifyQueuedTrackChanges(mFakeMediaStreamGraph, TRACK_VIDEO, 0, 0, trackEvent, tmpSegment);
}
}
}
void
CameraPreviewMediaStream::Destroy()
{

View File

@ -51,6 +51,7 @@ public:
virtual void AddListener(MediaStreamListener* aListener) MOZ_OVERRIDE;
virtual void RemoveListener(MediaStreamListener* aListener) MOZ_OVERRIDE;
virtual void Destroy();
void OnPreviewStateChange(bool aActive);
void Invalidate();
@ -67,6 +68,7 @@ protected:
int32_t mInvalidatePending;
uint32_t mDiscardedFrames;
bool mRateLimit;
bool mTrackCreated;
nsRefPtr<FakeMediaStreamGraph> mFakeMediaStreamGraph;
};

View File

@ -218,7 +218,8 @@ nsDOMCameraControl::nsDOMCameraControl(uint32_t aCameraId,
mCurrentConfiguration = initialConfig.forget();
// Attach our DOM-facing media stream to our viewfinder stream.
mStream = mInput;
SetHintContents(HINT_CONTENTS_VIDEO);
InitStreamCommon(mInput);
MOZ_ASSERT(mWindow, "Shouldn't be created with a null window!");
if (mWindow->GetExtantDoc()) {
CombineWithPrincipal(mWindow->GetExtantDoc()->NodePrincipal());

View File

@ -137,6 +137,7 @@ DOMCameraControlListener::OnPreviewStateChange(PreviewState aState)
MOZ_ASSERT_UNREACHABLE("Invalid preview state");
return;
}
mStream->OnPreviewStateChange(aState == kPreviewStarted);
NS_DispatchToMainThread(new Callback(mDOMCameraControl, aState));
}

View File

@ -109,18 +109,26 @@ var Camera = {
var blob = e.data;
var img = new Image();
var test = this._currentTest;
var onPreviewStateChange = function(e) {
if (e.newState === 'started') {
ok(true, "viewfinder is ready and playing after resume");
Camera.cameraObj.removeEventListener('previewstatechange', onPreviewStateChange);
Camera._testsCompleted++;
if(Camera._testsCompleted == Camera._tests.length) {
ok(true, "test finishing");
SimpleTest.finish();
} else {
Camera.runTests();
}
}
}
Camera.cameraObj.addEventListener('previewstatechange', onPreviewStateChange);
img.onload = function Imgsize() {
ok(this.width == test.pictureSize.width, "The image taken has the width " +
this.width + " pictureSize width = " + test.pictureSize.width);
ok(this.height == test.pictureSize.height, "The image taken has the height " +
this.height + " picturesize height = " + test.pictureSize.height);
Camera._testsCompleted++;
if(Camera._testsCompleted == Camera._tests.length) {
ok(true, "test finishing");
SimpleTest.finish();
} else {
Camera.runTests();
}
Camera.cameraObj.resumePreview();
}
ok(blob.size > 100 , "Blob Size Gathered = " + blob.size);
ok("image/" + test.fileFormat == blob.type, "Blob Type = " + blob.type);