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 HARDWARE_GOOGLE_CAMERA_HAL_HIDL_SERVICE_HIDL_PROFILER_H_
18 #define HARDWARE_GOOGLE_CAMERA_HAL_HIDL_SERVICE_HIDL_PROFILER_H_
19 
20 #include <memory>
21 
22 #include "profiler.h"
23 
24 namespace android {
25 namespace hardware {
26 namespace camera {
27 namespace implementation {
28 
29 class HidlScopedProfiler {
30  public:
31   HidlScopedProfiler(std::shared_ptr<google::camera_common::Profiler> profiler,
32                      const std::string name, int id,
33                      std::function<void()> end_callback);
34 
35   ~HidlScopedProfiler();
36 
37  private:
38   std::shared_ptr<google::camera_common::Profiler> profiler_;
39   const std::string name_;
40   int id_;
41   std::function<void()> end_callback_;
42 };
43 
44 class HidlProfiler {
45  public:
46   enum class ScopedType {
47     kOpen,
48     kConfigureStream,
49     kFlush,
50     kClose,
51   };
52   virtual ~HidlProfiler() = default;
53 
54   static std::shared_ptr<HidlProfiler> Create(uint32_t camera_id);
55 
56   // Make a ScopedProfiler for given type.
57   virtual std::unique_ptr<HidlScopedProfiler> MakeScopedProfiler(
58       ScopedType type) = 0;
59 
60   // Call when first frame is requested.
61   virtual void FirstFrameStart() = 0;
62 
63   // Call when all bufer in first frame is received.
64   virtual void FirstFrameEnd() = 0;
65 
66   // Call to profile frame rate for each stream.
67   virtual void ProfileFrameRate(const std::string& name) = 0;
68 
69   // Give a customized latency profiler so that client side can intercept various calls.
70   virtual void SetLatencyProfiler(
71       std::unique_ptr<google::camera_common::Profiler> profiler) = 0;
72 
73   // Give a customized fps profiler so that client side can intercept various calls.
74   virtual void SetFpsProfiler(
75       std::unique_ptr<google::camera_common::Profiler> profiler) = 0;
76 
77   virtual uint32_t GetCameraId() const = 0;
78   virtual int32_t GetLatencyFlag() const = 0;
79   virtual int32_t GetFpsFlag() const = 0;
80 
81  protected:
82   HidlProfiler() = default;
83 };
84 
85 }  // namespace implementation
86 }  // namespace camera
87 }  // namespace hardware
88 }  // namespace android
89 
90 #endif  // HARDWARE_GOOGLE_CAMERA_HAL_HIDL_SERVICE_HIDL_PROFILER_H_
91