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);
155class VRS_API ImageContentBlockSpec {
157 static constexpr uint8_t kQualityUndefined = 255;
158 static constexpr double kInvalidTimestamp = -1E-308;
160 ImageContentBlockSpec() =
default;
162 ImageContentBlockSpec(
const ImageContentBlockSpec&) =
default;
163 ImageContentBlockSpec(ImageContentBlockSpec&&)
noexcept =
default;
164 ImageContentBlockSpec(
165 ImageContentBlockSpec imageSpec,
166 double keyFrameTimestamp,
167 uint32_t keyFrameIndex);
170 ImageContentBlockSpec(
176 uint32_t stride2 = 0,
177 string codecName = {},
178 uint8_t codecQuality = kQualityUndefined,
179 double keyFrameTimestamp = kInvalidTimestamp,
180 uint32_t keyFrameIndex = 0);
183 ImageContentBlockSpec(
186 uint32_t height = 0);
189 ImageContentBlockSpec(
198 ImageContentBlockSpec(
201 uint8_t codecQuality = kQualityUndefined,
206 uint32_t stride2 = 0);
209 ImageContentBlockSpec(
211 uint8_t codecQuality,
216 uint32_t stride2 = 0);
219 explicit ImageContentBlockSpec(
const string& formatStr);
221 ~ImageContentBlockSpec() =
default;
228 uint32_t stride2 = 0,
229 string codecName = {},
230 uint8_t codecQuality = kQualityUndefined,
231 double keyFrameTimestamp = kInvalidTimestamp,
232 uint32_t keyFrameIndex = 0);
240 ImageContentBlockSpec
core()
const;
255 ImageContentBlockSpec&
operator=(
const ImageContentBlockSpec&) =
default;
256 ImageContentBlockSpec&
operator=(ImageContentBlockSpec&&) noexcept = default;
259 bool operator==(const ImageContentBlockSpec& rhs) const;
260 bool operator!=(const ImageContentBlockSpec& rhs) 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;
306 uint32_t getPlaneStride(uint32_t planeIndex)
const;
310 uint32_t getPlaneHeight(uint32_t planeIndex)
const;
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};
387class VRS_API AudioContentBlockSpec {
389 AudioContentBlockSpec() =
default;
392 AudioContentBlockSpec(AudioContentBlockSpec&&) noexcept = default;
394 explicit AudioContentBlockSpec(
AudioFormat audioFormat, uint8_t channelCount = 0);
395 AudioContentBlockSpec(
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);
403 ~AudioContentBlockSpec() = default;
407 explicit AudioContentBlockSpec(const
string& formatStr);
415 AudioContentBlockSpec& operator=(const AudioContentBlockSpec&) = default;
416 AudioContentBlockSpec& operator=(AudioContentBlockSpec&&) noexcept = default;
418 bool operator==(const AudioContentBlockSpec& rhs) const;
419 bool operator!=(const AudioContentBlockSpec& rhs)
const {
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;
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);
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);
640 explicit CustomContentBlock(
size_t size =
kSizeUnknown);
654class VRS_API ContentBlockId {
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;
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
void set(ContentParser &parser)
Definition RecordFormat.cpp:738
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
void clear()
Clear/reset object to default values.
Definition RecordFormat.cpp:729
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.
ContentBlock(ContentType type=ContentType::EMPTY, size_t size=kSizeUnknown)
Very generic block description.
Definition RecordFormat.cpp:1002
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:39
Specification of an image content block.
Definition RecordFormat.h:155
ImageContentBlockSpec & operator=(const ImageContentBlockSpec &)=default
Default copy assignment.
void set(ContentParser &parser)
When constructing from a string.
Definition RecordFormat.cpp:390
void clear()
Clear/reset object to default values.
Definition RecordFormat.cpp:347
uint8_t getCodecQuality() const
Definition RecordFormat.h:335
uint32_t getKeyFrameIndex() const
Definition RecordFormat.h:351
string asString() const
Definition RecordFormat.cpp:435
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
size_t getRawImageSize() const
Definition RecordFormat.cpp:637
uint32_t getRawStride() const
Definition RecordFormat.h:288
size_t getBlockSize() const
Definition RecordFormat.cpp:633
ImageContentBlockSpec core() const
Return base of format (no codec quality nor key frame info).
Definition RecordFormat.cpp:358
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
ImageFormat getImageFormat() const
Get image format.
Definition RecordFormat.h:263
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:94
Definition Compressor.cpp:130
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.
Definition RecordFormat.h:81
@ UNDEFINED
Unknown/unrecognized.
Definition RecordFormat.h:69
@ GREY10
uses 16 bit little-endian values. 6 most significant bits are unused and set to 0.
Definition RecordFormat.h:80
@ RGB8
3 uint8_t values, red + green + blue.
Definition RecordFormat.h:74
@ DEPTH32F
1 32 bit float value, representing a depth.
Definition RecordFormat.h:73
@ RGB_IR_RAW_4X4
Definition RecordFormat.h:86
@ YUV_420_NV21
Y plane + half width/half height chroma plane with weaved V and U values.
Definition RecordFormat.h:93
@ RAW10
https://developer.android.com/reference/android/graphics/ImageFormat#RAW10
Definition RecordFormat.h:90
@ RAW10_BAYER_RGGB
10 bit per pixel, RGGB bayer pattern.
Definition RecordFormat.h:91
@ YUV_I420_PLANAR
same as YUV_I420_SPLIT, but more conventional name.
Definition RecordFormat.h:76
@ YUV_I420_SPLIT
3 uint8_t values, 4:2:0. The 3 planes are stored separately.
Definition RecordFormat.h:75
@ RGBA32F
1 32 bit float value.
Definition RecordFormat.h:88
@ BAYER8_RGGB
8 bit per pixel, RGGB bayer pattern.
Definition RecordFormat.h:89
@ RAW10_BAYER_BGGR
10 bit per pixel, BGGR bayer pattern.
Definition RecordFormat.h:92
@ BAYER8_GBRG
8 bit per pixel, GBRG bayer pattern.
Definition RecordFormat.h:98
@ RGB10
uses 16 bit little-endian values. 6 most significant bits are unused and set to 0.
Definition RecordFormat.h:78
@ BAYER10_GBRG
10 bit per pixel, GBRG bayer pattern.
Definition RecordFormat.h:97
@ RGBA8
4 uint8_t values, red + blue + green + alpha.
Definition RecordFormat.h:77
@ GREY8
1 uint8_t.
Definition RecordFormat.h:71
@ YUY2
4 uint8_t values, 4:2:2, single plane.
Definition RecordFormat.h:85
@ YUV_420_NV12
Y plane + half width/half height chroma plane with weaved U and V values.
Definition RecordFormat.h:94
@ RGB12
uses 16 bit little-endian values. 4 most significant bits are unused and set to 0.
Definition RecordFormat.h:79
@ BAYER8_BGGR
8 bit per pixel, BGGR bayer pattern.
Definition RecordFormat.h:96
@ RGB32F
1 32 bit float value.
Definition RecordFormat.h:83
@ GREY10PACKED
10 bit per pixel, packed in successive little-endian bits, in 40 bits blocks.
Definition RecordFormat.h:95
@ SCALAR64F
1 64 bit float value, representing high precision image data.
Definition RecordFormat.h:84
@ BGR8
3 uint8_t values, blue + green + red.
Definition RecordFormat.h:72
@ GREY16
uses 16 bit little-endian values.
Definition RecordFormat.h:82
AudioSampleFormat
Audio sample format, when the audio type is AudioFormat::PCM.
Definition RecordFormat.h:121
@ U32_LE
LPCM, unsigned, 32 bit little endian.
Definition RecordFormat.h:136
@ F64_BE
LPCM, 64 bit float big endian.
Definition RecordFormat.h:142
@ U16_BE
LPCM, unsigned, 16 bit big endian.
Definition RecordFormat.h:130
@ U32_BE
LPCM, unsigned, 32 bit big endian.
Definition RecordFormat.h:138
@ F64_LE
LPCM, 64 bit float little endian.
Definition RecordFormat.h:141
@ S32_BE
LPCM, signed, 32 bit big endian.
Definition RecordFormat.h:137
@ U8
LPCM, unsigned, 8 bit.
Definition RecordFormat.h:124
@ S16_BE
LPCM, signed, 16 bit big endian.
Definition RecordFormat.h:129
@ F32_LE
LPCM, 32 bit float little endian.
Definition RecordFormat.h:139
@ S24_LE
LPCM, signed, 24 bit little endian.
Definition RecordFormat.h:131
@ S16_LE
LPCM, signed, 16 bit little endian.
Definition RecordFormat.h:127
@ U24_BE
LPCM, unsigned, 24 bit big endian.
Definition RecordFormat.h:134
@ S24_BE
LPCM, signed, 24 bit big endian.
Definition RecordFormat.h:133
@ S8
LPCM, signed, 8 bit.
Definition RecordFormat.h:123
@ MU_LAW
mu-law PCM, 8 bit.
Definition RecordFormat.h:126
@ U24_LE
LPCM, unsigned, 24 bit little endian.
Definition RecordFormat.h:132
@ U16_LE
LPCM, unsigned, 16 bit little endian.
Definition RecordFormat.h:128
@ F32_BE
LPCM, 32 bit float big endian.
Definition RecordFormat.h:140
@ A_LAW
a-law PCM, 8 bit.
Definition RecordFormat.h:125
@ S32_LE
LPCM, signed, 32 bit little endian.
Definition RecordFormat.h:135
ImageFormat
Definition RecordFormat.h:52
@ UNDEFINED
Unknown/unspecified.
Definition RecordFormat.h:53
@ CUSTOM_CODEC
Images encoded with a custom or experimental codec.
Definition RecordFormat.h:59
@ PNG
PNG data.
Definition RecordFormat.h:56
@ RAW
Raw pixel data.
Definition RecordFormat.h:54
@ JPG
JPEG data.
Definition RecordFormat.h:55
@ JXL
JPEG-XL data.
Definition RecordFormat.h:58
@ VIDEO
Video codec encoded images.
Definition RecordFormat.h:57
AudioFormat
Audio format type.
Definition RecordFormat.h:108
@ PCM
Raw PCM audio data.
Definition RecordFormat.h:110
@ OPUS
Audio data compressed using Opus. https://opus-codec.org/.
Definition RecordFormat.h:111
RecordableTypeId
VRS stream type or class identifier enum.
Definition StreamId.h:51
ContentType
Type of a record's block.
Definition RecordFormat.h:36
@ IMAGE
Image block.
Definition RecordFormat.h:40
@ DATA_LAYOUT
DataLayout block.
Definition RecordFormat.h:39
@ CUSTOM
Custom format, or unknown/unspecified data format.
Definition RecordFormat.h:37
@ EMPTY
No data (internal).
Definition RecordFormat.h:38
@ AUDIO
Audio block.
Definition RecordFormat.h:41
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