blob: 3d390e3134fdae232278451de3444f7c73c21b90 [file] [log] [blame]
Ari Hausman-Cohencb11a4d2016-09-19 17:57:37 -07001/*
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
Sergii Piatakov2ad591f2018-08-03 11:41:06 +030024#include <android-base/macros.h>
Sergii Piatakovb8f073f2018-10-10 17:22:10 +030025#include <hardware/camera3.h>
Ari Hausman-Cohencb11a4d2016-09-19 17:57:37 -070026#include "capture_request.h"
Ari Hausman-Cohencb11a4d2016-09-19 17:57:37 -070027
28namespace default_camera_hal {
29
30// Keep track of what requests and streams are in flight.
31class 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
Ari Hausman-Cohen0b2113c2016-10-03 13:43:13 -070047 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);
Ari Hausman-Cohencb11a4d2016-09-19 17:57:37 -070051 // Empty out all requests being tracked.
52 virtual void Clear(
Ari Hausman-Cohen0b2113c2016-10-03 13:43:13 -070053 std::set<std::shared_ptr<CaptureRequest>>* requests = nullptr);
Ari Hausman-Cohencb11a4d2016-09-19 17:57:37 -070054
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.
Ari Hausman-Cohen0b2113c2016-10-03 13:43:13 -070070 std::map<uint32_t, std::shared_ptr<CaptureRequest>> frames_in_flight_;
Ari Hausman-Cohencb11a4d2016-09-19 17:57:37 -070071
72 DISALLOW_COPY_AND_ASSIGN(RequestTracker);
73};
74
75} // namespace default_camera_hal
76
77#endif // DEFAULT_CAMERA_HAL_REQUEST_TRACKER_H_