<div dir="ltr">Mauteusz,<div>Did you get a chance to turn-this around? I think the performance improvement on MacOS is worth pulling this in.<br><div class="gmail_extra"><div><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div>Pradeep.</div><div><br></div></div></div></div></div></div></div></div></div></div></div></div></div></div></div><div class="gmail_quote">On Wed, Jan 10, 2018 at 8:04 PM, Mateusz <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">
  
    
  
  <div text="#000000" bgcolor="#FFFFFF">
    W dniu 25.05.2017 o 06:46, Pradeep Ramachandran pisze:<span class=""><br>
    <blockquote type="cite">
      <div dir="ltr">
        <div class="gmail_extra"><br>
          <div class="gmail_quote">On Sun, Apr 30, 2017 at 5:24 PM,
            Mateusz Brzostek <span dir="ltr"><<a href="mailto:mateusz@msystem.waw.pl" target="_blank">mateusz@msystem.waw.pl</a>></span>
            wrote:<br>
            <blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">This
              patch fixes issue #341 and allows Unicode filenames in
              Windows.<br>
              <br>
              Please review.<br>
              <br>
              # HG changeset patch<br>
              # User Ma0 <<a href="mailto:mateuszb@poczta.onet.pl" target="_blank">mateuszb@poczta.onet.pl</a>><br>
              # Date 1493552587 -7200<br>
              #      Sun Apr 30 13:43:07 2017 +0200<br>
              # Node ID 0c7e08be80975e4b52f6c8aabe95d3<wbr>b817d6723d<br>
              # Parent  5bc5e73760cdb61d2674e74cc52149<wbr>fa0603af8a<br>
              input: change from ifstream to stdio stream<br>
            </blockquote>
            <div><br>
            </div>
            <div>I finally got around to testing this patch! Apologies
              for the delay.</div>
            <div><br>
              I like this change and would like to pull it in. I don't
              see any performance improvement from my test with my linux
              box, but I would suspect there would be benefits of moving
              to stdio stream from ifstream.</div>
            <div><br>
            </div>
            <div>This patch no longer applied on top of the default tip.
              Could you please refactor and resend so that I can pull-it
              in and commit it to the default tip?</div>
          </div>
        </div>
      </div>
    </blockquote>
    <br></span>
    Sorry for delay -- I've subscribed to ffmpeg-devel list and didn't
    notice this e-mail.<br>
    <br>
    Now I'm busy at work but at the end of the week (Sunday) I will
    prepare new patch.<br>
    It is also not faster on my system (Windows) with this patch.<span class="HOEnZb"><font color="#888888"><br>
    <br>
    Mateusz</font></span><div><div class="h5"><br>
    <br>
    <br>
    <br>
    <br>
    <blockquote type="cite">
      <div dir="ltr">
        <div class="gmail_extra">
          <div class="gmail_quote">
            <div><br>
            </div>
            <blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
              <br>
              diff -r 5bc5e73760cd -r 0c7e08be8097
              source/common/common.h<br>
              --- a/source/common/common.h    Sat Apr 22 17:00:28 2017
              -0700<br>
              +++ b/source/common/common.h    Sun Apr 30 13:43:07 2017
              +0200<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 5bc5e73760cd -r 0c7e08be8097 source/input/y4m.cpp<br>
              --- a/source/input/y4m.cpp    Sat Apr 22 17:00:28 2017
              -0700<br>
              +++ b/source/input/y4m.cpp    Sun Apr 30 13:43:07 2017
              +0200<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>
              @@ -110,56 +110,35 @@<br>
                   size_t estFrameSize = framesize + strlen(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>
              @@ -327,10 +294,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>
              @@ -375,26 +341,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>
              <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, strlen(header), 1, ifs) != 1 ||
              memcmp(hbuf, header, strlen(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;<br>
              +    while ((c = fgetc(ifs)) != EOF)<br>
              +        if (c == '\n')<br>
              +            break;<br>
              <br>
                   /* wait for room in the ring buffer */<br>
                   int written = writeCount.get();<br>
              @@ -407,8 +371,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 5bc5e73760cd -r 0c7e08be8097 source/input/y4m.h<br>
              --- a/source/input/y4m.h    Sat Apr 22 17:00:28 2017 -0700<br>
              +++ b/source/input/y4m.h    Sun Apr 30 13:43:07 2017 +0200<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 5bc5e73760cd -r 0c7e08be8097 source/input/yuv.cpp<br>
              --- a/source/input/yuv.cpp    Sat Apr 22 17:00:28 2017
              -0700<br>
              +++ b/source/input/yuv.cpp    Sun Apr 30 13:43:07 2017
              +0200<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 5bc5e73760cd -r 0c7e08be8097 source/input/yuv.h<br>
              --- a/source/input/yuv.h    Sat Apr 22 17:00:28 2017 -0700<br>
              +++ b/source/input/yuv.h    Sun Apr 30 13:43:07 2017 +0200<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>
              <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>
              <br>
            </blockquote>
          </div>
          <br>
        </div>
      </div>
      <br>
      <fieldset class="m_6467617131875921649mimeAttachmentHeader"></fieldset>
      <br>
      <pre>______________________________<wbr>_________________
x265-devel mailing list
<a class="m_6467617131875921649moz-txt-link-abbreviated" href="mailto:x265-devel@videolan.org" target="_blank">x265-devel@videolan.org</a>
<a class="m_6467617131875921649moz-txt-link-freetext" href="https://mailman.videolan.org/listinfo/x265-devel" target="_blank">https://mailman.videolan.org/<wbr>listinfo/x265-devel</a>
</pre>
    </blockquote>
    <br>
  </div></div></div>

<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></div>