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