2012-07-30 21:59:05 +00:00
|
|
|
/*
|
2014-02-20 04:18:52 +00:00
|
|
|
* Copyright (C) 2012-2014 Mozilla Foundation
|
2012-07-30 21:59:05 +00: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-04-09 15:53:34 +00:00
|
|
|
#include "ICameraControl.h"
|
2014-02-14 13:27:44 +00:00
|
|
|
#include "CameraCommon.h"
|
2014-02-14 22:41:07 +00:00
|
|
|
#include "GonkCameraControl.h"
|
2014-06-19 13:20:49 +00:00
|
|
|
#include "CameraPreferences.h"
|
2014-04-25 20:28:15 +00:00
|
|
|
#include "TestGonkCameraControl.h"
|
2013-05-10 06:25:25 +00:00
|
|
|
|
2015-03-10 23:39:49 +00:00
|
|
|
#ifdef MOZ_WIDGET_GONK
|
|
|
|
#include <camera/Camera.h>
|
|
|
|
#else
|
|
|
|
#include "FallbackCameraPlatform.h"
|
|
|
|
#endif
|
|
|
|
|
2013-05-10 06:25:25 +00:00
|
|
|
using namespace mozilla;
|
2012-07-30 21:59:05 +00:00
|
|
|
|
2014-02-14 22:41:07 +00:00
|
|
|
// From ICameraControl, gonk-specific management functions
|
2013-05-02 11:59:58 +00:00
|
|
|
nsresult
|
2014-02-14 22:41:07 +00:00
|
|
|
ICameraControl::GetNumberOfCameras(int32_t& aDeviceCount)
|
2013-05-02 11:59:58 +00:00
|
|
|
{
|
|
|
|
aDeviceCount = android::Camera::getNumberOfCameras();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2014-02-14 22:41:07 +00:00
|
|
|
ICameraControl::GetCameraName(uint32_t aDeviceNum, nsCString& aDeviceName)
|
2013-05-02 11:59:58 +00:00
|
|
|
{
|
|
|
|
int32_t count = android::Camera::getNumberOfCameras();
|
2014-02-14 22:41:07 +00:00
|
|
|
int32_t deviceNum = static_cast<int32_t>(aDeviceNum);
|
|
|
|
|
2013-05-16 14:39:13 +00:00
|
|
|
DOM_CAMERA_LOGI("GetCameraName : getNumberOfCameras() returned %d\n", count);
|
2014-02-14 22:41:07 +00:00
|
|
|
if (deviceNum < 0 || deviceNum > count) {
|
|
|
|
DOM_CAMERA_LOGE("GetCameraName : invalid device number (%u)\n", aDeviceNum);
|
2014-04-25 20:28:15 +00:00
|
|
|
return NS_ERROR_INVALID_ARG;
|
2013-05-02 11:59:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
android::CameraInfo info;
|
2014-02-14 22:41:07 +00:00
|
|
|
int rv = android::Camera::getCameraInfo(deviceNum, &info);
|
2013-05-02 11:59:58 +00:00
|
|
|
if (rv != 0) {
|
2014-02-14 22:41:07 +00:00
|
|
|
DOM_CAMERA_LOGE("GetCameraName : get_camera_info(%d) failed: %d\n", deviceNum, rv);
|
2013-05-02 11:59:58 +00:00
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (info.facing) {
|
|
|
|
case CAMERA_FACING_BACK:
|
2014-05-22 03:48:51 +00:00
|
|
|
aDeviceName.AssignLiteral("back");
|
2013-05-02 11:59:58 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CAMERA_FACING_FRONT:
|
2014-05-22 03:48:51 +00:00
|
|
|
aDeviceName.AssignLiteral("front");
|
2013-05-02 11:59:58 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2014-05-22 03:48:51 +00:00
|
|
|
aDeviceName.AssignLiteral("extra-camera-");
|
2014-02-14 22:41:07 +00:00
|
|
|
aDeviceName.AppendInt(deviceNum);
|
2013-05-02 11:59:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2012-07-30 21:59:05 +00:00
|
|
|
|
2014-02-14 22:41:07 +00:00
|
|
|
nsresult
|
|
|
|
ICameraControl::GetListOfCameras(nsTArray<nsString>& aList)
|
2013-05-10 06:25:25 +00:00
|
|
|
{
|
|
|
|
int32_t count = android::Camera::getNumberOfCameras();
|
2014-02-14 22:41:07 +00:00
|
|
|
DOM_CAMERA_LOGI("getListOfCameras : getNumberOfCameras() returned %d\n", count);
|
2013-05-10 06:25:25 +00:00
|
|
|
if (count <= 0) {
|
2014-04-25 20:28:15 +00:00
|
|
|
aList.Clear();
|
2014-02-14 22:41:07 +00:00
|
|
|
return NS_OK;
|
2013-05-10 06:25:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Allocate 2 extra slots to reserve space for 'front' and 'back' cameras
|
|
|
|
// at the front of the array--we will collapse any empty slots below.
|
|
|
|
aList.SetLength(2);
|
|
|
|
uint32_t extraIdx = 2;
|
2014-02-14 22:41:07 +00:00
|
|
|
bool gotFront = false;
|
|
|
|
bool gotBack = false;
|
2013-05-10 06:25:25 +00:00
|
|
|
while (count--) {
|
|
|
|
nsCString cameraName;
|
|
|
|
nsresult result = GetCameraName(count, cameraName);
|
|
|
|
if (result != NS_OK) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The first camera we find named 'back' gets slot 0; and the first
|
|
|
|
// we find named 'front' gets slot 1. All others appear after these.
|
|
|
|
if (cameraName.EqualsLiteral("back")) {
|
|
|
|
CopyUTF8toUTF16(cameraName, aList[0]);
|
|
|
|
gotBack = true;
|
|
|
|
} else if (cameraName.EqualsLiteral("front")) {
|
|
|
|
CopyUTF8toUTF16(cameraName, aList[1]);
|
|
|
|
gotFront = true;
|
|
|
|
} else {
|
|
|
|
CopyUTF8toUTF16(cameraName, *aList.InsertElementAt(extraIdx));
|
|
|
|
extraIdx++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!gotFront) {
|
|
|
|
aList.RemoveElementAt(1);
|
|
|
|
}
|
2014-02-14 22:41:07 +00:00
|
|
|
|
2013-05-10 06:25:25 +00:00
|
|
|
if (!gotBack) {
|
|
|
|
aList.RemoveElementAt(0);
|
|
|
|
}
|
2014-02-14 22:41:07 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// implementation-specific camera factory
|
|
|
|
already_AddRefed<ICameraControl>
|
2014-02-20 04:18:52 +00:00
|
|
|
ICameraControl::Create(uint32_t aCameraId)
|
2014-02-14 22:41:07 +00:00
|
|
|
{
|
2014-06-19 13:20:49 +00:00
|
|
|
nsCString test;
|
|
|
|
CameraPreferences::GetPref("camera.control.test.enabled", test);
|
2014-04-25 20:28:15 +00:00
|
|
|
nsRefPtr<nsGonkCameraControl> control;
|
|
|
|
if (test.EqualsASCII("control")) {
|
|
|
|
NS_WARNING("Using test CameraControl layer");
|
|
|
|
control = new TestGonkCameraControl(aCameraId);
|
|
|
|
} else {
|
|
|
|
control = new nsGonkCameraControl(aCameraId);
|
|
|
|
}
|
2014-02-14 22:41:07 +00:00
|
|
|
return control.forget();
|
2013-05-10 06:25:25 +00:00
|
|
|
}
|