1 // Copyright (C) 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 15 #ifndef COMPUTEPIPE_RUNNER_EVS_DISPLAY_MANAGER 16 #define COMPUTEPIPE_RUNNER_EVS_DISPLAY_MANAGER 17 18 #include <memory> 19 #include <mutex> 20 #include <thread> 21 22 #include "DebugDisplayManager.h" 23 #include "InputFrame.h" 24 #include "MemHandle.h" 25 #include "types/Status.h" 26 27 namespace android { 28 namespace automotive { 29 namespace computepipe { 30 namespace runner { 31 namespace debug_display_manager { 32 33 class EvsDisplayManager : public DebugDisplayManager { 34 public: 35 /* Override DebugDisplayManager methods */ 36 /* Send a frame to debug display. 37 * This is a non-blocking call. When the frame is ready to be freed, setFreePacketCallback() 38 * should be invoked. */ 39 Status setArgs(std::string displayManagerArgs) override; 40 Status displayFrame(const std::shared_ptr<MemHandle>& dataHandle) override; 41 /* Free the packet (represented by buffer id). */ 42 void setFreePacketCallback(std::function<Status (int bufferId)> freePacketCallback) override; 43 44 /* handle execution phase notification from Runner Engine */ 45 Status handleExecutionPhase(const RunnerEvent& e) override; 46 /* handle a stop with flushing semantics phase notification from the engine */ 47 Status handleStopWithFlushPhase(const RunnerEvent& e) override; 48 /* handle an immediate stop phase notification from the engine */ 49 Status handleStopImmediatePhase(const RunnerEvent& e) override; 50 /* handle an engine notification to return to reset state */ 51 Status handleResetPhase(const RunnerEvent& e) override; 52 53 ~EvsDisplayManager(); 54 55 private: 56 void threadFn(); 57 58 void stopThread(); 59 60 // Variables to remember displayId if set through arguments. 61 bool mOverrideDisplayId = false; 62 int mDisplayId; 63 64 std::thread mThread; 65 bool mStopThread = false; 66 67 // Lock for variables shared with the thread. 68 std::mutex mLock; 69 std::condition_variable mWait; 70 std::shared_ptr<MemHandle> mNextFrame = nullptr; 71 std::function<Status (int bufferId)> mFreePacketCallback = nullptr; 72 }; 73 74 } // namespace debug_display_manager 75 } // namespace runner 76 } // namespace computepipe 77 } // namespace automotive 78 } // namespace android 79 80 #endif // COMPUTEPIPE_RUNNER_EVS_DISPLAY_MANAGER 81