You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

59 lines
1.7 KiB

/*
MediaMtx (C++) - H264 helpers (MediaMTX uses mediacommon/pkg/codecs/h264)
*/
#pragma once
#include <string>
#include <vector>
#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<Bytes> decodeSpropParameterSets(const char * sprop);
// Annex-B byte stream (00 00 00 01 start codes)
Bytes toAnnexB(const std::vector<Bytes> & nalus);
// Annex-B byte stream -> NAL units (3 or 4 byte start codes; AUD and empty units are dropped)
std::vector<Bytes> splitAnnexB(const uint8_t * data, size_t size);
// Length prefixed NAL units (lengthSize 1..4, MP4 / avcC style) -> NAL units
std::vector<Bytes> 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<Bytes> parameterSetsFromExtradata(const uint8_t * data, size_t size, int * avccLengthSize = nullptr);
// AVCC: 4 byte big-endian lengths (MP4 samples)
Bytes toAvcc(const std::vector<Bytes> & nalus);
// AVCDecoderConfigurationRecord (avcC box payload)
Bytes buildAvcC(const Bytes & sps, const Bytes & pps);
} // namespace h264
} // namespace mtx