Fix VVC Video Descriptor

Set VVC Video Descriptor as per IUT-T Rec.222 Table 2-133.
This commit is contained in:
jcdr428 2021-12-30 14:50:04 +01:00
parent c88a244743
commit b8ca2217ea
3 changed files with 65 additions and 62 deletions

View File

@ -56,6 +56,7 @@ int VvcUnit::deserialize()
}
catch (BitStreamException& e)
{
(void)e;
return NOT_ENOUGH_BUFFER;
}
}
@ -113,7 +114,15 @@ bool VvcUnit::dpb_parameters(int MaxSubLayersMinus1, bool subLayerInfoFlag)
// ------------------------- VvcUnitWithProfile -------------------
VvcUnitWithProfile::VvcUnitWithProfile() : profile_idc(0), level_idc(0) {}
VvcUnitWithProfile::VvcUnitWithProfile()
: profile_idc(0),
tier_flag(0),
level_idc(0),
ptl_frame_only_constraint_flag(true),
ptl_num_sub_profiles(0),
general_sub_profile_idc(0)
{
}
int VvcUnitWithProfile::profile_tier_level(bool profileTierPresentFlag, int MaxNumSubLayersMinus1)
{
@ -122,10 +131,11 @@ int VvcUnitWithProfile::profile_tier_level(bool profileTierPresentFlag, int MaxN
if (profileTierPresentFlag)
{
profile_idc = m_reader.getBits(7);
m_reader.skipBit(); // tier_flag
tier_flag = m_reader.getBit();
}
level_idc = m_reader.getBits(8);
m_reader.skipBits(2); // ptl_frame_only_constraint_flag, ptl_multilayer_enabled_flag
ptl_frame_only_constraint_flag = m_reader.getBit();
m_reader.skipBit(); // ptl_multilayer_enabled_flag
if (profileTierPresentFlag)
{ // general_constraints_info()
@ -139,7 +149,7 @@ int VvcUnitWithProfile::profile_tier_level(bool profileTierPresentFlag, int MaxN
}
m_reader.skipBits(m_reader.getBitsLeft() % 8); // gci_alignment_zero_bit
}
std::vector<int> ptl_sublayer_level_present_flag;
vector<int> ptl_sublayer_level_present_flag;
ptl_sublayer_level_present_flag.resize(MaxNumSubLayersMinus1);
for (int i = MaxNumSubLayersMinus1 - 1; i >= 0; i--) ptl_sublayer_level_present_flag[i] = m_reader.getBit();
@ -151,13 +161,15 @@ int VvcUnitWithProfile::profile_tier_level(bool profileTierPresentFlag, int MaxN
m_reader.skipBits(8); // sublayer_level_idc[i]
if (profileTierPresentFlag)
{
int ptl_num_sub_profiles = m_reader.getBits(8);
for (int i = 0; i < ptl_num_sub_profiles; i++) m_reader.skipBits(32); // general_sub_profile_idc[i]
ptl_num_sub_profiles = m_reader.getBits(8);
general_sub_profile_idc.resize(ptl_num_sub_profiles);
for (auto& i : general_sub_profile_idc) i = m_reader.getBits(32);
}
return 0;
}
catch (BitStreamException& e)
{
(void)e;
return NOT_ENOUGH_BUFFER;
}
}
@ -430,6 +442,7 @@ int VvcVpsUnit::deserialize()
}
catch (VodCoreException& e)
{
(void)e;
return NOT_ENOUGH_BUFFER;
}
}
@ -471,6 +484,9 @@ VvcSpsUnit::VvcSpsUnit()
pic_height_max_in_luma_samples(0),
bitdepth_minus8(0),
log2_max_pic_order_cnt_lsb(0),
progressive_source_flag(true),
interlaced_source_flag(true),
non_packed_constraint_flag(true),
colour_primaries(2),
transfer_characteristics(2),
matrix_coeffs(2), // 2 = unspecified
@ -817,6 +833,7 @@ int VvcSpsUnit::deserialize()
}
catch (VodCoreException& e)
{
(void)e;
return NOT_ENOUGH_BUFFER;
}
}
@ -873,9 +890,10 @@ string VvcSpsUnit::getDescription() const
/* Specified in Rec. ITU-T H.274 */
int VvcSpsUnit::vui_parameters()
{
bool progressive_source_flag = m_reader.getBit();
bool interlaced_source_flag = m_reader.getBit();
m_reader.skipBits(2); // non_packed_constraint_flag, non_projected_constraint_flag
progressive_source_flag = m_reader.getBit();
interlaced_source_flag = m_reader.getBit();
non_packed_constraint_flag = m_reader.getBit();
m_reader.skipBit(); // non_projected_constraint_flag
if (m_reader.getBit()) // aspect_ratio_info_present_flag
{
@ -931,6 +949,7 @@ int VvcPpsUnit::deserialize()
}
catch (VodCoreException& e)
{
(void)e;
return NOT_ENOUGH_BUFFER;
}
}
@ -1039,6 +1058,7 @@ int VvcSliceHeader::deserialize(const VvcSpsUnit* sps, const VvcPpsUnit* pps)
}
catch (VodCoreException& e)
{
(void)e;
return NOT_ENOUGH_BUFFER;
}
}

