blob: 24574d272af4a3625a818a60cf66311a1d182358 [file] [log] [blame]
Changyeon Joc7deb562019-07-23 10:40:04 -07001/*
2 * Copyright (C) 2019 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_AUTOMOTIVE_EVS_V1_1_HALCAMERA_H
18#define ANDROID_AUTOMOTIVE_EVS_V1_1_HALCAMERA_H
19
20#include <android/hardware/automotive/evs/1.1/types.h>
21#include <android/hardware/automotive/evs/1.1/IEvsCamera.h>
22#include <android/hardware/automotive/evs/1.1/IEvsCameraStream.h>
23#include <ui/GraphicBuffer.h>
24
25#include <thread>
26#include <list>
27
28
29using namespace ::android::hardware::automotive::evs::V1_1;
30using ::android::hardware::Return;
31using ::android::hardware::hidl_handle;
32using ::android::hardware::automotive::evs::V1_0::EvsResult;
33using IEvsCamera_1_0 = ::android::hardware::automotive::evs::V1_0::IEvsCamera;
34using IEvsCamera_1_1 = ::android::hardware::automotive::evs::V1_1::IEvsCamera;
35using BufferDesc_1_0 = ::android::hardware::automotive::evs::V1_0::BufferDesc;
36using BufferDesc_1_1 = ::android::hardware::automotive::evs::V1_1::BufferDesc;
37using IEvsCameraStream_1_0 = ::android::hardware::automotive::evs::V1_0::IEvsCameraStream;
38using IEvsCameraStream_1_1 = ::android::hardware::automotive::evs::V1_1::IEvsCameraStream;
39
40namespace android {
41namespace automotive {
42namespace evs {
43namespace V1_1 {
44namespace implementation {
45
46
47class VirtualCamera; // From VirtualCamera.h
48
49
50// This class wraps the actual hardware IEvsCamera objects. There is a one to many
51// relationship between instances of this class and instances of the VirtualCamera class.
52// This class implements the IEvsCameraStream interface so that it can receive the video
53// stream from the hardware camera and distribute it to the associated VirtualCamera objects.
54class HalCamera : public IEvsCameraStream_1_1 {
55public:
56 HalCamera(sp<IEvsCamera_1_1> hwCamera) : mHwCamera(hwCamera) {};
57
58 // Factory methods for client VirtualCameras
59 sp<VirtualCamera> makeVirtualCamera();
60 void disownVirtualCamera(sp<VirtualCamera> virtualCamera);
61
62 // Implementation details
63 sp<IEvsCamera_1_0> getHwCamera() { return mHwCamera; };
64 unsigned getClientCount() { return mClients.size(); };
65 bool changeFramesInFlight(int delta);
66
67 Return<EvsResult> clientStreamStarting();
68 void clientStreamEnding();
69 Return<void> doneWithFrame(const BufferDesc_1_0& buffer);
70 Return<void> doneWithFrame(const BufferDesc_1_1& buffer);
Changyeon Jo330d1c22019-07-30 11:58:41 -070071 Return<EvsResult> setMaster(sp<VirtualCamera> virtualCamera);
72 Return<EvsResult> unsetMaster(sp<VirtualCamera> virtualCamera);
73 Return<EvsResult> setParameter(sp<VirtualCamera> virtualCamera,
74 CameraParam id, int32_t& value);
75 Return<EvsResult> getParameter(CameraParam id, int32_t& value);
Changyeon Joc7deb562019-07-23 10:40:04 -070076
77 // Methods from ::android::hardware::automotive::evs::V1_1::IEvsCameraStream follow.
78 Return<void> deliverFrame(const BufferDesc_1_0& buffer) override;
79 Return<void> notifyEvent(const EvsEvent& event) override;
80
81private:
82 sp<IEvsCamera_1_1> mHwCamera;
83 std::list<wp<VirtualCamera>> mClients; // Weak pointers -> objects destruct if client dies
84
85 enum {
86 STOPPED,
87 RUNNING,
88 STOPPING,
89 } mStreamState = STOPPED;
90
91 struct FrameRecord {
92 uint32_t frameId;
93 uint32_t refCount;
94 FrameRecord(uint32_t id) : frameId(id), refCount(0) {};
95 };
96 std::vector<FrameRecord> mFrames;
Changyeon Jo330d1c22019-07-30 11:58:41 -070097 wp<VirtualCamera> mMaster = nullptr;
Changyeon Joc7deb562019-07-23 10:40:04 -070098};
99
100} // namespace implementation
101} // namespace V1_1
102} // namespace evs
103} // namespace automotive
104} // namespace android
105
106#endif // ANDROID_AUTOMOTIVE_EVS_V1_1_HALCAMERA_H