ADTF Qt5
Loading...
Searching...
No Matches
Example Qt5 Video Display

Description

Shows how to create an display to visualize uncompressed video streams.

Prebuilt Binaries

Source Code

./examples/demo_adtfplugins/qt5_video_display/

UI Filter

demo_qt_video_display.h

/*
* This file depends on Qt which is licensed under LGPLv3.
* See ADTF_DIR/3rdparty/qt5 and doc/license for detailed information.
*/
#pragma once
#include <adtffiltersdk/adtf_filtersdk.h>
// always include filtersdk, systemsdk or streaming3 sdk BEFORE adtfui!!
#include <adtf_ui.h>
#include <QWidget>
#ifndef ADTF_EXAMPLES_CID
#define ADTF_EXAMPLES_CID ".local.cid"
#endif
class cQtVideoFilter : public adtf::ui::cQtUIFilter
{
public:
ADTF_CLASS_ID_NAME(cQtVideoFilter, "demo_qt_video_display.ui_filter" ADTF_EXAMPLES_CID, "Qt5 Video Display");
ADTF_CLASS_DEPENDENCIES(REQUIRE_INTERFACE(adtf::ui::IQtXSystem));
private:
std::atomic_bool m_bStreamTypeChanged;
std::atomic_bool m_bInvalidated;
adtf::streaming::size_limited_sample_reader<1, false>* m_pReader = nullptr;
adtf::base::property_variable<uint32_t> m_nWidth = 640;
adtf::base::property_variable<uint32_t> m_nHeight = 480;
adtf::base::property_variable<bool> m_bKeepRatio = true;
adtf::base::property_variable<bool> m_bFitToScreen = true;
adtf::streaming::tStreamImageFormat m_sCurrentFormat;
adtf::ui::widget::cVideoWidget* m_pVideoWidget = nullptr;
public:
cQtVideoFilter();
~cQtVideoFilter() override;
tResult Init(tInitStage eStage) override;
tResult AcceptType(adtf::streaming::ISampleReader* pReader,
const adtf::ucom::iobject_ptr<const adtf::streaming::IStreamType>& pType) override;
protected:
QWidget* CreateView() override;
void ReleaseView() override;
tResult OnTimer() override;
private:
adtf::ucom::object_ptr<adtf::streaming::IStreamType> GetStreamTypeFromProperties();
tResult UpdateVideo();
};
virtual QWidget * CreateView()=0
virtual void ReleaseView()=0
tResult OnTimer() override
Definition xsystem_qtwindow.h:132
tResult Init(typename FILTERBASECLASS::tInitStage eStage) override
Definition qt_ui_filter.h:283
Interface definition for the ADTF XSystem based on Qt. Use this interface to create your own displays...
Definition qtxsystem_intf.h:385
Definition video_widget.h:32
v0::qt_ui_filter< adtf::filter::cFilter, cQtWindow > cQtUIFilter
Definition qt_ui_filter.h:382

demo_qt_video_display.cpp

/*
* 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<adtf::streaming::size_limited_sample_reader<1, false>>(
"video", GetStreamTypeFromProperties(),
// m_pReader is accessed from the UI thread, so the default processing in the trigger must be disabled.
// Otherwise m_pReader would get corrupted due to to race conditions.
false);
adtf::streaming::set_description(*this, "video", "Input Pin for uncompressed video data streams to visualize.");
// sets a short description for the component
SetDescription("Use this UI filter to visualize uncompressed ADTF Video streams.");
// set help link to jump to documentation from ADTF Configuration Editor
adtf::streaming::set_help_link(*this, "$(ADTF_QT5_DIR)/doc/html/page_qt5_video_display.html");
}
cQtVideoFilter::~cQtVideoFilter() = default;
tResult cQtVideoFilter::Init(tInitStage eStage)
{
RETURN_IF_FAILED(adtf::ui::cQtUIFilter::Init(eStage));
if (eStage == StageNormal)
{
adtf::ucom::object_ptr<adtf::streaming::IStreamType> pType = GetStreamTypeFromProperties();
RETURN_IF_FAILED(m_pReader->SetType(pType));
RETURN_IF_FAILED(AcceptType(m_pReader, pType));
}
RETURN_NOERROR;
}
adtf::ucom::object_ptr<adtf::streaming::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;
adtf::ucom::object_ptr<adtf::streaming::IStreamType> pType =
adtf::ucom::make_object_ptr<adtf::streaming::cStreamType>(adtf::streaming::stream_meta_type_image());
set_stream_type_image_format(*pType, m_sCurrentFormat);
return pType;
}
QWidget* cQtVideoFilter::CreateView()
{
m_pVideoWidget = new adtf::ui::widget::cVideoWidget(nullptr);
m_pVideoWidget->SetFitToScreen(m_bFitToScreen);
m_pVideoWidget->SetKeepRatio(m_bKeepRatio);
return m_pVideoWidget;
}
void cQtVideoFilter::ReleaseView()
{
m_pVideoWidget = nullptr;
}
tResult cQtVideoFilter::OnTimer()
{
RETURN_IF_FAILED(adtf::ui::cQtUIFilter::OnTimer());
RETURN_IF_FAILED(UpdateVideo());
RETURN_NOERROR;
}
tResult cQtVideoFilter::AcceptType(adtf::streaming::ISampleReader* /*pReader*/,
const adtf::ucom::iobject_ptr<const adtf::streaming::IStreamType>& pType)
{
if (!pType.Get())
{
RETURN_ERROR(ERR_INVALID_TYPE);
}
RETURN_IF_FAILED(adtf::streaming::get_stream_type_image_format(m_sCurrentFormat, *pType.Get()));
RETURN_NOERROR;
}
tResult cQtVideoFilter::UpdateVideo()
{
// We are only interested in the last sample and only if its new (thus no use of GetLastSample).
adtf::ucom::object_ptr<const adtf::streaming::ISample> pSample;
while (IS_OK(m_pReader->GetNextSample(pSample)))
{
}
if (pSample)
{
m_pVideoWidget->UpdateSample(m_sCurrentFormat, pSample);
}
RETURN_NOERROR;
}
Namespace for all functionality provided by ADTF and its SDKs.
Definition adtfui_pkg.h:13