ADTF  3.18.2
Source Code for Qt5 Video Display Plugin
Location
./src/examples/src/adtf/filters/qt/demo_qt_video_display/
Namespace for entire ADTF SDK.
Build Environment
To see how to set up the build environment have a look at ADTF CMake Environment
This implementation shows:
Remarks
  • This UI Filter does only support pixel formats that are supported by QImage! Extend the code for your own needs.
  • This UI Filter uses a simple implemented cVideoWidget class based on QWidget from Qt SDK.
Header
/*
* This file depends on Qt which is licensed under LGPLv3.
* See ADTF_DIR/3rdparty/qt5 and doc/license for detailed information.
*/
#pragma once
#include "video_widget.h"
// always include filtersdk, systemsdk or streaming3 sdk BEFORE adtfui!!
#include <adtf_ui.h>
#include <QtWidgets>
using namespace adtf::base;
using namespace adtf::ucom;
using namespace adtf::streaming;
using namespace adtf::filter;
using namespace adtf::ui;
class cQtVideoFilter : public cQtUIFilter
{
public:
ADTF_CLASS_ID_NAME(cQtVideoFilter,
"demo_qt_video_display.ui_filter.adtf.cid",
"Qt5 Video Display");
private:
std::atomic_bool m_bStreamTypeChanged;
std::atomic_bool m_bInvalidated;
size_limited_sample_reader<1, false>* m_pReader = nullptr;
property_variable<uint32_t> m_nWidth = 640;
property_variable<uint32_t> m_nHeight = 480;
property_variable<bool> m_bKeepRatio = true;
property_variable<bool> m_bFitToScreen = true;
tStreamImageFormat m_sCurrentFormat;
cVideoWidget* m_pVideoWidget = nullptr;
public:
cQtVideoFilter();
tResult Init(tInitStage eStage) override;
tResult AcceptType(ISampleReader* pReader, const iobject_ptr<const IStreamType>& pType) override;
protected:
QWidget* CreateView() override;
void ReleaseView() override;
tResult OnTimer() override;
private:
object_ptr<IStreamType> GetStreamTypeFromProperties();
tResult UpdateVideo();
};
Copyright © Audi Electronics Venture GmbH.
#define REQUIRE_INTERFACE(_interface)
Macro usable with ADTF_CLASS_DEPENDENCIES() to require mandatory interfaces.
#define ADTF_CLASS_DEPENDENCIES(...)
Add interface ids (string literals,.
#define ADTF_CLASS_ID_NAME(_class, _strcid, _strclabel)
Common macro to enable correct treatment of class identifier AND Class Name by IClassInfo.
Definition: class_id.h:33
Interface definition for the ADTF XSystem based on Qt.
Namespace for the ADTF Base SDK.
Namespace for the ADTF Filter SDK.
Namespace for the ADTF Streaming SDK.
Namespace for the ADTF uCOM3 SDK.
qt_ui_filter< adtf::filter::ant::cFilter > cQtUIFilter
UI Filter basic implementation which has static pins only and supports the IDataBinding.
Definition: qt_ui_filter.h:98
Namespace for the ADTF UI SDK.
Copyright © Audi Electronics Venture GmbH.
Implementation
/*
* This file depends on Qt which is licensed under LGPLv3.
* See ADTF_DIR/3rdparty/qt5 and doc/license for detailed information.
*/
#include "demo_qt_video_display.h"
//*************************************************************************************************
ADTF_PLUGIN("Qt5 Video Display Plugin", cQtVideoFilter)
//*************************************************************************************************
cQtVideoFilter::cQtVideoFilter():
adtf::ui::cQtUIFilter(),
m_bStreamTypeChanged(true),
m_pVideoWidget(nullptr)
{
m_nWidth.SetDescription("Specified width for Sample dimension.");
RegisterPropertyVariable("width", m_nWidth);
m_nHeight.SetDescription("Specified height for Sample dimension.");
RegisterPropertyVariable("height", m_nHeight);
m_bFitToScreen.SetDescription("If enabled, the sample will be resized to the window dimension.");
RegisterPropertyVariable("fit_to_screen", m_bFitToScreen);
m_bKeepRatio.SetDescription("If enabled, the ratio of the Sample will be kept even when resized.");
RegisterPropertyVariable("keep_ratio", m_bKeepRatio);
m_pReader = CreateInputPin<size_limited_sample_reader<1, tFalse>>("video",
GetStreamTypeFromProperties(),
false);
set_description(*this, "video", "Input Pin for uncompressed video data streams to visualize.");
// sets a short description for the component
SetDescription("Use this filter to visualize uncompressed ADTF Video streams.");
// set help link to jump to documentation from ADTF Configuration Editor
set_help_link(*this, "$(ADTF_DIR)/doc/adtf_html/page_demo_qt_video_display.html");
}
tResult cQtVideoFilter::Init(tInitStage eStage)
{
RETURN_IF_FAILED(cQtUIFilter::Init(eStage));
if (eStage == StageNormal)
{
adtf::ucom::object_ptr<IStreamType> pType = GetStreamTypeFromProperties();
RETURN_IF_FAILED(m_pReader->SetType(pType));
RETURN_IF_FAILED(AcceptType(m_pReader, pType));
}
}
object_ptr<IStreamType> cQtVideoFilter::GetStreamTypeFromProperties()
{
m_sCurrentFormat.m_strFormatName = ADTF_IMAGE_FORMAT(RGB_32);
m_sCurrentFormat.m_ui32Width = m_nWidth;
m_sCurrentFormat.m_ui32Height = m_nHeight;
m_sCurrentFormat.m_szMaxByteSize = 0;
m_sCurrentFormat.m_ui8DataEndianess = PLATFORM_BYTEORDER;
object_ptr<IStreamType> pType = make_object_ptr<cStreamType>(stream_meta_type_image());
set_stream_type_image_format(*pType, m_sCurrentFormat);
return pType;
}
QWidget* cQtVideoFilter::CreateView()
{
m_pVideoWidget = new cVideoWidget(nullptr);
m_pVideoWidget->SetFitToScreen(m_bFitToScreen);
m_pVideoWidget->SetKeepRatio(m_bKeepRatio);
return m_pVideoWidget;
}
void cQtVideoFilter::ReleaseView()
{
m_pVideoWidget = nullptr;
}
tResult cQtVideoFilter::OnTimer()
{
UpdateVideo();
}
tResult cQtVideoFilter::AcceptType(ISampleReader* /*pReader*/, const iobject_ptr<const IStreamType>& pType)
{
if (!pType.Get())
{
RETURN_ERROR(ERR_INVALID_TYPE);
}
return adtf::streaming::get_stream_type_image_format(m_sCurrentFormat, *pType.Get());
}
tResult cQtVideoFilter::UpdateVideo()
{
// we are only interested in the last sample and only if its new (thus no use of GetLastSample)
while (IS_OK(m_pReader->GetNextSample(pSample)))
{
}
if (pSample)
{
m_pVideoWidget->UpdateSample(m_sCurrentFormat, pSample);
}
}
#define ADTF_PLUGIN(__plugin_identifier,...)
The ADTF Plugin Macro will add the code of a adtf::ucom::ant::IPlugin implementation.
Definition: adtf_plugin.h:22
#define RETURN_IF_FAILED(s)
Return if expression is failed, which requires the calling function's return type to be tResult.
#define RETURN_NOERROR
Return status ERR_NOERROR, which requires the calling function's return type to be tResult.
#define RETURN_ERROR(code)
Return specific error code, which requires the calling function's return type to be tResult.
Object pointer implementation used for reference counting on objects of type IObject.
Definition: object_ptr.h:163
#define PLATFORM_BYTEORDER
defines a link to __get_platform_byteorder.
Definition: constants.h:124
tResult get_stream_type_image_format(tStreamImageFormat &oFormat, const IStreamType &oType)
Helper function to retrieve the oFormat (tStreamImageFormat) out of the of a IStreamType for a stream...
tResult set_stream_type_image_format(IStreamType &oType, const tStreamImageFormat &oFormat)
Helper function to set the properties of a IStreamType for a stream_meta_type_image.
void set_description(base::ant::IConfiguration &oConfig, const char *strDescription)
Sets description information.
void set_help_link(base::ant::IConfiguration &oConfig, const char *strUrl)
Set the link to the corresponding help/documentation.
#define ADTF_IMAGE_FORMAT(_FORMAT_)
Helper Macro to get the FormatName of the predefined Format within stream_image_format.