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 DEFAULT_CAMERA_HAL_REQUEST_TRACKER_H_ 18 #define DEFAULT_CAMERA_HAL_REQUEST_TRACKER_H_ 19 20 #include <map> 21 #include <memory> 22 #include <set> 23 24 #include <hardware/camera3.h> 25 26 #include "capture_request.h" 27 #include "common.h" 28 29 namespace default_camera_hal { 30 31 // Keep track of what requests and streams are in flight. 32 class RequestTracker { 33 public: 34 RequestTracker(); 35 virtual ~RequestTracker(); 36 37 // Configuration methods. Both have undefined effects on in-flight requests, 38 // and should only be called when empty. 39 // Add configured streams. Replaces the previous configuration if any. 40 virtual void SetStreamConfiguration( 41 const camera3_stream_configuration_t& config); 42 // Reset to no configured streams. 43 virtual void ClearStreamConfiguration(); 44 45 // Tracking methods. 46 // Track a request. 47 // False if a request of the same frame number is already being tracked 48 virtual bool Add(std::shared_ptr<CaptureRequest> request); 49 // Stop tracking a request. 50 // False if the given request is not being tracked. 51 virtual bool Remove(std::shared_ptr<CaptureRequest> request = nullptr); 52 // Empty out all requests being tracked. 53 virtual void Clear( 54 std::set<std::shared_ptr<CaptureRequest>>* requests = nullptr); 55 56 // Accessors to check availability. 57 // Check that a request isn't already in flight, and won't overflow any 58 // streams. 59 virtual bool CanAddRequest(const CaptureRequest& request) const; 60 // True if the given stream is already at max capacity. 61 virtual bool StreamFull(const camera3_stream_t* handle) const; 62 // True if a request is being tracked for the given frame number. 63 virtual bool InFlight(uint32_t frame_number) const; 64 // True if no requests being tracked. 65 virtual bool Empty() const; 66 67 private: 68 // Track for each stream, how many buffers are in flight. 69 std::map<const camera3_stream_t*, size_t> buffers_in_flight_; 70 // Track the frames in flight. 71 std::map<uint32_t, std::shared_ptr<CaptureRequest>> frames_in_flight_; 72 73 DISALLOW_COPY_AND_ASSIGN(RequestTracker); 74 }; 75 76 } // namespace default_camera_hal 77 78 #endif // DEFAULT_CAMERA_HAL_REQUEST_TRACKER_H_ 79