Bug 1208371 - Un-nest MediaEngineSource::PhotoCallback. r?roc draft
authorAndreas Pehrson <pehrsons@gmail.com>
Thu, 05 Nov 2015 15:42:21 +0800
changeset 306638 ad9e68e3740e035d4fb780113b144b44edb0e49b
parent 306637 c782bc0983c3d7dac6c416a488c6171931900da1
child 306639 60f2271c50f757e045383fac0ac0d2af6f1fbd51
child 316616 802af14fc3ecd0ebe6bbf6bd2b8e14e547dcbd4e
push id7183
push userpehrsons@gmail.com
push dateThu, 05 Nov 2015 07:42:40 +0000
reviewersroc
bugs1208371
milestone45.0a1
Bug 1208371 - Un-nest MediaEngineSource::PhotoCallback. r?roc So it may be forward declared.
dom/media/imagecapture/ImageCapture.cpp
dom/media/webrtc/MediaEngine.h
dom/media/webrtc/MediaEngineCameraVideoSource.h
dom/media/webrtc/MediaEngineDefault.h
dom/media/webrtc/MediaEngineGonkVideoSource.cpp
dom/media/webrtc/MediaEngineGonkVideoSource.h
dom/media/webrtc/MediaEngineTabVideoSource.h
dom/media/webrtc/MediaEngineWebRTC.h
--- a/dom/media/imagecapture/ImageCapture.cpp
+++ b/dom/media/imagecapture/ImageCapture.cpp
@@ -75,17 +75,17 @@ ImageCapture::GetVideoStreamTrack() cons
   return mVideoStreamTrack;
 }
 
 nsresult
 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:
     TakePhotoCallback(DOMMediaStream* aStream, ImageCapture* aImageCapture)
       : mStream(aStream)
       , mImageCapture(aImageCapture)
       , mPrincipalChanged(false)
     {
@@ -125,17 +125,17 @@ ImageCapture::TakePhotoByMediaEngine()
     bool mPrincipalChanged;
   };
 
   RefPtr<DOMMediaStream> domStream = mVideoStreamTrack->GetStream();
   DOMLocalMediaStream* domLocalStream = domStream->AsDOMLocalMediaStream();
   if (domLocalStream) {
     RefPtr<MediaEngineSource> mediaEngine =
       domLocalStream->GetMediaEngine(mVideoStreamTrack->GetTrackID());
-    RefPtr<MediaEngineSource::PhotoCallback> callback =
+    RefPtr<MediaEnginePhotoCallback> callback =
       new TakePhotoCallback(domStream, this);
     return mediaEngine->TakePhoto(callback);
   }
 
   return NS_ERROR_NOT_IMPLEMENTED;
 }
 
 void
