/* MediaMtx (C++) - H264 helpers (MediaMTX uses mediacommon/pkg/codecs/h264) */ #pragma once #include #include #include "../../unit/unit.h" namespace mtx { namespace h264 { enum NaluType { NALU_NON_IDR = 1, NALU_IDR = 5, NALU_SEI = 6, NALU_SPS = 7, NALU_PPS = 8, NALU_AUD = 9, NALU_STAP_A = 24, NALU_FU_A = 28 }; inline int naluType(const Bytes & n) { return n.empty() ? 0 : (n[0] & 0x1f); } struct SpsInfo { int width = 0; int height = 0; int profileIdc = 0; int constraints = 0; int levelIdc = 0; }; bool parseSps(const Bytes & sps, SpsInfo & info); // 4d401f style string for SDP profile-level-id and "avc1.4d401f" codec strings std::string profileLevelId(const Bytes & sps); // Base64 sprop-parameter-sets ("Z00AH...,aO4...") -> NAL units std::vector decodeSpropParameterSets(const char * sprop); // Annex-B byte stream (00 00 00 01 start codes) Bytes toAnnexB(const std::vector & nalus); // Annex-B byte stream -> NAL units (3 or 4 byte start codes; AUD and empty units are dropped) std::vector splitAnnexB(const uint8_t * data, size_t size); // Length prefixed NAL units (lengthSize 1..4, MP4 / avcC style) -> NAL units std::vector splitAvcc(const uint8_t * data, size_t size, int lengthSize = 4); // SPS / PPS of an avcC record (libav extradata of MP4 sources) or of Annex-B extradata std::vector parameterSetsFromExtradata(const uint8_t * data, size_t size, int * avccLengthSize = nullptr); // AVCC: 4 byte big-endian lengths (MP4 samples) Bytes toAvcc(const std::vector & nalus); // AVCDecoderConfigurationRecord (avcC box payload) Bytes buildAvcC(const Bytes & sps, const Bytes & pps); } // namespace h264 } // namespace mtx