24#include <vrs/Record.h>
25#include <vrs/VrsExport.h>
147 static constexpr uint8_t kQualityUndefined = 255;
148 static constexpr double kInvalidTimestamp = -1E-308;
156 double keyFrameTimestamp,
157 uint32_t keyFrameIndex);
166 uint32_t stride2 = 0,
167 string codecName = {},
168 uint8_t codecQuality = kQualityUndefined,
169 double keyFrameTimestamp = kInvalidTimestamp,
170 uint32_t keyFrameIndex = 0);
176 uint32_t height = 0);
191 uint8_t codecQuality = kQualityUndefined,
196 uint32_t stride2 = 0);
201 uint8_t codecQuality,
206 uint32_t stride2 = 0);
218 uint32_t stride2 = 0,
219 string codecName = {},
220 uint8_t codecQuality = kQualityUndefined,
221 double keyFrameTimestamp = kInvalidTimestamp,
222 uint32_t keyFrameIndex = 0);
234 string asString()
const;
238 size_t getBlockSize()
const;
242 size_t getRawImageSize()
const;
258 string getImageFormatAsString()
const;
265 string getPixelFormatAsString()
const;
275 uint32_t getStride()
const;
281 uint32_t getRawStride2()
const {
285 uint32_t getDefaultStride()
const;
287 uint32_t getDefaultStride2()
const;
291 return getPlaneCount(pixelFormat_);
296 uint32_t getPlaneStride(uint32_t planeIndex)
const;
300 uint32_t getPlaneHeight(uint32_t planeIndex)
const;
307 return getChannelCountPerPixel(pixelFormat_);
314 return getBytesPerPixel(pixelFormat_);
326 return isQualityValid(codecQuality_) ? codecQuality_ : kQualityUndefined;
331 return quality <= 100;
336 return keyFrameTimestamp_;
342 return keyFrameIndex_;
346 static uint8_t getChannelCountPerPixel(
PixelFormat pixel);
352 return toString(pixelFormat);
356 static uint32_t getPlaneCount(
PixelFormat pixelFormat);
360 bool sanityCheckStrides()
const;
364 PixelFormat pixelFormat_{PixelFormat::UNDEFINED};
368 uint32_t stride2_{0};
371 double keyFrameTimestamp_{kInvalidTimestamp};
372 uint32_t keyFrameIndex_{0};
373 uint8_t codecQuality_{kQualityUndefined};
388 uint8_t channelCount = 0,
389 uint8_t sampleFrameStride = 0,
390 uint32_t sampleFrameRate = 0,
391 uint32_t sampleFrameCount = 0,
392 uint8_t stereoPairCount = 0);
410 return !operator==(rhs);
414 string asString()
const;
417 size_t getBlockSize()
const;
420 size_t getPcmBlockSize()
const;
430 return sampleFormat_;
433 string getSampleFormatAsString()
const;
436 return isLittleEndian(sampleFormat_);
440 return isIEEEFloat(sampleFormat_);
444 return getBitsPerSample(sampleFormat_);
448 return (getBitsPerSample(sampleFormat_) + 7) / 8;
451 uint8_t getSampleFrameStride()
const;
454 return channelCount_;
458 return sampleFrameRate_;
462 return sampleFrameCount_;
466 sampleFrameCount_ = sampleCount;
469 uint8_t getStereoPairCount()
const {
470 return stereoPairCount_;
475 bool isSampleBlockFormatDefined()
const;
478 static bool isLittleEndian(AudioSampleFormat sampleFormat);
480 static bool isIEEEFloat(AudioSampleFormat sampleFormat);
482 static uint8_t getBitsPerSample(AudioSampleFormat sampleFormat);
484 static uint8_t getBytesPerSample(AudioSampleFormat sampleFormat);
487 return toString(sampleFormat);
492 AudioSampleFormat sampleFormat_{};
493 uint8_t sampleFrameStride_{};
494 uint8_t channelCount_{};
495 uint32_t sampleFrameRate_{};
496 uint32_t sampleFrameCount_{};
497 uint8_t stereoPairCount_{};
528 std::string codecName,
529 uint8_t codecQuality,
534 uint32_t stride2 = 0);
542 uint32_t stride2 = 0);
547 size_t size = kSizeUnknown)
noexcept;
550 double keyFrameTimestamp,
551 uint32_t keyFrameIndex);
561 uint8_t numChannels = 0,
562 uint8_t sampleFrameStride = 0,
563 uint32_t sampleRate = 0,
564 uint32_t sampleCount = 0,
565 uint8_t stereoPairCount = 0);
573 : contentType_{other.contentType_}, size_{size} {
574 if (contentType_ == ContentType::IMAGE) {
575 imageSpec_ = other.imageSpec_;
576 }
else if (contentType_ == ContentType::AUDIO) {
577 audioSpec_ = other.audioSpec_;
578 }
else if (contentType_ == ContentType::CUSTOM) {
579 customContentBlockFormat_ = other.customContentBlockFormat_;
583 ~ContentBlock() =
default;
585 ContentBlock& operator=(
const ContentBlock& rhs) =
default;
586 ContentBlock& operator=(ContentBlock&& rhs)
noexcept =
default;
589 string asString()
const;
592 size_t getBlockSize()
const;
602 return customContentBlockFormat_;
608 return !operator==(rhs);
612 RecordFormat operator+(
const ContentBlock&)
const;
615 const ImageContentBlockSpec& image()
const;
617 const AudioContentBlockSpec& audio()
const;
620 ContentType contentType_ = ContentType::EMPTY;
621 size_t size_ = kSizeUnknown;
622 ImageContentBlockSpec imageSpec_;
623 AudioContentBlockSpec audioSpec_;
624 string customContentBlockFormat_;
629 explicit CustomContentBlock(
const string& customContentBlockFormat,
size_t size = kSizeUnknown);
649 uint32_t formatVersionIn,
652 recordType(recordTypeIn),
653 formatVersion(formatVersionIn),
654 blockIndex(blockIndexIn) {}
664 uint32_t getFormatVersion()
const {
665 return formatVersion;
668 size_t getBlockIndex()
const {
675 uint32_t formatVersion;
714 blocks_.emplace_back(block);
718 blocks_.emplace_back(std::move(block));
722 blocks_.emplace_back(first);
723 blocks_.emplace_back(second);
727 blocks_.emplace_back(std::move(first));
728 blocks_.emplace_back(std::move(second));
735 blocks_.emplace_back(type, size);
740 blocks_.emplace_back(block);
745 blocks_.emplace_back(std::move(block));
751 return !operator==(rhs);
760 void set(
const string& format);
763 string asString()
const;
767 size_t getRecordSize()
const;
770 size_t getUsedBlocksCount()
const;
774 size_t getBlocksOfTypeCount(ContentType type)
const;
778 const ContentBlock& getContentBlock(
size_t index)
const;
782 return getContentBlock(0);
788 size_t getRemainingBlocksSize(
size_t firstBlock)
const;
795 size_t getBlockSize(
size_t blockIndex,
size_t remainingSize)
const;
800 static string getRecordFormatTagName(
Record::Type recordType, uint32_t formatVersion);
801 static string getDataLayoutTagName(
Record::Type type, uint32_t version,
size_t blockIndex);
804 static bool parseRecordFormatTagName(
805 const string& tagName,
807 uint32_t& formatVersion);
811 static bool addRecordFormat(
812 map<string, string>& inOutRecordFormatRegister,
814 uint32_t formatVersion,
816 const vector<const DataLayout*>& layouts);
818 static void getRecordFormats(
819 const map<string, string>& recordFormatRegister,
822 static unique_ptr<DataLayout> getDataLayout(
823 const map<string, string>& recordFormatRegister,
827 vector<ContentBlock> blocks_;
Specification of an audio content block.
Definition RecordFormat.h:377
uint8_t getChannelCount() const
Get the number of audio channels in each sample frame (not in the content block).
Definition RecordFormat.h:453
void setSampleCount(uint32_t sampleCount)
Set the number of audio sample frames in the content block.
Definition RecordFormat.h:465
uint8_t getBitsPerSample() const
Get the number of bits per audio sample.
Definition RecordFormat.h:443
AudioContentBlockSpec(const AudioContentBlockSpec &)=default
Default copy constructor.
bool isLittleEndian() const
Tell if the audio sample format is little endian.
Definition RecordFormat.h:435
uint32_t getSampleCount() const
Get the number of audio sample frames in the content block.
Definition RecordFormat.h:461
uint8_t getBytesPerSample() const
Get the number of bytes per audio sample.
Definition RecordFormat.h:447
uint32_t getSampleRate() const
Get the audio frame sample rate.
Definition RecordFormat.h:457
bool isIEEEFloat() const
Tell if the audio sample format is an IEEE float.
Definition RecordFormat.h:439
AudioFormat getAudioFormat() const
Get audio format.
Definition RecordFormat.h:425
AudioSampleFormat getSampleFormat() const
Get audio sample format.
Definition RecordFormat.h:429
static string getSampleFormatAsString(AudioSampleFormat sampleFormat)
Get an audio sample format as a string.
Definition RecordFormat.h:486
Specification of a VRS record content block.
Definition RecordFormat.h:512
ContentBlock(const ContentBlock &)=default
Default copy constructor.
ContentType getContentType() const
Get the ContentType of the block.
Definition RecordFormat.h:595
string getCustomContentBlockFormat() const
Definition RecordFormat.h:601
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:515
Helper to identify a particular content block within a file.
Definition RecordFormat.h:644
RecordFormat string parsing helper class.
Definition RecordFormat.cpp:37
Definition RecordFormat.h:627
Specification of an image content block.
Definition RecordFormat.h:145
ImageContentBlockSpec & operator=(const ImageContentBlockSpec &)=default
Default copy assignment.
uint8_t getCodecQuality() const
Definition RecordFormat.h:325
uint32_t getKeyFrameIndex() const
Definition RecordFormat.h:341
size_t getBytesPerPixel() const
Definition RecordFormat.h:313
uint32_t getHeight() const
Get image height, or 0 if unknown/unspecified.
Definition RecordFormat.h:271
PixelFormat getPixelFormat() const
Get Pixel format.
Definition RecordFormat.h:261
static string getPixelFormatAsString(PixelFormat pixelFormat)
Get pixel format presented as a readable string, from which it can be reconstructed.
Definition RecordFormat.h:351
const string & getCodecName() const
Definition RecordFormat.h:319
uint32_t getRawStride() const
Definition RecordFormat.h:278
double getKeyFrameTimestamp() const
Get timestamp of the key frame of the group of frames this video frame belongs to.
Definition RecordFormat.h:335
static bool isQualityValid(uint8_t quality)
Validate that a quality value is valid.
Definition RecordFormat.h:330
uint8_t getChannelCountPerPixel() const
Definition RecordFormat.h:306
uint32_t getPlaneCount() const
Get the number of planes for this pixel format.
Definition RecordFormat.h:290
uint32_t getWidth() const
Get image width, or 0 if unknown/unspecified.
Definition RecordFormat.h:267
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:634
PixelFormat
Pixel format type, then the image format is ImageFormat::RAW.
Definition RecordFormat.h:64
@ 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:113
@ 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:50
@ 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:102
@ 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).