2 * Copyright (C) 2005-2013 Team XBMC
5 * This Program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2, or (at your option)
10 * This Program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with XBMC; see the file COPYING. If not, see
17 * <http://www.gnu.org/licenses/>.
21 #include "DVDInputStreamFile.h"
22 #include "filesystem/File.h"
23 #include "filesystem/IFile.h"
24 #include "settings/AdvancedSettings.h"
25 #include "utils/log.h"
26 #include "utils/URIUtils.h"
28 using namespace XFILE;
30 CDVDInputStreamFile::CDVDInputStreamFile() : CDVDInputStream(DVDSTREAM_TYPE_FILE)
36 CDVDInputStreamFile::~CDVDInputStreamFile()
41 bool CDVDInputStreamFile::IsEOF()
43 return !m_pFile || m_eof;
46 bool CDVDInputStreamFile::Open(const char* strFile, const std::string& content)
48 if (!CDVDInputStream::Open(strFile, content))
51 m_pFile = new CFile();
55 unsigned int flags = READ_TRUNCATED | READ_BITRATE | READ_CHUNKED;
57 if (URIUtils::IsOnDVD(strFile) || URIUtils::IsBluray(strFile))
58 flags |= READ_NO_CACHE; // Never cache these
60 if (content == "video/mp4" || content == "video/x-msvideo" || content == "video/avi")
61 flags |= READ_MULTI_STREAM;
63 // open file in binary mode
64 if (!m_pFile->Open(strFile, flags))
71 if (m_pFile->GetImplemenation() && (content.empty() || content == "application/octet-stream"))
72 m_content = m_pFile->GetImplemenation()->GetContent();
78 // close file and reset everyting
79 void CDVDInputStreamFile::Close()
87 CDVDInputStream::Close();
92 int CDVDInputStreamFile::Read(uint8_t* buf, int buf_size)
94 if(!m_pFile) return -1;
96 unsigned int ret = m_pFile->Read(buf, buf_size);
98 /* we currently don't support non completing reads */
99 if( ret == 0 ) m_eof = true;
101 return (int)(ret & 0xFFFFFFFF);
104 int64_t CDVDInputStreamFile::Seek(int64_t offset, int whence)
106 if(!m_pFile) return -1;
108 if(whence == SEEK_POSSIBLE)
109 return m_pFile->IoControl(IOCTRL_SEEK_POSSIBLE, NULL);
111 int64_t ret = m_pFile->Seek(offset, whence);
113 /* if we succeed, we are not eof anymore */
114 if( ret >= 0 ) m_eof = false;
119 int64_t CDVDInputStreamFile::GetLength()
122 return m_pFile->GetLength();
126 bool CDVDInputStreamFile::GetCacheStatus(XFILE::SCacheStatus *status)
128 if(m_pFile && m_pFile->IoControl(IOCTRL_CACHE_STATUS, status) >= 0)
134 BitstreamStats CDVDInputStreamFile::GetBitstreamStats() const
137 return m_stats; // dummy return. defined in CDVDInputStream
139 if(m_pFile->GetBitstreamStats())
140 return *m_pFile->GetBitstreamStats();
145 int CDVDInputStreamFile::GetBlockSize()
148 return m_pFile->GetChunkSize();
153 void CDVDInputStreamFile::SetReadRate(unsigned rate)
155 unsigned maxrate = rate + 1024 * 1024 / 8;
156 if(m_pFile->IoControl(IOCTRL_CACHE_SETRATE, &maxrate) >= 0)
157 CLog::Log(LOGDEBUG, "CDVDInputStreamFile::SetReadRate - set cache throttle rate to %u bytes per second", maxrate);