1 /*
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_CAMERAPROXY_H
18 #define ANDROID_AUTOMOTIVE_EVS_V1_0_CAMERAPROXY_H
19 
20 #include <android/hardware/automotive/evs/1.0/IEvsCamera.h>
21 #include <android/hardware/automotive/evs/1.0/types.h>
22 #include <ui/GraphicBuffer.h>
23 
24 #include <deque>
25 #include <thread>
26 
27 using namespace ::android::hardware::automotive::evs::V1_0;
28 using ::android::hardware::hidl_handle;
29 using ::android::hardware::Return;
30 using ::android::hardware::Void;
31 
32 namespace android {
33 namespace automotive {
34 namespace evs {
35 namespace V1_0 {
36 namespace implementation {
37 
38 class HalCamera;  // From HalCamera.h
39 
40 // This class represents an EVS camera to the client application.  As such it presents
41 // the IEvsCamera interface, and also proxies the frame delivery to the client's
42 // IEvsCameraStream object.
43 class VirtualCamera : public IEvsCamera {
44 public:
45     explicit VirtualCamera(sp<HalCamera> halCamera);
46     virtual ~VirtualCamera();
47     void shutdown();
48 
getHalCamera()49     sp<HalCamera> getHalCamera() { return mHalCamera; };
getAllowedBuffers()50     unsigned getAllowedBuffers() { return mFramesAllowed; };
isStreaming()51     bool isStreaming() { return mStreamState == RUNNING; }
52 
53     // Proxy to receive frames and forward them to the client's stream
54     bool deliverFrame(const BufferDesc& buffer);
55 
56     // Methods from ::android::hardware::automotive::evs::V1_0::IEvsCamera follow.
57     Return<void> getCameraInfo(getCameraInfo_cb _hidl_cb) override;
58     Return<EvsResult> setMaxFramesInFlight(uint32_t bufferCount) override;
59     Return<EvsResult> startVideoStream(const ::android::sp<IEvsCameraStream>& stream) override;
60     Return<void> doneWithFrame(const BufferDesc& buffer) override;
61     Return<void> stopVideoStream() override;
62     Return<int32_t> getExtendedInfo(uint32_t opaqueIdentifier) override;
63     Return<EvsResult> setExtendedInfo(uint32_t opaqueIdentifier, int32_t opaqueValue) override;
64 
65 private:
66     sp<HalCamera> mHalCamera;  // The low level camera interface that backs this proxy
67     sp<IEvsCameraStream> mStream;
68 
69     std::deque<BufferDesc> mFramesHeld;
70     unsigned mFramesAllowed = 1;
71     enum {
72         STOPPED,
73         RUNNING,
74         STOPPING,
75     } mStreamState = STOPPED;
76 };
77 
78 }  // namespace implementation
79 }  // namespace V1_0
80 }  // namespace evs
81 }  // namespace automotive
82 }  // namespace android
83 
84 #endif  // ANDROID_AUTOMOTIVE_EVS_V1_0_CAMERAPROXY_H
85