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 ~SetErrorInterface()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 // Return the removed buffer ID if input cache is found. 54 // Otherwise return BUFFER_ID_NO_BUFFER 55 virtual uint64_t removeOneBufferCache(int streamId, const native_handle_t* handle) = 0; 56 57 // Find a buffer_handle_t based on frame number and stream ID 58 virtual status_t popInflightBuffer(int32_t frameNumber, int32_t streamId, 59 /*out*/ buffer_handle_t **buffer) = 0; 60 61 // Register a bufId (streamId, buffer_handle_t) to inflight request buffer 62 virtual status_t pushInflightRequestBuffer( 63 uint64_t bufferId, buffer_handle_t* buf, int32_t streamId) = 0; 64 65 // Find a buffer_handle_t based on bufferId 66 virtual status_t popInflightRequestBuffer(uint64_t bufferId, 67 /*out*/ buffer_handle_t** buffer, 68 /*optional out*/ int32_t* streamId = nullptr) = 0; 69 ~BufferRecordsInterface()70 virtual ~BufferRecordsInterface() {} 71 }; 72 73 class InflightRequestUpdateInterface { 74 public: 75 // Caller must hold the lock proctecting InflightRequestMap 76 // duration: the maxExpectedDuration of the removed entry 77 virtual void onInflightEntryRemovedLocked(nsecs_t duration) = 0; 78 79 virtual void checkInflightMapLengthLocked() = 0; 80 81 virtual void onInflightMapFlushedLocked() = 0; 82 ~InflightRequestUpdateInterface()83 virtual ~InflightRequestUpdateInterface() {} 84 }; 85 86 class RequestBufferInterface { 87 public: 88 // Return if the state machine currently allows for requestBuffers. 89 // If this returns true, caller must call endRequestBuffer() later to signal end of a 90 // request buffer transaction. 91 virtual bool startRequestBuffer() = 0; 92 93 virtual void endRequestBuffer() = 0; 94 95 // Returns how long should implementation wait for a buffer returned 96 virtual nsecs_t getWaitDuration() = 0; 97 ~RequestBufferInterface()98 virtual ~RequestBufferInterface() {} 99 }; 100 101 class FlushBufferInterface { 102 public: 103 virtual void getInflightBufferKeys(std::vector<std::pair<int32_t, int32_t>>* out) = 0; 104 105 virtual void getInflightRequestBufferKeys(std::vector<uint64_t>* out) = 0; 106 107 virtual std::vector<sp<Camera3StreamInterface>> getAllStreams() = 0; 108 ~FlushBufferInterface()109 virtual ~FlushBufferInterface() {} 110 }; 111 } // namespace camera3 112 113 } // namespace android 114 115 #endif 116