24#include <vrs/Record.h>
25#include <vrs/VrsExport.h>
47VRS_API
ContentType toEnum<ContentType>(
const string& name);
65VRS_API
ImageFormat toEnum<ImageFormat>(
const string& name);
105VRS_API
PixelFormat toEnum<PixelFormat>(
const string& name);
118VRS_API
AudioFormat toEnum<AudioFormat>(
const string& name);
157 static constexpr uint8_t kQualityUndefined = 255;
158 static constexpr double kInvalidTimestamp = -1E-308;
166 double keyFrameTimestamp,
167 uint32_t keyFrameIndex);
176 uint32_t stride2 = 0,
177 string codecName = {},
178 uint8_t codecQuality = kQualityUndefined,
179 double keyFrameTimestamp = kInvalidTimestamp,
180 uint32_t keyFrameIndex = 0);
186 uint32_t height = 0);
201 uint8_t codecQuality = kQualityUndefined,
206 uint32_t stride2 = 0);
211 uint8_t codecQuality,
216 uint32_t stride2 = 0);
228 uint32_t stride2 = 0,
229 string codecName = {},
230 uint8_t codecQuality = kQualityUndefined,
231 double keyFrameTimestamp = kInvalidTimestamp,
232 uint32_t keyFrameIndex = 0);
244 string asString()
const;
248 size_t getBlockSize()
const;
252 size_t getRawImageSize()
const;
268 string getImageFormatAsString()
const;
275 string getPixelFormatAsString()
const;
285 uint32_t getStride()
const;
291 uint32_t getRawStride2()
const {
295 uint32_t getDefaultStride()
const;
297 uint32_t getDefaultStride2()
const;
301 return getPlaneCount(pixelFormat_);
306 uint32_t getPlaneStride(uint32_t planeIndex)
const;
310 uint32_t getPlaneHeight(uint32_t planeIndex)
const;
317 return getChannelCountPerPixel(pixelFormat_);
324 return getBytesPerPixel(pixelFormat_);
336 return isQualityValid(codecQuality_) ? codecQuality_ : kQualityUndefined;
341 return quality <= 100;
346 return keyFrameTimestamp_;
352 return keyFrameIndex_;
356 static uint8_t getChannelCountPerPixel(
PixelFormat pixel);
362 return toString(pixelFormat);
366 static uint32_t getPlaneCount(
PixelFormat pixelFormat);
370 bool sanityCheckStrides()
const;
374 PixelFormat pixelFormat_{PixelFormat::UNDEFINED};
378 uint32_t stride2_{0};
381 double keyFrameTimestamp_{kInvalidTimestamp};
382 uint32_t keyFrameIndex_{0};
383 uint8_t codecQuality_{kQualityUndefined};
398 uint8_t channelCount = 0,
399 uint8_t sampleFrameStride = 0,
400 uint32_t sampleFrameRate = 0,
401 uint32_t sampleFrameCount = 0,
402 uint8_t stereoPairCount = 0);
420 return !operator==(rhs);
424 string asString()
const;
427 size_t getBlockSize()
const;
430 size_t getPcmBlockSize()
const;
440 return sampleFormat_;
443 string getSampleFormatAsString()
const;
446 return isLittleEndian(sampleFormat_);
450 return isIEEEFloat(sampleFormat_);
454 return getBitsPerSample(sampleFormat_);
458 return (getBitsPerSample(sampleFormat_) + 7) / 8;
461 uint8_t getSampleFrameStride()
const;
464 return channelCount_;
468 return sampleFrameRate_;
472 return sampleFrameCount_;
476 sampleFrameCount_ = sampleCount;
479 uint8_t getStereoPairCount()
const {
480 return stereoPairCount_;
485 bool isSampleBlockFormatDefined()
const;
488 static bool isLittleEndian(AudioSampleFormat sampleFormat);
490 static bool isIEEEFloat(AudioSampleFormat sampleFormat);
492 static uint8_t getBitsPerSample(AudioSampleFormat sampleFormat);
494 static uint8_t getBytesPerSample(AudioSampleFormat sampleFormat);
497 return toString(sampleFormat);
502 AudioSampleFormat sampleFormat_{};
503 uint8_t sampleFrameStride_{};
504 uint8_t channelCount_{};
505 uint32_t sampleFrameRate_{};
506 uint32_t sampleFrameCount_{};
507 uint8_t stereoPairCount_{};
538 std::string codecName,
539 uint8_t codecQuality,
544 uint32_t stride2 = 0);
552 uint32_t stride2 = 0);
557 size_t size = kSizeUnknown)
noexcept;
560 double keyFrameTimestamp,
561 uint32_t keyFrameIndex);
571 uint8_t numChannels = 0,
572 uint8_t sampleFrameStride = 0,
573 uint32_t sampleRate = 0,
574 uint32_t sampleCount = 0,
575 uint8_t stereoPairCount = 0);
583 : contentType_{other.contentType_}, size_{size} {
584 if (contentType_ == ContentType::IMAGE) {
585 imageSpec_ = other.imageSpec_;
586 }
else if (contentType_ == ContentType::AUDIO) {
587 audioSpec_ = other.audioSpec_;
588 }
else if (contentType_ == ContentType::CUSTOM) {
589 customContentBlockFormat_ = other.customContentBlockFormat_;
593 ~ContentBlock() =
default;
595 ContentBlock& operator=(
const ContentBlock& rhs) =
default;
596 ContentBlock& operator=(ContentBlock&& rhs)
noexcept =
default;
599 string asString()
const;
602 size_t getBlockSize()
const;
612 return customContentBlockFormat_;
618 return !operator==(rhs);
622 RecordFormat operator+(
const ContentBlock&)
const;
625 const ImageContentBlockSpec& image()
const;
627 const AudioContentBlockSpec& audio()
const;
630 ContentType contentType_ = ContentType::EMPTY;
631 size_t size_ = kSizeUnknown;
632 ImageContentBlockSpec imageSpec_;
633 AudioContentBlockSpec audioSpec_;
634 string customContentBlockFormat_;
639 explicit CustomContentBlock(
const string& customContentBlockFormat,
size_t size = kSizeUnknown);
659 uint32_t formatVersionIn,
662 recordType(recordTypeIn),
663 formatVersion(formatVersionIn),
664 blockIndex(blockIndexIn) {}
674 uint32_t getFormatVersion()
const {
675 return formatVersion;
678 size_t getBlockIndex()
const {
685 uint32_t formatVersion;
724 blocks_.emplace_back(block);
728 blocks_.emplace_back(std::move(block));
732 blocks_.emplace_back(first);
733 blocks_.emplace_back(second);
737 blocks_.emplace_back(std::move(first));
738 blocks_.emplace_back(std::move(second));
745 blocks_.emplace_back(type, size);
750 blocks_.emplace_back(block);
755 blocks_.emplace_back(std::move(block));
761 return !operator==(rhs);
770 void set(
const string& format);
773 string asString()
const;
777 size_t getRecordSize()
const;
780 size_t getUsedBlocksCount()
const;
784 size_t getBlocksOfTypeCount(ContentType type)
const;
788 const ContentBlock& getContentBlock(
size_t index)
const;
792 return getContentBlock(0);
798 size_t getRemainingBlocksSize(
size_t firstBlock)
const;
805 size_t getBlockSize(
size_t blockIndex,
size_t remainingSize)
const;
810 static string getRecordFormatTagName(
Record::Type recordType, uint32_t formatVersion);
811 static string getDataLayoutTagName(
Record::Type type, uint32_t version,
size_t blockIndex);
814 static bool parseRecordFormatTagName(
815 const string& tagName,
817 uint32_t& formatVersion);
821 static bool addRecordFormat(
822 map<string, string>& inOutRecordFormatRegister,
824 uint32_t formatVersion,
826 const vector<const DataLayout*>& layouts);
828 static void getRecordFormats(
829 const map<string, string>& recordFormatRegister,
832 static unique_ptr<DataLayout> getDataLayout(
833 const map<string, string>& recordFormatRegister,
837 vector<ContentBlock> blocks_;
Specification of an audio content block.
Definition RecordFormat.h:387
uint8_t getChannelCount() const
Get the number of audio channels in each sample frame (not in the content block).
Definition RecordFormat.h:463
void setSampleCount(uint32_t sampleCount)
Set the number of audio sample frames in the content block.
Definition RecordFormat.h:475
uint8_t getBitsPerSample() const
Get the number of bits per audio sample.
Definition RecordFormat.h:453
AudioContentBlockSpec(const AudioContentBlockSpec &)=default
Default copy constructor.
bool isLittleEndian() const
Tell if the audio sample format is little endian.
Definition RecordFormat.h:445
uint32_t getSampleCount() const
Get the number of audio sample frames in the content block.
Definition RecordFormat.h:471
uint8_t getBytesPerSample() const
Get the number of bytes per audio sample.
Definition RecordFormat.h:457
uint32_t getSampleRate() const
Get the audio frame sample rate.
Definition RecordFormat.h:467
bool isIEEEFloat() const
Tell if the audio sample format is an IEEE float.
Definition RecordFormat.h:449
AudioFormat getAudioFormat() const
Get audio format.
Definition RecordFormat.h:435
AudioSampleFormat getSampleFormat() const
Get audio sample format.
Definition RecordFormat.h:439
static string getSampleFormatAsString(AudioSampleFormat sampleFormat)
Get an audio sample format as a string.
Definition RecordFormat.h:496
Specification of a VRS record content block.
Definition RecordFormat.h:522
ContentBlock(const ContentBlock &)=default
Default copy constructor.
ContentType getContentType() const
Get the ContentType of the block.
Definition RecordFormat.h:605
string getCustomContentBlockFormat() const
Definition RecordFormat.h:611
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:525
Helper to identify a particular content block within a file.
Definition RecordFormat.h:654
RecordFormat string parsing helper class.
Definition RecordFormat.cpp:37
Definition RecordFormat.h:637
Specification of an image content block.
Definition RecordFormat.h:155
ImageContentBlockSpec & operator=(const ImageContentBlockSpec &)=default
Default copy assignment.
uint8_t getCodecQuality() const
Definition RecordFormat.h:335
uint32_t getKeyFrameIndex() const
Definition RecordFormat.h:351
size_t getBytesPerPixel() const
Definition RecordFormat.h:323
uint32_t getHeight() const
Get image height, or 0 if unknown/unspecified.
Definition RecordFormat.h:281
PixelFormat getPixelFormat() const
Get Pixel format.
Definition RecordFormat.h:271
static string getPixelFormatAsString(PixelFormat pixelFormat)
Get pixel format presented as a readable string, from which it can be reconstructed.
Definition RecordFormat.h:361
const string & getCodecName() const
Definition RecordFormat.h:329
uint32_t getRawStride() const
Definition RecordFormat.h:288
double getKeyFrameTimestamp() const
Get timestamp of the key frame of the group of frames this video frame belongs to.
Definition RecordFormat.h:345
static bool isQualityValid(uint8_t quality)
Validate that a quality value is valid.
Definition RecordFormat.h:340
uint8_t getChannelCountPerPixel() const
Definition RecordFormat.h:316
uint32_t getPlaneCount() const
Get the number of planes for this pixel format.
Definition RecordFormat.h:300
uint32_t getWidth() const
Get image width, or 0 if unknown/unspecified.
Definition RecordFormat.h:277
Type
Definition Record.h:91
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:644
PixelFormat
Pixel format type, then the image format is ImageFormat::RAW.
Definition RecordFormat.h:68
@ GREY12
uses 16 bit little-endian values. 4 most significant bits are unused and set to 0.
@ 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.
@ BAYER8_GBRG
8 bit per pixel, GBRG bayer pattern.
@ RGB10
uses 16 bit little-endian values. 6 most significant bits are unused and set to 0.
@ BAYER10_GBRG
10 bit per pixel, GBRG bayer pattern.
@ 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:121
@ 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:52
@ 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:108
@ 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:36
@ DATA_LAYOUT
DataLayout block.
@ CUSTOM
Custom format, or unknown/unspecified data format.
@ EMPTY
No data (internal).