[x265] [PATCH] Clean up SEI::write function

Ashok Kumar Mishra ashok at multicorewareinc.com
Fri Mar 23 10:30:24 CET 2018


On Thu, Mar 22, 2018 at 7:42 PM, <aarthi at multicorewareinc.com> wrote:

> # HG changeset patch
> # User Aarthi Thirumalai <aarthi at multicorewareinc.com>
> # Date 1521028474 -19800
> #      Wed Mar 14 17:24:34 2018 +0530
> # Node ID a65dc9e0ecf2a71abbda117debca8f7cd5d5e8b9
> # Parent  b9f5b5d7bf95c2a4dda1cec51fc104f9122f374b
> Clean up SEI::write function
>
> define another SEI function to count the payload size and return count in
> bits.
> Set the payload size before calling SEI::write() to avoid clutter of if
> conditions in
> write function. Write payloadtype and payload size in bitstream for all
> SEI in same way
> as it is the syntax defined in the spec for any SEI.
>
> diff -r b9f5b5d7bf95 -r a65dc9e0ecf2 source/encoder/encoder.cpp
> --- a/source/encoder/encoder.cpp        Thu Mar 15 10:52:52 2018 +0530
> +++ b/source/encoder/encoder.cpp        Wed Mar 14 17:24:34 2018 +0530
> @@ -2332,7 +2332,7 @@
>                  bs.resetBits();
>                  SEIuserDataUnregistered idsei;
>                  idsei.m_userData = (uint8_t*)buffer;
> -                idsei.setSize((uint32_t)strlen(buffer));
> +                idsei.setSize((uint32_t)strlen(buffer) + 16);
>                  idsei.write(bs, m_sps);
>                  bs.writeByteAlignment();
>                  list.serialize(NAL_UNIT_PREFIX_SEI, bs);
> @@ -2350,7 +2350,8 @@
>          SEIActiveParameterSets sei;
>          sei.m_selfContainedCvsFlag = true;
>          sei.m_noParamSetUpdateFlag = true;
> -
> +        int payloadSize = sei.countPayloadSize(m_sps);
> +        sei.setSize(payloadSize);
>          bs.resetBits();
>          sei.write(bs, m_sps);
>          bs.writeByteAlignment();
> diff -r b9f5b5d7bf95 -r a65dc9e0ecf2 source/encoder/frameencoder.cpp
> --- a/source/encoder/frameencoder.cpp   Thu Mar 15 10:52:52 2018 +0530
> +++ b/source/encoder/frameencoder.cpp   Wed Mar 14 17:24:34 2018 +0530
> @@ -634,7 +634,8 @@
>
>              // hrdFullness() calculates the initial CPB removal delay and
> offset
>              m_top->m_rateControl->hrdFullness(bpSei);
> -
> +            int payloadSize = bpSei->countPayloadSize(*slice->m_sps);
> +            bpSei->setSize(payloadSize);
>              m_bs.resetBits();
>              bpSei->write(m_bs, *slice->m_sps);
>              m_bs.writeByteAlignment();
> @@ -651,6 +652,7 @@
>              sei.m_recoveryPocCnt = 0;
>              sei.m_exactMatchingFlag = true;
>              sei.m_brokenLinkFlag = false;
> +            sei.setSize(sei.countPayloadSize(*slice->m_sps));
>              m_bs.resetBits();
>              sei.write(m_bs, *slice->m_sps);
>              m_bs.writeByteAlignment();
> @@ -688,6 +690,8 @@
>          }
>
>          m_bs.resetBits();
> +        int payloadSize = sei->countPayloadSize(*slice->m_sps);
> +        sei->setSize(payloadSize);
>          sei->write(m_bs, *slice->m_sps);
>          m_bs.writeByteAlignment();
>          m_nalList.serialize(NAL_UNIT_PREFIX_SEI, m_bs);
> @@ -702,7 +706,7 @@
>              SEIuserDataUnregistered sei;
>              sei.m_userData = payload->payload;
>              m_bs.resetBits();
> -            sei.setSize(payload->payloadSize);
> +            sei.setSize(payload->payloadSize + 16);
>              sei.write(m_bs, *slice->m_sps);
>              m_bs.writeByteAlignment();
>              m_nalList.serialize(NAL_UNIT_PREFIX_SEI, m_bs);
> diff -r b9f5b5d7bf95 -r a65dc9e0ecf2 source/encoder/sei.cpp
> --- a/source/encoder/sei.cpp    Thu Mar 15 10:52:52 2018 +0530
> +++ b/source/encoder/sei.cpp    Wed Mar 14 17:24:34 2018 +0530
> @@ -34,44 +34,33 @@
>      0xBB, 0x55, 0xA4, 0xFE, 0x7F, 0xC2, 0xFC, 0x4E
>  };
>
> +/* count the size of the payload and return the size in bits */
> +int SEI::countPayloadSize(const SPS& sps)
> +{
> +    BitCounter counter;
> +    int count = 0;
> +    m_bitIf = &counter;
> +    writeSEI(sps);
> +    X265_CHECK(0 == (count.getNumberOfWrittenBits() & 7), "payload
> unaligned\n");
> +    count = counter.getNumberOfWrittenBits() >> 3;
> +    return count;
> +}
> +
>  /* marshal a single SEI message sei, storing the marshalled representation
>   * in bitstream bs */
>  void SEI::write(Bitstream& bs, const SPS& sps)
>  {
>      uint32_t type = m_payloadType;
>      m_bitIf = &bs;
> -    BitCounter 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 payloadType = m_payloadType;
> -        for (; payloadType >= 0xff; payloadType -= 0xff)
> -            WRITE_CODE(0xff, 8, "payload_type");
> -    }
> +    uint32_t payloadSize = m_payloadSize;
> +    uint32_t payloadType = m_payloadType;
> +    for (; payloadType >= 0xff; payloadType -= 0xff)
> +        WRITE_CODE(0xff, 8, "payload_type");
>      WRITE_CODE(type, 8, "payload_type");
> -    uint32_t payloadSize;
> -    if (hrdTypes || m_payloadType == USER_DATA_UNREGISTERED ||
> m_payloadType == USER_DATA_REGISTERED_ITU_T_T35)
> -    {
> -        if (hrdTypes)
> -        {
> -            X265_CHECK(0 == (count.getNumberOfWrittenBits() & 7),
> "payload unaligned\n");
> -            payloadSize = count.getNumberOfWrittenBits() >> 3;
> -        }
> -        else if (m_payloadType == USER_DATA_UNREGISTERED)
> -            payloadSize = m_payloadSize + 16;
> -        else
> -            payloadSize = m_payloadSize;
>
> -        for (; payloadSize >= 0xff; payloadSize -= 0xff)
> -            WRITE_CODE(0xff, 8, "payload_size");
> -        WRITE_CODE(payloadSize, 8, "payload_size");
> -    }
> -    else
> -        WRITE_CODE(m_payloadSize, 8, "payload_size");
> +    for (; payloadSize >= 0xff; payloadSize -= 0xff)
> +        WRITE_CODE(0xff, 8, "payload_size");
> +    WRITE_CODE(payloadSize, 8, "payload_size");
>      /* virtual writeSEI method, write to bs */
>      writeSEI(sps);
>  }
> diff -r b9f5b5d7bf95 -r a65dc9e0ecf2 source/encoder/sei.h
> --- a/source/encoder/sei.h      Thu Mar 15 10:52:52 2018 +0530
> +++ b/source/encoder/sei.h      Wed Mar 14 17:24:34 2018 +0530
> @@ -37,7 +37,7 @@
>      /* 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);
> -
> +    int countPayloadSize(const SPS& sps);
>      void setSize(uint32_t size);
>      virtual ~SEI() {}
>  protected:
>
> _______________________________________________
> x265-devel mailing list
> x265-devel at videolan.org
> https://mailman.videolan.org/listinfo/x265-devel
>
>

Thanks. Pushed to default.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/x265-devel/attachments/20180323/9b4119a6/attachment-0001.html>


More information about the x265-devel mailing list