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 CAR_EVS_APP_STREAMHANDLER_H
18 #define CAR_EVS_APP_STREAMHANDLER_H
19 
20 #include <android/hardware/automotive/evs/1.0/IEvsCameraStream.h>
21 #include <android/hardware/automotive/evs/1.0/IEvsCamera.h>
22 #include <android/hardware/automotive/evs/1.0/IEvsDisplay.h>
23 
24 using namespace ::android::hardware::automotive::evs::V1_0;
25 using ::android::hardware::Return;
26 using ::android::hardware::Void;
27 using ::android::hardware::hidl_vec;
28 using ::android::hardware::hidl_handle;
29 using ::android::sp;
30 
31 
32 class StreamHandler : public IEvsCameraStream {
33 public:
34     StreamHandler(android::sp <IEvsCamera>  pCamera,
35                   android::sp <IEvsDisplay> pDisplay);
36 
37     void startStream();
38     void asyncStopStream();
39     void blockingStopStream();
40 
41     bool isRunning();
42 
43     unsigned getFramesReceived();
44     unsigned getFramesCompleted();
45 
46 private:
47     // Implementation for ::android::hardware::automotive::evs::V1_0::ICarCameraStream
48     Return<void> deliverFrame(const BufferDesc& buffer)  override;
49 
50     // Local implementation details
51     bool copyBufferContents(const BufferDesc& tgtBuffer, const BufferDesc& srcBuffer);
52 
53     android::sp <IEvsCamera>    mCamera;
54     android::sp <IEvsDisplay>   mDisplay;
55 
56     std::mutex                  mLock;
57     std::condition_variable     mSignal;
58 
59     bool                        mRunning = false;
60 
61     unsigned                    mFramesReceived = 0;    // Simple counter -- rolls over eventually!
62     unsigned                    mFramesCompleted = 0;   // Simple counter -- rolls over eventually!
63 };
64 
65 
66 #endif //CAR_EVS_APP_STREAMHANDLER_H
67