<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Oct 28, 2013 at 1:42 AM, Gopu Govindaswamy <span dir="ltr"><<a href="mailto:gopu@multicorewareinc.com" target="_blank">gopu@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 Gopu Govindaswamy <<a href="mailto:gopu@multicorewareinc.com">gopu@multicorewareinc.com</a>><br>
# Date 1382942530 -19800<br>
# Node ID 4327bc0b1bce6cbbeb28f4ef81063b63802b3a9a<br>
# Parent ef2428fd32feddd60168f3430c50f4d7e6f02741<br>
input: read y4m input from stdin if filename is passed as "-"<br></blockquote><div><br></div><div>queued for default, along with a commit that adds --y4m cli option to force y4m parser</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
diff -r ef2428fd32fe -r 4327bc0b1bce source/input/y4m.cpp<br>
--- a/source/input/y4m.cpp Mon Oct 28 00:08:06 2013 -0500<br>
+++ b/source/input/y4m.cpp Mon Oct 28 12:12:10 2013 +0530<br>
@@ -26,6 +26,15 @@<br>
#include "common.h"<br>
#include <stdio.h><br>
#include <string.h><br>
+#include <iostream><br>
+<br>
+#if WIN32<br>
+#include "io.h"<br>
+#include "fcntl.h"<br>
+#if defined(_MSC_VER)<br>
+#pragma warning(disable: 4996) // POSIX setmode and fileno deprecated<br>
+#endif<br>
+#endif<br>
<br>
using namespace x265;<br>
using namespace std;<br>
@@ -40,9 +49,19 @@<br>
buf = NULL;<br>
#endif<br>
<br>
- ifs.open(filename, ios::binary | ios::in);<br>
+ ifs = NULL;<br>
+ if (!strcmp(filename, "-"))<br>
+ {<br>
+ ifs = &cin;<br>
+#if WIN32<br>
+ setmode(fileno(stdin), O_BINARY);<br>
+#endif<br>
+ }<br>
+ else<br>
+ ifs = new ifstream(filename, ios::binary | ios::in);<br>
+<br>
threadActive = false;<br>
- if (!ifs.fail())<br>
+ if (ifs && !ifs->fail())<br>
{<br>
if (parseHeader())<br>
{<br>
@@ -64,13 +83,17 @@<br>
#endif // if defined(ENABLE_THREAD)<br>
}<br>
}<br>
- if (!threadActive)<br>
- ifs.close();<br>
+ if (!threadActive && ifs && ifs != &cin)<br>
+ {<br>
+ delete ifs;<br>
+ ifs = NULL;<br>
+ }<br>
}<br>
<br>
Y4MInput::~Y4MInput()<br>
{<br>
- ifs.close();<br>
+ if (ifs && ifs != &cin)<br>
+ delete ifs;<br>
#if defined(ENABLE_THREAD)<br>
for (int i = 0; i < QUEUE_SIZE; i++)<br>
{<br>
@@ -84,6 +107,9 @@<br>
<br>
bool Y4MInput::parseHeader()<br>
{<br>
+ if (!ifs)<br>
+ return false;<br>
+<br>
width = 0;<br>
height = 0;<br>
rateNum = 0;<br>
@@ -92,22 +118,22 @@<br>
while (ifs)<br>
{<br>
// Skip Y4MPEG string<br>
- int c = ifs.get();<br>
- while (!ifs.eof() && (c != ' ') && (c != '\n'))<br>
+ int c = ifs->get();<br>
+ while (!ifs->eof() && (c != ' ') && (c != '\n'))<br>
{<br>
- c = ifs.get();<br>
+ c = ifs->get();<br>
}<br>
<br>
while (c == ' ' && ifs)<br>
{<br>
// read parameter identifier<br>
- switch (ifs.get())<br>
+ switch (ifs->get())<br>
{<br>
case 'W':<br>
width = 0;<br>
while (ifs)<br>
{<br>
- c = ifs.get();<br>
+ c = ifs->get();<br>
<br>
if (c == ' ' || c == '\n')<br>
{<br>
@@ -125,7 +151,7 @@<br>
height = 0;<br>
while (ifs)<br>
{<br>
- c = ifs.get();<br>
+ c = ifs->get();<br>
if (c == ' ' || c == '\n')<br>
{<br>
break;<br>
@@ -143,13 +169,13 @@<br>
rateDenom = 0;<br>
while (ifs)<br>
{<br>
- c = ifs.get();<br>
+ c = ifs->get();<br>
if (c == '.')<br>
{<br>
rateDenom = 1;<br>
while (ifs)<br>
{<br>
- c = ifs.get();<br>
+ c = ifs->get();<br>
if (c == ' ' || c == '\n')<br>
{<br>
break;<br>
@@ -167,7 +193,7 @@<br>
{<br>
while (ifs)<br>
{<br>
- c = ifs.get();<br>
+ c = ifs->get();<br>
if (c == ' ' || c == '\n')<br>
{<br>
break;<br>
@@ -190,7 +216,7 @@<br>
while (ifs)<br>
{<br>
// consume this unsupported configuration word<br>
- c = ifs.get();<br>
+ c = ifs->get();<br>
if (c == ' ' || c == '\n')<br>
break;<br>
}<br>
@@ -217,25 +243,33 @@<br>
<br>
int Y4MInput::guessFrameCount()<br>
{<br>
- istream::pos_type cur = ifs.tellg();<br>
+ if (!ifs || ifs == &cin)<br>
+ return -1;<br>
+ istream::pos_type cur = ifs->tellg();<br>
if (cur < 0)<br>
return -1;<br>
<br>
- ifs.seekg(0, ios::end);<br>
- istream::pos_type size = ifs.tellg();<br>
+ ifs->seekg(0, ios::end);<br>
+ istream::pos_type size = ifs->tellg();<br>
if (size < 0)<br>
return -1;<br>
- ifs.seekg(cur, ios::beg);<br>
+ ifs->seekg(cur, ios::beg);<br>
<br>
return (int)((size - cur) / ((width * height * 3 / 2) + strlen(header) + 1));<br>
}<br>
<br>
void Y4MInput::skipFrames(int numFrames)<br>
{<br>
- const size_t count = (width * height * 3 / 2) + strlen(header);<br>
- for (int i = 0; i < numFrames; i++)<br>
+ const size_t count = (width * height * 3 / 2) + strlen(header) + 1;<br>
+ if (ifs && numFrames)<br>
{<br>
- ifs.ignore(count);<br>
+ if (ifs == &cin)<br>
+ {<br>
+ for (int i = 0; i < numFrames; i++)<br>
+ ifs->ignore(count);<br>
+ }<br>
+ else<br>
+ ifs->seekg(count * numFrames, ios::cur);<br>
}<br>
}<br>
<br>
@@ -296,8 +330,10 @@<br>
{<br>
/* strip off the FRAME header */<br>
char hbuf[sizeof(header)];<br>
+ if (!ifs)<br>
+ return false;<br>
<br>
- ifs.read(hbuf, strlen(header));<br>
+ ifs->read(hbuf, strlen(header));<br>
if (!ifs || memcmp(hbuf, header, strlen(header)))<br>
{<br>
if (ifs)<br>
@@ -305,10 +341,10 @@<br>
return false;<br>
}<br>
/* consume bytes up to line feed */<br>
- int c = ifs.get();<br>
+ int c = ifs->get();<br>
while (c != '\n' && !ifs)<br>
{<br>
- c = ifs.get();<br>
+ c = ifs->get();<br>
}<br>
<br>
const size_t count = width * height * 3 / 2;<br>
@@ -319,11 +355,11 @@<br>
return false;<br>
}<br>
<br>
- ifs.read(buf[tail], count);<br>
- frameStat[tail] = !ifs.fail();<br>
+ ifs->read(buf[tail], count);<br>
+ frameStat[tail] = !ifs->fail();<br>
tail = (tail + 1) % QUEUE_SIZE;<br>
notEmpty.trigger();<br>
- return !ifs.fail();<br>
+ return !ifs->fail();<br>
}<br>
<br>
#else // if defined(ENABLE_THREAD)<br>
@@ -333,7 +369,11 @@<br>
<br>
/* strip off the FRAME header */<br>
char hbuf[sizeof(header)];<br>
- ifs.read(hbuf, strlen(header));<br>
+<br>
+ if (!ifs)<br>
+ return false;<br>
+<br>
+ ifs->read(hbuf, strlen(header));<br>
if (!ifs || memcmp(hbuf, header, strlen(header)))<br>
{<br>
x265_log(NULL, X265_LOG_ERROR, "y4m: frame header missing\n");<br>
@@ -341,10 +381,10 @@<br>
}<br>
<br>
/* consume bytes up to line feed */<br>
- int c = ifs.get();<br>
+ int c = ifs->get();<br>
while (c != '\n' && !ifs)<br>
{<br>
- c = ifs.get();<br>
+ c = ifs->get();<br>
}<br>
<br>
const size_t count = width * height * 3 / 2;<br>
@@ -361,10 +401,10 @@<br>
<br>
pic.stride[1] = pic.stride[2] = pic.stride[0] >> 1;<br>
<br>
- ifs.read(buf, count);<br>
+ ifs->read(buf, count);<br>
PPAStopCpuEventFunc(read_yuv);<br>
<br>
- return !ifs.fail();<br>
+ return !ifs->fail();<br>
}<br>
<br>
#endif // if defined(ENABLE_THREAD)<br>
diff -r ef2428fd32fe -r 4327bc0b1bce source/input/y4m.h<br>
--- a/source/input/y4m.h Mon Oct 28 00:08:06 2013 -0500<br>
+++ b/source/input/y4m.h Mon Oct 28 12:12:10 2013 +0530<br>
@@ -68,7 +68,7 @@<br>
#else // if defined(ENABLE_THREAD)<br>
char *buf;<br>
#endif // if defined(ENABLE_THREAD)<br>
- std::ifstream ifs;<br>
+ std::istream *ifs;<br>
<br>
bool parseHeader();<br>
<br>
@@ -88,9 +88,9 @@<br>
<br>
int getHeight() const { return height; }<br>
<br>
- bool isEof() const { return ifs.eof(); }<br>
+ bool isEof() const { return (ifs && ifs->eof()); }<br>
<br>
- bool isFail() { return !(ifs.is_open() && threadActive); }<br>
+ bool isFail() { return !(ifs && !ifs->fail() && threadActive); }<br>
<br>
void startReader();<br>
<br>
_______________________________________________<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" target="_blank">https://mailman.videolan.org/listinfo/x265-devel</a><br>
</blockquote></div><br><br clear="all"><div><br></div>-- <br>Steve Borho
</div></div>