зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1208371 - Un-nest MediaEngineSource::PhotoCallback. r=roc
So it may be forward declared. MozReview-Commit-ID: JLEsMt1fqKz --HG-- extra : rebase_source : 6bf12bd61d1bd479a340b10cafca049ef3fd0fac
This commit is contained in:
Родитель
4f3a6bae57
Коммит
2a7a664d3b
|
@ -77,7 +77,7 @@ ImageCapture::TakePhotoByMediaEngine()
|
|||
{
|
||||
// Callback for TakPhoto(), it also monitor the principal. If principal
|
||||
// changes, it returns PHOTO_ERROR with security error.
|
||||
class TakePhotoCallback : public MediaEngineSource::PhotoCallback,
|
||||
class TakePhotoCallback : public MediaEnginePhotoCallback,
|
||||
public DOMMediaStream::PrincipalChangeObserver
|
||||
{
|
||||
public:
|
||||
|
@ -127,7 +127,7 @@ ImageCapture::TakePhotoByMediaEngine()
|
|||
if (domLocalStream) {
|
||||
RefPtr<MediaEngineSource> mediaEngine =
|
||||
domLocalStream->GetMediaEngine(mVideoStreamTrack->GetTrackID());
|
||||
RefPtr<MediaEngineSource::PhotoCallback> callback =
|
||||
RefPtr<MediaEnginePhotoCallback> callback =
|
||||
new TakePhotoCallback(domStream, this);
|
||||
return mediaEngine->TakePhoto(callback);
|
||||
}
|
||||
|
|
|
@ -75,6 +75,25 @@ protected:
|
|||
virtual ~MediaEngine() {}
|
||||
};
|
||||
|
||||
/**
|
||||
* Callback interface for TakePhoto(). Either PhotoComplete() or PhotoError()
|
||||
* should be called.
|
||||
*/
|
||||
class MediaEnginePhotoCallback {
|
||||
public:
|
||||
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(MediaEnginePhotoCallback)
|
||||
|
||||
// aBlob is the image captured by MediaEngineSource. It is
|
||||
// called on main thread.
|
||||
virtual nsresult PhotoComplete(already_AddRefed<dom::Blob> aBlob) = 0;
|
||||
|
||||
// It is called on main thread. aRv is the error code.
|
||||
virtual nsresult PhotoError(nsresult aRv) = 0;
|
||||
|
||||
protected:
|
||||
virtual ~MediaEnginePhotoCallback() {}
|
||||
};
|
||||
|
||||
/**
|
||||
* Common abstract base class for audio and video sources.
|
||||
*/
|
||||
|
@ -129,28 +148,11 @@ public:
|
|||
/* Returns the type of media source (camera, microphone, screen, window, etc) */
|
||||
virtual dom::MediaSourceEnum GetMediaSource() const = 0;
|
||||
|
||||
// Callback interface for TakePhoto(). Either PhotoComplete() or PhotoError()
|
||||
// should be called.
|
||||
class PhotoCallback {
|
||||
public:
|
||||
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(PhotoCallback)
|
||||
|
||||
// aBlob is the image captured by MediaEngineSource. It is
|
||||
// called on main thread.
|
||||
virtual nsresult PhotoComplete(already_AddRefed<dom::Blob> aBlob) = 0;
|
||||
|
||||
// It is called on main thread. aRv is the error code.
|
||||
virtual nsresult PhotoError(nsresult aRv) = 0;
|
||||
|
||||
protected:
|
||||
virtual ~PhotoCallback() {}
|
||||
};
|
||||
|
||||
/* If implementation of MediaEngineSource supports TakePhoto(), the picture
|
||||
* should be return via aCallback object. Otherwise, it returns NS_ERROR_NOT_IMPLEMENTED.
|
||||
* Currently, only Gonk MediaEngineSource implementation supports it.
|
||||
*/
|
||||
virtual nsresult TakePhoto(PhotoCallback* aCallback) = 0;
|
||||
virtual nsresult TakePhoto(MediaEnginePhotoCallback* aCallback) = 0;
|
||||
|
||||
/* Return false if device is currently allocated or started */
|
||||
bool IsAvailable() {
|
||||
|
|
|
@ -43,7 +43,7 @@ public:
|
|||
return false;
|
||||
}
|
||||
|
||||
nsresult TakePhoto(PhotoCallback* aCallback) override
|
||||
nsresult TakePhoto(MediaEnginePhotoCallback* aCallback) override
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
|
|
@ -70,7 +70,7 @@ public:
|
|||
return dom::MediaSourceEnum::Camera;
|
||||
}
|
||||
|
||||
nsresult TakePhoto(PhotoCallback* aCallback) override
|
||||
nsresult TakePhoto(MediaEnginePhotoCallback* aCallback) override
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
@ -154,7 +154,7 @@ public:
|
|||
return dom::MediaSourceEnum::Microphone;
|
||||
}
|
||||
|
||||
nsresult TakePhoto(PhotoCallback* aCallback) override
|
||||
nsresult TakePhoto(MediaEnginePhotoCallback* aCallback) override
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
|
|
@ -560,10 +560,11 @@ MediaEngineGonkVideoSource::OnUserError(UserContext aContext, nsresult aError)
|
|||
mCallbackMonitor.Notify();
|
||||
}
|
||||
|
||||
// A main thread runnable to send error code to all queued PhotoCallbacks.
|
||||
// A main thread runnable to send error code to all queued
|
||||
// MediaEnginePhotoCallbacks.
|
||||
class TakePhotoError : public nsRunnable {
|
||||
public:
|
||||
TakePhotoError(nsTArray<RefPtr<PhotoCallback>>& aCallbacks,
|
||||
TakePhotoError(nsTArray<RefPtr<MediaEnginePhotoCallback>>& aCallbacks,
|
||||
nsresult aRv)
|
||||
: mRv(aRv)
|
||||
{
|
||||
|
@ -576,13 +577,13 @@ MediaEngineGonkVideoSource::OnUserError(UserContext aContext, nsresult aError)
|
|||
for (uint8_t i = 0; i < callbackNumbers; i++) {
|
||||
mCallbacks[i]->PhotoError(mRv);
|
||||
}
|
||||
// PhotoCallback needs to dereference on main thread.
|
||||
// MediaEnginePhotoCallback needs to dereference on main thread.
|
||||
mCallbacks.Clear();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
protected:
|
||||
nsTArray<RefPtr<PhotoCallback>> mCallbacks;
|
||||
nsTArray<RefPtr<MediaEnginePhotoCallback>> mCallbacks;
|
||||
nsresult mRv;
|
||||
};
|
||||
|
||||
|
@ -602,10 +603,10 @@ MediaEngineGonkVideoSource::OnTakePictureComplete(const uint8_t* aData, uint32_t
|
|||
mCameraControl->StartPreview();
|
||||
|
||||
// Create a main thread runnable to generate a blob and call all current queued
|
||||
// PhotoCallbacks.
|
||||
// MediaEnginePhotoCallbacks.
|
||||
class GenerateBlobRunnable : public nsRunnable {
|
||||
public:
|
||||
GenerateBlobRunnable(nsTArray<RefPtr<PhotoCallback>>& aCallbacks,
|
||||
GenerateBlobRunnable(nsTArray<RefPtr<MediaEnginePhotoCallback>>& aCallbacks,
|
||||
const uint8_t* aData,
|
||||
uint32_t aLength,
|
||||
const nsAString& aMimeType)
|
||||
|
@ -626,12 +627,12 @@ MediaEngineGonkVideoSource::OnTakePictureComplete(const uint8_t* aData, uint32_t
|
|||
RefPtr<dom::Blob> tempBlob = blob;
|
||||
mCallbacks[i]->PhotoComplete(tempBlob.forget());
|
||||
}
|
||||
// PhotoCallback needs to dereference on main thread.
|
||||
// MediaEnginePhotoCallback needs to dereference on main thread.
|
||||
mCallbacks.Clear();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsTArray<RefPtr<PhotoCallback>> mCallbacks;
|
||||
nsTArray<RefPtr<MediaEnginePhotoCallback>> mCallbacks;
|
||||
uint8_t* mPhotoData;
|
||||
nsString mMimeType;
|
||||
uint32_t mPhotoDataLength;
|
||||
|
@ -639,7 +640,7 @@ MediaEngineGonkVideoSource::OnTakePictureComplete(const uint8_t* aData, uint32_t
|
|||
|
||||
// All elements in mPhotoCallbacks will be swapped in GenerateBlobRunnable
|
||||
// constructor. This captured image will be sent to all the queued
|
||||
// PhotoCallbacks in this runnable.
|
||||
// MediaEnginePhotoCallbacks in this runnable.
|
||||
MonitorAutoLock lock(mMonitor);
|
||||
if (mPhotoCallbacks.Length()) {
|
||||
NS_DispatchToMainThread(
|
||||
|
@ -648,7 +649,7 @@ MediaEngineGonkVideoSource::OnTakePictureComplete(const uint8_t* aData, uint32_t
|
|||
}
|
||||
|
||||
nsresult
|
||||
MediaEngineGonkVideoSource::TakePhoto(PhotoCallback* aCallback)
|
||||
MediaEngineGonkVideoSource::TakePhoto(MediaEnginePhotoCallback* aCallback)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
|
|
|
@ -92,7 +92,7 @@ public:
|
|||
void RotateImage(layers::Image* aImage, uint32_t aWidth, uint32_t aHeight);
|
||||
void Notify(const mozilla::hal::ScreenConfiguration& aConfiguration);
|
||||
|
||||
nsresult TakePhoto(PhotoCallback* aCallback) override;
|
||||
nsresult TakePhoto(MediaEnginePhotoCallback* aCallback) override;
|
||||
|
||||
// It sets the correct photo orientation via camera parameter according to
|
||||
// current screen orientation.
|
||||
|
@ -125,7 +125,7 @@ protected:
|
|||
android::sp<android::GonkCameraSource> mCameraSource;
|
||||
|
||||
// These are protected by mMonitor in parent class
|
||||
nsTArray<RefPtr<PhotoCallback>> mPhotoCallbacks;
|
||||
nsTArray<RefPtr<MediaEnginePhotoCallback>> mPhotoCallbacks;
|
||||
int mRotation;
|
||||
int mCameraAngle; // See dom/base/ScreenOrientation.h
|
||||
bool mBackCamera;
|
||||
|
|
|
@ -45,7 +45,7 @@ class MediaEngineTabVideoSource : public MediaEngineVideoSource, nsIDOMEventList
|
|||
return 0;
|
||||
}
|
||||
|
||||
nsresult TakePhoto(PhotoCallback* aCallback) override
|
||||
nsresult TakePhoto(MediaEnginePhotoCallback* aCallback) override
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
|
|
@ -115,7 +115,7 @@ public:
|
|||
{
|
||||
return false;
|
||||
}
|
||||
nsresult TakePhoto(PhotoCallback* aCallback) override
|
||||
nsresult TakePhoto(MediaEnginePhotoCallback* aCallback) override
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
@ -463,7 +463,7 @@ public:
|
|||
return dom::MediaSourceEnum::Microphone;
|
||||
}
|
||||
|
||||
nsresult TakePhoto(PhotoCallback* aCallback) override
|
||||
nsresult TakePhoto(MediaEnginePhotoCallback* aCallback) override
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче