Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4349b8df authored by Steve Kondik's avatar Steve Kondik
Browse files

camera: Full support for HTC camera switch

 * Splits the changes for using the "htcwc" switch out from the
   Froyo-compatibility bit. We still need this even on GB.
 * Also split out the reverse-FFC stuff, we need that too at least
   on Glacier.

Change-Id: I5f24cb379b359c5796748f496a03ef431c36e283
parent 4c9d05ed
Loading
Loading
Loading
Loading
+8 −3
Original line number Diff line number Diff line
@@ -69,10 +69,15 @@ endif

ifeq ($(BOARD_USE_FROYO_LIBCAMERA), true)
LOCAL_CFLAGS += -DBOARD_USE_FROYO_LIBCAMERA
endif

ifeq ($(BOARD_HAVE_HTC_FFC), true)
LOCAL_CFLAGS += -DBOARD_HAVE_HTC_FFC
endif

ifeq ($(BOARD_USE_REVERSE_FFC), true)
LOCAL_CFLAGS += -DBOARD_USE_REVERSE_FFC
endif
endif

ifeq ($(BOARD_CAMERA_USE_GETBUFFERINFO),true)
LOCAL_CFLAGS += -DUSE_GETBUFFERINFO
+54 −49
Original line number Diff line number Diff line
@@ -80,6 +80,23 @@ static int getCallingUid() {
    return IPCThreadState::self()->getCallingUid();
}

#if defined(BOARD_USE_FROYO_LIBCAMERA) || defined(BOARD_HAVE_HTC_FFC)
#define HTC_SWITCH_CAMERA_FILE_PATH "/sys/android_camera2/htcwc"
static void htcCameraSwitch(int cameraId)
{
    char buffer[16];
    int fd;

    if (access(HTC_SWITCH_CAMERA_FILE_PATH, W_OK) == 0) {
        snprintf(buffer, sizeof(buffer), "%d", cameraId);

        fd = open(HTC_SWITCH_CAMERA_FILE_PATH, O_WRONLY);
        write(fd, buffer, strlen(buffer));
        close(fd);
    }
}
#endif

// ----------------------------------------------------------------------------

// This is ugly and only safe if we never re-create the CameraService, but
@@ -119,13 +136,35 @@ int32_t CameraService::getNumberOfCameras() {
    return mNumberOfCameras;
}

#if defined(BOARD_USE_FROYO_LIBCAMERA) || defined(BOARD_HAVE_HTC_FFC)
#ifndef FIRST_CAMERA_FACING
#define FIRST_CAMERA_FACING CAMERA_FACING_BACK
#endif
#ifndef FIRST_CAMERA_ORIENTATION
#define FIRST_CAMERA_ORIENTATION 90
#endif
static const CameraInfo sCameraInfo[] = {
    {
        FIRST_CAMERA_FACING,
        FIRST_CAMERA_ORIENTATION,  /* orientation */
    },
    {
        CAMERA_FACING_FRONT,
        270, /* orientation */
    }
};
#endif

status_t CameraService::getCameraInfo(int cameraId,
                                      struct CameraInfo* cameraInfo) {
    if (cameraId < 0 || cameraId >= mNumberOfCameras) {
        return BAD_VALUE;
    }

#if defined(BOARD_USE_FROYO_LIBCAMERA) || defined(BOARD_HAVE_HTC_FFC)
    memcpy(cameraInfo, &sCameraInfo[cameraId], sizeof(CameraInfo));
#else
    HAL_getCameraInfo(cameraId, cameraInfo);
#endif
    return OK;
}

@@ -164,11 +203,25 @@ sp<ICamera> CameraService::connect(
        return NULL;
    }

#if defined(BOARD_USE_FROYO_LIBCAMERA) || defined(BOARD_HAVE_HTC_FFC)
    htcCameraSwitch(cameraId);
#endif

    sp<CameraHardwareInterface> hardware = HAL_openCameraHardware(cameraId);
    if (hardware == NULL) {
        LOGE("Fail to open camera hardware (id=%d)", cameraId);
        return NULL;
    }

#if defined(BOARD_USE_REVERSE_FFC)
    if (cameraId == 1) {
        /* Change default parameters for the front camera */
        CameraParameters params(hardware->getParameters());
        params.set("front-camera-mode", "reverse"); // default is "mirror"
        hardware->setParameters(params);
    }
#endif

    CameraInfo info;
    HAL_getCameraInfo(cameraId, &info);
    client = new Client(this, cameraClient, hardware, cameraId, info.facing,
@@ -1418,27 +1471,6 @@ status_t CameraService::dump(int fd, const Vector<String16>& args) {
}

#ifdef BOARD_USE_FROYO_LIBCAMERA

#ifndef FIRST_CAMERA_FACING
#define FIRST_CAMERA_FACING CAMERA_FACING_BACK
#endif
#ifndef FIRST_CAMERA_ORIENTATION
#define FIRST_CAMERA_ORIENTATION 90
#endif

static const CameraInfo sCameraInfo[] = {
    {
        FIRST_CAMERA_FACING,
        FIRST_CAMERA_ORIENTATION,  /* orientation */
    },
    {
        CAMERA_FACING_FRONT,
        270, /* orientation */
    }
};

#define HTC_SWITCH_CAMERA_FILE_PATH "/sys/android_camera2/htcwc"

static int getNumberOfCameras() {
    if (access(HTC_SWITCH_CAMERA_FILE_PATH, W_OK) == 0) {
        return 2;
@@ -1447,18 +1479,6 @@ static int getNumberOfCameras() {
    return 1;
}

static void htcCameraSwitch(int cameraId)
{
    char buffer[16];
    int fd;

    snprintf(buffer, sizeof(buffer), "%d", cameraId);

    fd = open(HTC_SWITCH_CAMERA_FILE_PATH, O_WRONLY);
    write(fd, buffer, strlen(buffer));
    close(fd);
}

extern "C" int HAL_getNumberOfCameras()
{
    return getNumberOfCameras();
@@ -1474,21 +1494,6 @@ extern "C" sp<CameraHardwareInterface> openCameraHardware(int cameraId);
extern "C" sp<CameraHardwareInterface> HAL_openCameraHardware(int cameraId)
{
    LOGV("openCameraHardware: call createInstance");
    if (getNumberOfCameras() == 2) {
        htcCameraSwitch(cameraId);
#ifdef BOARD_USE_REVERSE_FFC
        if (cameraId == 1) {
            /* Change default parameters for the front camera */
            sp<CameraHardwareInterface> hardware = openCameraHardware(cameraId);
            if (hardware != NULL) {
                CameraParameters params(hardware->getParameters());
                params.set("front-camera-mode", "reverse"); // default is "mirror"
                hardware->setParameters(params);
            }
            return hardware;
        }
#endif
    }
    return openCameraHardware(cameraId);
}
#endif