blob: b719de14ccd5d4cf5adcedeedf6a001a99556a8b [file] [log] [blame]
Scott Randolphdcc35342017-01-19 13:33:42 -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_AUTOMOTIVE_EVS_V1_0_HALCAMERA_H
18#define ANDROID_AUTOMOTIVE_EVS_V1_0_HALCAMERA_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#include <list>
26
27using namespace ::android::hardware::evs::V1_0;
28using ::android::hardware::Return;
29using ::android::hardware::hidl_handle;
30
31namespace android {
32namespace automotive {
33namespace evs {
34namespace V1_0 {
35namespace implementation {
36
37
38// From VirtualCamera.h
39class VirtualCamera;
40
41
42// This class wraps the actual hardware IEvsCamera objects. There is a one to many
43// relationship between instances of this class and instances of the VirtualCamera class.
44// This class implements the IEvsCameraStream interface so that it can receive the video
45// stream from the hardware camera and distribute it to the associated VirtualCamera objects.
46class HalCamera : public IEvsCameraStream {
47public:
48 HalCamera(sp<IEvsCamera> hwCamera) : mHwCamera(hwCamera) {};
49
50 // Factory methods for client VirtualCameras
51 sp<VirtualCamera> makeVirtualCamera();
52 void disownVirtualCamera(sp<VirtualCamera> virtualCamera);
53
54 // Implementation details
55 sp<IEvsCamera> getHwCamera() { return mHwCamera; };
56 unsigned getClientCount() { return mClients.size(); };
57 bool changeFramesInFlight(int delta);
58
59 Return<EvsResult> clientStreamStarting();
60 void clientStreamEnding();
61 Return<void> doneWithFrame(const BufferDesc& buffer);
62
63 // Methods from ::android::hardware::evs::V1_0::ICarCameraStream follow.
64 Return<void> deliverFrame(const BufferDesc& buffer) override;
65
66private:
67 sp<IEvsCamera> mHwCamera;
Scott Randolph29803802017-01-25 13:11:51 -080068 std::list<wp<VirtualCamera>> mClients; // Weak pointers -> objects destruct if client dies
Scott Randolphdcc35342017-01-19 13:33:42 -080069
70 enum {
71 STOPPED,
72 RUNNING,
73 STOPPING,
74 } mStreamState = STOPPED;
75
76 struct FrameRecord {
77 uint32_t frameId;
78 uint32_t refCount;
79 FrameRecord(uint32_t id) : frameId(id), refCount(0) {};
80 };
81 std::vector<FrameRecord> mFrames;
82};
83
84} // namespace implementation
85} // namespace V1_0
86} // namespace evs
87} // namespace automotive
88} // namespace android
89
90#endif // ANDROID_AUTOMOTIVE_EVS_V1_0_HALCAMERA_H