Skip to content

Commit

Permalink
workaround for backup camera switching.
Browse files Browse the repository at this point in the history
Make video work on firmware 70.00.100
  • Loading branch information
silverchris committed Apr 11, 2021
1 parent e349abf commit 23a734c
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 1 deletion.
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})

Expand Down
40 changes: 40 additions & 0 deletions include/autoapp/Managers/VideoManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,45 @@
#include <autoapp/Service/VideoService.hpp>
#include <autoapp/Signals/VideoSignals.hpp>

#include <Mazda/Dbus/com.jci.nativeguictrl.h>

class NativeGUICtrlClient final : public sdbus::ProxyInterfaces<com::jci::nativeguictrl_proxy> {
public:
NativeGUICtrlClient(std::unique_ptr<sdbus::IConnection> &connection, std::string destination, std::string objectPath)
: sdbus::ProxyInterfaces<com::jci::nativeguictrl_proxy>(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<int16_t>(fadeOpera ? 1 : 0));
}
};

class VideoManager {
private:
std::unique_ptr<sdbus::IProxy> bucpsa;
Expand All @@ -16,6 +55,7 @@ class VideoManager {
sigc::connection releaseFocusConnection;
bool currentDisplayMode;
bool hasFocus = false;
NativeGUICtrlClient *gui;

public:
explicit VideoManager(VideoSignals::Pointer videosignals);
Expand Down
2 changes: 2 additions & 0 deletions include/autoapp/Projection/GSTVideoOutput.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
};
}
4 changes: 4 additions & 0 deletions src/autoapp/Managers/VideoManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -40,13 +42,15 @@ void VideoManager::requestFocus(VIDEO_FOCUS_REQUESTOR requestor) {
LOG(DEBUG) << "Setting focus, requested by "
<< static_cast<std::underlying_type<VIDEO_FOCUS_REQUESTOR>::type>(requestor);
hasFocus = true;
gui->SetRequiredSurfacesByEnum(NativeGUICtrlClient::TV_TOUCH_SURFACE, true);
vs->focusChanged.emit(true);
}

void VideoManager::releaseFocus(VIDEO_FOCUS_REQUESTOR requestor) {
LOG(DEBUG) << "Releasing focus, requested by "
<< static_cast<std::underlying_type<VIDEO_FOCUS_REQUESTOR>::type>(requestor);
hasFocus = false;
gui->SetRequiredSurfacesByEnum(NativeGUICtrlClient::JCI_OPERA_PRIMARY, true);
vs->focusChanged.emit(false);
}

Expand Down
27 changes: 27 additions & 0 deletions src/autoapp/Projection/GSTVideoOutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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);
}
Expand All @@ -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 {
Expand Down

0 comments on commit 23a734c

Please sign in to comment.