Files
android_development/tools/emulator/system/camera/emulated_camera_common.h
Vladimir Chtchetkine b97c2f0b59 Fake camera implementation
The code submitted here builds a camera.goldfish.so module that encapsulates a camera HAL.

The major components of the camera HAL implementation are:
* Generic HAL module implemented in emulated_camera_hal.cpp There is nothing much
  to it: just exporting the required HAL header.
* EmulatedCameraFactory class that manages emulated cameras, and provides handling for
  camera_module_methods_ methods. There is only one object of this class, that is statically
  instantiated when camera.goldfish.so module is loaded.
* EmulatedCamera class that implements camera_device_ops_t API. Objects of this class are
  instantiated during EmulatedCameraFactory construction, and they interact with objects
  of EmulatedCameraDevice class to get frames.
* EmulatedCameraDevice class encapsulates an actual camera device. Objects of this class
  are contained in EmulatedCameraDevice objects, and interact with them as required by the
  API.

The fake camera implementation is shared between EmulatedFakeCamera, and EmulatedFakeCameraDevice
classes. They are pretty light. In fact, EmulatedFakeCamera is nothing more than just a
placeholder for EmulatedFakeCameraDevice instance, and EmulatedFakeCameraDevice does nothing
more, than just drawing a checker board with a bouncing square.

Other components / routines are minor: helpers, wrappers, etc. The code is heavily commented,
so there will be plenty of explanations between the lines.

Change-Id: I4463e14c255c6e3b1dcca17bed5f4efde32d9879
2011-09-12 08:37:48 -07:00

71 lines
2.0 KiB
C++

/*
* Copyright (C) 2011 The Android Open Source Project
*
* 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.
*/
#ifndef HW_EMULATOR_CAMERA_EMULATED_CAMERA_COMMON_H
#define HW_EMULATOR_CAMERA_EMULATED_CAMERA_COMMON_H
/*
* Contains common declarations that are used across the camera emulation.
*/
#include <linux/videodev2.h>
#include <hardware/camera.h>
/* A helper class that tracks a routine execution.
* Basically, it dumps an enry message in its constructor, and an exit message
* in its destructor. Use LOGRE() macro (declared bellow) to create instances
* of this class at the beginning of the tracked routines / methods.
*/
class HWERoutineTracker {
public:
/* Constructor that prints an "entry" trace message. */
explicit HWERoutineTracker(const char* name)
: name_(name) {
LOGV("Entering %s", name_);
}
/* Destructor that prints a "leave" trace message. */
~HWERoutineTracker() {
LOGV("Leaving %s", name_);
}
private:
/* Stores the routine name. */
const char* name_;
};
/* Logs an execution of a routine / method. */
#define LOGRE() HWERoutineTracker hwertracker_##__LINE__(__FUNCTION__)
static __inline__ void Sleep(int millisec)
{
if (millisec != 0) {
timeval to;
to.tv_sec = millisec / 1000;
to.tv_usec = (millisec % 1000) * 1000;
select(0, NULL, NULL, NULL, &to);
}
}
/*
* min / max macros
*/
#define min(a,b) (((a) < (b)) ? (a) : (b))
#define max(a,b) (((a) > (b)) ? (a) : (b))
#endif /* HW_EMULATOR_CAMERA_EMULATED_CAMERA_COMMON_H */