#include "demo_video_decompressor_filter.h"
#include "stream_meta_type_compressed_video.h"
#include <base64_codec/base64.h>
#include <cstring>
using namespace adtf_file::adtf2::compressed_video;
using namespace video_codec::adtf_codec;
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)");
SetDescription("Use this filter to decompress video data recorded with ADTF 2 Video Compression Toolbox using adtf codec and underlying rice codec.");
SetHelpLink("$(ADTF_DIR)/doc/adtf_html/page_demo_adtf2_video_decompressor_filter.html");
}
cString cDemoVideoDecompressorFilter::GetPixelFormatName(uint16_t nPixelFormat)
const
{
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());
return pStreamType;
}
tResult cDemoVideoDecompressorFilter::AcceptType(ISampleReader* pReader,
const iobject_ptr<const IStreamType>& pType)
{
if (pReader == m_pReader)
{
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)));
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
{
}
}
}
tResult cDemoVideoDecompressorFilter::ProcessInput(ISampleReader* ,
const iobject_ptr<const ISample>& pSample)
{
object_ptr_shared_locked<const ISampleBuffer> pCompressedBuffer;
object_ptr<ISample> pDecompressedSample;
object_ptr_locked<ISampleBuffer> pDecompressedBuffer;
m_pDecompressor->Decompress(*pCompressedBuffer.Get(), *pDecompressedBuffer.Get());
}
}
}
}
#define ADTF_PLUGIN(__plugin_identifier,...)
The ADTF Plugin Macro will add the code of a adtf::ucom::ant::IPlugin implementation.
#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