--- a/dom/media/webrtc/MediaEngine.h
+++ b/dom/media/webrtc/MediaEngine.h
@@ -72,16 +72,35 @@ public:
 
   virtual void Shutdown() = 0;
 
 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.
  */
 class MediaEngineSource : public nsISupports
 {
 public:
   // code inside webrtc.org assumes these sizes; don't use anything smaller
   // without verifying it's ok
   static const unsigned int kMaxDeviceNameLength = 128;
@@ -131,38 +150,21 @@ public:
   /* Returns true if a source represents a fake capture device and
    * false otherwise
    */
   virtual bool IsFake() = 0;
 
   /* Returns the type of media source (camera, microphone, screen, window, etc) */
   virtual const dom::MediaSourceEnum GetMediaSource() = 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() {
     if (mState == kAllocated || mState == kStarted) {
       return false;
     } else {
       return true;
     }
--- a/dom/media/webrtc/MediaEngineCameraVideoSource.h
+++ b/dom/media/webrtc/MediaEngineCameraVideoSource.h
@@ -45,17 +45,17 @@ public:
     return NS_OK;
   };
 
   virtual bool IsFake() override
   {
     return false;
   }
 
-  virtual nsresult TakePhoto(PhotoCallback* aCallback) override
+  virtual nsresult TakePhoto(MediaEnginePhotoCallback* aCallback) override
   {
     return NS_ERROR_NOT_IMPLEMENTED;
   }
 
   uint32_t GetBestFitnessDistance(
       const nsTArray<const dom::MediaTrackConstraintSet*>& aConstraintSets,
       const nsString& aDeviceId) override;
 
--- a/dom/media/webrtc/MediaEngineDefault.h
+++ b/dom/media/webrtc/MediaEngineDefault.h
@@ -68,17 +68,17 @@ public:
   virtual bool IsFake() override {
     return true;
   }
 
   virtual const dom::MediaSourceEnum GetMediaSource() override {
     return dom::MediaSourceEnum::Camera;
   }
 
-  virtual nsresult TakePhoto(PhotoCallback* aCallback) override
+  virtual nsresult TakePhoto(MediaEnginePhotoCallback* aCallback) override
   {
     return NS_ERROR_NOT_IMPLEMENTED;
   }
 
   NS_DECL_THREADSAFE_ISUPPORTS
   NS_DECL_NSITIMERCALLBACK
 
 protected:
@@ -138,17 +138,17 @@ public:
   virtual bool IsFake() override {
     return true;
   }
 
   virtual const dom::MediaSourceEnum GetMediaSource() override {
     return dom::MediaSourceEnum::Microphone;
   }
 
-  virtual nsresult TakePhoto(PhotoCallback* aCallback) override
+  virtual nsresult TakePhoto(MediaEnginePhotoCallback* aCallback) override
   {
     return NS_ERROR_NOT_IMPLEMENTED;
   }
 
   virtual uint32_t GetBestFitnessDistance(
       const nsTArray<const dom::MediaTrackConstraintSet*>& aConstraintSets,
       const nsString& aDeviceId) override;
 
--- a/dom/media/webrtc/MediaEngineGonkVideoSource.cpp
+++ b/dom/media/webrtc/MediaEngineGonkVideoSource.cpp
@@ -554,39 +554,40 @@ MediaEngineGonkVideoSource::OnUserError(
 {
   {
     // Scope the monitor, since there is another monitor below and we don't want
     // unexpected deadlock.
     ReentrantMonitorAutoEnter sync(mCallbackMonitor);
     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)
     {
       mCallbacks.SwapElements(aCallbacks);
     }
 
     NS_IMETHOD Run()
     {
       uint32_t callbackNumbers = mCallbacks.Length();
       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;
   };
 
   if (aContext == UserContext::kInTakePicture) {
     MonitorAutoLock lock(mMonitor);
     if (mPhotoCallbacks.Length()) {
       NS_DispatchToMainThread(new TakePhotoError(mPhotoCallbacks, aError));
     }
@@ -596,17 +597,17 @@ MediaEngineGonkVideoSource::OnUserError(
 void
 MediaEngineGonkVideoSource::OnTakePictureComplete(const uint8_t* aData, uint32_t aLength, const nsAString& aMimeType)
 {
   // It needs to start preview because Gonk camera will stop preview while
   // taking picture.
   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,
                          const uint8_t* aData,
                          uint32_t aLength,
                          const nsAString& aMimeType)
       : mPhotoDataLength(aLength)
     {
--- a/dom/media/webrtc/MediaEngineGonkVideoSource.h
+++ b/dom/media/webrtc/MediaEngineGonkVideoSource.h
@@ -86,17 +86,17 @@ public:
   void AllocImpl();
   void DeallocImpl();
   void StartImpl(webrtc::CaptureCapability aCapability);
   void StopImpl();
   uint32_t ConvertPixelFormatToFOURCC(int aFormat);
   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.
   nsresult UpdatePhotoOrientation();
 
   // It adds aBuffer to current preview image and sends this image to MediaStreamDirectListener
   // via AppendToTrack(). Due to MediaBuffer is limited resource, it will clear
   // image's MediaBuffer by calling GonkCameraImage::ClearMediaBuffer() before leaving
@@ -119,17 +119,17 @@ protected:
   mozilla::ReentrantMonitor mCallbackMonitor; // Monitor for camera callback handling
   // This is only modified on MainThread (AllocImpl and DeallocImpl)
   RefPtr<ICameraControl> mCameraControl;
   RefPtr<dom::File> mLastCapture;
 
   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;
   bool mOrientationChanged; // True when screen rotates.
 
   RefPtr<layers::TextureClientRecycleAllocator> mTextureClientAllocator;
 };
 
--- a/dom/media/webrtc/MediaEngineTabVideoSource.h
+++ b/dom/media/webrtc/MediaEngineTabVideoSource.h
@@ -39,17 +39,17 @@ class MediaEngineTabVideoSource : public
     }
     virtual uint32_t GetBestFitnessDistance(
       const nsTArray<const dom::MediaTrackConstraintSet*>& aConstraintSets,
       const nsString& aDeviceId) override
     {
       return 0;
     }
 
-    virtual nsresult TakePhoto(PhotoCallback* aCallback) override
+    virtual nsresult TakePhoto(MediaEnginePhotoCallback* aCallback) override
     {
       return NS_ERROR_NOT_IMPLEMENTED;
     }
 
     void Draw();
 
     class StartRunnable : public nsRunnable {
     public:
--- a/dom/media/webrtc/MediaEngineWebRTC.h
+++ b/dom/media/webrtc/MediaEngineWebRTC.h
@@ -101,17 +101,17 @@ public:
   const dom::MediaSourceEnum GetMediaSource() override
   {
     return dom::MediaSourceEnum::AudioCapture;
   }
   bool IsFake() override
   {
     return false;
   }
-  nsresult TakePhoto(PhotoCallback* aCallback) override
+  nsresult TakePhoto(MediaEnginePhotoCallback* aCallback) override
   {
     return NS_ERROR_NOT_IMPLEMENTED;
   }
   uint32_t GetBestFitnessDistance(
     const nsTArray<const dom::MediaTrackConstraintSet*>& aConstraintSets,
     const nsString& aDeviceId) override;
 
 protected:
@@ -177,17 +177,17 @@ public:
   virtual bool IsFake() override {
     return false;
   }
 
   virtual const dom::MediaSourceEnum GetMediaSource() override {
     return dom::MediaSourceEnum::Microphone;
   }
 
-  virtual nsresult TakePhoto(PhotoCallback* aCallback) override
+  virtual nsresult TakePhoto(MediaEnginePhotoCallback* aCallback) override
   {
     return NS_ERROR_NOT_IMPLEMENTED;
   }
 
   virtual uint32_t GetBestFitnessDistance(
       const nsTArray<const dom::MediaTrackConstraintSet*>& aConstraintSets,
       const nsString& aDeviceId) override;