add interfaces to dynamically adjust video size (#1)

* adding interfaces for toggling fullscreen

* passing in destrect to omx

* adding flag for deffering video update

* remove skipUpdate option for video output

* fixing omx player stop deadlock; setting omx alpha in constructor

* jk not setting opacity in constructor for omx

* removing unsed function
This commit is contained in:
Robert Stanley Judka 2020-03-22 16:08:44 -05:00 committed by GitHub
parent 5df4b957a1
commit 5f8d5f4f6a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 59 additions and 18 deletions

View File

@ -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();

View File

@ -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();

View File

@ -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();

View File

@ -20,7 +20,9 @@
#include <f1x/openauto/autoapp/Service/IServiceFactory.hpp>
#include <f1x/openauto/autoapp/Configuration/IConfiguration.hpp>
#include <f1x/openauto/autoapp/Projection/InputDevice.hpp>
#include <f1x/openauto/autoapp/Projection/OMXVideoOutput.hpp>
#include <f1x/openauto/autoapp/Projection/QtVideoOutput.hpp>
namespace f1x
{
@ -37,6 +39,7 @@ public:
ServiceFactory(boost::asio::io_service& ioService, configuration::IConfiguration::Pointer configuration, QWidget* activeArea=nullptr, std::function<void(bool)> 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<void(bool)> activeCallback_;
std::shared_ptr<projection::InputDevice> inputDevice_;
#ifdef USE_OMX
std::shared_ptr<projection::OMXVideoOutput> omxVideoOutput_;
#else
projection::QtVideoOutput *qtVideoOutput_;
#endif
};

View File

@ -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();

View File

@ -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<decltype(mutex_)> 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_DISPLAYSETTYPE >(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<decltype(mutex_)> lock(mutex_);
destRect_ = destRect;
if(isActive_)
{
this->setupDisplayRegion();
}
}

View File

@ -69,6 +69,11 @@ void QtVideoOutput::write(uint64_t, const aasdk::common::DataConstBuffer& buffer
videoBuffer_.write(reinterpret_cast<const char*>(buffer.cdata), buffer.size);
}
void QtVideoOutput::resize()
{
if (videoWidget_ != nullptr && videoContainer_ != nullptr) videoWidget_->resize(videoContainer_->size());
}
void QtVideoOutput::onStartPlayback()
{
if (videoContainer_ == nullptr)

View File

@ -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<VideoService>(ioService_, messenger, std::move(videoOutput));
}
@ -128,9 +132,9 @@ IService::Pointer ServiceFactory::createInputService(aasdk::messenger::IMessenge
}
QObject* inputObject = activeArea_ == nullptr ? qobject_cast<QObject*>(QApplication::instance()) : qobject_cast<QObject*>(activeArea_);
projection::IInputDevice::Pointer inputDevice(std::make_shared<projection::InputDevice>(*inputObject, configuration_, std::move(screenGeometry_), std::move(videoGeometry)));
inputDevice_ = std::make_shared<projection::InputDevice>(*inputObject, configuration_, std::move(screenGeometry_), std::move(videoGeometry));
return std::make_shared<InputService>(ioService_, messenger, std::move(inputDevice));
return std::make_shared<InputService>(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
}