Bug 783682 - Camera - always assume the camera gives us yuv420sp [r=gal]
authorMike Habicher <mhabicher@mozilla.com>
Mon, 20 Aug 2012 09:11:20 -0700
changeset 102811 49123250304ff3a9f495b7f9424ebe7ef6ef1192
parent 102810 b00ca24001f639f2c082d45f1e8b459ea490b2b9
child 102812 1baaa5534998e97c4bc423c8d94d4de59574f6a6
push id23312
push useremorley@mozilla.com
push dateTue, 21 Aug 2012 13:23:13 +0000
treeherdermozilla-central@f9a8fdb08193 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgal
bugs783682
milestone17.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 783682 - Camera - always assume the camera gives us yuv420sp [r=gal]
dom/camera/GonkCameraHwMgr.cpp
--- a/dom/camera/GonkCameraHwMgr.cpp
+++ b/dom/camera/GonkCameraHwMgr.cpp
@@ -21,16 +21,26 @@
 
 #define DOM_CAMERA_LOG_LEVEL        3
 #include "CameraCommon.h"
 
 using namespace mozilla;
 using namespace mozilla::layers;
 using namespace android;
 
+/**
+ * See bug 783682.  Most camera implementations, despite claiming they
+ * support 'yuv420p' as a preview format, actually ignore this setting
+ * and return 'yuv420sp' data anyway.  We have come across a new implementation
+ * that, while reporting that 'yuv420p' is supported *and* has been accepted,
+ * still returns the frame data in 'yuv420sp' anyway.  So for now, since
+ * everyone seems to return this format, we just force it.
+ */
+#define FORCE_PREVIEW_FORMAT_YUV420SP   1
+
 #if GIHM_TIMING_RECEIVEFRAME
 #define INCLUDE_TIME_H                  1
 #endif
 #if GIHM_TIMING_OVERALL
 #define INCLUDE_TIME_H                  1
 #endif
 
 #if INCLUDE_TIME_H
@@ -46,24 +56,28 @@ static __inline void timespecSubtract(st
   a->tv_nsec = b->tv_nsec - a->tv_nsec;
   a->tv_sec = b->tv_sec - a->tv_sec;
 }
 #endif
 
 GonkCameraHardware::GonkCameraHardware(GonkCamera* aTarget, PRUint32 aCamera)
   : mCamera(aCamera)
   , mFps(30)
+#if !FORCE_PREVIEW_FORMAT_YUV420SP
   , mPreviewFormat(PREVIEW_FORMAT_UNKNOWN)
+#else
+  , mPreviewFormat(PREVIEW_FORMAT_YUV420SP)
+#endif
   , mClosing(false)
   , mMonitor("GonkCameraHardware.Monitor")
   , mNumFrames(0)
   , mTarget(aTarget)
   , mInitialized(false)
 {
-  DOM_CAMERA_LOGI( "%s: this = %p (aTarget = %p)\n", __func__, (void* )this, (void* )aTarget );
+  DOM_CAMERA_LOGI( "%s: this = %p (aTarget = %p)\n", __func__, (void*)this, (void*)aTarget );
   init();
 }
 
 void
 GonkCameraHardware::OnNewFrame()
 {
   if (mClosing) {
     return;
@@ -379,16 +393,17 @@ GonkCameraHardware::PullParameters(PRUin
   }
 }
 
 int
 GonkCameraHardware::StartPreview()
 {
   const char* format;
 
+#if !FORCE_PREVIEW_FORMAT_YUV420SP
   DOM_CAMERA_LOGI("Preview formats: %s\n", mParams.get(mParams.KEY_SUPPORTED_PREVIEW_FORMATS));
 
   // try to set preferred image format and frame rate
   const char* const PREVIEW_FORMAT = "yuv420p";
   const char* const BAD_PREVIEW_FORMAT = "yuv420sp";
   mParams.setPreviewFormat(PREVIEW_FORMAT);
   mParams.setPreviewFrameRate(mFps);
   mHardware->setParameters(mParams);
@@ -400,16 +415,21 @@ GonkCameraHardware::StartPreview()
     mPreviewFormat = PREVIEW_FORMAT_YUV420P;  /* \o/ */
   } else if (strcmp(format, BAD_PREVIEW_FORMAT) == 0) {
     mPreviewFormat = PREVIEW_FORMAT_YUV420SP;
     DOM_CAMERA_LOGA("Camera ignored our request for '%s' preview, will have to convert (from %d)\n", PREVIEW_FORMAT, mPreviewFormat);
   } else {
     mPreviewFormat = PREVIEW_FORMAT_UNKNOWN;
     DOM_CAMERA_LOGE("Camera ignored our request for '%s' preview, returned UNSUPPORTED format '%s'\n", PREVIEW_FORMAT, format);
   }
+#else
+  mParams.setPreviewFormat("yuv420sp");
+  mParams.setPreviewFrameRate(mFps);
+  mHardware->setParameters(mParams);
+#endif
 
   // Check the frame rate and log if the camera ignored our setting
   PRUint32 fps = mParams.getPreviewFrameRate();
   if (fps != mFps) {
     DOM_CAMERA_LOGA("We asked for %d fps but camera returned %d fps, using it", mFps, fps);
     mFps = fps;
   }