diff --git a/include/f1x/openauto/autoapp/Projection/InputDevice.hpp b/include/f1x/openauto/autoapp/Projection/InputDevice.hpp index b6197a1..7d119bb 100644 --- a/include/f1x/openauto/autoapp/Projection/InputDevice.hpp +++ b/include/f1x/openauto/autoapp/Projection/InputDevice.hpp @@ -45,6 +45,7 @@ public: bool eventFilter(QObject* obj, QEvent* event) override; bool hasTouchscreen() const override; QRect getTouchscreenGeometry() const override; + void setTouchscreenGeometry(QRect& touchscreenGeometry); private: void setVideoGeometry(); diff --git a/include/f1x/openauto/autoapp/Projection/OMXVideoOutput.hpp b/include/f1x/openauto/autoapp/Projection/OMXVideoOutput.hpp index 30d0888..028f7ee 100644 --- a/include/f1x/openauto/autoapp/Projection/OMXVideoOutput.hpp +++ b/include/f1x/openauto/autoapp/Projection/OMXVideoOutput.hpp @@ -62,6 +62,7 @@ public: void write(uint64_t timestamp, const aasdk::common::DataConstBuffer& buffer) override; void stop() override; void setOpacity(OMX_U32 alpha); + void setDestRect(DestRect destRect); private: bool createComponents(); diff --git a/include/f1x/openauto/autoapp/Projection/QtVideoOutput.hpp b/include/f1x/openauto/autoapp/Projection/QtVideoOutput.hpp index 5800351..4a18319 100644 --- a/include/f1x/openauto/autoapp/Projection/QtVideoOutput.hpp +++ b/include/f1x/openauto/autoapp/Projection/QtVideoOutput.hpp @@ -43,6 +43,7 @@ public: bool init() override; void write(uint64_t timestamp, const aasdk::common::DataConstBuffer& buffer) override; void stop() override; + void resize(); signals: void startPlayback(); diff --git a/include/f1x/openauto/autoapp/Service/ServiceFactory.hpp b/include/f1x/openauto/autoapp/Service/ServiceFactory.hpp index 2c4475c..61d2223 100644 --- a/include/f1x/openauto/autoapp/Service/ServiceFactory.hpp +++ b/include/f1x/openauto/autoapp/Service/ServiceFactory.hpp @@ -20,7 +20,9 @@ #include #include +#include #include +#include namespace f1x { @@ -37,6 +39,7 @@ public: ServiceFactory(boost::asio::io_service& ioService, configuration::IConfiguration::Pointer configuration, QWidget* activeArea=nullptr, std::function activeCallback=nullptr); ServiceList create(aasdk::messenger::IMessenger::Pointer messenger) override; void setOpacity(unsigned int alpha); + void resize(); static QRect mapActiveAreaToGlobal(QWidget* activeArea); #ifdef USE_OMX static projection::DestRect QRectToDestRect(QRect rect); @@ -53,8 +56,11 @@ private: QWidget* activeArea_; QRect screenGeometry_; std::function activeCallback_; + std::shared_ptr inputDevice_; #ifdef USE_OMX std::shared_ptr omxVideoOutput_; +#else + projection::QtVideoOutput *qtVideoOutput_; #endif }; diff --git a/src/autoapp/Projection/InputDevice.cpp b/src/autoapp/Projection/InputDevice.cpp index 95d2a97..ec7c3a9 100644 --- a/src/autoapp/Projection/InputDevice.cpp +++ b/src/autoapp/Projection/InputDevice.cpp @@ -225,6 +225,11 @@ QRect InputDevice::getTouchscreenGeometry() const return touchscreenGeometry_; } +void InputDevice::setTouchscreenGeometry(QRect& touchscreenGeometry) +{ + touchscreenGeometry_ = touchscreenGeometry; +} + IInputDevice::ButtonCodes InputDevice::getSupportedButtonCodes() const { return configuration_->getButtonCodes(); diff --git a/src/autoapp/Projection/OMXVideoOutput.cpp b/src/autoapp/Projection/OMXVideoOutput.cpp index 4b4f75a..cd700fe 100644 --- a/src/autoapp/Projection/OMXVideoOutput.cpp +++ b/src/autoapp/Projection/OMXVideoOutput.cpp @@ -114,10 +114,12 @@ bool OMXVideoOutput::open() } isActive_ = true; - if(this->activeCallback_ != nullptr) + + if(activeCallback_ != nullptr) { - this->activeCallback_(isActive_); + activeCallback_(true); } + return true; } @@ -214,15 +216,16 @@ void OMXVideoOutput::stop() { OPENAUTO_LOG(info) << "[OMXVideoOutput] stop."; + if(activeCallback_ != nullptr) + { + activeCallback_(false); + } + std::lock_guard lock(mutex_); if(isActive_) { isActive_ = false; - if(this->activeCallback_ != nullptr) - { - this->activeCallback_(isActive_); - } ilclient_disable_tunnel(&tunnels_[0]); ilclient_disable_tunnel(&tunnels_[1]); @@ -249,14 +252,18 @@ void OMXVideoOutput::setOpacity(OMX_U32 alpha) alpha_ = alpha; if(isActive_) { - OMX_CONFIG_DISPLAYREGIONTYPE displayRegion; - displayRegion.nSize = sizeof(OMX_CONFIG_DISPLAYREGIONTYPE); - displayRegion.nVersion.nVersion = OMX_VERSION; - displayRegion.nPortIndex = 90; - displayRegion.alpha = alpha_; - displayRegion.set = static_cast(OMX_DISPLAY_SET_ALPHA); + this->setupDisplayRegion(); + } +} - OMX_SetConfig(ilclient_get_handle(components_[VideoComponent::RENDERER]), OMX_IndexConfigDisplayRegion, &displayRegion) == OMX_ErrorNone; +void OMXVideoOutput::setDestRect(DestRect destRect) +{ + std::lock_guard lock(mutex_); + + destRect_ = destRect; + if(isActive_) + { + this->setupDisplayRegion(); } } diff --git a/src/autoapp/Projection/QtVideoOutput.cpp b/src/autoapp/Projection/QtVideoOutput.cpp index ec7c349..68ceddf 100644 --- a/src/autoapp/Projection/QtVideoOutput.cpp +++ b/src/autoapp/Projection/QtVideoOutput.cpp @@ -69,6 +69,11 @@ void QtVideoOutput::write(uint64_t, const aasdk::common::DataConstBuffer& buffer videoBuffer_.write(reinterpret_cast(buffer.cdata), buffer.size); } +void QtVideoOutput::resize() +{ + if (videoWidget_ != nullptr && videoContainer_ != nullptr) videoWidget_->resize(videoContainer_->size()); +} + void QtVideoOutput::onStartPlayback() { if (videoContainer_ == nullptr) diff --git a/src/autoapp/Service/ServiceFactory.cpp b/src/autoapp/Service/ServiceFactory.cpp index ceead5e..dca6f65 100644 --- a/src/autoapp/Service/ServiceFactory.cpp +++ b/src/autoapp/Service/ServiceFactory.cpp @@ -82,8 +82,12 @@ IService::Pointer ServiceFactory::createVideoService(aasdk::messenger::IMessenge #ifdef USE_OMX auto videoOutput(omxVideoOutput_); #else - auto qtVideoOutput = new projection::QtVideoOutput(configuration_, activeArea_); - projection::IVideoOutput::Pointer videoOutput(qtVideoOutput, std::bind(&QObject::deleteLater, std::placeholders::_1)); + qtVideoOutput_ = new projection::QtVideoOutput(configuration_, activeArea_); + if (activeCallback_ != nullptr) { + QObject::connect(qtVideoOutput_, &projection::QtVideoOutput::startPlayback, [callback = activeCallback_]() { callback(true); }); + QObject::connect(qtVideoOutput_, &projection::QtVideoOutput::stopPlayback, [callback = activeCallback_]() { callback(false); }); + } + projection::IVideoOutput::Pointer videoOutput(qtVideoOutput_, std::bind(&QObject::deleteLater, std::placeholders::_1)); #endif return std::make_shared(ioService_, messenger, std::move(videoOutput)); } @@ -128,9 +132,9 @@ IService::Pointer ServiceFactory::createInputService(aasdk::messenger::IMessenge } QObject* inputObject = activeArea_ == nullptr ? qobject_cast(QApplication::instance()) : qobject_cast(activeArea_); - projection::IInputDevice::Pointer inputDevice(std::make_shared(*inputObject, configuration_, std::move(screenGeometry_), std::move(videoGeometry))); + inputDevice_ = std::make_shared(*inputObject, configuration_, std::move(screenGeometry_), std::move(videoGeometry)); - return std::make_shared(ioService_, messenger, std::move(inputDevice)); + return std::make_shared(ioService_, messenger, std::move(projection::IInputDevice::Pointer(inputDevice_))); } void ServiceFactory::createAudioServices(ServiceList& serviceList, aasdk::messenger::IMessenger::Pointer messenger) @@ -163,7 +167,18 @@ void ServiceFactory::createAudioServices(ServiceList& serviceList, aasdk::messen void ServiceFactory::setOpacity(unsigned int alpha) { #ifdef USE_OMX - omxVideoOutput_->setOpacity(alpha); + if (omxVideoOutput_ != nullptr) omxVideoOutput_->setOpacity(alpha); +#endif +} + +void ServiceFactory::resize() +{ + screenGeometry_ = this->mapActiveAreaToGlobal(activeArea_); + if (inputDevice_ != nullptr) inputDevice_->setTouchscreenGeometry(screenGeometry_); +#ifdef USE_OMX + if (omxVideoOutput_ != nullptr) omxVideoOutput_->setDestRect(this->QRectToDestRect(screenGeometry_)); +#else + if (qtVideoOutput_ != nullptr) qtVideoOutput_->resize(); #endif }