ADTF  3.18.2
Source Code for ADTF2 Video Decompressor Filter Plugin
Location
./src/examples/src/adtf/deserializer/adtf2_video_decompressor_filter/
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:
Header
#pragma once
#include <adtf_filtersdk.h>
#include <video_codec/adtf_codec.h>
#include <vector>
#include <memory>
namespace adtf_file
{
namespace adtf2
{
namespace compressed_video
{
//*************************************************************************************************
class cDemoVideoDecompressorFilter : public adtf::filter::cFilter
{
public:
ADTF_CLASS_ID_NAME(cDemoVideoDecompressorFilter,
"demo_video_decompressor.filter.adtf.cid",
"ADTF2 Video Decompressor Filter");
cDemoVideoDecompressorFilter();
public: // overwrites cFilter
public:
adtf::util::cString GetPixelFormatName(uint16_t nPixelFormat) const;
protected:
tResult ProcessInput(adtf::streaming::ISampleReader* /*pReader*/,
private:
adtf::ucom::object_ptr<adtf::streaming::IStreamType> GetStreamTypeFromBitmapFormat(const adtf_file::adtf2::BitmapFormat& sFormat) const;
private:
std::unique_ptr<video_codec::IVideoDecompressor> m_pDecompressor;
// reader for our input pin
adtf::streaming::ISampleReader* m_pReader = nullptr;
// writer for our output pin
adtf::streaming::ISampleWriter* m_pWriter = nullptr;
// property to disable alpha channels in output formats
adtf::base::property_variable<bool> m_bDisableOutputAlphaChannel = false;
};
}// ns compressed_video
}// ns adtf2
}// ns adtf_file
#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
Property Variable template for the given T.
Interface for sample reads that read from sample streams via input pins.
Interface for sample writers that write to sample streams via output pins.
Base object pointer to realize binary compatible reference counting in interface methods.
Object pointer implementation used for reference counting on objects of type IObject.
Definition: object_ptr.h:163
string_base< cStackString > cString
cString implementation for a stack string which works on stack if string is lower than A_UTILS_DEFAUL...
Definition: string.h:2778
Implementation
#include "demo_video_decompressor_filter.h"
#include "stream_meta_type_compressed_video.h"
#include <base64_codec/base64.h>
#include <cstring>
using namespace adtf::ucom;
using namespace adtf::streaming;
using namespace adtf::util;
using namespace adtf::base;
using namespace adtf_file::adtf2::compressed_video;
using namespace video_codec::adtf_codec;
// this creates the plugin entry methods and class factories
ADTF_PLUGIN("ADTF2 Video Decompressor Plugin", cDemoVideoDecompressorFilter);
namespace adtf_file
{
namespace adtf2
{
namespace compressed_video
{
//**************************************************************************************************
#define FORMAT_CONVERSION_CASE(__format, __newformat__) \
case PixelFormats::pf_##__format:\
{\
if (cString(__newformat__).IsEmpty()) \
{ \
strFormatName = #__format; \
} \
else \
{ \
strFormatName = __newformat__; \
}\
break;\
}
#define FORMAT_CONVERSION_ALPHA_CASE(__format, __newformat__, __newformat_no_alpha__) \
case PixelFormats::pf_##__format:\
{\
if (m_bDisableOutputAlphaChannel) \
{ \
strFormatName = __newformat_no_alpha__; \
} \
else \
{ \
strFormatName = __newformat__; \
}\
break;\
}
//**************************************************************************************************
cDemoVideoDecompressorFilter::cDemoVideoDecompressorFilter()
{
m_bDisableOutputAlphaChannel.SetDescription("Enable this the change to output formats without alpha channel. "
"The image data will remain the same, but other components will not interpret the alpha channel data within the image. "
"Enable this option for backwards compatibility with videos that do not contain valid data within the alpha channel.");
RegisterPropertyVariable("disable_output_alpha_channel", m_bDisableOutputAlphaChannel);
m_pReader = CreateInputPin("compressed_video", stream_meta_type_video_compressed());
SetDescription("compressed_video", "Input for compressed video data recorded with ADTF 2 Video Compression Toolbox using adtf codec and underlying rice codec");
m_pWriter = CreateOutputPin("decompressed_video", stream_meta_type_image());
SetDescription("decompressed_video", "Provides decoded video data (e.g. for using within Qt5 Video Display)");
// sets a short description for the component
SetDescription("Use this filter to decompress video data recorded with ADTF 2 Video Compression Toolbox using adtf codec and underlying rice codec.");
// set help link to jump to documentation from ADTF Configuration Editor
SetHelpLink("$(ADTF_DIR)/doc/adtf_html/page_demo_adtf2_video_decompressor_filter.html");
}
//**************************************************************************************************
cString cDemoVideoDecompressorFilter::GetPixelFormatName(uint16_t nPixelFormat) const
{
cString strFormatName;
switch (nPixelFormat)
{
FORMAT_CONVERSION_CASE(unknown, "")
FORMAT_CONVERSION_CASE(8_bit, "")
FORMAT_CONVERSION_CASE(greyscale_8, "GREY(8)")
FORMAT_CONVERSION_CASE(rgb_8, "R(3)G(3)B(2)")
FORMAT_CONVERSION_CASE(16_bit, "")
FORMAT_CONVERSION_CASE(greyscale_10, "GREY(10)")
FORMAT_CONVERSION_CASE(greyscale_12, "GREY(12)")
FORMAT_CONVERSION_CASE(greyscale_14, "GREY(14)")
FORMAT_CONVERSION_CASE(greyscale_16, "GREY(16)")
FORMAT_CONVERSION_CASE(rgb_444, "R(4)G(4)B(4)")
FORMAT_CONVERSION_CASE(rgb_555, "R(5)G(5)B(5)(1)")
FORMAT_CONVERSION_CASE(rgb_565, "R(5)G(6)B(5)")
FORMAT_CONVERSION_CASE(rgba_4444, "R(4)G(4)B(4)A(4)")
FORMAT_CONVERSION_CASE(abgr_4444, "A(4)B(4)G(4)R(4)")
FORMAT_CONVERSION_CASE(riii_10, "")
FORMAT_CONVERSION_CASE(riii_12, "")
FORMAT_CONVERSION_CASE(riii_14, "")
FORMAT_CONVERSION_CASE(riii_16, "")
FORMAT_CONVERSION_CASE(bgr_555, "(1)B(5)G(5)R(5)")
FORMAT_CONVERSION_CASE(bgr_565, "B(5)G(6)R(5)")
FORMAT_CONVERSION_CASE(24_bit, "")
FORMAT_CONVERSION_CASE(greyscale_18, "GREY(18)")
FORMAT_CONVERSION_CASE(greyscale_20, "GREY(20)")
FORMAT_CONVERSION_CASE(greyscale_22, "GREY(22)")
FORMAT_CONVERSION_CASE(greyscale_24, "GREY(24)")
FORMAT_CONVERSION_CASE(rgb_888, "R(8)G(8)B(8)")
FORMAT_CONVERSION_CASE(bgr_888, "B(8)G(8)R(8)")
FORMAT_CONVERSION_CASE(32_bit, "")
FORMAT_CONVERSION_ALPHA_CASE(argb_8888, "A(8)R(8)G(8)B(8)", "(8)R(8)G(8)B(8)")
FORMAT_CONVERSION_ALPHA_CASE(abgr_8888, "A(8)B(8)G(8)R(8)", "(8)B(8)G(8)R(8)")
FORMAT_CONVERSION_ALPHA_CASE(rgba_8888, "R(8)G(8)B(8)A(8)", "R(8)G(8)B(8)(8)")
FORMAT_CONVERSION_ALPHA_CASE(bgra_8888, "B(8)G(8)R(8)A(8)", "B(8)G(8)R(8)(8)")
FORMAT_CONVERSION_CASE(greyscale_32, "GREY(32)")
FORMAT_CONVERSION_CASE(greyscale_float_32, "")
FORMAT_CONVERSION_CASE(yuv420p_888, "")
default:
{
strFormatName = cString::FromType(nPixelFormat);
break;
}
}
return strFormatName;
}
//**************************************************************************************************
object_ptr<IStreamType> cDemoVideoDecompressorFilter::GetStreamTypeFromBitmapFormat(const BitmapFormat& sFormat) const
{
tStreamImageFormat sStreamImageFormat;
sStreamImageFormat.m_strFormatName = GetPixelFormatName(sFormat.pixel_format);
sStreamImageFormat.m_szMaxByteSize = sFormat.size;
sStreamImageFormat.m_ui32Height = sFormat.height;
sStreamImageFormat.m_ui32Width = sFormat.width;
object_ptr<IStreamType> pStreamType = make_object_ptr<cStreamType>(stream_meta_type_image());
THROW_IF_FAILED(set_stream_type_image_format(*pStreamType, sStreamImageFormat));
return pStreamType;
}
//**************************************************************************************************
tResult cDemoVideoDecompressorFilter::AcceptType(ISampleReader* pReader,
const iobject_ptr<const IStreamType>& pType)
{
// we want the default compatibility behaviour, so we call the base method first.
RETURN_IF_FAILED(cFilter::AcceptType(pReader, pType));
if (pReader == m_pReader)
{
//get codec independent data
BitmapFormat sBitmapFormat;
sBitmapFormat.size = get_property<int32_t>(*pType.Get(),
stream_meta_type_video_compressed::MaxByteSize);
sBitmapFormat.height = get_property<int32_t>(*pType.Get(),
stream_meta_type_video_compressed::PixelHeight);
sBitmapFormat.width = get_property<int32_t>(*pType.Get(),
stream_meta_type_video_compressed::PixelWidth);
sBitmapFormat.pixel_format = static_cast<int16_t>(get_property<int32_t>(*pType.Get(),
stream_meta_type_video_compressed::PixelFormat));
sBitmapFormat.bits_per_pixel = static_cast<int16_t>(get_property<int32_t>(*pType.Get(),
stream_meta_type_video_compressed::BitsPerPixel));
sBitmapFormat.bytes_per_line = get_property<int32_t>(*pType.Get(),
stream_meta_type_video_compressed::BytesPerLine);
sBitmapFormat.palette_size = get_property<int32_t>(*pType.Get(),
stream_meta_type_video_compressed::PaletteSize);
auto oAttachedData = base64_codec::Base64::decode(get_property<cString>(*pType.Get(),
stream_meta_type_video_compressed::AttachedBase64Data).GetPtr());
RETURN_IF_FAILED(m_pWriter->ChangeType(GetStreamTypeFromBitmapFormat(sBitmapFormat)));
//Choose codec
auto strCodecName = get_property<cString>(*pType.Get(),
stream_meta_type_video_compressed::CodecName);
if ("adtf" == strCodecName)
{
m_pDecompressor = std::make_unique<cADTFCodecDecompressor>(cADTFCodecDecompressor(sBitmapFormat,
adtf_memory_buffer<const void>(oAttachedData.data(),
oAttachedData.size())));
}
else // or add new codecs
{
RETURN_ERROR_DESC(ERR_NOT_IMPL, "Codec %s not implemented", strCodecName.GetPtr());
}
}
}
//**************************************************************************************************
tResult cDemoVideoDecompressorFilter::ProcessInput(ISampleReader* /*pReader*/,
const iobject_ptr<const ISample>& pSample)
{
object_ptr_shared_locked<const ISampleBuffer> pCompressedBuffer;
RETURN_IF_FAILED(pSample->Lock(pCompressedBuffer));
auto nSampleTime = get_sample_time(pSample);
object_ptr<ISample> pDecompressedSample;
object_ptr_locked<ISampleBuffer> pDecompressedBuffer;
RETURN_IF_FAILED(alloc_sample(pDecompressedSample, nSampleTime));
RETURN_IF_FAILED(pDecompressedSample->WriteLock(pDecompressedBuffer, 0));
RETURN_IF_FAILED(pDecompressedSample->SetFlags(ISample::SF_VideoKeyFrame));
m_pDecompressor->Decompress(*pCompressedBuffer.Get(), *pDecompressedBuffer.Get());
RETURN_IF_FAILED(m_pWriter->Write(pDecompressedSample));
}
}// ns compressed_video
}// ns adtf2
}// ns adtf_file
#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_ERROR_DESC(_code,...)
Same as RETURN_ERROR(_error) using a printf like parameter list for detailed error description.
#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.
Namespace for the ADTF Base SDK.
B(8) G(8) R(8)") ADTF_DEFINE_STREAM_IMAGE_FORMAT(RGB_32
Format definition this description means always first in lowest bit of lowest byte.
A(8) B(8) G(8) R(8)") ADTF_DEFINE_STREAM_IMAGE_FORMAT(ARGB_32
Format definition this description means always first in lowest bit of lowest byte.
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.
tResult alloc_sample(ucom::ant::iobject_ptr< ucom::ant::IObject > &pSampleObject, const char *strSampleCID)
Helper Function to get a Sample Instance through the adtf::ucom::ant::IRuntime.
R(5) G(5) B(5)(1)") ADTF_DEFINE_STREAM_IMAGE_FORMAT(RGB_565
Format definition.
base::flash::tNanoSeconds get_sample_time(const ucom::ant::iobject_ptr< const ant::ISample > &pSample)
Returns the sample time stamp with nanosecond precision.
Namespace for the ADTF Streaming SDK.
Namespace for the ADTF uCOM3 SDK.
alias namespace for the A_UTILS Library.
#define THROW_IF_FAILED(s)
throws if the expression returns a failed tResult