From 23a734ce8ee5f723dc6297425f78e5860ca47e7c Mon Sep 17 00:00:00 2001 From: Chris Date: Sat, 10 Apr 2021 20:25:04 -0400 Subject: [PATCH] workaround for backup camera switching. Make video work on firmware 70.00.100 --- CMakeLists.txt | 3 +- include/autoapp/Managers/VideoManager.hpp | 40 +++++++++++++++++++ include/autoapp/Projection/GSTVideoOutput.hpp | 2 + src/autoapp/Managers/VideoManager.cpp | 4 ++ src/autoapp/Projection/GSTVideoOutput.cpp | 27 +++++++++++++ 5 files changed, 75 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b8e8ab31..4e331821 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -130,7 +130,8 @@ add_executable(autoapp "Mazda/Dbus/com.jci.lds.data.h" "Mazda/Dbus/com.jci.navi2IHU.HUDSettings.h" "Mazda/Dbus/com.jci.vbs.navi.tmc.h" - "Mazda/Dbus/com.jci.vbs.navi.h") + "Mazda/Dbus/com.jci.vbs.navi.h" + "Mazda/Dbus/com.jci.nativeguictrl.h") target_include_directories(autoapp PUBLIC ${CMAKE_CURRENT_BINARY_DIR}/generated/) target_include_directories(autoapp PRIVATE ${include_directory}) diff --git a/include/autoapp/Managers/VideoManager.hpp b/include/autoapp/Managers/VideoManager.hpp index d7c953e9..70f9f86a 100644 --- a/include/autoapp/Managers/VideoManager.hpp +++ b/include/autoapp/Managers/VideoManager.hpp @@ -7,6 +7,45 @@ #include #include +#include + +class NativeGUICtrlClient final : public sdbus::ProxyInterfaces { + public: + NativeGUICtrlClient(std::unique_ptr &connection, std::string destination, std::string objectPath) + : sdbus::ProxyInterfaces(std::move(connection), + std::move(destination), + std::move(objectPath)) { + registerProxy(); + } + + ~NativeGUICtrlClient() { + unregisterProxy(); + } + + enum SURFACES { + NNG_NAVI_ID = 0, + TV_TOUCH_SURFACE = 1, + NATGUI_SURFACE = 2, + LOOPLOGO_SURFACE = 3, + TRANLOGOEND_SURFACE = 4, + TRANLOGO_SURFACE = 5, + QUICKTRANLOGO_SURFACE = 6, + EXITLOGO_SURFACE = 8, + JCI_OPERA_PRIMARY = 9, + JCI_OPERA_SECONDARY = 10, + lvdsSurface = 11, + SCREENREP_IVI_NAME = 12, + NNG_NAVI_MAP1 = 13, + NNG_NAVI_MAP2 = 14, + NNG_NAVI_HMI = 15, + NNG_NAVI_TWN = 16, + }; + + void SetRequiredSurfacesByEnum(const int surface, bool fadeOpera) { + SetRequiredSurfaces(std::to_string(surface), static_cast(fadeOpera ? 1 : 0)); + } +}; + class VideoManager { private: std::unique_ptr bucpsa; @@ -16,6 +55,7 @@ class VideoManager { sigc::connection releaseFocusConnection; bool currentDisplayMode; bool hasFocus = false; + NativeGUICtrlClient *gui; public: explicit VideoManager(VideoSignals::Pointer videosignals); diff --git a/include/autoapp/Projection/GSTVideoOutput.hpp b/include/autoapp/Projection/GSTVideoOutput.hpp index 45600277..8ee268f5 100644 --- a/include/autoapp/Projection/GSTVideoOutput.hpp +++ b/include/autoapp/Projection/GSTVideoOutput.hpp @@ -44,9 +44,11 @@ class GSTVideoOutput : public IVideoOutput { int p_stdin[2]{}, p_stdout[2]{}; asio::streambuf buffer; asio::posix::stream_descriptor *sd = nullptr; + bool running; void message_handler(asio::error_code ec, size_t bytes_transferred); void spawn_gst(); + int CheckReverse(); }; } diff --git a/src/autoapp/Managers/VideoManager.cpp b/src/autoapp/Managers/VideoManager.cpp index 9d595f0c..c5c5074d 100644 --- a/src/autoapp/Managers/VideoManager.cpp +++ b/src/autoapp/Managers/VideoManager.cpp @@ -3,6 +3,8 @@ VideoManager::VideoManager(VideoSignals::Pointer videosignals) : vs(std::move(videosignals)) { + auto guiConnection = sdbus::createSessionBusConnection(); + gui = new NativeGUICtrlClient(guiConnection, "com.jci.nativeguictrl", "/com/jci/nativeguictrl"); auto bucpsaConnection = sdbus::createSessionBusConnection(); bucpsa = sdbus::createProxy(std::move(bucpsaConnection), "com.jci.bucpsa", "/com/jci/bucpsa"); bucpsa->uponSignal("DisplayMode").onInterface("com.jci.bucpsa").call([this](const uint32_t &DisplayMode) { @@ -40,6 +42,7 @@ void VideoManager::requestFocus(VIDEO_FOCUS_REQUESTOR requestor) { LOG(DEBUG) << "Setting focus, requested by " << static_cast::type>(requestor); hasFocus = true; + gui->SetRequiredSurfacesByEnum(NativeGUICtrlClient::TV_TOUCH_SURFACE, true); vs->focusChanged.emit(true); } @@ -47,6 +50,7 @@ void VideoManager::releaseFocus(VIDEO_FOCUS_REQUESTOR requestor) { LOG(DEBUG) << "Releasing focus, requested by " << static_cast::type>(requestor); hasFocus = false; + gui->SetRequiredSurfacesByEnum(NativeGUICtrlClient::JCI_OPERA_PRIMARY, true); vs->focusChanged.emit(false); } diff --git a/src/autoapp/Projection/GSTVideoOutput.cpp b/src/autoapp/Projection/GSTVideoOutput.cpp index 79e47648..a6bf59ea 100644 --- a/src/autoapp/Projection/GSTVideoOutput.cpp +++ b/src/autoapp/Projection/GSTVideoOutput.cpp @@ -91,6 +91,11 @@ bool GSTVideoOutput::open() { std::ofstream ofs("/proc/sys/vm/drop_caches"); ofs << "3" << std::endl; + if (CheckReverse()) { + running = true; + return true; + } + if (gstpid == -1) { spawn_gst(); @@ -108,6 +113,14 @@ bool GSTVideoOutput::init() { void GSTVideoOutput::write(__attribute__((unused)) uint64_t timestamp, const aasdk::common::DataConstBuffer &buf) { + if (CheckReverse()) { + running = true; + stop(); + } else { + if (running && gstpid == -1) { + open(); + } + } if (gstpid != -1) { fwrite(buf.cdata, sizeof(buf.cdata[0]), buf.size, gst_file); } @@ -123,6 +136,20 @@ void GSTVideoOutput::stop() { } } +int GSTVideoOutput::CheckReverse() { + bool reverse = false; + char gpio_value[3]; + FILE *fd = fopen("/sys/class/gpio/Reverse/value", "r"); + if (fd == nullptr) { + LOG(ERROR) << "Failed to open Reverse gpio value for reading"; + } else { + fread(gpio_value, 1, 2, fd); + reverse = (gpio_value[0] == '0'); + } + fclose(fd); + return reverse; +} + GSTVideoOutput::~GSTVideoOutput() = default; VideoMargins GSTVideoOutput::getVideoMargins() const {