ADTF  3.18.2
ADTF2 Compressed Video Deserializer
Description
Implements a adtffileplugin, which derives from adtf_file::StreamTypeDeserializer, to deserialize the compressed video Stream Meta Type of ADTF 2 DAT Files. The resulting adtffileplugin can be loaded by the ADTF File Support Service to announce, the previously unknown, section_stream_meta_type to the Playback Service.
Dependencies
  • adtf_file::StreamTypeDeserializer
  • base64_codec::Base64
Location
./src/examples/src/adtf/deserializer/adtf2_compressed_video_deserializer/
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
  • Give the class a class id composed of the class id of the ADTF 2 Media Type followed by ".adtf2_support.serialization.adtf.cid", such that the ADTF File Support Service Plugin can find it.
Header
#pragma once
#include <adtf_file/adtf_file_reader.h>
namespace adtf_file
{
namespace adtf2
{
namespace compressed_video
{
class DemoCompressedVideoMediaTypeDeserializer : public adtf_file::StreamTypeDeserializer
{
public:
// Inherited via StreamTypeDeserializer
std::string getId() const override;
void deserialize(adtf_file::InputStream& stream,
adtf_file::PropertyStreamType& stream_type) const override;
};
}// namespace compressed_video
}// namespace adtf2
}// namespace adtf_file
Implementation
#include "demo_compressed_video_media_type_deserializer.h"
#include "adtf2_compressed_video_types.h"
#include <base64_codec/base64.h>
using namespace video_codec;
namespace adtf_file
{
namespace adtf2
{
namespace compressed_video
{
static PluginInitializer initializer([]
{
getObjects().push_back(std::make_shared<DemoCompressedVideoMediaTypeDeserializer>());
});
std::string DemoCompressedVideoMediaTypeDeserializer::getId() const
{
return "adtf.type.video_compressed.adtf2_support.serialization.adtf.cid";
}
void DemoCompressedVideoMediaTypeDeserializer::deserialize(InputStream& stream,
PropertyStreamType& stream_type) const
{
uint32_t major_type{}, sub_type{}, flags{}, size{};
CodecInfo codec_info{};
stream >> major_type >> sub_type >> flags >> size;
size_t attached_bytes_size{size - sizeof(CodecInfo)};
codec_info.size = size;
stream >> codec_info.version
>> codec_info.bitmap_format.width
>> codec_info.bitmap_format.height
>> codec_info.bitmap_format.bits_per_pixel
>> codec_info.bitmap_format.pixel_format
>> codec_info.bitmap_format.bytes_per_line
>> codec_info.bitmap_format.size
>> codec_info.bitmap_format.palette_size;
std::vector<char> codec_name(ADTF_MAX_CODEC_NAME_LENGTH, '\0');
std::vector<uint8_t> attached_bytes(attached_bytes_size);
stream.read(codec_name.data(), ADTF_MAX_CODEC_NAME_LENGTH);
stream_type.setMetaType("adtf/video_compressed");
stream_type.setProperty("codec_size", "tUInt32", std::to_string(codec_info.size));
stream_type.setProperty("codec_version", "tUInt32", std::to_string(codec_info.version));
stream_type.setProperty("bitmap_pixel_width", "tInt32", std::to_string(codec_info.bitmap_format.width));
stream_type.setProperty("bitmap_pixel_height", "tInt32", std::to_string(codec_info.bitmap_format.height));
stream_type.setProperty("bitmap_bits_per_pixel", "tInt32", std::to_string(codec_info.bitmap_format.bits_per_pixel));
stream_type.setProperty("bitmap_pixel_format", "tInt32", std::to_string(codec_info.bitmap_format.pixel_format));
stream_type.setProperty("bitmap_bytes_per_line", "tInt32", std::to_string(codec_info.bitmap_format.bytes_per_line));
stream_type.setProperty("bitmap_byte_size", "tInt32", std::to_string(codec_info.bitmap_format.size));
stream_type.setProperty("bitmap_palette_size", "tInt32", std::to_string(codec_info.bitmap_format.palette_size));
stream_type.setProperty("codec_name", "cString", codec_name.data());
if (attached_bytes_size > 0)
{
stream.read(attached_bytes.data(), attached_bytes_size);
stream_type.setProperty("attached_base64_data", "cString", base64_codec::Base64::encode(attached_bytes));
}
}
}// namespace compressed_video
}// namespace adtf2
}// namespace adtf_file
cString to_string(const tResult &i_oResult, eResultFormatFlags i_eFormatFlags=eResultFormatFlags::RFF_DisableNone, const tChar *i_strFormat=nullptr)
Copy all information of an assigned result object to a (formatted) string.