ronnie
2022-10-14 1504bb53e29d3d46222c0b3ea994fc494b48e153
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
 * Copyright (c) 2021 by Allwinnertech Co., Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
 
 
#ifndef DEFAULT_CAMERA_HAL_REQUEST_TRACKER_H_
#define DEFAULT_CAMERA_HAL_REQUEST_TRACKER_H_
 
#include <hardware/camera3.h>
 
#include <map>
#include <memory>
#include <set>
 
#include "capture_request.h"
#include "common.h"
 
namespace default_camera_hal {
 
// Keep track of what requests and streams are in flight.
class RequestTracker {
 public:
  RequestTracker();
  virtual ~RequestTracker();
 
  // Configuration methods. Both have undefined effects on in-flight requests,
  // and should only be called when empty.
  // Add configured streams. Replaces the previous configuration if any.
  virtual void SetStreamConfiguration(
      const camera3_stream_configuration_t& config);
  // Reset to no configured streams.
  virtual void ClearStreamConfiguration();
 
  // Tracking methods.
  // Track a request.
  // False if a request of the same frame number is already being tracked
  virtual bool Add(std::shared_ptr<CaptureRequest> request);
  // Stop tracking a request.
  // False if the given request is not being tracked.
  virtual bool Remove(std::shared_ptr<CaptureRequest> request = nullptr);
  // Empty out all requests being tracked.
  virtual void Clear(
      std::set<std::shared_ptr<CaptureRequest>>* requests = nullptr);
 
  // Accessors to check availability.
  // Check that a request isn't already in flight, and won't overflow any
  // streams.
  virtual bool CanAddRequest(const CaptureRequest& request) const;
  // True if the given stream is already at max capacity.
  virtual bool StreamFull(const camera3_stream_t* handle) const;
  // True if a request is being tracked for the given frame number.
  virtual bool InFlight(uint32_t frame_number) const;
  // True if no requests being tracked.
  virtual bool Empty() const;
 
 private:
  // Track for each stream, how many buffers are in flight.
  std::map<const camera3_stream_t*, size_t> buffers_in_flight_;
  // Track the frames in flight.
  std::map<uint32_t, std::shared_ptr<CaptureRequest>> frames_in_flight_;
 
  DISALLOW_COPY_AND_ASSIGN(RequestTracker);
};
 
}  // namespace default_camera_hal
 
#endif  // DEFAULT_CAMERA_HAL_REQUEST_TRACKER_H_