include/MediaEnumerations.h

include/MediaEnumerations.h File Reference

Namespaces

Name
Acl

Classes

Name
structfmt::formatter< Acl::FieldOrder >
structfmt::formatter< Acl::AudioChannelLayout >

Source code

// Copyright (c) 2024, Ateliere. All rights reserved.

#pragma once

#include <cstdint>
#include <ostream>

#include <fmt/format.h>

namespace Acl {

constexpr uint32_t makeFourCC(char a, char b, char c, char d) {
    return static_cast<uint32_t>(a) + (static_cast<uint32_t>(b) << 8) + (static_cast<uint32_t>(c) << 16) +
           (static_cast<uint32_t>(d) << 24);
}

enum PixelFormat : uint32_t {
    kUnknown = 0,                                // Unknown format
    kNv12 = Acl::makeFourCC('N', 'V', '1', '2'), // 4:2:0 format with Y plane followed by UVUVUV.. plane
    kUyvy = Acl::makeFourCC('U', 'Y', 'V', 'Y'), // 4:2:2 format with packed UYVY macropixels
    kP010 = Acl::makeFourCC('P', '0', '1', '0'), // 4:2:0 P016 with data in the 10 MSB
    kP016 = Acl::makeFourCC('P', '0', '1', '6'), // 4:2:0 format with 16 bit words, Y plane followed by UVUVUV.. plane
    kP210 = Acl::makeFourCC('P', '2', '1', '0'), // 4:2:2 P216 with data in the 10 MSB
    kP216 = Acl::makeFourCC('P', '2', '1', '6'), // 4:2:2 format with 16 bit words, Y plane followed by UVUVUV.. plane
    kRgba =
        Acl::makeFourCC('R', 'G', 'B', 'A'), // 4:4:4:4 RGB format, 8 bit per channel, ordered RGBARGBARG.. in memory
    kV210 = Acl::makeFourCC('V', '2', '1', '0'), // 4:2:2 packed format with 10 bit per component
    kRgba64Le =
        Acl::makeFourCC('R', 'G', 'B', 64) // 16 bit per component, ordered as RGBA in memory with little endian words.
};

std::ostream& operator<<(std::ostream& stream, const PixelFormat& pixelFormat);

enum class FieldOrder : uint8_t {
    kProgressive,     // No fields, i.e. progressive
    kTopFieldFirst,   // Interlaced frame with interleaved fields, top field first
    kBottomFieldFirst // Interlaced frame with interleaved fields, bottom field first
};

std::ostream& operator<<(std::ostream& stream, const FieldOrder& fieldOrder);

enum class AudioFormat : uint16_t {
    kInt16,     // 16 bits signed integer per sample
    kInt24In32, // 24 bits per sample, stored in the LSB of a 32-bit signed integer
    kFloat32    // 32 bit float per sample
};

std::ostream& operator<<(std::ostream& stream, const AudioFormat& audioFormat);

enum class AudioChannelLayout : uint8_t {
    kPlanar,     // The audio samples of each channel are in separate "planes", first comes all channel 1's samples,
                 // then channel 2 and so on.
    kInterleaved // The audio samples are interleaved, first comes sample one of each channel, then sample two, and
                 // so on.
};

std::ostream& operator<<(std::ostream& stream, const AudioChannelLayout& audioChannelLayout);

} // namespace Acl

template <> struct fmt::formatter<Acl::FieldOrder> : formatter<std::string> {
    template <typename FormatContext> auto format(const Acl::FieldOrder fieldOrder, FormatContext& ctx) {
        std::string value;
        switch (fieldOrder) {
        case Acl::FieldOrder::kProgressive:
            value = "progressive";
            break;
        case Acl::FieldOrder::kTopFieldFirst:
            value = "top_field_first";
            break;
        case Acl::FieldOrder::kBottomFieldFirst:
            value = "bottom_field_first";
            break;
        }
        return formatter<std::string>::format(value, ctx);
    }
};

template <> struct fmt::formatter<Acl::AudioChannelLayout> : formatter<std::string> {
    template <typename FormatContext>
    auto format(const Acl::AudioChannelLayout audioChannelLayout, FormatContext& ctx) {
        std::string value;
        switch (audioChannelLayout) {
        case Acl::AudioChannelLayout::kPlanar:
            value = "planar";
            break;
        case Acl::AudioChannelLayout::kInterleaved:
            value = "interleaved";
            break;
        }
        return formatter<std::string>::format(value, ctx);
    }
};