<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Mar 22, 2018 at 7:42 PM,  <span dir="ltr"><<a href="mailto:aarthi@multicorewareinc.com" target="_blank">aarthi@multicorewareinc.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"># HG changeset patch<br>
# User Aarthi Thirumalai <<a href="mailto:aarthi@multicorewareinc.com">aarthi@multicorewareinc.com</a>><br>
# Date 1521028474 -19800<br>
#      Wed Mar 14 17:24:34 2018 +0530<br>
# Node ID a65dc9e0ecf2a71abbda117debca8f<wbr>7cd5d5e8b9<br>
# Parent  b9f5b5d7bf95c2a4dda1cec51fc104<wbr>f9122f374b<br>
Clean up SEI::write function<br>
<br>
define another SEI function to count the payload size and return count in bits.<br>
Set the payload size before calling SEI::write() to avoid clutter of if conditions in<br>
write function. Write payloadtype and payload size in bitstream for all SEI in same way<br>
as it is the syntax defined in the spec for any SEI.<br>
<br>
diff -r b9f5b5d7bf95 -r a65dc9e0ecf2 source/encoder/encoder.cpp<br>
--- a/source/encoder/encoder.cpp        Thu Mar 15 10:52:52 2018 +0530<br>
+++ b/source/encoder/encoder.cpp        Wed Mar 14 17:24:34 2018 +0530<br>
@@ -2332,7 +2332,7 @@<br>
                 bs.resetBits();<br>
                 SEIuserDataUnregistered idsei;<br>
                 idsei.m_userData = (uint8_t*)buffer;<br>
-                idsei.setSize((uint32_t)<wbr>strlen(buffer));<br>
+                idsei.setSize((uint32_t)<wbr>strlen(buffer) + 16);<br>
                 idsei.write(bs, m_sps);<br>
                 bs.writeByteAlignment();<br>
                 list.serialize(NAL_UNIT_<wbr>PREFIX_SEI, bs);<br>
@@ -2350,7 +2350,8 @@<br>
         SEIActiveParameterSets sei;<br>
         sei.m_selfContainedCvsFlag = true;<br>
         sei.m_noParamSetUpdateFlag = true;<br>
-<br>
+        int payloadSize = sei.countPayloadSize(m_sps);<br>
+        sei.setSize(payloadSize);<br>
         bs.resetBits();<br>
         sei.write(bs, m_sps);<br>
         bs.writeByteAlignment();<br>
diff -r b9f5b5d7bf95 -r a65dc9e0ecf2 source/encoder/frameencoder.<wbr>cpp<br>
--- a/source/encoder/frameencoder.<wbr>cpp   Thu Mar 15 10:52:52 2018 +0530<br>
+++ b/source/encoder/frameencoder.<wbr>cpp   Wed Mar 14 17:24:34 2018 +0530<br>
@@ -634,7 +634,8 @@<br>
<br>
             // hrdFullness() calculates the initial CPB removal delay and offset<br>
             m_top->m_rateControl-><wbr>hrdFullness(bpSei);<br>
-<br>
+            int payloadSize = bpSei->countPayloadSize(*<wbr>slice->m_sps);<br>
+            bpSei->setSize(payloadSize);<br>
             m_bs.resetBits();<br>
             bpSei->write(m_bs, *slice->m_sps);<br>
             m_bs.writeByteAlignment();<br>
@@ -651,6 +652,7 @@<br>
             sei.m_recoveryPocCnt = 0;<br>
             sei.m_exactMatchingFlag = true;<br>
             sei.m_brokenLinkFlag = false;<br>
+            sei.setSize(sei.<wbr>countPayloadSize(*slice->m_<wbr>sps));<br>
             m_bs.resetBits();<br>
             sei.write(m_bs, *slice->m_sps);<br>
             m_bs.writeByteAlignment();<br>
@@ -688,6 +690,8 @@<br>
         }<br>
<br>
         m_bs.resetBits();<br>
+        int payloadSize = sei->countPayloadSize(*slice-><wbr>m_sps);<br>
+        sei->setSize(payloadSize);<br>
         sei->write(m_bs, *slice->m_sps);<br>
         m_bs.writeByteAlignment();<br>
         m_nalList.serialize(NAL_UNIT_<wbr>PREFIX_SEI, m_bs);<br>
@@ -702,7 +706,7 @@<br>
             SEIuserDataUnregistered sei;<br>
             sei.m_userData = payload->payload;<br>
             m_bs.resetBits();<br>
-            sei.setSize(payload-><wbr>payloadSize);<br>
+            sei.setSize(payload-><wbr>payloadSize + 16);<br>
             sei.write(m_bs, *slice->m_sps);<br>
             m_bs.writeByteAlignment();<br>
             m_nalList.serialize(NAL_UNIT_<wbr>PREFIX_SEI, m_bs);<br>
