Scott Randolph | 5c99d85 | 2016-11-15 17:01:23 -0800 | [diff] [blame] | 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_HARDWARE_EVS_V1_0_EVSCAMERA_H |
| 18 | #define ANDROID_HARDWARE_EVS_V1_0_EVSCAMERA_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 | |
| 26 | namespace android { |
| 27 | namespace hardware { |
| 28 | namespace evs { |
| 29 | namespace V1_0 { |
| 30 | namespace implementation { |
| 31 | |
| 32 | class EvsCamera : public IEvsCamera { |
| 33 | public: |
| 34 | // Methods from ::android::hardware::evs::V1_0::IEvsCamera follow. |
| 35 | Return<void> getId(getId_cb id_cb) override; |
| 36 | Return<EvsResult> setMaxFramesInFlight(uint32_t bufferCount) override; |
| 37 | Return<EvsResult> startVideoStream(const ::android::sp<IEvsCameraStream>& stream) override; |
| 38 | Return<EvsResult> doneWithFrame(uint32_t frameId, const hidl_handle& bufferHandle) override; |
| 39 | Return<void> stopVideoStream() override; |
| 40 | Return<int32_t> getExtendedInfo(uint32_t opaqueIdentifier) override; |
| 41 | Return<EvsResult> setExtendedInfo(uint32_t opaqueIdentifier, int32_t opaqueValue) override; |
| 42 | |
| 43 | // Implementation details |
| 44 | EvsCamera(const char* id); |
| 45 | virtual ~EvsCamera() override; |
| 46 | |
| 47 | const CameraDesc& getDesc() { return mDescription; }; |
| 48 | void GenerateFrames(); |
| 49 | |
| 50 | static const char kCameraName_Backup[]; |
| 51 | static const char kCameraName_RightTurn[]; |
| 52 | |
| 53 | private: |
| 54 | CameraDesc mDescription = {}; // The properties of this camera |
| 55 | |
| 56 | buffer_handle_t mBuffer = nullptr; // A graphics buffer into which we'll store images |
| 57 | uint32_t mWidth = 0; // number of pixels across the buffer |
| 58 | uint32_t mHeight = 0; // number of pixels vertically in the buffer |
| 59 | uint32_t mStride = 0; // Bytes per line in the buffer |
| 60 | |
| 61 | sp<IEvsCameraStream> mStream = nullptr; // The callback the user expects when a frame is ready |
| 62 | |
| 63 | std::thread mCaptureThread; // The thread we'll use to synthesize frames |
| 64 | |
| 65 | uint32_t mFrameId; // A frame counter used to identify specific frames |
| 66 | |
| 67 | enum StreamStateValues { |
| 68 | STOPPED, |
| 69 | RUNNING, |
| 70 | STOPPING, |
| 71 | }; |
| 72 | StreamStateValues mStreamState; |
| 73 | bool mFrameBusy; // A flag telling us our one buffer is in use |
| 74 | |
| 75 | std::mutex mAccessLock; |
| 76 | }; |
| 77 | |
| 78 | } // namespace implementation |
| 79 | } // namespace V1_0 |
| 80 | } // namespace evs |
| 81 | } // namespace hardware |
| 82 | } // namespace android |
| 83 | |
| 84 | #endif // ANDROID_HARDWARE_EVS_V1_0_EVSCAMERA_H |