blob: ee91ca4cdade128b050a506f2c6d3af473ca80af [file] [log] [blame]
Scott Randolph83422792017-03-01 20:32:59 -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_AUTOMOTIVE_EVS_V1_0_EVSCAMERA_H
18#define ANDROID_HARDWARE_AUTOMOTIVE_EVS_V1_0_EVSCAMERA_H
19
20#include <android/hardware/automotive/evs/1.0/types.h>
21#include <android/hardware/automotive/evs/1.0/IEvsCamera.h>
22#include <ui/GraphicBuffer.h>
23
24#include <thread>
25
26
27namespace android {
28namespace hardware {
29namespace automotive {
30namespace evs {
31namespace V1_0 {
32namespace implementation {
33
34
35class EvsCamera : public IEvsCamera {
36public:
37 // Methods from ::android::hardware::automotive::evs::V1_0::IEvsCamera follow.
38 Return<void> getId(getId_cb id_cb) override;
39
40 Return <EvsResult> setMaxFramesInFlight(uint32_t bufferCount) override;
41
42 Return <EvsResult> startVideoStream(const ::android::sp<IEvsCameraStream>& stream) override;
43
44 Return<void> doneWithFrame(const BufferDesc& buffer) override;
45
46 Return<void> stopVideoStream() override;
47
48 Return <int32_t> getExtendedInfo(uint32_t opaqueIdentifier) override;
49
50 Return <EvsResult> setExtendedInfo(uint32_t opaqueIdentifier, int32_t opaqueValue) override;
51
52 // Implementation details
53 EvsCamera(const char* id);
54
55 virtual ~EvsCamera() override;
56
57 const CameraDesc& getDesc() { return mDescription; };
58
59 static const char kCameraName_Backup[];
60 static const char kCameraName_RightTurn[];
61
62private:
63 // These three functions are expected to be called while mAccessLock is held
64 bool setAvailableFrames_Locked(unsigned bufferCount);
65
66 unsigned increaseAvailableFrames_Locked(unsigned numToAdd);
67
68 unsigned decreaseAvailableFrames_Locked(unsigned numToRemove);
69
70 void generateFrames();
71
72 void fillTestFrame(const BufferDesc& buff);
73
74 CameraDesc mDescription = {}; // The properties of this camera
75
76 std::thread mCaptureThread; // The thread we'll use to synthesize frames
77
78 uint32_t mWidth = 0; // Horizontal pixel count in the buffers
79 uint32_t mHeight = 0; // Vertical pixel count in the buffers
80 uint32_t mFormat = 0; // Values from android_pixel_format_t [TODO: YUV? Leave opaque?]
81 uint32_t mUsage = 0; // Values from from Gralloc.h
82 uint32_t mStride = 0; // Bytes per line in the buffers
83
84 sp <IEvsCameraStream> mStream = nullptr; // The callback used to deliver each frame
85
86 struct BufferRecord {
87 buffer_handle_t handle;
88 bool inUse;
89
90 explicit BufferRecord(buffer_handle_t h) : handle(h), inUse(false) {};
91 };
92
93 std::vector <BufferRecord> mBuffers; // Graphics buffers to transfer images
94 unsigned mFramesAllowed; // How many buffers are we currently using
95 unsigned mFramesInUse; // How many buffers are currently outstanding
96
97 enum StreamStateValues {
98 STOPPED,
99 RUNNING,
100 STOPPING,
101 };
102 StreamStateValues mStreamState;
103
104 // Syncrhonization necessary to deconflict mCaptureThread from the main service thread
105 std::mutex mAccessLock;
106};
107
108} // namespace implementation
109} // namespace V1_0
110} // namespace evs
111} // namespace automotive
112} // namespace hardware
113} // namespace android
114
115#endif // ANDROID_HARDWARE_AUTOMOTIVE_EVS_V1_0_EVSCAMERA_H