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