/
DVDInputStreamPVRManager.cpp
400 lines (346 loc) · 9.7 KB
/
DVDInputStreamPVRManager.cpp
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
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
/*
* Copyright (C) 2012-2013 Team XBMC
* http://www.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 "DVDFactoryInputStream.h"
#include "DVDInputStreamPVRManager.h"
#include "filesystem/PVRFile.h"
#include "URL.h"
#include "pvr/PVRManager.h"
#include "pvr/channels/PVRChannel.h"
#include "utils/log.h"
#include "utils/StringUtils.h"
#include "pvr/addons/PVRClients.h"
#include "pvr/channels/PVRChannelGroupsContainer.h"
#include "settings/GUISettings.h"
using namespace XFILE;
using namespace PVR;
/************************************************************************
* Description: Class constructor, initialize member variables
* public class is CDVDInputStream
*/
CDVDInputStreamPVRManager::CDVDInputStreamPVRManager(IDVDPlayer* pPlayer) : CDVDInputStream(DVDSTREAM_TYPE_PVRMANAGER)
{
m_pPlayer = pPlayer;
m_pFile = NULL;
m_pRecordable = NULL;
m_pLiveTV = NULL;
m_pOtherStream = NULL;
m_eof = true;
m_bReopened = false;
m_iScanTimeout = 0;
}
/************************************************************************
* Description: Class destructor
*/
CDVDInputStreamPVRManager::~CDVDInputStreamPVRManager()
{
Close();
}
void CDVDInputStreamPVRManager::ResetScanTimeout(unsigned int iTimeoutMs)
{
m_iScanTimeout = iTimeoutMs > 0 ?
XbmcThreads::SystemClockMillis() + iTimeoutMs :
0;
}
bool CDVDInputStreamPVRManager::IsEOF()
{
// don't mark as eof while within the scan timeout
if (m_iScanTimeout && XbmcThreads::SystemClockMillis() < m_iScanTimeout)
return false;
if (m_pOtherStream)
return m_pOtherStream->IsEOF();
else
return !m_pFile || m_eof;
}
bool CDVDInputStreamPVRManager::Open(const char* strFile, const std::string& content)
{
/* Open PVR File for both cases, to have access to ILiveTVInterface and
* IRecordable
*/
m_pFile = new CPVRFile;
m_pLiveTV = ((CPVRFile*)m_pFile)->GetLiveTV();
m_pRecordable = ((CPVRFile*)m_pFile)->GetRecordable();
CURL url(strFile);
if (!CDVDInputStream::Open(strFile, content)) return false;
if (!m_pFile->Open(url))
{
delete m_pFile;
m_pFile = NULL;
m_pLiveTV = NULL;
m_pRecordable = NULL;
return false;
}
m_eof = false;
/*
* Translate the "pvr://....." entry.
* The PVR Client can use http or whatever else is supported by DVDPlayer.
* to access streams.
* If after translation the file protocol is still "pvr://" use this class
* to read the stream data over the CPVRFile class and the PVR Library itself.
* Otherwise call CreateInputStream again with the translated filename and looks again
* for the right protocol stream handler and swap every call to this input stream
* handler.
*/
std::string transFile = XFILE::CPVRFile::TranslatePVRFilename(strFile);
if(transFile.substr(0, 6) != "pvr://")
{
m_pOtherStream = CDVDFactoryInputStream::CreateInputStream(m_pPlayer, transFile, content);
if (!m_pOtherStream)
{
CLog::Log(LOGERROR, "CDVDInputStreamPVRManager::Open - unable to create input stream for [%s]", transFile.c_str());
return false;
}
else
m_pOtherStream->SetFileItem(m_item);
if (!m_pOtherStream->Open(transFile.c_str(), content))
{
CLog::Log(LOGERROR, "CDVDInputStreamPVRManager::Open - error opening [%s]", transFile.c_str());
delete m_pFile;
m_pFile = NULL;
m_pLiveTV = NULL;
m_pRecordable = NULL;
delete m_pOtherStream;
m_pOtherStream = NULL;
return false;
}
}
ResetScanTimeout((unsigned int) g_guiSettings.GetInt("pvrplayback.scantime") * 1000);
m_content = content;
CLog::Log(LOGDEBUG, "CDVDInputStreamPVRManager::Open - stream opened: %s", transFile.c_str());
return true;
}
// close file and reset everyting
void CDVDInputStreamPVRManager::Close()
{
if (m_pOtherStream)
{
m_pOtherStream->Close();
delete m_pOtherStream;
}
if (m_pFile)
{
m_pFile->Close();
delete m_pFile;
}
CDVDInputStream::Close();
m_pPlayer = NULL;
m_pFile = NULL;
m_pLiveTV = NULL;
m_pRecordable = NULL;
m_pOtherStream = NULL;
m_eof = true;
CLog::Log(LOGDEBUG, "CDVDInputStreamPVRManager::Close - stream closed");
}
int CDVDInputStreamPVRManager::Read(BYTE* buf, int buf_size)
{
if(!m_pFile) return -1;
if (m_pOtherStream)
{
return m_pOtherStream->Read(buf, buf_size);
}
else
{
unsigned int ret = m_pFile->Read(buf, buf_size);
/* we currently don't support non completing reads */
if( ret <= 0 ) m_eof = true;
return (int)(ret & 0xFFFFFFFF);
}
}
int64_t CDVDInputStreamPVRManager::Seek(int64_t offset, int whence)
{
if (!m_pFile)
return -1;
if (whence == SEEK_POSSIBLE)
return m_pFile->IoControl(IOCTRL_SEEK_POSSIBLE, NULL);
if (m_pOtherStream)
{
return m_pOtherStream->Seek(offset, whence);
}
else
{
int64_t ret = m_pFile->Seek(offset, whence);
/* if we succeed, we are not eof anymore */
if( ret >= 0 ) m_eof = false;
return ret;
}
}
int64_t CDVDInputStreamPVRManager::GetLength()
{
if(!m_pFile) return -1;
if (m_pOtherStream)
return m_pOtherStream->GetLength();
else
return m_pFile->GetLength();
}
int CDVDInputStreamPVRManager::GetTotalTime()
{
if (m_pLiveTV)
return m_pLiveTV->GetTotalTime();
return 0;
}
int CDVDInputStreamPVRManager::GetTime()
{
if (m_pLiveTV)
return m_pLiveTV->GetStartTime();
return 0;
}
bool CDVDInputStreamPVRManager::NextChannel(bool preview/* = false*/)
{
PVR_CLIENT client;
if (!preview && !SupportsChannelSwitch())
{
CPVRChannelPtr channel;
g_PVRManager.GetCurrentChannel(channel);
CFileItemPtr item = g_PVRChannelGroups->Get(channel->IsRadio())->GetSelectedGroup()->GetByChannelUp(*channel);
if (item.get())
return CloseAndOpen(item->GetPath().c_str());
}
else if (m_pLiveTV)
return m_pLiveTV->NextChannel(preview);
return false;
}
bool CDVDInputStreamPVRManager::PrevChannel(bool preview/* = false*/)
{
PVR_CLIENT client;
if (!preview && !SupportsChannelSwitch())
{
CPVRChannelPtr channel;
g_PVRManager.GetCurrentChannel(channel);
CFileItemPtr item = g_PVRChannelGroups->Get(channel->IsRadio())->GetSelectedGroup()->GetByChannelDown(*channel);
if (item.get())
return CloseAndOpen(item->GetPath().c_str());
}
else if (m_pLiveTV)
return m_pLiveTV->PrevChannel(preview);
return false;
}
bool CDVDInputStreamPVRManager::SelectChannelByNumber(unsigned int iChannelNumber)
{
PVR_CLIENT client;
if (!SupportsChannelSwitch())
{
CPVRChannelPtr channel;
g_PVRManager.GetCurrentChannel(channel);
CFileItemPtr item = g_PVRChannelGroups->Get(channel->IsRadio())->GetSelectedGroup()->GetByChannelNumber(iChannelNumber);
if (item.get())
return CloseAndOpen(item->GetPath().c_str());
}
else if (m_pLiveTV)
return m_pLiveTV->SelectChannel(iChannelNumber);
return false;
}
bool CDVDInputStreamPVRManager::SelectChannel(const CPVRChannel &channel)
{
PVR_CLIENT client;
if (!SupportsChannelSwitch())
{
CFileItem item(channel);
return CloseAndOpen(item.GetPath().c_str());
}
else if (m_pLiveTV)
{
return m_pLiveTV->SelectChannel(channel.ChannelNumber());
}
return false;
}
bool CDVDInputStreamPVRManager::GetSelectedChannel(CPVRChannelPtr& channel) const
{
return g_PVRManager.GetCurrentChannel(channel);
}
bool CDVDInputStreamPVRManager::UpdateItem(CFileItem& item)
{
if (m_pLiveTV)
return m_pLiveTV->UpdateItem(item);
return false;
}
CDVDInputStream::ENextStream CDVDInputStreamPVRManager::NextStream()
{
if(!m_pFile) return NEXTSTREAM_NONE;
if(m_bReopened)
{
if (IsEOF())
return NEXTSTREAM_NONE;
else
{
m_bReopened = false;
m_eof = false;
return NEXTSTREAM_RETRY;
}
}
if (m_pOtherStream)
return m_pOtherStream->NextStream();
else if(m_pFile->SkipNext())
{
m_eof = false;
return NEXTSTREAM_OPEN;
}
return NEXTSTREAM_NONE;
}
bool CDVDInputStreamPVRManager::CanRecord()
{
if (m_pRecordable)
return m_pRecordable->CanRecord();
return false;
}
bool CDVDInputStreamPVRManager::IsRecording()
{
if (m_pRecordable)
return m_pRecordable->IsRecording();
return false;
}
bool CDVDInputStreamPVRManager::Record(bool bOnOff)
{
if (m_pRecordable)
return m_pRecordable->Record(bOnOff);
return false;
}
bool CDVDInputStreamPVRManager::CanPause()
{
return g_PVRClients->CanPauseStream();
}
bool CDVDInputStreamPVRManager::CanSeek()
{
return g_PVRClients->CanSeekStream();
}
void CDVDInputStreamPVRManager::Pause(bool bPaused)
{
g_PVRClients->PauseStream(bPaused);
}
CStdString CDVDInputStreamPVRManager::GetInputFormat()
{
if (!m_pOtherStream && g_PVRManager.IsStarted())
return g_PVRClients->GetCurrentInputFormat();
return StringUtils::EmptyString;
}
bool CDVDInputStreamPVRManager::CloseAndOpen(const char* strFile)
{
Close();
if (Open(strFile, m_content))
{
m_bReopened = true;
return true;
}
return false;
}
bool CDVDInputStreamPVRManager::SupportsChannelSwitch(void)
{
PVR_CLIENT client;
return g_PVRClients->GetPlayingClient(client) &&
client->HandlesInputStream();
}