diff --git a/source/Lib/CommonLib/SEI.cpp b/source/Lib/CommonLib/SEI.cpp index b467b2bb79c2c1abecd9dd0575d90c11c511d796..a702d96589d4312bce8630ae721321334dc59b1d 100644 --- a/source/Lib/CommonLib/SEI.cpp +++ b/source/Lib/CommonLib/SEI.cpp @@ -834,9 +834,7 @@ SEIMasteringDisplayColourVolume::SEIMasteringDisplayColourVolume(const SEIMaster SEIScalableNesting::SEIScalableNesting(const SEIScalableNesting& sei) { olsIdx = sei.olsIdx; - allLayersFlag = sei.allLayersFlag; - m_snNumLayersMinus1 = sei.m_snNumLayersMinus1; - std::memcpy(m_snLayerId, sei.m_snLayerId, sizeof(sei.m_snLayerId)); + layerId = sei.layerId; subpicIdLen = sei.subpicIdLen; subpicId = sei.subpicId; m_nestedSEIs = sei.m_nestedSEIs; diff --git a/source/Lib/CommonLib/SEI.h b/source/Lib/CommonLib/SEI.h index b570341e2ecd70f239e046b2536afe82490981d7..b11bb37195fb0eb0312b9848b79433af924e0e65 100644 --- a/source/Lib/CommonLib/SEI.h +++ b/source/Lib/CommonLib/SEI.h @@ -894,7 +894,7 @@ class SEIScalableNesting : public SEI public: PayloadType payloadType() const { return PayloadType::SCALABLE_NESTING; } - SEIScalableNesting() : m_snNumLayersMinus1(0) + SEIScalableNesting() { olsIdx.clear(); subpicId.clear(); @@ -906,15 +906,15 @@ public: deleteSEIs(m_nestedSEIs); } + uint8_t subpicIdLen = 0; + static_vector<uint32_t, MAX_NESTING_NUM_LAYER> olsIdx; std::vector<uint16_t> subpicId; - bool allLayersFlag = false; // value valid if m_nestingOlsFlag == 0 - uint32_t m_snNumLayersMinus1; //value valid if m_nestingOlsFlag == 0 and m_nestingAllLayersFlag == 0 - uint8_t m_snLayerId[MAX_NESTING_NUM_LAYER]; // value valid if m_nestingOlsFlag == 0 and m_nestingAllLayersFlag == 0. - // This can e.g. be a static array of 64 uint8_t values - uint8_t subpicIdLen = 0; + static_vector<uint8_t, MAX_NESTING_NUM_LAYER> layerId; + + bool allLayersFlag() const { return layerId.empty(); } SEIMessages m_nestedSEIs; }; diff --git a/source/Lib/DecoderLib/SEIread.cpp b/source/Lib/DecoderLib/SEIread.cpp index 8360e98cfe8fba6b659626de953e5ab14144fbfa..2702ddaf0feee77c5392ce20fe89b91907344eb9 100644 --- a/source/Lib/DecoderLib/SEIread.cpp +++ b/source/Lib/DecoderLib/SEIread.cpp @@ -993,16 +993,22 @@ void SEIReader::xParseSEIScalableNesting(SEIScalableNesting& sei, const NalUnitT else { sei_read_flag(decodedMessageOutputStream, symbol, "sn_all_layers_flag"); - sei.allLayersFlag = symbol != 0; - if (!sei.allLayersFlag) + const bool allLayersFlag = symbol != 0; + if (!allLayersFlag) { - sei_read_uvlc(decodedMessageOutputStream, symbol, "sn_num_layers_minus1"); sei.m_snNumLayersMinus1 = symbol; - sei.m_snLayerId[0] = nuhLayerId; - for (uint32_t i = 1; i <= sei.m_snNumLayersMinus1; i++) + sei_read_uvlc(decodedMessageOutputStream, symbol, "sn_num_layers_minus1"); + sei.layerId.resize(symbol + 1); + sei.layerId[0] = nuhLayerId; + for (uint32_t i = 1; i < sei.layerId.size(); i++) { - sei_read_code(decodedMessageOutputStream, 6, symbol, "sn_layer_id[i]"); sei.m_snLayerId[i] = symbol; + sei_read_code(decodedMessageOutputStream, 6, symbol, "sn_layer_id[i]"); + sei.layerId[i] = symbol; } } + else + { + sei.layerId.clear(); + } } if (hasSubpicId) { @@ -1253,16 +1259,22 @@ void SEIReader::xParseSEIScalableNestingBinary(SEIScalableNesting &sei, const Na else { sei_read_flag(decodedMessageOutputStream, symbol, "sn_all_layers_flag"); - sei.allLayersFlag = symbol != 0; - if (!sei.allLayersFlag) + const bool allLayersFlag = symbol != 0; + if (!allLayersFlag) { - sei_read_uvlc(decodedMessageOutputStream, symbol, "sn_num_layers_minus1"); sei.m_snNumLayersMinus1 = symbol; - sei.m_snLayerId[0] = nuhLayerId; - for (uint32_t i = 1; i <= sei.m_snNumLayersMinus1; i++) + sei_read_uvlc(decodedMessageOutputStream, symbol, "sn_num_layers_minus1"); + sei.layerId.resize(symbol + 1); + sei.layerId[0] = nuhLayerId; + for (uint32_t i = 1; i < sei.layerId.size(); i++) { - sei_read_code(decodedMessageOutputStream, 6, symbol, "sn_layer_id[i]"); sei.m_snLayerId[i] = symbol; + sei_read_code(decodedMessageOutputStream, 6, symbol, "sn_layer_id[i]"); + sei.layerId[i] = symbol; } } + else + { + sei.layerId.clear(); + } } if (hasSubpicId) { @@ -1360,7 +1372,7 @@ void SEIReader::xParseSEIScalableNestingBinary(SEIScalableNesting &sei, const Na } } } - else if (sei.allLayersFlag) + else if (sei.allLayersFlag()) { for (uint32_t k = 0; k < numSubPics; k++) { @@ -1380,20 +1392,20 @@ void SEIReader::xParseSEIScalableNestingBinary(SEIScalableNesting &sei, const Na } else { - for (uint32_t j = 0; j <= sei.m_snNumLayersMinus1; j++) + for (uint32_t j = 0; j < sei.layerId.size(); j++) { for (uint32_t k = 0; k < numSubPics; k++) { if (j == 0 && k == 0) { - seiList->push_back(SeiPayload{ payloadType, sei.m_snLayerId[j], false, payloadSize, payload, duiIdx, + seiList->push_back(SeiPayload{ payloadType, sei.layerId[j], false, payloadSize, payload, duiIdx, !sei.subpicId.empty() ? sei.subpicId[k] : 0 }); } else { uint8_t *payloadTemp = new uint8_t[payloadSize]; memcpy(payloadTemp, payload, payloadSize *sizeof(uint8_t)); - seiList->push_back(SeiPayload{ payloadType, sei.m_snLayerId[j], false, payloadSize, payloadTemp, duiIdx, + seiList->push_back(SeiPayload{ payloadType, sei.layerId[j], false, payloadSize, payloadTemp, duiIdx, !sei.subpicId.empty() ? sei.subpicId[k] : 0 }); } } diff --git a/source/Lib/EncoderLib/SEIEncoder.cpp b/source/Lib/EncoderLib/SEIEncoder.cpp index 9581bf39645070eb3a15d01f170a758fae064f7e..8fa062d57cb74ec8494aa509ed910c9ad6fbf87e 100644 --- a/source/Lib/EncoderLib/SEIEncoder.cpp +++ b/source/Lib/EncoderLib/SEIEncoder.cpp @@ -476,11 +476,10 @@ void SEIEncoder::initSEIScalableNesting(SEIScalableNesting *scalableNestingSEI, } else { - scalableNestingSEI->allLayersFlag = false; // nesting is not applied to all layers - scalableNestingSEI->m_snNumLayersMinus1 = (uint32_t) targetLayers.size() - 1; //nesting_num_layers_minus1 - for (int i=0; i <= scalableNestingSEI->m_snNumLayersMinus1; i++ ) + scalableNestingSEI->layerId.resize(targetLayers.size()); + for (int i = 0; i < scalableNestingSEI->layerId.size(); i++) { - scalableNestingSEI->m_snLayerId[i] = targetLayers[i]; + scalableNestingSEI->layerId[i] = targetLayers[i]; } } if (!subpictureIDs.empty()) diff --git a/source/Lib/EncoderLib/SEIwrite.cpp b/source/Lib/EncoderLib/SEIwrite.cpp index bea5c07092f06cedc6f7ef4f603c3868d45d178d..22ece860f1f08bc030e1f81c7ff826b152f9f6ad 100644 --- a/source/Lib/EncoderLib/SEIwrite.cpp +++ b/source/Lib/EncoderLib/SEIwrite.cpp @@ -628,13 +628,13 @@ void SEIWriter::xWriteSEIScalableNesting(OutputBitstream& bs, const SEIScalableN } else { - xWriteFlag(sei.allLayersFlag ? 1 : 0, "sn_all_layers_flag"); - if (!sei.allLayersFlag) + xWriteFlag(sei.allLayersFlag() ? 1 : 0, "sn_all_layers_flag"); + if (!sei.allLayersFlag()) { - xWriteUvlc(sei.m_snNumLayersMinus1, "sn_num_layers_minus1"); - for (uint32_t i = 1; i <= sei.m_snNumLayersMinus1; i++) + xWriteUvlc((uint32_t) sei.layerId.size() - 1, "sn_num_layers_minus1"); + for (uint32_t i = 1; i < sei.layerId.size(); i++) { - xWriteCode(sei.m_snLayerId[i], 6, "sn_layer_id"); + xWriteCode(sei.layerId[i], 6, "sn_layer_id"); } } }