Yin-Chia Yeh | 5fd603e | 2019-11-20 11:22:27 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2019 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_SERVERS_CAMERA3_OUTPUT_INTERFACE_H |
| 18 | #define ANDROID_SERVERS_CAMERA3_OUTPUT_INTERFACE_H |
| 19 | |
| 20 | #include <memory> |
| 21 | |
| 22 | #include <cutils/native_handle.h> |
| 23 | |
| 24 | #include <utils/Timers.h> |
| 25 | |
| 26 | #include "device3/Camera3StreamInterface.h" |
| 27 | |
| 28 | namespace android { |
| 29 | |
| 30 | namespace camera3 { |
| 31 | |
| 32 | /** |
| 33 | * Interfaces used by result/notification path shared between Camera3Device and |
| 34 | * Camera3OfflineSession |
| 35 | */ |
| 36 | class SetErrorInterface { |
| 37 | public: |
| 38 | // Switch device into error state and send a ERROR_DEVICE notification |
| 39 | virtual void setErrorState(const char *fmt, ...) = 0; |
| 40 | // Same as setErrorState except this method assumes callers holds the main object lock |
| 41 | virtual void setErrorStateLocked(const char *fmt, ...) = 0; |
| 42 | |
| 43 | virtual ~SetErrorInterface() {} |
| 44 | }; |
| 45 | |
| 46 | // Interface used by callback path to update buffer records |
| 47 | class BufferRecordsInterface { |
| 48 | public: |
| 49 | // method to extract buffer's unique ID |
| 50 | // return pair of (newlySeenBuffer?, bufferId) |
| 51 | virtual std::pair<bool, uint64_t> getBufferId(const buffer_handle_t& buf, int streamId) = 0; |
| 52 | |
| 53 | // Find a buffer_handle_t based on frame number and stream ID |
| 54 | virtual status_t popInflightBuffer(int32_t frameNumber, int32_t streamId, |
| 55 | /*out*/ buffer_handle_t **buffer) = 0; |
| 56 | |
| 57 | // Register a bufId (streamId, buffer_handle_t) to inflight request buffer |
| 58 | virtual status_t pushInflightRequestBuffer( |
| 59 | uint64_t bufferId, buffer_handle_t* buf, int32_t streamId) = 0; |
| 60 | |
| 61 | // Find a buffer_handle_t based on bufferId |
| 62 | virtual status_t popInflightRequestBuffer(uint64_t bufferId, |
| 63 | /*out*/ buffer_handle_t** buffer, |
| 64 | /*optional out*/ int32_t* streamId = nullptr) = 0; |
| 65 | |
| 66 | virtual ~BufferRecordsInterface() {} |
| 67 | }; |
| 68 | |
| 69 | class InflightRequestUpdateInterface { |
| 70 | public: |
| 71 | // Caller must hold the lock proctecting InflightRequestMap |
| 72 | // duration: the maxExpectedDuration of the removed entry |
| 73 | virtual void onInflightEntryRemovedLocked(nsecs_t duration) = 0; |
| 74 | |
| 75 | virtual void checkInflightMapLengthLocked() = 0; |
| 76 | |
| 77 | virtual void onInflightMapFlushedLocked() = 0; |
| 78 | |
| 79 | virtual ~InflightRequestUpdateInterface() {} |
| 80 | }; |
| 81 | |
| 82 | class RequestBufferInterface { |
| 83 | public: |
| 84 | // Return if the state machine currently allows for requestBuffers. |
| 85 | // If this returns true, caller must call endRequestBuffer() later to signal end of a |
| 86 | // request buffer transaction. |
| 87 | virtual bool startRequestBuffer() = 0; |
| 88 | |
| 89 | virtual void endRequestBuffer() = 0; |
| 90 | |
| 91 | // Returns how long should implementation wait for a buffer returned |
| 92 | virtual nsecs_t getWaitDuration() = 0; |
| 93 | |
| 94 | virtual ~RequestBufferInterface() {} |
| 95 | }; |
| 96 | |
| 97 | class FlushBufferInterface { |
| 98 | public: |
| 99 | virtual void getInflightBufferKeys(std::vector<std::pair<int32_t, int32_t>>* out) = 0; |
| 100 | |
| 101 | virtual void getInflightRequestBufferKeys(std::vector<uint64_t>* out) = 0; |
| 102 | |
| 103 | virtual std::vector<sp<Camera3StreamInterface>> getAllStreams() = 0; |
| 104 | |
| 105 | virtual ~FlushBufferInterface() {} |
| 106 | }; |
| 107 | } // namespace camera3 |
| 108 | |
| 109 | } // namespace android |
| 110 | |
| 111 | #endif |