133bda475286a625337ed184e7053fc29e403d57bVladimir Chtchetkine/*
233bda475286a625337ed184e7053fc29e403d57bVladimir Chtchetkine * Copyright (C) 2011 The Android Open Source Project
333bda475286a625337ed184e7053fc29e403d57bVladimir Chtchetkine *
433bda475286a625337ed184e7053fc29e403d57bVladimir Chtchetkine * Licensed under the Apache License, Version 2.0 (the "License");
533bda475286a625337ed184e7053fc29e403d57bVladimir Chtchetkine * you may not use this file except in compliance with the License.
633bda475286a625337ed184e7053fc29e403d57bVladimir Chtchetkine * You may obtain a copy of the License at
733bda475286a625337ed184e7053fc29e403d57bVladimir Chtchetkine *
833bda475286a625337ed184e7053fc29e403d57bVladimir Chtchetkine *      http://www.apache.org/licenses/LICENSE-2.0
933bda475286a625337ed184e7053fc29e403d57bVladimir Chtchetkine *
1033bda475286a625337ed184e7053fc29e403d57bVladimir Chtchetkine * Unless required by applicable law or agreed to in writing, software
1133bda475286a625337ed184e7053fc29e403d57bVladimir Chtchetkine * distributed under the License is distributed on an "AS IS" BASIS,
1233bda475286a625337ed184e7053fc29e403d57bVladimir Chtchetkine * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1333bda475286a625337ed184e7053fc29e403d57bVladimir Chtchetkine * See the License for the specific language governing permissions and
1433bda475286a625337ed184e7053fc29e403d57bVladimir Chtchetkine * limitations under the License.
1533bda475286a625337ed184e7053fc29e403d57bVladimir Chtchetkine */
1633bda475286a625337ed184e7053fc29e403d57bVladimir Chtchetkine
1733bda475286a625337ed184e7053fc29e403d57bVladimir Chtchetkine#ifndef HW_EMULATOR_CAMERA_EMULATED_QEMU_CAMERA_DEVICE_H
1833bda475286a625337ed184e7053fc29e403d57bVladimir Chtchetkine#define HW_EMULATOR_CAMERA_EMULATED_QEMU_CAMERA_DEVICE_H
1933bda475286a625337ed184e7053fc29e403d57bVladimir Chtchetkine
2033bda475286a625337ed184e7053fc29e403d57bVladimir Chtchetkine/*
2133bda475286a625337ed184e7053fc29e403d57bVladimir Chtchetkine * Contains declaration of a class EmulatedQemuCameraDevice that encapsulates
2233bda475286a625337ed184e7053fc29e403d57bVladimir Chtchetkine * an emulated camera device connected to the host.
2333bda475286a625337ed184e7053fc29e403d57bVladimir Chtchetkine */
2433bda475286a625337ed184e7053fc29e403d57bVladimir Chtchetkine
255467be2eefc007ebf09baf109dafe058abc1ffc5Vladimir Chtchetkine#include "EmulatedCameraDevice.h"
2633bda475286a625337ed184e7053fc29e403d57bVladimir Chtchetkine#include "QemuClient.h"
2733bda475286a625337ed184e7053fc29e403d57bVladimir Chtchetkine
2833bda475286a625337ed184e7053fc29e403d57bVladimir Chtchetkinenamespace android {
2933bda475286a625337ed184e7053fc29e403d57bVladimir Chtchetkine
3033bda475286a625337ed184e7053fc29e403d57bVladimir Chtchetkineclass EmulatedQemuCamera;
3133bda475286a625337ed184e7053fc29e403d57bVladimir Chtchetkine
3233bda475286a625337ed184e7053fc29e403d57bVladimir Chtchetkine/* Encapsulates an emulated camera device connected to the host.
3333bda475286a625337ed184e7053fc29e403d57bVladimir Chtchetkine */
3433bda475286a625337ed184e7053fc29e403d57bVladimir Chtchetkineclass EmulatedQemuCameraDevice : public EmulatedCameraDevice {
3533bda475286a625337ed184e7053fc29e403d57bVladimir Chtchetkinepublic:
3633bda475286a625337ed184e7053fc29e403d57bVladimir Chtchetkine    /* Constructs EmulatedQemuCameraDevice instance. */
3733bda475286a625337ed184e7053fc29e403d57bVladimir Chtchetkine    explicit EmulatedQemuCameraDevice(EmulatedQemuCamera* camera_hal);
3833bda475286a625337ed184e7053fc29e403d57bVladimir Chtchetkine
3933bda475286a625337ed184e7053fc29e403d57bVladimir Chtchetkine    /* Destructs EmulatedQemuCameraDevice instance. */
4033bda475286a625337ed184e7053fc29e403d57bVladimir Chtchetkine    ~EmulatedQemuCameraDevice();
4133bda475286a625337ed184e7053fc29e403d57bVladimir Chtchetkine
425467be2eefc007ebf09baf109dafe058abc1ffc5Vladimir Chtchetkine    /***************************************************************************
4333bda475286a625337ed184e7053fc29e403d57bVladimir Chtchetkine     * Public API
445467be2eefc007ebf09baf109dafe058abc1ffc5Vladimir Chtchetkine     **************************************************************************/
4533bda475286a625337ed184e7053fc29e403d57bVladimir Chtchetkine
4633bda475286a625337ed184e7053fc29e403d57bVladimir Chtchetkinepublic:
4733bda475286a625337ed184e7053fc29e403d57bVladimir Chtchetkine    /* Initializes EmulatedQemuCameraDevice instance.
4833bda475286a625337ed184e7053fc29e403d57bVladimir Chtchetkine     * Param:
4933bda475286a625337ed184e7053fc29e403d57bVladimir Chtchetkine     *  device_name - Name of the camera device connected to the host. The name
5033bda475286a625337ed184e7053fc29e403d57bVladimir Chtchetkine     *      that is used here must have been reported by the 'factory' camera
5133bda475286a625337ed184e7053fc29e403d57bVladimir Chtchetkine     *      service when it listed camera devices connected to the host.
5233bda475286a625337ed184e7053fc29e403d57bVladimir Chtchetkine     * Return:
5333bda475286a625337ed184e7053fc29e403d57bVladimir Chtchetkine     *  NO_ERROR on success, or an appropriate error status.
5433bda475286a625337ed184e7053fc29e403d57bVladimir Chtchetkine     */
5533bda475286a625337ed184e7053fc29e403d57bVladimir Chtchetkine    status_t Initialize(const char* device_name);
5633bda475286a625337ed184e7053fc29e403d57bVladimir Chtchetkine
575467be2eefc007ebf09baf109dafe058abc1ffc5Vladimir Chtchetkine    /***************************************************************************
5833bda475286a625337ed184e7053fc29e403d57bVladimir Chtchetkine     * Emulated camera device abstract interface implementation.
5933bda475286a625337ed184e7053fc29e403d57bVladimir Chtchetkine     * See declarations of these methods in EmulatedCameraDevice class for
6033bda475286a625337ed184e7053fc29e403d57bVladimir Chtchetkine     * information on each of these methods.
615467be2eefc007ebf09baf109dafe058abc1ffc5Vladimir Chtchetkine     **************************************************************************/
6233bda475286a625337ed184e7053fc29e403d57bVladimir Chtchetkine
6333bda475286a625337ed184e7053fc29e403d57bVladimir Chtchetkinepublic:
6433bda475286a625337ed184e7053fc29e403d57bVladimir Chtchetkine    /* Connects to the camera device. */
655467be2eefc007ebf09baf109dafe058abc1ffc5Vladimir Chtchetkine    status_t connectDevice();
6633bda475286a625337ed184e7053fc29e403d57bVladimir Chtchetkine
6733bda475286a625337ed184e7053fc29e403d57bVladimir Chtchetkine    /* Disconnects from the camera device. */
685467be2eefc007ebf09baf109dafe058abc1ffc5Vladimir Chtchetkine    status_t disconnectDevice();
6933bda475286a625337ed184e7053fc29e403d57bVladimir Chtchetkine
7033bda475286a625337ed184e7053fc29e403d57bVladimir Chtchetkine    /* Starts capturing frames from the camera device. */
7149842cee0549befb6d7a4353247190820037e1c4Vladimir Chtchetkine    status_t startDevice(int width, int height, uint32_t pix_fmt);
7233bda475286a625337ed184e7053fc29e403d57bVladimir Chtchetkine
7333bda475286a625337ed184e7053fc29e403d57bVladimir Chtchetkine    /* Stops capturing frames from the camera device. */
745467be2eefc007ebf09baf109dafe058abc1ffc5Vladimir Chtchetkine    status_t stopDevice();
7533bda475286a625337ed184e7053fc29e403d57bVladimir Chtchetkine
765467be2eefc007ebf09baf109dafe058abc1ffc5Vladimir Chtchetkine    /***************************************************************************
7733bda475286a625337ed184e7053fc29e403d57bVladimir Chtchetkine     * EmulatedCameraDevice virtual overrides
7849842cee0549befb6d7a4353247190820037e1c4Vladimir Chtchetkine     * See declarations of these methods in EmulatedCameraDevice class for
7949842cee0549befb6d7a4353247190820037e1c4Vladimir Chtchetkine     * information on each of these methods.
805467be2eefc007ebf09baf109dafe058abc1ffc5Vladimir Chtchetkine     **************************************************************************/
8133bda475286a625337ed184e7053fc29e403d57bVladimir Chtchetkine
8233bda475286a625337ed184e7053fc29e403d57bVladimir Chtchetkinepublic:
8333bda475286a625337ed184e7053fc29e403d57bVladimir Chtchetkine    /* Gets current preview fame into provided buffer.
8433bda475286a625337ed184e7053fc29e403d57bVladimir Chtchetkine     * We override this method in order to provide preview frames cached in this
8533bda475286a625337ed184e7053fc29e403d57bVladimir Chtchetkine     * object.
8633bda475286a625337ed184e7053fc29e403d57bVladimir Chtchetkine     */
875467be2eefc007ebf09baf109dafe058abc1ffc5Vladimir Chtchetkine    status_t getCurrentPreviewFrame(void* buffer);
8833bda475286a625337ed184e7053fc29e403d57bVladimir Chtchetkine
895467be2eefc007ebf09baf109dafe058abc1ffc5Vladimir Chtchetkine    /***************************************************************************
9033bda475286a625337ed184e7053fc29e403d57bVladimir Chtchetkine     * Worker thread management overrides.
9133bda475286a625337ed184e7053fc29e403d57bVladimir Chtchetkine     * See declarations of these methods in EmulatedCameraDevice class for
9233bda475286a625337ed184e7053fc29e403d57bVladimir Chtchetkine     * information on each of these methods.
935467be2eefc007ebf09baf109dafe058abc1ffc5Vladimir Chtchetkine     **************************************************************************/
9433bda475286a625337ed184e7053fc29e403d57bVladimir Chtchetkine
9533bda475286a625337ed184e7053fc29e403d57bVladimir Chtchetkineprotected:
9633bda475286a625337ed184e7053fc29e403d57bVladimir Chtchetkine    /* Implementation of the worker thread routine. */
975467be2eefc007ebf09baf109dafe058abc1ffc5Vladimir Chtchetkine    bool inWorkerThread();
9833bda475286a625337ed184e7053fc29e403d57bVladimir Chtchetkine
995467be2eefc007ebf09baf109dafe058abc1ffc5Vladimir Chtchetkine    /***************************************************************************
10033bda475286a625337ed184e7053fc29e403d57bVladimir Chtchetkine     * Qemu camera device data members
1015467be2eefc007ebf09baf109dafe058abc1ffc5Vladimir Chtchetkine     **************************************************************************/
10233bda475286a625337ed184e7053fc29e403d57bVladimir Chtchetkine
10333bda475286a625337ed184e7053fc29e403d57bVladimir Chtchetkineprivate:
1045467be2eefc007ebf09baf109dafe058abc1ffc5Vladimir Chtchetkine    /* Qemu client that is used to communicate with the 'emulated camera'
1055467be2eefc007ebf09baf109dafe058abc1ffc5Vladimir Chtchetkine     * service, created for this instance in the emulator. */
1065467be2eefc007ebf09baf109dafe058abc1ffc5Vladimir Chtchetkine    CameraQemuClient    mQemuClient;
10733bda475286a625337ed184e7053fc29e403d57bVladimir Chtchetkine
10833bda475286a625337ed184e7053fc29e403d57bVladimir Chtchetkine    /* Name of the camera device connected to the host. */
1095467be2eefc007ebf09baf109dafe058abc1ffc5Vladimir Chtchetkine    String8             mDeviceName;
11033bda475286a625337ed184e7053fc29e403d57bVladimir Chtchetkine
11133bda475286a625337ed184e7053fc29e403d57bVladimir Chtchetkine    /* Current preview framebuffer. */
11249842cee0549befb6d7a4353247190820037e1c4Vladimir Chtchetkine    uint32_t*           mPreviewFrame;
11333bda475286a625337ed184e7053fc29e403d57bVladimir Chtchetkine
11433bda475286a625337ed184e7053fc29e403d57bVladimir Chtchetkine    /* Emulated FPS (frames per second).
11533bda475286a625337ed184e7053fc29e403d57bVladimir Chtchetkine     * We will emulate 50 FPS. */
1165467be2eefc007ebf09baf109dafe058abc1ffc5Vladimir Chtchetkine    static const int    mEmulatedFPS = 50;
11733bda475286a625337ed184e7053fc29e403d57bVladimir Chtchetkine};
11833bda475286a625337ed184e7053fc29e403d57bVladimir Chtchetkine
11933bda475286a625337ed184e7053fc29e403d57bVladimir Chtchetkine}; /* namespace android */
12033bda475286a625337ed184e7053fc29e403d57bVladimir Chtchetkine
12133bda475286a625337ed184e7053fc29e403d57bVladimir Chtchetkine#endif  /* HW_EMULATOR_CAMERA_EMULATED_QEMU_CAMERA_DEVICE_H */
122