2012-07-30 14:59:05 -07:00
|
|
|
/*
|
2014-02-14 14:41:07 -08:00
|
|
|
* Copyright (C) 2012-2014 Mozilla Foundation
|
2012-07-30 14:59:05 -07:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
#include "GonkCameraControl.h"
|
2013-01-18 13:06:28 -08:00
|
|
|
#include <time.h>
|
2012-07-30 14:59:05 -07:00
|
|
|
#include <string.h>
|
2012-09-28 22:30:52 -07:00
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <libgen.h>
|
2012-08-17 03:56:55 -07:00
|
|
|
#include "base/basictypes.h"
|
2012-07-30 14:59:05 -07:00
|
|
|
#include "camera/CameraParameters.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsMemory.h"
|
|
|
|
#include "nsThread.h"
|
2012-09-28 22:30:52 -07:00
|
|
|
#include <media/MediaProfiles.h>
|
2012-10-29 16:16:42 -07:00
|
|
|
#include "mozilla/FileUtils.h"
|
2012-12-11 15:15:07 -08:00
|
|
|
#include "mozilla/Services.h"
|
2014-02-14 14:41:07 -08:00
|
|
|
#include "mozilla/unused.h"
|
2014-02-28 12:02:55 -08:00
|
|
|
#include "mozilla/ipc/FileDescriptorUtils.h"
|
2012-11-02 16:53:40 -07:00
|
|
|
#include "nsAlgorithm.h"
|
2012-11-02 13:11:50 -07:00
|
|
|
#include <media/mediaplayer.h>
|
2012-07-30 14:59:05 -07:00
|
|
|
#include "nsPrintfCString.h"
|
2012-12-04 18:00:39 -08:00
|
|
|
#include "nsIObserverService.h"
|
2013-05-11 02:10:18 -07:00
|
|
|
#include "nsIVolume.h"
|
|
|
|
#include "nsIVolumeService.h"
|
2014-02-14 14:41:07 -08:00
|
|
|
#include "AutoRwLock.h"
|
2012-07-30 14:59:05 -07:00
|
|
|
#include "GonkCameraHwMgr.h"
|
2012-10-23 15:30:28 -07:00
|
|
|
#include "GonkRecorderProfiles.h"
|
2012-07-30 14:59:05 -07:00
|
|
|
#include "CameraCommon.h"
|
2014-02-14 14:41:07 -08:00
|
|
|
#include "GonkCameraParameters.h"
|
2014-01-16 17:01:43 -08:00
|
|
|
#include "DeviceStorageFileDescriptor.h"
|
2012-07-30 14:59:05 -07:00
|
|
|
|
|
|
|
using namespace mozilla;
|
2012-11-12 16:06:31 -08:00
|
|
|
using namespace mozilla::layers;
|
2014-02-14 14:41:07 -08:00
|
|
|
using namespace mozilla::gfx;
|
2014-02-28 12:02:55 -08:00
|
|
|
using namespace mozilla::ipc;
|
2012-09-04 18:01:56 -07:00
|
|
|
using namespace android;
|
2012-12-18 15:19:38 -08:00
|
|
|
|
2013-03-14 14:30:38 -07:00
|
|
|
#define RETURN_IF_NO_CAMERA_HW() \
|
|
|
|
do { \
|
|
|
|
if (!mCameraHw.get()) { \
|
2014-04-25 13:28:15 -07:00
|
|
|
NS_WARNING("Camera hardware is not initialized"); \
|
2013-03-14 14:30:38 -07:00
|
|
|
DOM_CAMERA_LOGE("%s:%d : mCameraHw is null\n", __func__, __LINE__); \
|
2014-04-25 13:28:15 -07:00
|
|
|
return NS_ERROR_NOT_INITIALIZED; \
|
2013-03-14 14:30:38 -07:00
|
|
|
} \
|
|
|
|
} while(0)
|
|
|
|
|
2012-09-04 18:01:56 -07:00
|
|
|
// Construct nsGonkCameraControl on the main thread.
|
2014-02-14 14:41:07 -08:00
|
|
|
nsGonkCameraControl::nsGonkCameraControl(uint32_t aCameraId)
|
|
|
|
: CameraControlImpl(aCameraId)
|
|
|
|
, mLastPictureSize({0, 0})
|
|
|
|
, mLastThumbnailSize({0, 0})
|
|
|
|
, mPreviewFps(30)
|
|
|
|
, mResumePreviewAfterTakingPicture(false) // XXXmikeh - see bug 950102
|
2014-04-09 08:53:41 -07:00
|
|
|
, mFlashSupported(false)
|
|
|
|
, mLuminanceSupported(false)
|
|
|
|
, mAutoFlashModeOverridden(false)
|
2014-09-16 12:36:48 -07:00
|
|
|
, mSeparateVideoAndPreviewSizesSupported(false)
|
2014-02-14 14:41:07 -08:00
|
|
|
, mDeferConfigUpdate(0)
|
2012-10-23 15:30:28 -07:00
|
|
|
, mMediaProfiles(nullptr)
|
|
|
|
, mRecorder(nullptr)
|
2014-06-10 06:52:22 -07:00
|
|
|
, mRecorderMonitor("GonkCameraControl::mRecorder.Monitor")
|
2012-10-23 15:30:28 -07:00
|
|
|
, mProfileManager(nullptr)
|
|
|
|
, mRecorderProfile(nullptr)
|
2012-12-04 18:00:39 -08:00
|
|
|
, mVideoFile(nullptr)
|
2014-06-10 06:52:22 -07:00
|
|
|
, mReentrantMonitor("GonkCameraControl::OnTakePicture.Monitor")
|
2012-09-04 18:01:56 -07:00
|
|
|
{
|
|
|
|
// Constructor runs on the main thread...
|
|
|
|
DOM_CAMERA_LOGT("%s:%d : this=%p\n", __func__, __LINE__, this);
|
2014-02-14 14:41:07 -08:00
|
|
|
mImageContainer = LayerManager::CreateImageContainer();
|
2013-02-16 11:05:45 -08:00
|
|
|
}
|
2012-09-04 18:01:56 -07:00
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
nsresult
|
2014-02-19 20:18:52 -08:00
|
|
|
nsGonkCameraControl::StartImpl(const Configuration* aInitialConfig)
|
2013-02-16 11:05:45 -08:00
|
|
|
{
|
2014-02-19 20:18:52 -08:00
|
|
|
/**
|
|
|
|
* For initialization, we try to return the camera control to the upper
|
|
|
|
* upper layer (i.e. the DOM) as quickly as possible. To do this, the
|
|
|
|
* camera is initialized in the following stages:
|
|
|
|
*
|
|
|
|
* 0. Initialize() initializes the hardware;
|
|
|
|
* 1. SetConfigurationInternal() does the minimal configuration
|
|
|
|
* required so that we can start the preview -and- report a valid
|
|
|
|
* configuration to the upper layer;
|
|
|
|
* 2. OnHardwareStateChange() reports that the hardware is ready,
|
|
|
|
* which the upper (e.g. DOM) layer can (and does) use to return
|
|
|
|
* the camera control object;
|
|
|
|
* 3. StartPreviewImpl() starts the flow of preview frames from the
|
|
|
|
* camera hardware.
|
|
|
|
*
|
|
|
|
* The intent of the above flow is to let the Main Thread do as much work
|
|
|
|
* up-front as possible without waiting for blocking Camera Thread calls
|
|
|
|
* to complete.
|
|
|
|
*/
|
|
|
|
MOZ_ASSERT(NS_GetCurrentThread() == mCameraThread);
|
2014-02-14 14:41:07 -08:00
|
|
|
|
2014-02-19 20:18:52 -08:00
|
|
|
nsresult rv = Initialize();
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
2014-04-25 13:28:15 -07:00
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
2014-02-19 20:18:52 -08:00
|
|
|
}
|
2014-02-14 14:41:07 -08:00
|
|
|
|
2014-02-19 20:18:52 -08:00
|
|
|
if (aInitialConfig) {
|
|
|
|
rv = SetConfigurationInternal(*aInitialConfig);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
// The initial configuration failed, close up the hardware
|
|
|
|
StopImpl();
|
|
|
|
return rv;
|
2014-02-14 14:41:07 -08:00
|
|
|
}
|
2014-02-19 20:18:52 -08:00
|
|
|
}
|
2014-02-14 14:41:07 -08:00
|
|
|
|
2014-02-19 20:18:52 -08:00
|
|
|
OnHardwareStateChange(CameraControlListener::kHardwareOpen);
|
2014-08-05 10:20:31 -07:00
|
|
|
if (aInitialConfig) {
|
|
|
|
return StartPreviewImpl();
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
2012-09-04 18:01:56 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2014-02-19 20:18:52 -08:00
|
|
|
nsGonkCameraControl::Initialize()
|
2012-07-30 14:59:05 -07:00
|
|
|
{
|
2014-04-25 13:28:15 -07:00
|
|
|
if (mCameraHw.get()) {
|
|
|
|
DOM_CAMERA_LOGI("Camera %d already connected (this=%p)\n", mCameraId, this);
|
|
|
|
return NS_ERROR_ALREADY_INITIALIZED;
|
|
|
|
}
|
|
|
|
|
2013-03-08 11:43:33 -08:00
|
|
|
mCameraHw = GonkCameraHardware::Connect(this, mCameraId);
|
2013-03-14 14:30:38 -07:00
|
|
|
if (!mCameraHw.get()) {
|
|
|
|
DOM_CAMERA_LOGE("Failed to connect to camera %d (this=%p)\n", mCameraId, this);
|
2014-04-25 13:28:15 -07:00
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
2013-03-14 14:30:38 -07:00
|
|
|
}
|
|
|
|
|
2013-03-08 11:43:33 -08:00
|
|
|
DOM_CAMERA_LOGI("Initializing camera %d (this=%p, mCameraHw=%p)\n", mCameraId, this, mCameraHw.get());
|
2012-07-30 14:59:05 -07:00
|
|
|
|
|
|
|
// Initialize our camera configuration database.
|
2012-09-04 18:01:56 -07:00
|
|
|
PullParametersImpl();
|
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
// Set preferred preview frame format.
|
|
|
|
mParams.Set(CAMERA_PARAM_PREVIEWFORMAT, NS_LITERAL_STRING("yuv420sp"));
|
2014-04-16 18:46:36 -07:00
|
|
|
// Turn off any normal pictures returned by the HDR scene mode
|
|
|
|
mParams.Set(CAMERA_PARAM_SCENEMODE_HDR_RETURNNORMALPICTURE, false);
|
2012-11-02 16:53:40 -07:00
|
|
|
PushParametersImpl();
|
2012-09-04 18:01:56 -07:00
|
|
|
|
|
|
|
// Grab any other settings we'll need later.
|
2014-02-14 14:41:07 -08:00
|
|
|
mParams.Get(CAMERA_PARAM_PICTURE_FILEFORMAT, mFileFormat);
|
|
|
|
mParams.Get(CAMERA_PARAM_THUMBNAILSIZE, mLastThumbnailSize);
|
|
|
|
|
|
|
|
// The emulator's camera returns -1 for these values; bump them up to 0
|
|
|
|
int areas;
|
|
|
|
mParams.Get(CAMERA_PARAM_SUPPORTED_MAXMETERINGAREAS, areas);
|
|
|
|
mCurrentConfiguration.mMaxMeteringAreas = areas != -1 ? areas : 0;
|
|
|
|
mParams.Get(CAMERA_PARAM_SUPPORTED_MAXFOCUSAREAS, areas);
|
|
|
|
mCurrentConfiguration.mMaxFocusAreas = areas != -1 ? areas : 0;
|
|
|
|
|
|
|
|
mParams.Get(CAMERA_PARAM_PICTURE_SIZE, mLastPictureSize);
|
|
|
|
mParams.Get(CAMERA_PARAM_PREVIEWSIZE, mCurrentConfiguration.mPreviewSize);
|
|
|
|
|
2014-04-09 08:53:41 -07:00
|
|
|
nsString luminance; // check for support
|
|
|
|
mParams.Get(CAMERA_PARAM_LUMINANCE, luminance);
|
|
|
|
mLuminanceSupported = !luminance.IsEmpty();
|
|
|
|
|
|
|
|
nsString flashMode;
|
|
|
|
mParams.Get(CAMERA_PARAM_FLASHMODE, flashMode);
|
|
|
|
mFlashSupported = !flashMode.IsEmpty();
|
|
|
|
|
2014-08-25 12:12:49 -07:00
|
|
|
double quality; // informational only
|
|
|
|
mParams.Get(CAMERA_PARAM_PICTURE_QUALITY, quality);
|
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
DOM_CAMERA_LOGI(" - maximum metering areas: %u\n", mCurrentConfiguration.mMaxMeteringAreas);
|
|
|
|
DOM_CAMERA_LOGI(" - maximum focus areas: %u\n", mCurrentConfiguration.mMaxFocusAreas);
|
|
|
|
DOM_CAMERA_LOGI(" - default picture size: %u x %u\n",
|
|
|
|
mLastPictureSize.width, mLastPictureSize.height);
|
2014-08-25 12:12:49 -07:00
|
|
|
DOM_CAMERA_LOGI(" - default picture file format: %s\n",
|
|
|
|
NS_ConvertUTF16toUTF8(mFileFormat).get());
|
|
|
|
DOM_CAMERA_LOGI(" - default picture quality: %f\n", quality);
|
2014-02-14 14:41:07 -08:00
|
|
|
DOM_CAMERA_LOGI(" - default thumbnail size: %u x %u\n",
|
|
|
|
mLastThumbnailSize.width, mLastThumbnailSize.height);
|
|
|
|
DOM_CAMERA_LOGI(" - default preview size: %u x %u\n",
|
|
|
|
mCurrentConfiguration.mPreviewSize.width, mCurrentConfiguration.mPreviewSize.height);
|
2014-04-09 08:53:41 -07:00
|
|
|
DOM_CAMERA_LOGI(" - luminance reporting: %ssupported\n",
|
|
|
|
mLuminanceSupported ? "" : "NOT ");
|
|
|
|
if (mFlashSupported) {
|
|
|
|
DOM_CAMERA_LOGI(" - flash: supported, default mode '%s'\n",
|
|
|
|
NS_ConvertUTF16toUTF8(flashMode).get());
|
|
|
|
} else {
|
|
|
|
DOM_CAMERA_LOGI(" - flash: NOT supported\n");
|
|
|
|
}
|
2012-09-04 18:01:56 -07:00
|
|
|
|
2014-09-16 12:36:48 -07:00
|
|
|
nsAutoTArray<Size, 16> sizes;
|
|
|
|
mParams.Get(CAMERA_PARAM_SUPPORTED_VIDEOSIZES, sizes);
|
|
|
|
if (sizes.Length() > 0) {
|
|
|
|
mSeparateVideoAndPreviewSizesSupported = true;
|
|
|
|
DOM_CAMERA_LOGI(" - support for separate preview and video sizes\n");
|
|
|
|
mParams.Get(CAMERA_PARAM_VIDEOSIZE, mLastRecorderSize);
|
|
|
|
DOM_CAMERA_LOGI(" - default video recorder size: %u x %u\n",
|
|
|
|
mLastRecorderSize.width, mLastRecorderSize.height);
|
|
|
|
} else {
|
|
|
|
mLastRecorderSize = mCurrentConfiguration.mPreviewSize;
|
|
|
|
}
|
|
|
|
|
2013-03-14 14:30:38 -07:00
|
|
|
return NS_OK;
|
2012-07-30 14:59:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsGonkCameraControl::~nsGonkCameraControl()
|
|
|
|
{
|
2013-03-08 11:43:33 -08:00
|
|
|
DOM_CAMERA_LOGT("%s:%d : this=%p, mCameraHw = %p\n", __func__, __LINE__, this, mCameraHw.get());
|
2013-01-07 04:54:24 -08:00
|
|
|
|
2014-02-19 20:18:52 -08:00
|
|
|
StopImpl();
|
2012-09-04 18:01:56 -07:00
|
|
|
DOM_CAMERA_LOGT("%s:%d\n", __func__, __LINE__);
|
2012-07-30 14:59:05 -07:00
|
|
|
}
|
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
nsresult
|
|
|
|
nsGonkCameraControl::SetConfigurationInternal(const Configuration& aConfig)
|
2014-02-14 05:27:44 -08:00
|
|
|
{
|
2014-02-14 14:41:07 -08:00
|
|
|
DOM_CAMERA_LOGT("%s:%d\n", __func__, __LINE__);
|
2014-02-14 05:27:44 -08:00
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
nsresult rv;
|
2014-02-14 05:27:44 -08:00
|
|
|
|
2014-06-25 14:45:02 -07:00
|
|
|
{
|
|
|
|
ICameraControlParameterSetAutoEnter set(this);
|
2014-02-14 05:27:44 -08:00
|
|
|
|
2014-06-25 14:45:02 -07:00
|
|
|
switch (aConfig.mMode) {
|
|
|
|
case kPictureMode:
|
|
|
|
rv = SetPictureConfiguration(aConfig);
|
|
|
|
break;
|
2012-07-30 14:59:05 -07:00
|
|
|
|
2014-06-25 14:45:02 -07:00
|
|
|
case kVideoMode:
|
|
|
|
rv = SetVideoConfiguration(aConfig);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
MOZ_ASSERT_UNREACHABLE("Unanticipated camera mode in SetConfigurationInternal()");
|
|
|
|
rv = NS_ERROR_FAILURE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-07-02 15:49:54 -07:00
|
|
|
DOM_CAMERA_LOGT("%s:%d\n", __func__, __LINE__);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = Set(CAMERA_PARAM_RECORDINGHINT, aConfig.mMode == kVideoMode);
|
2014-06-25 14:45:02 -07:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
DOM_CAMERA_LOGE("Failed to set recording hint (0x%x)\n", rv);
|
|
|
|
}
|
2012-07-30 14:59:05 -07:00
|
|
|
}
|
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
mCurrentConfiguration.mMode = aConfig.mMode;
|
|
|
|
mCurrentConfiguration.mRecorderProfile = aConfig.mRecorderProfile;
|
2013-12-06 06:47:29 -08:00
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
OnConfigurationChange();
|
|
|
|
return NS_OK;
|
2013-12-06 06:47:29 -08:00
|
|
|
}
|
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
nsresult
|
|
|
|
nsGonkCameraControl::SetConfigurationImpl(const Configuration& aConfig)
|
2012-07-30 14:59:05 -07:00
|
|
|
{
|
2014-02-14 14:41:07 -08:00
|
|
|
DOM_CAMERA_LOGT("%s:%d\n", __func__, __LINE__);
|
|
|
|
MOZ_ASSERT(NS_GetCurrentThread() == mCameraThread);
|
2014-02-14 05:27:44 -08:00
|
|
|
|
2014-08-05 10:20:31 -07:00
|
|
|
if (aConfig.mMode == kUnspecifiedMode) {
|
|
|
|
DOM_CAMERA_LOGW("Can't set camera mode to 'unspecified', ignoring\n");
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
// Stop any currently running preview
|
2014-02-19 20:18:55 -08:00
|
|
|
nsresult rv = PausePreview();
|
|
|
|
if (NS_FAILED(rv)) {
|
2014-06-25 14:45:02 -07:00
|
|
|
DOM_CAMERA_LOGW("PausePreview() in SetConfigurationImpl() failed (0x%x)\n", rv);
|
|
|
|
if (rv == NS_ERROR_NOT_INITIALIZED) {
|
|
|
|
// If there no hardware available, nothing else we try will work,
|
|
|
|
// so bail out here.
|
|
|
|
return rv;
|
|
|
|
}
|
2014-02-19 20:18:55 -08:00
|
|
|
}
|
2014-02-14 05:27:44 -08:00
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
DOM_CAMERA_LOGT("%s:%d\n", __func__, __LINE__);
|
2014-02-19 20:18:55 -08:00
|
|
|
rv = SetConfigurationInternal(aConfig);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
StopPreviewImpl();
|
|
|
|
return rv;
|
|
|
|
}
|
2014-02-14 05:27:44 -08:00
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
// Restart the preview
|
|
|
|
DOM_CAMERA_LOGT("%s:%d\n", __func__, __LINE__);
|
|
|
|
return StartPreviewImpl();
|
2012-11-02 16:53:40 -07:00
|
|
|
}
|
2012-07-30 14:59:05 -07:00
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
nsresult
|
|
|
|
nsGonkCameraControl::SetPictureConfiguration(const Configuration& aConfig)
|
2012-11-02 16:53:40 -07:00
|
|
|
{
|
2014-02-14 14:41:07 -08:00
|
|
|
DOM_CAMERA_LOGT("%s:%d\n", __func__, __LINE__);
|
2012-11-02 16:53:40 -07:00
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
// remove any existing recorder profile
|
|
|
|
mRecorderProfile = nullptr;
|
2012-11-02 16:53:40 -07:00
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
nsresult rv = SetPreviewSize(aConfig.mPreviewSize);
|
2014-04-07 15:21:00 -07:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
mParams.Get(CAMERA_PARAM_PREVIEWFRAMERATE, mPreviewFps);
|
2012-11-02 16:53:40 -07:00
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
DOM_CAMERA_LOGI("picture mode preview: wanted %ux%u, got %ux%u (%u fps)\n",
|
|
|
|
aConfig.mPreviewSize.width, aConfig.mPreviewSize.height,
|
|
|
|
mCurrentConfiguration.mPreviewSize.width, mCurrentConfiguration.mPreviewSize.height,
|
|
|
|
mPreviewFps);
|
2012-11-02 16:53:40 -07:00
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
return NS_OK;
|
2012-07-30 14:59:05 -07:00
|
|
|
}
|
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
// Parameter management.
|
2012-09-04 18:01:56 -07:00
|
|
|
nsresult
|
2012-07-30 14:59:05 -07:00
|
|
|
nsGonkCameraControl::PushParameters()
|
|
|
|
{
|
2014-02-14 14:41:07 -08:00
|
|
|
uint32_t dcu = mDeferConfigUpdate;
|
|
|
|
if (dcu > 0) {
|
|
|
|
DOM_CAMERA_LOGI("Defering config update (nest level %u)\n", dcu);
|
2012-09-04 18:01:56 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* If we're already on the camera thread, call PushParametersImpl()
|
|
|
|
* directly, so that it executes synchronously. Some callers
|
|
|
|
* require this so that changes take effect immediately before
|
|
|
|
* we can proceed.
|
|
|
|
*/
|
2014-02-14 14:41:07 -08:00
|
|
|
if (NS_GetCurrentThread() != mCameraThread) {
|
|
|
|
DOM_CAMERA_LOGT("%s:%d - dispatching to Camera Thread\n", __func__, __LINE__);
|
|
|
|
nsCOMPtr<nsIRunnable> pushParametersTask =
|
|
|
|
NS_NewRunnableMethod(this, &nsGonkCameraControl::PushParametersImpl);
|
2012-09-04 18:01:56 -07:00
|
|
|
return mCameraThread->Dispatch(pushParametersTask, NS_DISPATCH_NORMAL);
|
2012-07-30 14:59:05 -07:00
|
|
|
}
|
2012-09-04 18:01:56 -07:00
|
|
|
|
|
|
|
DOM_CAMERA_LOGT("%s:%d\n", __func__, __LINE__);
|
|
|
|
return PushParametersImpl();
|
2012-07-30 14:59:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-02-14 14:41:07 -08:00
|
|
|
nsGonkCameraControl::BeginBatchParameterSet()
|
2012-07-30 14:59:05 -07:00
|
|
|
{
|
2014-02-14 14:41:07 -08:00
|
|
|
uint32_t dcu = ++mDeferConfigUpdate;
|
|
|
|
if (dcu == 0) {
|
|
|
|
NS_WARNING("Overflow weirdness incrementing mDeferConfigUpdate!");
|
|
|
|
MOZ_CRASH();
|
2012-07-30 14:59:05 -07:00
|
|
|
}
|
2014-02-14 14:41:07 -08:00
|
|
|
DOM_CAMERA_LOGI("Begin deferring camera configuration updates (nest level %u)\n", dcu);
|
2012-07-30 14:59:05 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-02-14 14:41:07 -08:00
|
|
|
nsGonkCameraControl::EndBatchParameterSet()
|
2012-07-30 14:59:05 -07:00
|
|
|
{
|
2014-02-14 14:41:07 -08:00
|
|
|
uint32_t dcu = mDeferConfigUpdate--;
|
|
|
|
if (dcu == 0) {
|
|
|
|
NS_WARNING("Underflow badness decrementing mDeferConfigUpdate!");
|
|
|
|
MOZ_CRASH();
|
2012-07-30 14:59:05 -07:00
|
|
|
}
|
2014-02-14 14:41:07 -08:00
|
|
|
DOM_CAMERA_LOGI("End deferring camera configuration updates (nest level %u)\n", dcu);
|
2012-07-30 14:59:05 -07:00
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
if (dcu == 1) {
|
|
|
|
PushParameters();
|
2012-07-30 14:59:05 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
template<class T> nsresult
|
|
|
|
nsGonkCameraControl::SetAndPush(uint32_t aKey, const T& aValue)
|
2012-07-30 14:59:05 -07:00
|
|
|
{
|
2014-02-14 14:41:07 -08:00
|
|
|
nsresult rv = mParams.Set(aKey, aValue);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
DOM_CAMERA_LOGE("Camera parameter aKey=%d failed to set (0x%x)\n", aKey, rv);
|
|
|
|
return rv;
|
2012-07-30 14:59:05 -07:00
|
|
|
}
|
2014-02-14 14:41:07 -08:00
|
|
|
return PushParameters();
|
|
|
|
}
|
2012-07-30 14:59:05 -07:00
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
// Array-of-Size parameter accessor.
|
|
|
|
nsresult
|
|
|
|
nsGonkCameraControl::Get(uint32_t aKey, nsTArray<Size>& aSizes)
|
|
|
|
{
|
2014-09-16 12:36:48 -07:00
|
|
|
if (aKey == CAMERA_PARAM_SUPPORTED_VIDEOSIZES &&
|
|
|
|
!mSeparateVideoAndPreviewSizesSupported) {
|
2014-02-14 14:41:07 -08:00
|
|
|
aKey = CAMERA_PARAM_SUPPORTED_PREVIEWSIZES;
|
2012-07-30 14:59:05 -07:00
|
|
|
}
|
2014-02-14 14:41:07 -08:00
|
|
|
|
|
|
|
return mParams.Get(aKey, aSizes);
|
2012-07-30 14:59:05 -07:00
|
|
|
}
|
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
// Array-of-doubles parameter accessor.
|
|
|
|
nsresult
|
|
|
|
nsGonkCameraControl::Get(uint32_t aKey, nsTArray<double>& aValues)
|
2014-02-13 21:28:57 -08:00
|
|
|
{
|
2014-02-14 14:41:07 -08:00
|
|
|
return mParams.Get(aKey, aValues);
|
|
|
|
}
|
2012-11-02 16:53:40 -07:00
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
// Array-of-nsString parameter accessor.
|
|
|
|
nsresult
|
|
|
|
nsGonkCameraControl::Get(uint32_t aKey, nsTArray<nsString>& aValues)
|
|
|
|
{
|
|
|
|
return mParams.Get(aKey, aValues);
|
|
|
|
}
|
2014-02-10 14:53:19 -08:00
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
// nsString-valued parameter accessors
|
|
|
|
nsresult
|
|
|
|
nsGonkCameraControl::Set(uint32_t aKey, const nsAString& aValue)
|
|
|
|
{
|
|
|
|
nsresult rv = mParams.Set(aKey, aValue);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
2014-02-14 05:27:44 -08:00
|
|
|
}
|
2014-02-10 14:53:19 -08:00
|
|
|
|
2014-04-09 08:53:41 -07:00
|
|
|
switch (aKey) {
|
|
|
|
case CAMERA_PARAM_PICTURE_FILEFORMAT:
|
|
|
|
// Picture format -- need to keep it for the TakePicture() callback.
|
|
|
|
mFileFormat = aValue;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CAMERA_PARAM_FLASHMODE:
|
|
|
|
// Explicit flash mode changes always win and stick.
|
|
|
|
mAutoFlashModeOverridden = false;
|
|
|
|
break;
|
2014-05-20 09:24:00 -07:00
|
|
|
|
|
|
|
case CAMERA_PARAM_SCENEMODE:
|
|
|
|
// Reset disabling normal pictures in HDR mode in conjunction with setting
|
|
|
|
// scene mode because some drivers require they be changed together.
|
|
|
|
mParams.Set(CAMERA_PARAM_SCENEMODE_HDR_RETURNNORMALPICTURE, false);
|
|
|
|
break;
|
2014-02-14 05:27:44 -08:00
|
|
|
}
|
2014-02-10 14:53:19 -08:00
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
return PushParameters();
|
|
|
|
}
|
2014-02-13 21:28:57 -08:00
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
nsresult
|
|
|
|
nsGonkCameraControl::Get(uint32_t aKey, nsAString& aRet)
|
|
|
|
{
|
|
|
|
return mParams.Get(aKey, aRet);
|
|
|
|
}
|
2014-02-13 21:28:57 -08:00
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
// Double-valued parameter accessors
|
|
|
|
nsresult
|
|
|
|
nsGonkCameraControl::Set(uint32_t aKey, double aValue)
|
|
|
|
{
|
|
|
|
return SetAndPush(aKey, aValue);
|
2014-02-13 21:28:57 -08:00
|
|
|
}
|
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
nsresult
|
|
|
|
nsGonkCameraControl::Get(uint32_t aKey, double& aRet)
|
2014-02-13 21:28:57 -08:00
|
|
|
{
|
2014-02-14 14:41:07 -08:00
|
|
|
return mParams.Get(aKey, aRet);
|
2014-02-13 21:28:57 -08:00
|
|
|
}
|
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
// Signed-64-bit parameter accessors.
|
|
|
|
nsresult
|
|
|
|
nsGonkCameraControl::Set(uint32_t aKey, int64_t aValue)
|
|
|
|
{
|
|
|
|
return SetAndPush(aKey, aValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsGonkCameraControl::Get(uint32_t aKey, int64_t& aRet)
|
|
|
|
{
|
|
|
|
return mParams.Get(aKey, aRet);
|
|
|
|
}
|
|
|
|
|
2014-06-30 03:33:00 -07:00
|
|
|
// Boolean parameter accessors.
|
|
|
|
nsresult
|
|
|
|
nsGonkCameraControl::Set(uint32_t aKey, bool aValue)
|
|
|
|
{
|
|
|
|
return SetAndPush(aKey, aValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsGonkCameraControl::Get(uint32_t aKey, bool& aRet)
|
|
|
|
{
|
|
|
|
return mParams.Get(aKey, aRet);
|
|
|
|
}
|
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
// Weighted-region parameter accessors.
|
|
|
|
nsresult
|
|
|
|
nsGonkCameraControl::Set(uint32_t aKey, const nsTArray<Region>& aRegions)
|
|
|
|
{
|
|
|
|
return SetAndPush(aKey, aRegions);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsGonkCameraControl::Get(uint32_t aKey, nsTArray<Region>& aRegions)
|
|
|
|
{
|
|
|
|
return mParams.Get(aKey, aRegions);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Singleton-size parameter accessors.
|
|
|
|
nsresult
|
|
|
|
nsGonkCameraControl::Set(uint32_t aKey, const Size& aSize)
|
2013-10-30 12:41:08 -07:00
|
|
|
{
|
|
|
|
switch (aKey) {
|
2014-04-09 08:53:41 -07:00
|
|
|
case CAMERA_PARAM_PICTURE_SIZE:
|
2013-10-30 12:41:08 -07:00
|
|
|
DOM_CAMERA_LOGI("setting picture size to %ux%u\n", aSize.width, aSize.height);
|
2014-02-14 14:41:07 -08:00
|
|
|
return SetPictureSize(aSize);
|
2013-10-30 12:41:08 -07:00
|
|
|
|
|
|
|
case CAMERA_PARAM_THUMBNAILSIZE:
|
|
|
|
DOM_CAMERA_LOGI("setting thumbnail size to %ux%u\n", aSize.width, aSize.height);
|
2014-02-14 14:41:07 -08:00
|
|
|
return SetThumbnailSize(aSize);
|
2013-10-30 12:41:08 -07:00
|
|
|
|
|
|
|
default:
|
2014-02-14 14:41:07 -08:00
|
|
|
return SetAndPush(aKey, aSize);
|
|
|
|
}
|
|
|
|
}
|
2013-10-30 12:41:08 -07:00
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
nsresult
|
|
|
|
nsGonkCameraControl::Get(uint32_t aKey, Size& aSize)
|
|
|
|
{
|
|
|
|
return mParams.Get(aKey, aSize);
|
|
|
|
}
|
2013-10-30 12:41:08 -07:00
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
// Signed int parameter accessors.
|
|
|
|
nsresult
|
|
|
|
nsGonkCameraControl::Set(uint32_t aKey, int aValue)
|
|
|
|
{
|
|
|
|
if (aKey == CAMERA_PARAM_PICTURE_ROTATION) {
|
2014-02-24 10:01:21 -08:00
|
|
|
RETURN_IF_NO_CAMERA_HW();
|
2014-02-14 14:41:07 -08:00
|
|
|
aValue = RationalizeRotation(aValue + mCameraHw->GetSensorOrientation());
|
2013-10-30 12:41:08 -07:00
|
|
|
}
|
2014-02-14 14:41:07 -08:00
|
|
|
return SetAndPush(aKey, aValue);
|
2013-10-30 12:41:08 -07:00
|
|
|
}
|
|
|
|
|
2012-07-30 14:59:05 -07:00
|
|
|
nsresult
|
2014-02-14 14:41:07 -08:00
|
|
|
nsGonkCameraControl::Get(uint32_t aKey, int& aRet)
|
2012-07-30 14:59:05 -07:00
|
|
|
{
|
2014-02-14 14:41:07 -08:00
|
|
|
if (aKey == CAMERA_PARAM_SENSORANGLE) {
|
2014-02-24 10:01:21 -08:00
|
|
|
RETURN_IF_NO_CAMERA_HW();
|
2014-02-14 14:41:07 -08:00
|
|
|
aRet = mCameraHw->GetSensorOrientation();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2014-02-10 19:09:23 -08:00
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
return mParams.Get(aKey, aRet);
|
|
|
|
}
|
2014-02-14 05:27:44 -08:00
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
// GPS location parameter accessors.
|
|
|
|
nsresult
|
|
|
|
nsGonkCameraControl::SetLocation(const Position& aLocation)
|
|
|
|
{
|
|
|
|
return SetAndPush(CAMERA_PARAM_PICTURE_LOCATION, aLocation);
|
2012-09-04 18:01:56 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2014-02-14 14:41:07 -08:00
|
|
|
nsGonkCameraControl::StartPreviewImpl()
|
2012-09-04 18:01:56 -07:00
|
|
|
{
|
2014-02-14 14:41:07 -08:00
|
|
|
MOZ_ASSERT(NS_GetCurrentThread() == mCameraThread);
|
|
|
|
RETURN_IF_NO_CAMERA_HW();
|
|
|
|
|
|
|
|
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
|
|
|
|
|
|
|
|
if (mPreviewState == CameraControlListener::kPreviewStarted) {
|
|
|
|
DOM_CAMERA_LOGW("Camera preview already started, nothing to do\n");
|
|
|
|
return NS_OK;
|
2012-09-04 18:01:56 -07:00
|
|
|
}
|
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
DOM_CAMERA_LOGI("Starting preview (this=%p)\n", this);
|
2013-03-14 14:30:38 -07:00
|
|
|
|
2013-03-08 11:43:33 -08:00
|
|
|
if (mCameraHw->StartPreview() != OK) {
|
2014-02-14 14:41:07 -08:00
|
|
|
DOM_CAMERA_LOGE("Failed to start camera preview\n");
|
2012-09-04 18:01:56 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
2012-07-30 14:59:05 -07:00
|
|
|
}
|
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
OnPreviewStateChange(CameraControlListener::kPreviewStarted);
|
2012-09-04 18:01:56 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2014-02-14 14:41:07 -08:00
|
|
|
nsGonkCameraControl::StopPreviewImpl()
|
2012-09-04 18:01:56 -07:00
|
|
|
{
|
2014-02-14 14:41:07 -08:00
|
|
|
RETURN_IF_NO_CAMERA_HW();
|
2012-07-30 14:59:05 -07:00
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
DOM_CAMERA_LOGI("Stopping preview (this=%p)\n", this);
|
2012-09-28 22:30:52 -07:00
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
mCameraHw->StopPreview();
|
|
|
|
OnPreviewStateChange(CameraControlListener::kPreviewStopped);
|
|
|
|
return NS_OK;
|
2014-02-14 05:27:44 -08:00
|
|
|
}
|
|
|
|
|
2014-02-19 20:18:55 -08:00
|
|
|
nsresult
|
|
|
|
nsGonkCameraControl::PausePreview()
|
|
|
|
{
|
|
|
|
RETURN_IF_NO_CAMERA_HW();
|
|
|
|
|
|
|
|
DOM_CAMERA_LOGI("Pausing preview (this=%p)\n", this);
|
|
|
|
|
|
|
|
mCameraHw->StopPreview();
|
|
|
|
OnPreviewStateChange(CameraControlListener::kPreviewPaused);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-02-14 05:27:44 -08:00
|
|
|
nsresult
|
2014-04-15 12:46:40 -07:00
|
|
|
nsGonkCameraControl::AutoFocusImpl()
|
2014-02-14 05:27:44 -08:00
|
|
|
{
|
2014-02-14 14:41:07 -08:00
|
|
|
MOZ_ASSERT(NS_GetCurrentThread() == mCameraThread);
|
|
|
|
RETURN_IF_NO_CAMERA_HW();
|
2014-04-15 12:46:40 -07:00
|
|
|
|
|
|
|
DOM_CAMERA_LOGI("Starting auto focus\n");
|
2012-07-30 14:59:05 -07:00
|
|
|
|
2013-03-08 11:43:33 -08:00
|
|
|
if (mCameraHw->AutoFocus() != OK) {
|
2012-07-30 14:59:05 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-04-09 08:52:10 -07:00
|
|
|
nsresult
|
|
|
|
nsGonkCameraControl::StartFaceDetectionImpl()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_GetCurrentThread() == mCameraThread);
|
|
|
|
RETURN_IF_NO_CAMERA_HW();
|
|
|
|
|
|
|
|
DOM_CAMERA_LOGI("Starting face detection\n");
|
|
|
|
|
|
|
|
if (mCameraHw->StartFaceDetection() != OK) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsGonkCameraControl::StopFaceDetectionImpl()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_GetCurrentThread() == mCameraThread);
|
|
|
|
RETURN_IF_NO_CAMERA_HW();
|
|
|
|
|
|
|
|
DOM_CAMERA_LOGI("Stopping face detection\n");
|
|
|
|
|
|
|
|
if (mCameraHw->StopFaceDetection() != OK) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
nsresult
|
|
|
|
nsGonkCameraControl::SetThumbnailSizeImpl(const Size& aSize)
|
2012-11-02 16:53:40 -07:00
|
|
|
{
|
2014-02-14 14:41:07 -08:00
|
|
|
MOZ_ASSERT(NS_GetCurrentThread() == mCameraThread);
|
|
|
|
|
2012-11-02 16:53:40 -07:00
|
|
|
/**
|
2013-10-30 12:41:08 -07:00
|
|
|
* We keep a copy of the specified size so that if the picture size
|
|
|
|
* changes, we can choose a new thumbnail size close to what was asked for
|
|
|
|
* last time.
|
|
|
|
*/
|
2014-02-14 14:41:07 -08:00
|
|
|
mLastThumbnailSize = aSize;
|
2013-10-30 12:41:08 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* If either of width or height is zero, set the other to zero as well.
|
|
|
|
* This should disable inclusion of a thumbnail in the final picture.
|
|
|
|
*/
|
2014-02-14 14:41:07 -08:00
|
|
|
if (!aSize.width || !aSize.height) {
|
|
|
|
DOM_CAMERA_LOGW("Requested thumbnail size %ux%u, disabling thumbnail\n",
|
|
|
|
aSize.width, aSize.height);
|
|
|
|
Size size = { 0, 0 };
|
|
|
|
return SetAndPush(CAMERA_PARAM_THUMBNAILSIZE, size);
|
2013-10-30 12:41:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Choose the supported thumbnail size that is closest to the specified size.
|
|
|
|
* Some drivers will fail to take a picture if the thumbnail does not have
|
|
|
|
* the same aspect ratio as the set picture size, so we need to enforce that
|
|
|
|
* too.
|
2012-11-02 16:53:40 -07:00
|
|
|
*/
|
2013-10-30 12:41:08 -07:00
|
|
|
int smallestDelta = INT_MAX;
|
|
|
|
uint32_t smallestDeltaIndex = UINT32_MAX;
|
2014-02-14 14:41:07 -08:00
|
|
|
int targetArea = aSize.width * aSize.height;
|
2013-10-30 12:41:08 -07:00
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
nsAutoTArray<Size, 8> supportedSizes;
|
|
|
|
Get(CAMERA_PARAM_SUPPORTED_JPEG_THUMBNAIL_SIZES, supportedSizes);
|
2013-10-30 12:41:08 -07:00
|
|
|
|
|
|
|
for (uint32_t i = 0; i < supportedSizes.Length(); ++i) {
|
|
|
|
int area = supportedSizes[i].width * supportedSizes[i].height;
|
|
|
|
int delta = abs(area - targetArea);
|
2012-11-02 16:53:40 -07:00
|
|
|
|
|
|
|
if (area != 0
|
2013-10-30 12:41:08 -07:00
|
|
|
&& delta < smallestDelta
|
2014-02-14 14:41:07 -08:00
|
|
|
&& supportedSizes[i].width * mLastPictureSize.height /
|
|
|
|
supportedSizes[i].height == mLastPictureSize.width
|
2012-11-02 16:53:40 -07:00
|
|
|
) {
|
2013-10-30 12:41:08 -07:00
|
|
|
smallestDelta = delta;
|
|
|
|
smallestDeltaIndex = i;
|
2012-11-02 16:53:40 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-30 12:41:08 -07:00
|
|
|
if (smallestDeltaIndex == UINT32_MAX) {
|
2014-02-24 16:50:26 -08:00
|
|
|
DOM_CAMERA_LOGW("Unable to find a thumbnail size close to %ux%u, disabling thumbnail\n",
|
2014-02-14 14:41:07 -08:00
|
|
|
aSize.width, aSize.height);
|
2014-02-24 16:50:26 -08:00
|
|
|
// If we are unable to find a thumbnail size with a suitable aspect ratio,
|
|
|
|
// just disable the thumbnail altogether.
|
|
|
|
Size size = { 0, 0 };
|
|
|
|
return SetAndPush(CAMERA_PARAM_THUMBNAILSIZE, size);
|
2013-10-30 12:41:08 -07:00
|
|
|
}
|
2012-11-02 16:53:40 -07:00
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
Size size = supportedSizes[smallestDeltaIndex];
|
2014-02-24 10:01:21 -08:00
|
|
|
DOM_CAMERA_LOGI("camera-param set thumbnail-size = %ux%u (requested %ux%u)\n",
|
2014-02-14 14:41:07 -08:00
|
|
|
size.width, size.height, aSize.width, aSize.height);
|
|
|
|
if (size.width > INT32_MAX || size.height > INT32_MAX) {
|
2013-10-30 12:41:08 -07:00
|
|
|
DOM_CAMERA_LOGE("Supported thumbnail size is too big, no change\n");
|
2014-02-14 14:41:07 -08:00
|
|
|
return NS_ERROR_FAILURE;
|
2014-02-13 21:28:57 -08:00
|
|
|
}
|
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
return SetAndPush(CAMERA_PARAM_THUMBNAILSIZE, size);
|
2014-02-13 21:28:57 -08:00
|
|
|
}
|
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
nsresult
|
|
|
|
nsGonkCameraControl::SetThumbnailSize(const Size& aSize)
|
|
|
|
{
|
|
|
|
class SetThumbnailSize : public nsRunnable
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
SetThumbnailSize(nsGonkCameraControl* aCameraControl, const Size& aSize)
|
|
|
|
: mCameraControl(aCameraControl)
|
|
|
|
, mSize(aSize)
|
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(SetThumbnailSize);
|
|
|
|
}
|
|
|
|
~SetThumbnailSize() { MOZ_COUNT_DTOR(SetThumbnailSize); }
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
Run() MOZ_OVERRIDE
|
|
|
|
{
|
|
|
|
nsresult rv = mCameraControl->SetThumbnailSizeImpl(mSize);
|
|
|
|
if (NS_FAILED(rv)) {
|
2014-04-25 13:28:15 -07:00
|
|
|
mCameraControl->OnUserError(CameraControlListener::kInSetThumbnailSize, rv);
|
2014-02-14 14:41:07 -08:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
nsRefPtr<nsGonkCameraControl> mCameraControl;
|
|
|
|
Size mSize;
|
|
|
|
};
|
|
|
|
|
|
|
|
if (NS_GetCurrentThread() == mCameraThread) {
|
|
|
|
return SetThumbnailSizeImpl(aSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
return mCameraThread->Dispatch(new SetThumbnailSize(this, aSize), NS_DISPATCH_NORMAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2013-10-30 12:41:08 -07:00
|
|
|
nsGonkCameraControl::UpdateThumbnailSize()
|
|
|
|
{
|
2014-02-14 14:41:07 -08:00
|
|
|
return SetThumbnailSize(mLastThumbnailSize);
|
2013-10-30 12:41:08 -07:00
|
|
|
}
|
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
nsresult
|
|
|
|
nsGonkCameraControl::SetPictureSizeImpl(const Size& aSize)
|
2013-10-30 12:41:08 -07:00
|
|
|
{
|
2014-02-14 14:41:07 -08:00
|
|
|
MOZ_ASSERT(NS_GetCurrentThread() == mCameraThread);
|
|
|
|
|
2013-10-30 12:41:08 -07:00
|
|
|
/**
|
|
|
|
* Some drivers are less friendly about getting one of these set to zero,
|
|
|
|
* so if either is not specified, ignore both and go with current or
|
|
|
|
* default settings.
|
|
|
|
*/
|
2014-02-14 14:41:07 -08:00
|
|
|
if (!aSize.width || !aSize.height) {
|
|
|
|
DOM_CAMERA_LOGW("Ignoring requested picture size of %ux%u\n", aSize.width, aSize.height);
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
2013-10-30 12:41:08 -07:00
|
|
|
}
|
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
if (aSize.width == mLastPictureSize.width && aSize.height == mLastPictureSize.height) {
|
|
|
|
DOM_CAMERA_LOGI("Requested picture size %ux%u unchanged\n", aSize.width, aSize.height);
|
|
|
|
return NS_OK;
|
2013-10-30 12:41:08 -07:00
|
|
|
}
|
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
nsAutoTArray<Size, 8> supportedSizes;
|
|
|
|
Get(CAMERA_PARAM_SUPPORTED_PICTURESIZES, supportedSizes);
|
2013-10-30 12:41:08 -07:00
|
|
|
|
2014-09-10 08:48:55 -07:00
|
|
|
Size best;
|
|
|
|
nsresult rv = GetSupportedSize(aSize, supportedSizes, best);
|
|
|
|
if (NS_FAILED(rv)) {
|
2014-02-14 14:41:07 -08:00
|
|
|
DOM_CAMERA_LOGW("Unable to find a picture size close to %ux%u\n",
|
|
|
|
aSize.width, aSize.height);
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
2013-10-30 12:41:08 -07:00
|
|
|
}
|
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
DOM_CAMERA_LOGI("camera-param set picture-size = %ux%u (requested %ux%u)\n",
|
2014-09-10 08:48:55 -07:00
|
|
|
best.width, best.height, aSize.width, aSize.height);
|
|
|
|
if (best.width > INT32_MAX || best.height > INT32_MAX) {
|
2013-10-30 12:41:08 -07:00
|
|
|
DOM_CAMERA_LOGE("Supported picture size is too big, no change\n");
|
2014-02-14 14:41:07 -08:00
|
|
|
return NS_ERROR_FAILURE;
|
2013-10-30 12:41:08 -07:00
|
|
|
}
|
|
|
|
|
2014-09-10 08:48:55 -07:00
|
|
|
rv = mParams.Set(CAMERA_PARAM_PICTURE_SIZE, best);
|
2014-02-14 14:41:07 -08:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
2014-02-14 05:27:44 -08:00
|
|
|
}
|
2014-02-13 21:28:57 -08:00
|
|
|
|
2014-09-10 08:48:55 -07:00
|
|
|
mLastPictureSize = best;
|
2014-02-14 14:41:07 -08:00
|
|
|
|
2014-09-10 08:48:55 -07:00
|
|
|
// Finally, update the thumbnail size in case the picture aspect ratio changed.
|
|
|
|
// Some drivers will fail to take a picture if the thumbnail size is not the
|
|
|
|
// same aspect ratio as the picture size.
|
2014-02-14 14:41:07 -08:00
|
|
|
return UpdateThumbnailSize();
|
2012-11-02 16:53:40 -07:00
|
|
|
}
|
|
|
|
|
2014-01-23 16:10:23 -08:00
|
|
|
int32_t
|
|
|
|
nsGonkCameraControl::RationalizeRotation(int32_t aRotation)
|
|
|
|
{
|
|
|
|
int32_t r = aRotation;
|
|
|
|
|
|
|
|
// The result of this operation is an angle from 0..270 degrees,
|
|
|
|
// in steps of 90 degrees. Angles are rounded to the nearest
|
|
|
|
// magnitude, so 45 will be rounded to 90, and -45 will be rounded
|
|
|
|
// to -90 (not 0).
|
|
|
|
if (r >= 0) {
|
|
|
|
r += 45;
|
|
|
|
} else {
|
|
|
|
r -= 45;
|
|
|
|
}
|
|
|
|
r /= 90;
|
|
|
|
r %= 4;
|
|
|
|
r *= 90;
|
|
|
|
if (r < 0) {
|
|
|
|
r += 360;
|
|
|
|
}
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2012-07-30 14:59:05 -07:00
|
|
|
nsresult
|
2014-02-14 14:41:07 -08:00
|
|
|
nsGonkCameraControl::SetPictureSize(const Size& aSize)
|
2012-07-30 14:59:05 -07:00
|
|
|
{
|
2014-02-14 14:41:07 -08:00
|
|
|
class SetPictureSize : public nsRunnable
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
SetPictureSize(nsGonkCameraControl* aCameraControl, const Size& aSize)
|
|
|
|
: mCameraControl(aCameraControl)
|
|
|
|
, mSize(aSize)
|
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(SetPictureSize);
|
2013-03-14 14:30:38 -07:00
|
|
|
}
|
2014-02-14 14:41:07 -08:00
|
|
|
~SetPictureSize() { MOZ_COUNT_DTOR(SetPictureSize); }
|
2014-02-14 05:27:44 -08:00
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
NS_IMETHODIMP
|
|
|
|
Run() MOZ_OVERRIDE
|
|
|
|
{
|
|
|
|
nsresult rv = mCameraControl->SetPictureSizeImpl(mSize);
|
|
|
|
if (NS_FAILED(rv)) {
|
2014-04-25 13:28:15 -07:00
|
|
|
mCameraControl->OnUserError(CameraControlListener::kInSetPictureSize, rv);
|
2014-02-14 14:41:07 -08:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2012-07-30 14:59:05 -07:00
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
protected:
|
|
|
|
nsRefPtr<nsGonkCameraControl> mCameraControl;
|
|
|
|
Size mSize;
|
|
|
|
};
|
2012-07-30 14:59:05 -07:00
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
if (NS_GetCurrentThread() == mCameraThread) {
|
|
|
|
return SetPictureSizeImpl(aSize);
|
2012-07-30 14:59:05 -07:00
|
|
|
}
|
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
return mCameraThread->Dispatch(new SetPictureSize(this, aSize), NS_DISPATCH_NORMAL);
|
|
|
|
}
|
2013-01-18 13:06:28 -08:00
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
nsresult
|
|
|
|
nsGonkCameraControl::TakePictureImpl()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_GetCurrentThread() == mCameraThread);
|
|
|
|
RETURN_IF_NO_CAMERA_HW();
|
2012-07-30 14:59:05 -07:00
|
|
|
|
2013-03-08 11:43:33 -08:00
|
|
|
if (mCameraHw->TakePicture() != OK) {
|
2012-07-30 14:59:05 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2014-02-14 14:41:07 -08:00
|
|
|
|
|
|
|
// In Gonk, taking a picture implicitly stops the preview stream,
|
2013-08-05 13:24:43 -07:00
|
|
|
// so we need to reflect that here.
|
2014-02-14 14:41:07 -08:00
|
|
|
OnPreviewStateChange(CameraControlListener::kPreviewPaused);
|
2012-07-30 14:59:05 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2012-09-04 18:01:56 -07:00
|
|
|
nsGonkCameraControl::PushParametersImpl()
|
2012-07-30 14:59:05 -07:00
|
|
|
{
|
2014-02-14 14:41:07 -08:00
|
|
|
MOZ_ASSERT(NS_GetCurrentThread() == mCameraThread);
|
2012-09-04 18:01:56 -07:00
|
|
|
DOM_CAMERA_LOGI("Pushing camera parameters\n");
|
2013-03-14 14:30:38 -07:00
|
|
|
RETURN_IF_NO_CAMERA_HW();
|
|
|
|
|
2013-03-08 11:43:33 -08:00
|
|
|
if (mCameraHw->PushParameters(mParams) != OK) {
|
2012-07-30 14:59:05 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2012-09-04 18:01:56 -07:00
|
|
|
nsGonkCameraControl::PullParametersImpl()
|
2012-07-30 14:59:05 -07:00
|
|
|
{
|
2014-02-14 14:41:07 -08:00
|
|
|
MOZ_ASSERT(NS_GetCurrentThread() == mCameraThread);
|
2012-09-04 18:01:56 -07:00
|
|
|
DOM_CAMERA_LOGI("Pulling camera parameters\n");
|
2013-03-14 14:30:38 -07:00
|
|
|
RETURN_IF_NO_CAMERA_HW();
|
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
return mCameraHw->PullParameters(mParams);
|
2012-07-30 14:59:05 -07:00
|
|
|
}
|
|
|
|
|
2014-04-09 08:53:41 -07:00
|
|
|
nsresult
|
|
|
|
nsGonkCameraControl::SetupRecordingFlash(bool aAutoEnableLowLightTorch)
|
|
|
|
{
|
|
|
|
mAutoFlashModeOverridden = false;
|
|
|
|
|
|
|
|
if (!aAutoEnableLowLightTorch || !mLuminanceSupported || !mFlashSupported) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
DOM_CAMERA_LOGI("Luminance reporting and flash supported\n");
|
|
|
|
|
|
|
|
nsresult rv = PullParametersImpl();
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsString luminance;
|
|
|
|
rv = mParams.Get(CAMERA_PARAM_LUMINANCE, luminance);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
// If we failed to get the luminance, assume it's "high"
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsString flashMode;
|
|
|
|
rv = mParams.Get(CAMERA_PARAM_FLASHMODE, flashMode);
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
// If we failed to get the current flash mode, swallow the error
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (luminance.EqualsASCII("low") && flashMode.EqualsASCII("auto")) {
|
|
|
|
DOM_CAMERA_LOGI("Low luminance detected, turning on flash\n");
|
|
|
|
rv = SetAndPush(CAMERA_PARAM_FLASHMODE, NS_LITERAL_STRING("torch"));
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
// If we failed to turn on the flash, swallow the error
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
mAutoFlashModeOverridden = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-07-30 14:59:05 -07:00
|
|
|
nsresult
|
2014-02-14 14:41:07 -08:00
|
|
|
nsGonkCameraControl::StartRecordingImpl(DeviceStorageFileDescriptor* aFileDescriptor,
|
|
|
|
const StartRecordingOptions* aOptions)
|
2012-07-30 14:59:05 -07:00
|
|
|
{
|
2014-04-09 08:53:41 -07:00
|
|
|
MOZ_ASSERT(NS_GetCurrentThread() == mCameraThread);
|
|
|
|
|
2014-06-10 06:52:22 -07:00
|
|
|
ReentrantMonitorAutoEnter mon(mRecorderMonitor);
|
|
|
|
|
2012-12-23 07:56:59 -08:00
|
|
|
NS_ENSURE_TRUE(mRecorderProfile, NS_ERROR_NOT_INITIALIZED);
|
|
|
|
NS_ENSURE_FALSE(mRecorder, NS_ERROR_FAILURE);
|
2012-09-28 22:30:52 -07:00
|
|
|
|
|
|
|
/**
|
2012-10-10 03:32:37 -07:00
|
|
|
* Get the base path from device storage and append the app-specified
|
|
|
|
* filename to it. The filename may include a relative subpath
|
|
|
|
* (e.g.) "DCIM/IMG_0001.jpg".
|
|
|
|
*
|
2012-09-30 17:37:47 -07:00
|
|
|
* The camera app needs to provide the file extension '.3gp' for now.
|
2012-09-28 22:30:52 -07:00
|
|
|
* See bug 795202.
|
|
|
|
*/
|
2014-04-25 13:28:15 -07:00
|
|
|
if (NS_WARN_IF(!aFileDescriptor)) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
2014-01-16 17:01:43 -08:00
|
|
|
nsAutoString fullPath;
|
2014-02-14 14:41:07 -08:00
|
|
|
mVideoFile = aFileDescriptor->mDSFile;
|
2014-01-16 17:01:43 -08:00
|
|
|
mVideoFile->GetFullPath(fullPath);
|
|
|
|
DOM_CAMERA_LOGI("Video filename is '%s'\n",
|
|
|
|
NS_LossyConvertUTF16toASCII(fullPath).get());
|
2012-09-30 17:37:47 -07:00
|
|
|
|
2012-12-04 18:00:39 -08:00
|
|
|
if (!mVideoFile->IsSafePath()) {
|
|
|
|
DOM_CAMERA_LOGE("Invalid video file name\n");
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
2014-02-28 12:02:55 -08:00
|
|
|
// SetupRecording creates a dup of the file descriptor, so we need to
|
|
|
|
// close the file descriptor when we leave this function. Also note, that
|
|
|
|
// since we're already off the main thread, we don't need to dispatch this.
|
|
|
|
// We just let the CloseFileRunnable destructor do the work.
|
|
|
|
nsRefPtr<CloseFileRunnable> closer;
|
|
|
|
if (aFileDescriptor->mFileDescriptor.IsValid()) {
|
|
|
|
closer = new CloseFileRunnable(aFileDescriptor->mFileDescriptor);
|
|
|
|
}
|
2014-01-16 17:01:43 -08:00
|
|
|
nsresult rv;
|
2014-02-14 14:41:07 -08:00
|
|
|
int fd = aFileDescriptor->mFileDescriptor.PlatformHandle();
|
|
|
|
if (aOptions) {
|
|
|
|
rv = SetupRecording(fd, aOptions->rotation, aOptions->maxFileSizeBytes,
|
|
|
|
aOptions->maxVideoLengthMs);
|
2014-04-09 08:53:41 -07:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
rv = SetupRecordingFlash(aOptions->autoEnableLowLightTorch);
|
|
|
|
}
|
2014-02-14 14:41:07 -08:00
|
|
|
} else {
|
|
|
|
rv = SetupRecording(fd, 0, 0, 0);
|
|
|
|
}
|
2014-04-09 08:53:41 -07:00
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
2012-10-29 16:16:42 -07:00
|
|
|
|
2012-09-28 22:30:52 -07:00
|
|
|
if (mRecorder->start() != OK) {
|
|
|
|
DOM_CAMERA_LOGE("mRecorder->start() failed\n");
|
2013-01-08 01:11:32 -08:00
|
|
|
// important: we MUST destroy the recorder if start() fails!
|
|
|
|
mRecorder = nullptr;
|
2014-04-09 08:53:41 -07:00
|
|
|
// put the flash back to the 'auto' state
|
|
|
|
if (mAutoFlashModeOverridden) {
|
|
|
|
SetAndPush(CAMERA_PARAM_FLASHMODE, NS_LITERAL_STRING("auto"));
|
|
|
|
}
|
2012-09-28 22:30:52 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2014-02-19 20:18:52 -08:00
|
|
|
OnRecorderStateChange(CameraControlListener::kRecorderStarted);
|
2012-09-28 22:30:52 -07:00
|
|
|
return NS_OK;
|
2012-07-30 14:59:05 -07:00
|
|
|
}
|
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
nsresult
|
|
|
|
nsGonkCameraControl::StopRecordingImpl()
|
2012-12-04 18:00:39 -08:00
|
|
|
{
|
2014-02-14 14:41:07 -08:00
|
|
|
class RecordingComplete : public nsRunnable
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
RecordingComplete(DeviceStorageFile* aFile)
|
|
|
|
: mFile(aFile)
|
|
|
|
{ }
|
2012-12-04 18:00:39 -08:00
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
~RecordingComplete() { }
|
2012-12-04 18:00:39 -08:00
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
NS_IMETHODIMP
|
|
|
|
Run()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2014-02-10 14:53:19 -08:00
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
|
|
|
|
obs->NotifyObservers(mFile, "file-watcher-notify", NS_LITERAL_STRING("modified").get());
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2014-02-13 21:28:57 -08:00
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
private:
|
|
|
|
nsRefPtr<DeviceStorageFile> mFile;
|
|
|
|
};
|
|
|
|
|
2014-06-10 06:52:22 -07:00
|
|
|
ReentrantMonitorAutoEnter mon(mRecorderMonitor);
|
2012-12-04 18:00:39 -08:00
|
|
|
|
2012-12-23 07:56:59 -08:00
|
|
|
// nothing to do if we have no mRecorder
|
|
|
|
NS_ENSURE_TRUE(mRecorder, NS_OK);
|
|
|
|
|
2012-09-28 22:30:52 -07:00
|
|
|
mRecorder->stop();
|
|
|
|
mRecorder = nullptr;
|
2014-02-19 20:18:52 -08:00
|
|
|
OnRecorderStateChange(CameraControlListener::kRecorderStopped);
|
2012-12-04 18:00:39 -08:00
|
|
|
|
2014-05-19 02:10:00 -07:00
|
|
|
{
|
|
|
|
ICameraControlParameterSetAutoEnter set(this);
|
|
|
|
|
|
|
|
if (mAutoFlashModeOverridden) {
|
2014-06-25 14:45:02 -07:00
|
|
|
nsresult rv = Set(CAMERA_PARAM_FLASHMODE, NS_LITERAL_STRING("auto"));
|
2014-05-19 02:10:00 -07:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
DOM_CAMERA_LOGE("Failed to set flash mode (0x%x)\n", rv);
|
|
|
|
}
|
|
|
|
}
|
2014-04-09 08:53:41 -07:00
|
|
|
}
|
|
|
|
|
2012-12-04 18:00:39 -08:00
|
|
|
// notify DeviceStorage that the new video file is closed and ready
|
2014-05-23 12:53:17 -07:00
|
|
|
return NS_DispatchToMainThread(new RecordingComplete(mVideoFile));
|
2012-07-30 14:59:05 -07:00
|
|
|
}
|
|
|
|
|
2014-04-15 12:46:40 -07:00
|
|
|
nsresult
|
|
|
|
nsGonkCameraControl::ResumeContinuousFocusImpl()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_GetCurrentThread() == mCameraThread);
|
|
|
|
RETURN_IF_NO_CAMERA_HW();
|
|
|
|
|
|
|
|
DOM_CAMERA_LOGI("Resuming continuous autofocus\n");
|
|
|
|
|
|
|
|
// see
|
|
|
|
// http://developer.android.com/reference/android/hardware/Camera.Parameters.html#FOCUS_MODE_CONTINUOUS_PICTURE
|
|
|
|
if (NS_WARN_IF(mCameraHw->CancelAutoFocus() != OK)) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-07-30 14:59:05 -07:00
|
|
|
void
|
2014-02-14 14:41:07 -08:00
|
|
|
nsGonkCameraControl::OnAutoFocusComplete(bool aSuccess)
|
2012-09-04 18:01:56 -07:00
|
|
|
{
|
2014-02-14 14:41:07 -08:00
|
|
|
class AutoFocusComplete : public nsRunnable
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
AutoFocusComplete(nsGonkCameraControl* aCameraControl, bool aSuccess)
|
|
|
|
: mCameraControl(aCameraControl)
|
|
|
|
, mSuccess(aSuccess)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
Run() MOZ_OVERRIDE
|
|
|
|
{
|
|
|
|
mCameraControl->OnAutoFocusComplete(mSuccess);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
nsRefPtr<nsGonkCameraControl> mCameraControl;
|
|
|
|
bool mSuccess;
|
|
|
|
};
|
|
|
|
|
|
|
|
if (NS_GetCurrentThread() == mCameraThread) {
|
|
|
|
/**
|
|
|
|
* Auto focusing can change some of the camera's parameters, so
|
|
|
|
* we need to pull a new set before notifying any clients.
|
|
|
|
*/
|
|
|
|
PullParametersImpl();
|
|
|
|
CameraControlImpl::OnAutoFocusComplete(aSuccess);
|
|
|
|
return;
|
|
|
|
}
|
2012-09-04 18:01:56 -07:00
|
|
|
|
|
|
|
/**
|
2014-02-14 14:41:07 -08:00
|
|
|
* Because the callback needs to call PullParametersImpl(),
|
|
|
|
* we need to dispatch this callback through the Camera Thread.
|
2014-02-14 05:27:44 -08:00
|
|
|
*/
|
2014-02-14 14:41:07 -08:00
|
|
|
mCameraThread->Dispatch(new AutoFocusComplete(this, aSuccess), NS_DISPATCH_NORMAL);
|
2012-09-04 18:01:56 -07:00
|
|
|
}
|
|
|
|
|
2014-04-09 08:52:10 -07:00
|
|
|
bool
|
|
|
|
FeatureDetected(int32_t feature[])
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* For information on what constitutes a valid feature, see:
|
|
|
|
* http://androidxref.com/4.0.4/xref/system/core/include/system/camera.h#202
|
|
|
|
*
|
|
|
|
* Although the comments explicitly state that undetected features are
|
|
|
|
* indicated using the value -2000, we conservatively include anything
|
|
|
|
* outside the explicitly valid range of [-1000, 1000] as undetected
|
|
|
|
* as well.
|
|
|
|
*/
|
|
|
|
const int32_t kLowerFeatureBound = -1000;
|
|
|
|
const int32_t kUpperFeatureBound = 1000;
|
|
|
|
return (feature[0] >= kLowerFeatureBound && feature[0] <= kUpperFeatureBound) ||
|
|
|
|
(feature[1] >= kLowerFeatureBound && feature[1] <= kUpperFeatureBound);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsGonkCameraControl::OnFacesDetected(camera_frame_metadata_t* aMetaData)
|
|
|
|
{
|
|
|
|
NS_ENSURE_TRUE_VOID(aMetaData);
|
|
|
|
|
|
|
|
nsTArray<Face> faces;
|
|
|
|
uint32_t numFaces = aMetaData->number_of_faces;
|
|
|
|
DOM_CAMERA_LOGI("Camera detected %d face(s)", numFaces);
|
|
|
|
|
|
|
|
faces.SetCapacity(numFaces);
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < numFaces; ++i) {
|
|
|
|
Face* f = faces.AppendElement();
|
|
|
|
|
|
|
|
f->id = aMetaData->faces[i].id;
|
|
|
|
f->score = aMetaData->faces[i].score;
|
|
|
|
if (f->score > 100) {
|
|
|
|
f->score = 100;
|
|
|
|
}
|
|
|
|
f->bound.left = aMetaData->faces[i].rect[0];
|
|
|
|
f->bound.top = aMetaData->faces[i].rect[1];
|
|
|
|
f->bound.right = aMetaData->faces[i].rect[2];
|
|
|
|
f->bound.bottom = aMetaData->faces[i].rect[3];
|
|
|
|
DOM_CAMERA_LOGI("Camera face[%u] appended: id=%d, score=%d, bound=(%d, %d)-(%d, %d)\n",
|
|
|
|
i, f->id, f->score, f->bound.left, f->bound.top, f->bound.right, f->bound.bottom);
|
|
|
|
|
|
|
|
f->hasLeftEye = FeatureDetected(aMetaData->faces[i].left_eye);
|
|
|
|
if (f->hasLeftEye) {
|
|
|
|
f->leftEye.x = aMetaData->faces[i].left_eye[0];
|
|
|
|
f->leftEye.y = aMetaData->faces[i].left_eye[1];
|
|
|
|
DOM_CAMERA_LOGI(" Left eye detected at (%d, %d)\n",
|
|
|
|
f->leftEye.x, f->leftEye.y);
|
|
|
|
} else {
|
|
|
|
DOM_CAMERA_LOGI(" No left eye detected\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
f->hasRightEye = FeatureDetected(aMetaData->faces[i].right_eye);
|
|
|
|
if (f->hasRightEye) {
|
|
|
|
f->rightEye.x = aMetaData->faces[i].right_eye[0];
|
|
|
|
f->rightEye.y = aMetaData->faces[i].right_eye[1];
|
|
|
|
DOM_CAMERA_LOGI(" Right eye detected at (%d, %d)\n",
|
|
|
|
f->rightEye.x, f->rightEye.y);
|
|
|
|
} else {
|
|
|
|
DOM_CAMERA_LOGI(" No right eye detected\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
f->hasMouth = FeatureDetected(aMetaData->faces[i].mouth);
|
|
|
|
if (f->hasMouth) {
|
|
|
|
f->mouth.x = aMetaData->faces[i].mouth[0];
|
|
|
|
f->mouth.y = aMetaData->faces[i].mouth[1];
|
|
|
|
DOM_CAMERA_LOGI(" Mouth detected at (%d, %d)\n", f->mouth.x, f->mouth.y);
|
|
|
|
} else {
|
|
|
|
DOM_CAMERA_LOGI(" No mouth detected\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CameraControlImpl::OnFacesDetected(faces);
|
|
|
|
}
|
|
|
|
|
2012-09-04 18:01:56 -07:00
|
|
|
void
|
2014-02-14 14:41:07 -08:00
|
|
|
nsGonkCameraControl::OnTakePictureComplete(uint8_t* aData, uint32_t aLength)
|
2012-07-30 14:59:05 -07:00
|
|
|
{
|
2014-02-14 14:41:07 -08:00
|
|
|
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
|
|
|
|
|
2012-09-04 18:01:56 -07:00
|
|
|
uint8_t* data = new uint8_t[aLength];
|
|
|
|
|
|
|
|
memcpy(data, aData, aLength);
|
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
nsString s(NS_LITERAL_STRING("image/"));
|
|
|
|
s.Append(mFileFormat);
|
|
|
|
DOM_CAMERA_LOGI("Got picture, type '%s', %u bytes\n", NS_ConvertUTF16toUTF8(s).get(), aLength);
|
|
|
|
OnTakePictureComplete(data, aLength, s);
|
|
|
|
|
|
|
|
if (mResumePreviewAfterTakingPicture) {
|
|
|
|
nsresult rv = StartPreview();
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
DOM_CAMERA_LOGE("Failed to restart camera preview (%x)\n", rv);
|
|
|
|
OnPreviewStateChange(CameraControlListener::kPreviewStopped);
|
|
|
|
}
|
2012-09-04 18:01:56 -07:00
|
|
|
}
|
2014-02-14 14:41:07 -08:00
|
|
|
|
|
|
|
DOM_CAMERA_LOGI("nsGonkCameraControl::OnTakePictureComplete() done\n");
|
2012-09-04 18:01:56 -07:00
|
|
|
}
|
2012-07-30 14:59:05 -07:00
|
|
|
|
2013-01-24 10:41:18 -08:00
|
|
|
void
|
2014-02-14 14:41:07 -08:00
|
|
|
nsGonkCameraControl::OnTakePictureError()
|
2013-01-24 10:41:18 -08:00
|
|
|
{
|
2014-04-25 13:28:15 -07:00
|
|
|
CameraControlImpl::OnUserError(CameraControlListener::kInTakePicture,
|
|
|
|
NS_ERROR_FAILURE);
|
2014-02-14 05:27:44 -08:00
|
|
|
}
|
2014-02-10 14:53:19 -08:00
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
nsresult
|
|
|
|
nsGonkCameraControl::SetPreviewSize(const Size& aSize)
|
2014-02-14 05:27:44 -08:00
|
|
|
{
|
2014-02-14 14:41:07 -08:00
|
|
|
MOZ_ASSERT(NS_GetCurrentThread() == mCameraThread);
|
2014-02-14 05:27:44 -08:00
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
nsTArray<Size> previewSizes;
|
2014-06-25 14:45:02 -07:00
|
|
|
nsresult rv = Get(CAMERA_PARAM_SUPPORTED_PREVIEWSIZES, previewSizes);
|
2014-02-14 14:41:07 -08:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
DOM_CAMERA_LOGE("Camera failed to return any preview sizes (0x%x)\n", rv);
|
|
|
|
return rv;
|
2014-02-14 05:27:44 -08:00
|
|
|
}
|
2014-02-13 21:28:57 -08:00
|
|
|
|
2014-04-07 15:21:00 -07:00
|
|
|
Size best;
|
2014-09-10 08:48:55 -07:00
|
|
|
rv = GetSupportedSize(aSize, previewSizes, best);
|
2014-04-07 15:21:00 -07:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
DOM_CAMERA_LOGE("Failed to find a supported preview size, requested size %dx%d",
|
|
|
|
aSize.width, aSize.height);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2014-09-16 12:36:48 -07:00
|
|
|
if (mSeparateVideoAndPreviewSizesSupported) {
|
|
|
|
// Some camera drivers will ignore our preview size if it's larger
|
|
|
|
// than the currently set video recording size, so we need to set
|
|
|
|
// the video size here as well, just in case.
|
|
|
|
if (best.width > mLastRecorderSize.width || best.height > mLastRecorderSize.height) {
|
|
|
|
SetVideoSize(best);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
mLastRecorderSize = best;
|
2014-04-07 15:21:00 -07:00
|
|
|
}
|
|
|
|
mCurrentConfiguration.mPreviewSize = best;
|
2014-06-25 14:45:02 -07:00
|
|
|
return Set(CAMERA_PARAM_PREVIEWSIZE, best);
|
2014-04-07 15:21:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsGonkCameraControl::SetVideoSize(const Size& aSize)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_GetCurrentThread() == mCameraThread);
|
|
|
|
|
2014-09-16 12:36:48 -07:00
|
|
|
if (!mSeparateVideoAndPreviewSizesSupported) {
|
|
|
|
DOM_CAMERA_LOGE("Camera does not support setting separate video size\n");
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
2014-04-07 15:21:00 -07:00
|
|
|
nsTArray<Size> videoSizes;
|
2014-06-25 14:45:02 -07:00
|
|
|
nsresult rv = Get(CAMERA_PARAM_SUPPORTED_VIDEOSIZES, videoSizes);
|
2014-04-07 15:21:00 -07:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
DOM_CAMERA_LOGE("Camera failed to return any video sizes (0x%x)\n", rv);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
Size best;
|
|
|
|
rv = GetSupportedSize(aSize, videoSizes, best);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
DOM_CAMERA_LOGE("Failed to find a supported video size, requested size %dx%d",
|
|
|
|
aSize.width, aSize.height);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
mLastRecorderSize = best;
|
2014-06-25 14:45:02 -07:00
|
|
|
return Set(CAMERA_PARAM_VIDEOSIZE, best);
|
2014-04-07 15:21:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsGonkCameraControl::GetSupportedSize(const Size& aSize,
|
|
|
|
const nsTArray<Size>& supportedSizes,
|
|
|
|
Size& best)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_ERROR_INVALID_ARG;
|
|
|
|
best = aSize;
|
2014-02-14 14:41:07 -08:00
|
|
|
uint32_t minSizeDelta = UINT32_MAX;
|
|
|
|
uint32_t delta;
|
|
|
|
|
|
|
|
if (!aSize.width && !aSize.height) {
|
2012-09-04 18:01:56 -07:00
|
|
|
// no size specified, take the first supported size
|
2014-04-07 15:21:00 -07:00
|
|
|
best = supportedSizes[0];
|
2014-09-10 08:48:55 -07:00
|
|
|
return NS_OK;
|
2014-02-14 14:41:07 -08:00
|
|
|
} else if (aSize.width && aSize.height) {
|
2014-09-10 08:48:55 -07:00
|
|
|
// both height and width specified, find the supported size closest to
|
|
|
|
// the requested size, looking for an exact match first
|
|
|
|
for (nsTArray<Size>::index_type i = 0; i < supportedSizes.Length(); i++) {
|
|
|
|
Size size = supportedSizes[i];
|
|
|
|
if (size.width == aSize.width && size.height == aSize.height) {
|
|
|
|
best = size;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// no exact matches--look for a match closest in area
|
2014-02-14 14:41:07 -08:00
|
|
|
uint32_t targetArea = aSize.width * aSize.height;
|
2014-04-07 15:21:00 -07:00
|
|
|
for (nsTArray<Size>::index_type i = 0; i < supportedSizes.Length(); i++) {
|
|
|
|
Size size = supportedSizes[i];
|
2014-02-14 14:41:07 -08:00
|
|
|
uint32_t delta = abs((long int)(size.width * size.height - targetArea));
|
2012-09-04 18:01:56 -07:00
|
|
|
if (delta < minSizeDelta) {
|
|
|
|
minSizeDelta = delta;
|
2014-02-14 14:41:07 -08:00
|
|
|
best = size;
|
2014-04-07 15:21:00 -07:00
|
|
|
rv = NS_OK;
|
2012-09-04 18:01:56 -07:00
|
|
|
}
|
|
|
|
}
|
2014-02-14 14:41:07 -08:00
|
|
|
} else if (!aSize.width) {
|
2012-09-04 18:01:56 -07:00
|
|
|
// width not specified, find closest height match
|
2014-04-07 15:21:00 -07:00
|
|
|
for (nsTArray<Size>::index_type i = 0; i < supportedSizes.Length(); i++) {
|
|
|
|
Size size = supportedSizes[i];
|
2014-02-14 14:41:07 -08:00
|
|
|
delta = abs((long int)(size.height - aSize.height));
|
2012-09-04 18:01:56 -07:00
|
|
|
if (delta < minSizeDelta) {
|
|
|
|
minSizeDelta = delta;
|
2014-02-14 14:41:07 -08:00
|
|
|
best = size;
|
2014-04-07 15:21:00 -07:00
|
|
|
rv = NS_OK;
|
2012-09-04 18:01:56 -07:00
|
|
|
}
|
|
|
|
}
|
2014-02-14 14:41:07 -08:00
|
|
|
} else if (!aSize.height) {
|
2012-09-04 18:01:56 -07:00
|
|
|
// height not specified, find closest width match
|
2014-04-07 15:21:00 -07:00
|
|
|
for (nsTArray<Size>::index_type i = 0; i < supportedSizes.Length(); i++) {
|
|
|
|
Size size = supportedSizes[i];
|
2014-02-14 14:41:07 -08:00
|
|
|
delta = abs((long int)(size.width - aSize.width));
|
2012-09-04 18:01:56 -07:00
|
|
|
if (delta < minSizeDelta) {
|
|
|
|
minSizeDelta = delta;
|
2014-02-14 14:41:07 -08:00
|
|
|
best = size;
|
2014-04-07 15:21:00 -07:00
|
|
|
rv = NS_OK;
|
2012-09-04 18:01:56 -07:00
|
|
|
}
|
|
|
|
}
|
2012-07-30 14:59:05 -07:00
|
|
|
}
|
2014-04-07 15:21:00 -07:00
|
|
|
return rv;
|
2012-07-30 14:59:05 -07:00
|
|
|
}
|
|
|
|
|
2012-09-28 22:30:52 -07:00
|
|
|
nsresult
|
2014-09-16 12:36:48 -07:00
|
|
|
nsGonkCameraControl::SetVideoConfiguration(const Configuration& aConfig)
|
2012-09-28 22:30:52 -07:00
|
|
|
{
|
2014-02-14 14:41:07 -08:00
|
|
|
DOM_CAMERA_LOGT("%s:%d\n", __func__, __LINE__);
|
|
|
|
|
2012-09-28 22:30:52 -07:00
|
|
|
// read preferences for camcorder
|
|
|
|
mMediaProfiles = MediaProfiles::getInstance();
|
|
|
|
|
2014-09-16 12:36:48 -07:00
|
|
|
nsAutoCString profile = NS_ConvertUTF16toUTF8(aConfig.mRecorderProfile);
|
2014-03-15 12:00:15 -07:00
|
|
|
mRecorderProfile = GetGonkRecorderProfileManager().take()->Get(profile.get());
|
2012-10-23 15:30:28 -07:00
|
|
|
if (!mRecorderProfile) {
|
|
|
|
DOM_CAMERA_LOGE("Recorder profile '%s' is not supported\n", profile.get());
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
const GonkRecorderVideoProfile* video = mRecorderProfile->GetGonkVideoProfile();
|
|
|
|
int width = video->GetWidth();
|
|
|
|
int height = video->GetHeight();
|
|
|
|
int fps = video->GetFramerate();
|
2014-02-14 14:41:07 -08:00
|
|
|
if (fps == -1 || width < 0 || height < 0) {
|
|
|
|
DOM_CAMERA_LOGE("Can't configure preview with fps=%d, width=%d, height=%d\n",
|
|
|
|
fps, width, height);
|
2012-09-28 22:30:52 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
PullParametersImpl();
|
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
Size size;
|
|
|
|
size.width = static_cast<uint32_t>(width);
|
|
|
|
size.height = static_cast<uint32_t>(height);
|
2012-09-28 22:30:52 -07:00
|
|
|
|
2013-11-13 11:24:20 -08:00
|
|
|
{
|
2014-02-14 14:41:07 -08:00
|
|
|
ICameraControlParameterSetAutoEnter set(this);
|
2014-09-16 12:36:48 -07:00
|
|
|
nsresult rv;
|
2014-02-14 14:41:07 -08:00
|
|
|
|
2014-09-16 12:36:48 -07:00
|
|
|
if (mSeparateVideoAndPreviewSizesSupported) {
|
|
|
|
// The camera supports two video streams: a low(er) resolution preview
|
|
|
|
// stream and and a potentially high(er) resolution stream for encoding.
|
|
|
|
rv = SetVideoSize(size);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
DOM_CAMERA_LOGE("Failed to set video mode video size (0x%x)\n", rv);
|
|
|
|
return rv;
|
|
|
|
}
|
2014-02-13 21:28:57 -08:00
|
|
|
|
2014-09-16 12:36:48 -07:00
|
|
|
// The video size must be set first, before the preview size, because
|
|
|
|
// some platforms have a dependency between the two.
|
|
|
|
rv = SetPreviewSize(aConfig.mPreviewSize);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
DOM_CAMERA_LOGE("Failed to set video mode preview size (0x%x)\n", rv);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// The camera only supports a single video stream: in this case, we set
|
|
|
|
// the preview size to be the desired video recording size, and ignore
|
|
|
|
// the specified preview size.
|
|
|
|
rv = SetPreviewSize(size);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
DOM_CAMERA_LOGE("Failed to set video mode preview size (0x%x)\n", rv);
|
|
|
|
return rv;
|
|
|
|
}
|
2014-02-14 14:41:07 -08:00
|
|
|
}
|
|
|
|
|
2014-06-25 14:45:02 -07:00
|
|
|
rv = Set(CAMERA_PARAM_PREVIEWFRAMERATE, fps);
|
2014-02-14 14:41:07 -08:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
DOM_CAMERA_LOGE("Failed to set video mode frame rate (0x%x)\n", rv);
|
|
|
|
return rv;
|
|
|
|
}
|
2013-11-13 11:24:20 -08:00
|
|
|
}
|
2014-06-25 14:45:02 -07:00
|
|
|
|
|
|
|
mPreviewFps = fps;
|
2012-09-28 22:30:52 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-11-02 13:11:50 -07:00
|
|
|
class GonkRecorderListener : public IMediaRecorderClient
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
GonkRecorderListener(nsGonkCameraControl* aCameraControl)
|
|
|
|
: mCameraControl(aCameraControl)
|
|
|
|
{
|
2014-02-14 14:41:07 -08:00
|
|
|
DOM_CAMERA_LOGT("%s:%d : this=%p, aCameraControl=%p\n",
|
|
|
|
__func__, __LINE__, this, mCameraControl.get());
|
2012-11-02 13:11:50 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void notify(int msg, int ext1, int ext2)
|
|
|
|
{
|
|
|
|
if (mCameraControl) {
|
2014-02-14 14:41:07 -08:00
|
|
|
mCameraControl->OnRecorderEvent(msg, ext1, ext2);
|
2012-11-02 13:11:50 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
IBinder* onAsBinder()
|
|
|
|
{
|
|
|
|
DOM_CAMERA_LOGE("onAsBinder() called, should NEVER get called!\n");
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
~GonkRecorderListener() { }
|
|
|
|
nsRefPtr<nsGonkCameraControl> mCameraControl;
|
|
|
|
};
|
|
|
|
|
|
|
|
void
|
2014-02-14 14:41:07 -08:00
|
|
|
nsGonkCameraControl::OnRecorderEvent(int msg, int ext1, int ext2)
|
2012-11-02 13:11:50 -07:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Refer to base/include/media/mediarecorder.h for a complete list
|
|
|
|
* of error and info message codes. There are duplicate values
|
|
|
|
* within the status/error code space, as determined by code inspection:
|
|
|
|
*
|
|
|
|
* +------- msg
|
|
|
|
* | +----- ext1
|
|
|
|
* | | +--- ext2
|
|
|
|
* V V V
|
|
|
|
* 1 MEDIA_RECORDER_EVENT_ERROR
|
|
|
|
* 1 MEDIA_RECORDER_ERROR_UNKNOWN
|
|
|
|
* [3] ERROR_MALFORMED
|
|
|
|
* 100 mediaplayer.h::MEDIA_ERROR_SERVER_DIED
|
|
|
|
* 0 <always zero>
|
|
|
|
* 2 MEDIA_RECORDER_EVENT_INFO
|
|
|
|
* 800 MEDIA_RECORDER_INFO_MAX_DURATION_REACHED
|
|
|
|
* 0 <always zero>
|
|
|
|
* 801 MEDIA_RECORDER_INFO_MAX_FILESIZE_REACHED
|
|
|
|
* 0 <always zero>
|
|
|
|
* 1000 MEDIA_RECORDER_TRACK_INFO_COMPLETION_STATUS[1b]
|
|
|
|
* [3] UNKNOWN_ERROR, etc.
|
|
|
|
* 100 MEDIA_ERROR[4]
|
|
|
|
* 100 mediaplayer.h::MEDIA_ERROR_SERVER_DIED
|
|
|
|
* 0 <always zero>
|
|
|
|
* 100 MEDIA_RECORDER_TRACK_EVENT_ERROR
|
|
|
|
* 100 MEDIA_RECORDER_TRACK_ERROR_GENERAL[1a]
|
|
|
|
* [3] UNKNOWN_ERROR, etc.
|
|
|
|
* 200 MEDIA_RECORDER_ERROR_VIDEO_NO_SYNC_FRAME[2]
|
|
|
|
* ? <unknown>
|
|
|
|
* 101 MEDIA_RECORDER_TRACK_EVENT_INFO
|
|
|
|
* 1000 MEDIA_RECORDER_TRACK_INFO_COMPLETION_STATUS[1a]
|
|
|
|
* [3] UNKNOWN_ERROR, etc.
|
|
|
|
* N see mediarecorder.h::media_recorder_info_type[5]
|
|
|
|
*
|
|
|
|
* 1. a) High 4 bits are the track number, the next 12 bits are reserved,
|
|
|
|
* and the final 16 bits are the actual error code (above).
|
|
|
|
* b) But not in this case.
|
|
|
|
* 2. Never actually used in AOSP code?
|
|
|
|
* 3. Specific error codes are from utils/Errors.h and/or
|
|
|
|
* include/media/stagefright/MediaErrors.h.
|
|
|
|
* 4. Only in frameworks/base/media/libmedia/mediaplayer.cpp.
|
|
|
|
* 5. These are mostly informational and we can ignore them; note that
|
|
|
|
* although the MEDIA_RECORDER_INFO_MAX_DURATION_REACHED and
|
|
|
|
* MEDIA_RECORDER_INFO_MAX_FILESIZE_REACHED values are defined in this
|
|
|
|
* enum, they are used with different ext1 codes. /o\
|
|
|
|
*/
|
2014-02-14 14:41:07 -08:00
|
|
|
int trackNum = CameraControlListener::kNoTrackNumber;
|
2012-11-02 13:11:50 -07:00
|
|
|
|
|
|
|
switch (msg) {
|
|
|
|
// Recorder-related events
|
|
|
|
case MEDIA_RECORDER_EVENT_INFO:
|
|
|
|
switch (ext1) {
|
|
|
|
case MEDIA_RECORDER_INFO_MAX_FILESIZE_REACHED:
|
|
|
|
DOM_CAMERA_LOGI("recorder-event : info: maximum file size reached\n");
|
2014-02-14 14:41:07 -08:00
|
|
|
OnRecorderStateChange(CameraControlListener::kFileSizeLimitReached, ext2, trackNum);
|
2012-11-02 13:11:50 -07:00
|
|
|
return;
|
|
|
|
|
|
|
|
case MEDIA_RECORDER_INFO_MAX_DURATION_REACHED:
|
|
|
|
DOM_CAMERA_LOGI("recorder-event : info: maximum video duration reached\n");
|
2014-02-14 14:41:07 -08:00
|
|
|
OnRecorderStateChange(CameraControlListener::kVideoLengthLimitReached, ext2, trackNum);
|
2012-11-02 13:11:50 -07:00
|
|
|
return;
|
|
|
|
|
|
|
|
case MEDIA_RECORDER_TRACK_INFO_COMPLETION_STATUS:
|
|
|
|
DOM_CAMERA_LOGI("recorder-event : info: track completed\n");
|
2014-02-14 14:41:07 -08:00
|
|
|
OnRecorderStateChange(CameraControlListener::kTrackCompleted, ext2, trackNum);
|
2012-11-02 13:11:50 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MEDIA_RECORDER_EVENT_ERROR:
|
|
|
|
switch (ext1) {
|
|
|
|
case MEDIA_RECORDER_ERROR_UNKNOWN:
|
|
|
|
DOM_CAMERA_LOGE("recorder-event : recorder-error: %d (0x%08x)\n", ext2, ext2);
|
2014-02-14 14:41:07 -08:00
|
|
|
OnRecorderStateChange(CameraControlListener::kMediaRecorderFailed, ext2, trackNum);
|
2012-11-02 13:11:50 -07:00
|
|
|
return;
|
|
|
|
|
|
|
|
case MEDIA_ERROR_SERVER_DIED:
|
|
|
|
DOM_CAMERA_LOGE("recorder-event : recorder-error: server died\n");
|
2014-02-14 14:41:07 -08:00
|
|
|
OnRecorderStateChange(CameraControlListener::kMediaServerFailed, ext2, trackNum);
|
2012-11-02 13:11:50 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Track-related events, see note 1(a) above.
|
|
|
|
case MEDIA_RECORDER_TRACK_EVENT_INFO:
|
|
|
|
trackNum = (ext1 & 0xF0000000) >> 28;
|
|
|
|
ext1 &= 0xFFFF;
|
|
|
|
switch (ext1) {
|
|
|
|
case MEDIA_RECORDER_TRACK_INFO_COMPLETION_STATUS:
|
|
|
|
if (ext2 == OK) {
|
|
|
|
DOM_CAMERA_LOGI("recorder-event : track-complete: track %d, %d (0x%08x)\n", trackNum, ext2, ext2);
|
2014-02-14 14:41:07 -08:00
|
|
|
OnRecorderStateChange(CameraControlListener::kTrackCompleted, ext2, trackNum);
|
2012-11-02 13:11:50 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
DOM_CAMERA_LOGE("recorder-event : track-error: track %d, %d (0x%08x)\n", trackNum, ext2, ext2);
|
2014-02-14 14:41:07 -08:00
|
|
|
OnRecorderStateChange(CameraControlListener::kTrackFailed, ext2, trackNum);
|
2012-11-02 13:11:50 -07:00
|
|
|
return;
|
|
|
|
|
|
|
|
case MEDIA_RECORDER_TRACK_INFO_PROGRESS_IN_TIME:
|
|
|
|
DOM_CAMERA_LOGI("recorder-event : track-info: progress in time: %d ms\n", ext2);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MEDIA_RECORDER_TRACK_EVENT_ERROR:
|
|
|
|
trackNum = (ext1 & 0xF0000000) >> 28;
|
|
|
|
ext1 &= 0xFFFF;
|
|
|
|
DOM_CAMERA_LOGE("recorder-event : track-error: track %d, %d (0x%08x)\n", trackNum, ext2, ext2);
|
2014-02-14 14:41:07 -08:00
|
|
|
OnRecorderStateChange(CameraControlListener::kTrackFailed, ext2, trackNum);
|
2012-11-02 13:11:50 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// All unhandled cases wind up here
|
|
|
|
DOM_CAMERA_LOGW("recorder-event : unhandled: msg=%d, ext1=%d, ext2=%d\n", msg, ext1, ext2);
|
|
|
|
}
|
|
|
|
|
2012-09-28 22:30:52 -07:00
|
|
|
nsresult
|
2014-04-09 08:53:41 -07:00
|
|
|
nsGonkCameraControl::SetupRecording(int aFd, int aRotation,
|
2014-05-14 14:33:00 -07:00
|
|
|
uint64_t aMaxFileSizeBytes,
|
|
|
|
uint64_t aMaxVideoLengthMs)
|
2012-09-28 22:30:52 -07:00
|
|
|
{
|
2013-03-14 14:30:38 -07:00
|
|
|
RETURN_IF_NO_CAMERA_HW();
|
|
|
|
|
2012-09-28 22:30:52 -07:00
|
|
|
// choosing a size big enough to hold the params
|
|
|
|
const size_t SIZE = 256;
|
|
|
|
char buffer[SIZE];
|
|
|
|
|
2014-06-10 06:52:22 -07:00
|
|
|
ReentrantMonitorAutoEnter mon(mRecorderMonitor);
|
|
|
|
|
2012-09-28 22:30:52 -07:00
|
|
|
mRecorder = new GonkRecorder();
|
2014-05-14 14:33:00 -07:00
|
|
|
CHECK_SETARG_RETURN(mRecorder->init(), NS_ERROR_FAILURE);
|
2012-09-28 22:30:52 -07:00
|
|
|
|
2012-10-23 15:30:28 -07:00
|
|
|
nsresult rv = mRecorderProfile->ConfigureRecorder(mRecorder);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2014-05-14 14:33:00 -07:00
|
|
|
CHECK_SETARG_RETURN(mRecorder->setCamera(mCameraHw), NS_ERROR_FAILURE);
|
2012-10-23 15:30:28 -07:00
|
|
|
|
2014-05-14 14:33:00 -07:00
|
|
|
DOM_CAMERA_LOGI("maxVideoLengthMs=%llu\n", aMaxVideoLengthMs);
|
|
|
|
const uint64_t kMaxVideoLengthMs = INT64_MAX / 1000;
|
2012-11-02 13:11:50 -07:00
|
|
|
if (aMaxVideoLengthMs == 0) {
|
|
|
|
aMaxVideoLengthMs = -1;
|
2014-05-14 14:33:00 -07:00
|
|
|
} else if (aMaxVideoLengthMs > kMaxVideoLengthMs) {
|
|
|
|
// GonkRecorder parameters are internally limited to signed 64-bit values,
|
|
|
|
// and the time length limit is converted from milliseconds to microseconds,
|
|
|
|
// so we limit this value to prevent any unexpected overflow weirdness.
|
|
|
|
DOM_CAMERA_LOGW("maxVideoLengthMs capped to %lld\n", kMaxVideoLengthMs);
|
|
|
|
aMaxVideoLengthMs = kMaxVideoLengthMs;
|
2012-11-02 13:11:50 -07:00
|
|
|
}
|
|
|
|
snprintf(buffer, SIZE, "max-duration=%lld", aMaxVideoLengthMs);
|
2014-05-14 14:33:00 -07:00
|
|
|
CHECK_SETARG_RETURN(mRecorder->setParameters(String8(buffer)),
|
|
|
|
NS_ERROR_INVALID_ARG);
|
2012-10-23 15:30:28 -07:00
|
|
|
|
2014-05-14 14:33:00 -07:00
|
|
|
DOM_CAMERA_LOGI("maxFileSizeBytes=%llu\n", aMaxFileSizeBytes);
|
2012-11-02 13:11:50 -07:00
|
|
|
if (aMaxFileSizeBytes == 0) {
|
|
|
|
aMaxFileSizeBytes = -1;
|
2014-05-14 14:33:00 -07:00
|
|
|
} else if (aMaxFileSizeBytes > INT64_MAX) {
|
|
|
|
// GonkRecorder parameters are internally limited to signed 64-bit values
|
|
|
|
DOM_CAMERA_LOGW("maxFileSizeBytes capped to INT64_MAX\n");
|
|
|
|
aMaxFileSizeBytes = INT64_MAX;
|
2012-11-02 13:11:50 -07:00
|
|
|
}
|
|
|
|
snprintf(buffer, SIZE, "max-filesize=%lld", aMaxFileSizeBytes);
|
2014-05-14 14:33:00 -07:00
|
|
|
CHECK_SETARG_RETURN(mRecorder->setParameters(String8(buffer)),
|
|
|
|
NS_ERROR_INVALID_ARG);
|
2012-10-23 15:30:28 -07:00
|
|
|
|
2012-11-06 19:32:01 -08:00
|
|
|
// adjust rotation by camera sensor offset
|
|
|
|
int r = aRotation;
|
2014-01-12 18:12:40 -08:00
|
|
|
r += mCameraHw->GetSensorOrientation();
|
2014-01-23 16:10:23 -08:00
|
|
|
r = RationalizeRotation(r);
|
2012-11-06 19:32:01 -08:00
|
|
|
DOM_CAMERA_LOGI("setting video rotation to %d degrees (mapped from %d)\n", r, aRotation);
|
|
|
|
snprintf(buffer, SIZE, "video-param-rotation-angle-degrees=%d", r);
|
2014-05-14 14:33:00 -07:00
|
|
|
CHECK_SETARG_RETURN(mRecorder->setParameters(String8(buffer)),
|
|
|
|
NS_ERROR_INVALID_ARG);
|
2012-09-28 22:30:52 -07:00
|
|
|
|
2014-05-14 14:33:00 -07:00
|
|
|
CHECK_SETARG_RETURN(mRecorder->setListener(new GonkRecorderListener(this)),
|
|
|
|
NS_ERROR_FAILURE);
|
2012-11-02 13:11:50 -07:00
|
|
|
|
2012-09-28 22:30:52 -07:00
|
|
|
// recording API needs file descriptor of output file
|
2014-05-14 14:33:00 -07:00
|
|
|
CHECK_SETARG_RETURN(mRecorder->setOutputFile(aFd, 0, 0), NS_ERROR_FAILURE);
|
|
|
|
CHECK_SETARG_RETURN(mRecorder->prepare(), NS_ERROR_FAILURE);
|
2014-04-09 08:53:41 -07:00
|
|
|
|
2012-09-28 22:30:52 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2014-02-19 20:18:52 -08:00
|
|
|
nsGonkCameraControl::StopImpl()
|
2012-12-23 07:54:54 -08:00
|
|
|
{
|
|
|
|
DOM_CAMERA_LOGT("%s:%d : this=%p\n", __func__, __LINE__, this);
|
|
|
|
|
|
|
|
// if we're recording, stop recording
|
2014-04-09 08:53:41 -07:00
|
|
|
StopRecordingImpl();
|
2012-12-23 07:54:54 -08:00
|
|
|
|
|
|
|
// stop the preview
|
2014-02-14 14:41:07 -08:00
|
|
|
StopPreviewImpl();
|
2012-12-23 07:54:54 -08:00
|
|
|
|
|
|
|
// release the hardware handle
|
2013-03-08 11:43:33 -08:00
|
|
|
if (mCameraHw.get()){
|
|
|
|
mCameraHw->Close();
|
|
|
|
mCameraHw.clear();
|
|
|
|
}
|
2012-12-23 07:54:54 -08:00
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
OnHardwareStateChange(CameraControlListener::kHardwareClosed);
|
2012-12-23 07:54:54 -08:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-10-23 15:30:28 -07:00
|
|
|
already_AddRefed<GonkRecorderProfileManager>
|
|
|
|
nsGonkCameraControl::GetGonkRecorderProfileManager()
|
|
|
|
{
|
|
|
|
if (!mProfileManager) {
|
2014-02-14 14:41:07 -08:00
|
|
|
nsTArray<Size> sizes;
|
|
|
|
nsresult rv = Get(CAMERA_PARAM_SUPPORTED_VIDEOSIZES, sizes);
|
2012-10-23 15:30:28 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, nullptr);
|
|
|
|
|
|
|
|
mProfileManager = new GonkRecorderProfileManager(mCameraId);
|
|
|
|
mProfileManager->SetSupportedResolutions(sizes);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRefPtr<GonkRecorderProfileManager> profileMgr = mProfileManager;
|
|
|
|
return profileMgr.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<RecorderProfileManager>
|
|
|
|
nsGonkCameraControl::GetRecorderProfileManagerImpl()
|
|
|
|
{
|
|
|
|
nsRefPtr<RecorderProfileManager> profileMgr = GetGonkRecorderProfileManager();
|
|
|
|
return profileMgr.forget();
|
|
|
|
}
|
|
|
|
|
2014-07-02 16:55:00 -07:00
|
|
|
void
|
|
|
|
nsGonkCameraControl::OnRateLimitPreview(bool aLimit)
|
|
|
|
{
|
|
|
|
CameraControlImpl::OnRateLimitPreview(aLimit);
|
|
|
|
}
|
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
void
|
2014-03-31 08:24:28 -07:00
|
|
|
nsGonkCameraControl::OnNewPreviewFrame(layers::TextureClient* aBuffer)
|
2012-10-23 15:30:28 -07:00
|
|
|
{
|
2014-02-14 14:41:07 -08:00
|
|
|
nsRefPtr<Image> frame = mImageContainer->CreateImage(ImageFormat::GRALLOC_PLANAR_YCBCR);
|
2012-10-23 15:30:28 -07:00
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
GrallocImage* videoImage = static_cast<GrallocImage*>(frame.get());
|
2012-10-23 15:30:28 -07:00
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
GrallocImage::GrallocData data;
|
2014-03-31 08:24:28 -07:00
|
|
|
data.mGraphicBuffer = aBuffer;
|
2014-02-14 14:41:07 -08:00
|
|
|
data.mPicSize = IntSize(mCurrentConfiguration.mPreviewSize.width,
|
|
|
|
mCurrentConfiguration.mPreviewSize.height);
|
|
|
|
videoImage->SetData(data);
|
2014-02-10 14:53:19 -08:00
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
OnNewPreviewFrame(frame, mCurrentConfiguration.mPreviewSize.width,
|
|
|
|
mCurrentConfiguration.mPreviewSize.height);
|
|
|
|
}
|
2014-02-13 21:28:57 -08:00
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
void
|
2014-04-25 13:28:15 -07:00
|
|
|
nsGonkCameraControl::OnSystemError(CameraControlListener::SystemContext aWhere,
|
|
|
|
nsresult aError)
|
2014-02-14 14:41:07 -08:00
|
|
|
{
|
2014-04-25 13:28:15 -07:00
|
|
|
if (aWhere == CameraControlListener::kSystemService) {
|
2014-02-14 14:41:07 -08:00
|
|
|
OnPreviewStateChange(CameraControlListener::kPreviewStopped);
|
|
|
|
OnHardwareStateChange(CameraControlListener::kHardwareClosed);
|
2014-02-14 05:27:44 -08:00
|
|
|
}
|
2014-02-14 14:41:07 -08:00
|
|
|
|
2014-04-25 13:28:15 -07:00
|
|
|
CameraControlImpl::OnSystemError(aWhere, aError);
|
2012-10-23 15:30:28 -07:00
|
|
|
}
|
|
|
|
|
2012-07-30 14:59:05 -07:00
|
|
|
// Gonk callback handlers.
|
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
void
|
2014-02-14 14:41:07 -08:00
|
|
|
OnTakePictureComplete(nsGonkCameraControl* gc, uint8_t* aData, uint32_t aLength)
|
2012-07-30 14:59:05 -07:00
|
|
|
{
|
2014-02-14 14:41:07 -08:00
|
|
|
gc->OnTakePictureComplete(aData, aLength);
|
2012-07-30 14:59:05 -07:00
|
|
|
}
|
|
|
|
|
2013-01-24 10:41:18 -08:00
|
|
|
void
|
2014-02-14 14:41:07 -08:00
|
|
|
OnTakePictureError(nsGonkCameraControl* gc)
|
2013-01-24 10:41:18 -08:00
|
|
|
{
|
2014-02-14 14:41:07 -08:00
|
|
|
gc->OnTakePictureError();
|
2013-01-24 10:41:18 -08:00
|
|
|
}
|
|
|
|
|
2012-07-30 14:59:05 -07:00
|
|
|
void
|
2014-02-14 14:41:07 -08:00
|
|
|
OnAutoFocusComplete(nsGonkCameraControl* gc, bool aSuccess)
|
2012-09-04 18:01:56 -07:00
|
|
|
{
|
2014-02-14 14:41:07 -08:00
|
|
|
gc->OnAutoFocusComplete(aSuccess);
|
2012-07-30 14:59:05 -07:00
|
|
|
}
|
|
|
|
|
2014-04-09 08:12:25 -07:00
|
|
|
void
|
|
|
|
OnAutoFocusMoving(nsGonkCameraControl* gc, bool aIsMoving)
|
|
|
|
{
|
|
|
|
gc->OnAutoFocusMoving(aIsMoving);
|
|
|
|
}
|
|
|
|
|
2014-04-09 08:52:10 -07:00
|
|
|
void
|
|
|
|
OnFacesDetected(nsGonkCameraControl* gc, camera_frame_metadata_t* aMetaData)
|
|
|
|
{
|
|
|
|
gc->OnFacesDetected(aMetaData);
|
|
|
|
}
|
|
|
|
|
2014-07-02 16:55:00 -07:00
|
|
|
void
|
|
|
|
OnRateLimitPreview(nsGonkCameraControl* gc, bool aLimit)
|
|
|
|
{
|
|
|
|
gc->OnRateLimitPreview(aLimit);
|
|
|
|
}
|
|
|
|
|
2012-07-30 14:59:05 -07:00
|
|
|
void
|
2014-03-31 08:24:28 -07:00
|
|
|
OnNewPreviewFrame(nsGonkCameraControl* gc, layers::TextureClient* aBuffer)
|
2012-07-30 14:59:05 -07:00
|
|
|
{
|
2014-02-14 14:41:07 -08:00
|
|
|
gc->OnNewPreviewFrame(aBuffer);
|
2012-07-30 14:59:05 -07:00
|
|
|
}
|
|
|
|
|
2012-09-30 17:37:47 -07:00
|
|
|
void
|
|
|
|
OnShutter(nsGonkCameraControl* gc)
|
|
|
|
{
|
|
|
|
gc->OnShutter();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
OnClosed(nsGonkCameraControl* gc)
|
|
|
|
{
|
|
|
|
gc->OnClosed();
|
|
|
|
}
|
|
|
|
|
2014-02-14 14:41:07 -08:00
|
|
|
void
|
2014-04-25 13:28:15 -07:00
|
|
|
OnSystemError(nsGonkCameraControl* gc,
|
|
|
|
CameraControlListener::SystemContext aWhere,
|
|
|
|
int32_t aArg1, int32_t aArg2)
|
2014-02-14 14:41:07 -08:00
|
|
|
{
|
|
|
|
#ifdef PR_LOGGING
|
2014-04-25 13:28:15 -07:00
|
|
|
DOM_CAMERA_LOGE("OnSystemError : aWhere=%d, aArg1=%d, aArg2=%d\n", aWhere, aArg1, aArg2);
|
2014-02-14 14:41:07 -08:00
|
|
|
#else
|
|
|
|
unused << aArg1;
|
|
|
|
unused << aArg2;
|
|
|
|
#endif
|
2014-04-25 13:28:15 -07:00
|
|
|
gc->OnSystemError(aWhere, NS_ERROR_FAILURE);
|
2014-02-14 14:41:07 -08:00
|
|
|
}
|
|
|
|
|
2012-07-30 14:59:05 -07:00
|
|
|
} // namespace mozilla
|