blob: 02a677cebb5be7f44acf4ef55d59002d44a3d4a8 [file] [log] [blame]
Scott Randolph5c99d852016-11-15 17:01:23 -08001/*
2 * Copyright (C) 2016 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#ifndef ANDROID_HARDWARE_EVS_V1_0_EVSCAMERA_H
18#define ANDROID_HARDWARE_EVS_V1_0_EVSCAMERA_H
19
20#include <android/hardware/evs/1.0/types.h>
21#include <android/hardware/evs/1.0/IEvsCamera.h>
22#include <ui/GraphicBuffer.h>
23
24#include <thread>
25
Scott Randolphdb5a5982017-01-23 12:35:05 -080026
Scott Randolph5c99d852016-11-15 17:01:23 -080027namespace android {
28namespace hardware {
29namespace evs {
30namespace V1_0 {
31namespace implementation {
32
Scott Randolphdb5a5982017-01-23 12:35:05 -080033
Scott Randolph5c99d852016-11-15 17:01:23 -080034class EvsCamera : public IEvsCamera {
35public:
36 // Methods from ::android::hardware::evs::V1_0::IEvsCamera follow.
37 Return<void> getId(getId_cb id_cb) override;
38 Return<EvsResult> setMaxFramesInFlight(uint32_t bufferCount) override;
39 Return<EvsResult> startVideoStream(const ::android::sp<IEvsCameraStream>& stream) override;
Scott Randolphdb5a5982017-01-23 12:35:05 -080040 Return<void> doneWithFrame(const BufferDesc& buffer) override;
Scott Randolph5c99d852016-11-15 17:01:23 -080041 Return<void> stopVideoStream() override;
42 Return<int32_t> getExtendedInfo(uint32_t opaqueIdentifier) override;
43 Return<EvsResult> setExtendedInfo(uint32_t opaqueIdentifier, int32_t opaqueValue) override;
44
45 // Implementation details
46 EvsCamera(const char* id);
47 virtual ~EvsCamera() override;
48
49 const CameraDesc& getDesc() { return mDescription; };
Scott Randolph5c99d852016-11-15 17:01:23 -080050
51 static const char kCameraName_Backup[];
52 static const char kCameraName_RightTurn[];
53
54private:
Scott Randolphdb5a5982017-01-23 12:35:05 -080055 // These three functions are expected to be called while mAccessLock is held
56 bool setAvailableFrames_Locked(unsigned bufferCount);
57 unsigned increaseAvailableFrames_Locked(unsigned numToAdd);
58 unsigned decreaseAvailableFrames_Locked(unsigned numToRemove);
Scott Randolph5c99d852016-11-15 17:01:23 -080059
Scott Randolphdb5a5982017-01-23 12:35:05 -080060 void generateFrames();
Scott Randolph9a773c72017-02-15 16:25:48 -080061 void fillTestFrame(const BufferDesc& buff);
Scott Randolph5c99d852016-11-15 17:01:23 -080062
Scott Randolphdb5a5982017-01-23 12:35:05 -080063 CameraDesc mDescription = {}; // The properties of this camera
Scott Randolph5c99d852016-11-15 17:01:23 -080064
Scott Randolphdb5a5982017-01-23 12:35:05 -080065 std::thread mCaptureThread; // The thread we'll use to synthesize frames
Scott Randolph5c99d852016-11-15 17:01:23 -080066
Scott Randolphdb5a5982017-01-23 12:35:05 -080067 uint32_t mWidth = 0; // Horizontal pixel count in the buffers
68 uint32_t mHeight = 0; // Vertical pixel count in the buffers
69 uint32_t mFormat = 0; // Values from android_pixel_format_t [TODO: YUV? Leave opaque?]
70 uint32_t mUsage = 0; // Values from from Gralloc.h
71 uint32_t mStride = 0; // Bytes per line in the buffers
72
73 sp<IEvsCameraStream> mStream = nullptr; // The callback used to deliver each frame
74
75 struct BufferRecord {
76 buffer_handle_t handle;
77 bool inUse;
78 explicit BufferRecord(buffer_handle_t h) : handle(h), inUse(false) {};
79 };
80 std::vector<BufferRecord> mBuffers; // Graphics buffers to transfer images
81 unsigned mFramesAllowed; // How many buffers are we currently using
82 unsigned mFramesInUse; // How many buffers are currently outstanding
Scott Randolph5c99d852016-11-15 17:01:23 -080083
84 enum StreamStateValues {
85 STOPPED,
86 RUNNING,
87 STOPPING,
88 };
Scott Randolphdb5a5982017-01-23 12:35:05 -080089 StreamStateValues mStreamState;
Scott Randolph5c99d852016-11-15 17:01:23 -080090
Scott Randolphdb5a5982017-01-23 12:35:05 -080091 // Syncrhonization necessary to deconflict mCaptureThread from the main service thread
92 std::mutex mAccessLock;
Scott Randolph5c99d852016-11-15 17:01:23 -080093};
94
95} // namespace implementation
96} // namespace V1_0
97} // namespace evs
98} // namespace hardware
99} // namespace android
100
101#endif // ANDROID_HARDWARE_EVS_V1_0_EVSCAMERA_H