24#include <vrs/Record.h>
144 static constexpr uint8_t kQualityUndefined = 255;
145 static constexpr double kInvalidTimestamp = -1E-308;
153 double keyFrameTimestamp,
154 uint32_t keyFrameIndex);
163 uint32_t stride2 = 0,
164 string codecName = {},
165 uint8_t codecQuality = kQualityUndefined,
166 double keyFrameTimestamp = kInvalidTimestamp,
167 uint32_t keyFrameIndex = 0);
173 uint32_t height = 0);
188 uint8_t codecQuality = kQualityUndefined,
193 uint32_t stride2 = 0);
198 uint8_t codecQuality,
203 uint32_t stride2 = 0);
215 uint32_t stride2 = 0,
216 string codecName = {},
217 uint8_t codecQuality = kQualityUndefined,
218 double keyFrameTimestamp = kInvalidTimestamp,
219 uint32_t keyFrameIndex = 0);
278 uint32_t getRawStride2()
const {
323 return isQualityValid(codecQuality_) ? codecQuality_ : kQualityUndefined;
328 return quality <= 100;
333 return keyFrameTimestamp_;
339 return keyFrameIndex_;
349 return toString(pixelFormat);
365 uint32_t stride2_{0};
368 double keyFrameTimestamp_{kInvalidTimestamp};
369 uint32_t keyFrameIndex_{0};
370 uint8_t codecQuality_{kQualityUndefined};
385 uint8_t channelCount = 0,
386 uint8_t sampleFrameStride = 0,
387 uint32_t sampleFrameRate = 0,
388 uint32_t sampleFrameCount = 0,
389 uint8_t stereoPairCount = 0);
407 return !operator==(rhs);
427 return sampleFormat_;
451 return channelCount_;
455 return sampleFrameRate_;
459 return sampleFrameCount_;
463 sampleFrameCount_ = sampleCount;
466 uint8_t getStereoPairCount()
const {
467 return stereoPairCount_;
484 return toString(sampleFormat);
490 uint8_t sampleFrameStride_{};
491 uint8_t channelCount_{};
492 uint32_t sampleFrameRate_{};
493 uint32_t sampleFrameCount_{};
494 uint8_t stereoPairCount_{};
525 std::string codecName,
526 uint8_t codecQuality,
531 uint32_t stride2 = 0);
539 uint32_t stride2 = 0);
547 double keyFrameTimestamp,
548 uint32_t keyFrameIndex);
558 uint8_t numChannels = 0,
559 uint8_t sampleFrameStride = 0,
560 uint32_t sampleRate = 0,
561 uint32_t sampleCount = 0,
562 uint8_t stereoPairCount = 0);
570 : contentType_{other.contentType_}, size_{size} {
572 imageSpec_ = other.imageSpec_;
574 audioSpec_ = other.audioSpec_;
576 customContentBlockFormat_ = other.customContentBlockFormat_;
580 ~ContentBlock() =
default;
582 ContentBlock& operator=(
const ContentBlock& rhs) =
default;
583 ContentBlock& operator=(ContentBlock&& rhs)
noexcept =
default;
599 return customContentBlockFormat_;
605 return !operator==(rhs);
609 RecordFormat
operator+(
const ContentBlock&)
const;
612 const ImageContentBlockSpec&
image()
const;
614 const AudioContentBlockSpec&
audio()
const;
619 ImageContentBlockSpec imageSpec_;
620 AudioContentBlockSpec audioSpec_;
621 string customContentBlockFormat_;
646 uint32_t formatVersionIn,
649 recordType(recordTypeIn),
650 formatVersion(formatVersionIn),
651 blockIndex(blockIndexIn) {}
661 uint32_t getFormatVersion()
const {
662 return formatVersion;
665 size_t getBlockIndex()
const {
672 uint32_t formatVersion;
711 blocks_.emplace_back(block);
715 blocks_.emplace_back(std::move(block));
719 blocks_.emplace_back(first);
720 blocks_.emplace_back(second);
724 blocks_.emplace_back(std::move(first));
725 blocks_.emplace_back(std::move(second));
732 blocks_.emplace_back(type, size);
737 blocks_.emplace_back(block);
742 blocks_.emplace_back(std::move(block));
748 return !operator==(rhs);
757 void set(
const string& format);
792 size_t getBlockSize(
size_t blockIndex,
size_t remainingSize)
const;
798 static string getDataLayoutTagName(
Record::Type type, uint32_t version,
size_t blockIndex);
802 const string& tagName,
804 uint32_t& formatVersion);
809 map<string, string>& inOutRecordFormatRegister,
811 uint32_t formatVersion,
813 const vector<const DataLayout*>& layouts);
815 static void getRecordFormats(
816 const map<string, string>& recordFormatRegister,
819 static unique_ptr<DataLayout> getDataLayout(
820 const map<string, string>& recordFormatRegister,
824 vector<ContentBlock> blocks_;
Specification of an audio content block.
Definition RecordFormat.h:374
uint8_t getChannelCount() const
Get the number of audio channels in each sample frame (not in the content block).
Definition RecordFormat.h:450
void setSampleCount(uint32_t sampleCount)
Set the number of audio sample frames in the content block.
Definition RecordFormat.h:462
string asString() const
Definition RecordFormat.cpp:778
uint8_t getBitsPerSample() const
Get the number of bits per audio sample.
Definition RecordFormat.h:440
AudioContentBlockSpec(const AudioContentBlockSpec &)=default
Default copy constructor.
bool isLittleEndian() const
Tell if the audio sample format is little endian.
Definition RecordFormat.h:432
bool isSampleBlockFormatDefined() const
Definition RecordFormat.cpp:831
size_t getPcmBlockSize() const
Assuming PCM, get the number of bytes for this content block, or ContentBlock::kSizeUnknown.
Definition RecordFormat.cpp:807
uint32_t getSampleCount() const
Get the number of audio sample frames in the content block.
Definition RecordFormat.h:458
void clear()
Clear/reset object to default values.
Definition RecordFormat.cpp:718
uint8_t getBytesPerSample() const
Get the number of bytes per audio sample.
Definition RecordFormat.h:444
uint8_t getSampleFrameStride() const
Number of bytes used by a group of synchronous audio samples, including padding.
Definition RecordFormat.cpp:925
uint32_t getSampleRate() const
Get the audio frame sample rate.
Definition RecordFormat.h:454
bool isIEEEFloat() const
Tell if the audio sample format is an IEEE float.
Definition RecordFormat.h:436
AudioFormat getAudioFormat() const
Get audio format.
Definition RecordFormat.h:422
AudioSampleFormat getSampleFormat() const
Get audio sample format.
Definition RecordFormat.h:426
size_t getBlockSize() const
Get the number of bytes for this content block, or ContentBlock::kSizeUnknown.
Definition RecordFormat.cpp:803
string getSampleFormatAsString() const
Get audio sample format as a string.
Definition RecordFormat.cpp:827
bool isCompatibleWith(const AudioContentBlockSpec &rhs) const
Tell if two audio block have identical audio formats.
Definition RecordFormat.cpp:821
static string getSampleFormatAsString(AudioSampleFormat sampleFormat)
Get an audio sample format as a string.
Definition RecordFormat.h:483
Specification of a VRS record content block.
Definition RecordFormat.h:509
size_t getBlockSize() const
Get the content block size, if available or calculable.
Definition RecordFormat.cpp:1069
ContentBlock(const ContentBlock &)=default
Default copy constructor.
string asString() const
Conversion to string, to store on disk & reconstruct later using constructor.
Definition RecordFormat.cpp:1039
const ImageContentBlockSpec & image() const
Get the image content spec. Requires the content block to be of type ContentType::IMAGE.
Definition RecordFormat.cpp:1111
ContentBlock(ContentType type=ContentType::EMPTY, size_t size=kSizeUnknown)
Very generic block description.
Definition RecordFormat.cpp:991
ContentType getContentType() const
Get the ContentType of the block.
Definition RecordFormat.h:592
string getCustomContentBlockFormat() const
Definition RecordFormat.h:598
const AudioContentBlockSpec & audio() const
Get the audio content spec. Requires the content block to be of type ContentType::AUDIO.
Definition RecordFormat.cpp:1116
RecordFormat operator+(const ContentBlock &) const
Assembly operator, to construct a RecordFormat for ContentBlock parts.
Definition RecordFormat.cpp:1107
ContentBlock(std::string codecName, uint8_t codecQuality, PixelFormat pixelFormat=PixelFormat::UNDEFINED, uint32_t width=0, uint32_t height=0, uint32_t stride=0, uint32_t stride2=0)
Image formats with custom codec encoding.
static const size_t kSizeUnknown
Special value used to represent an unknown block size.
Definition RecordFormat.h:512
Helper to identify a particular content block within a file.
Definition RecordFormat.h:641
RecordFormat string parsing helper class.
Definition RecordFormat.cpp:37
Definition RecordFormat.h:624
Specification of an image content block.
Definition RecordFormat.h:142
ImageContentBlockSpec & operator=(const ImageContentBlockSpec &)=default
Default copy assignment.
void set(ContentParser &parser)
When constructing from a string.
Definition RecordFormat.cpp:383
void clear()
Clear/reset object to default values.
Definition RecordFormat.cpp:340
uint32_t getDefaultStride2() const
Get default stride for planes N > 0, when stride2 isn't specified (minimum stride2 value)
Definition RecordFormat.cpp:589
uint8_t getCodecQuality() const
Definition RecordFormat.h:322
string getPixelFormatAsString() const
Get pixel format presented as a readable string, from which it can be reconstructed.
Definition RecordFormat.cpp:640
uint32_t getKeyFrameIndex() const
Definition RecordFormat.h:338
string asString() const
Definition RecordFormat.cpp:428
size_t getBytesPerPixel() const
Definition RecordFormat.h:310
uint32_t getHeight() const
Get image height, or 0 if unknown/unspecified.
Definition RecordFormat.h:268
string getImageFormatAsString() const
Get Image format as string.
Definition RecordFormat.cpp:644
uint32_t getPlaneHeight(uint32_t planeIndex) const
Definition RecordFormat.cpp:603
uint32_t getStride() const
Get image stride (number of bytes between rows) for the first plane.
Definition RecordFormat.cpp:648
PixelFormat getPixelFormat() const
Get Pixel format.
Definition RecordFormat.h:258
static string getPixelFormatAsString(PixelFormat pixelFormat)
Get pixel format presented as a readable string, from which it can be reconstructed.
Definition RecordFormat.h:348
const string & getCodecName() const
Definition RecordFormat.h:316
uint32_t getPlaneStride(uint32_t planeIndex) const
Definition RecordFormat.cpp:579
bool sanityCheckStrides() const
Definition RecordFormat.cpp:566
size_t getRawImageSize() const
Definition RecordFormat.cpp:626
uint32_t getRawStride() const
Definition RecordFormat.h:275
size_t getBlockSize() const
Definition RecordFormat.cpp:622
ImageContentBlockSpec core() const
Return base of format (no codec quality nor key frame info)
Definition RecordFormat.cpp:351
double getKeyFrameTimestamp() const
Get timestamp of the key frame of the group of frames this video frame belongs to.
Definition RecordFormat.h:332
uint32_t getDefaultStride() const
Get default stride for plane 0 when stride isn't specified (minimum stride value)
Definition RecordFormat.cpp:653
static bool isQualityValid(uint8_t quality)
Validate that a quality value is valid.
Definition RecordFormat.h:327
uint8_t getChannelCountPerPixel() const
Definition RecordFormat.h:303
ImageFormat getImageFormat() const
Get image format.
Definition RecordFormat.h:250
uint32_t getPlaneCount() const
Get the number of planes for this pixel format.
Definition RecordFormat.h:287
uint32_t getWidth() const
Get image width, or 0 if unknown/unspecified.
Definition RecordFormat.h:264
Type
Definition Record.h:90
Definition Compressor.cpp:113
map< pair< Record::Type, uint32_t >, RecordFormat > RecordFormatMap
Map a pair of record type/format version to a record format, for a particular stream.
Definition RecordFormat.h:631
PixelFormat
Pixel format type, then the image format is ImageFormat::RAW.
Definition RecordFormat.h:63
@ GREY12
uses 16 bit little-endian values. 4 most significant bits are unused and set to 0.
@ UNDEFINED
Unknown/unrecognized.
@ GREY10
uses 16 bit little-endian values. 6 most significant bits are unused and set to 0.
@ RGB8
3 uint8_t values, red + green + blue.
@ DEPTH32F
1 32 bit float value, representing a depth.
@ YUV_420_NV21
Y plane + half width/half height chroma plane with weaved V and U values.
@ RAW10
https://developer.android.com/reference/android/graphics/ImageFormat#RAW10
@ RAW10_BAYER_RGGB
10 bit per pixel, RGGB bayer pattern.
@ YUV_I420_PLANAR
same as YUV_I420_SPLIT, but more conventional name.
@ YUV_I420_SPLIT
3 uint8_t values, 4:2:0. The 3 planes are stored separately.
@ RGBA32F
1 32 bit float value.
@ BAYER8_RGGB
8 bit per pixel, RGGB bayer pattern.
@ RAW10_BAYER_BGGR
10 bit per pixel, BGGR bayer pattern.
@ RGB10
uses 16 bit little-endian values. 6 most significant bits are unused and set to 0.
@ RGBA8
4 uint8_t values, red + blue + green + alpha.
@ YUY2
4 uint8_t values, 4:2:2, single plane.
@ YUV_420_NV12
Y plane + half width/half height chroma plane with weaved U and V values.
@ RGB12
uses 16 bit little-endian values. 4 most significant bits are unused and set to 0.
@ BAYER8_BGGR
8 bit per pixel, BGGR bayer pattern.
@ RGB32F
1 32 bit float value.
@ GREY10PACKED
10 bit per pixel, packed in successive little-endian bits, in 40 bits blocks.
@ SCALAR64F
1 64 bit float value, representing high precision image data.
@ BGR8
3 uint8_t values, blue + green + red.
@ GREY16
uses 16 bit little-endian values.
AudioSampleFormat
Audio sample format, when the audio type is AudioFormat::PCM.
Definition RecordFormat.h:110
@ U32_LE
LPCM, unsigned, 32 bit little endian.
@ F64_BE
LPCM, 64 bit float big endian.
@ U16_BE
LPCM, unsigned, 16 bit big endian.
@ U32_BE
LPCM, unsigned, 32 bit big endian.
@ F64_LE
LPCM, 64 bit float little endian.
@ S32_BE
LPCM, signed, 32 bit big endian.
@ U8
LPCM, unsigned, 8 bit.
@ S16_BE
LPCM, signed, 16 bit big endian.
@ F32_LE
LPCM, 32 bit float little endian.
@ S24_LE
LPCM, signed, 24 bit little endian.
@ S16_LE
LPCM, signed, 16 bit little endian.
@ U24_BE
LPCM, unsigned, 24 bit big endian.
@ S24_BE
LPCM, signed, 24 bit big endian.
@ MU_LAW
mu-law PCM, 8 bit.
@ U24_LE
LPCM, unsigned, 24 bit little endian.
@ U16_LE
LPCM, unsigned, 16 bit little endian.
@ F32_BE
LPCM, 32 bit float big endian.
@ S32_LE
LPCM, signed, 32 bit little endian.
ImageFormat
Definition RecordFormat.h:49
@ UNDEFINED
Unknown/unspecified.
@ CUSTOM_CODEC
Images encoded with a custom or experimental codec.
@ VIDEO
Video codec encoded images.
AudioFormat
Audio format type.
Definition RecordFormat.h:99
@ OPUS
Audio data compressed using Opus. https://opus-codec.org/.
RecordableTypeId
VRS stream type or class identifier enum.
Definition StreamId.h:51
ContentType
Type of a record's block.
Definition RecordFormat.h:35
@ DATA_LAYOUT
DataLayout block.
@ CUSTOM
Custom format, or unknown/unspecified data format.
@ EMPTY
No data (internal).