diff -r b9f5b5d7bf95 -r a65dc9e0ecf2 source/encoder/sei.cpp<br>
--- a/source/encoder/sei.cpp    Thu Mar 15 10:52:52 2018 +0530<br>
+++ b/source/encoder/sei.cpp    Wed Mar 14 17:24:34 2018 +0530<br>
@@ -34,44 +34,33 @@<br>
     0xBB, 0x55, 0xA4, 0xFE, 0x7F, 0xC2, 0xFC, 0x4E<br>
 };<br>
<br>
+/* count the size of the payload and return the size in bits */<br>
+int SEI::countPayloadSize(const SPS& sps)<br>
+{<br>
+    BitCounter counter;<br>
+    int count = 0;<br>
+    m_bitIf = &counter;<br>
+    writeSEI(sps);<br>
+    X265_CHECK(0 == (count.getNumberOfWrittenBits(<wbr>) & 7), "payload unaligned\n");<br>
+    count = counter.<wbr>getNumberOfWrittenBits() >> 3;<br>
+    return count;<br>
+}<br>
+<br>
 /* marshal a single SEI message sei, storing the marshalled representation<br>
  * in bitstream bs */<br>
 void SEI::write(Bitstream& bs, const SPS& sps)<br>
 {<br>
     uint32_t type = m_payloadType;<br>
     m_bitIf = &bs;<br>
-    BitCounter count;<br>
-    bool hrdTypes = (m_payloadType == ACTIVE_PARAMETER_SETS || m_payloadType == PICTURE_TIMING || m_payloadType == BUFFERING_PERIOD);<br>
-    if (hrdTypes)<br>
-    {<br>
-        m_bitIf = &count;<br>
-        /* virtual writeSEI method, write to bit counter to determine size */<br>
-        writeSEI(sps);<br>
-        m_bitIf = &bs;<br>
-        uint32_t payloadType = m_payloadType;<br>
-        for (; payloadType >= 0xff; payloadType -= 0xff)<br>
-            WRITE_CODE(0xff, 8, "payload_type");<br>
-    }<br>
+    uint32_t payloadSize = m_payloadSize;<br>
+    uint32_t payloadType = m_payloadType;<br>
+    for (; payloadType >= 0xff; payloadType -= 0xff)<br>
+        WRITE_CODE(0xff, 8, "payload_type");<br>
     WRITE_CODE(type, 8, "payload_type");<br>
-    uint32_t payloadSize;<br>
-    if (hrdTypes || m_payloadType == USER_DATA_UNREGISTERED || m_payloadType == USER_DATA_REGISTERED_ITU_T_<wbr>T35)<br>
-    {<br>
-        if (hrdTypes)<br>
-        {<br>
-            X265_CHECK(0 == (count.getNumberOfWrittenBits(<wbr>) & 7), "payload unaligned\n");<br>
-            payloadSize = count.getNumberOfWrittenBits() >> 3;<br>
-        }<br>
-        else if (m_payloadType == USER_DATA_UNREGISTERED)<br>
-            payloadSize = m_payloadSize + 16;<br>
-        else<br>
-            payloadSize = m_payloadSize;<br>
<br>
-        for (; payloadSize >= 0xff; payloadSize -= 0xff)<br>
-            WRITE_CODE(0xff, 8, "payload_size");<br>
-        WRITE_CODE(payloadSize, 8, "payload_size");<br>
-    }<br>
-    else<br>
-        WRITE_CODE(m_payloadSize, 8, "payload_size");<br>
+    for (; payloadSize >= 0xff; payloadSize -= 0xff)<br>
+        WRITE_CODE(0xff, 8, "payload_size");<br>
+    WRITE_CODE(payloadSize, 8, "payload_size");<br>
     /* virtual writeSEI method, write to bs */<br>
     writeSEI(sps);<br>
 }<br>
diff -r b9f5b5d7bf95 -r a65dc9e0ecf2 source/encoder/sei.h<br>
--- a/source/encoder/sei.h      Thu Mar 15 10:52:52 2018 +0530<br>
+++ b/source/encoder/sei.h      Wed Mar 14 17:24:34 2018 +0530<br>
@@ -37,7 +37,7 @@<br>
     /* SEI users call write() to marshal an SEI to a bitstream.<br>
      * The write() method calls writeSEI() which encodes the header */<br>
     void write(Bitstream& bs, const SPS& sps);<br>
-<br>
+    int countPayloadSize(const SPS& sps);<br>
     void setSize(uint32_t size);<br>
     virtual ~SEI() {}<br>
 protected:<br>
<br>______________________________<wbr>_________________<br>
x265-devel mailing list<br>
<a href="mailto:x265-devel@videolan.org">x265-devel@videolan.org</a><br>
<a href="https://mailman.videolan.org/listinfo/x265-devel" rel="noreferrer" target="_blank">https://mailman.videolan.org/<wbr>listinfo/x265-devel</a><br>
<br></blockquote></div><br></div><div class="gmail_extra"><br></div><div class="gmail_extra">Thanks. Pushed to default.</div></div>