2002-06-16 12:57:31 +02:00
|
|
|
/*
|
|
|
|
* dvbplayer.c: The DVB player
|
|
|
|
*
|
|
|
|
* See the main source file 'vdr.c' for copyright information and
|
|
|
|
* how to reach the author.
|
|
|
|
*
|
2022-12-05 14:45:51 +01:00
|
|
|
* $Id: dvbplayer.c 5.2 2022/12/05 14:45:51 kls Exp $
|
2002-06-16 12:57:31 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "dvbplayer.h"
|
2009-01-24 11:42:24 +01:00
|
|
|
#include <math.h>
|
2002-08-11 10:47:11 +02:00
|
|
|
#include <stdlib.h>
|
2003-04-27 09:55:53 +02:00
|
|
|
#include "remux.h"
|
2002-06-16 12:57:31 +02:00
|
|
|
#include "ringbuffer.h"
|
|
|
|
#include "thread.h"
|
2002-08-15 10:13:03 +02:00
|
|
|
#include "tools.h"
|
2002-06-16 12:57:31 +02:00
|
|
|
|
2009-03-13 14:45:12 +01:00
|
|
|
// --- cPtsIndex -------------------------------------------------------------
|
2002-06-16 12:57:31 +02:00
|
|
|
|
2016-12-22 11:33:12 +01:00
|
|
|
#define PTSINDEX_ENTRIES 1024
|
2002-06-16 12:57:31 +02:00
|
|
|
|
2009-03-13 14:45:12 +01:00
|
|
|
class cPtsIndex {
|
2002-06-16 12:57:31 +02:00
|
|
|
private:
|
2009-03-13 14:45:12 +01:00
|
|
|
struct tPtsIndex {
|
|
|
|
uint32_t pts; // no need for 33 bit - some devices don't even supply the msb
|
|
|
|
int index;
|
2016-12-22 11:33:12 +01:00
|
|
|
bool independent;
|
2009-03-13 14:45:12 +01:00
|
|
|
};
|
|
|
|
tPtsIndex pi[PTSINDEX_ENTRIES];
|
|
|
|
int w, r;
|
|
|
|
int lastFound;
|
|
|
|
cMutex mutex;
|
2002-06-16 12:57:31 +02:00
|
|
|
public:
|
2009-03-13 14:45:12 +01:00
|
|
|
cPtsIndex(void);
|
2002-06-16 12:57:31 +02:00
|
|
|
void Clear(void);
|
2013-03-07 14:47:02 +01:00
|
|
|
bool IsEmpty(void);
|
2016-12-22 11:33:12 +01:00
|
|
|
void Put(uint32_t Pts, int Index, bool Independent);
|
2009-03-13 14:45:12 +01:00
|
|
|
int FindIndex(uint32_t Pts);
|
2016-12-22 11:33:12 +01:00
|
|
|
int FindFrameNumber(uint32_t Pts);
|
2002-06-16 12:57:31 +02:00
|
|
|
};
|
|
|
|
|
2009-03-13 14:45:12 +01:00
|
|
|
cPtsIndex::cPtsIndex(void)
|
2002-06-16 12:57:31 +02:00
|
|
|
{
|
2009-03-13 14:45:12 +01:00
|
|
|
lastFound = 0;
|
2002-06-16 12:57:31 +02:00
|
|
|
Clear();
|
|
|
|
}
|
|
|
|
|
2009-03-13 14:45:12 +01:00
|
|
|
void cPtsIndex::Clear(void)
|
2002-06-16 12:57:31 +02:00
|
|
|
{
|
2009-03-13 14:45:12 +01:00
|
|
|
cMutexLock MutexLock(&mutex);
|
|
|
|
w = r = 0;
|
2002-06-16 12:57:31 +02:00
|
|
|
}
|
|
|
|
|
2013-03-07 14:47:02 +01:00
|
|
|
bool cPtsIndex::IsEmpty(void)
|
|
|
|
{
|
|
|
|
cMutexLock MutexLock(&mutex);
|
|
|
|
return w == r;
|
|
|
|
}
|
|
|
|
|
2016-12-22 11:33:12 +01:00
|
|
|
void cPtsIndex::Put(uint32_t Pts, int Index, bool Independent)
|
2002-06-16 12:57:31 +02:00
|
|
|
{
|
2009-03-13 14:45:12 +01:00
|
|
|
cMutexLock MutexLock(&mutex);
|
|
|
|
pi[w].pts = Pts;
|
2016-12-22 11:33:12 +01:00
|
|
|
pi[w].independent = Independent;
|
2009-03-13 14:45:12 +01:00
|
|
|
pi[w].index = Index;
|
|
|
|
w = (w + 1) % PTSINDEX_ENTRIES;
|
|
|
|
if (w == r)
|
|
|
|
r = (r + 1) % PTSINDEX_ENTRIES;
|
2002-06-16 12:57:31 +02:00
|
|
|
}
|
|
|
|
|
2009-03-13 14:45:12 +01:00
|
|
|
int cPtsIndex::FindIndex(uint32_t Pts)
|
|
|
|
{
|
|
|
|
cMutexLock MutexLock(&mutex);
|
|
|
|
if (w == r)
|
|
|
|
return lastFound; // list is empty, let's not jump way off the last known position
|
|
|
|
uint32_t Delta = 0xFFFFFFFF;
|
|
|
|
int Index = -1;
|
|
|
|
for (int i = w; i != r; ) {
|
|
|
|
if (--i < 0)
|
|
|
|
i = PTSINDEX_ENTRIES - 1;
|
|
|
|
uint32_t d = pi[i].pts < Pts ? Pts - pi[i].pts : pi[i].pts - Pts;
|
|
|
|
if (d > 0x7FFFFFFF)
|
|
|
|
d = 0xFFFFFFFF - d; // handle rollover
|
|
|
|
if (d < Delta) {
|
|
|
|
Delta = d;
|
|
|
|
Index = pi[i].index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
lastFound = Index;
|
|
|
|
return Index;
|
2002-06-16 12:57:31 +02:00
|
|
|
}
|
|
|
|
|
2016-12-22 11:33:12 +01:00
|
|
|
int cPtsIndex::FindFrameNumber(uint32_t Pts)
|
|
|
|
{
|
|
|
|
cMutexLock MutexLock(&mutex);
|
|
|
|
if (w == r)
|
|
|
|
return lastFound; // replay always starts at an I frame
|
|
|
|
bool Valid = false;
|
|
|
|
int d;
|
|
|
|
int FrameNumber = 0;
|
|
|
|
int UnplayedIFrame = 2; // GOPs may intersect, so we're looping until we found two unplayed I frames
|
|
|
|
for (int i = r; i != w && UnplayedIFrame; ) {
|
|
|
|
d = Pts - pi[i].pts;
|
|
|
|
if (d > 0x7FFFFFFF)
|
|
|
|
d = 0xFFFFFFFF - d; // handle rollover
|
|
|
|
if (d > 0) {
|
|
|
|
if (pi[i].independent) {
|
|
|
|
FrameNumber = pi[i].index; // an I frame's index represents its frame number
|
|
|
|
Valid = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
FrameNumber++; // for every played non-I frame, increase frame number
|
|
|
|
}
|
|
|
|
else
|
|
|
|
if (pi[i].independent)
|
|
|
|
--UnplayedIFrame;
|
|
|
|
if (++i >= PTSINDEX_ENTRIES)
|
|
|
|
i = 0;
|
|
|
|
}
|
|
|
|
return Valid ? FrameNumber : FindIndex(Pts); // fall back during trick speeds
|
|
|
|
}
|
|
|
|
|
2003-01-19 15:43:58 +01:00
|
|
|
// --- cNonBlockingFileReader ------------------------------------------------
|
|
|
|
|
|
|
|
class cNonBlockingFileReader : public cThread {
|
|
|
|
private:
|
2005-10-31 13:14:26 +01:00
|
|
|
cUnbufferedFile *f;
|
2003-01-19 15:43:58 +01:00
|
|
|
uchar *buffer;
|
|
|
|
int wanted;
|
|
|
|
int length;
|
2004-10-16 09:36:28 +02:00
|
|
|
cCondWait newSet;
|
2006-02-19 14:23:17 +01:00
|
|
|
cCondVar newDataCond;
|
|
|
|
cMutex newDataMutex;
|
2003-01-19 15:43:58 +01:00
|
|
|
protected:
|
|
|
|
void Action(void);
|
|
|
|
public:
|
|
|
|
cNonBlockingFileReader(void);
|
|
|
|
~cNonBlockingFileReader();
|
|
|
|
void Clear(void);
|
2009-05-31 14:12:42 +02:00
|
|
|
void Request(cUnbufferedFile *File, int Length);
|
|
|
|
int Result(uchar **Buffer);
|
2012-02-21 11:36:49 +01:00
|
|
|
bool Reading(void) { return buffer; }
|
2006-02-19 14:23:17 +01:00
|
|
|
bool WaitForDataMs(int msToWait);
|
2003-01-19 15:43:58 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
cNonBlockingFileReader::cNonBlockingFileReader(void)
|
2003-10-18 12:29:08 +02:00
|
|
|
:cThread("non blocking file reader")
|
2003-01-19 15:43:58 +01:00
|
|
|
{
|
2005-10-31 13:14:26 +01:00
|
|
|
f = NULL;
|
2003-01-19 15:43:58 +01:00
|
|
|
buffer = NULL;
|
|
|
|
wanted = length = 0;
|
|
|
|
Start();
|
|
|
|
}
|
|
|
|
|
|
|
|
cNonBlockingFileReader::~cNonBlockingFileReader()
|
|
|
|
{
|
2004-10-16 09:36:28 +02:00
|
|
|
newSet.Signal();
|
2003-01-19 15:43:58 +01:00
|
|
|
Cancel(3);
|
|
|
|
free(buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
void cNonBlockingFileReader::Clear(void)
|
|
|
|
{
|
2004-10-16 09:36:28 +02:00
|
|
|
Lock();
|
2005-10-31 13:14:26 +01:00
|
|
|
f = NULL;
|
2003-05-24 09:10:07 +02:00
|
|
|
free(buffer);
|
2003-01-19 15:43:58 +01:00
|
|
|
buffer = NULL;
|
|
|
|
wanted = length = 0;
|
2009-05-31 14:12:42 +02:00
|
|
|
Unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
void cNonBlockingFileReader::Request(cUnbufferedFile *File, int Length)
|
|
|
|
{
|
|
|
|
Lock();
|
|
|
|
Clear();
|
|
|
|
wanted = Length;
|
|
|
|
buffer = MALLOC(uchar, wanted);
|
|
|
|
f = File;
|
2012-02-18 11:22:01 +01:00
|
|
|
Unlock();
|
2012-02-21 11:36:49 +01:00
|
|
|
newSet.Signal();
|
2003-01-19 15:43:58 +01:00
|
|
|
}
|
|
|
|
|
2009-05-31 14:12:42 +02:00
|
|
|
int cNonBlockingFileReader::Result(uchar **Buffer)
|
2003-01-19 15:43:58 +01:00
|
|
|
{
|
2009-05-31 14:12:42 +02:00
|
|
|
LOCK_THREAD;
|
2012-02-21 11:36:49 +01:00
|
|
|
if (buffer && length == wanted) {
|
|
|
|
*Buffer = buffer;
|
|
|
|
buffer = NULL;
|
2009-05-31 14:12:42 +02:00
|
|
|
return wanted;
|
2012-02-21 11:36:49 +01:00
|
|
|
}
|
2003-01-19 15:43:58 +01:00
|
|
|
errno = EAGAIN;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void cNonBlockingFileReader::Action(void)
|
|
|
|
{
|
2005-08-14 11:24:57 +02:00
|
|
|
while (Running()) {
|
2004-10-16 09:36:28 +02:00
|
|
|
Lock();
|
2009-05-31 14:12:42 +02:00
|
|
|
if (f && buffer && length < wanted) {
|
2005-10-31 13:14:26 +01:00
|
|
|
int r = f->Read(buffer + length, wanted - length);
|
2009-05-31 14:12:42 +02:00
|
|
|
if (r > 0)
|
2003-01-19 15:43:58 +01:00
|
|
|
length += r;
|
2009-05-31 14:12:42 +02:00
|
|
|
else if (r == 0) { // r == 0 means EOF
|
|
|
|
if (length > 0)
|
|
|
|
wanted = length; // already read something, so return the rest
|
|
|
|
else
|
|
|
|
length = wanted = 0; // report EOF
|
2003-01-19 15:43:58 +01:00
|
|
|
}
|
2009-05-31 14:12:42 +02:00
|
|
|
else if (FATALERRNO) {
|
2003-01-19 15:43:58 +01:00
|
|
|
LOG_ERROR;
|
2009-05-31 14:12:42 +02:00
|
|
|
length = wanted = r; // this will forward the error status to the caller
|
|
|
|
}
|
|
|
|
if (length == wanted) {
|
|
|
|
cMutexLock NewDataLock(&newDataMutex);
|
|
|
|
newDataCond.Broadcast();
|
2003-01-19 15:43:58 +01:00
|
|
|
}
|
|
|
|
}
|
2004-10-16 09:36:28 +02:00
|
|
|
Unlock();
|
|
|
|
newSet.Wait(1000);
|
2003-01-19 15:43:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-02-19 14:23:17 +01:00
|
|
|
bool cNonBlockingFileReader::WaitForDataMs(int msToWait)
|
|
|
|
{
|
2012-02-18 11:22:01 +01:00
|
|
|
cMutexLock NewDataLock(&newDataMutex);
|
2012-02-21 11:36:49 +01:00
|
|
|
if (buffer && length == wanted)
|
|
|
|
return true;
|
2006-02-19 14:23:17 +01:00
|
|
|
return newDataCond.TimedWait(newDataMutex, msToWait);
|
|
|
|
}
|
|
|
|
|
2002-06-16 12:57:31 +02:00
|
|
|
// --- cDvbPlayer ------------------------------------------------------------
|
|
|
|
|
2019-05-27 14:15:06 +02:00
|
|
|
#define PLAYERBUFSIZE (MAXFRAMESIZE * 5)
|
2002-06-16 12:57:31 +02:00
|
|
|
|
2009-03-13 14:45:12 +01:00
|
|
|
#define RESUMEBACKUP 10 // number of seconds to back up when resuming an interrupted replay session
|
2009-04-05 09:08:02 +02:00
|
|
|
#define MAXSTUCKATEOF 3 // max. number of seconds to wait in case the device doesn't play the last frame
|
2002-06-16 12:57:31 +02:00
|
|
|
|
|
|
|
class cDvbPlayer : public cPlayer, cThread {
|
|
|
|
private:
|
|
|
|
enum ePlayModes { pmPlay, pmPause, pmSlow, pmFast, pmStill };
|
|
|
|
enum ePlayDirs { pdForward, pdBackward };
|
|
|
|
static int Speeds[];
|
2003-01-19 15:43:58 +01:00
|
|
|
cNonBlockingFileReader *nonBlockingFileReader;
|
2002-06-16 12:57:31 +02:00
|
|
|
cRingBufferFrame *ringBuffer;
|
2009-03-13 14:45:12 +01:00
|
|
|
cPtsIndex ptsIndex;
|
2015-09-01 11:14:27 +02:00
|
|
|
const cMarks *marks;
|
2002-06-16 12:57:31 +02:00
|
|
|
cFileName *fileName;
|
|
|
|
cIndexFile *index;
|
2005-10-31 13:14:26 +01:00
|
|
|
cUnbufferedFile *replayFile;
|
2009-01-06 14:41:11 +01:00
|
|
|
double framesPerSecond;
|
|
|
|
bool isPesRecording;
|
2012-02-19 11:50:20 +01:00
|
|
|
bool pauseLive;
|
2002-06-16 12:57:31 +02:00
|
|
|
bool eof;
|
2003-04-27 09:55:53 +02:00
|
|
|
bool firstPacket;
|
2002-06-16 12:57:31 +02:00
|
|
|
ePlayModes playMode;
|
|
|
|
ePlayDirs playDir;
|
|
|
|
int trickSpeed;
|
2009-03-13 14:45:12 +01:00
|
|
|
int readIndex;
|
|
|
|
bool readIndependent;
|
2002-06-16 12:57:31 +02:00
|
|
|
cFrame *readFrame;
|
2003-04-27 09:55:53 +02:00
|
|
|
cFrame *playFrame;
|
2010-03-07 14:32:22 +01:00
|
|
|
cFrame *dropFrame;
|
2013-02-20 09:10:19 +01:00
|
|
|
bool resyncAfterPause;
|
2002-06-16 12:57:31 +02:00
|
|
|
void TrickSpeed(int Increment);
|
|
|
|
void Empty(void);
|
2009-03-28 17:14:53 +01:00
|
|
|
bool NextFile(uint16_t FileNumber = 0, off_t FileOffset = -1);
|
2002-06-16 12:57:31 +02:00
|
|
|
int Resume(void);
|
|
|
|
bool Save(void);
|
|
|
|
protected:
|
|
|
|
virtual void Activate(bool On);
|
|
|
|
virtual void Action(void);
|
|
|
|
public:
|
2012-02-19 11:50:20 +01:00
|
|
|
cDvbPlayer(const char *FileName, bool PauseLive);
|
2002-06-16 12:57:31 +02:00
|
|
|
virtual ~cDvbPlayer();
|
2015-09-01 11:14:27 +02:00
|
|
|
void SetMarks(const cMarks *Marks);
|
2005-08-14 11:24:57 +02:00
|
|
|
bool Active(void) { return cThread::Running(); }
|
2002-06-16 12:57:31 +02:00
|
|
|
void Pause(void);
|
|
|
|
void Play(void);
|
|
|
|
void Forward(void);
|
|
|
|
void Backward(void);
|
|
|
|
int SkipFrames(int Frames);
|
|
|
|
void SkipSeconds(int Seconds);
|
|
|
|
void Goto(int Position, bool Still = false);
|
2009-01-06 14:41:11 +01:00
|
|
|
virtual double FramesPerSecond(void) { return framesPerSecond; }
|
2013-02-20 09:10:19 +01:00
|
|
|
virtual void SetAudioTrack(eTrackType Type, const tTrackId *TrackId);
|
2002-07-13 11:16:27 +02:00
|
|
|
virtual bool GetIndex(int &Current, int &Total, bool SnapToIFrame = false);
|
2016-12-22 11:33:12 +01:00
|
|
|
virtual bool GetFrameNumber(int &Current, int &Total);
|
2002-07-13 11:16:27 +02:00
|
|
|
virtual bool GetReplayMode(bool &Play, bool &Forward, int &Speed);
|
2002-06-16 12:57:31 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#define MAX_VIDEO_SLOWMOTION 63 // max. arg to pass to VIDEO_SLOWMOTION // TODO is this value correct?
|
|
|
|
#define NORMAL_SPEED 4 // the index of the '1' entry in the following array
|
|
|
|
#define MAX_SPEEDS 3 // the offset of the maximum speed from normal speed in either direction
|
|
|
|
#define SPEED_MULT 12 // the speed multiplier
|
|
|
|
int cDvbPlayer::Speeds[] = { 0, -2, -4, -8, 1, 2, 4, 12, 0 };
|
|
|
|
|
2012-02-19 11:50:20 +01:00
|
|
|
cDvbPlayer::cDvbPlayer(const char *FileName, bool PauseLive)
|
2003-10-18 12:29:08 +02:00
|
|
|
:cThread("dvbplayer")
|
2002-06-16 12:57:31 +02:00
|
|
|
{
|
2003-01-19 15:43:58 +01:00
|
|
|
nonBlockingFileReader = NULL;
|
2002-06-16 12:57:31 +02:00
|
|
|
ringBuffer = NULL;
|
2015-02-06 15:42:21 +01:00
|
|
|
marks = NULL;
|
2002-06-16 12:57:31 +02:00
|
|
|
index = NULL;
|
2009-01-06 14:41:11 +01:00
|
|
|
cRecording Recording(FileName);
|
|
|
|
framesPerSecond = Recording.FramesPerSecond();
|
|
|
|
isPesRecording = Recording.IsPesRecording();
|
2012-02-19 11:50:20 +01:00
|
|
|
pauseLive = PauseLive;
|
2002-06-16 12:57:31 +02:00
|
|
|
eof = false;
|
2003-04-27 09:55:53 +02:00
|
|
|
firstPacket = true;
|
2002-06-16 12:57:31 +02:00
|
|
|
playMode = pmPlay;
|
|
|
|
playDir = pdForward;
|
|
|
|
trickSpeed = NORMAL_SPEED;
|
2009-03-13 14:45:12 +01:00
|
|
|
readIndex = -1;
|
|
|
|
readIndependent = false;
|
2002-06-16 12:57:31 +02:00
|
|
|
readFrame = NULL;
|
|
|
|
playFrame = NULL;
|
2010-03-07 14:32:22 +01:00
|
|
|
dropFrame = NULL;
|
2013-02-20 09:10:19 +01:00
|
|
|
resyncAfterPause = false;
|
2002-06-16 12:57:31 +02:00
|
|
|
isyslog("replay %s", FileName);
|
2009-01-06 14:41:11 +01:00
|
|
|
fileName = new cFileName(FileName, false, false, isPesRecording);
|
2002-06-16 12:57:31 +02:00
|
|
|
replayFile = fileName->Open();
|
2005-10-31 13:14:26 +01:00
|
|
|
if (!replayFile)
|
2002-06-16 12:57:31 +02:00
|
|
|
return;
|
2004-10-16 09:36:28 +02:00
|
|
|
ringBuffer = new cRingBufferFrame(PLAYERBUFSIZE);
|
2002-06-16 12:57:31 +02:00
|
|
|
// Create the index file:
|
2012-02-19 11:50:20 +01:00
|
|
|
index = new cIndexFile(FileName, false, isPesRecording, pauseLive);
|
2002-06-16 12:57:31 +02:00
|
|
|
if (!index)
|
|
|
|
esyslog("ERROR: can't allocate index");
|
|
|
|
else if (!index->Ok()) {
|
|
|
|
delete index;
|
|
|
|
index = NULL;
|
|
|
|
}
|
2012-02-19 14:34:50 +01:00
|
|
|
else if (PauseLive)
|
|
|
|
framesPerSecond = cRecording(FileName).FramesPerSecond(); // the fps rate might have changed from the default
|
2002-06-16 12:57:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
cDvbPlayer::~cDvbPlayer()
|
|
|
|
{
|
|
|
|
Save();
|
2009-03-13 14:45:12 +01:00
|
|
|
Detach();
|
2005-05-05 12:53:43 +02:00
|
|
|
delete readFrame; // might not have been stored in the buffer in Action()
|
2002-06-16 12:57:31 +02:00
|
|
|
delete index;
|
|
|
|
delete fileName;
|
|
|
|
delete ringBuffer;
|
2015-02-06 15:42:21 +01:00
|
|
|
// don't delete marks here, we don't own them!
|
|
|
|
}
|
|
|
|
|
2015-09-01 11:14:27 +02:00
|
|
|
void cDvbPlayer::SetMarks(const cMarks *Marks)
|
2015-02-06 15:42:21 +01:00
|
|
|
{
|
|
|
|
marks = Marks;
|
2002-06-16 12:57:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void cDvbPlayer::TrickSpeed(int Increment)
|
|
|
|
{
|
|
|
|
int nts = trickSpeed + Increment;
|
|
|
|
if (Speeds[nts] == 1) {
|
|
|
|
trickSpeed = nts;
|
|
|
|
if (playMode == pmFast)
|
|
|
|
Play();
|
|
|
|
else
|
|
|
|
Pause();
|
|
|
|
}
|
|
|
|
else if (Speeds[nts]) {
|
|
|
|
trickSpeed = nts;
|
|
|
|
int Mult = (playMode == pmSlow && playDir == pdForward) ? 1 : SPEED_MULT;
|
|
|
|
int sp = (Speeds[nts] > 0) ? Mult / Speeds[nts] : -Speeds[nts] * Mult;
|
|
|
|
if (sp > MAX_VIDEO_SLOWMOTION)
|
|
|
|
sp = MAX_VIDEO_SLOWMOTION;
|
2013-12-25 13:36:51 +01:00
|
|
|
DeviceTrickSpeed(sp, playDir == pdForward);
|
2002-06-16 12:57:31 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void cDvbPlayer::Empty(void)
|
|
|
|
{
|
2003-01-19 15:43:58 +01:00
|
|
|
LOCK_THREAD;
|
|
|
|
if (nonBlockingFileReader)
|
|
|
|
nonBlockingFileReader->Clear();
|
2009-03-13 14:45:12 +01:00
|
|
|
if (!firstPacket) // don't set the readIndex twice if Empty() is called more than once
|
2009-04-19 15:17:17 +02:00
|
|
|
readIndex = ptsIndex.FindIndex(DeviceGetSTC()) - 1; // Action() will first increment it!
|
2005-05-05 12:53:43 +02:00
|
|
|
delete readFrame; // might not have been stored in the buffer in Action()
|
2002-06-16 12:57:31 +02:00
|
|
|
readFrame = NULL;
|
|
|
|
playFrame = NULL;
|
2010-03-07 14:32:22 +01:00
|
|
|
dropFrame = NULL;
|
2002-06-16 12:57:31 +02:00
|
|
|
ringBuffer->Clear();
|
2009-03-13 14:45:12 +01:00
|
|
|
ptsIndex.Clear();
|
2002-06-16 12:57:31 +02:00
|
|
|
DeviceClear();
|
2003-04-27 09:55:53 +02:00
|
|
|
firstPacket = true;
|
2002-06-16 12:57:31 +02:00
|
|
|
}
|
|
|
|
|
2009-03-28 17:14:53 +01:00
|
|
|
bool cDvbPlayer::NextFile(uint16_t FileNumber, off_t FileOffset)
|
2002-06-16 12:57:31 +02:00
|
|
|
{
|
|
|
|
if (FileNumber > 0)
|
|
|
|
replayFile = fileName->SetOffset(FileNumber, FileOffset);
|
2005-10-31 13:14:26 +01:00
|
|
|
else if (replayFile && eof)
|
2002-06-16 12:57:31 +02:00
|
|
|
replayFile = fileName->NextFile();
|
|
|
|
eof = false;
|
2005-10-31 13:14:26 +01:00
|
|
|
return replayFile != NULL;
|
2002-06-16 12:57:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int cDvbPlayer::Resume(void)
|
|
|
|
{
|
|
|
|
if (index) {
|
|
|
|
int Index = index->GetResume();
|
|
|
|
if (Index >= 0) {
|
2009-01-06 14:41:11 +01:00
|
|
|
uint16_t FileNumber;
|
|
|
|
off_t FileOffset;
|
2002-06-16 12:57:31 +02:00
|
|
|
if (index->Get(Index, &FileNumber, &FileOffset) && NextFile(FileNumber, FileOffset))
|
|
|
|
return Index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool cDvbPlayer::Save(void)
|
|
|
|
{
|
|
|
|
if (index) {
|
2009-03-13 14:45:12 +01:00
|
|
|
int Index = ptsIndex.FindIndex(DeviceGetSTC());
|
2002-06-16 12:57:31 +02:00
|
|
|
if (Index >= 0) {
|
2015-02-06 15:42:21 +01:00
|
|
|
if (Setup.SkipEdited && marks) {
|
2015-09-01 11:14:27 +02:00
|
|
|
cStateKey StateKey;
|
|
|
|
marks->Lock(StateKey);
|
2015-02-06 15:42:21 +01:00
|
|
|
if (marks->First() && abs(Index - marks->First()->Position()) <= int(round(RESUMEBACKUP * framesPerSecond)))
|
|
|
|
Index = 0; // when stopping within RESUMEBACKUP seconds of the first mark the recording shall still be considered unviewed
|
2015-09-01 11:14:27 +02:00
|
|
|
StateKey.Remove();
|
2015-02-06 15:42:21 +01:00
|
|
|
}
|
2009-01-24 11:42:24 +01:00
|
|
|
Index -= int(round(RESUMEBACKUP * framesPerSecond));
|
2002-06-16 12:57:31 +02:00
|
|
|
if (Index > 0)
|
|
|
|
Index = index->GetNextIFrame(Index, false);
|
|
|
|
else
|
|
|
|
Index = 0;
|
|
|
|
if (Index >= 0)
|
|
|
|
return index->StoreResume(Index);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void cDvbPlayer::Activate(bool On)
|
|
|
|
{
|
|
|
|
if (On) {
|
2005-10-31 13:14:26 +01:00
|
|
|
if (replayFile)
|
2002-06-16 12:57:31 +02:00
|
|
|
Start();
|
|
|
|
}
|
2005-08-13 13:17:24 +02:00
|
|
|
else
|
2005-05-22 11:29:19 +02:00
|
|
|
Cancel(9);
|
2002-06-16 12:57:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void cDvbPlayer::Action(void)
|
|
|
|
{
|
2003-04-27 09:55:53 +02:00
|
|
|
uchar *p = NULL;
|
2002-06-16 12:57:31 +02:00
|
|
|
int pc = 0;
|
|
|
|
|
|
|
|
readIndex = Resume();
|
2015-01-26 10:20:51 +01:00
|
|
|
if (readIndex > 0)
|
2009-01-06 14:41:11 +01:00
|
|
|
isyslog("resuming replay at index %d (%s)", readIndex, *IndexToHMSF(readIndex, true, framesPerSecond));
|
2015-02-06 15:42:21 +01:00
|
|
|
else if (Setup.SkipEdited && marks) {
|
2015-09-01 11:14:27 +02:00
|
|
|
cStateKey StateKey;
|
|
|
|
marks->Lock(StateKey);
|
2015-02-06 15:42:21 +01:00
|
|
|
if (marks->First() && index) {
|
|
|
|
int Index = marks->First()->Position();
|
2015-01-26 10:20:51 +01:00
|
|
|
uint16_t FileNumber;
|
|
|
|
off_t FileOffset;
|
|
|
|
if (index->Get(Index, &FileNumber, &FileOffset) && NextFile(FileNumber, FileOffset)) {
|
|
|
|
isyslog("starting replay at first mark %d (%s)", Index, *IndexToHMSF(Index, true, framesPerSecond));
|
|
|
|
readIndex = Index;
|
|
|
|
}
|
|
|
|
}
|
2015-09-01 11:14:27 +02:00
|
|
|
StateKey.Remove();
|
2015-01-26 10:20:51 +01:00
|
|
|
}
|
2016-12-22 09:41:48 +01:00
|
|
|
if (readIndex > 0) // will first be incremented in the loop!
|
|
|
|
--readIndex;
|
2002-06-16 12:57:31 +02:00
|
|
|
|
2003-01-19 15:43:58 +01:00
|
|
|
nonBlockingFileReader = new cNonBlockingFileReader;
|
|
|
|
int Length = 0;
|
2005-05-08 14:07:00 +02:00
|
|
|
bool Sleep = false;
|
2006-02-19 14:23:17 +01:00
|
|
|
bool WaitingForData = false;
|
2009-04-05 09:08:02 +02:00
|
|
|
time_t StuckAtEof = 0;
|
|
|
|
uint32_t LastStc = 0;
|
2016-12-22 11:40:25 +01:00
|
|
|
int LastReadFrame = -1;
|
2009-04-05 10:11:26 +02:00
|
|
|
int SwitchToPlayFrame = 0;
|
2015-01-26 10:20:51 +01:00
|
|
|
bool CutIn = false;
|
|
|
|
bool AtLastMark = false;
|
2003-01-19 15:43:58 +01:00
|
|
|
|
2012-02-19 11:50:20 +01:00
|
|
|
if (pauseLive)
|
|
|
|
Goto(0, true);
|
2009-04-18 14:28:15 +02:00
|
|
|
while (Running()) {
|
|
|
|
if (WaitingForData)
|
2012-05-06 11:04:07 +02:00
|
|
|
WaitingForData = !nonBlockingFileReader->WaitForDataMs(3); // this keeps the CPU load low, but reacts immediately on new data
|
2009-04-18 14:28:15 +02:00
|
|
|
else if (Sleep) {
|
|
|
|
cPoller Poller;
|
|
|
|
DevicePoll(Poller, 10);
|
2005-05-08 14:07:00 +02:00
|
|
|
Sleep = false;
|
2012-02-19 11:50:20 +01:00
|
|
|
if (playMode == pmStill || playMode == pmPause)
|
2012-02-21 11:36:49 +01:00
|
|
|
cCondWait::SleepMs(3);
|
2005-05-08 14:07:00 +02:00
|
|
|
}
|
2009-04-18 14:28:15 +02:00
|
|
|
{
|
|
|
|
LOCK_THREAD;
|
|
|
|
|
|
|
|
// Read the next frame from the file:
|
|
|
|
|
2015-02-13 15:17:45 +01:00
|
|
|
if (playMode != pmStill && playMode != pmPause) {
|
2009-04-18 14:28:15 +02:00
|
|
|
if (!readFrame && (replayFile || readIndex >= 0)) {
|
2015-02-13 15:17:45 +01:00
|
|
|
if (!nonBlockingFileReader->Reading() && !AtLastMark) {
|
2009-04-18 14:28:15 +02:00
|
|
|
if (!SwitchToPlayFrame && (playMode == pmFast || (playMode == pmSlow && playDir == pdBackward))) {
|
|
|
|
uint16_t FileNumber;
|
|
|
|
off_t FileOffset;
|
|
|
|
bool TimeShiftMode = index->IsStillRecording();
|
|
|
|
int Index = -1;
|
|
|
|
readIndependent = false;
|
|
|
|
if (DeviceHasIBPTrickSpeed() && playDir == pdForward) {
|
|
|
|
if (index->Get(readIndex + 1, &FileNumber, &FileOffset, &readIndependent, &Length))
|
|
|
|
Index = readIndex + 1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
int d = int(round(0.4 * framesPerSecond));
|
|
|
|
if (playDir != pdForward)
|
|
|
|
d = -d;
|
|
|
|
int NewIndex = readIndex + d;
|
|
|
|
if (NewIndex <= 0 && readIndex > 0)
|
|
|
|
NewIndex = 1; // make sure the very first frame is delivered
|
2012-03-12 14:53:59 +01:00
|
|
|
NewIndex = index->GetNextIFrame(NewIndex, playDir == pdForward, &FileNumber, &FileOffset, &Length);
|
2009-04-18 14:28:15 +02:00
|
|
|
if (NewIndex < 0 && TimeShiftMode && playDir == pdForward)
|
2012-03-12 14:53:59 +01:00
|
|
|
SwitchToPlayFrame = readIndex;
|
2009-04-18 14:28:15 +02:00
|
|
|
Index = NewIndex;
|
|
|
|
readIndependent = true;
|
|
|
|
}
|
|
|
|
if (Index >= 0) {
|
|
|
|
readIndex = Index;
|
|
|
|
if (!NextFile(FileNumber, FileOffset))
|
|
|
|
continue;
|
|
|
|
}
|
2012-03-12 14:53:59 +01:00
|
|
|
else if (!(TimeShiftMode && playDir == pdForward))
|
2009-04-18 14:28:15 +02:00
|
|
|
eof = true;
|
|
|
|
}
|
|
|
|
else if (index) {
|
|
|
|
uint16_t FileNumber;
|
|
|
|
off_t FileOffset;
|
2015-01-26 10:20:51 +01:00
|
|
|
if (index->Get(readIndex + 1, &FileNumber, &FileOffset, &readIndependent, &Length) && NextFile(FileNumber, FileOffset)) {
|
2009-04-18 14:28:15 +02:00
|
|
|
readIndex++;
|
2015-02-06 15:42:21 +01:00
|
|
|
if ((Setup.SkipEdited || Setup.PauseAtLastMark) && marks) {
|
2015-09-01 11:14:27 +02:00
|
|
|
cStateKey StateKey;
|
|
|
|
marks->Lock(StateKey);
|
|
|
|
const cMark *m = marks->Get(readIndex);
|
2015-01-26 10:20:51 +01:00
|
|
|
if (m && (m->Index() & 0x01) != 0) { // we're at an end mark
|
2015-02-06 15:42:21 +01:00
|
|
|
m = marks->GetNextBegin(m);
|
2015-01-26 10:20:51 +01:00
|
|
|
int Index = -1;
|
|
|
|
if (m)
|
|
|
|
Index = m->Position(); // skip to next begin mark
|
|
|
|
else if (Setup.PauseAtLastMark)
|
|
|
|
AtLastMark = true; // triggers going into Pause mode
|
|
|
|
else if (index->IsStillRecording())
|
|
|
|
Index = index->GetNextIFrame(index->Last() - int(round(MAXSTUCKATEOF * framesPerSecond)), false); // skip, but stay off end of live-recordings
|
|
|
|
else
|
|
|
|
AtLastMark = true; // triggers stopping replay
|
|
|
|
if (Setup.SkipEdited && Index > readIndex) {
|
|
|
|
isyslog("skipping from %d (%s) to %d (%s)", readIndex - 1, *IndexToHMSF(readIndex - 1, true, framesPerSecond), Index, *IndexToHMSF(Index, true, framesPerSecond));
|
|
|
|
readIndex = Index;
|
|
|
|
CutIn = true;
|
|
|
|
}
|
|
|
|
}
|
2015-09-01 11:14:27 +02:00
|
|
|
StateKey.Remove();
|
2015-01-26 10:20:51 +01:00
|
|
|
}
|
|
|
|
}
|
2009-04-18 14:28:15 +02:00
|
|
|
else
|
|
|
|
eof = true;
|
|
|
|
}
|
|
|
|
else // allows replay even if the index file is missing
|
|
|
|
Length = MAXFRAMESIZE;
|
|
|
|
if (Length == -1)
|
|
|
|
Length = MAXFRAMESIZE; // this means we read up to EOF (see cIndex)
|
|
|
|
else if (Length > MAXFRAMESIZE) {
|
|
|
|
esyslog("ERROR: frame larger than buffer (%d > %d)", Length, MAXFRAMESIZE);
|
|
|
|
Length = MAXFRAMESIZE;
|
|
|
|
}
|
2009-05-31 14:12:42 +02:00
|
|
|
if (!eof)
|
|
|
|
nonBlockingFileReader->Request(replayFile, Length);
|
2009-04-18 14:28:15 +02:00
|
|
|
}
|
2009-05-31 14:12:42 +02:00
|
|
|
if (!eof) {
|
|
|
|
uchar *b = NULL;
|
2012-02-21 11:36:49 +01:00
|
|
|
int r = nonBlockingFileReader->Result(&b);
|
2009-04-18 14:28:15 +02:00
|
|
|
if (r > 0) {
|
|
|
|
WaitingForData = false;
|
2016-12-22 11:40:25 +01:00
|
|
|
LastReadFrame = readIndex;
|
|
|
|
uint32_t Pts = isPesRecording ? (PesHasPts(b) ? PesGetPts(b) : -1) : TsGetPts(b, r);
|
|
|
|
readFrame = new cFrame(b, -r, ftUnknown, readIndex, Pts, readIndependent); // hands over b to the ringBuffer
|
2009-04-18 14:28:15 +02:00
|
|
|
}
|
2012-03-12 14:53:59 +01:00
|
|
|
else if (r < 0) {
|
|
|
|
if (errno == EAGAIN)
|
|
|
|
WaitingForData = true;
|
|
|
|
else if (FATALERRNO) {
|
2009-05-31 10:02:20 +02:00
|
|
|
LOG_ERROR;
|
|
|
|
break;
|
|
|
|
}
|
2009-04-18 14:28:15 +02:00
|
|
|
}
|
2012-03-12 14:53:59 +01:00
|
|
|
else
|
|
|
|
eof = true;
|
2009-04-18 14:28:15 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Store the frame in the buffer:
|
|
|
|
|
|
|
|
if (readFrame) {
|
2015-01-26 10:20:51 +01:00
|
|
|
if (CutIn) {
|
|
|
|
if (isPesRecording)
|
|
|
|
cRemux::SetBrokenLink(readFrame->Data(), readFrame->Count());
|
|
|
|
CutIn = false;
|
|
|
|
}
|
2009-04-18 14:28:15 +02:00
|
|
|
if (ringBuffer->Put(readFrame))
|
|
|
|
readFrame = NULL;
|
|
|
|
else
|
|
|
|
Sleep = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
Sleep = true;
|
|
|
|
|
2010-03-07 14:32:22 +01:00
|
|
|
if (dropFrame) {
|
|
|
|
if (!eof || (playDir != pdForward && dropFrame->Index() > 0) || (playDir == pdForward && dropFrame->Index() < readIndex)) {
|
2012-06-09 14:40:26 +02:00
|
|
|
ringBuffer->Drop(dropFrame); // the very first and last frame are continuously repeated to flush data through the device
|
2010-03-07 14:32:22 +01:00
|
|
|
dropFrame = NULL;
|
2010-02-06 12:43:16 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-18 14:28:15 +02:00
|
|
|
// Get the next frame from the buffer:
|
|
|
|
|
|
|
|
if (!playFrame) {
|
|
|
|
playFrame = ringBuffer->Get();
|
|
|
|
p = NULL;
|
|
|
|
pc = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Play the frame:
|
|
|
|
|
|
|
|
if (playFrame) {
|
|
|
|
if (!p) {
|
|
|
|
p = playFrame->Data();
|
|
|
|
pc = playFrame->Count();
|
|
|
|
if (p) {
|
2009-04-19 15:19:10 +02:00
|
|
|
if (playFrame->Index() >= 0 && playFrame->Pts() != 0)
|
2016-12-22 11:33:12 +01:00
|
|
|
ptsIndex.Put(playFrame->Pts(), playFrame->Index(), playFrame->Independent());
|
2009-04-18 14:28:15 +02:00
|
|
|
if (firstPacket) {
|
|
|
|
if (isPesRecording) {
|
|
|
|
PlayPes(NULL, 0);
|
|
|
|
cRemux::SetBrokenLink(p, pc);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
PlayTs(NULL, 0);
|
|
|
|
firstPacket = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (p) {
|
|
|
|
int w;
|
2013-01-27 14:18:19 +01:00
|
|
|
bool VideoOnly = (dropFrame || playMode != pmPlay && !(playMode == pmSlow && playDir == pdForward)) && DeviceIsPlayingVideo();
|
2009-04-18 14:28:15 +02:00
|
|
|
if (isPesRecording)
|
2013-01-27 14:18:19 +01:00
|
|
|
w = PlayPes(p, pc, VideoOnly);
|
2009-04-18 14:28:15 +02:00
|
|
|
else
|
2013-01-27 14:18:19 +01:00
|
|
|
w = PlayTs(p, pc, VideoOnly);
|
2009-04-18 14:28:15 +02:00
|
|
|
if (w > 0) {
|
|
|
|
p += w;
|
|
|
|
pc -= w;
|
|
|
|
}
|
|
|
|
else if (w < 0 && FATALERRNO)
|
|
|
|
LOG_ERROR;
|
|
|
|
else
|
|
|
|
Sleep = true;
|
|
|
|
}
|
|
|
|
if (pc <= 0) {
|
2010-03-07 14:32:22 +01:00
|
|
|
dropFrame = playFrame;
|
2009-04-18 14:28:15 +02:00
|
|
|
playFrame = NULL;
|
|
|
|
p = NULL;
|
|
|
|
}
|
|
|
|
}
|
2015-01-26 10:20:51 +01:00
|
|
|
else {
|
|
|
|
if (AtLastMark) {
|
|
|
|
if (Setup.PauseAtLastMark) {
|
|
|
|
playMode = pmPause;
|
|
|
|
AtLastMark = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
eof = true;
|
|
|
|
}
|
2009-04-18 14:28:15 +02:00
|
|
|
Sleep = true;
|
2015-01-26 10:20:51 +01:00
|
|
|
}
|
2009-04-18 14:28:15 +02:00
|
|
|
|
|
|
|
// Handle hitting begin/end of recording:
|
|
|
|
|
|
|
|
if (eof || SwitchToPlayFrame) {
|
|
|
|
bool SwitchToPlay = false;
|
|
|
|
uint32_t Stc = DeviceGetSTC();
|
2013-02-12 10:53:46 +01:00
|
|
|
if (Stc != LastStc || playMode == pmPause)
|
2009-04-18 14:28:15 +02:00
|
|
|
StuckAtEof = 0;
|
|
|
|
else if (!StuckAtEof)
|
|
|
|
StuckAtEof = time(NULL);
|
|
|
|
else if (time(NULL) - StuckAtEof > MAXSTUCKATEOF) {
|
|
|
|
if (playDir == pdForward)
|
|
|
|
break; // automatically stop at end of recording
|
|
|
|
SwitchToPlay = true;
|
|
|
|
}
|
|
|
|
LastStc = Stc;
|
|
|
|
int Index = ptsIndex.FindIndex(Stc);
|
|
|
|
if (playDir == pdForward && !SwitchToPlayFrame) {
|
2016-12-22 11:40:25 +01:00
|
|
|
if (Index >= LastReadFrame)
|
2009-04-18 14:28:15 +02:00
|
|
|
break; // automatically stop at end of recording
|
|
|
|
}
|
|
|
|
else if (Index <= 0 || SwitchToPlayFrame && Index >= SwitchToPlayFrame)
|
|
|
|
SwitchToPlay = true;
|
|
|
|
if (SwitchToPlay) {
|
|
|
|
if (!SwitchToPlayFrame)
|
|
|
|
Empty();
|
|
|
|
DevicePlay();
|
|
|
|
playMode = pmPlay;
|
|
|
|
playDir = pdForward;
|
|
|
|
SwitchToPlayFrame = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-06-16 12:57:31 +02:00
|
|
|
}
|
2009-04-05 12:29:27 +02:00
|
|
|
|
2003-01-19 15:43:58 +01:00
|
|
|
cNonBlockingFileReader *nbfr = nonBlockingFileReader;
|
|
|
|
nonBlockingFileReader = NULL;
|
|
|
|
delete nbfr;
|
2002-06-16 12:57:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void cDvbPlayer::Pause(void)
|
|
|
|
{
|
|
|
|
if (playMode == pmPause || playMode == pmStill)
|
|
|
|
Play();
|
|
|
|
else {
|
|
|
|
LOCK_THREAD;
|
2008-02-09 15:12:55 +01:00
|
|
|
if (playMode == pmFast || (playMode == pmSlow && playDir == pdBackward)) {
|
|
|
|
if (!(DeviceHasIBPTrickSpeed() && playDir == pdForward))
|
|
|
|
Empty();
|
|
|
|
}
|
2002-06-16 12:57:31 +02:00
|
|
|
DeviceFreeze();
|
|
|
|
playMode = pmPause;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void cDvbPlayer::Play(void)
|
|
|
|
{
|
|
|
|
if (playMode != pmPlay) {
|
|
|
|
LOCK_THREAD;
|
2008-02-09 15:12:55 +01:00
|
|
|
if (playMode == pmStill || playMode == pmFast || (playMode == pmSlow && playDir == pdBackward)) {
|
|
|
|
if (!(DeviceHasIBPTrickSpeed() && playDir == pdForward))
|
|
|
|
Empty();
|
|
|
|
}
|
2002-06-16 12:57:31 +02:00
|
|
|
DevicePlay();
|
|
|
|
playMode = pmPlay;
|
|
|
|
playDir = pdForward;
|
2013-02-20 09:10:19 +01:00
|
|
|
if (resyncAfterPause) {
|
|
|
|
int Current, Total;
|
|
|
|
if (GetIndex(Current, Total, true))
|
|
|
|
Goto(Current);
|
|
|
|
resyncAfterPause = false;
|
|
|
|
}
|
|
|
|
}
|
2002-06-16 12:57:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void cDvbPlayer::Forward(void)
|
|
|
|
{
|
|
|
|
if (index) {
|
|
|
|
switch (playMode) {
|
|
|
|
case pmFast:
|
|
|
|
if (Setup.MultiSpeedMode) {
|
|
|
|
TrickSpeed(playDir == pdForward ? 1 : -1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if (playDir == pdForward) {
|
|
|
|
Play();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// run into pmPlay
|
|
|
|
case pmPlay: {
|
|
|
|
LOCK_THREAD;
|
2008-02-09 15:12:55 +01:00
|
|
|
if (!(DeviceHasIBPTrickSpeed() && playDir == pdForward))
|
|
|
|
Empty();
|
2009-01-25 11:39:43 +01:00
|
|
|
if (DeviceIsPlayingVideo())
|
|
|
|
DeviceMute();
|
2002-06-16 12:57:31 +02:00
|
|
|
playMode = pmFast;
|
|
|
|
playDir = pdForward;
|
|
|
|
trickSpeed = NORMAL_SPEED;
|
|
|
|
TrickSpeed(Setup.MultiSpeedMode ? 1 : MAX_SPEEDS);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case pmSlow:
|
|
|
|
if (Setup.MultiSpeedMode) {
|
|
|
|
TrickSpeed(playDir == pdForward ? -1 : 1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if (playDir == pdForward) {
|
|
|
|
Pause();
|
|
|
|
break;
|
|
|
|
}
|
2009-03-13 14:45:12 +01:00
|
|
|
Empty();
|
2002-06-16 12:57:31 +02:00
|
|
|
// run into pmPause
|
|
|
|
case pmStill:
|
|
|
|
case pmPause:
|
|
|
|
DeviceMute();
|
|
|
|
playMode = pmSlow;
|
|
|
|
playDir = pdForward;
|
|
|
|
trickSpeed = NORMAL_SPEED;
|
|
|
|
TrickSpeed(Setup.MultiSpeedMode ? -1 : -MAX_SPEEDS);
|
|
|
|
break;
|
2009-12-06 12:57:45 +01:00
|
|
|
default: esyslog("ERROR: unknown playMode %d (%s)", playMode, __FUNCTION__);
|
2002-06-16 12:57:31 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void cDvbPlayer::Backward(void)
|
|
|
|
{
|
|
|
|
if (index) {
|
|
|
|
switch (playMode) {
|
|
|
|
case pmFast:
|
|
|
|
if (Setup.MultiSpeedMode) {
|
|
|
|
TrickSpeed(playDir == pdBackward ? 1 : -1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if (playDir == pdBackward) {
|
|
|
|
Play();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// run into pmPlay
|
|
|
|
case pmPlay: {
|
|
|
|
LOCK_THREAD;
|
|
|
|
Empty();
|
2009-01-25 11:39:43 +01:00
|
|
|
if (DeviceIsPlayingVideo())
|
|
|
|
DeviceMute();
|
2002-06-16 12:57:31 +02:00
|
|
|
playMode = pmFast;
|
|
|
|
playDir = pdBackward;
|
|
|
|
trickSpeed = NORMAL_SPEED;
|
|
|
|
TrickSpeed(Setup.MultiSpeedMode ? 1 : MAX_SPEEDS);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case pmSlow:
|
|
|
|
if (Setup.MultiSpeedMode) {
|
|
|
|
TrickSpeed(playDir == pdBackward ? -1 : 1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if (playDir == pdBackward) {
|
|
|
|
Pause();
|
|
|
|
break;
|
|
|
|
}
|
2009-03-13 14:45:12 +01:00
|
|
|
Empty();
|
2002-06-16 12:57:31 +02:00
|
|
|
// run into pmPause
|
|
|
|
case pmStill:
|
|
|
|
case pmPause: {
|
|
|
|
LOCK_THREAD;
|
|
|
|
Empty();
|
|
|
|
DeviceMute();
|
|
|
|
playMode = pmSlow;
|
|
|
|
playDir = pdBackward;
|
|
|
|
trickSpeed = NORMAL_SPEED;
|
|
|
|
TrickSpeed(Setup.MultiSpeedMode ? -1 : -MAX_SPEEDS);
|
|
|
|
}
|
|
|
|
break;
|
2009-12-06 12:57:45 +01:00
|
|
|
default: esyslog("ERROR: unknown playMode %d (%s)", playMode, __FUNCTION__);
|
2002-06-16 12:57:31 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int cDvbPlayer::SkipFrames(int Frames)
|
|
|
|
{
|
|
|
|
if (index && Frames) {
|
|
|
|
int Current, Total;
|
|
|
|
GetIndex(Current, Total, true);
|
|
|
|
int OldCurrent = Current;
|
2006-01-08 11:44:37 +01:00
|
|
|
// As GetNextIFrame() increments/decrements at least once, the
|
2005-08-29 15:45:38 +02:00
|
|
|
// destination frame (= Current + Frames) must be adjusted by
|
|
|
|
// -1/+1 respectively.
|
|
|
|
Current = index->GetNextIFrame(Current + Frames + (Frames > 0 ? -1 : 1), Frames > 0);
|
2002-06-16 12:57:31 +02:00
|
|
|
return Current >= 0 ? Current : OldCurrent;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void cDvbPlayer::SkipSeconds(int Seconds)
|
|
|
|
{
|
|
|
|
if (index && Seconds) {
|
|
|
|
LOCK_THREAD;
|
2009-03-13 14:45:12 +01:00
|
|
|
int Index = ptsIndex.FindIndex(DeviceGetSTC());
|
2002-06-16 12:57:31 +02:00
|
|
|
Empty();
|
|
|
|
if (Index >= 0) {
|
2009-01-06 14:41:11 +01:00
|
|
|
Index = max(Index + SecondsToFrames(Seconds, framesPerSecond), 0);
|
2002-06-16 12:57:31 +02:00
|
|
|
if (Index > 0)
|
2012-03-12 14:53:59 +01:00
|
|
|
Index = index->GetNextIFrame(Index, false, NULL, NULL, NULL);
|
2002-06-16 12:57:31 +02:00
|
|
|
if (Index >= 0)
|
2009-03-13 14:45:12 +01:00
|
|
|
readIndex = Index - 1; // Action() will first increment it!
|
2002-06-16 12:57:31 +02:00
|
|
|
}
|
|
|
|
Play();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void cDvbPlayer::Goto(int Index, bool Still)
|
|
|
|
{
|
|
|
|
if (index) {
|
|
|
|
LOCK_THREAD;
|
|
|
|
Empty();
|
|
|
|
if (++Index <= 0)
|
|
|
|
Index = 1; // not '0', to allow GetNextIFrame() below to work!
|
2009-01-06 14:41:11 +01:00
|
|
|
uint16_t FileNumber;
|
|
|
|
off_t FileOffset;
|
|
|
|
int Length;
|
2002-06-16 12:57:31 +02:00
|
|
|
Index = index->GetNextIFrame(Index, false, &FileNumber, &FileOffset, &Length);
|
2015-02-01 11:20:54 +01:00
|
|
|
if (Index >= 0) {
|
|
|
|
if (Still) {
|
|
|
|
if (NextFile(FileNumber, FileOffset)) {
|
|
|
|
uchar b[MAXFRAMESIZE];
|
|
|
|
int r = ReadFrame(replayFile, b, Length, sizeof(b));
|
|
|
|
if (r > 0) {
|
|
|
|
if (playMode == pmPause)
|
|
|
|
DevicePlay();
|
|
|
|
DeviceStillPicture(b, r);
|
2016-12-22 11:33:12 +01:00
|
|
|
ptsIndex.Put(isPesRecording ? PesGetPts(b) : TsGetPts(b, r), Index, true);
|
2015-02-01 11:20:54 +01:00
|
|
|
}
|
|
|
|
playMode = pmStill;
|
2022-01-13 21:41:41 +01:00
|
|
|
readIndex = Index - 1; // makes sure a later play starts with this I-frame
|
2015-02-01 11:20:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
readIndex = Index - 1; // Action() will first increment it!
|
|
|
|
Play();
|
2002-06-16 12:57:31 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-20 09:10:19 +01:00
|
|
|
void cDvbPlayer::SetAudioTrack(eTrackType Type, const tTrackId *TrackId)
|
|
|
|
{
|
2013-03-08 13:47:02 +01:00
|
|
|
if (!cThread::IsMainThread())
|
|
|
|
return; // only do this upon user interaction
|
2013-02-20 09:10:19 +01:00
|
|
|
if (playMode == pmPlay) {
|
2013-03-07 14:47:02 +01:00
|
|
|
if (!ptsIndex.IsEmpty()) {
|
|
|
|
int Current, Total;
|
|
|
|
if (GetIndex(Current, Total, true))
|
|
|
|
Goto(Current);
|
|
|
|
}
|
2013-02-20 09:10:19 +01:00
|
|
|
}
|
|
|
|
else if (playMode == pmPause)
|
|
|
|
resyncAfterPause = true;
|
|
|
|
}
|
|
|
|
|
2002-07-13 11:16:27 +02:00
|
|
|
bool cDvbPlayer::GetIndex(int &Current, int &Total, bool SnapToIFrame)
|
2002-06-16 12:57:31 +02:00
|
|
|
{
|
|
|
|
if (index) {
|
2009-03-13 14:45:12 +01:00
|
|
|
Current = ptsIndex.FindIndex(DeviceGetSTC());
|
|
|
|
if (SnapToIFrame) {
|
|
|
|
int i1 = index->GetNextIFrame(Current + 1, false);
|
|
|
|
int i2 = index->GetNextIFrame(Current, true);
|
|
|
|
Current = (abs(Current - i1) <= abs(Current - i2)) ? i1 : i2;
|
2002-06-16 12:57:31 +02:00
|
|
|
}
|
|
|
|
Total = index->Last();
|
2002-07-13 11:16:27 +02:00
|
|
|
return true;
|
2002-06-16 12:57:31 +02:00
|
|
|
}
|
2002-07-13 11:16:27 +02:00
|
|
|
Current = Total = -1;
|
|
|
|
return false;
|
2002-06-16 12:57:31 +02:00
|
|
|
}
|
|
|
|
|
2016-12-22 11:33:12 +01:00
|
|
|
bool cDvbPlayer::GetFrameNumber(int &Current, int &Total)
|
|
|
|
{
|
|
|
|
if (index) {
|
|
|
|
Current = ptsIndex.FindFrameNumber(DeviceGetSTC());
|
|
|
|
Total = index->Last();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
Current = Total = -1;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2002-06-16 12:57:31 +02:00
|
|
|
bool cDvbPlayer::GetReplayMode(bool &Play, bool &Forward, int &Speed)
|
|
|
|
{
|
|
|
|
Play = (playMode == pmPlay || playMode == pmFast);
|
|
|
|
Forward = (playDir == pdForward);
|
|
|
|
if (playMode == pmFast || playMode == pmSlow)
|
|
|
|
Speed = Setup.MultiSpeedMode ? abs(trickSpeed - NORMAL_SPEED) : 0;
|
|
|
|
else
|
|
|
|
Speed = -1;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// --- cDvbPlayerControl -----------------------------------------------------
|
|
|
|
|
2012-02-19 11:50:20 +01:00
|
|
|
cDvbPlayerControl::cDvbPlayerControl(const char *FileName, bool PauseLive)
|
2022-12-05 14:45:51 +01:00
|
|
|
:cControl(NULL, PauseLive)
|
2002-06-16 12:57:31 +02:00
|
|
|
{
|
2022-12-05 14:45:51 +01:00
|
|
|
player = new cDvbPlayer(FileName, PauseLive);
|
|
|
|
SetPlayer(player);
|
2002-06-16 12:57:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
cDvbPlayerControl::~cDvbPlayerControl()
|
|
|
|
{
|
|
|
|
Stop();
|
|
|
|
}
|
|
|
|
|
2015-09-01 11:14:27 +02:00
|
|
|
void cDvbPlayerControl::SetMarks(const cMarks *Marks)
|
2015-02-06 15:42:21 +01:00
|
|
|
{
|
|
|
|
if (player)
|
|
|
|
player->SetMarks(Marks);
|
|
|
|
}
|
|
|
|
|
2002-06-16 12:57:31 +02:00
|
|
|
bool cDvbPlayerControl::Active(void)
|
|
|
|
{
|
|
|
|
return player && player->Active();
|
|
|
|
}
|
|
|
|
|
|
|
|
void cDvbPlayerControl::Stop(void)
|
|
|
|
{
|
2017-11-26 15:02:54 +01:00
|
|
|
cControl::player = NULL;
|
2002-06-16 12:57:31 +02:00
|
|
|
delete player;
|
|
|
|
player = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void cDvbPlayerControl::Pause(void)
|
|
|
|
{
|
|
|
|
if (player)
|
|
|
|
player->Pause();
|
|
|
|
}
|
|
|
|
|
|
|
|
void cDvbPlayerControl::Play(void)
|
|
|
|
{
|
|
|
|
if (player)
|
|
|
|
player->Play();
|
|
|
|
}
|
|
|
|
|
|
|
|
void cDvbPlayerControl::Forward(void)
|
|
|
|
{
|
|
|
|
if (player)
|
|
|
|
player->Forward();
|
|
|
|
}
|
|
|
|
|
|
|
|
void cDvbPlayerControl::Backward(void)
|
|
|
|
{
|
|
|
|
if (player)
|
|
|
|
player->Backward();
|
|
|
|
}
|
|
|
|
|
|
|
|
void cDvbPlayerControl::SkipSeconds(int Seconds)
|
|
|
|
{
|
|
|
|
if (player)
|
|
|
|
player->SkipSeconds(Seconds);
|
|
|
|
}
|
|
|
|
|
|
|
|
int cDvbPlayerControl::SkipFrames(int Frames)
|
|
|
|
{
|
|
|
|
if (player)
|
|
|
|
return player->SkipFrames(Frames);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool cDvbPlayerControl::GetIndex(int &Current, int &Total, bool SnapToIFrame)
|
|
|
|
{
|
|
|
|
if (player) {
|
|
|
|
player->GetIndex(Current, Total, SnapToIFrame);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-12-22 11:33:12 +01:00
|
|
|
bool cDvbPlayerControl::GetFrameNumber(int &Current, int &Total)
|
|
|
|
{
|
|
|
|
if (player) {
|
|
|
|
player->GetFrameNumber(Current, Total);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2002-06-16 12:57:31 +02:00
|
|
|
bool cDvbPlayerControl::GetReplayMode(bool &Play, bool &Forward, int &Speed)
|
|
|
|
{
|
|
|
|
return player && player->GetReplayMode(Play, Forward, Speed);
|
|
|
|
}
|
|
|
|
|
|
|
|
void cDvbPlayerControl::Goto(int Position, bool Still)
|
|
|
|
{
|
|
|
|
if (player)
|
|
|
|
player->Goto(Position, Still);
|
|
|
|
}
|