Home | History | Annotate | Download | only in camera
      1 /*
      2  * Copyright (C) 2011 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 /*
     18  * Contains implementation of a class EmulatedQemuCamera that encapsulates
     19  * functionality of an emulated camera connected to the host.
     20  */
     21 
     22 #define LOG_NDEBUG 0
     23 #define LOG_TAG "EmulatedCamera_QemuCamera"
     24 #include "EmulatedQemuCamera.h"
     25 #include <cutils/log.h>
     26 #include "EmulatedCameraFactory.h"
     27 
     28 namespace android {
     29 
     30 EmulatedQemuCamera::EmulatedQemuCamera(int cameraId, struct hw_module_t* module)
     31     : EmulatedCamera(cameraId, module), mQemuCameraDevice(this) {}
     32 
     33 EmulatedQemuCamera::~EmulatedQemuCamera() {}
     34 
     35 /****************************************************************************
     36  * EmulatedCamera virtual overrides.
     37  ***************************************************************************/
     38 
     39 status_t EmulatedQemuCamera::Initialize(const char* device_name,
     40                                         const char* frame_dims,
     41                                         const char* facing_dir) {
     42   ALOGV("%s:\n   Name=%s\n   Facing '%s'\n   Dimensions=%s", __FUNCTION__,
     43         device_name, facing_dir, frame_dims);
     44   /* Save dimensions. */
     45   mFrameDims = frame_dims;
     46 
     47   /* Initialize camera device. */
     48   status_t res = mQemuCameraDevice.Initialize(device_name);
     49   if (res != NO_ERROR) {
     50     return res;
     51   }
     52 
     53   /* Initialize base class. */
     54   res = EmulatedCamera::Initialize();
     55   if (res != NO_ERROR) {
     56     return res;
     57   }
     58 
     59   /*
     60    * Set customizable parameters.
     61    */
     62 
     63   mParameters.set(EmulatedCamera::FACING_KEY, facing_dir);
     64   mParameters.set(EmulatedCamera::ORIENTATION_KEY,
     65                   gEmulatedCameraFactory.getQemuCameraOrientation());
     66   mParameters.set(CameraParameters::KEY_SUPPORTED_PICTURE_SIZES, frame_dims);
     67   mParameters.set(CameraParameters::KEY_SUPPORTED_PREVIEW_SIZES, frame_dims);
     68 
     69   /*
     70    * Use first dimension reported by the device to set current preview and
     71    * picture sizes.
     72    */
     73 
     74   char first_dim[128];
     75   /* Dimensions are separated with ',' */
     76   const char* c = strchr(frame_dims, ',');
     77   if (c == NULL) {
     78     strncpy(first_dim, frame_dims, sizeof(first_dim));
     79     first_dim[sizeof(first_dim) - 1] = '\0';
     80   } else if (static_cast<size_t>(c - frame_dims) < sizeof(first_dim)) {
     81     memcpy(first_dim, frame_dims, c - frame_dims);
     82     first_dim[c - frame_dims] = '\0';
     83   } else {
     84     memcpy(first_dim, frame_dims, sizeof(first_dim));
     85     first_dim[sizeof(first_dim) - 1] = '\0';
     86   }
     87 
     88   /* Width and height are separated with 'x' */
     89   char* sep = strchr(first_dim, 'x');
     90   if (sep == NULL) {
     91     ALOGE("%s: Invalid first dimension format in %s", __FUNCTION__, frame_dims);
     92     return EINVAL;
     93   }
     94 
     95   *sep = '\0';
     96   const int x = atoi(first_dim);
     97   const int y = atoi(sep + 1);
     98   mParameters.setPreviewSize(x, y);
     99   mParameters.setPictureSize(x, y);
    100 
    101   ALOGV("%s: Qemu camera %s is initialized. Current frame is %dx%d",
    102         __FUNCTION__, device_name, x, y);
    103 
    104   return NO_ERROR;
    105 }
    106 
    107 EmulatedCameraDevice* EmulatedQemuCamera::getCameraDevice() {
    108   return &mQemuCameraDevice;
    109 }
    110 
    111 }; /* namespace android */
    112