blob: 60fd4734cb8406bfa71c5d21ae6adfd46cb60f3c [file] [log] [blame]
Hanumant Singhb0170002020-01-19 17:19:33 -08001// Copyright 2020 The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14#ifndef COMPUTEPIPE_EXAMPLE_FACE_TRACKER_H
15#define COMPUTEPIPE_EXAMPLE_FACE_TRACKER_H
16
17#include <aidl/android/automotive/computepipe/registry/BnClientInfo.h>
18#include <aidl/android/automotive/computepipe/registry/IPipeQuery.h>
19#include <aidl/android/automotive/computepipe/registry/IPipeRegistration.h>
20#include <aidl/android/automotive/computepipe/runner/BnPipeStateCallback.h>
21#include <aidl/android/automotive/computepipe/runner/BnPipeStream.h>
22#include <aidl/android/automotive/computepipe/runner/PipeState.h>
23
24#include <condition_variable>
25#include <iostream>
26#include <memory>
27
28#include "FaceOutput.pb.h"
29
30namespace android {
31namespace automotive {
32namespace computepipe {
33
34using ::aidl::android::automotive::computepipe::registry::BnClientInfo;
35using ::aidl::android::automotive::computepipe::registry::IPipeQuery;
36using ::aidl::android::automotive::computepipe::runner::BnPipeStateCallback;
37using ::aidl::android::automotive::computepipe::runner::BnPipeStream;
38using ::aidl::android::automotive::computepipe::runner::IPipeRunner;
39using ::aidl::android::automotive::computepipe::runner::IPipeStream;
40using ::aidl::android::automotive::computepipe::runner::PacketDescriptor;
41using ::aidl::android::automotive::computepipe::runner::PipeState;
42using ::android::automotive::computepipe::example::BoundingBox;
43
44class RemoteState {
45 public:
46 explicit RemoteState(std::function<void(bool, std::string)>& cb);
47 PipeState GetCurrentState();
48 void UpdateCurrentState(const PipeState& state);
49
50 private:
51 bool hasChanged = false;
52 PipeState mState = PipeState::RESET;
53 std::mutex mStateLock;
54 std::condition_variable mWait;
55 std::function<void(bool, std::string)> mTerminationCb;
56};
57
58class ClientInfo : public BnClientInfo {
59 public:
Hanumant Singh523fe112020-01-21 15:17:55 -080060 ndk::ScopedAStatus getClientName(std::string* _aidl_return) override {
Hanumant Singhb0170002020-01-19 17:19:33 -080061 if (_aidl_return) {
Hanumant Singh523fe112020-01-21 15:17:55 -080062 *_aidl_return = "FaceTrackerClient";
Hanumant Singhb0170002020-01-19 17:19:33 -080063 return ndk::ScopedAStatus::ok();
64 }
65 return ndk::ScopedAStatus::fromExceptionCode(EX_TRANSACTION_FAILED);
66 }
67};
68
69class StreamCallback : public BnPipeStream {
70 public:
71 StreamCallback() = default;
72 ndk::ScopedAStatus deliverPacket(const PacketDescriptor& in_packet) override;
73
74 private:
75 BoundingBox mLastBox;
76};
77
78class StateCallback : public BnPipeStateCallback {
79 public:
80 explicit StateCallback(std::shared_ptr<RemoteState> s);
81 ndk::ScopedAStatus handleState(PipeState state) override;
82
83 private:
84 std::shared_ptr<RemoteState> mStateTracker = nullptr;
85};
86
87class FaceTracker {
88 public:
89 FaceTracker() = default;
90 ndk::ScopedAStatus init(std::function<void(bool, std::string)>&& termination);
91 void start();
92 void stop();
93
94 private:
95 ndk::ScopedAStatus setupConfig();
96 std::shared_ptr<IPipeRunner> mPipeRunner = nullptr;
97 std::shared_ptr<ClientInfo> mClientInfo = nullptr;
98 std::shared_ptr<StreamCallback> mStreamCallback = nullptr;
99 std::shared_ptr<StateCallback> mStateCallback = nullptr;
100 std::shared_ptr<RemoteState> mRemoteState = nullptr;
101};
102
103} // namespace computepipe
104} // namespace automotive
105} // namespace android
106#endif