static int dvd_file_read(URLContext *h, BYTE* buf, int size)
{
  //if (g_urltimeout && GetTickCount() > g_urltimeout)
  //  return -1;

  CDVDInputStream* pInputStream = (CDVDInputStream*)h->priv_data;
  return pInputStream->Read(buf, size);
}
bool CDVDSubtitleStream::Open(const string& strFile)
{
  CDVDInputStream* pInputStream;
  pInputStream = CDVDFactoryInputStream::CreateInputStream(NULL, strFile, "");
  if (pInputStream && pInputStream->Open(strFile.c_str(), ""))
  {
    unsigned char buffer[16384];
    int size_read = 0;
    size_read = pInputStream->Read(buffer,3);
    bool isUTF8 = false;
    bool isUTF16 = false;
    if (buffer[0] == 0xEF && buffer[1] == 0xBB && buffer[2] == 0xBF)
      isUTF8 = true;
    else if (buffer[0] == 0xFF && buffer[1] == 0xFE)
    {
      isUTF16 = true;
      pInputStream->Seek(2, SEEK_SET);
    }
    else
      pInputStream->Seek(0, SEEK_SET);

    if (isUTF16)
    {
      std::wstringstream wstringstream;
      while( (size_read = pInputStream->Read(buffer, sizeof(buffer)-2) ) > 0 )
      {
        buffer[size_read] = buffer[size_read + 1] = '\0';
        CStdStringW temp; 
        g_charsetConverter.utf16LEtoW(std::u16string((char16_t*)buffer),temp); 
        wstringstream << temp; 
      }
      delete pInputStream;

      CStdString strUTF8;
      g_charsetConverter.wToUTF8(CStdStringW(wstringstream.str()),strUTF8);
      m_stringstream.str("");
      m_stringstream << strUTF8;
    }
    else
    {
      while( (size_read = pInputStream->Read(buffer, sizeof(buffer)-1) ) > 0 )
      {
        buffer[size_read] = '\0';
        m_stringstream << buffer;
      }
      delete pInputStream;

      if (!isUTF8)
        isUTF8 = CUtf8Utils::isValidUtf8(m_stringstream.str());

      if (!isUTF8)
      {
        CStdStringW strUTF16;
        CStdString strUTF8;
        g_charsetConverter.subtitleCharsetToW(m_stringstream.str(), strUTF16);
        g_charsetConverter.wToUTF8(strUTF16,strUTF8);
        m_stringstream.str("");
        m_stringstream << strUTF8;
      }
    }
    return true;
  }

  delete pInputStream;
  return false;
}