• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef HARDWARE_GOOGLE_CAMERA_HAL_UTILS_TRACKED_PROFILER_H
17 #define HARDWARE_GOOGLE_CAMERA_HAL_UTILS_TRACKED_PROFILER_H
18 
19 #include <memory>
20 #include <mutex>
21 #include <string>
22 
23 #include "aidl_profiler.h"
24 #include "profiler.h"
25 #include "profiler_util.h"
26 
27 namespace android {
28 namespace google_camera_hal {
29 
30 using google::camera_common::Profiler;
31 
32 class TrackedProfiler {
33   /* Tracks the progress of a profiling operation (open, close,
34    * reconfiguration) by accepting or rejecting new AIDL events (open, flush,
35    * configure streams, first frame start, first frame end, or close)
36    */
37  public:
TrackedProfiler(std::shared_ptr<Profiler> profiler,std::string camera_id_string,EventType initial_state)38   TrackedProfiler(std::shared_ptr<Profiler> profiler,
39                   std::string camera_id_string, EventType initial_state)
40       : state_(initial_state),
41         profiler_(profiler),
42         camera_id_string_(camera_id_string){};
43 
44   void SetUseCase(std::string name);
45   bool ShouldDelete(EventType incoming);
46   void UpdateStateLocked(EventType incoming);
47   std::unique_ptr<android::google_camera_hal::AidlScopedProfiler>
48   AcceptNextState(EventType incoming);
49   bool AcceptFirstFrameStart();
50   bool AcceptFirstFrameEnd();
51   void DeleteProfilerLocked();
52   void DeleteProfiler();
53   void IdleStartLocked();
54   void IdleStart();
55   void IdleEndLocked();
56 
GetState()57   EventType GetState() {
58     return state_;
59   }
60 
61   std::mutex tracked_api_mutex_;
62   EventType state_ = EventType::kNone;
63   std::shared_ptr<Profiler> profiler_ = nullptr;
64   const std::string camera_id_string_;
65   uint8_t config_count_ = 0;
66   uint8_t flush_count_ = 0;
67   uint8_t idle_start_count_ = 0;
68   uint8_t idle_end_count_ = 0;
69 };
70 
71 }  // namespace google_camera_hal
72 }  // namespace android
73 
74 #endif  // HARDWARE_GOOGLE_CAMERA_HAL_UTILS_TRACKED_PROFILER_H
75