1 /* 2 * Copyright 2020 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 CPP_COMPUTEPIPE_TESTS_RUNNER_GRAPH_INCLUDES_PREBUILTENGINEINTERFACEIMPL_H_ 18 #define CPP_COMPUTEPIPE_TESTS_RUNNER_GRAPH_INCLUDES_PREBUILTENGINEINTERFACEIMPL_H_ 19 20 #include <string> 21 22 #include "ClientConfig.pb.h" 23 #include "LocalPrebuiltGraph.h" 24 #include "PrebuiltEngineInterface.h" 25 #include "ProfilingType.pb.h" 26 #include "RunnerComponent.h" 27 #include "gmock/gmock-matchers.h" 28 #include "gmock/gmock.h" 29 #include "gtest/gtest.h" 30 #include "types/Status.h" 31 32 namespace android { 33 namespace automotive { 34 namespace computepipe { 35 namespace graph { 36 37 // Barebones implementation of the PrebuiltEngineInterface. This implementation should suffice for 38 // basic cases. More complicated use cases might need their own implementation of it. 39 typedef std::function<void(int, int64_t, const runner::InputFrame&)> PixelCallback; 40 typedef std::function<void(int, int64_t, std::string&&)> SerializedStreamCallback; 41 typedef std::function<void(Status, std::string&&)> GraphTerminationCallback; 42 class PrebuiltEngineInterfaceImpl : public PrebuiltEngineInterface { 43 private: 44 PixelCallback mPixelCallbackFn; 45 SerializedStreamCallback mSerializedStreamCallbackFn; 46 GraphTerminationCallback mGraphTerminationCallbackFn; 47 48 public: 49 virtual ~PrebuiltEngineInterfaceImpl() = default; 50 DispatchPixelData(int streamId,int64_t timestamp,const runner::InputFrame & frame)51 void DispatchPixelData(int streamId, int64_t timestamp, 52 const runner::InputFrame& frame) override { 53 mPixelCallbackFn(streamId, timestamp, frame); 54 } 55 DispatchSerializedData(int streamId,int64_t timestamp,std::string && data)56 void DispatchSerializedData(int streamId, int64_t timestamp, std::string&& data) override { 57 mSerializedStreamCallbackFn(streamId, timestamp, std::move(data)); 58 } 59 DispatchGraphTerminationMessage(Status status,std::string && msg)60 void DispatchGraphTerminationMessage(Status status, std::string&& msg) override { 61 mGraphTerminationCallbackFn(status, std::move(msg)); 62 } 63 SetPixelCallback(PixelCallback callback)64 void SetPixelCallback(PixelCallback callback) { mPixelCallbackFn = callback; } 65 SetSerializedStreamCallback(SerializedStreamCallback callback)66 void SetSerializedStreamCallback(SerializedStreamCallback callback) { 67 mSerializedStreamCallbackFn = callback; 68 } 69 SetGraphTerminationCallback(GraphTerminationCallback callback)70 void SetGraphTerminationCallback(GraphTerminationCallback callback) { 71 mGraphTerminationCallbackFn = callback; 72 } 73 }; 74 75 } // namespace graph 76 } // namespace computepipe 77 } // namespace automotive 78 } // namespace android 79 80 #endif // CPP_COMPUTEPIPE_TESTS_RUNNER_GRAPH_INCLUDES_PREBUILTENGINEINTERFACEIMPL_H_ 81