Bug 1171374 - Permit software video codecs with the emulated camera. r=sotaro
authorAndrew Osmond <aosmond@mozilla.com>
Thu, 18 Jun 2015 17:12:06 -0400
changeset 269178 dfcbd19717efcba56e9e9d69ff5ba6f4ce095e92
parent 269177 96fcd278ca611923b5f683a41d17b4b741786fc9
child 269179 88458747047560c4b0ead1329fb34bfb6c02ff05
push id8157
push userjlund@mozilla.com
push dateMon, 29 Jun 2015 20:36:23 +0000
treeherdermozilla-aurora@d480e05bd276 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssotaro
bugs1171374
milestone41.0a1
Bug 1171374 - Permit software video codecs with the emulated camera. r=sotaro
dom/camera/GonkCameraHwMgr.cpp
dom/camera/GonkCameraHwMgr.h
dom/camera/GonkRecorder.cpp
--- a/dom/camera/GonkCameraHwMgr.cpp
+++ b/dom/camera/GonkCameraHwMgr.cpp
@@ -48,16 +48,17 @@ GonkCameraHardware::GonkCameraHardware(m
   , mClosing(false)
   , mNumFrames(0)
 #ifdef MOZ_WIDGET_GONK
   , mCamera(aCamera)
 #endif
   , mTarget(aTarget)
   , mRawSensorOrientation(0)
   , mSensorOrientation(0)
+  , mEmulated(false)
 {
   DOM_CAMERA_LOGT("%s:%d : this=%p (aTarget=%p)\n", __func__, __LINE__, (void*)this, (void*)aTarget);
 }
 
 void
 GonkCameraHardware::OnRateLimitPreview(bool aLimit)
 {
   ::OnRateLimitPreview(mTarget, aLimit);
@@ -189,16 +190,21 @@ GonkCameraHardware::Init()
   snprintf(propname, sizeof(propname), "ro.moz.cam.%d.sensor_offset", mCameraId);
   if (__system_property_get(propname, prop) > 0) {
     offset = clamped(atoi(prop), 0, 270);
     mSensorOrientation += offset;
     mSensorOrientation %= 360;
   }
   DOM_CAMERA_LOGI("Sensor orientation: base=%d, offset=%d, final=%d\n", info.orientation, offset, mSensorOrientation);
 
+  if (__system_property_get("ro.kernel.qemu", prop) > 0 && atoi(prop)) {
+    DOM_CAMERA_LOGI("Using emulated camera\n");
+    mEmulated = true;
+  }
+
   // Disable shutter sound in android CameraService because gaia camera app will play it
   mCamera->sendCommand(CAMERA_CMD_ENABLE_SHUTTER_SOUND, 0, 0);
 
 #if ANDROID_VERSION >= 21
   sp<IGraphicBufferProducer> producer;
   sp<IGonkGraphicBufferConsumer> consumer;
   GonkBufferQueue::createBufferQueue(&producer, &consumer);
   static_cast<GonkBufferQueueProducer*>(producer.get())->setSynchronousMode(false);
@@ -317,16 +323,22 @@ GonkCameraHardware::GetSensorOrientation
       return mRawSensorOrientation;
 
     default:
       DOM_CAMERA_LOGE("%s:%d : unknown aType=%d\n", __func__, __LINE__, aType);
       return 0;
   }
 }
 
+bool
+GonkCameraHardware::IsEmulated()
+{
+  return mEmulated;
+}
+
 int
 GonkCameraHardware::AutoFocus()
 {
   DOM_CAMERA_LOGI("%s\n", __func__);
   if (NS_WARN_IF(mClosing)) {
     return DEAD_OBJECT;
   }
   return mCamera->autoFocus();
--- a/dom/camera/GonkCameraHwMgr.h
+++ b/dom/camera/GonkCameraHwMgr.h
@@ -94,16 +94,18 @@ public:
    * orientation.
    */
   enum {
     RAW_SENSOR_ORIENTATION,
     OFFSET_SENSOR_ORIENTATION
   };
   virtual int      GetSensorOrientation(uint32_t aType = RAW_SENSOR_ORIENTATION);
 
+  virtual bool     IsEmulated();
+
   /**
    * MIN_UNDEQUEUED_BUFFERS has increased to 4 since Android JB. For FFOS, more
    * than 3 gralloc buffers are necessary between ImageHost and GonkBufferQueue
    * for consuming preview stream. To keep the stability for older platform, we
    * set MIN_UNDEQUEUED_BUFFERS to 4 only in Android KK base.
    * See also bug 988704.
    */
   enum { MIN_UNDEQUEUED_BUFFERS = 4};
@@ -135,16 +137,17 @@ protected:
   sp<Camera>                    mCamera;
   mozilla::nsGonkCameraControl* mTarget;
 #ifdef MOZ_WIDGET_GONK
   sp<GonkNativeWindow>          mNativeWindow;
   sp<GonkCameraListener>        mListener;
 #endif
   int                           mRawSensorOrientation;
   int                           mSensorOrientation;
+  bool                          mEmulated;
 
 private:
   GonkCameraHardware(const GonkCameraHardware&) = delete;
   GonkCameraHardware& operator=(const GonkCameraHardware&) = delete;
 };
 
 } // namespace android
 
--- a/dom/camera/GonkRecorder.cpp
+++ b/dom/camera/GonkRecorder.cpp
@@ -1267,17 +1267,19 @@ status_t GonkRecorder::setupVideoEncoder
     }
 
     // OMXClient::connect() always returns OK and abort's fatally if
     // it can't connect.
     OMXClient client;
     // CHECK_EQ causes an abort if the given condition fails.
     CHECK_EQ(client.connect(), (status_t)OK);
 
-    uint32_t encoder_flags = OMXCodec::kHardwareCodecsOnly;
+    uint32_t encoder_flags = mCameraHw->IsEmulated()
+                             ? 0
+                             : OMXCodec::kHardwareCodecsOnly;
     if (mIsMetaDataStoredInVideoBuffers) {
 #if defined(MOZ_WIDGET_GONK) && ANDROID_VERSION >= 17
         encoder_flags |= OMXCodec::kStoreMetaDataInVideoBuffers;
 #else
         encoder_flags |= OMXCodec::kStoreMetaDataInVideoBuffers;
         encoder_flags |= OMXCodec::kOnlySubmitOneInputBufferAtOneTime;
 #endif
     }