<div dir="ltr"><div dir="ltr"><div class="gmail_default" style="font-family:tahoma,sans-serif"><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Nov 12, 2024 at 7:48 PM Andrey Semashev <<a href="mailto:andrey.semashev@gmail.com">andrey.semashev@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On 11/12/24 16:20, Pavan Tarun Chakka Venkata wrote:<br>
<br>
This patch has broken indentation (using tabs).</blockquote><div> </div><span style="font-family:tahoma,sans-serif">Thanks for pointing this out, I missed this while rebasing.</span><br style="font-family:tahoma,sans-serif"><span style="font-family:tahoma,sans-serif">Will send an updated patch.<br><br></span><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
> From 52d1f689c5bcc8a6b913e55094d0dcc03a7ff809 Mon Sep 17 00:00:00 2001<br>
> From: PavanTarun <<a href="mailto:pavan.tarun@multicorewareinc.com" target="_blank">pavan.tarun@multicorewareinc.com</a><br>
> <mailto:<a href="mailto:pavan.tarun@multicorewareinc.com" target="_blank">pavan.tarun@multicorewareinc.com</a>>><br>
> Date: Sat, 9 Nov 2024 13:18:18 +0530<br>
> Subject: [PATCH 3/3] SEI Memory Leak Fix<br>
> <br>
> ---<br>
> source/encoder/encoder.cpp | 5 +-<br>
> source/encoder/sei.cpp | 102 +++++++++++++++++--------------------<br>
> source/encoder/sei.h | 2 +-<br>
> 3 files changed, 53 insertions(+), 56 deletions(-)<br>
> <br>
> diff --git a/source/encoder/encoder.cpp b/source/encoder/encoder.cpp<br>
> index eef7519a1..db6d746e3 100644<br>
> --- a/source/encoder/encoder.cpp<br>
> +++ b/source/encoder/encoder.cpp<br>
> @@ -6127,7 +6127,9 @@ void Encoder::readUserSeiFile(x265_sei_payload&<br>
> seiMsg, int curPoc)<br>
> int payloadType = atoi(strtok(NULL, " "));<br>
> char *base64Encode = strtok(NULL, "\n");<br>
> int base64EncodeLength = (int)strlen(base64Encode);<br>
> - char *base64Decode = SEI::base64Decode(base64Encode,<br>
> base64EncodeLength);<br>
> + char* decodedString;<br>
> + decodedString = (char*)malloc(sizeof(char) * (base64EncodeLength));<br>
> + char *base64Decode = SEI::base64Decode(base64Encode,<br>
> base64EncodeLength, decodedString);<br>
> if (nalType == NAL_UNIT_PREFIX_SEI && (!strcmp(prefix, "PREFIX")))<br>
> {<br>
> int currentPOC = curPoc;<br>
> @@ -6150,6 +6152,7 @@ void Encoder::readUserSeiFile(x265_sei_payload&<br>
> seiMsg, int curPoc)<br>
> break;<br>
> }<br>
> memcpy(seiMsg.payload, base64Decode, seiMsg.payloadSize);<br>
> + free(decodedString);<br>
> break;<br>
> }<br>
> }<br>
> diff --git a/source/encoder/sei.cpp b/source/encoder/sei.cpp<br>
> index 6e4b805e5..85cd7894a 100644<br>
> --- a/source/encoder/sei.cpp<br>
> +++ b/source/encoder/sei.cpp<br>
> @@ -92,60 +92,54 @@ void SEI::setSize(uint32_t size)<br>
> <br>
> /* charSet =<br>
> "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" */<br>
> <br>
> -char* SEI::base64Decode(char encodedString[], int base64EncodeLength)<br>
> +char* SEI::base64Decode(char encodedString[], int base64EncodeLength,<br>
> char* decodedString)<br>
> {<br>
> - char* decodedString;<br>
> - decodedString = (char*)malloc(sizeof(char) * ((base64EncodeLength /<br>
> 4) * 3));<br>
> - int i, j, k = 0;<br>
> - // stores the bitstream<br>
> - int bitstream = 0;<br>
> - // countBits stores current number of bits in bitstream<br>
> - int countBits = 0;<br>
> - // selects 4 characters from encodedString at a time. Find the<br>
> position of each encoded character in charSet and stores in bitstream<br>
> - for (i = 0; i < base64EncodeLength; i += 4)<br>
> - {<br>
> - bitstream = 0, countBits = 0;<br>
> - for (j = 0; j < 4; j++)<br>
> - {<br>
> - // make space for 6 bits<br>
> - if (encodedString[i + j] != '=')<br>
> - {<br>
> - bitstream = bitstream << 6;<br>
> - countBits += 6;<br>
> - }<br>
> - // Finding the position of each encoded character in<br>
> charSet and storing in bitstream, use OR '|' operator to store bits<br>
> -<br>
> - if (encodedString[i + j] >= 'A' && encodedString[i + j] <= 'Z')<br>
> - bitstream = bitstream | (encodedString[i + j] - 'A');<br>
> -<br>
> - else if (encodedString[i + j] >= 'a' && encodedString[i +<br>
> j] <= 'z')<br>
> - bitstream = bitstream | (encodedString[i + j] - 'a' + 26);<br>
> - <br>
> - else if (encodedString[i + j] >= '0' && encodedString[i +<br>
> j] <= '9')<br>
> - bitstream = bitstream | (encodedString[i + j] - '0' + 52);<br>
> - <br>
> - // '+' occurs in 62nd position in charSet<br>
> - else if (encodedString[i + j] == '+')<br>
> - bitstream = bitstream | 62;<br>
> - <br>
> - // '/' occurs in 63rd position in charSet<br>
> - else if (encodedString[i + j] == '/')<br>
> - bitstream = bitstream | 63;<br>
> - <br>
> - // to delete appended bits during encoding<br>
> - else<br>
> - {<br>
> - bitstream = bitstream >> 2;<br>
> - countBits -= 2;<br>
> - }<br>
> - }<br>
> - <br>
> - while (countBits != 0)<br>
> - {<br>
> - countBits -= 8;<br>
> - decodedString[k++] = (bitstream >> countBits) & 255;<br>
> - }<br>
> - }<br>
> - return decodedString;<br>
> + int i, j, k = 0;<br>
> + // stores the bitstream<br>
> + int bitstream = 0;<br>
> + // countBits stores the current number of bits in bitstream<br>
> + int countBits = 0;<br>
> +<br>
> + for (i = 0; i < base64EncodeLength; i += 4)<br>
> + {<br>
> + bitstream = 0;<br>
> + countBits = 0;<br>
> +<br>
> + for (j = 0; j < 4; j++)<br>
> + {<br>
> + if (encodedString[i + j] != '=')<br>
> + {<br>
> + int value = 0;<br>
> + if (encodedString[i + j] >= 'A' && encodedString[i + j] <= 'Z')<br>
> + value = encodedString[i + j] - 'A';<br>
> + else if (encodedString[i + j] >= 'a' && encodedString[i + j] <= 'z')<br>
> + value = encodedString[i + j] - 'a' + 26;<br>
> + else if (encodedString[i + j] >= '0' && encodedString[i + j] <= '9')<br>
> + value = encodedString[i + j] - '0' + 52;<br>
> + else if (encodedString[i + j] == '+')<br>
> + value = 62;<br>
> + else if (encodedString[i + j] == '/')<br>
> + value = 63;<br>
> + else<br>
> + value = 0;<br>
> +<br>
> + bitstream = (bitstream << 6) | value;<br>
> + countBits += 6;<br>
> + }<br>
> + }<br>
> +<br>
> + while (countBits >= 8)<br>
> + {<br>
> + countBits -= 8;<br>
> + decodedString[k++] = (bitstream >> countBits) & 0xFF;<br>
> + }<br>
> + }<br>
> +<br>
> + if (k < base64EncodeLength)<br>
> + {<br>
> + decodedString[k] = '\0';<br>
> + }<br>
> +<br>
> + return decodedString;<br>
> }<br>
> <br>
> diff --git a/source/encoder/sei.h b/source/encoder/sei.h<br>
> index a33cb94e9..f02e0c50d 100644<br>
> --- a/source/encoder/sei.h<br>
> +++ b/source/encoder/sei.h<br>
> @@ -40,7 +40,7 @@ public:<br>
> * The writeSEImessages() method calls writeSEI() which encodes the<br>
> header */<br>
> void writeSEImessages(Bitstream& bs, const SPS& sps, NalUnitType<br>
> nalUnitType, NALList& list, int isNested, int layerId = 0);<br>
> void setSize(uint32_t size);<br>
> - static char* base64Decode(char encodedString[], int<br>
> base64EncodeLength);<br>
> + static char* base64Decode(char encodedString[], int<br>
> base64EncodeLength, char* base64Decode);<br>
> virtual ~SEI() {}<br>
> protected:<br>
> SEIPayloadType m_payloadType;<br>
> -- <br>
> 2.41.0.windows.1<br>
> <br>
> <br>
> _______________________________________________<br>
> x265-devel mailing list<br>
> <a href="mailto:x265-devel@videolan.org" target="_blank">x265-devel@videolan.org</a><br>
> <a href="https://mailman.videolan.org/listinfo/x265-devel" rel="noreferrer" target="_blank">https://mailman.videolan.org/listinfo/x265-devel</a><br>
<br>
_______________________________________________<br>
x265-devel mailing list<br>
<a href="mailto:x265-devel@videolan.org" target="_blank">x265-devel@videolan.org</a><br>
<a href="https://mailman.videolan.org/listinfo/x265-devel" rel="noreferrer" target="_blank">https://mailman.videolan.org/listinfo/x265-devel</a></blockquote><div> </div><div class="gmail_default" style="font-family:tahoma,sans-serif">Thanks,</div><span style="font-family:tahoma,sans-serif">Pavan Tarun</span></div></div>