2012-07-31 01:59:05 +04:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2012 Mozilla Foundation
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2013-03-08 23:43:33 +04:00
|
|
|
#include <camera/Camera.h>
|
|
|
|
|
2014-02-14 09:28:57 +04:00
|
|
|
#include "GonkCameraControl.h"
|
2014-02-14 17:27:44 +04:00
|
|
|
#include "DOMCameraManager.h"
|
|
|
|
#include "CameraCommon.h"
|
|
|
|
#include "mozilla/ErrorResult.h"
|
2013-05-10 10:25:25 +04:00
|
|
|
|
|
|
|
using namespace mozilla;
|
2012-07-31 01:59:05 +04:00
|
|
|
|
2014-02-14 17:27:44 +04:00
|
|
|
// From nsDOMCameraManager, but gonk-specific!
|
2013-05-02 15:59:58 +04:00
|
|
|
nsresult
|
2014-02-14 17:27:44 +04:00
|
|
|
nsDOMCameraManager::GetNumberOfCameras(int32_t& aDeviceCount)
|
2013-05-02 15:59:58 +04:00
|
|
|
{
|
|
|
|
aDeviceCount = android::Camera::getNumberOfCameras();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2014-02-14 17:27:44 +04:00
|
|
|
nsDOMCameraManager::GetCameraName(uint32_t aDeviceNum, nsCString& aDeviceName)
|
2013-05-02 15:59:58 +04:00
|
|
|
{
|
|
|
|
int32_t count = android::Camera::getNumberOfCameras();
|
2013-05-16 18:39:13 +04:00
|
|
|
DOM_CAMERA_LOGI("GetCameraName : getNumberOfCameras() returned %d\n", count);
|
2014-02-14 17:27:44 +04:00
|
|
|
if (aDeviceNum > count) {
|
|
|
|
DOM_CAMERA_LOGE("GetCameraName : invalid device number");
|
2013-05-02 15:59:58 +04:00
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
android::CameraInfo info;
|
2014-02-14 17:27:44 +04:00
|
|
|
int rv = android::Camera::getCameraInfo(aDeviceNum, &info);
|
2013-05-02 15:59:58 +04:00
|
|
|
if (rv != 0) {
|
2014-02-14 17:27:44 +04:00
|
|
|
DOM_CAMERA_LOGE("GetCameraName : get_camera_info(%d) failed: %d\n", aDeviceNum, rv);
|
2013-05-02 15:59:58 +04:00
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (info.facing) {
|
|
|
|
case CAMERA_FACING_BACK:
|
|
|
|
aDeviceName.Assign("back");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CAMERA_FACING_FRONT:
|
|
|
|
aDeviceName.Assign("front");
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
aDeviceName.Assign("extra-camera-");
|
2014-02-14 17:27:44 +04:00
|
|
|
aDeviceName.AppendInt(aDeviceNum);
|
2013-05-02 15:59:58 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2012-07-31 01:59:05 +04:00
|
|
|
|
2014-02-14 17:27:44 +04:00
|
|
|
void
|
|
|
|
nsDOMCameraManager::GetListOfCameras(nsTArray<nsString>& aList, ErrorResult& aRv)
|
2013-05-10 10:25:25 +04:00
|
|
|
{
|
|
|
|
int32_t count = android::Camera::getNumberOfCameras();
|
|
|
|
if (count <= 0) {
|
2014-02-14 17:27:44 +04:00
|
|
|
return;
|
2013-05-10 10:25:25 +04:00
|
|
|
}
|
|
|
|
|
2014-02-14 17:27:44 +04:00
|
|
|
DOM_CAMERA_LOGI("getListOfCameras : getNumberOfCameras() returned %d\n", count);
|
|
|
|
|
2013-05-10 10:25:25 +04: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 17:27:44 +04:00
|
|
|
bool gotFront = false, gotBack = false;
|
2013-05-10 10:25:25 +04: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 17:27:44 +04:00
|
|
|
|
2013-05-10 10:25:25 +04:00
|
|
|
if (!gotBack) {
|
|
|
|
aList.RemoveElementAt(0);
|
|
|
|
}
|
|
|
|
}
|