custom aspect ratios (#21)
* Working on proper resizing of AA * allow for custom aspect ratios
This commit is contained in:
parent
94ee66acd7
commit
e940b8036e
@ -79,6 +79,7 @@ private:
|
||||
QGst::ElementPtr videoSink_;
|
||||
QQuickWidget* videoWidget_;
|
||||
GstElement* vidPipeline_;
|
||||
GstVideoFilter* vidCrop_;
|
||||
GstAppSrc* vidSrc_;
|
||||
QWidget* videoContainer_;
|
||||
QGst::Quick::VideoSurface* surface_;
|
||||
|
@ -15,7 +15,6 @@
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with openauto. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifdef USE_GST
|
||||
|
||||
#include "aasdk/Common/Data.hpp"
|
||||
@ -27,6 +26,7 @@ namespace openauto
|
||||
namespace projection
|
||||
{
|
||||
|
||||
|
||||
GSTVideoOutput::GSTVideoOutput(configuration::IConfiguration::Pointer configuration, QWidget* videoContainer, std::function<void(bool)> activeCallback)
|
||||
: VideoOutput(std::move(configuration))
|
||||
, videoContainer_(videoContainer)
|
||||
@ -53,7 +53,7 @@ GSTVideoOutput::GSTVideoOutput(configuration::IConfiguration::Pointer configurat
|
||||
#else
|
||||
"avdec_h264 ! "
|
||||
#endif
|
||||
"capsfilter caps=video/x-raw name=mycapsfilter";
|
||||
"videocrop top=0 bottom=0 name=videocropper ! capsfilter caps=video/x-raw name=mycapsfilter";
|
||||
#ifdef RPI
|
||||
OPENAUTO_LOG(info) << "[GSTVideoOutput] RPI Build, running with " <<
|
||||
#ifdef PI4
|
||||
@ -80,6 +80,8 @@ GSTVideoOutput::GSTVideoOutput(configuration::IConfiguration::Pointer configurat
|
||||
vidSrc_ = GST_APP_SRC(gst_bin_get_by_name(GST_BIN(vidPipeline_), "mysrc"));
|
||||
gst_app_src_set_stream_type(vidSrc_, GST_APP_STREAM_TYPE_STREAM);
|
||||
|
||||
vidCrop_ = GST_VIDEO_FILTER(gst_bin_get_by_name(GST_BIN(vidPipeline_), "videocropper"));
|
||||
|
||||
connect(this, &GSTVideoOutput::startPlayback, this, &GSTVideoOutput::onStartPlayback, Qt::QueuedConnection);
|
||||
connect(this, &GSTVideoOutput::stopPlayback, this, &GSTVideoOutput::onStopPlayback, Qt::QueuedConnection);
|
||||
}
|
||||
@ -222,6 +224,50 @@ void GSTVideoOutput::resize()
|
||||
{
|
||||
videoWidget_->resize(videoContainer_->size());
|
||||
}
|
||||
|
||||
int width = 0;
|
||||
int height = 0;
|
||||
int containerWidth = videoContainer_->width();
|
||||
int containerHeight = videoContainer_->height();
|
||||
|
||||
switch(this->getVideoResolution()){
|
||||
case aasdk::proto::enums::VideoResolution_Enum__1080p:
|
||||
width = 1920;
|
||||
height = 1080;
|
||||
break;
|
||||
case aasdk::proto::enums::VideoResolution_Enum__720p:
|
||||
width = 1280;
|
||||
height = 720;
|
||||
break;
|
||||
case aasdk::proto::enums::VideoResolution_Enum__480p:
|
||||
width = 800;
|
||||
height = 480;
|
||||
break;
|
||||
}
|
||||
|
||||
double marginWidth = 0;
|
||||
double marginHeight = 0;
|
||||
|
||||
double widthRatio = (double)containerWidth / width;
|
||||
double heightRatio = (double)containerHeight / height;
|
||||
|
||||
if(widthRatio > heightRatio){
|
||||
//cropping height
|
||||
marginHeight = (widthRatio * height - containerHeight)/widthRatio;
|
||||
marginHeight /= 2;
|
||||
}else{
|
||||
//cropping width
|
||||
marginWidth = (heightRatio * width - containerWidth)/heightRatio;
|
||||
marginWidth /= 2;
|
||||
}
|
||||
|
||||
|
||||
OPENAUTO_LOG(info) << "[GSTVideoOutput] Android Auto is "<< width << "x" << height << ", calculated margins of: " << marginWidth << "x" << marginHeight;
|
||||
g_object_set(vidCrop_, "top", (int)marginHeight, nullptr);
|
||||
g_object_set(vidCrop_, "bottom", (int)marginHeight, nullptr);
|
||||
g_object_set(vidCrop_, "left", (int)marginWidth, nullptr);
|
||||
g_object_set(vidCrop_, "right", (int)marginWidth, nullptr);
|
||||
this->configuration_->setVideoMargins(QRect(0,0,(int)(marginWidth*2), (int)(marginHeight*2)));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -145,6 +145,11 @@ IService::Pointer ServiceFactory::createInputService(aasdk::messenger::IMessenge
|
||||
break;
|
||||
}
|
||||
|
||||
//account for margins being applied to android auto
|
||||
videoGeometry.setWidth(videoGeometry.width()-configuration_->getVideoMargins().width());
|
||||
videoGeometry.setHeight(videoGeometry.height()-configuration_->getVideoMargins().height());
|
||||
|
||||
|
||||
QObject* inputObject = activeArea_ == nullptr ? qobject_cast<QObject*>(QApplication::instance()) : qobject_cast<QObject*>(activeArea_);
|
||||
inputDevice_ = std::make_shared<projection::InputDevice>(*inputObject, configuration_, std::move(screenGeometry_), std::move(videoGeometry));
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user