<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Jan 16, 2018 at 1:15 AM, Ashok Kumar Mishra <span dir="ltr"><<a href="mailto:ashok@multicorewareinc.com" target="_blank">ashok@multicorewareinc.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div class="h5"><br><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Jan 13, 2018 at 7:43 AM, Ma0 <span dir="ltr"><<a href="mailto:mateuszb@poczta.onet.pl" target="_blank">mateuszb@poczta.onet.pl</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 Ma0 <<a href="mailto:mateuszb@poczta.onet.pl" target="_blank">mateuszb@poczta.onet.pl</a>><br>
# Date 1515808050 -3600<br>
# Sat Jan 13 02:47:30 2018 +0100<br>
# Node ID 5066d1a0dfa3a7a5aef54c26b93b03<wbr>595b3e3508<br>
# Parent 2f3c4158cf3553030920708271bc43<wbr>cdc79932a3<br>
input: change from ifstream to stdio stream<br>
<br>
diff -r 2f3c4158cf35 -r 5066d1a0dfa3 source/common/common.h<br>
--- a/source/common/common.h Thu Jan 04 12:37:01 2018 +0530<br>
+++ b/source/common/common.h Sat Jan 13 02:47:30 2018 +0100<br>
@@ -78,6 +78,7 @@<br>
<br>
#if defined(__MINGW32__)<br>
#define fseeko fseeko64<br>
+#define ftello ftello64<br>
#endif<br>
<br>
#elif defined(_MSC_VER)<br>
@@ -87,6 +88,7 @@<br>
#define ALIGN_VAR_16(T, var) __declspec(align(16)) T var<br>
#define ALIGN_VAR_32(T, var) __declspec(align(32)) T var<br>
#define fseeko _fseeki64<br>
+#define ftello _ftelli64<br>
<br>
#endif // if defined(__GNUC__)<br>
<br>
diff -r 2f3c4158cf35 -r 5066d1a0dfa3 source/input/y4m.cpp<br>
--- a/source/input/y4m.cpp Thu Jan 04 12:37:01 2018 +0530<br>
+++ b/source/input/y4m.cpp Sat Jan 13 02:47:30 2018 +0100<br>
@@ -39,7 +39,7 @@<br>
using namespace X265_NS;<br>
using namespace std;<br>
<br>
-static const char header[] = "FRAME";<br>
+static const char header[] = {'F','R','A','M','E'};<br>
<br>
Y4MInput::Y4MInput(InputFileI<wbr>nfo& info)<br>
{<br>
@@ -60,15 +60,15 @@<br>
ifs = NULL;<br>
if (!strcmp(info.filename, "-"))<br>
{<br>
- ifs = &cin;<br>
+ ifs = stdin;<br>
#if _WIN32<br>
setmode(fileno(stdin), O_BINARY);<br>
#endif<br>
}<br>
else<br>
- ifs = new ifstream(info.filename, ios::binary | ios::in);<br>
+ ifs = x265_fopen(info.filename, "rb");<br>
<br>
- if (ifs && ifs->good() && parseHeader())<br>
+ if (ifs && !ferror(ifs) && parseHeader())<br>
{<br>
int pixelbytes = depth > 8 ? 2 : 1;<br>
for (int i = 0; i < x265_cli_csps[colorSpace].plan<wbr>es; i++)<br>
@@ -91,8 +91,8 @@<br>
}<br>
if (!threadActive)<br>
{<br>
- if (ifs && ifs != &cin)<br>
- delete ifs;<br>
+ if (ifs && ifs != stdin)<br>
+ fclose(ifs);<br>
ifs = NULL;<br>
return;<br>
}<br>
@@ -107,59 +107,38 @@<br>
info.depth = depth;<br>
info.frameCount = -1;<br>
<br>
- size_t estFrameSize = framesize + strlen(header) + 1; /* assume basic FRAME\n headers */<br>
+ size_t estFrameSize = framesize + sizeof(header) + 1; /* assume basic FRAME\n headers */<br>
<br>
/* try to estimate frame count, if this is not stdin */<br>
- if (ifs != &cin)<br>
+ if (ifs != stdin)<br>
{<br>
- istream::pos_type cur = ifs->tellg();<br>
+ int64_t cur = ftello(ifs);<br>
<br>
-#if defined(_MSC_VER) && _MSC_VER < 1700<br>
- /* Older MSVC versions cannot handle 64bit file sizes properly, so go native */<br>
- HANDLE hFile = CreateFileA(info.filename, GENERIC_READ,<br>
- FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING,<br>
- FILE_ATTRIBUTE_NORMAL, NULL);<br>
- if (hFile != INVALID_HANDLE_VALUE)<br>
- {<br>
- LARGE_INTEGER size;<br>
- if (GetFileSizeEx(hFile, &size))<br>
- info.frameCount = (int)((size.QuadPart - (int64_t)cur) / estFrameSize);<br>
- CloseHandle(hFile);<br>
- }<br>
-#else // if defined(_MSC_VER) && _MSC_VER < 1700<br>
if (cur >= 0)<br>
{<br>
- ifs->seekg(0, ios::end);<br>
- istream::pos_type size = ifs->tellg();<br>
- ifs->seekg(cur, ios::beg);<br>
+ fseeko(ifs, 0, SEEK_END);<br>
+ int64_t size = ftello(ifs);<br>
+ fseeko(ifs, cur, SEEK_SET);<br>
if (size > 0)<br>
info.frameCount = (int)((size - cur) / estFrameSize);<br>
}<br>
-#endif // if defined(_MSC_VER) && _MSC_VER < 1700<br>
}<br>
<br>
if (info.skipFrames)<br>
{<br>
-#if X86_64<br>
- if (ifs != &cin)<br>
- ifs->seekg((uint64_t)estFrameS<wbr>ize * info.skipFrames, ios::cur);<br>
+ if (ifs != stdin)<br>
+ fseeko(ifs, (int64_t)estFrameSize * info.skipFrames, SEEK_CUR);<br>
else<br>
for (int i = 0; i < info.skipFrames; i++)<br>
- {<br>
- ifs->read(buf[0], estFrameSize - framesize);<br>
- ifs->read(buf[0], framesize);<br>
- }<br>
-#else<br>
- for (int i = 0; i < info.skipFrames; i++)<br>
- ifs->ignore(estFrameSize);<br>
-#endif<br>
+ if (fread(buf[0], estFrameSize - framesize, 1, ifs) + fread(buf[0], framesize, 1, ifs) != 2)<br>
+ break;<br>
}<br>
}<br>
<br>
Y4MInput::~Y4MInput()<br>
{<br>
- if (ifs && ifs != &cin)<br>
- delete ifs;<br>
+ if (ifs && ifs != stdin)<br>
+ fclose(ifs);<br>
<br>
for (int i = 0; i < QUEUE_SIZE; i++)<br>
X265_FREE(buf[i]);<br>
@@ -181,24 +160,22 @@<br>
int csp = 0;<br>
int d = 0;<br>
<br>
- while (ifs->good())<br>
+ int c;<br>
+ while ((c = fgetc(ifs)) != EOF)<br>
{<br>
// Skip Y4MPEG string<br>
- int c = ifs->get();<br>
- while (ifs->good() && (c != ' ') && (c != '\n'))<br>
- c = ifs->get();<br>
+ while ((c != EOF) && (c != ' ') && (c != '\n'))<br>
+ c = fgetc(ifs);<br>
<br>
- while (c == ' ' && ifs->good())<br>
+ while (c == ' ')<br>
{<br>
// read parameter identifier<br>
- switch (ifs->get())<br>
+ switch (fgetc(ifs))<br>
{<br>
case 'W':<br>
width = 0;<br>
- while (ifs->good())<br>
+ while ((c = fgetc(ifs)) != EOF)<br>
{<br>
- c = ifs->get();<br>
-<br>
if (c == ' ' || c == '\n')<br>
break;<br>
else<br>
@@ -208,9 +185,8 @@<br>
<br>
case 'H':<br>
height = 0;<br>
- while (ifs->good())<br>
+ while ((c = fgetc(ifs)) != EOF)<br>
{<br>
- c = ifs->get();<br>
if (c == ' ' || c == '\n')<br>
break;<br>
else<br>
@@ -221,15 +197,13 @@<br>
case 'F':<br>
rateNum = 0;<br>
rateDenom = 0;<br>
- while (ifs->good())<br>
+ while ((c = fgetc(ifs)) != EOF)<br>
{<br>
- c = ifs->get();<br>
if (c == '.')<br>
{<br>
rateDenom = 1;<br>
- while (ifs->good())<br>
+ while ((c = fgetc(ifs)) != EOF)<br>
{<br>
- c = ifs->get();<br>
if (c == ' ' || c == '\n')<br>
break;<br>
else<br>
@@ -242,9 +216,8 @@<br>
}<br>
else if (c == ':')<br>
{<br>
- while (ifs->good())<br>
+ while ((c = fgetc(ifs)) != EOF)<br>
{<br>
- c = ifs->get();<br>
if (c == ' ' || c == '\n')<br>
break;<br>
else<br>
@@ -260,14 +233,12 @@<br>
case 'A':<br>
sarWidth = 0;<br>
sarHeight = 0;<br>
- while (ifs->good())<br>
+ while ((c = fgetc(ifs)) != EOF)<br>
{<br>
- c = ifs->get();<br>
if (c == ':')<br>
{<br>
- while (ifs->good())<br>
+ while ((c = fgetc(ifs)) != EOF)<br>
{<br>
- c = ifs->get();<br>
if (c == ' ' || c == '\n')<br>
break;<br>
else<br>
@@ -283,19 +254,15 @@<br>
case 'C':<br>
csp = 0;<br>
d = 0;<br>
- while (ifs->good())<br>
+ while ((c = fgetc(ifs)) != EOF)<br>
{<br>
- c = ifs->get();<br>
-<br>
if (c <= 'o' && c >= '0')<br>
csp = csp * 10 + (c - '0');<br>
else if (c == 'p')<br>
{<br>
// example: C420p16<br>
- while (ifs->good())<br>
+ while ((c = fgetc(ifs)) != EOF)<br>
{<br>
- c = ifs->get();<br>
-<br>
if (c <= '9' && c >= '0')<br>
d = d * 10 + (c - '0');<br>
else<br>
@@ -330,10 +297,9 @@<br>
break;<br>
<br>
default:<br>
- while (ifs->good())<br>
+ while ((c = fgetc(ifs)) != EOF)<br>
{<br>
// consume this unsupported configuration word<br>
- c = ifs->get();<br>
if (c == ' ' || c == '\n')<br>
break;<br>
}<br>
@@ -378,26 +344,24 @@<br>
<br>
bool Y4MInput::populateFrameQueue()<br>
{<br>
- if (!ifs || ifs->fail())<br>
+ if (!ifs || ferror(ifs))<br>
return false;<br>
<br>
- /* strip off the FRAME header */<br>
- char hbuf[sizeof(header)];<br>
+ /* strip off the FRAME\n header */<br>
+ char hbuf[sizeof(header) + 1];<br>
<br>
- ifs->read(hbuf, strlen(header));<br>
- if (ifs->eof())<br>
- return false;<br>
-<br>
- if (!ifs->good() || memcmp(hbuf, header, strlen(header)))<br>
+ if (fread(hbuf, sizeof(hbuf), 1, ifs) != 1 || memcmp(hbuf, header, sizeof(header)))<br>
{<br>
- x265_log(NULL, X265_LOG_ERROR, "y4m: frame header missing\n");<br>
+ if (!feof(ifs))<br>
+ x265_log(NULL, X265_LOG_ERROR, "y4m: frame header missing\n");<br>
return false;<br>
}<br>
<br>
/* consume bytes up to line feed */<br>
- int c = ifs->get();<br>
- while (c != '\n' && ifs->good())<br>
- c = ifs->get();<br>
+ int c = hbuf[sizeof(header)];<br>
+ while (c != '\n')<br>
+ if ((c = fgetc(ifs)) == EOF)<br>
+ break;<br>
<br>
/* wait for room in the ring buffer */<br>
int written = writeCount.get();<br>
@@ -410,8 +374,7 @@<br>
}<br>
<br>
ProfileScopeEvent(frameRead);<br>
- ifs->read(buf[written % QUEUE_SIZE], framesize);<br>
- if (ifs->good())<br>
+ if (fread(buf[written % QUEUE_SIZE], framesize, 1, ifs) == 1)<br>
{<br>
writeCount.incr();<br>
return true;<br>
diff -r 2f3c4158cf35 -r 5066d1a0dfa3 source/input/y4m.h<br>
--- a/source/input/y4m.h Thu Jan 04 12:37:01 2018 +0530<br>
+++ b/source/input/y4m.h Sat Jan 13 02:47:30 2018 +0100<br>
@@ -63,7 +63,7 @@<br>
<br>
char* buf[QUEUE_SIZE];<br>
<br>
- std::istream *ifs;<br>
+ FILE *ifs;<br>
<br>
bool parseHeader();<br>
<br>
@@ -79,9 +79,9 @@<br>
<br>
void release();<br>
<br>
- bool isEof() const { return ifs && ifs->eof(); }<br>
+ bool isEof() const { return ifs && feof(ifs); }<br>
<br>
- bool isFail() { return !(ifs && !ifs->fail() && threadActive); }<br>
+ bool isFail() { return !(ifs && !ferror(ifs) && threadActive); }<br>
<br>
void startReader();<br>
<br>
diff -r 2f3c4158cf35 -r 5066d1a0dfa3 source/input/yuv.cpp<br>
--- a/source/input/yuv.cpp Thu Jan 04 12:37:01 2018 +0530<br>
+++ b/source/input/yuv.cpp Sat Jan 13 02:47:30 2018 +0100<br>
@@ -68,20 +68,20 @@<br>
<br>
if (!strcmp(info.filename, "-"))<br>
{<br>
- ifs = &cin;<br>
+ ifs = stdin;<br>
#if _WIN32<br>
setmode(fileno(stdin), O_BINARY);<br>
#endif<br>
}<br>
else<br>
- ifs = new ifstream(info.filename, ios::binary | ios::in);<br>
+ ifs = x265_fopen(info.filename, "rb");<br>
<br>
- if (ifs && ifs->good())<br>
+ if (ifs && !ferror(ifs))<br>
threadActive = true;<br>
else<br>
{<br>
- if (ifs && ifs != &cin)<br>
- delete ifs;<br>
+ if (ifs && ifs != stdin)<br>
+ fclose(ifs);<br>
ifs = NULL;<br>
return;<br>
}<br>
@@ -100,53 +100,35 @@<br>
info.frameCount = -1;<br>
<br>
/* try to estimate frame count, if this is not stdin */<br>
- if (ifs != &cin)<br>
+ if (ifs != stdin)<br>
{<br>
- istream::pos_type cur = ifs->tellg();<br>
+ int64_t cur = ftello(ifs);<br>
<br>
-#if defined(_MSC_VER) && _MSC_VER < 1700<br>
- /* Older MSVC versions cannot handle 64bit file sizes properly, so go native */<br>
- HANDLE hFile = CreateFileA(info.filename, GENERIC_READ,<br>
- FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING,<br>
- FILE_ATTRIBUTE_NORMAL, NULL);<br>
- if (hFile != INVALID_HANDLE_VALUE)<br>
- {<br>
- LARGE_INTEGER size;<br>
- if (GetFileSizeEx(hFile, &size))<br>
- info.frameCount = (int)((size.QuadPart - (int64_t)cur) / framesize);<br>
- CloseHandle(hFile);<br>
- }<br>
-#else // if defined(_MSC_VER) && _MSC_VER < 1700<br>
if (cur >= 0)<br>
{<br>
- ifs->seekg(0, ios::end);<br>
- istream::pos_type size = ifs->tellg();<br>
- ifs->seekg(cur, ios::beg);<br>
+ fseeko(ifs, 0, SEEK_END);<br>
+ int64_t size = ftello(ifs);<br>
+ fseeko(ifs, cur, SEEK_SET);<br>
if (size > 0)<br>
info.frameCount = (int)((size - cur) / framesize);<br>
}<br>
-#endif // if defined(_MSC_VER) && _MSC_VER < 1700<br>
}<br>
<br>
if (info.skipFrames)<br>
{<br>
-#if X86_64<br>
- if (ifs != &cin)<br>
- ifs->seekg((uint64_t)framesize * info.skipFrames, ios::cur);<br>
+ if (ifs != stdin)<br>
+ fseeko(ifs, (int64_t)framesize * info.skipFrames, SEEK_CUR);<br>
else<br>
for (int i = 0; i < info.skipFrames; i++)<br>
- ifs->read(buf[0], framesize);<br>
-#else<br>
- for (int i = 0; i < info.skipFrames; i++)<br>
- ifs->ignore(framesize);<br>
-#endif<br>
+ if (fread(buf[0], framesize, 1, ifs) != 1)<br>
+ break;<br>
}<br>
}<br>
<br>
YUVInput::~YUVInput()<br>
{<br>
- if (ifs && ifs != &cin)<br>
- delete ifs;<br>
+ if (ifs && ifs != stdin)<br>
+ fclose(ifs);<br>
for (int i = 0; i < QUEUE_SIZE; i++)<br>
X265_FREE(buf[i]);<br>
}<br>
@@ -182,7 +164,7 @@<br>
<br>
bool YUVInput::populateFrameQueue()<br>
{<br>
- if (!ifs || ifs->fail())<br>
+ if (!ifs || ferror(ifs))<br>
return false;<br>
<br>
/* wait for room in the ring buffer */<br>
@@ -197,8 +179,7 @@<br>
}<br>
<br>
ProfileScopeEvent(frameRead);<br>
- ifs->read(buf[written % QUEUE_SIZE], framesize);<br>
- if (ifs->good())<br>
+ if (fread(buf[written % QUEUE_SIZE], framesize, 1, ifs) == 1)<br>
{<br>
writeCount.incr();<br>
return true;<br>
diff -r 2f3c4158cf35 -r 5066d1a0dfa3 source/input/yuv.h<br>
--- a/source/input/yuv.h Thu Jan 04 12:37:01 2018 +0530<br>
+++ b/source/input/yuv.h Sat Jan 13 02:47:30 2018 +0100<br>
@@ -55,7 +55,7 @@<br>
<br>
char* buf[QUEUE_SIZE];<br>
<br>
- std::istream *ifs;<br>
+ FILE *ifs;<br>
<br>
int guessFrameCount();<br>
<br>
@@ -71,9 +71,9 @@<br>
<br>
void release();<br>
<br>
- bool isEof() const { return ifs && ifs->eof(); }<br>
+ bool isEof() const { return ifs && feof(ifs); }<br>
<br>
- bool isFail() { return !(ifs && !ifs->fail() && threadActive); }<br>
+ bool isFail() { return !(ifs && !ferror(ifs) && threadActive); }<br>
<br>
void startReader();<br>
<br>
______________________________<wbr>_________________<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/l<wbr>istinfo/x265-devel</a><br>
</blockquote></div><br></div></div></div><div class="gmail_extra">Looks good to me, can be pushed to default branch after smoke test.</div></div>
</blockquote></div><br></div><div class="gmail_extra"><br></div><div class="gmail_extra">Pushed.</div></div>