Permalink
Browse files

changed: move the SEEK_POSSIBLE API to IoControl instead of being par…

…t of Seek.
  • Loading branch information...
elupus committed Mar 28, 2011
1 parent da83718 commit a081e12ee869cd8624a2cc548ccd28a75ef4e80d
@@ -41,6 +41,8 @@ enum DVDStreamType
DVDSTREAM_TYPE_BLURAY = 11,
};
+#define SEEK_POSSIBLE 0x10 // flag used to check if protocol allows seeks
+
#define DVDSTREAM_BLOCK_SIZE_FILE (2048 * 16)
#define DVDSTREAM_BLOCK_SIZE_DVD 2048
@@ -99,6 +99,10 @@ int CDVDInputStreamFile::Read(BYTE* buf, int buf_size)
__int64 CDVDInputStreamFile::Seek(__int64 offset, int whence)
{
if(!m_pFile) return -1;
+
+ if(whence == SEEK_POSSIBLE)
+ return m_pFile->IoControl(IOCTRL_SEEK_POSSIBLE, NULL);
+
__int64 ret = m_pFile->Seek(offset, whence);
/* if we succeed, we are not eof anymore */
@@ -105,11 +105,15 @@ int CDVDInputStreamHttp::Read(BYTE* buf, int buf_size)
__int64 CDVDInputStreamHttp::Seek(__int64 offset, int whence)
{
- __int64 ret = 0;
- if (m_pFile) ret = m_pFile->Seek(offset, whence);
- else return -1;
+ if(!m_pFile)
+ return -1;
- m_eof = false;
+ if(whence == SEEK_POSSIBLE)
+ return m_pFile->IoControl(IOCTRL_SEEK_POSSIBLE, NULL);
+
+ __int64 ret = m_pFile->Seek(offset, whence);
+
+ if( ret >= 0 ) m_eof = false;
return ret;
}
@@ -95,6 +95,8 @@ __int64 CDVDInputStreamMemory::Seek(__int64 offset, int whence)
else m_iDataPos = (int)offset;
break;
}
+ default:
+ return -1;
}
return m_iDataPos;
}
View
@@ -518,21 +518,7 @@ int64_t CFile::Seek(int64_t iFilePosition, int iWhence)
try
{
- if(iWhence == SEEK_POSSIBLE)
- {
- int64_t ret = m_pFile->Seek(iFilePosition, iWhence);
- if(ret >= 0)
- return ret;
- else
- {
- if(m_pFile->GetLength() && m_pFile->Seek(0, SEEK_CUR) >= 0)
- return 1;
- else
- return 0;
- }
- }
- else
- return m_pFile->Seek(iFilePosition, iWhence);
+ return m_pFile->Seek(iFilePosition, iWhence);
}
#ifndef _LINUX
catch (const win32_exception &e)
@@ -773,6 +759,14 @@ int CFile::IoControl(EIoControl request, void* param)
if (m_pFile)
result = m_pFile->IoControl(request, param);
+ if(result == -1 && request == IOCTRL_SEEK_POSSIBLE)
+ {
+ if(m_pFile->GetLength() >= 0 && m_pFile->Seek(0, SEEK_CUR) >= 0)
+ return 1;
+ else
+ return 0;
+ }
+
return result;
}
//*********************************************************************************************
@@ -107,7 +107,7 @@ bool CFileCache::Open(const CURL& url)
}
// check if source can seek
- m_seekPossible = m_source.Seek(0, SEEK_POSSIBLE);
+ m_seekPossible = m_source.IoControl(IOCTRL_SEEK_POSSIBLE, NULL);
m_readPos = 0;
m_seekEvent.Reset();
@@ -147,7 +147,7 @@ void CFileCache::Process()
if (m_nSeekResult != m_seekPos)
{
CLog::Log(LOGERROR,"%s, error %d seeking. seek returned %"PRId64, __FUNCTION__, (int)GetLastError(), m_nSeekResult);
- m_seekPossible = m_source.Seek(0, SEEK_POSSIBLE);
+ m_seekPossible = m_source.IoControl(IOCTRL_SEEK_POSSIBLE, NULL);
}
else
m_pCache->Reset(m_seekPos);
@@ -282,8 +282,6 @@ int64_t CFileCache::Seek(int64_t iFilePosition, int iWhence)
iTarget = GetLength() + iTarget;
else if (iWhence == SEEK_CUR)
iTarget = iCurPos + iTarget;
- else if (iWhence == SEEK_POSSIBLE)
- return m_seekPossible;
else if (iWhence != SEEK_SET)
return -1;
@@ -358,5 +356,8 @@ int CFileCache::IoControl(EIoControl request, void* param)
return 0;
}
+ if(request == IOCTRL_SEEK_POSSIBLE)
+ return m_seekPossible;
+
return -1;
}
@@ -55,14 +55,16 @@ namespace XFILE
virtual int64_t GetPosition();
virtual int64_t GetLength();
+ virtual int IoControl(EIoControl request, void* param);
+
IFile *GetFileImp();
virtual CStdString GetContent();
private:
CCacheStrategy *m_pCache;
bool m_bDeleteCache;
- int64_t m_seekPossible;
+ int m_seekPossible;
CFile m_source;
CStdString m_sourcePath;
CEvent m_seekEvent;
@@ -982,8 +982,6 @@ int64_t CFileCurl::Seek(int64_t iFilePosition, int iWhence)
else
return -1;
break;
- case SEEK_POSSIBLE:
- return m_seekable ? 1 : 0;
default:
return -1;
}
@@ -1389,3 +1387,11 @@ bool CFileCurl::GetMimeType(const CURL &url, CStdString &content, CStdString use
content = "";
return false;
}
+
+int CFileCurl::IoControl(EIoControl request, void* param)
+{
+ if(request == IOCTRL_SEEK_POSSIBLE)
+ return m_seekable ? 1 : 0;
+
+ return -1;
+}
@@ -51,6 +51,7 @@ namespace XFILE
virtual bool ReadString(char *szLine, int iLineLength) { return m_state->ReadString(szLine, iLineLength); }
virtual unsigned int Read(void* lpBuf, int64_t uiBufSize) { return m_state->Read(lpBuf, uiBufSize); }
virtual CStdString GetMimeType() { return m_state->m_httpheader.GetMimeType(); }
+ virtual int IoControl(EIoControl request, void* param);
bool Post(const CStdString& strURL, const CStdString& strPostData, CStdString& strHTML);
bool Get(const CStdString& strURL, CStdString& strHTML);
@@ -215,9 +215,6 @@ int64_t CFileDAAP::Seek(int64_t iFilePosition, int iWhence)
{
CSingleLock lock(g_DaapClient);
- if(iWhence == SEEK_POSSIBLE)
- return 1; //m_curl.Seek(iFilePosition, iWhence);
-
int requestid = ++m_thisHost->request_id;
char hash[33] = {0};
@@ -250,3 +247,11 @@ int CFileDAAP::Stat(const CURL& url, struct __stat64* buffer)
{
return -1;
}
+
+int CFileDAAP::IoControl(EIoControl request, void* param)
+{
+ if(request == IOCTRL_SEEK_POSSIBLE)
+ return 1;
+
+ return -1;
+}
@@ -77,6 +77,7 @@ class CFileDAAP : public IFile
virtual unsigned int Read(void* lpBuf, int64_t uiBufSize);
virtual int64_t Seek(int64_t iFilePosition, int iWhence = SEEK_SET);
virtual void Close();
+ virtual int IoControl(EIoControl request, void* param);
protected:
@@ -475,9 +475,6 @@ void CFileSFTP::Close()
int64_t CFileSFTP::Seek(int64_t iFilePosition, int iWhence)
{
- if(iWhence == SEEK_POSSIBLE)
- return 1;
-
if (m_session && m_sftp_handle)
{
uint64_t position = 0;
@@ -570,4 +567,13 @@ int64_t CFileSFTP::GetPosition()
CLog::Log(LOGERROR, "SFTPFile: Can't get position without a filehandle");
return 0;
}
+
+int CFileSFTP::IoControl(EIoControl request, void* param)
+{
+ if(request == IOCTRL_SEEK_POSSIBLE)
+ return 1;
+
+ return -1;
+}
+
#endif
@@ -103,7 +103,7 @@ namespace XFILE
virtual int64_t GetLength();
virtual int64_t GetPosition();
virtual int GetChunkSize() {return 1;};
-
+ virtual int IoControl(EIoControl request, void* param);
private:
CStdString m_file;
CSFTPSessionPtr m_session;
View
@@ -38,8 +38,6 @@
#include <stdint.h>
#include <sys/stat.h>
-#define SEEK_POSSIBLE 0x10 // flag used to check if protocol allows seeks
-
namespace XFILE
{
@@ -56,6 +54,7 @@ struct SCacheStatus
typedef enum {
IOCTRL_NATIVE = 1, /**< SNativeIoControl structure, containing what should be passed to native ioctrl */
+ IOCTRL_SEEK_POSSIBLE = 2, /**< return 0 if known not to work, 1 if it should work */
IOCTRL_CACHE_STATUS = 3, /**< SCacheStatus structure */
} EIoControl;
@@ -465,14 +465,6 @@ int64_t CMythFile::Seek(int64_t pos, int whence)
{
CLog::Log(LOGDEBUG, "%s - seek to pos %"PRId64", whence %d", __FUNCTION__, pos, whence);
- if(whence == SEEK_POSSIBLE)
- {
- if(m_recorder)
- return 0;
- else
- return 1;
- }
-
int64_t result;
if(m_recorder)
result = -1; //m_dll->livetv_seek(m_recorder, pos, whence);
@@ -715,3 +707,15 @@ bool CMythFile::GetCutList(cmyth_commbreaklist_t& commbreaklist)
}
return false;
}
+
+int CMythFile::IoControl(EIoControl request, void* param)
+{
+ if(request == IOCTRL_SEEK_POSSIBLE)
+ {
+ if(m_recorder)
+ return 0;
+ else
+ return 1;
+ }
+ return -1;
+}
@@ -80,6 +80,7 @@ class CMythFile
virtual bool GetCommBreakList(cmyth_commbreaklist_t& commbreaklist);
virtual bool GetCutList(cmyth_commbreaklist_t& commbreaklist);
+ virtual int IoControl(EIoControl request, void* param);
protected:
virtual void OnEvent(int event, const std::string& data);
@@ -130,8 +130,6 @@ int64_t CSAPFile::Seek(int64_t iFilePosition, int iWhence)
case SEEK_END:
m_stream.seekg((int)iFilePosition, ios_base::end);
break;
- case SEEK_POSSIBLE:
- return 1;
default:
return -1;
}
@@ -171,3 +169,10 @@ bool CSAPFile::Rename(const CURL& url, const CURL& urlnew)
return false;
}
+int CSAPFile::IoControl(EIoControl request, void* param)
+{
+ if(request == IOCTRL_SEEK_POSSIBLE)
+ return 1;
+
+ return -1;
+}
@@ -44,6 +44,8 @@ class CSAPFile : public IFile
virtual bool Delete(const CURL& url);
virtual bool Rename(const CURL& url, const CURL& urlnew);
+
+ virtual int IoControl(EIoControl request, void* param);
protected:
std::stringstream m_stream;
int m_len;
@@ -140,10 +140,6 @@ unsigned int CVTPFile::Read(void* buffer, int64_t size)
int64_t CVTPFile::Seek(int64_t pos, int whence)
{
CLog::Log(LOGDEBUG, "CVTPFile::Seek - seek to pos %"PRId64", whence %d", pos, whence);
-
- if(whence == SEEK_POSSIBLE)
- return 0;
-
return -1;
}
@@ -222,3 +218,11 @@ bool CVTPFile::SelectChannel(unsigned int channel)
else
return false;
}
+
+int CVTPFile::IoControl(EIoControl request, void* param)
+{
+ if(request == IOCTRL_SEEK_POSSIBLE)
+ return 0;
+
+ return -1;
+}
@@ -59,7 +59,7 @@ class CVTPFile
virtual int GetStartTime() { return 0; }
virtual bool UpdateItem(CFileItem& item) { return false; }
-
+ virtual int IoControl(EIoControl request, void* param);
protected:
CVTPSession* m_session;
SOCKET m_socket;
@@ -964,8 +964,6 @@ int64_t iso9660::Seek(HANDLE hFile, int64_t lOffset, int whence)
// end += pos
pContext->m_dwFilePos = pContext->m_dwFileSize + lOffset;
break;
- case SEEK_POSSIBLE:
- return 1;
default:
return -1;
}

0 comments on commit a081e12

Please sign in to comment.