# HG changeset patch # User Bhavna Hariharan <bha...@multicorewareinc.com> # Date 1490678611 -19800 # Tue Mar 28 10:53:31 2017 +0530 # Node ID 9c3ae5906579b7494ca86b957c68d66d69d2817a # Parent e2eb86dce7f493cd14ea3d8bc002d17f839b1aa7 sei clean up
diff -r e2eb86dce7f4 -r 9c3ae5906579 source/encoder/encoder.cpp --- a/source/encoder/encoder.cpp Wed Apr 19 16:36:59 2017 -0700 +++ b/source/encoder/encoder.cpp Tue Mar 28 10:53:31 2017 +0530 @@ -86,7 +86,7 @@ m_frameEncoder[i] = NULL; MotionEstimate::initScales(); #if ENABLE_DYNAMIC_HDR10 - api = hdr10plus_api_get(); + m_hdr10plus_api = hdr10plus_api_get(); #endif } inline char *strcatFilename(const char *input, const char *suffix) @@ -602,7 +602,7 @@ if (m_bToneMap) { uint8_t *cim = NULL; - if (api->hdr10plus_json_to_frame_cim(m_param->toneMapFile, pic_in->poc, cim)) + if (m_hdr10plus_api->hdr10plus_json_to_frame_cim(m_param->toneMapFile, pic_in->poc, cim)) { toneMap.payload = (uint8_t*)x265_malloc(sizeof(uint8_t) * cim[0]); toneMap.payloadSize = cim[0]; @@ -1758,9 +1758,8 @@ bs.resetBits(); SEIuserDataUnregistered idsei; - idsei.m_payloadType = USER_DATA_UNREGISTERED; idsei.m_userData = (uint8_t*)buffer; - idsei.m_userDataLength = (uint32_t)strlen(buffer); + idsei.setSize((uint32_t)strlen(buffer)); idsei.write(bs, m_sps); bs.writeByteAlignment(); list.serialize(NAL_UNIT_PREFIX_SEI, bs); diff -r e2eb86dce7f4 -r 9c3ae5906579 source/encoder/encoder.h --- a/source/encoder/encoder.h Wed Apr 19 16:36:59 2017 -0700 +++ b/source/encoder/encoder.h Tue Mar 28 10:53:31 2017 +0530 @@ -172,8 +172,10 @@ /* For HDR*/ double m_cB; double m_cR; - int m_bToneMap; // Enables tone-mapping - const hdr10plus_api* api; + + int m_bToneMap; // Enables tone-mapping + const hdr10plus_api* m_hdr10plus_api; + Encoder(); ~Encoder() {} void create(); diff -r e2eb86dce7f4 -r 9c3ae5906579 source/encoder/frameencoder.cpp --- a/source/encoder/frameencoder.cpp Wed Apr 19 16:36:59 2017 -0700 +++ b/source/encoder/frameencoder.cpp Tue Mar 28 10:53:31 2017 +0530 @@ -615,30 +615,28 @@ for (int i = 0; i < m_frame->m_userSEI.numPayloads; i++) { x265_sei_payload *payload = &m_frame->m_userSEI.payloads[i]; - if (payload->payloadType != USER_DATA_REGISTERED_ITU_T_T35) + if (payload->payloadType == USER_DATA_UNREGISTERED) { SEIuserDataUnregistered sei; - sei.m_payloadType = payload->payloadType; - sei.m_userDataLength = payload->payloadSize; sei.m_userData = payload->payload; m_bs.resetBits(); + sei.setSize(payload->payloadSize); sei.write(m_bs, *slice->m_sps); m_bs.writeByteAlignment(); m_nalList.serialize(NAL_UNIT_PREFIX_SEI, m_bs); } -#if ENABLE_DYNAMIC_HDR10 - else if (m_param->toneMapFile != NULL) + else if (payload->payloadType == USER_DATA_REGISTERED_ITU_T_T35) { SEICreativeIntentMeta sei; - sei.cim = payload->payload; - m_bs.resetBits(); + sei.setSize(payload->payloadSize); sei.write(m_bs, *slice->m_sps); m_bs.writeByteAlignment(); m_nalList.serialize(NAL_UNIT_PREFIX_SEI, m_bs); } -#endif + else + x265_log(m_param, X265_LOG_ERROR, "Unrecognized SEI type\n"); } /* CQP and CRF (without capped VBV) doesn't use mid-frame statistics to * tune RateControl parameters for other frames. @@ -948,29 +946,32 @@ if (m_param->decodedPictureHashSEI) { int planes = (m_frame->m_param->internalCsp != X265_CSP_I400) ? 3 : 1; + int32_t payloadSize = 0; if (m_param->decodedPictureHashSEI == 1) { m_seiReconPictureDigest.m_method = SEIDecodedPictureHash::MD5; for (int i = 0; i < planes; i++) MD5Final(&m_state[i], m_seiReconPictureDigest.m_digest[i]); + payloadSize = 1 + 16 * planes; } else if (m_param->decodedPictureHashSEI == 2) { m_seiReconPictureDigest.m_method = SEIDecodedPictureHash::CRC; for (int i = 0; i < planes; i++) crcFinish(m_crc[i], m_seiReconPictureDigest.m_digest[i]); + payloadSize = 1 + 2 * planes; } else if (m_param->decodedPictureHashSEI == 3) { m_seiReconPictureDigest.m_method = SEIDecodedPictureHash::CHECKSUM; for (int i = 0; i < planes; i++) checksumFinish(m_checksum[i], m_seiReconPictureDigest.m_digest[i]); + payloadSize = 1 + 4 * planes; } - m_bs.resetBits(); + m_seiReconPictureDigest.setSize(payloadSize); m_seiReconPictureDigest.write(m_bs, *slice->m_sps); m_bs.writeByteAlignment(); - m_nalList.serialize(NAL_UNIT_SUFFIX_SEI, m_bs); } diff -r e2eb86dce7f4 -r 9c3ae5906579 source/encoder/sei.cpp --- a/source/encoder/sei.cpp Wed Apr 19 16:36:59 2017 -0700 +++ b/source/encoder/sei.cpp Tue Mar 28 10:53:31 2017 +0530 @@ -38,24 +38,38 @@ * in bitstream bs */ void SEI::write(Bitstream& bs, const SPS& sps) { + uint32_t type = m_payloadType; + m_bitIf = &bs; BitCounter count; - m_bitIf = &count; + bool hrdTypes = (m_payloadType == ACTIVE_PARAMETER_SETS || m_payloadType == PICTURE_TIMING || m_payloadType == BUFFERING_PERIOD); + if (hrdTypes) + { + m_bitIf = &count; + /* virtual writeSEI method, write to bit counter to determine size */ + writeSEI(sps); + m_bitIf = &bs; + uint32_t type = m_payloadType; + for (; type >= 0xff; type -= 0xff) + WRITE_CODE(0xff, 8, "payload_type"); + } + WRITE_CODE(type, 8, "payload_type"); + uint32_t payloadSize; + if (hrdTypes || m_payloadType == USER_DATA_UNREGISTERED) + { + if (hrdTypes) + { + X265_CHECK(0 == (count.getNumberOfWrittenBits() & 7), "payload unaligned\n"); + payloadSize = count.getNumberOfWrittenBits() >> 3; + } + else + payloadSize = m_payloadSize + 16; - /* virtual writeSEI method, write to bit counter */ - writeSEI(sps); - - m_bitIf = &bs; - uint32_t type = payloadType(); - for (; type >= 0xff; type -= 0xff) - WRITE_CODE(0xff, 8, "payload_type"); - WRITE_CODE(type, 8, "payload_type"); - - X265_CHECK(0 == (count.getNumberOfWrittenBits() & 7), "payload unaligned\n"); - uint32_t payloadSize = count.getNumberOfWrittenBits() >> 3; - for (; payloadSize >= 0xff; payloadSize -= 0xff) - WRITE_CODE(0xff, 8, "payload_size"); - WRITE_CODE(payloadSize, 8, "payload_size"); - + for (; payloadSize >= 0xff; payloadSize -= 0xff) + WRITE_CODE(0xff, 8, "payload_size"); + WRITE_CODE(payloadSize, 8, "payload_size"); + } + else if(m_payloadType != USER_DATA_REGISTERED_ITU_T_T35) + WRITE_CODE(m_payloadSize, 8, "payload_size"); /* virtual writeSEI method, write to bs */ writeSEI(sps); } @@ -72,3 +86,8 @@ } } } + +void SEI::setSize(uint32_t size) +{ + m_payloadSize = size; +} diff -r e2eb86dce7f4 -r 9c3ae5906579 source/encoder/sei.h --- a/source/encoder/sei.h Wed Apr 19 16:36:59 2017 -0700 +++ b/source/encoder/sei.h Tue Mar 28 10:53:31 2017 +0530 @@ -34,53 +34,34 @@ class SEI : public SyntaxElementWriter { public: + /* SEI users call write() to marshal an SEI to a bitstream. + * The write() method calls writeSEI() which encodes the header */ + void write(Bitstream& bs, const SPS& sps); - /* SEI users call write() to marshal an SEI to a bitstream. SEI - * subclasses may implement write() or accept the default write() - * method which calls writeSEI() with a bitcounter to determine - * the size, then it encodes the header and calls writeSEI a - * second time for the real encode. */ - virtual void write(Bitstream& bs, const SPS& sps); - + void setSize(uint32_t size); virtual ~SEI() {} - protected: - - virtual SEIPayloadType payloadType() const = 0; - - virtual void writeSEI(const SPS&) { X265_CHECK(0, "empty writeSEI method called\n"); } - + SEIPayloadType m_payloadType; + uint32_t m_payloadSize; + virtual void writeSEI(const SPS&) = 0; void writeByteAlign(); }; class SEIuserDataUnregistered : public SEI { public: - - SEIPayloadType payloadType() const { return m_payloadType; } - - SEIuserDataUnregistered() : m_userData(NULL) {} - + SEIuserDataUnregistered() : m_userData(NULL) + { + m_payloadType = USER_DATA_UNREGISTERED; + m_payloadSize = 0; + } static const uint8_t m_uuid_iso_iec_11578[16]; - SEIPayloadType m_payloadType; - uint32_t m_userDataLength; uint8_t *m_userData; - - void write(Bitstream& bs, const SPS&) + void writeSEI(const SPS&) { - m_bitIf = &bs; - - WRITE_CODE(m_payloadType, 8, "payload_type"); - - uint32_t payloadSize = 16 + m_userDataLength; - for (; payloadSize >= 0xff; payloadSize -= 0xff) - WRITE_CODE(0xff, 8, "payload_size"); - WRITE_CODE(payloadSize, 8, "payload_size"); - for (uint32_t i = 0; i < 16; i++) WRITE_CODE(m_uuid_iso_iec_11578[i], 8, "sei.uuid_iso_iec_11578[i]"); - - for (uint32_t i = 0; i < m_userDataLength; i++) + for (uint32_t i = 0; i < m_payloadSize; i++) WRITE_CODE(m_userData[i], 8, "user_data"); } }; @@ -88,15 +69,16 @@ class SEIMasteringDisplayColorVolume : public SEI { public: - + SEIMasteringDisplayColorVolume() + { + m_payloadType = MASTERING_DISPLAY_INFO; + m_payloadSize = (8 * 2 + 2 * 4); + } uint16_t displayPrimaryX[3]; uint16_t displayPrimaryY[3]; uint16_t whitePointX, whitePointY; uint32_t maxDisplayMasteringLuminance; uint32_t minDisplayMasteringLuminance; - - SEIPayloadType payloadType() const { return MASTERING_DISPLAY_INFO; } - bool parse(const char* value) { return sscanf(value, "G(%hu,%hu)B(%hu,%hu)R(%hu,%hu)WP(%hu,%hu)L(%u,%u)", @@ -106,14 +88,8 @@ &whitePointX, &whitePointY, &maxDisplayMasteringLuminance, &minDisplayMasteringLuminance) == 10; } - - void write(Bitstream& bs, const SPS&) + void writeSEI(const SPS&) { - m_bitIf = &bs; - - WRITE_CODE(MASTERING_DISPLAY_INFO, 8, "payload_type"); - WRITE_CODE(8 * 2 + 2 * 4, 8, "payload_size"); - for (uint32_t i = 0; i < 3; i++) { WRITE_CODE(displayPrimaryX[i], 16, "display_primaries_x[ c ]"); @@ -129,18 +105,15 @@ class SEIContentLightLevel : public SEI { public: - + SEIContentLightLevel() + { + m_payloadType = CONTENT_LIGHT_LEVEL_INFO; + m_payloadSize = 4; + } uint16_t max_content_light_level; uint16_t max_pic_average_light_level; - - SEIPayloadType payloadType() const { return CONTENT_LIGHT_LEVEL_INFO; } - - void write(Bitstream& bs, const SPS&) + void writeSEI(const SPS&) { - m_bitIf = &bs; - - WRITE_CODE(CONTENT_LIGHT_LEVEL_INFO, 8, "payload_type"); - WRITE_CODE(4, 8, "payload_size"); WRITE_CODE(max_content_light_level, 16, "max_content_light_level"); WRITE_CODE(max_pic_average_light_level, 16, "max_pic_average_light_level"); } @@ -149,42 +122,22 @@ class SEIDecodedPictureHash : public SEI { public: - - SEIPayloadType payloadType() const { return DECODED_PICTURE_HASH; } - + SEIDecodedPictureHash() + { + m_payloadType = DECODED_PICTURE_HASH; + m_payloadSize = 0; + } enum Method { MD5, CRC, CHECKSUM, } m_method; - uint8_t m_digest[3][16]; - - void write(Bitstream& bs, const SPS& sps) + void writeSEI(const SPS& sps) { - m_bitIf = &bs; - int planes = (sps.chromaFormatIdc != X265_CSP_I400) ? 3 : 1; - - WRITE_CODE(DECODED_PICTURE_HASH, 8, "payload_type"); - - switch (m_method) - { - case MD5: - WRITE_CODE(1 + 16 * planes, 8, "payload_size"); - WRITE_CODE(MD5, 8, "hash_type"); - break; - case CRC: - WRITE_CODE(1 + 2 * planes, 8, "payload_size"); - WRITE_CODE(CRC, 8, "hash_type"); - break; - case CHECKSUM: - WRITE_CODE(1 + 4 * planes, 8, "payload_size"); - WRITE_CODE(CHECKSUM, 8, "hash_type"); - break; - } - + WRITE_CODE(m_method, 8, "hash_type"); for (int yuvIdx = 0; yuvIdx < planes; yuvIdx++) { if (m_method == MD5) @@ -209,9 +162,11 @@ class SEIActiveParameterSets : public SEI { public: - - SEIPayloadType payloadType() const { return ACTIVE_PARAMETER_SETS; } - + SEIActiveParameterSets() + { + m_payloadType = ACTIVE_PARAMETER_SETS; + m_payloadSize = 0; + } bool m_selfContainedCvsFlag; bool m_noParamSetUpdateFlag; @@ -229,16 +184,14 @@ class SEIBufferingPeriod : public SEI { public: - - SEIPayloadType payloadType() const { return BUFFERING_PERIOD; } - SEIBufferingPeriod() : m_cpbDelayOffset(0) , m_dpbDelayOffset(0) , m_auCpbRemovalDelayDelta(1) { + m_payloadType = BUFFERING_PERIOD; + m_payloadSize = 0; } - bool m_cpbDelayOffset; bool m_dpbDelayOffset; uint32_t m_initialCpbRemovalDelay; @@ -263,9 +216,11 @@ class SEIPictureTiming : public SEI { public: - - SEIPayloadType payloadType() const { return PICTURE_TIMING; } - + SEIPictureTiming() + { + m_payloadType = PICTURE_TIMING; + m_payloadSize = 0; + } uint32_t m_picStruct; uint32_t m_sourceScanType; bool m_duplicateFlag; @@ -298,9 +253,6 @@ class SEIRecoveryPoint : public SEI { public: - - SEIPayloadType payloadType() const { return RECOVERY_POINT; } - int m_recoveryPocCnt; bool m_exactMatchingFlag; bool m_brokenLinkFlag; @@ -318,38 +270,34 @@ class SEICreativeIntentMeta : public SEI { public: + SEICreativeIntentMeta() + { + m_payloadType = USER_DATA_REGISTERED_ITU_T_T35; + m_payloadSize = 0; + } + uint8_t *cim; - SEIPayloadType payloadType() const { return USER_DATA_REGISTERED_ITU_T_T35; } - // daniel...@samsung.com :: for the Creative Intent Meta Data Encoding ( seongnam...@samsung.com ) - void write(Bitstream& bs, const SPS&) + void writeSEI(const SPS&) { if (!cim) - { return; - } - m_bitIf = &bs; - WRITE_CODE(USER_DATA_REGISTERED_ITU_T_T35, 8, "payload_type"); int i = 0; - int payloadSize = cim[0]; + int payloadSize = m_payloadSize; while (cim[i] == 0xFF) { i++; payloadSize += cim[i]; WRITE_CODE(0xFF, 8, "payload_size"); } - WRITE_CODE((uint8_t)payloadSize, 8, "payload_size"); + WRITE_CODE(payloadSize, 8, "payload_size"); i++; payloadSize += i; for (; i < payloadSize; ++i) - { WRITE_CODE(cim[i], 8, "creative_intent_metadata"); - } - } }; - } #endif // ifndef X265_SEI_H _______________________________________________ x265-devel mailing list x265-devel@videolan.org https://mailman.videolan.org/listinfo/x265-devel