View File

@ -52,7 +52,10 @@ struct VvcHrdUnit
struct VvcUnit
{
VvcUnit() : nal_unit_type(0), nuh_layer_id(0), nuh_temporal_id_plus1(0), m_nalBuffer(0), m_nalBufferLen(0) {}
VvcUnit()
: nal_unit_type(0), nuh_layer_id(0), nuh_temporal_id_plus1(0), m_nalBuffer(0), m_nalBufferLen(0), m_reader()
{
}
void decodeBuffer(const uint8_t* buffer, const uint8_t* end);
virtual int deserialize();
@ -87,7 +90,11 @@ struct VvcUnitWithProfile : public VvcUnit
public:
int profile_idc;
int tier_flag;
int level_idc;
bool ptl_frame_only_constraint_flag;
int ptl_num_sub_profiles;
std::vector<int> general_sub_profile_idc;
protected:
int profile_tier_level(bool profileTierPresentFlag, int MaxNumSubLayersMinus1);
@ -131,6 +138,10 @@ struct VvcSpsUnit : public VvcUnitWithProfile
std::vector<unsigned> cpb_cnt_minus1;
// T-Rec. H.274 7.2 vui_parameters()
bool progressive_source_flag;
bool interlaced_source_flag;
bool non_packed_constraint_flag;
int colour_primaries;
int transfer_characteristics;
int matrix_coeffs;

View File

@ -124,64 +124,36 @@ int VVCStreamReader::getTSDescriptor(uint8_t* dstBuff, bool blurayMode, bool hdm
int video_format, frame_rate_index, aspect_ratio_index;
M2TSStreamInfo::blurayStreamParams(getFPS(), getInterlaced(), getStreamWidth(), getStreamHeight(),
getStreamAR(), &video_format, &frame_rate_index, &aspect_ratio_index);
(float)getStreamAR(), &video_format, &frame_rate_index, &aspect_ratio_index);
*dstBuff++ = (video_format << 4) + frame_rate_index;
*dstBuff++ = (aspect_ratio_index << 4) + 0xf;
}
else
{
uint8_t tmpBuffer[512];
for (uint8_t* nal = NALUnit::findNextNAL(m_buffer, m_bufEnd); nal < m_bufEnd - 4;
nal = NALUnit::findNextNAL(nal, m_bufEnd))
{
uint8_t nalType = (*nal >> 1) & 0x3f;
uint8_t* nextNal = NALUnit::findNALWithStartCode(nal, m_bufEnd, true);
if (nalType == V_SPS)
{
int toDecode = (int)FFMIN(sizeof(tmpBuffer) - 8, nextNal - nal);
int decodedLen = NALUnit::decodeNAL(nal, nal + toDecode, tmpBuffer, sizeof(tmpBuffer));
break;
}
return 10;
}
uint8_t* descStart = dstBuff;
// ITU-T Rec.H.222 Table 2-133 - VVC video descriptor
*dstBuff++ = VVC_DESCRIPTOR_TAG;
*dstBuff++ = 13; // descriptor length
memcpy(dstBuff, tmpBuffer + 3, 12);
dstBuff += 12;
// flags temporal_layer_subset, VVC_still_present,
// VVC_24hr_picture_present, HDR_WCG unspecified
*dstBuff = 0x0f;
dstBuff++;
uint8_t* descLength = dstBuff++;
*dstBuff++ = (m_sps->profile_idc << 1) | m_sps->tier_flag;
*dstBuff++ = m_sps->ptl_num_sub_profiles;
uint32_t* bufPos = (uint32_t*)dstBuff;
for (auto i : m_sps->general_sub_profile_idc)
*bufPos++ = i;
dstBuff = (uint8_t*)bufPos;
*dstBuff++ = (m_sps->progressive_source_flag << 7) | (m_sps->interlaced_source_flag << 6) |
(m_sps->non_packed_constraint_flag << 5) | (m_sps->ptl_frame_only_constraint_flag << 4);
*dstBuff++ = m_sps->level_idc;
*dstBuff++ = 0;
*dstBuff++ = 0xc0;
/* VVC_timing_and_HRD_descriptor
// mandatory for interlaced video only
memcpy(dstBuff, "\x3f\x0f\x03\x7f\x7f", 5);
dstBuff += 5;
uint8_t* descEnd = dstBuff;
int descSize = (int)(descEnd - descStart);
*descLength = descSize - 2;
uint32_t N = 1001 * getFPS();
uint32_t K = 27000000;
uint32_t num_units_in_tick = 1001;
if (N % 1000)
{
N = 1000 * getFPS();
num_units_in_tick = 1000;
}
N = my_htonl(N);
K = my_htonl(K);
num_units_in_tick = my_htonl(num_units_in_tick);
memcpy(dstBuff, &N, 4);
dstBuff += 4;
memcpy(dstBuff, &K, 4);
dstBuff += 4;
memcpy(dstBuff, &num_units_in_tick, 4);
dstBuff += 4;
*/
}
return (hdmvDescriptors ? 10 : 15);
return descSize;
}
void VVCStreamReader::updateStreamFps(void* nalUnit, uint8_t* buff, uint8_t* nextNal, int)