1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329
|
/*
* Copyright (C) 2012-2013 Team XBMC
* http://xbmc.org
*
* This Program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with XBMC; see the file COPYING. If not, see
* <http://www.gnu.org/licenses/>.
*
*/
#include "PVRFile.h"
#include "cores/dvdplayer/DVDInputStreams/DVDInputStream.h"
#include "pvr/PVRManager.h"
#include "pvr/channels/PVRChannelGroupsContainer.h"
#include "pvr/recordings/PVRRecordings.h"
#include "pvr/addons/PVRClients.h"
#include "utils/log.h"
#include "utils/StringUtils.h"
#include "URL.h"
using namespace XFILE;
using namespace PVR;
CPVRFile::CPVRFile()
{
m_isPlayRecording = false;
}
CPVRFile::~CPVRFile()
{
}
bool CPVRFile::Open(const CURL& url)
{
Close();
if (!g_PVRManager.IsStarted())
return false;
std::string strURL = url.Get();
if (StringUtils::StartsWith(strURL, "pvr://channels/tv/") ||
StringUtils::StartsWith(strURL, "pvr://channels/radio/"))
{
CFileItemPtr tag = g_PVRChannelGroups->GetByPath(strURL);
if (tag && tag->HasPVRChannelInfoTag())
{
if (!g_PVRManager.OpenLiveStream(*tag))
return false;
m_isPlayRecording = false;
CLog::Log(LOGDEBUG, "PVRFile - %s - playback has started on filename %s", __FUNCTION__, strURL.c_str());
}
else
{
CLog::Log(LOGERROR, "PVRFile - %s - channel not found with filename %s", __FUNCTION__, strURL.c_str());
return false;
}
}
else if (StringUtils::StartsWith(strURL, "pvr://recordings/active"))
{
CFileItemPtr tag = g_PVRRecordings->GetByPath(strURL);
if (tag && tag->HasPVRRecordingInfoTag())
{
if (!g_PVRManager.OpenRecordedStream(tag->GetPVRRecordingInfoTag()))
return false;
m_isPlayRecording = true;
CLog::Log(LOGDEBUG, "%s - playback has started on recording %s (%s)", __FUNCTION__, strURL.c_str(), tag->GetPVRRecordingInfoTag()->m_strIconPath.c_str());
}
else
{
CLog::Log(LOGERROR, "PVRFile - Recording not found with filename %s", strURL.c_str());
return false;
}
}
else if (StringUtils::StartsWith(strURL, "pvr://recordings/deleted/"))
{
CLog::Log(LOGNOTICE, "PVRFile - Playback of deleted recordings is not possible (%s)", strURL.c_str());
return false;
}
else
{
CLog::Log(LOGERROR, "%s - invalid path specified %s", __FUNCTION__, strURL.c_str());
return false;
}
return true;
}
void CPVRFile::Close()
{
g_PVRManager.CloseStream();
}
ssize_t CPVRFile::Read(void* buffer, size_t size)
{
if (size > SSIZE_MAX)
size = SSIZE_MAX;
if (!g_PVRManager.IsStarted())
return -1;
// TODO: Fix overflow in case of sizeof(int) != sizeof(size_t)
const int ret = g_PVRClients->ReadStream((BYTE*)buffer, size);
if (ret < 0)
return -1;
return ret;
}
int64_t CPVRFile::GetLength()
{
return g_PVRManager.IsStarted() ? g_PVRClients->GetStreamLength() : 0;
}
int64_t CPVRFile::Seek(int64_t pos, int whence)
{
return g_PVRManager.IsStarted() ? g_PVRClients->SeekStream(pos, whence) : 0;
}
int64_t CPVRFile::GetPosition()
{
return g_PVRManager.IsStarted() ? g_PVRClients->GetStreamPosition() : 0;
}
int CPVRFile::GetTotalTime()
{
// for recordings leave this to demuxer
return m_isPlayRecording ? 0 : g_PVRManager.GetTotalTime();
}
int CPVRFile::GetStartTime()
{
return g_PVRManager.GetStartTime();
}
bool CPVRFile::NextChannel(bool preview/* = false*/)
{
unsigned int newchannel;
if (m_isPlayRecording)
{
/* We are inside a recording, skip channelswitch */
return true;
}
/* Do channel switch and save new channel number, it is not always
* increased by one in a case if next channel is encrypted or we
* on the beginning or end of the channel list!
*/
if (g_PVRManager.ChannelUp(&newchannel, preview))
{
return true;
}
else
{
return false;
}
}
bool CPVRFile::PrevChannel(bool preview/* = false*/)
{
unsigned int newchannel;
if (m_isPlayRecording)
{
/* We are inside a recording, skip channelswitch */
return true;
}
/* Do channel switch and save new channel number, it is not always
* increased by one in a case if next channel is encrypted or we
* on the beginning or end of the channel list!
*/
if (g_PVRManager.ChannelDown(&newchannel, preview))
{
return true;
}
else
{
return false;
}
}
bool CPVRFile::SelectChannelById(unsigned int channelid)
{
if (m_isPlayRecording)
{
/* We are inside a recording, skip channelswitch */
/** TODO:
** Add support for cutting keys (functions becomes the numeric keys as integer)
**/
return true;
}
if (g_PVRManager.ChannelSwitchById(channelid))
{
return true;
}
else
{
return false;
}
}
bool CPVRFile::UpdateItem(CFileItem& item)
{
return g_PVRManager.UpdateItem(item);
}
std::string CPVRFile::TranslatePVRFilename(const std::string& pathFile)
{
if (!g_PVRManager.IsStarted())
return "";
std::string FileName = pathFile;
if (FileName.substr(0, 14) == "pvr://channels")
{
CFileItemPtr channel = g_PVRChannelGroups->GetByPath(FileName);
if (channel && channel->HasPVRChannelInfoTag())
{
std::string stream = channel->GetPVRChannelInfoTag()->StreamURL();
if(!stream.empty())
{
if (stream.compare(6, 7, "stream/") == 0)
{
// pvr://stream
// This function was added to retrieve the stream URL for this item
// Is is used for the MediaPortal (ffmpeg) PVR addon
// see PVRManager.cpp
return g_PVRClients->GetStreamURL(channel->GetPVRChannelInfoTag());
}
else
{
return stream;
}
}
}
}
return FileName;
}
bool CPVRFile::CanRecord()
{
if (m_isPlayRecording || !g_PVRManager.IsStarted())
return false;
return g_PVRClients->CanRecordInstantly();
}
bool CPVRFile::IsRecording()
{
return g_PVRManager.IsStarted() && g_PVRClients->IsRecordingOnPlayingChannel();
}
bool CPVRFile::Record(bool bOnOff)
{
return g_PVRManager.StartRecordingOnPlayingChannel(bOnOff);
}
bool CPVRFile::Delete(const CURL& url)
{
if (!g_PVRManager.IsStarted())
return false;
std::string path(url.GetFileName());
if (StringUtils::StartsWith(path, "recordings/") && path[path.size()-1] != '/')
{
std::string strURL = url.Get();
CFileItemPtr tag = g_PVRRecordings->GetByPath(strURL);
if (tag && tag->HasPVRRecordingInfoTag())
return tag->GetPVRRecordingInfoTag()->Delete();
}
return false;
}
bool CPVRFile::Rename(const CURL& url, const CURL& urlnew)
{
if (!g_PVRManager.IsStarted())
return false;
std::string path(url.GetFileName());
std::string newname(urlnew.GetFileName());
size_t found = newname.find_last_of("/");
if (found != std::string::npos)
newname = newname.substr(found+1);
if (StringUtils::StartsWith(path, "recordings/active/") && path[path.size()-1] != '/')
{
std::string strURL = url.Get();
CFileItemPtr tag = g_PVRRecordings->GetByPath(strURL);
if (tag && tag->HasPVRRecordingInfoTag())
return tag->GetPVRRecordingInfoTag()->Rename(newname);
}
return false;
}
bool CPVRFile::Exists(const CURL& url)
{
return g_PVRManager.IsStarted() &&
g_PVRRecordings->GetByPath(url.Get())->HasPVRRecordingInfoTag();
}
int CPVRFile::IoControl(EIoControl request, void *param)
{
if (request == IOCTRL_SEEK_POSSIBLE)
{
if (!g_PVRManager.IsStarted())
return 0;
else if (g_PVRClients->CanSeekStream())
return 1;
else
return 0;
}
return -1;
}
|