Bug 774581: Send event when starting/stopping audio or video recording; r=anant,mhabicher

This commit is contained in:
Paul Adenot 2012-08-17 09:10:08 -07:00
parent 30e8676a5a
commit 627efd03dc
2 changed files with 65 additions and 1 deletions

View File

@ -10,6 +10,8 @@
#include "CameraControl.h"
#include "CameraCapabilities.h"
#include "CameraControl.h"
#include "mozilla/Services.h"
#include "nsIObserverService.h"
#define DOM_CAMERA_LOG_LEVEL 3
#include "CameraCommon.h"
@ -374,6 +376,16 @@ nsCameraControl::StartRecording(const JS::Value& aOptions, nsICameraStartRecordi
nsCOMPtr<nsIRunnable> startRecordingTask = new StartRecordingTask(this, size, onSuccess, onError);
mCameraThread->Dispatch(startRecordingTask, NS_DISPATCH_NORMAL);
nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
if (!obs) {
NS_WARNING("Could not get the Observer service for CameraControl::StartRecording.");
return NS_ERROR_FAILURE;
}
obs->NotifyObservers(nullptr,
"recording-device-events",
NS_LITERAL_STRING("starting").get());
return NS_OK;
}
@ -384,6 +396,16 @@ nsCameraControl::StopRecording()
nsCOMPtr<nsIRunnable> stopRecordingTask = new StopRecordingTask(this);
mCameraThread->Dispatch(stopRecordingTask, NS_DISPATCH_NORMAL);
nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
if (!obs) {
NS_WARNING("Could not get the Observer service for CameraControl::StopRecording.");
return NS_ERROR_FAILURE;
}
obs->NotifyObservers(nullptr,
"recording-device-events",
NS_LITERAL_STRING("shutdown").get());
return NS_OK;
}

View File

@ -16,6 +16,40 @@
namespace mozilla {
class GetUserMediaNotificationEvent: public nsRunnable
{
public:
enum GetUserMediaStatus {
STARTING,
STOPPING
};
GetUserMediaNotificationEvent(GetUserMediaStatus aStatus)
: mStatus(aStatus) {}
NS_IMETHOD
Run()
{
nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
if (!obs) {
NS_WARNING("Could not get the Observer service for GetUserMedia recording notification.");
return NS_ERROR_FAILURE;
}
if (mStatus) {
obs->NotifyObservers(nullptr,
"recording-device-events",
NS_LITERAL_STRING("starting").get());
} else {
obs->NotifyObservers(nullptr,
"recording-device-events",
NS_LITERAL_STRING("shutdown").get());
}
return NS_OK;
}
protected:
GetUserMediaStatus mStatus;
};
/**
* This class is an implementation of MediaStreamListener. This is used
* to Start() and Stop() the underlying MediaEngineSource when MediaStreams
@ -41,6 +75,11 @@ public:
mValid = false;
mSource->Stop();
mSource->Deallocate();
nsCOMPtr<GetUserMediaNotificationEvent> event =
new GetUserMediaNotificationEvent(GetUserMediaNotificationEvent::STOPPING);
NS_DispatchToMainThread(event, NS_DISPATCH_NORMAL);
}
void
@ -49,6 +88,10 @@ public:
if (aConsuming == CONSUMED) {
SourceMediaStream* stream = mStream->GetStream()->AsSourceStream();
mSource->Start(stream, mID);
nsCOMPtr<GetUserMediaNotificationEvent> event =
new GetUserMediaNotificationEvent(GetUserMediaNotificationEvent::STARTING);
NS_DispatchToMainThread(event, NS_DISPATCH_NORMAL);
return;
}
@ -112,7 +155,6 @@ private:
MediaEngine* mBackend;
nsCOMPtr<nsIThread> mMediaThread;
WindowTable mActiveWindows;
static nsRefPtr<MediaManager> sSingleton;