Merge pull request #4594 from FernetMenta/paplayer
[xbmc.git] / xbmc / cores / dvdplayer / DVDInputStreams / DVDInputStreamFile.cpp
blob1b0f7e8460946d7fa589b39b3d8ad633962d4837
1 /*
2 * Copyright (C) 2005-2013 Team XBMC
3 * http://xbmc.org
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)
8 * any later version.
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)
32 m_pFile = NULL;
33 m_eof = true;
36 CDVDInputStreamFile::~CDVDInputStreamFile()
38 Close();
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))
49 return false;
51 m_pFile = new CFile();
52 if (!m_pFile)
53 return false;
55 unsigned int flags = READ_TRUNCATED | READ_BITRATE | READ_CHUNKED;
58 * There are 4 buffer modes available (configurable in as.xml)
59 * 0) Buffer all internet filesystems (like 2 but additionally also ftp, webdav, etc.) (default)
60 * 1) Buffer all filesystems (including local)
61 * 2) Only buffer true internet filesystems (streams) (http, etc.)
62 * 3) No buffer
64 if (!URIUtils::IsOnDVD(strFile) && !URIUtils::IsBluray(strFile)) // Never cache these
66 if (g_advancedSettings.m_networkBufferMode == 0 || g_advancedSettings.m_networkBufferMode == 2)
68 if (URIUtils::IsInternetStream(CURL(strFile), (g_advancedSettings.m_networkBufferMode == 0) ) )
69 flags |= READ_CACHED;
71 else if (g_advancedSettings.m_networkBufferMode == 1)
73 flags |= READ_CACHED; // In buffer mode 1 force cache for (almost) all files
77 if (!(flags & READ_CACHED))
78 flags |= READ_NO_CACHE; // Make sure CFile honors our no-cache hint
80 if (content == "video/mp4" || content == "video/x-msvideo" || content == "video/avi" || content == "video/x-matroska")
81 flags |= READ_MULTI_STREAM;
83 // open file in binary mode
84 if (!m_pFile->Open(strFile, flags))
86 delete m_pFile;
87 m_pFile = NULL;
88 return false;
91 if (m_pFile->GetImplemenation() && (content.empty() || content == "application/octet-stream"))
92 m_content = m_pFile->GetImplemenation()->GetContent();
94 m_eof = false;
95 return true;
98 // close file and reset everyting
99 void CDVDInputStreamFile::Close()
101 if (m_pFile)
103 m_pFile->Close();
104 delete m_pFile;
107 CDVDInputStream::Close();
108 m_pFile = NULL;
109 m_eof = true;
112 int CDVDInputStreamFile::Read(uint8_t* buf, int buf_size)
114 if(!m_pFile) return -1;
116 unsigned int ret = m_pFile->Read(buf, buf_size);
118 /* we currently don't support non completing reads */
119 if( ret == 0 ) m_eof = true;
121 return (int)(ret & 0xFFFFFFFF);
124 int64_t CDVDInputStreamFile::Seek(int64_t offset, int whence)
126 if(!m_pFile) return -1;
128 if(whence == SEEK_POSSIBLE)
129 return m_pFile->IoControl(IOCTRL_SEEK_POSSIBLE, NULL);
131 int64_t ret = m_pFile->Seek(offset, whence);
133 /* if we succeed, we are not eof anymore */
134 if( ret >= 0 ) m_eof = false;
136 return ret;
139 int64_t CDVDInputStreamFile::GetLength()
141 if (m_pFile)
142 return m_pFile->GetLength();
143 return 0;
146 bool CDVDInputStreamFile::GetCacheStatus(XFILE::SCacheStatus *status)
148 if(m_pFile && m_pFile->IoControl(IOCTRL_CACHE_STATUS, status) >= 0)
149 return true;
150 else
151 return false;
154 BitstreamStats CDVDInputStreamFile::GetBitstreamStats() const
156 if (!m_pFile)
157 return m_stats; // dummy return. defined in CDVDInputStream
159 if(m_pFile->GetBitstreamStats())
160 return *m_pFile->GetBitstreamStats();
161 else
162 return m_stats;
165 int CDVDInputStreamFile::GetBlockSize()
167 if(m_pFile)
168 return m_pFile->GetChunkSize();
169 else
170 return 0;
173 void CDVDInputStreamFile::SetReadRate(unsigned rate)
175 unsigned maxrate = rate + 1024 * 1024 / 8;
176 if(m_pFile->IoControl(IOCTRL_CACHE_SETRATE, &maxrate) >= 0)
177 CLog::Log(LOGDEBUG, "CDVDInputStreamFile::SetReadRate - set cache throttle rate to %u bytes per second", maxrate);