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 EmulatedFakeCamera that encapsulates
     19  * functionality of a fake camera.
     20  */
     21 
     22 #define LOG_NDEBUG 0
     23 #define LOG_TAG "EmulatedCamera_FakeCamera"
     24 #include "EmulatedFakeCamera.h"
     25 #include <log/log.h>
     26 #include <cutils/properties.h>
     27 #undef min
     28 #undef max
     29 #include <algorithm>
     30 #include <sstream>
     31 #include <string>
     32 #include "EmulatedCameraFactory.h"
     33 
     34 namespace android {
     35 
     36 EmulatedFakeCamera::EmulatedFakeCamera(int cameraId, bool facingBack,
     37                                        struct hw_module_t* module)
     38     : EmulatedCamera(cameraId, module),
     39       mFacingBack(facingBack),
     40       mFakeCameraDevice(this) {}
     41 
     42 EmulatedFakeCamera::~EmulatedFakeCamera() {}
     43 
     44 /****************************************************************************
     45  * Public API overrides
     46  ***************************************************************************/
     47 
     48 status_t EmulatedFakeCamera::Initialize(const cvd::CameraDefinition& params) {
     49   status_t res = mFakeCameraDevice.Initialize();
     50   if (res != NO_ERROR) {
     51     return res;
     52   }
     53 
     54   const char* facing =
     55       mFacingBack ? EmulatedCamera::FACING_BACK : EmulatedCamera::FACING_FRONT;
     56 
     57   mParameters.set(EmulatedCamera::FACING_KEY, facing);
     58   ALOGD("%s: Fake camera is facing %s", __FUNCTION__, facing);
     59 
     60   mParameters.set(EmulatedCamera::ORIENTATION_KEY,
     61                   EmulatedCameraFactory::Instance().getFakeCameraOrientation());
     62 
     63   res = EmulatedCamera::Initialize(params);
     64   if (res != NO_ERROR) {
     65     return res;
     66   }
     67 
     68   /*
     69    * Parameters provided by the camera device.
     70    */
     71 
     72   /* 352x288 and 320x240 frame dimensions are required by the framework for
     73    * video mode preview and video recording. */
     74   std::ostringstream resolutions;
     75   for (size_t index = 0; index < params.resolutions.size(); ++index) {
     76     if (resolutions.str().size()) {
     77       resolutions << ",";
     78     }
     79     resolutions << params.resolutions[index].width << "x"
     80                 << params.resolutions[index].height;
     81   }
     82 
     83   mParameters.set(CameraParameters::KEY_SUPPORTED_PICTURE_SIZES,
     84                   resolutions.str().c_str());
     85   mParameters.set(CameraParameters::KEY_SUPPORTED_PREVIEW_SIZES,
     86                   resolutions.str().c_str());
     87   mParameters.setPreviewSize(640, 480);
     88   mParameters.setPictureSize(640, 480);
     89 
     90   mParameters.set(CameraParameters::KEY_SUPPORTED_ANTIBANDING,
     91                   CameraParameters::ANTIBANDING_AUTO);
     92   mParameters.set(CameraParameters::KEY_ANTIBANDING,
     93                   CameraParameters::ANTIBANDING_AUTO);
     94   mParameters.set(CameraParameters::KEY_SUPPORTED_EFFECTS,
     95                   CameraParameters::EFFECT_NONE);
     96   mParameters.set(CameraParameters::KEY_EFFECT, CameraParameters::EFFECT_NONE);
     97 
     98   return NO_ERROR;
     99 }
    100 
    101 EmulatedCameraDevice* EmulatedFakeCamera::getCameraDevice() {
    102   return &mFakeCameraDevice;
    103 }
    104 
    105 }; /* namespace android */
    106