2000-02-19 13:36:48 +01:00
|
|
|
/*
|
|
|
|
* dvbapi.c: Interface to the DVB driver
|
|
|
|
*
|
2000-04-24 09:46:05 +02:00
|
|
|
* See the main source file 'vdr.c' for copyright information and
|
2000-02-19 13:36:48 +01:00
|
|
|
* how to reach the author.
|
|
|
|
*
|
2002-04-21 12:11:00 +02:00
|
|
|
* $Id: dvbapi.c 1.173 2002/04/21 11:55:48 kls Exp $
|
2000-02-19 13:36:48 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "dvbapi.h"
|
2001-06-02 10:47:40 +02:00
|
|
|
#include <dirent.h>
|
2000-04-15 17:38:11 +02:00
|
|
|
#include <errno.h>
|
2000-02-19 13:36:48 +01:00
|
|
|
#include <fcntl.h>
|
2000-09-17 11:53:35 +02:00
|
|
|
extern "C" {
|
2001-06-02 10:47:40 +02:00
|
|
|
#define HAVE_BOOLEAN
|
2000-09-17 11:53:35 +02:00
|
|
|
#include <jpeglib.h>
|
|
|
|
}
|
2000-04-15 17:38:11 +02:00
|
|
|
#include <stdlib.h>
|
2000-02-19 13:36:48 +01:00
|
|
|
#include <sys/ioctl.h>
|
2000-09-17 11:53:35 +02:00
|
|
|
#include <sys/mman.h>
|
2000-04-15 17:38:11 +02:00
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/time.h>
|
2000-02-19 13:36:48 +01:00
|
|
|
#include <unistd.h>
|
2000-10-08 16:18:23 +02:00
|
|
|
#include "config.h"
|
2000-12-28 12:57:16 +01:00
|
|
|
#include "recording.h"
|
2001-03-31 08:42:27 +02:00
|
|
|
#include "remux.h"
|
|
|
|
#include "ringbuffer.h"
|
2000-02-19 13:36:48 +01:00
|
|
|
#include "tools.h"
|
2000-07-29 15:21:42 +02:00
|
|
|
#include "videodir.h"
|
2000-02-19 13:36:48 +01:00
|
|
|
|
2001-09-15 14:00:14 +02:00
|
|
|
#define DEV_VIDEO "/dev/video"
|
|
|
|
#define DEV_OST_OSD "/dev/ost/osd"
|
|
|
|
#define DEV_OST_FRONTEND "/dev/ost/frontend"
|
|
|
|
#define DEV_OST_SEC "/dev/ost/sec"
|
|
|
|
#define DEV_OST_DVR "/dev/ost/dvr"
|
|
|
|
#define DEV_OST_DEMUX "/dev/ost/demux"
|
|
|
|
#define DEV_OST_VIDEO "/dev/ost/video"
|
|
|
|
#define DEV_OST_AUDIO "/dev/ost/audio"
|
2000-02-19 13:36:48 +01:00
|
|
|
|
2000-04-15 17:38:11 +02:00
|
|
|
// The size of the array used to buffer video data:
|
2001-03-31 08:42:27 +02:00
|
|
|
// (must be larger than MINVIDEODATA - see remux.h)
|
2001-08-25 13:52:38 +02:00
|
|
|
#define VIDEOBUFSIZE MEGABYTE(1)
|
2000-02-19 13:36:48 +01:00
|
|
|
|
2001-06-02 10:47:40 +02:00
|
|
|
// The maximum size of a single frame:
|
2001-08-25 13:52:38 +02:00
|
|
|
#define MAXFRAMESIZE KILOBYTE(192)
|
|
|
|
|
2000-04-15 17:38:11 +02:00
|
|
|
#define MAXFILESPERRECORDING 255
|
|
|
|
|
2000-07-29 15:21:42 +02:00
|
|
|
#define MINFREEDISKSPACE (512) // MB
|
|
|
|
#define DISKCHECKINTERVAL 100 // seconds
|
|
|
|
|
2000-04-15 17:38:11 +02:00
|
|
|
#define INDEXFILESUFFIX "/index.vdr"
|
|
|
|
#define RECORDFILESUFFIX "/%03d.vdr"
|
|
|
|
#define RECORDFILESUFFIXLEN 20 // some additional bytes for safety...
|
|
|
|
|
|
|
|
// The number of frames to back up when resuming an interrupted replay session:
|
|
|
|
#define RESUMEBACKUP (10 * FRAMESPERSEC)
|
|
|
|
|
2001-07-29 09:50:49 +02:00
|
|
|
// The maximum time we wait before assuming that a recorded video data stream
|
|
|
|
// is broken:
|
|
|
|
#define MAXBROKENTIMEOUT 30 // seconds
|
|
|
|
|
2001-10-21 13:36:27 +02:00
|
|
|
// The maximum time to wait before giving up while catching up on an index file:
|
|
|
|
#define MAXINDEXCATCHUP 2 // seconds
|
|
|
|
|
2002-03-08 14:24:19 +01:00
|
|
|
// The default priority for non-primary DVB cards:
|
|
|
|
#define DEFAULTPRIORITY -2
|
|
|
|
|
2001-06-02 10:47:40 +02:00
|
|
|
#define CHECK(s) { if ((s) < 0) LOG_ERROR; } // used for 'ioctl()' calls
|
2000-04-15 17:38:11 +02:00
|
|
|
|
2001-08-12 15:22:48 +02:00
|
|
|
#define FATALERRNO (errno != EAGAIN && errno != EINTR)
|
|
|
|
|
2001-06-02 10:47:40 +02:00
|
|
|
typedef unsigned char uchar;
|
2000-12-08 16:23:32 +01:00
|
|
|
|
2000-12-28 12:57:16 +01:00
|
|
|
const char *IndexToHMSF(int Index, bool WithFrame)
|
2000-12-09 11:13:00 +01:00
|
|
|
{
|
|
|
|
static char buffer[16];
|
|
|
|
int f = (Index % FRAMESPERSEC) + 1;
|
|
|
|
int s = (Index / FRAMESPERSEC);
|
|
|
|
int m = s / 60 % 60;
|
|
|
|
int h = s / 3600;
|
|
|
|
s %= 60;
|
|
|
|
snprintf(buffer, sizeof(buffer), WithFrame ? "%d:%02d:%02d.%02d" : "%d:%02d:%02d", h, m, s, f);
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
|
2000-12-28 12:57:16 +01:00
|
|
|
int HMSFToIndex(const char *HMSF)
|
|
|
|
{
|
|
|
|
int h, m, s, f = 0;
|
|
|
|
if (3 <= sscanf(HMSF, "%d:%d:%d.%d", &h, &m, &s, &f))
|
|
|
|
return (h * 3600 + m * 60 + s) * FRAMESPERSEC + f - 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2000-04-15 17:38:11 +02:00
|
|
|
// --- cIndexFile ------------------------------------------------------------
|
|
|
|
|
|
|
|
class cIndexFile {
|
|
|
|
private:
|
|
|
|
struct tIndex { int offset; uchar type; uchar number; short reserved; };
|
|
|
|
int f;
|
2002-03-23 16:17:39 +01:00
|
|
|
char *fileName;
|
2000-10-03 11:26:10 +02:00
|
|
|
int size, last;
|
2000-04-15 17:38:11 +02:00
|
|
|
tIndex *index;
|
2000-10-03 11:26:10 +02:00
|
|
|
cResumeFile resumeFile;
|
2001-10-21 13:36:27 +02:00
|
|
|
bool CatchUp(int Index = -1);
|
2000-04-15 17:38:11 +02:00
|
|
|
public:
|
2000-12-28 12:57:16 +01:00
|
|
|
cIndexFile(const char *FileName, bool Record);
|
2000-04-15 17:38:11 +02:00
|
|
|
~cIndexFile();
|
2001-06-02 10:47:40 +02:00
|
|
|
bool Ok(void) { return index != NULL; }
|
2002-01-26 13:42:15 +01:00
|
|
|
bool Write(uchar PictureType, uchar FileNumber, int FileOffset);
|
2000-12-28 12:57:16 +01:00
|
|
|
bool Get(int Index, uchar *FileNumber, int *FileOffset, uchar *PictureType = NULL, int *Length = NULL);
|
2001-10-21 13:36:27 +02:00
|
|
|
int GetNextIFrame(int Index, bool Forward, uchar *FileNumber = NULL, int *FileOffset = NULL, int *Length = NULL, bool StayOffEnd = false);
|
2000-04-15 17:38:11 +02:00
|
|
|
int Get(uchar FileNumber, int FileOffset);
|
2000-12-28 12:57:16 +01:00
|
|
|
int Last(void) { CatchUp(); return last; }
|
2000-10-03 11:26:10 +02:00
|
|
|
int GetResume(void) { return resumeFile.Read(); }
|
|
|
|
bool StoreResume(int Index) { return resumeFile.Save(Index); }
|
2000-04-15 17:38:11 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
cIndexFile::cIndexFile(const char *FileName, bool Record)
|
2000-10-03 11:26:10 +02:00
|
|
|
:resumeFile(FileName)
|
2000-02-19 13:36:48 +01:00
|
|
|
{
|
2000-04-15 17:38:11 +02:00
|
|
|
f = -1;
|
2002-03-23 16:17:39 +01:00
|
|
|
fileName = NULL;
|
2000-05-27 14:07:17 +02:00
|
|
|
size = 0;
|
2000-10-03 11:26:10 +02:00
|
|
|
last = -1;
|
2000-04-15 17:38:11 +02:00
|
|
|
index = NULL;
|
|
|
|
if (FileName) {
|
2000-10-03 11:26:10 +02:00
|
|
|
fileName = new char[strlen(FileName) + strlen(INDEXFILESUFFIX) + 1];
|
|
|
|
if (fileName) {
|
2000-04-15 17:38:11 +02:00
|
|
|
strcpy(fileName, FileName);
|
2002-03-23 16:17:39 +01:00
|
|
|
char *pFileExt = fileName + strlen(fileName);
|
2000-04-15 17:38:11 +02:00
|
|
|
strcpy(pFileExt, INDEXFILESUFFIX);
|
|
|
|
int delta = 0;
|
|
|
|
if (access(fileName, R_OK) == 0) {
|
|
|
|
struct stat buf;
|
|
|
|
if (stat(fileName, &buf) == 0) {
|
|
|
|
delta = buf.st_size % sizeof(tIndex);
|
|
|
|
if (delta) {
|
|
|
|
delta = sizeof(tIndex) - delta;
|
2002-01-13 16:21:48 +01:00
|
|
|
esyslog(LOG_ERR, "ERROR: invalid file size (%ld) in '%s'", buf.st_size, fileName);
|
2000-04-15 17:38:11 +02:00
|
|
|
}
|
|
|
|
last = (buf.st_size + delta) / sizeof(tIndex) - 1;
|
|
|
|
if (!Record && last >= 0) {
|
2000-05-27 14:07:17 +02:00
|
|
|
size = last + 1;
|
|
|
|
index = new tIndex[size];
|
|
|
|
if (index) {
|
|
|
|
f = open(fileName, O_RDONLY);
|
|
|
|
if (f >= 0) {
|
2001-08-12 15:22:48 +02:00
|
|
|
if ((int)safe_read(f, index, buf.st_size) != buf.st_size) {
|
2000-05-27 14:07:17 +02:00
|
|
|
esyslog(LOG_ERR, "ERROR: can't read from file '%s'", fileName);
|
|
|
|
delete index;
|
|
|
|
index = NULL;
|
|
|
|
close(f);
|
|
|
|
f = -1;
|
|
|
|
}
|
|
|
|
// we don't close f here, see CatchUp()!
|
2000-04-15 17:38:11 +02:00
|
|
|
}
|
2000-05-27 14:07:17 +02:00
|
|
|
else
|
|
|
|
LOG_ERROR_STR(fileName);
|
2000-04-15 17:38:11 +02:00
|
|
|
}
|
|
|
|
else
|
2000-05-27 14:07:17 +02:00
|
|
|
esyslog(LOG_ERR, "ERROR: can't allocate %d bytes for index '%s'", size * sizeof(tIndex), fileName);
|
2000-04-15 17:38:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
LOG_ERROR;
|
|
|
|
}
|
2001-06-02 10:47:40 +02:00
|
|
|
else if (!Record)
|
|
|
|
isyslog(LOG_INFO, "missing index file %s", fileName);
|
2000-04-15 17:38:11 +02:00
|
|
|
if (Record) {
|
2001-06-02 10:47:40 +02:00
|
|
|
if ((f = open(fileName, O_WRONLY | O_CREAT | O_APPEND, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)) >= 0) {
|
2000-04-15 17:38:11 +02:00
|
|
|
if (delta) {
|
|
|
|
esyslog(LOG_ERR, "ERROR: padding index file with %d '0' bytes", delta);
|
|
|
|
while (delta--)
|
|
|
|
writechar(f, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
LOG_ERROR_STR(fileName);
|
|
|
|
}
|
|
|
|
}
|
2000-02-19 13:36:48 +01:00
|
|
|
else
|
2000-04-15 17:38:11 +02:00
|
|
|
esyslog(LOG_ERR, "ERROR: can't copy file name '%s'", FileName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
cIndexFile::~cIndexFile()
|
|
|
|
{
|
|
|
|
if (f >= 0)
|
|
|
|
close(f);
|
|
|
|
delete fileName;
|
2001-11-03 12:52:39 +01:00
|
|
|
delete index;
|
2000-04-15 17:38:11 +02:00
|
|
|
}
|
|
|
|
|
2001-10-21 13:36:27 +02:00
|
|
|
bool cIndexFile::CatchUp(int Index)
|
2000-05-27 14:07:17 +02:00
|
|
|
{
|
|
|
|
if (index && f >= 0) {
|
2001-10-21 13:36:27 +02:00
|
|
|
for (int i = 0; i <= MAXINDEXCATCHUP && (Index < 0 || Index >= last); i++) {
|
|
|
|
struct stat buf;
|
|
|
|
if (fstat(f, &buf) == 0) {
|
|
|
|
int newLast = buf.st_size / sizeof(tIndex) - 1;
|
|
|
|
if (newLast > last) {
|
|
|
|
if (size <= newLast) {
|
|
|
|
size *= 2;
|
|
|
|
if (size <= newLast)
|
|
|
|
size = newLast + 1;
|
|
|
|
}
|
|
|
|
index = (tIndex *)realloc(index, size * sizeof(tIndex));
|
|
|
|
if (index) {
|
|
|
|
int offset = (last + 1) * sizeof(tIndex);
|
|
|
|
int delta = (newLast - last) * sizeof(tIndex);
|
|
|
|
if (lseek(f, offset, SEEK_SET) == offset) {
|
|
|
|
if (safe_read(f, &index[last + 1], delta) != delta) {
|
|
|
|
esyslog(LOG_ERR, "ERROR: can't read from index");
|
|
|
|
delete index;
|
|
|
|
index = NULL;
|
|
|
|
close(f);
|
|
|
|
f = -1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
last = newLast;
|
|
|
|
}
|
|
|
|
else
|
2002-03-23 16:17:39 +01:00
|
|
|
LOG_ERROR_STR(fileName);
|
2001-10-21 13:36:27 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
esyslog(LOG_ERR, "ERROR: can't realloc() index");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2002-03-23 16:17:39 +01:00
|
|
|
LOG_ERROR_STR(fileName);
|
2001-10-21 13:36:27 +02:00
|
|
|
if (Index >= last)
|
|
|
|
sleep(1);
|
|
|
|
else
|
|
|
|
return true;
|
|
|
|
}
|
2000-05-27 14:07:17 +02:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2002-01-26 13:42:15 +01:00
|
|
|
bool cIndexFile::Write(uchar PictureType, uchar FileNumber, int FileOffset)
|
2000-04-15 17:38:11 +02:00
|
|
|
{
|
|
|
|
if (f >= 0) {
|
|
|
|
tIndex i = { FileOffset, PictureType, FileNumber, 0 };
|
2002-03-23 16:17:39 +01:00
|
|
|
if (safe_write(f, &i, sizeof(i)) < 0) {
|
|
|
|
LOG_ERROR_STR(fileName);
|
2000-04-15 17:38:11 +02:00
|
|
|
close(f);
|
|
|
|
f = -1;
|
2002-01-26 13:42:15 +01:00
|
|
|
return false;
|
2000-04-15 17:38:11 +02:00
|
|
|
}
|
|
|
|
last++;
|
|
|
|
}
|
2002-01-26 13:42:15 +01:00
|
|
|
return f >= 0;
|
2000-04-15 17:38:11 +02:00
|
|
|
}
|
|
|
|
|
2000-12-28 12:57:16 +01:00
|
|
|
bool cIndexFile::Get(int Index, uchar *FileNumber, int *FileOffset, uchar *PictureType, int *Length)
|
2000-04-15 17:38:11 +02:00
|
|
|
{
|
|
|
|
if (index) {
|
2001-10-21 13:36:27 +02:00
|
|
|
CatchUp(Index);
|
2000-04-15 17:38:11 +02:00
|
|
|
if (Index >= 0 && Index <= last) {
|
|
|
|
*FileNumber = index[Index].number;
|
|
|
|
*FileOffset = index[Index].offset;
|
|
|
|
if (PictureType)
|
|
|
|
*PictureType = index[Index].type;
|
2000-12-28 12:57:16 +01:00
|
|
|
if (Length) {
|
|
|
|
int fn = index[Index + 1].number;
|
|
|
|
int fo = index[Index + 1].offset;
|
|
|
|
if (fn == *FileNumber)
|
|
|
|
*Length = fo - *FileOffset;
|
|
|
|
else
|
|
|
|
*Length = -1; // this means "everything up to EOF" (the buffer's Read function will act accordingly)
|
|
|
|
}
|
2000-02-19 13:36:48 +01:00
|
|
|
return true;
|
2000-04-15 17:38:11 +02:00
|
|
|
}
|
2000-02-19 13:36:48 +01:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2001-10-21 13:36:27 +02:00
|
|
|
int cIndexFile::GetNextIFrame(int Index, bool Forward, uchar *FileNumber, int *FileOffset, int *Length, bool StayOffEnd)
|
2000-04-15 17:38:11 +02:00
|
|
|
{
|
|
|
|
if (index) {
|
2000-05-27 14:07:17 +02:00
|
|
|
if (Forward)
|
|
|
|
CatchUp();
|
2000-04-15 17:38:11 +02:00
|
|
|
int d = Forward ? 1 : -1;
|
|
|
|
for (;;) {
|
|
|
|
Index += d;
|
2001-10-21 13:36:27 +02:00
|
|
|
if (Index >= 0 && Index < last - ((Forward && StayOffEnd) ? 100 : 0)) {
|
2000-04-15 17:38:11 +02:00
|
|
|
if (index[Index].type == I_FRAME) {
|
2000-12-28 12:57:16 +01:00
|
|
|
if (FileNumber)
|
|
|
|
*FileNumber = index[Index].number;
|
|
|
|
else
|
|
|
|
FileNumber = &index[Index].number;
|
|
|
|
if (FileOffset)
|
|
|
|
*FileOffset = index[Index].offset;
|
|
|
|
else
|
|
|
|
FileOffset = &index[Index].offset;
|
2000-04-15 17:38:11 +02:00
|
|
|
if (Length) {
|
|
|
|
// all recordings end with a non-I_FRAME, so the following should be safe:
|
|
|
|
int fn = index[Index + 1].number;
|
|
|
|
int fo = index[Index + 1].offset;
|
|
|
|
if (fn == *FileNumber)
|
|
|
|
*Length = fo - *FileOffset;
|
|
|
|
else {
|
|
|
|
esyslog(LOG_ERR, "ERROR: 'I' frame at end of file #%d", *FileNumber);
|
|
|
|
*Length = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int cIndexFile::Get(uchar FileNumber, int FileOffset)
|
|
|
|
{
|
|
|
|
if (index) {
|
2000-05-27 14:07:17 +02:00
|
|
|
CatchUp();
|
2000-04-15 17:38:11 +02:00
|
|
|
//TODO implement binary search!
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < last; i++) {
|
|
|
|
if (index[i].number > FileNumber || (index[i].number == FileNumber) && index[i].offset >= FileOffset)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
2000-02-19 13:36:48 +01:00
|
|
|
|
2000-12-28 12:57:16 +01:00
|
|
|
// --- cFileName -------------------------------------------------------------
|
|
|
|
|
|
|
|
class cFileName {
|
|
|
|
private:
|
|
|
|
int file;
|
|
|
|
int fileNumber;
|
2000-04-15 17:38:11 +02:00
|
|
|
char *fileName, *pFileNumber;
|
2000-12-28 12:57:16 +01:00
|
|
|
bool record;
|
2001-06-02 10:47:40 +02:00
|
|
|
bool blocking;
|
2000-04-15 17:38:11 +02:00
|
|
|
public:
|
2001-06-02 10:47:40 +02:00
|
|
|
cFileName(const char *FileName, bool Record, bool Blocking = false);
|
2000-12-28 12:57:16 +01:00
|
|
|
~cFileName();
|
|
|
|
const char *Name(void) { return fileName; }
|
|
|
|
int Number(void) { return fileNumber; }
|
|
|
|
int Open(void);
|
|
|
|
void Close(void);
|
|
|
|
int SetOffset(int Number, int Offset = 0);
|
|
|
|
int NextFile(void);
|
2000-04-15 17:38:11 +02:00
|
|
|
};
|
|
|
|
|
2001-06-02 10:47:40 +02:00
|
|
|
cFileName::cFileName(const char *FileName, bool Record, bool Blocking)
|
2000-04-15 17:38:11 +02:00
|
|
|
{
|
2000-12-28 12:57:16 +01:00
|
|
|
file = -1;
|
2000-04-15 17:38:11 +02:00
|
|
|
fileNumber = 0;
|
2000-12-28 12:57:16 +01:00
|
|
|
record = Record;
|
2001-06-02 10:47:40 +02:00
|
|
|
blocking = Blocking;
|
2000-04-15 17:38:11 +02:00
|
|
|
// Prepare the file name:
|
|
|
|
fileName = new char[strlen(FileName) + RECORDFILESUFFIXLEN];
|
|
|
|
if (!fileName) {
|
|
|
|
esyslog(LOG_ERR, "ERROR: can't copy file name '%s'", fileName);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
strcpy(fileName, FileName);
|
|
|
|
pFileNumber = fileName + strlen(fileName);
|
2000-12-28 12:57:16 +01:00
|
|
|
SetOffset(1);
|
2000-04-15 17:38:11 +02:00
|
|
|
}
|
|
|
|
|
2000-12-28 12:57:16 +01:00
|
|
|
cFileName::~cFileName()
|
2000-04-15 17:38:11 +02:00
|
|
|
{
|
2000-12-28 12:57:16 +01:00
|
|
|
Close();
|
2000-04-15 17:38:11 +02:00
|
|
|
delete fileName;
|
|
|
|
}
|
|
|
|
|
2000-12-28 12:57:16 +01:00
|
|
|
int cFileName::Open(void)
|
2000-04-15 17:38:11 +02:00
|
|
|
{
|
2000-12-28 12:57:16 +01:00
|
|
|
if (file < 0) {
|
2001-06-02 10:47:40 +02:00
|
|
|
int BlockingFlag = blocking ? 0 : O_NONBLOCK;
|
2000-12-28 12:57:16 +01:00
|
|
|
if (record) {
|
|
|
|
dsyslog(LOG_INFO, "recording to '%s'", fileName);
|
2001-06-02 10:47:40 +02:00
|
|
|
file = OpenVideoFile(fileName, O_RDWR | O_CREAT | BlockingFlag);
|
2000-12-28 12:57:16 +01:00
|
|
|
if (file < 0)
|
|
|
|
LOG_ERROR_STR(fileName);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (access(fileName, R_OK) == 0) {
|
|
|
|
dsyslog(LOG_INFO, "playing '%s'", fileName);
|
2001-06-02 10:47:40 +02:00
|
|
|
file = open(fileName, O_RDONLY | BlockingFlag);
|
2000-12-28 12:57:16 +01:00
|
|
|
if (file < 0)
|
|
|
|
LOG_ERROR_STR(fileName);
|
|
|
|
}
|
|
|
|
else if (errno != ENOENT)
|
|
|
|
LOG_ERROR_STR(fileName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return file;
|
|
|
|
}
|
2000-04-15 17:38:11 +02:00
|
|
|
|
2000-12-28 12:57:16 +01:00
|
|
|
void cFileName::Close(void)
|
|
|
|
{
|
|
|
|
if (file >= 0) {
|
|
|
|
if ((record && CloseVideoFile(file) < 0) || (!record && close(file) < 0))
|
|
|
|
LOG_ERROR_STR(fileName);
|
|
|
|
file = -1;
|
|
|
|
}
|
|
|
|
}
|
2000-12-08 16:23:32 +01:00
|
|
|
|
2000-12-28 12:57:16 +01:00
|
|
|
int cFileName::SetOffset(int Number, int Offset)
|
|
|
|
{
|
|
|
|
if (fileNumber != Number)
|
|
|
|
Close();
|
|
|
|
if (0 < Number && Number <= MAXFILESPERRECORDING) {
|
|
|
|
fileNumber = Number;
|
|
|
|
sprintf(pFileNumber, RECORDFILESUFFIX, fileNumber);
|
|
|
|
if (record) {
|
|
|
|
if (access(fileName, F_OK) == 0) // file exists, let's try next suffix
|
|
|
|
return SetOffset(Number + 1);
|
|
|
|
else if (errno != ENOENT) { // something serious has happened
|
|
|
|
LOG_ERROR_STR(fileName);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
// found a non existing file suffix
|
|
|
|
}
|
|
|
|
if (Open() >= 0) {
|
|
|
|
if (!record && Offset >= 0 && lseek(file, Offset, SEEK_SET) != Offset) {
|
|
|
|
LOG_ERROR_STR(fileName);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return file;
|
|
|
|
}
|
|
|
|
esyslog(LOG_ERR, "ERROR: max number of files (%d) exceeded", MAXFILESPERRECORDING);
|
2000-04-15 17:38:11 +02:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2000-12-28 12:57:16 +01:00
|
|
|
int cFileName::NextFile(void)
|
2000-04-15 17:38:11 +02:00
|
|
|
{
|
2000-12-28 12:57:16 +01:00
|
|
|
return SetOffset(fileNumber + 1);
|
2000-04-15 17:38:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// --- cRecordBuffer ---------------------------------------------------------
|
|
|
|
|
2001-08-05 12:23:24 +02:00
|
|
|
class cRecordBuffer : public cRingBufferLinear {
|
2000-04-15 17:38:11 +02:00
|
|
|
private:
|
2001-06-02 10:47:40 +02:00
|
|
|
cDvbApi *dvbApi;
|
2000-12-28 12:57:16 +01:00
|
|
|
cFileName fileName;
|
|
|
|
cIndexFile *index;
|
2001-03-31 08:42:27 +02:00
|
|
|
cRemux remux;
|
2000-04-15 17:38:11 +02:00
|
|
|
uchar pictureType;
|
|
|
|
int fileSize;
|
2000-12-08 16:23:32 +01:00
|
|
|
int videoDev;
|
2000-04-15 17:38:11 +02:00
|
|
|
int recordFile;
|
2001-03-31 08:42:27 +02:00
|
|
|
bool recording;
|
2000-07-29 15:21:42 +02:00
|
|
|
time_t lastDiskSpaceCheck;
|
|
|
|
bool RunningLowOnDiskSpace(void);
|
2000-04-15 17:38:11 +02:00
|
|
|
bool NextFile(void);
|
2000-12-08 16:23:32 +01:00
|
|
|
protected:
|
2001-03-31 08:42:27 +02:00
|
|
|
virtual void Input(void);
|
|
|
|
virtual void Output(void);
|
2000-04-15 17:38:11 +02:00
|
|
|
public:
|
2001-06-24 17:42:19 +02:00
|
|
|
cRecordBuffer(cDvbApi *DvbApi, const char *FileName, int VPid, int APid1, int APid2, int DPid1, int DPid2);
|
2000-04-15 17:38:11 +02:00
|
|
|
virtual ~cRecordBuffer();
|
|
|
|
};
|
|
|
|
|
2001-06-24 17:42:19 +02:00
|
|
|
cRecordBuffer::cRecordBuffer(cDvbApi *DvbApi, const char *FileName, int VPid, int APid1, int APid2, int DPid1, int DPid2)
|
2001-08-05 12:23:24 +02:00
|
|
|
:cRingBufferLinear(VIDEOBUFSIZE, true)
|
2000-12-28 12:57:16 +01:00
|
|
|
,fileName(FileName, true)
|
2001-06-24 17:42:19 +02:00
|
|
|
,remux(VPid, APid1, APid2, DPid1, DPid2, true)
|
2000-04-15 17:38:11 +02:00
|
|
|
{
|
2001-06-02 10:47:40 +02:00
|
|
|
dvbApi = DvbApi;
|
2000-12-28 12:57:16 +01:00
|
|
|
index = NULL;
|
2000-04-15 17:38:11 +02:00
|
|
|
pictureType = NO_PICTURE;
|
|
|
|
fileSize = 0;
|
2000-12-28 12:57:16 +01:00
|
|
|
recordFile = fileName.Open();
|
2001-03-31 08:42:27 +02:00
|
|
|
recording = false;
|
2000-07-29 15:21:42 +02:00
|
|
|
lastDiskSpaceCheck = time(NULL);
|
2000-12-28 12:57:16 +01:00
|
|
|
if (!fileName.Name())
|
|
|
|
return;
|
|
|
|
// Create the index file:
|
|
|
|
index = new cIndexFile(FileName, true);
|
|
|
|
if (!index)
|
|
|
|
esyslog(LOG_ERR, "ERROR: can't allocate index");
|
|
|
|
// let's continue without index, so we'll at least have the recording
|
2001-06-02 10:47:40 +02:00
|
|
|
videoDev = dvbApi->SetModeRecord();
|
2000-12-08 16:23:32 +01:00
|
|
|
Start();
|
2000-04-15 17:38:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
cRecordBuffer::~cRecordBuffer()
|
|
|
|
{
|
2001-03-31 08:42:27 +02:00
|
|
|
Stop();
|
2001-06-02 10:47:40 +02:00
|
|
|
dvbApi->SetModeNormal(true);
|
2000-12-28 12:57:16 +01:00
|
|
|
delete index;
|
2000-07-29 15:21:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool cRecordBuffer::RunningLowOnDiskSpace(void)
|
|
|
|
{
|
|
|
|
if (time(NULL) > lastDiskSpaceCheck + DISKCHECKINTERVAL) {
|
2002-01-27 13:11:23 +01:00
|
|
|
int Free = FreeDiskSpaceMB(fileName.Name());
|
2000-07-29 15:21:42 +02:00
|
|
|
lastDiskSpaceCheck = time(NULL);
|
|
|
|
if (Free < MINFREEDISKSPACE) {
|
|
|
|
dsyslog(LOG_INFO, "low disk space (%d MB, limit is %d MB)", Free, MINFREEDISKSPACE);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2000-04-15 17:38:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool cRecordBuffer::NextFile(void)
|
|
|
|
{
|
2000-07-29 15:21:42 +02:00
|
|
|
if (recordFile >= 0 && pictureType == I_FRAME) { // every file shall start with an I_FRAME
|
2001-08-25 13:52:38 +02:00
|
|
|
if (fileSize > MEGABYTE(Setup.MaxVideoFileSize) || RunningLowOnDiskSpace()) {
|
2000-12-28 12:57:16 +01:00
|
|
|
recordFile = fileName.NextFile();
|
2000-07-29 15:21:42 +02:00
|
|
|
fileSize = 0;
|
|
|
|
}
|
2000-04-15 17:38:11 +02:00
|
|
|
}
|
2000-12-28 12:57:16 +01:00
|
|
|
return recordFile >= 0;
|
2000-02-19 13:36:48 +01:00
|
|
|
}
|
|
|
|
|
2001-03-31 08:42:27 +02:00
|
|
|
void cRecordBuffer::Input(void)
|
2000-02-19 13:36:48 +01:00
|
|
|
{
|
2001-03-31 08:42:27 +02:00
|
|
|
dsyslog(LOG_INFO, "input thread started (pid=%d)", getpid());
|
|
|
|
|
|
|
|
uchar b[MINVIDEODATA];
|
|
|
|
time_t t = time(NULL);
|
|
|
|
recording = true;
|
|
|
|
for (;;) {
|
2002-03-29 11:43:58 +01:00
|
|
|
if (cFile::FileReady(videoDev, 100)) {
|
|
|
|
int r = read(videoDev, b, sizeof(b));
|
|
|
|
if (r > 0) {
|
|
|
|
uchar *p = b;
|
|
|
|
while (r > 0) {
|
|
|
|
int w = Put(p, r);
|
|
|
|
p += w;
|
|
|
|
r -= w;
|
2002-04-20 10:45:33 +02:00
|
|
|
if (r > 0)
|
|
|
|
usleep(1); // this keeps the CPU load low
|
2002-03-29 11:43:58 +01:00
|
|
|
}
|
|
|
|
t = time(NULL);
|
|
|
|
}
|
|
|
|
else if (r < 0) {
|
|
|
|
if (FATALERRNO) {
|
|
|
|
if (errno == EBUFFEROVERFLOW) // this error code is not defined in the library
|
|
|
|
esyslog(LOG_ERR, "ERROR (%s,%d): DVB driver buffer overflow", __FILE__, __LINE__);
|
|
|
|
else {
|
|
|
|
LOG_ERROR;
|
|
|
|
break;
|
|
|
|
}
|
2001-08-19 14:37:17 +02:00
|
|
|
}
|
2000-04-15 17:38:11 +02:00
|
|
|
}
|
2001-03-31 08:42:27 +02:00
|
|
|
}
|
2001-07-29 09:50:49 +02:00
|
|
|
if (time(NULL) - t > MAXBROKENTIMEOUT) {
|
2001-03-31 08:42:27 +02:00
|
|
|
esyslog(LOG_ERR, "ERROR: video data stream broken");
|
2001-06-02 10:47:40 +02:00
|
|
|
cThread::EmergencyExit(true);
|
2001-06-14 08:22:30 +02:00
|
|
|
t = time(NULL);
|
2001-03-31 08:42:27 +02:00
|
|
|
}
|
|
|
|
if (!recording)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
dsyslog(LOG_INFO, "input thread ended (pid=%d)", getpid());
|
2000-02-19 13:36:48 +01:00
|
|
|
}
|
|
|
|
|
2001-03-31 08:42:27 +02:00
|
|
|
void cRecordBuffer::Output(void)
|
2000-02-19 13:36:48 +01:00
|
|
|
{
|
2001-03-31 08:42:27 +02:00
|
|
|
dsyslog(LOG_INFO, "output thread started (pid=%d)", getpid());
|
|
|
|
|
2001-06-02 10:47:40 +02:00
|
|
|
uchar b[MINVIDEODATA];
|
2001-03-31 08:42:27 +02:00
|
|
|
int r = 0;
|
|
|
|
for (;;) {
|
2001-06-02 10:47:40 +02:00
|
|
|
int g = Get(b + r, sizeof(b) - r);
|
2001-08-12 15:22:48 +02:00
|
|
|
if (g > 0)
|
2001-06-02 10:47:40 +02:00
|
|
|
r += g;
|
2001-08-12 15:22:48 +02:00
|
|
|
if (r > 0) {
|
2001-03-31 08:42:27 +02:00
|
|
|
int Count = r, Result;
|
2001-06-02 10:47:40 +02:00
|
|
|
const uchar *p = remux.Process(b, Count, Result, &pictureType);
|
2001-03-31 08:42:27 +02:00
|
|
|
if (p) {
|
|
|
|
if (!Busy() && pictureType == I_FRAME) // finish the recording before the next 'I' frame
|
|
|
|
break;
|
|
|
|
if (NextFile()) {
|
|
|
|
if (index && pictureType != NO_PICTURE)
|
|
|
|
index->Write(pictureType, fileName.Number(), fileSize);
|
2002-03-23 16:17:39 +01:00
|
|
|
if (safe_write(recordFile, p, Result) < 0) {
|
|
|
|
LOG_ERROR_STR(fileName.Name());
|
|
|
|
recording = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
fileSize += Result;
|
2001-03-31 08:42:27 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (Count > 0) {
|
|
|
|
r -= Count;
|
|
|
|
memmove(b, b + Count, r);
|
|
|
|
}
|
|
|
|
if (!recording)
|
|
|
|
break;
|
|
|
|
}
|
2001-06-02 10:47:40 +02:00
|
|
|
else
|
|
|
|
usleep(1); // this keeps the CPU load low
|
2001-03-31 08:42:27 +02:00
|
|
|
}
|
|
|
|
recording = false;
|
|
|
|
|
|
|
|
dsyslog(LOG_INFO, "output thread ended (pid=%d)", getpid());
|
2000-04-15 17:38:11 +02:00
|
|
|
}
|
|
|
|
|
2001-06-15 14:12:56 +02:00
|
|
|
// --- ReadFrame -------------------------------------------------------------
|
|
|
|
|
|
|
|
int ReadFrame(int f, uchar *b, int Length, int Max)
|
|
|
|
{
|
|
|
|
if (Length == -1)
|
|
|
|
Length = Max; // this means we read up to EOF (see cIndex)
|
|
|
|
else if (Length > Max) {
|
|
|
|
esyslog(LOG_ERR, "ERROR: frame larger than buffer (%d > %d)", Length, Max);
|
|
|
|
Length = Max;
|
|
|
|
}
|
2001-08-12 15:22:48 +02:00
|
|
|
int r = safe_read(f, b, Length);
|
2001-06-15 14:12:56 +02:00
|
|
|
if (r < 0)
|
|
|
|
LOG_ERROR;
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2001-09-09 13:36:16 +02:00
|
|
|
// --- cBackTrace ----------------------------------------------------------
|
|
|
|
|
|
|
|
#define AVG_FRAME_SIZE 15000 // an assumption about the average frame size
|
|
|
|
#define DVB_BUF_SIZE (256 * 1024) // an assumption about the dvb firmware buffer size
|
|
|
|
#define BACKTRACE_ENTRIES (DVB_BUF_SIZE / AVG_FRAME_SIZE + 20) // how many entries are needed to backtrace buffer contents
|
|
|
|
|
|
|
|
class cBackTrace {
|
|
|
|
private:
|
|
|
|
int index[BACKTRACE_ENTRIES];
|
|
|
|
int length[BACKTRACE_ENTRIES];
|
|
|
|
int pos, num;
|
|
|
|
public:
|
|
|
|
cBackTrace(void);
|
|
|
|
void Clear(void);
|
|
|
|
void Add(int Index, int Length);
|
|
|
|
int Get(bool Forward);
|
|
|
|
};
|
|
|
|
|
|
|
|
cBackTrace::cBackTrace(void)
|
|
|
|
{
|
|
|
|
Clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void cBackTrace::Clear(void)
|
|
|
|
{
|
|
|
|
pos = num = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void cBackTrace::Add(int Index, int Length)
|
|
|
|
{
|
|
|
|
index[pos] = Index;
|
|
|
|
length[pos] = Length;
|
|
|
|
if (++pos >= BACKTRACE_ENTRIES)
|
|
|
|
pos = 0;
|
|
|
|
if (num < BACKTRACE_ENTRIES)
|
|
|
|
num++;
|
|
|
|
}
|
|
|
|
|
|
|
|
int cBackTrace::Get(bool Forward)
|
|
|
|
{
|
|
|
|
int p = pos;
|
|
|
|
int n = num;
|
|
|
|
int l = DVB_BUF_SIZE + (Forward ? 0 : 256 * 1024); //XXX (256 * 1024) == DVB_BUF_SIZE ???
|
|
|
|
int i = -1;
|
|
|
|
|
|
|
|
while (n && l > 0) {
|
|
|
|
if (--p < 0)
|
|
|
|
p = BACKTRACE_ENTRIES - 1;
|
|
|
|
i = index[p] - 1;
|
|
|
|
l -= length[p];
|
|
|
|
n--;
|
|
|
|
}
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
2001-08-03 14:18:08 +02:00
|
|
|
// --- cPlayBuffer ---------------------------------------------------------
|
|
|
|
|
2001-09-09 12:52:41 +02:00
|
|
|
#define MAX_VIDEO_SLOWMOTION 63 // max. arg to pass to VIDEO_SLOWMOTION // TODO is this value correct?
|
|
|
|
|
2001-08-05 12:23:24 +02:00
|
|
|
class cPlayBuffer : public cRingBufferFrame {
|
2001-09-09 13:36:16 +02:00
|
|
|
private:
|
|
|
|
cBackTrace backTrace;
|
2001-08-03 14:18:08 +02:00
|
|
|
protected:
|
2001-09-09 12:52:41 +02:00
|
|
|
enum ePlayModes { pmPlay, pmPause, pmSlow, pmFast, pmStill };
|
|
|
|
enum ePlayDirs { pdForward, pdBackward };
|
|
|
|
static int Speeds[];
|
2001-08-03 14:18:08 +02:00
|
|
|
cDvbApi *dvbApi;
|
|
|
|
int videoDev, audioDev;
|
2001-09-15 13:00:58 +02:00
|
|
|
cPipe dolbyDev;
|
2001-08-03 14:18:08 +02:00
|
|
|
int blockInput, blockOutput;
|
2001-09-09 12:52:41 +02:00
|
|
|
ePlayModes playMode;
|
|
|
|
ePlayDirs playDir;
|
|
|
|
int trickSpeed;
|
2001-08-05 12:23:24 +02:00
|
|
|
int readIndex, writeIndex;
|
|
|
|
bool canDoTrickMode;
|
2001-08-03 14:18:08 +02:00
|
|
|
bool canToggleAudioTrack;
|
2001-11-25 16:44:13 +01:00
|
|
|
bool skipAC3bytes;
|
2001-08-03 14:18:08 +02:00
|
|
|
uchar audioTrack;
|
2001-09-09 12:52:41 +02:00
|
|
|
void TrickSpeed(int Increment);
|
2001-08-05 12:23:24 +02:00
|
|
|
virtual void Empty(bool Block = false);
|
|
|
|
virtual void StripAudioPackets(uchar *b, int Length, uchar Except = 0x00) {}
|
2001-11-03 11:05:15 +01:00
|
|
|
virtual void PlayExternalDolby(const uchar *b, int MaxLength);
|
2001-08-05 12:23:24 +02:00
|
|
|
virtual void Output(void);
|
2001-11-03 11:05:15 +01:00
|
|
|
void putFrame(cFrame *Frame);
|
|
|
|
void putFrame(unsigned char *Data, int Length, eFrameType Type = ftUnknown);
|
2001-08-03 14:18:08 +02:00
|
|
|
public:
|
|
|
|
cPlayBuffer(cDvbApi *DvbApi, int VideoDev, int AudioDev);
|
|
|
|
virtual ~cPlayBuffer();
|
2001-08-05 12:23:24 +02:00
|
|
|
virtual void Pause(void);
|
|
|
|
virtual void Play(void);
|
|
|
|
virtual void Forward(void);
|
|
|
|
virtual void Backward(void);
|
2001-08-03 14:18:08 +02:00
|
|
|
virtual int SkipFrames(int Frames) { return -1; }
|
|
|
|
virtual void SkipSeconds(int Seconds) {}
|
|
|
|
virtual void Goto(int Position, bool Still = false) {}
|
|
|
|
virtual void GetIndex(int &Current, int &Total, bool SnapToIFrame = false) { Current = Total = -1; }
|
2001-09-14 14:06:43 +02:00
|
|
|
bool GetReplayMode(bool &Play, bool &Forward, int &Speed);
|
2001-08-03 14:18:08 +02:00
|
|
|
bool CanToggleAudioTrack(void) { return canToggleAudioTrack; };
|
|
|
|
virtual void ToggleAudioTrack(void);
|
|
|
|
};
|
|
|
|
|
2001-09-09 12:52:41 +02:00
|
|
|
#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 cPlayBuffer::Speeds[] = { 0, -2, -4, -8, 1, 2, 4, 12, 0 };
|
|
|
|
|
2001-08-03 14:18:08 +02:00
|
|
|
cPlayBuffer::cPlayBuffer(cDvbApi *DvbApi, int VideoDev, int AudioDev)
|
2001-08-05 12:23:24 +02:00
|
|
|
:cRingBufferFrame(VIDEOBUFSIZE)
|
2001-08-03 14:18:08 +02:00
|
|
|
{
|
|
|
|
dvbApi = DvbApi;
|
|
|
|
videoDev = VideoDev;
|
|
|
|
audioDev = AudioDev;
|
|
|
|
blockInput = blockOutput = false;
|
2001-09-09 12:52:41 +02:00
|
|
|
playMode = pmPlay;
|
|
|
|
playDir = pdForward;
|
|
|
|
trickSpeed = NORMAL_SPEED;
|
2001-08-05 12:23:24 +02:00
|
|
|
readIndex = writeIndex = -1;
|
|
|
|
canDoTrickMode = false;
|
2001-08-03 14:18:08 +02:00
|
|
|
canToggleAudioTrack = false;
|
2001-11-25 16:44:13 +01:00
|
|
|
skipAC3bytes = false;
|
2001-08-03 14:18:08 +02:00
|
|
|
audioTrack = 0xC0;
|
|
|
|
}
|
|
|
|
|
|
|
|
cPlayBuffer::~cPlayBuffer()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2001-11-03 11:05:15 +01:00
|
|
|
void cPlayBuffer::PlayExternalDolby(const uchar *b, int MaxLength)
|
|
|
|
{
|
2002-03-09 12:09:57 +01:00
|
|
|
if (cDvbApi::AudioCommand()) {
|
|
|
|
if (!dolbyDev && !dolbyDev.Open(cDvbApi::AudioCommand(), "w")) {
|
|
|
|
esyslog(LOG_ERR, "ERROR: can't open pipe to audio command '%s'", cDvbApi::AudioCommand());
|
|
|
|
return;
|
|
|
|
}
|
2001-11-03 11:05:15 +01:00
|
|
|
if (b[0] == 0x00 && b[1] == 0x00 && b[2] == 0x01) {
|
|
|
|
if (b[3] == 0xBD) { // dolby
|
|
|
|
int l = b[4] * 256 + b[5] + 6;
|
2001-11-25 16:44:13 +01:00
|
|
|
int written = b[8] + (skipAC3bytes ? 13 : 9); // skips the PES header
|
2001-11-03 11:05:15 +01:00
|
|
|
int n = min(l - written, MaxLength);
|
|
|
|
while (n > 0) {
|
|
|
|
int w = fwrite(&b[written], 1, n, dolbyDev);
|
|
|
|
if (w < 0) {
|
|
|
|
LOG_ERROR;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
n -= w;
|
|
|
|
written += w;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-08-05 12:23:24 +02:00
|
|
|
void cPlayBuffer::Output(void)
|
|
|
|
{
|
|
|
|
dsyslog(LOG_INFO, "output thread started (pid=%d)", getpid());
|
|
|
|
|
|
|
|
while (Busy()) {
|
|
|
|
if (blockOutput) {
|
|
|
|
if (blockOutput > 1)
|
|
|
|
blockOutput = 1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
const cFrame *frame = Get();
|
|
|
|
if (frame) {
|
2001-11-03 11:05:15 +01:00
|
|
|
if (frame->Type() == ftDolby)
|
|
|
|
PlayExternalDolby(frame->Data(), frame->Count());
|
|
|
|
else {
|
|
|
|
StripAudioPackets((uchar *)frame->Data(), frame->Count(), (playMode == pmFast || playMode == pmSlow) ? 0x00 : audioTrack);//XXX
|
|
|
|
const uchar *p = frame->Data();
|
|
|
|
int r = frame->Count();
|
|
|
|
while (r > 0 && Busy() && !blockOutput) {
|
2002-03-29 11:43:58 +01:00
|
|
|
if (cFile::FileReadyForWriting(videoDev, 100)) {
|
|
|
|
int w = write(videoDev, p, r);
|
|
|
|
if (w > 0) {
|
|
|
|
p += w;
|
|
|
|
r -= w;
|
|
|
|
}
|
|
|
|
else if (w < 0 && FATALERRNO) {
|
|
|
|
LOG_ERROR;
|
|
|
|
Stop();
|
|
|
|
return;
|
|
|
|
}
|
2001-11-03 11:05:15 +01:00
|
|
|
}
|
2001-09-09 12:52:41 +02:00
|
|
|
}
|
2001-11-03 11:05:15 +01:00
|
|
|
writeIndex = frame->Index();
|
|
|
|
backTrace.Add(frame->Index(), frame->Count());
|
|
|
|
}
|
2001-08-05 12:23:24 +02:00
|
|
|
Drop(frame);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
dsyslog(LOG_INFO, "output thread ended (pid=%d)", getpid());
|
|
|
|
}
|
|
|
|
|
2001-11-03 11:05:15 +01:00
|
|
|
void cPlayBuffer::putFrame(cFrame *Frame)
|
|
|
|
{
|
|
|
|
while (Busy() && !blockInput) {
|
|
|
|
if (Put(Frame))
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
delete Frame; // caller relies on frame being put, otherwise this would be a memory leak!
|
|
|
|
}
|
|
|
|
|
|
|
|
void cPlayBuffer::putFrame(unsigned char *Data, int Length, eFrameType Type)
|
|
|
|
{
|
|
|
|
putFrame(new cFrame(Data, Length, Type));
|
|
|
|
}
|
|
|
|
|
2001-09-09 12:52:41 +02:00
|
|
|
void cPlayBuffer::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;
|
|
|
|
CHECK(ioctl(videoDev, VIDEO_SLOWMOTION, sp));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-08-05 12:23:24 +02:00
|
|
|
void cPlayBuffer::Empty(bool Block)
|
|
|
|
{
|
|
|
|
if (!(blockInput || blockOutput)) {
|
|
|
|
blockInput = blockOutput = 2;
|
|
|
|
EnablePut();
|
|
|
|
EnableGet();
|
|
|
|
time_t t0 = time(NULL);
|
|
|
|
while ((blockInput > 1 || blockOutput > 1) && time(NULL) - t0 < 2)
|
|
|
|
usleep(1);
|
|
|
|
Lock();
|
2001-09-09 13:36:16 +02:00
|
|
|
if ((readIndex = backTrace.Get(playDir == pdForward)) < 0)
|
|
|
|
readIndex = writeIndex;
|
2001-08-05 12:23:24 +02:00
|
|
|
cRingBufferFrame::Clear();
|
|
|
|
CHECK(ioctl(videoDev, VIDEO_CLEAR_BUFFER));
|
|
|
|
CHECK(ioctl(audioDev, AUDIO_CLEAR_BUFFER));
|
|
|
|
}
|
|
|
|
if (!Block) {
|
|
|
|
blockInput = blockOutput = 0;
|
2001-09-09 13:36:16 +02:00
|
|
|
backTrace.Clear();
|
2001-08-05 12:23:24 +02:00
|
|
|
Unlock();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void cPlayBuffer::Pause(void)
|
|
|
|
{
|
2001-09-09 12:52:41 +02:00
|
|
|
if (playMode == pmPause || playMode == pmStill)
|
|
|
|
Play();
|
|
|
|
else {
|
|
|
|
bool empty = (playMode == pmFast || (playMode == pmSlow && playDir == pdBackward));
|
|
|
|
if (empty)
|
|
|
|
Empty(true);
|
|
|
|
CHECK(ioctl(audioDev, AUDIO_SET_AV_SYNC, false));
|
|
|
|
CHECK(ioctl(videoDev, VIDEO_FREEZE));
|
|
|
|
playMode = pmPause;
|
|
|
|
if (empty)
|
|
|
|
Empty(false);
|
|
|
|
}
|
2001-08-05 12:23:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void cPlayBuffer::Play(void)
|
|
|
|
{
|
2001-09-09 12:52:41 +02:00
|
|
|
if (playMode != pmPlay) {
|
|
|
|
bool empty = (playMode == pmStill || playMode == pmFast || (playMode == pmSlow && playDir == pdBackward));
|
2001-08-05 12:23:24 +02:00
|
|
|
if (empty)
|
|
|
|
Empty(true);
|
|
|
|
CHECK(ioctl(audioDev, AUDIO_SET_AV_SYNC, true));
|
2001-09-09 12:52:41 +02:00
|
|
|
CHECK(ioctl(videoDev, VIDEO_CONTINUE));
|
|
|
|
playMode = pmPlay;
|
|
|
|
playDir = pdForward;
|
2001-08-05 12:23:24 +02:00
|
|
|
if (empty)
|
|
|
|
Empty(false);
|
2001-09-09 12:52:41 +02:00
|
|
|
}
|
2001-08-05 12:23:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void cPlayBuffer::Forward(void)
|
|
|
|
{
|
2001-09-09 12:52:41 +02:00
|
|
|
if (canDoTrickMode) {
|
|
|
|
switch (playMode) {
|
2001-09-14 14:19:37 +02:00
|
|
|
case pmFast:
|
|
|
|
if (Setup.MultiSpeedMode) {
|
|
|
|
TrickSpeed(playDir == pdForward ? 1 : -1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if (playDir == pdForward) {
|
|
|
|
Play();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// run into pmPlay
|
2001-09-09 12:52:41 +02:00
|
|
|
case pmPlay:
|
|
|
|
Empty(true);
|
|
|
|
CHECK(ioctl(audioDev, AUDIO_SET_AV_SYNC, false));
|
|
|
|
playMode = pmFast;
|
|
|
|
playDir = pdForward;
|
|
|
|
trickSpeed = NORMAL_SPEED;
|
|
|
|
TrickSpeed(Setup.MultiSpeedMode ? 1 : MAX_SPEEDS);
|
|
|
|
Empty(false);
|
|
|
|
break;
|
2001-09-14 14:19:37 +02:00
|
|
|
case pmSlow:
|
|
|
|
if (Setup.MultiSpeedMode) {
|
|
|
|
TrickSpeed(playDir == pdForward ? -1 : 1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if (playDir == pdForward) {
|
|
|
|
Pause();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// run into pmPause
|
2001-09-09 12:52:41 +02:00
|
|
|
case pmStill:
|
|
|
|
case pmPause:
|
|
|
|
CHECK(ioctl(audioDev, AUDIO_SET_AV_SYNC, false));
|
|
|
|
playMode = pmSlow;
|
|
|
|
playDir = pdForward;
|
|
|
|
trickSpeed = NORMAL_SPEED;
|
|
|
|
TrickSpeed(Setup.MultiSpeedMode ? -1 : -MAX_SPEEDS);
|
|
|
|
break;
|
|
|
|
}
|
2001-09-14 14:19:37 +02:00
|
|
|
}
|
2001-08-05 12:23:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void cPlayBuffer::Backward(void)
|
2001-08-03 14:18:08 +02:00
|
|
|
{
|
2001-08-05 12:23:24 +02:00
|
|
|
if (canDoTrickMode) {
|
2001-09-09 12:52:41 +02:00
|
|
|
switch (playMode) {
|
2001-09-14 14:19:37 +02:00
|
|
|
case pmFast:
|
|
|
|
if (Setup.MultiSpeedMode) {
|
|
|
|
TrickSpeed(playDir == pdBackward ? 1 : -1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if (playDir == pdBackward) {
|
|
|
|
Play();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// run into pmPlay
|
2001-09-09 12:52:41 +02:00
|
|
|
case pmPlay:
|
|
|
|
Empty(true);
|
|
|
|
CHECK(ioctl(audioDev, AUDIO_SET_AV_SYNC, false));
|
|
|
|
playMode = pmFast;
|
|
|
|
playDir = pdBackward;
|
|
|
|
trickSpeed = NORMAL_SPEED;
|
|
|
|
TrickSpeed(Setup.MultiSpeedMode ? 1 : MAX_SPEEDS);
|
|
|
|
Empty(false);
|
|
|
|
break;
|
2001-09-14 14:19:37 +02:00
|
|
|
case pmSlow:
|
|
|
|
if (Setup.MultiSpeedMode) {
|
|
|
|
TrickSpeed(playDir == pdBackward ? -1 : 1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if (playDir == pdBackward) {
|
|
|
|
Pause();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// run into pmPause
|
2001-09-09 12:52:41 +02:00
|
|
|
case pmStill:
|
|
|
|
case pmPause:
|
|
|
|
Empty(true);
|
|
|
|
CHECK(ioctl(audioDev, AUDIO_SET_AV_SYNC, false));
|
|
|
|
playMode = pmSlow;
|
|
|
|
playDir = pdBackward;
|
|
|
|
trickSpeed = NORMAL_SPEED;
|
|
|
|
TrickSpeed(Setup.MultiSpeedMode ? -1 : -MAX_SPEEDS);
|
|
|
|
Empty(false);
|
|
|
|
break;
|
|
|
|
}
|
2001-08-05 12:23:24 +02:00
|
|
|
}
|
2001-08-03 14:18:08 +02:00
|
|
|
}
|
|
|
|
|
2001-09-14 14:06:43 +02:00
|
|
|
bool cPlayBuffer::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;
|
|
|
|
}
|
|
|
|
|
2001-08-03 14:18:08 +02:00
|
|
|
void cPlayBuffer::ToggleAudioTrack(void)
|
|
|
|
{
|
|
|
|
if (CanToggleAudioTrack()) {
|
|
|
|
audioTrack = (audioTrack == 0xC0) ? 0xC1 : 0xC0;
|
2001-08-05 12:23:24 +02:00
|
|
|
Empty();
|
2001-08-03 14:18:08 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-04-15 17:38:11 +02:00
|
|
|
// --- cReplayBuffer ---------------------------------------------------------
|
|
|
|
|
2001-08-03 14:18:08 +02:00
|
|
|
class cReplayBuffer : public cPlayBuffer {
|
2000-04-15 17:38:11 +02:00
|
|
|
private:
|
2000-12-28 12:57:16 +01:00
|
|
|
cIndexFile *index;
|
|
|
|
cFileName fileName;
|
2000-04-15 17:38:11 +02:00
|
|
|
int replayFile;
|
2001-06-02 10:47:40 +02:00
|
|
|
bool eof;
|
2000-04-15 17:38:11 +02:00
|
|
|
bool NextFile(uchar FileNumber = 0, int FileOffset = -1);
|
|
|
|
void Close(void);
|
2001-08-05 12:23:24 +02:00
|
|
|
virtual void StripAudioPackets(uchar *b, int Length, uchar Except = 0x00);
|
2001-06-02 10:47:40 +02:00
|
|
|
void DisplayFrame(uchar *b, int Length);
|
|
|
|
int Resume(void);
|
|
|
|
bool Save(void);
|
2000-12-08 16:23:32 +01:00
|
|
|
protected:
|
2001-06-02 10:47:40 +02:00
|
|
|
virtual void Input(void);
|
2000-04-15 17:38:11 +02:00
|
|
|
public:
|
2001-06-02 10:47:40 +02:00
|
|
|
cReplayBuffer(cDvbApi *DvbApi, int VideoDev, int AudioDev, const char *FileName);
|
2000-09-17 11:53:35 +02:00
|
|
|
virtual ~cReplayBuffer();
|
2001-08-03 14:18:08 +02:00
|
|
|
virtual int SkipFrames(int Frames);
|
|
|
|
virtual void SkipSeconds(int Seconds);
|
|
|
|
virtual void Goto(int Position, bool Still = false);
|
|
|
|
virtual void GetIndex(int &Current, int &Total, bool SnapToIFrame = false);
|
2000-04-15 17:38:11 +02:00
|
|
|
};
|
|
|
|
|
2001-06-02 10:47:40 +02:00
|
|
|
cReplayBuffer::cReplayBuffer(cDvbApi *DvbApi, int VideoDev, int AudioDev, const char *FileName)
|
2001-08-03 14:18:08 +02:00
|
|
|
:cPlayBuffer(DvbApi, VideoDev, AudioDev)
|
2000-12-28 12:57:16 +01:00
|
|
|
,fileName(FileName, false)
|
2000-04-15 17:38:11 +02:00
|
|
|
{
|
2000-12-28 12:57:16 +01:00
|
|
|
index = NULL;
|
|
|
|
replayFile = fileName.Open();
|
2001-06-02 10:47:40 +02:00
|
|
|
eof = false;
|
2000-12-28 12:57:16 +01:00
|
|
|
if (!fileName.Name())
|
|
|
|
return;
|
|
|
|
// Create the index file:
|
|
|
|
index = new cIndexFile(FileName, false);
|
2002-02-02 13:44:24 +01:00
|
|
|
if (!index)
|
2000-12-28 12:57:16 +01:00
|
|
|
esyslog(LOG_ERR, "ERROR: can't allocate index");
|
2001-06-02 10:47:40 +02:00
|
|
|
else if (!index->Ok()) {
|
|
|
|
delete index;
|
|
|
|
index = NULL;
|
|
|
|
}
|
2001-08-05 12:23:24 +02:00
|
|
|
canDoTrickMode = index != NULL;
|
2001-06-02 10:47:40 +02:00
|
|
|
dvbApi->SetModeReplay();
|
2000-12-08 16:23:32 +01:00
|
|
|
Start();
|
2000-04-15 17:38:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
cReplayBuffer::~cReplayBuffer()
|
|
|
|
{
|
2001-06-02 10:47:40 +02:00
|
|
|
Stop();
|
|
|
|
Save();
|
2000-04-15 17:38:11 +02:00
|
|
|
Close();
|
2001-06-02 10:47:40 +02:00
|
|
|
dvbApi->SetModeNormal(false);
|
2000-12-28 12:57:16 +01:00
|
|
|
delete index;
|
2000-12-08 16:23:32 +01:00
|
|
|
}
|
|
|
|
|
2001-06-02 10:47:40 +02:00
|
|
|
void cReplayBuffer::Input(void)
|
2000-12-08 16:23:32 +01:00
|
|
|
{
|
2001-06-02 10:47:40 +02:00
|
|
|
dsyslog(LOG_INFO, "input thread started (pid=%d)", getpid());
|
2000-12-08 16:23:32 +01:00
|
|
|
|
2001-08-05 12:23:24 +02:00
|
|
|
readIndex = Resume();
|
|
|
|
if (readIndex >= 0)
|
|
|
|
isyslog(LOG_INFO, "resuming replay at index %d (%s)", readIndex, IndexToHMSF(readIndex, true));
|
2001-06-02 10:47:40 +02:00
|
|
|
|
|
|
|
uchar b[MAXFRAMESIZE];
|
|
|
|
while (Busy() && (blockInput || NextFile())) {
|
2001-08-05 12:23:24 +02:00
|
|
|
if (blockInput) {
|
|
|
|
if (blockInput > 1)
|
|
|
|
blockInput = 1;
|
|
|
|
continue;
|
|
|
|
}
|
2001-09-09 12:52:41 +02:00
|
|
|
if (playMode != pmStill) {
|
2001-06-02 10:47:40 +02:00
|
|
|
int r = 0;
|
2001-09-09 12:52:41 +02:00
|
|
|
if (playMode == pmFast || (playMode == pmSlow && playDir == pdBackward)) {
|
2001-06-02 10:47:40 +02:00
|
|
|
uchar FileNumber;
|
|
|
|
int FileOffset, Length;
|
2001-10-21 13:36:27 +02:00
|
|
|
int Index = index->GetNextIFrame(readIndex, playDir == pdForward, &FileNumber, &FileOffset, &Length, true);
|
2001-06-02 10:47:40 +02:00
|
|
|
if (Index >= 0) {
|
|
|
|
if (!NextFile(FileNumber, FileOffset))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else {
|
2001-10-21 13:36:27 +02:00
|
|
|
// can't call Play() here, because those functions may only be
|
|
|
|
// called from the foreground thread - and we also don't need
|
|
|
|
// to empty the buffer here
|
|
|
|
CHECK(ioctl(audioDev, AUDIO_SET_AV_SYNC, true));
|
|
|
|
CHECK(ioctl(videoDev, VIDEO_CONTINUE));
|
|
|
|
playMode = pmPlay;
|
|
|
|
playDir = pdForward;
|
2001-06-02 10:47:40 +02:00
|
|
|
continue;
|
|
|
|
}
|
2001-08-05 12:23:24 +02:00
|
|
|
readIndex = Index;
|
2001-06-15 14:12:56 +02:00
|
|
|
r = ReadFrame(replayFile, b, Length, sizeof(b));
|
2001-10-21 13:36:27 +02:00
|
|
|
// must call StripAudioPackets() here because the buffer is not emptied
|
|
|
|
// when falling back from "fast forward" to "play" (see above)
|
|
|
|
StripAudioPackets(b, r);
|
2001-06-02 10:47:40 +02:00
|
|
|
}
|
2001-07-28 11:41:51 +02:00
|
|
|
else if (index) {
|
2001-06-14 15:57:30 +02:00
|
|
|
uchar FileNumber;
|
|
|
|
int FileOffset, Length;
|
2001-08-05 12:23:24 +02:00
|
|
|
readIndex++;
|
|
|
|
if (!(index->Get(readIndex, &FileNumber, &FileOffset, NULL, &Length) && NextFile(FileNumber, FileOffset)))
|
2001-06-14 15:57:30 +02:00
|
|
|
break;
|
2001-06-15 14:12:56 +02:00
|
|
|
r = ReadFrame(replayFile, b, Length, sizeof(b));
|
2001-06-02 10:47:40 +02:00
|
|
|
}
|
2001-07-28 11:41:51 +02:00
|
|
|
else // allows replay even if the index file is missing
|
|
|
|
r = read(replayFile, b, sizeof(b));
|
2001-11-03 11:05:15 +01:00
|
|
|
if (r > 0)
|
|
|
|
putFrame(new cFrame(b, r, ftUnknown, readIndex));
|
2001-08-05 12:23:24 +02:00
|
|
|
else if (r == 0)
|
2001-06-02 10:47:40 +02:00
|
|
|
eof = true;
|
2001-08-12 15:22:48 +02:00
|
|
|
else if (r < 0 && FATALERRNO) {
|
2001-06-02 10:47:40 +02:00
|
|
|
LOG_ERROR;
|
|
|
|
break;
|
|
|
|
}
|
2000-12-08 16:23:32 +01:00
|
|
|
}
|
2001-08-05 12:23:24 +02:00
|
|
|
else//XXX
|
2001-07-14 09:24:57 +02:00
|
|
|
usleep(1); // this keeps the CPU load low
|
2000-12-28 12:57:16 +01:00
|
|
|
}
|
2000-12-08 16:23:32 +01:00
|
|
|
|
2001-06-02 10:47:40 +02:00
|
|
|
dsyslog(LOG_INFO, "input thread ended (pid=%d)", getpid());
|
|
|
|
}
|
|
|
|
|
2001-06-14 15:57:30 +02:00
|
|
|
void cReplayBuffer::StripAudioPackets(uchar *b, int Length, uchar Except)
|
2001-06-02 10:47:40 +02:00
|
|
|
{
|
2001-08-05 12:23:24 +02:00
|
|
|
if (canDoTrickMode) {
|
|
|
|
for (int i = 0; i < Length - 6; i++) {
|
|
|
|
if (b[i] == 0x00 && b[i + 1] == 0x00 && b[i + 2] == 0x01) {
|
|
|
|
uchar c = b[i + 3];
|
|
|
|
int l = b[i + 4] * 256 + b[i + 5] + 6;
|
|
|
|
switch (c) {
|
|
|
|
case 0xBD: // dolby
|
2002-03-09 12:09:57 +01:00
|
|
|
if (Except)
|
2001-11-03 11:05:15 +01:00
|
|
|
PlayExternalDolby(&b[i], Length - i);
|
2001-08-05 12:23:24 +02:00
|
|
|
// continue with deleting the data - otherwise it disturbs DVB replay
|
|
|
|
case 0xC0 ... 0xC1: // audio
|
|
|
|
if (c == 0xC1)
|
|
|
|
canToggleAudioTrack = true;
|
|
|
|
if (!Except || c != Except) {
|
|
|
|
int n = l;
|
|
|
|
for (int j = i; j < Length && n--; j++)
|
|
|
|
b[j] = 0x00;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 0xE0 ... 0xEF: // video
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
//esyslog(LOG_ERR, "ERROR: unexpected packet id %02X", c);
|
|
|
|
l = 0;
|
|
|
|
}
|
|
|
|
if (l)
|
|
|
|
i += l - 1; // the loop increments, too!
|
|
|
|
}
|
|
|
|
/*XXX
|
|
|
|
else
|
|
|
|
esyslog(LOG_ERR, "ERROR: broken packet header");
|
|
|
|
XXX*/
|
2001-06-02 10:47:40 +02:00
|
|
|
}
|
2001-08-05 12:23:24 +02:00
|
|
|
}
|
2001-06-02 10:47:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void cReplayBuffer::DisplayFrame(uchar *b, int Length)
|
|
|
|
{
|
|
|
|
StripAudioPackets(b, Length);
|
|
|
|
CHECK(ioctl(audioDev, AUDIO_SET_AV_SYNC, false));
|
|
|
|
CHECK(ioctl(audioDev, AUDIO_SET_MUTE, true));
|
2002-03-23 14:24:27 +01:00
|
|
|
/* Using the VIDEO_STILLPICTURE ioctl call would be the
|
|
|
|
correct way to display a still frame, but unfortunately this
|
|
|
|
doesn't work with frames from VDR. So let's do pretty much the
|
|
|
|
same here as in DVB/driver/dvb.c's play_iframe() - I have absolutely
|
|
|
|
no idea why it works this way, but doesn't work with VIDEO_STILLPICTURE.
|
|
|
|
If anybody ever finds out what could be changed so that VIDEO_STILLPICTURE
|
|
|
|
could be used, please let me know!
|
|
|
|
kls 2002-03-23
|
|
|
|
*/
|
|
|
|
//#define VIDEO_STILLPICTURE_WORKS_WITH_VDR_FRAMES
|
|
|
|
#ifdef VIDEO_STILLPICTURE_WORKS_WITH_VDR_FRAMES
|
|
|
|
videoDisplayStillPicture sp = { (char *)b, Length };
|
2001-06-02 10:47:40 +02:00
|
|
|
CHECK(ioctl(videoDev, VIDEO_STILLPICTURE, &sp));
|
2002-03-23 14:24:27 +01:00
|
|
|
#else
|
|
|
|
#define MIN_IFRAME 400000
|
2002-04-07 09:48:32 +02:00
|
|
|
for (int i = MIN_IFRAME / Length + 1; i > 0; i--) {
|
2002-03-23 14:24:27 +01:00
|
|
|
safe_write(videoDev, b, Length);
|
2002-04-07 09:48:32 +02:00
|
|
|
usleep(1); // allows the buffer to be displayed in case the progress display is active
|
|
|
|
}
|
2002-03-23 14:24:27 +01:00
|
|
|
#endif
|
2001-06-02 10:47:40 +02:00
|
|
|
}
|
|
|
|
|
2000-04-15 17:38:11 +02:00
|
|
|
void cReplayBuffer::Close(void)
|
2000-02-19 13:36:48 +01:00
|
|
|
{
|
2000-04-15 17:38:11 +02:00
|
|
|
if (replayFile >= 0) {
|
2000-12-28 12:57:16 +01:00
|
|
|
fileName.Close();
|
2000-04-15 17:38:11 +02:00
|
|
|
replayFile = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int cReplayBuffer::Resume(void)
|
|
|
|
{
|
|
|
|
if (index) {
|
|
|
|
int Index = index->GetResume();
|
|
|
|
if (Index >= 0) {
|
|
|
|
uchar FileNumber;
|
|
|
|
int FileOffset;
|
|
|
|
if (index->Get(Index, &FileNumber, &FileOffset) && NextFile(FileNumber, FileOffset))
|
|
|
|
return Index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool cReplayBuffer::Save(void)
|
|
|
|
{
|
|
|
|
if (index) {
|
2001-08-05 12:23:24 +02:00
|
|
|
int Index = writeIndex;
|
2000-04-15 17:38:11 +02:00
|
|
|
if (Index >= 0) {
|
|
|
|
Index -= RESUMEBACKUP;
|
2000-12-28 12:57:16 +01:00
|
|
|
if (Index > 0)
|
|
|
|
Index = index->GetNextIFrame(Index, false);
|
2000-04-15 17:38:11 +02:00
|
|
|
else
|
|
|
|
Index = 0;
|
|
|
|
if (Index >= 0)
|
|
|
|
return index->StoreResume(Index);
|
|
|
|
}
|
|
|
|
}
|
2000-02-19 13:36:48 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2000-12-28 12:57:16 +01:00
|
|
|
int cReplayBuffer::SkipFrames(int Frames)
|
|
|
|
{
|
|
|
|
if (index && Frames) {
|
|
|
|
int Current, Total;
|
|
|
|
GetIndex(Current, Total, true);
|
|
|
|
int OldCurrent = Current;
|
|
|
|
Current = index->GetNextIFrame(Current + Frames, Frames > 0);
|
|
|
|
return Current >= 0 ? Current : OldCurrent;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2000-04-15 17:38:11 +02:00
|
|
|
void cReplayBuffer::SkipSeconds(int Seconds)
|
|
|
|
{
|
|
|
|
if (index && Seconds) {
|
2001-08-05 12:23:24 +02:00
|
|
|
Empty(true);
|
|
|
|
int Index = writeIndex;
|
2000-04-15 17:38:11 +02:00
|
|
|
if (Index >= 0) {
|
2001-10-21 13:36:27 +02:00
|
|
|
Index = max(Index + Seconds * FRAMESPERSEC, 0);
|
|
|
|
if (Index > 0)
|
|
|
|
Index = index->GetNextIFrame(Index, false, NULL, NULL, NULL, true);
|
|
|
|
if (Index >= 0)
|
|
|
|
readIndex = writeIndex = Index - 1; // Input() will first increment it!
|
2000-04-15 17:38:11 +02:00
|
|
|
}
|
2001-08-05 12:23:24 +02:00
|
|
|
Empty(false);
|
2001-06-02 10:47:40 +02:00
|
|
|
Play();
|
2000-04-15 17:38:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-01-07 17:00:50 +01:00
|
|
|
void cReplayBuffer::Goto(int Index, bool Still)
|
2000-12-28 12:57:16 +01:00
|
|
|
{
|
2001-06-02 10:47:40 +02:00
|
|
|
if (index) {
|
2001-08-05 12:23:24 +02:00
|
|
|
Empty(true);
|
2001-06-02 10:47:40 +02:00
|
|
|
if (++Index <= 0)
|
|
|
|
Index = 1; // not '0', to allow GetNextIFrame() below to work!
|
|
|
|
uchar FileNumber;
|
|
|
|
int FileOffset, Length;
|
|
|
|
Index = index->GetNextIFrame(Index, false, &FileNumber, &FileOffset, &Length);
|
|
|
|
if (Index >= 0 && NextFile(FileNumber, FileOffset) && Still) {
|
|
|
|
uchar b[MAXFRAMESIZE];
|
2001-06-15 14:12:56 +02:00
|
|
|
int r = ReadFrame(replayFile, b, Length, sizeof(b));
|
2001-09-09 12:52:41 +02:00
|
|
|
if (r > 0) {
|
|
|
|
if (playMode == pmPause)
|
|
|
|
CHECK(ioctl(videoDev, VIDEO_CONTINUE));
|
2001-06-02 10:47:40 +02:00
|
|
|
DisplayFrame(b, r);
|
2001-09-09 12:52:41 +02:00
|
|
|
}
|
|
|
|
playMode = pmStill;
|
2001-06-02 10:47:40 +02:00
|
|
|
}
|
2001-08-05 12:23:24 +02:00
|
|
|
readIndex = writeIndex = Index;
|
|
|
|
Empty(false);
|
2001-06-02 10:47:40 +02:00
|
|
|
}
|
2000-12-28 12:57:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void cReplayBuffer::GetIndex(int &Current, int &Total, bool SnapToIFrame)
|
2000-04-23 15:38:16 +02:00
|
|
|
{
|
|
|
|
if (index) {
|
2001-09-09 12:52:41 +02:00
|
|
|
if (playMode == pmStill)
|
2001-10-21 13:36:27 +02:00
|
|
|
Current = max(readIndex, 0);
|
2000-12-28 12:57:16 +01:00
|
|
|
else {
|
2001-10-21 13:36:27 +02:00
|
|
|
Current = max(writeIndex, 0);
|
2000-12-28 12:57:16 +01:00
|
|
|
if (SnapToIFrame) {
|
|
|
|
int i1 = index->GetNextIFrame(Current + 1, false);
|
|
|
|
int i2 = index->GetNextIFrame(Current, true);
|
|
|
|
Current = (abs(Current - i1) <= abs(Current - i2)) ? i1 : i2;
|
|
|
|
}
|
|
|
|
}
|
2000-04-23 15:38:16 +02:00
|
|
|
Total = index->Last();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
Current = Total = -1;
|
|
|
|
}
|
|
|
|
|
2000-04-15 17:38:11 +02:00
|
|
|
bool cReplayBuffer::NextFile(uchar FileNumber, int FileOffset)
|
|
|
|
{
|
2001-08-05 12:23:24 +02:00
|
|
|
if (FileNumber > 0)
|
2000-12-28 12:57:16 +01:00
|
|
|
replayFile = fileName.SetOffset(FileNumber, FileOffset);
|
2001-06-02 10:47:40 +02:00
|
|
|
else if (replayFile >= 0 && eof) {
|
2000-04-15 17:38:11 +02:00
|
|
|
Close();
|
2000-12-28 12:57:16 +01:00
|
|
|
replayFile = fileName.NextFile();
|
2000-04-15 17:38:11 +02:00
|
|
|
}
|
2001-06-02 10:47:40 +02:00
|
|
|
eof = false;
|
2000-12-28 12:57:16 +01:00
|
|
|
return replayFile >= 0;
|
2000-02-19 13:36:48 +01:00
|
|
|
}
|
|
|
|
|
2000-11-19 16:49:14 +01:00
|
|
|
// --- cTransferBuffer -------------------------------------------------------
|
|
|
|
|
2001-08-05 12:23:24 +02:00
|
|
|
class cTransferBuffer : public cRingBufferLinear {
|
2000-11-19 16:49:14 +01:00
|
|
|
private:
|
2001-06-02 10:47:40 +02:00
|
|
|
cDvbApi *dvbApi;
|
2000-11-19 16:49:14 +01:00
|
|
|
int fromDevice, toDevice;
|
2001-06-03 13:07:20 +02:00
|
|
|
bool gotBufferReserve;
|
2001-06-02 10:47:40 +02:00
|
|
|
cRemux remux;
|
2000-11-19 16:49:14 +01:00
|
|
|
protected:
|
2001-06-02 10:47:40 +02:00
|
|
|
virtual void Input(void);
|
|
|
|
virtual void Output(void);
|
2000-11-19 16:49:14 +01:00
|
|
|
public:
|
2001-06-24 17:42:19 +02:00
|
|
|
cTransferBuffer(cDvbApi *DvbApi, int ToDevice, int VPid, int APid);
|
2000-11-19 16:49:14 +01:00
|
|
|
virtual ~cTransferBuffer();
|
2001-06-03 13:07:20 +02:00
|
|
|
void SetAudioPid(int APid);
|
2000-11-19 16:49:14 +01:00
|
|
|
};
|
|
|
|
|
2001-06-24 17:42:19 +02:00
|
|
|
cTransferBuffer::cTransferBuffer(cDvbApi *DvbApi, int ToDevice, int VPid, int APid)
|
2001-08-05 12:23:24 +02:00
|
|
|
:cRingBufferLinear(VIDEOBUFSIZE, true)
|
2001-06-24 17:42:19 +02:00
|
|
|
,remux(VPid, APid, 0, 0, 0)
|
2000-11-19 16:49:14 +01:00
|
|
|
{
|
2001-06-02 10:47:40 +02:00
|
|
|
dvbApi = DvbApi;
|
|
|
|
fromDevice = dvbApi->SetModeRecord();
|
2000-11-19 16:49:14 +01:00
|
|
|
toDevice = ToDevice;
|
2001-06-03 13:07:20 +02:00
|
|
|
gotBufferReserve = false;
|
2000-11-19 16:49:14 +01:00
|
|
|
Start();
|
|
|
|
}
|
|
|
|
|
|
|
|
cTransferBuffer::~cTransferBuffer()
|
|
|
|
{
|
2001-06-02 10:47:40 +02:00
|
|
|
Stop();
|
|
|
|
dvbApi->SetModeNormal(true);
|
2000-11-19 16:49:14 +01:00
|
|
|
}
|
|
|
|
|
2001-06-03 13:07:20 +02:00
|
|
|
void cTransferBuffer::SetAudioPid(int APid)
|
|
|
|
{
|
|
|
|
Clear();
|
|
|
|
//XXX we may need to have access to the audio device, too, in order to clear it
|
|
|
|
CHECK(ioctl(toDevice, VIDEO_CLEAR_BUFFER));
|
|
|
|
gotBufferReserve = false;
|
|
|
|
remux.SetAudioPid(APid);
|
|
|
|
}
|
|
|
|
|
2001-06-02 10:47:40 +02:00
|
|
|
void cTransferBuffer::Input(void)
|
2000-11-19 16:49:14 +01:00
|
|
|
{
|
2001-06-02 10:47:40 +02:00
|
|
|
dsyslog(LOG_INFO, "input thread started (pid=%d)", getpid());
|
2000-12-08 16:23:32 +01:00
|
|
|
|
2001-06-02 10:47:40 +02:00
|
|
|
uchar b[MINVIDEODATA];
|
|
|
|
int n = 0;
|
|
|
|
while (Busy()) {
|
2002-03-29 11:43:58 +01:00
|
|
|
if (cFile::FileReady(fromDevice, 100)) {
|
|
|
|
int r = read(fromDevice, b + n, sizeof(b) - n);
|
|
|
|
if (r > 0) {
|
|
|
|
n += r;
|
|
|
|
int Count = n, Result;
|
|
|
|
const uchar *p = remux.Process(b, Count, Result);
|
|
|
|
if (p) {
|
|
|
|
while (Result > 0 && Busy()) {
|
|
|
|
int w = Put(p, Result);
|
|
|
|
p += w;
|
|
|
|
Result -= w;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (Count > 0) {
|
|
|
|
n -= Count;
|
|
|
|
memmove(b, b + Count, n);
|
|
|
|
}
|
2001-06-02 10:47:40 +02:00
|
|
|
}
|
2002-03-29 11:43:58 +01:00
|
|
|
else if (r < 0) {
|
|
|
|
if (FATALERRNO) {
|
|
|
|
if (errno == EBUFFEROVERFLOW) // this error code is not defined in the library
|
|
|
|
esyslog(LOG_ERR, "ERROR (%s,%d): DVB driver buffer overflow", __FILE__, __LINE__);
|
|
|
|
else {
|
|
|
|
LOG_ERROR;
|
|
|
|
break;
|
|
|
|
}
|
2001-08-19 14:37:17 +02:00
|
|
|
}
|
2001-06-02 10:47:40 +02:00
|
|
|
}
|
|
|
|
}
|
2000-11-19 16:49:14 +01:00
|
|
|
}
|
2001-06-02 10:47:40 +02:00
|
|
|
|
|
|
|
dsyslog(LOG_INFO, "input thread ended (pid=%d)", getpid());
|
|
|
|
}
|
|
|
|
|
|
|
|
void cTransferBuffer::Output(void)
|
|
|
|
{
|
|
|
|
dsyslog(LOG_INFO, "output thread started (pid=%d)", getpid());
|
|
|
|
|
|
|
|
uchar b[MINVIDEODATA];
|
|
|
|
while (Busy()) {
|
2001-06-03 13:07:20 +02:00
|
|
|
if (!gotBufferReserve) {
|
2001-07-28 11:26:45 +02:00
|
|
|
if (Available() < MAXFRAMESIZE) {
|
2001-06-02 10:47:40 +02:00
|
|
|
usleep(100000); // allow the buffer to collect some reserve
|
2001-07-28 11:26:45 +02:00
|
|
|
continue;
|
|
|
|
}
|
2001-06-02 10:47:40 +02:00
|
|
|
else
|
2001-06-03 13:07:20 +02:00
|
|
|
gotBufferReserve = true;
|
2001-06-02 10:47:40 +02:00
|
|
|
}
|
|
|
|
int r = Get(b, sizeof(b));
|
|
|
|
if (r > 0) {
|
|
|
|
uchar *p = b;
|
2002-03-16 14:27:35 +01:00
|
|
|
while (r > 0 && Busy() && cFile::FileReadyForWriting(toDevice, 100)) {
|
2001-06-02 10:47:40 +02:00
|
|
|
int w = write(toDevice, p, r);
|
2001-06-09 10:32:09 +02:00
|
|
|
if (w > 0) {
|
|
|
|
p += w;
|
|
|
|
r -= w;
|
|
|
|
}
|
2001-08-12 15:22:48 +02:00
|
|
|
else if (w < 0 && FATALERRNO) {
|
2001-06-02 10:47:40 +02:00
|
|
|
LOG_ERROR;
|
|
|
|
Stop();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
usleep(1); // this keeps the CPU load low
|
2000-12-28 12:57:16 +01:00
|
|
|
}
|
2001-06-02 10:47:40 +02:00
|
|
|
|
|
|
|
dsyslog(LOG_INFO, "output thread ended (pid=%d)", getpid());
|
2000-11-19 16:49:14 +01:00
|
|
|
}
|
|
|
|
|
2000-12-28 12:57:16 +01:00
|
|
|
// --- cCuttingBuffer --------------------------------------------------------
|
|
|
|
|
2001-06-02 10:47:40 +02:00
|
|
|
class cCuttingBuffer : public cThread {
|
2000-12-28 12:57:16 +01:00
|
|
|
private:
|
2002-01-26 13:42:15 +01:00
|
|
|
const char *error;
|
2000-12-28 12:57:16 +01:00
|
|
|
bool active;
|
|
|
|
int fromFile, toFile;
|
|
|
|
cFileName *fromFileName, *toFileName;
|
|
|
|
cIndexFile *fromIndex, *toIndex;
|
|
|
|
cMarks fromMarks, toMarks;
|
|
|
|
protected:
|
|
|
|
virtual void Action(void);
|
|
|
|
public:
|
|
|
|
cCuttingBuffer(const char *FromFileName, const char *ToFileName);
|
|
|
|
virtual ~cCuttingBuffer();
|
2002-01-26 13:42:15 +01:00
|
|
|
const char *Error(void) { return error; }
|
2000-12-28 12:57:16 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
cCuttingBuffer::cCuttingBuffer(const char *FromFileName, const char *ToFileName)
|
|
|
|
{
|
2002-01-26 13:42:15 +01:00
|
|
|
error = NULL;
|
2000-12-28 12:57:16 +01:00
|
|
|
active = false;
|
|
|
|
fromFile = toFile = -1;
|
|
|
|
fromFileName = toFileName = NULL;
|
|
|
|
fromIndex = toIndex = NULL;
|
|
|
|
if (fromMarks.Load(FromFileName) && fromMarks.Count()) {
|
2001-06-02 10:47:40 +02:00
|
|
|
fromFileName = new cFileName(FromFileName, false, true);
|
|
|
|
toFileName = new cFileName(ToFileName, true, true);
|
2000-12-28 12:57:16 +01:00
|
|
|
fromIndex = new cIndexFile(FromFileName, false);
|
|
|
|
toIndex = new cIndexFile(ToFileName, true);
|
|
|
|
toMarks.Load(ToFileName); // doesn't actually load marks, just sets the file name
|
|
|
|
Start();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
esyslog(LOG_ERR, "no editing marks found for %s", FromFileName);
|
|
|
|
}
|
|
|
|
|
|
|
|
cCuttingBuffer::~cCuttingBuffer()
|
|
|
|
{
|
|
|
|
active = false;
|
|
|
|
Cancel(3);
|
|
|
|
delete fromFileName;
|
|
|
|
delete toFileName;
|
|
|
|
delete fromIndex;
|
|
|
|
delete toIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
void cCuttingBuffer::Action(void)
|
|
|
|
{
|
|
|
|
dsyslog(LOG_INFO, "video cutting thread started (pid=%d)", getpid());
|
|
|
|
|
|
|
|
cMark *Mark = fromMarks.First();
|
|
|
|
if (Mark) {
|
|
|
|
fromFile = fromFileName->Open();
|
|
|
|
toFile = toFileName->Open();
|
|
|
|
active = fromFile >= 0 && toFile >= 0;
|
|
|
|
int Index = Mark->position;
|
|
|
|
Mark = fromMarks.Next(Mark);
|
|
|
|
int FileSize = 0;
|
|
|
|
int CurrentFileNumber = 0;
|
|
|
|
int LastIFrame = 0;
|
|
|
|
toMarks.Add(0);
|
|
|
|
toMarks.Save();
|
2001-06-02 10:47:40 +02:00
|
|
|
uchar buffer[MAXFRAMESIZE];
|
2000-12-28 12:57:16 +01:00
|
|
|
while (active) {
|
|
|
|
uchar FileNumber;
|
|
|
|
int FileOffset, Length;
|
|
|
|
uchar PictureType;
|
2001-06-02 10:47:40 +02:00
|
|
|
|
2002-01-26 15:28:41 +01:00
|
|
|
// Make sure there is enough disk space:
|
|
|
|
|
|
|
|
AssertFreeDiskSpace();
|
|
|
|
|
2000-12-28 12:57:16 +01:00
|
|
|
// Read one frame:
|
2001-06-02 10:47:40 +02:00
|
|
|
|
2000-12-28 12:57:16 +01:00
|
|
|
if (fromIndex->Get(Index++, &FileNumber, &FileOffset, &PictureType, &Length)) {
|
|
|
|
if (FileNumber != CurrentFileNumber) {
|
|
|
|
fromFile = fromFileName->SetOffset(FileNumber, FileOffset);
|
|
|
|
CurrentFileNumber = FileNumber;
|
|
|
|
}
|
2001-06-02 10:47:40 +02:00
|
|
|
if (fromFile >= 0) {
|
2001-06-15 14:12:56 +02:00
|
|
|
Length = ReadFrame(fromFile, buffer, Length, sizeof(buffer));
|
2002-01-26 13:42:15 +01:00
|
|
|
if (Length < 0) {
|
|
|
|
error = "ReadFrame";
|
2001-06-02 10:47:40 +02:00
|
|
|
break;
|
2002-01-26 13:42:15 +01:00
|
|
|
}
|
2001-06-02 10:47:40 +02:00
|
|
|
}
|
2002-01-26 13:42:15 +01:00
|
|
|
else {
|
|
|
|
error = "fromFile";
|
2000-12-28 12:57:16 +01:00
|
|
|
break;
|
2002-01-26 13:42:15 +01:00
|
|
|
}
|
2000-12-28 12:57:16 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Write one frame:
|
|
|
|
|
|
|
|
if (PictureType == I_FRAME) { // every file shall start with an I_FRAME
|
2001-09-16 09:53:44 +02:00
|
|
|
if (!Mark) // edited version shall end before next I-frame
|
|
|
|
break;
|
2001-08-25 13:52:38 +02:00
|
|
|
if (FileSize > MEGABYTE(Setup.MaxVideoFileSize)) {
|
2000-12-28 12:57:16 +01:00
|
|
|
toFile = toFileName->NextFile();
|
2002-01-26 13:42:15 +01:00
|
|
|
if (toFile < 0) {
|
|
|
|
error = "toFile 1";
|
2000-12-28 12:57:16 +01:00
|
|
|
break;
|
2002-01-26 13:42:15 +01:00
|
|
|
}
|
2000-12-28 12:57:16 +01:00
|
|
|
FileSize = 0;
|
|
|
|
}
|
|
|
|
LastIFrame = 0;
|
|
|
|
}
|
2002-03-23 16:17:39 +01:00
|
|
|
if (safe_write(toFile, buffer, Length) < 0) {
|
2002-01-26 13:42:15 +01:00
|
|
|
error = "safe_write";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!toIndex->Write(PictureType, toFileName->Number(), FileSize)) {
|
|
|
|
error = "toIndex";
|
|
|
|
break;
|
|
|
|
}
|
2000-12-28 12:57:16 +01:00
|
|
|
FileSize += Length;
|
|
|
|
if (!LastIFrame)
|
|
|
|
LastIFrame = toIndex->Last();
|
|
|
|
|
|
|
|
// Check editing marks:
|
|
|
|
|
|
|
|
if (Mark && Index >= Mark->position) {
|
|
|
|
Mark = fromMarks.Next(Mark);
|
2001-09-16 09:35:51 +02:00
|
|
|
toMarks.Add(LastIFrame);
|
|
|
|
if (Mark)
|
|
|
|
toMarks.Add(toIndex->Last() + 1);
|
|
|
|
toMarks.Save();
|
2000-12-28 12:57:16 +01:00
|
|
|
if (Mark) {
|
|
|
|
Index = Mark->position;
|
|
|
|
Mark = fromMarks.Next(Mark);
|
|
|
|
CurrentFileNumber = 0; // triggers SetOffset before reading next frame
|
2001-09-30 11:31:43 +02:00
|
|
|
if (Setup.SplitEditedFiles) {
|
|
|
|
toFile = toFileName->NextFile();
|
2002-01-26 13:42:15 +01:00
|
|
|
if (toFile < 0) {
|
|
|
|
error = "toFile 2";
|
2001-09-30 11:31:43 +02:00
|
|
|
break;
|
2002-01-26 13:42:15 +01:00
|
|
|
}
|
2001-09-30 11:31:43 +02:00
|
|
|
FileSize = 0;
|
|
|
|
}
|
2000-12-28 12:57:16 +01:00
|
|
|
}
|
2001-09-16 09:53:44 +02:00
|
|
|
// the 'else' case (i.e. 'final end mark reached') is handled above
|
|
|
|
// in 'Write one frame', so that the edited version will end right
|
|
|
|
// before the next I-frame.
|
2000-12-28 12:57:16 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
esyslog(LOG_ERR, "no editing marks found!");
|
|
|
|
dsyslog(LOG_INFO, "end video cutting thread");
|
|
|
|
}
|
|
|
|
|
|
|
|
// --- cVideoCutter ----------------------------------------------------------
|
|
|
|
|
2001-09-23 14:02:11 +02:00
|
|
|
char *cVideoCutter::editedVersionName = NULL;
|
2000-12-28 12:57:16 +01:00
|
|
|
cCuttingBuffer *cVideoCutter::cuttingBuffer = NULL;
|
2002-01-26 13:42:15 +01:00
|
|
|
bool cVideoCutter::error = false;
|
|
|
|
bool cVideoCutter::ended = false;
|
2000-12-28 12:57:16 +01:00
|
|
|
|
|
|
|
bool cVideoCutter::Start(const char *FileName)
|
|
|
|
{
|
|
|
|
if (!cuttingBuffer) {
|
2002-01-26 13:42:15 +01:00
|
|
|
error = false;
|
|
|
|
ended = false;
|
2001-09-01 13:38:09 +02:00
|
|
|
cRecording Recording(FileName);
|
2001-09-23 14:02:11 +02:00
|
|
|
const char *evn = Recording.PrefixFileName('%');
|
|
|
|
if (evn && RemoveVideoFile(evn) && MakeDirs(evn, true)) {
|
2002-04-06 15:28:08 +02:00
|
|
|
// XXX this can be removed once RenameVideoFile() follows symlinks (see videodir.c)
|
|
|
|
// remove a possible deleted recording with the same name to avoid symlink mixups:
|
|
|
|
char *s = strdup(evn);
|
|
|
|
char *e = strrchr(s, '.');
|
|
|
|
if (e) {
|
|
|
|
if (strcmp(e, ".rec") == 0) {
|
|
|
|
strcpy(e, ".del");
|
|
|
|
RemoveVideoFile(s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
delete s;
|
|
|
|
// XXX
|
2001-09-23 14:02:11 +02:00
|
|
|
editedVersionName = strdup(evn);
|
2001-09-01 13:38:09 +02:00
|
|
|
Recording.WriteSummary();
|
2001-09-23 14:02:11 +02:00
|
|
|
cuttingBuffer = new cCuttingBuffer(FileName, editedVersionName);
|
2000-12-28 12:57:16 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void cVideoCutter::Stop(void)
|
|
|
|
{
|
2002-01-26 13:42:15 +01:00
|
|
|
bool Interrupted = cuttingBuffer && cuttingBuffer->Active();
|
|
|
|
const char *Error = cuttingBuffer ? cuttingBuffer->Error() : NULL;
|
2000-12-28 12:57:16 +01:00
|
|
|
delete cuttingBuffer;
|
|
|
|
cuttingBuffer = NULL;
|
2002-01-26 13:42:15 +01:00
|
|
|
if ((Interrupted || Error) && editedVersionName) {
|
|
|
|
if (Interrupted)
|
|
|
|
isyslog(LOG_INFO, "editing process has been interrupted");
|
|
|
|
if (Error)
|
|
|
|
esyslog(LOG_ERR, "ERROR: '%s' during editing process", Error);
|
|
|
|
RemoveVideoFile(editedVersionName); //XXX what if this file is currently being replayed?
|
|
|
|
}
|
2000-12-28 12:57:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool cVideoCutter::Active(void)
|
|
|
|
{
|
|
|
|
if (cuttingBuffer) {
|
|
|
|
if (cuttingBuffer->Active())
|
|
|
|
return true;
|
2002-01-26 13:42:15 +01:00
|
|
|
error = cuttingBuffer->Error();
|
2000-12-28 12:57:16 +01:00
|
|
|
Stop();
|
2002-01-26 13:42:15 +01:00
|
|
|
if (!error)
|
|
|
|
cRecordingUserCommand::InvokeCommand(RUC_EDITEDRECORDING, editedVersionName);
|
2001-09-23 14:02:11 +02:00
|
|
|
delete editedVersionName;
|
|
|
|
editedVersionName = NULL;
|
2002-01-26 13:42:15 +01:00
|
|
|
ended = true;
|
2000-12-28 12:57:16 +01:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2002-01-26 13:42:15 +01:00
|
|
|
bool cVideoCutter::Error(void)
|
|
|
|
{
|
|
|
|
bool result = error;
|
|
|
|
error = false;
|
|
|
|
return result;
|
|
|
|
}
|
2000-02-19 13:36:48 +01:00
|
|
|
|
2002-01-26 13:42:15 +01:00
|
|
|
bool cVideoCutter::Ended(void)
|
|
|
|
{
|
|
|
|
bool result = ended;
|
|
|
|
ended = false;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
// --- cDvbApi ---------------------------------------------------------------
|
2001-06-02 10:47:40 +02:00
|
|
|
|
|
|
|
static const char *OstName(const char *Name, int n)
|
|
|
|
{
|
|
|
|
static char buffer[_POSIX_PATH_MAX];
|
|
|
|
snprintf(buffer, sizeof(buffer), "%s%d", Name, n);
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int OstOpen(const char *Name, int n, int Mode, bool ReportError = false)
|
|
|
|
{
|
|
|
|
const char *FileName = OstName(Name, n);
|
|
|
|
int fd = open(FileName, Mode);
|
|
|
|
if (fd < 0 && ReportError)
|
|
|
|
LOG_ERROR_STR(FileName);
|
|
|
|
return fd;
|
|
|
|
}
|
|
|
|
|
2000-05-01 16:29:46 +02:00
|
|
|
int cDvbApi::NumDvbApis = 0;
|
2001-02-02 15:49:46 +01:00
|
|
|
int cDvbApi::useDvbApi = 0;
|
2000-05-01 16:29:46 +02:00
|
|
|
cDvbApi *cDvbApi::dvbApi[MAXDVBAPI] = { NULL };
|
|
|
|
cDvbApi *cDvbApi::PrimaryDvbApi = NULL;
|
2001-06-24 17:42:19 +02:00
|
|
|
char *cDvbApi::audioCommand = NULL;
|
2000-05-01 16:29:46 +02:00
|
|
|
|
2001-06-02 10:47:40 +02:00
|
|
|
cDvbApi::cDvbApi(int n)
|
2000-03-11 11:22:37 +01:00
|
|
|
{
|
2001-10-27 13:01:33 +02:00
|
|
|
frontendType = FrontendType(-1); // don't know how else to initialize this - there is no FE_UNKNOWN
|
2001-06-24 17:42:19 +02:00
|
|
|
vPid = aPid1 = aPid2 = dPid1 = dPid2 = 0;
|
2000-10-29 13:17:22 +01:00
|
|
|
siProcessor = NULL;
|
2000-12-08 16:23:32 +01:00
|
|
|
recordBuffer = NULL;
|
|
|
|
replayBuffer = NULL;
|
2000-11-19 16:49:14 +01:00
|
|
|
transferBuffer = NULL;
|
|
|
|
transferringFromDvbApi = NULL;
|
2002-03-03 16:12:29 +01:00
|
|
|
ca = -1;
|
2002-03-08 14:24:19 +01:00
|
|
|
priority = DEFAULTPRIORITY;
|
2001-08-10 15:18:07 +02:00
|
|
|
cardIndex = n;
|
2001-06-02 10:47:40 +02:00
|
|
|
|
|
|
|
// Devices that are only present on DVB-C or DVB-S cards:
|
|
|
|
|
2001-09-15 14:00:14 +02:00
|
|
|
fd_frontend = OstOpen(DEV_OST_FRONTEND, n, O_RDWR);
|
|
|
|
fd_sec = OstOpen(DEV_OST_SEC, n, O_RDWR);
|
2001-06-02 10:47:40 +02:00
|
|
|
|
|
|
|
// Devices that all DVB cards must have:
|
|
|
|
|
2001-06-14 15:57:30 +02:00
|
|
|
fd_demuxv = OstOpen(DEV_OST_DEMUX, n, O_RDWR | O_NONBLOCK, true);
|
|
|
|
fd_demuxa1 = OstOpen(DEV_OST_DEMUX, n, O_RDWR | O_NONBLOCK, true);
|
|
|
|
fd_demuxa2 = OstOpen(DEV_OST_DEMUX, n, O_RDWR | O_NONBLOCK, true);
|
2001-06-24 17:42:19 +02:00
|
|
|
fd_demuxd1 = OstOpen(DEV_OST_DEMUX, n, O_RDWR | O_NONBLOCK, true);
|
|
|
|
fd_demuxd2 = OstOpen(DEV_OST_DEMUX, n, O_RDWR | O_NONBLOCK, true);
|
2001-06-14 15:57:30 +02:00
|
|
|
fd_demuxt = OstOpen(DEV_OST_DEMUX, n, O_RDWR | O_NONBLOCK, true);
|
2001-06-02 10:47:40 +02:00
|
|
|
|
|
|
|
// Devices not present on "budget" cards:
|
|
|
|
|
2001-06-14 15:57:30 +02:00
|
|
|
fd_osd = OstOpen(DEV_OST_OSD, n, O_RDWR);
|
|
|
|
fd_video = OstOpen(DEV_OST_VIDEO, n, O_RDWR | O_NONBLOCK);
|
|
|
|
fd_audio = OstOpen(DEV_OST_AUDIO, n, O_RDWR | O_NONBLOCK);
|
2001-06-02 10:47:40 +02:00
|
|
|
|
|
|
|
// Devices that will be dynamically opened and closed when necessary:
|
|
|
|
|
2001-06-14 15:57:30 +02:00
|
|
|
fd_dvr = -1;
|
2001-06-02 10:47:40 +02:00
|
|
|
|
2001-06-16 14:31:14 +02:00
|
|
|
// Video format:
|
|
|
|
|
|
|
|
SetVideoFormat(Setup.VideoFormat ? VIDEO_FORMAT_16_9 : VIDEO_FORMAT_4_3);
|
|
|
|
|
2001-06-02 10:47:40 +02:00
|
|
|
// We only check the devices that must be present - the others will be checked before accessing them:
|
|
|
|
|
2001-09-15 14:00:14 +02:00
|
|
|
if (fd_frontend >= 0 && fd_demuxv >= 0 && fd_demuxa1 >= 0 && fd_demuxa2 >= 0 && fd_demuxd1 >= 0 && fd_demuxd2 >= 0 && fd_demuxt >= 0) {
|
2001-06-02 10:47:40 +02:00
|
|
|
siProcessor = new cSIProcessor(OstName(DEV_OST_DEMUX, n));
|
2001-10-27 13:01:33 +02:00
|
|
|
FrontendInfo feinfo;
|
|
|
|
CHECK(ioctl(fd_frontend, FE_GET_INFO, &feinfo));
|
|
|
|
frontendType = feinfo.type;
|
2000-10-29 13:17:22 +01:00
|
|
|
}
|
|
|
|
else
|
2001-06-02 10:47:40 +02:00
|
|
|
esyslog(LOG_ERR, "ERROR: can't open video device %d", n);
|
2000-03-11 11:22:37 +01:00
|
|
|
cols = rows = 0;
|
2000-09-17 13:47:06 +02:00
|
|
|
|
2000-07-15 12:39:20 +02:00
|
|
|
#if defined(DEBUG_OSD) || defined(REMOTE_KBD)
|
2000-03-11 11:22:37 +01:00
|
|
|
initscr();
|
2000-09-17 11:53:35 +02:00
|
|
|
keypad(stdscr, true);
|
2000-03-11 11:22:37 +01:00
|
|
|
nonl();
|
|
|
|
cbreak();
|
|
|
|
noecho();
|
2000-10-14 08:56:08 +02:00
|
|
|
timeout(10);
|
2000-04-15 17:38:11 +02:00
|
|
|
#endif
|
|
|
|
#if defined(DEBUG_OSD)
|
|
|
|
memset(&colorPairs, 0, sizeof(colorPairs));
|
|
|
|
start_color();
|
2000-09-17 11:53:35 +02:00
|
|
|
leaveok(stdscr, true);
|
2000-04-22 13:51:48 +02:00
|
|
|
window = NULL;
|
2000-10-03 10:34:48 +02:00
|
|
|
#else
|
|
|
|
osd = NULL;
|
2000-03-11 11:22:37 +01:00
|
|
|
#endif
|
2000-11-05 18:39:17 +01:00
|
|
|
currentChannel = 1;
|
2001-09-16 15:06:54 +02:00
|
|
|
mute = false;
|
2002-03-08 16:37:42 +01:00
|
|
|
volume = Setup.CurrentVolume;
|
2000-03-11 11:22:37 +01:00
|
|
|
}
|
|
|
|
|
2000-04-15 17:38:11 +02:00
|
|
|
cDvbApi::~cDvbApi()
|
2000-03-11 11:22:37 +01:00
|
|
|
{
|
2001-06-02 10:47:40 +02:00
|
|
|
delete siProcessor;
|
|
|
|
Close();
|
|
|
|
StopReplay();
|
|
|
|
StopRecord();
|
|
|
|
StopTransfer();
|
|
|
|
// We're not explicitly closing any device files here, since this sometimes
|
|
|
|
// caused segfaults. Besides, the program is about to terminate anyway...
|
2000-07-15 12:39:20 +02:00
|
|
|
#if defined(DEBUG_OSD) || defined(REMOTE_KBD)
|
2000-05-01 16:29:46 +02:00
|
|
|
endwin();
|
2000-04-15 17:38:11 +02:00
|
|
|
#endif
|
2000-03-11 11:22:37 +01:00
|
|
|
}
|
|
|
|
|
2001-02-02 15:49:46 +01:00
|
|
|
void cDvbApi::SetUseDvbApi(int n)
|
|
|
|
{
|
|
|
|
if (n < MAXDVBAPI)
|
|
|
|
useDvbApi |= (1 << n);
|
|
|
|
}
|
|
|
|
|
2000-09-10 10:51:58 +02:00
|
|
|
bool cDvbApi::SetPrimaryDvbApi(int n)
|
|
|
|
{
|
|
|
|
n--;
|
|
|
|
if (0 <= n && n < NumDvbApis && dvbApi[n]) {
|
|
|
|
isyslog(LOG_INFO, "setting primary DVB to %d", n + 1);
|
|
|
|
PrimaryDvbApi = dvbApi[n];
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
esyslog(LOG_ERR, "invalid DVB interface: %d", n + 1);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2002-04-21 10:09:56 +02:00
|
|
|
int cDvbApi::CanShift(int Ca, int Priority, int UsedCards)
|
2002-03-03 16:12:29 +01:00
|
|
|
{
|
|
|
|
// Test whether a recording on this DVB device can be shifted to another one
|
|
|
|
// in order to perform a new recording with the given Ca and Priority on this device:
|
|
|
|
int ShiftLevel = -1; // default means this device can't be shifted
|
2002-04-21 10:09:56 +02:00
|
|
|
if (UsedCards & (1 << CardIndex()) != 0)
|
|
|
|
return ShiftLevel; // otherwise we would get into a loop
|
2002-03-03 16:12:29 +01:00
|
|
|
if (Recording()) {
|
|
|
|
if (ProvidesCa(Ca) // this device provides the requested Ca
|
|
|
|
&& (Ca != this->Ca() // the requested Ca is different from the one currently used...
|
|
|
|
|| Priority > this->Priority())) { // ...or the request comes from a higher priority
|
|
|
|
cDvbApi *d = NULL;
|
|
|
|
int Provides[MAXDVBAPI];
|
2002-04-21 10:09:56 +02:00
|
|
|
UsedCards |= (1 << CardIndex());
|
2002-03-03 16:12:29 +01:00
|
|
|
for (int i = 0; i < NumDvbApis; i++) {
|
|
|
|
if ((Provides[i] = dvbApi[i]->ProvidesCa(this->Ca())) != 0) { // this device is basicly able to do the job
|
|
|
|
if (dvbApi[i] != this) { // it is not _this_ device
|
2002-04-21 10:09:56 +02:00
|
|
|
int sl = dvbApi[i]->CanShift(this->Ca(), Priority, UsedCards); // this is the original Priority!
|
2002-03-03 16:12:29 +01:00
|
|
|
if (sl >= 0 && (ShiftLevel < 0 || sl < ShiftLevel)) {
|
|
|
|
d = dvbApi[i];
|
|
|
|
ShiftLevel = sl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ShiftLevel >= 0)
|
|
|
|
ShiftLevel++; // adds the device's own shift
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (Priority > this->Priority())
|
|
|
|
ShiftLevel = 0; // no shifting necessary, this device can do the job
|
|
|
|
return ShiftLevel;
|
|
|
|
}
|
|
|
|
|
2000-11-12 14:06:53 +01:00
|
|
|
cDvbApi *cDvbApi::GetDvbApi(int Ca, int Priority)
|
2000-05-01 16:29:46 +02:00
|
|
|
{
|
2002-03-03 16:12:29 +01:00
|
|
|
cDvbApi *d = NULL;
|
|
|
|
int Provides[MAXDVBAPI];
|
|
|
|
// Check which devices provide Ca:
|
|
|
|
for (int i = 0; i < NumDvbApis; i++) {
|
|
|
|
if ((Provides[i] = dvbApi[i]->ProvidesCa(Ca)) != 0) { // this device is basicly able to do the job
|
|
|
|
if (Priority > dvbApi[i]->Priority() // Priority is high enough to use this device
|
|
|
|
&& (!d // we don't have a device yet, or...
|
|
|
|
|| dvbApi[i]->Priority() < d->Priority() // ...this one has an even lower Priority
|
|
|
|
|| (dvbApi[i]->Priority() == d->Priority() // ...same Priority...
|
|
|
|
&& Provides[i] < Provides[d->CardIndex()]))) // ...but this one provides fewer Ca values
|
2000-09-10 10:51:58 +02:00
|
|
|
d = dvbApi[i];
|
2000-05-01 16:29:46 +02:00
|
|
|
}
|
|
|
|
}
|
2002-03-03 16:12:29 +01:00
|
|
|
if (!d && Ca > MAXDVBAPI) {
|
|
|
|
// We didn't find one the easy way, so now we have to try harder:
|
|
|
|
int ShiftLevel = -1;
|
|
|
|
for (int i = 0; i < NumDvbApis; i++) {
|
|
|
|
if (Provides[i]) { // this device is basicly able to do the job, but for some reason we didn't get it above
|
|
|
|
int sl = dvbApi[i]->CanShift(Ca, Priority); // asks this device to shift its job to another device
|
|
|
|
if (sl >= 0 && (ShiftLevel < 0 || sl < ShiftLevel)) {
|
|
|
|
d = dvbApi[i]; // found one that can be shifted with the fewest number of subsequent shifts
|
|
|
|
ShiftLevel = sl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2001-02-24 14:03:39 +01:00
|
|
|
}
|
2002-03-03 16:12:29 +01:00
|
|
|
return d;
|
|
|
|
}
|
|
|
|
|
|
|
|
void cDvbApi::SetCaCaps(void)
|
|
|
|
{
|
2002-03-08 15:19:49 +01:00
|
|
|
for (int d = 0; d < NumDvbApis; d++) {
|
|
|
|
for (int i = 0; i < MAXCACAPS; i++)
|
|
|
|
dvbApi[d]->caCaps[i] = Setup.CaCaps[dvbApi[d]->CardIndex()][i];
|
|
|
|
}
|
2002-03-03 16:12:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int cDvbApi::ProvidesCa(int Ca)
|
|
|
|
{
|
|
|
|
if (Ca == CardIndex() + 1)
|
|
|
|
return 1; // exactly _this_ card was requested
|
|
|
|
if (Ca && Ca <= MAXDVBAPI)
|
|
|
|
return 0; // a specific card was requested, but not _this_ one
|
|
|
|
int result = Ca ? 0 : 1; // by default every card can provide FTA
|
|
|
|
int others = Ca ? 1 : 0;
|
|
|
|
for (int i = 0; i < MAXCACAPS; i++) {
|
|
|
|
if (caCaps[i]) {
|
|
|
|
if (caCaps[i] == Ca)
|
|
|
|
result = 1;
|
|
|
|
else
|
|
|
|
others++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result ? result + others : 0;
|
2000-05-01 16:29:46 +02:00
|
|
|
}
|
|
|
|
|
2001-06-02 10:47:40 +02:00
|
|
|
bool cDvbApi::Probe(const char *FileName)
|
|
|
|
{
|
|
|
|
if (access(FileName, F_OK) == 0) {
|
|
|
|
dsyslog(LOG_INFO, "probing %s", FileName);
|
|
|
|
int f = open(FileName, O_RDONLY);
|
|
|
|
if (f >= 0) {
|
|
|
|
close(f);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (errno != ENODEV && errno != EINVAL)
|
|
|
|
LOG_ERROR_STR(FileName);
|
|
|
|
}
|
|
|
|
else if (errno != ENOENT)
|
|
|
|
LOG_ERROR_STR(FileName);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2000-05-01 16:29:46 +02:00
|
|
|
bool cDvbApi::Init(void)
|
|
|
|
{
|
|
|
|
NumDvbApis = 0;
|
2000-10-29 13:17:22 +01:00
|
|
|
for (int i = 0; i < MAXDVBAPI; i++) {
|
2001-02-02 15:49:46 +01:00
|
|
|
if (useDvbApi == 0 || (useDvbApi & (1 << i)) != 0) {
|
2001-09-15 14:00:14 +02:00
|
|
|
if (Probe(OstName(DEV_OST_FRONTEND, i)))
|
2001-06-02 10:47:40 +02:00
|
|
|
dvbApi[NumDvbApis++] = new cDvbApi(i);
|
|
|
|
else
|
2000-05-01 16:29:46 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
PrimaryDvbApi = dvbApi[0];
|
2002-02-02 13:44:24 +01:00
|
|
|
if (NumDvbApis > 0)
|
2000-05-01 16:29:46 +02:00
|
|
|
isyslog(LOG_INFO, "found %d video device%s", NumDvbApis, NumDvbApis > 1 ? "s" : "");
|
2002-02-02 13:44:24 +01:00
|
|
|
else
|
2000-05-01 16:29:46 +02:00
|
|
|
esyslog(LOG_ERR, "ERROR: no video device found, giving up!");
|
2002-03-08 15:19:49 +01:00
|
|
|
SetCaCaps();
|
2000-05-01 16:29:46 +02:00
|
|
|
return NumDvbApis > 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void cDvbApi::Cleanup(void)
|
|
|
|
{
|
2002-03-03 16:12:29 +01:00
|
|
|
for (int i = 0; i < NumDvbApis; i++) {
|
2000-05-01 16:29:46 +02:00
|
|
|
delete dvbApi[i];
|
|
|
|
dvbApi[i] = NULL;
|
|
|
|
}
|
|
|
|
PrimaryDvbApi = NULL;
|
|
|
|
}
|
|
|
|
|
2000-09-17 11:53:35 +02:00
|
|
|
bool cDvbApi::GrabImage(const char *FileName, bool Jpeg, int Quality, int SizeX, int SizeY)
|
|
|
|
{
|
2002-02-23 10:43:42 +01:00
|
|
|
int videoDev = OstOpen(DEV_VIDEO, CardIndex(), O_RDWR, true);
|
2001-11-04 12:13:01 +01:00
|
|
|
if (videoDev >= 0) {
|
2002-02-23 10:43:42 +01:00
|
|
|
int result = 0;
|
2001-11-04 12:13:01 +01:00
|
|
|
struct video_mbuf mbuf;
|
|
|
|
result |= ioctl(videoDev, VIDIOCGMBUF, &mbuf);
|
|
|
|
if (result == 0) {
|
|
|
|
int msize = mbuf.size;
|
|
|
|
unsigned char *mem = (unsigned char *)mmap(0, msize, PROT_READ | PROT_WRITE, MAP_SHARED, videoDev, 0);
|
|
|
|
if (mem && mem != (unsigned char *)-1) {
|
|
|
|
// set up the size and RGB
|
|
|
|
struct video_capability vc;
|
|
|
|
result |= ioctl(videoDev, VIDIOCGCAP, &vc);
|
|
|
|
struct video_mmap vm;
|
|
|
|
vm.frame = 0;
|
|
|
|
if ((SizeX > 0) && (SizeX <= vc.maxwidth) &&
|
|
|
|
(SizeY > 0) && (SizeY <= vc.maxheight)) {
|
|
|
|
vm.width = SizeX;
|
|
|
|
vm.height = SizeY;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
vm.width = vc.maxwidth;
|
|
|
|
vm.height = vc.maxheight;
|
|
|
|
}
|
|
|
|
vm.format = VIDEO_PALETTE_RGB24;
|
|
|
|
result |= ioctl(videoDev, VIDIOCMCAPTURE, &vm);
|
|
|
|
result |= ioctl(videoDev, VIDIOCSYNC, &vm.frame);
|
|
|
|
// make RGB out of BGR:
|
|
|
|
int memsize = vm.width * vm.height;
|
|
|
|
unsigned char *mem1 = mem;
|
|
|
|
for (int i = 0; i < memsize; i++) {
|
|
|
|
unsigned char tmp = mem1[2];
|
|
|
|
mem1[2] = mem1[0];
|
|
|
|
mem1[0] = tmp;
|
|
|
|
mem1 += 3;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Quality < 0)
|
|
|
|
Quality = 255; //XXX is this 'best'???
|
|
|
|
|
|
|
|
isyslog(LOG_INFO, "grabbing to %s (%s %d %d %d)", FileName, Jpeg ? "JPEG" : "PNM", Quality, vm.width, vm.height);
|
|
|
|
FILE *f = fopen(FileName, "wb");
|
|
|
|
if (f) {
|
|
|
|
if (Jpeg) {
|
|
|
|
// write JPEG file:
|
|
|
|
struct jpeg_compress_struct cinfo;
|
|
|
|
struct jpeg_error_mgr jerr;
|
|
|
|
cinfo.err = jpeg_std_error(&jerr);
|
|
|
|
jpeg_create_compress(&cinfo);
|
|
|
|
jpeg_stdio_dest(&cinfo, f);
|
|
|
|
cinfo.image_width = vm.width;
|
|
|
|
cinfo.image_height = vm.height;
|
|
|
|
cinfo.input_components = 3;
|
|
|
|
cinfo.in_color_space = JCS_RGB;
|
|
|
|
|
|
|
|
jpeg_set_defaults(&cinfo);
|
|
|
|
jpeg_set_quality(&cinfo, Quality, true);
|
|
|
|
jpeg_start_compress(&cinfo, true);
|
|
|
|
|
|
|
|
int rs = vm.width * 3;
|
|
|
|
JSAMPROW rp[vm.height];
|
|
|
|
for (int k = 0; k < vm.height; k++)
|
|
|
|
rp[k] = &mem[rs * k];
|
|
|
|
jpeg_write_scanlines(&cinfo, rp, vm.height);
|
|
|
|
jpeg_finish_compress(&cinfo);
|
|
|
|
jpeg_destroy_compress(&cinfo);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// write PNM file:
|
|
|
|
if (fprintf(f, "P6\n%d\n%d\n255\n", vm.width, vm.height) < 0 ||
|
|
|
|
fwrite(mem, vm.width * vm.height * 3, 1, f) < 0) {
|
|
|
|
LOG_ERROR_STR(FileName);
|
|
|
|
result |= 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fclose(f);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
LOG_ERROR_STR(FileName);
|
|
|
|
result |= 1;
|
|
|
|
}
|
|
|
|
munmap(mem, msize);
|
2000-09-17 11:53:35 +02:00
|
|
|
}
|
2001-11-04 12:13:01 +01:00
|
|
|
else
|
|
|
|
result |= 1;
|
2000-09-17 11:53:35 +02:00
|
|
|
}
|
2001-11-04 12:13:01 +01:00
|
|
|
close(videoDev);
|
2002-02-23 10:43:42 +01:00
|
|
|
return result == 0;
|
2000-09-17 11:53:35 +02:00
|
|
|
}
|
2002-02-23 10:43:42 +01:00
|
|
|
return false;
|
2000-09-17 11:53:35 +02:00
|
|
|
}
|
|
|
|
|
2000-03-11 11:22:37 +01:00
|
|
|
#ifdef DEBUG_OSD
|
2000-04-15 17:38:11 +02:00
|
|
|
void cDvbApi::SetColor(eDvbColor colorFg, eDvbColor colorBg)
|
2000-03-11 11:22:37 +01:00
|
|
|
{
|
|
|
|
int color = (colorBg << 16) | colorFg | 0x80000000;
|
|
|
|
for (int i = 0; i < MaxColorPairs; i++) {
|
|
|
|
if (!colorPairs[i]) {
|
|
|
|
colorPairs[i] = color;
|
|
|
|
init_pair(i + 1, colorFg, colorBg);
|
|
|
|
wattrset(window, COLOR_PAIR(i + 1));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if (color == colorPairs[i]) {
|
|
|
|
wattrset(window, COLOR_PAIR(i + 1));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2000-04-23 15:38:16 +02:00
|
|
|
void cDvbApi::Open(int w, int h)
|
2000-03-11 11:22:37 +01:00
|
|
|
{
|
2001-07-27 11:51:42 +02:00
|
|
|
int d = (h < 0) ? Setup.OSDheight + h : 0;
|
2000-04-23 15:38:16 +02:00
|
|
|
h = abs(h);
|
2000-03-11 11:22:37 +01:00
|
|
|
cols = w;
|
|
|
|
rows = h;
|
|
|
|
#ifdef DEBUG_OSD
|
2001-09-14 14:06:43 +02:00
|
|
|
window = subwin(stdscr, h, w, d, (Setup.OSDwidth - w) / 2);
|
2000-09-17 11:53:35 +02:00
|
|
|
syncok(window, true);
|
2000-03-11 11:22:37 +01:00
|
|
|
#define B2C(b) (((b) * 1000) / 255)
|
|
|
|
#define SETCOLOR(n, r, g, b, o) init_color(n, B2C(r), B2C(g), B2C(b))
|
2001-07-22 12:33:45 +02:00
|
|
|
//XXX
|
2000-10-03 10:34:48 +02:00
|
|
|
SETCOLOR(clrBackground, 0x00, 0x00, 0x00, 127); // background 50% gray
|
|
|
|
SETCOLOR(clrBlack, 0x00, 0x00, 0x00, 255);
|
|
|
|
SETCOLOR(clrRed, 0xFC, 0x14, 0x14, 255);
|
|
|
|
SETCOLOR(clrGreen, 0x24, 0xFC, 0x24, 255);
|
|
|
|
SETCOLOR(clrYellow, 0xFC, 0xC0, 0x24, 255);
|
|
|
|
SETCOLOR(clrBlue, 0x00, 0x00, 0xFC, 255);
|
|
|
|
SETCOLOR(clrCyan, 0x00, 0xFC, 0xFC, 255);
|
|
|
|
SETCOLOR(clrMagenta, 0xB0, 0x00, 0xFC, 255);
|
|
|
|
SETCOLOR(clrWhite, 0xFC, 0xFC, 0xFC, 255);
|
2001-07-22 12:33:45 +02:00
|
|
|
#else
|
|
|
|
w *= charWidth;
|
|
|
|
h *= lineHeight;
|
|
|
|
d *= lineHeight;
|
2001-09-14 14:06:43 +02:00
|
|
|
int x = (720 - w + charWidth) / 2; //TODO PAL vs. NTSC???
|
2001-07-27 11:51:42 +02:00
|
|
|
int y = (576 - Setup.OSDheight * lineHeight) / 2 + d;
|
2001-07-22 12:33:45 +02:00
|
|
|
//XXX
|
|
|
|
osd = new cDvbOsd(fd_osd, x, y);
|
|
|
|
//XXX TODO this should be transferred to the places where the individual windows are requested (there's too much detailed knowledge here!)
|
2001-07-27 10:59:50 +02:00
|
|
|
if (h / lineHeight == 5) { //XXX channel display
|
2001-07-22 12:33:45 +02:00
|
|
|
osd->Create(0, 0, w, h, 4);
|
|
|
|
}
|
|
|
|
else if (h / lineHeight == 1) { //XXX info display
|
|
|
|
osd->Create(0, 0, w, h, 4);
|
|
|
|
}
|
2001-07-27 10:59:50 +02:00
|
|
|
else if (d == 0) { //XXX full menu
|
2001-07-27 11:51:42 +02:00
|
|
|
osd->Create(0, 0, w, lineHeight, 2);
|
2002-01-13 15:55:08 +01:00
|
|
|
osd->Create(0, lineHeight, w, (Setup.OSDheight - 3) * lineHeight, 2);
|
|
|
|
osd->AddColor(clrBackground);
|
|
|
|
osd->AddColor(clrCyan);
|
|
|
|
osd->AddColor(clrWhite);
|
|
|
|
osd->AddColor(clrBlack);
|
2001-07-27 11:51:42 +02:00
|
|
|
osd->Create(0, (Setup.OSDheight - 2) * lineHeight, w, 2 * lineHeight, 4);
|
2001-07-27 10:59:50 +02:00
|
|
|
}
|
2001-07-22 12:33:45 +02:00
|
|
|
else { //XXX progress display
|
|
|
|
/*XXX
|
|
|
|
osd->Create(0, 0, w, lineHeight, 1);
|
|
|
|
osd->Create(0, lineHeight, w, lineHeight, 2, false);
|
|
|
|
osd->Create(0, 2 * lineHeight, w, lineHeight, 1);
|
|
|
|
XXX*///XXX some pixels are not drawn correctly with lower bpp values
|
|
|
|
osd->Create(0, 0, w, 3*lineHeight, 4);
|
|
|
|
}
|
|
|
|
#endif
|
2000-03-11 11:22:37 +01:00
|
|
|
}
|
2000-02-19 13:36:48 +01:00
|
|
|
|
2000-04-15 17:38:11 +02:00
|
|
|
void cDvbApi::Close(void)
|
2000-02-19 13:36:48 +01:00
|
|
|
{
|
2000-05-01 16:29:46 +02:00
|
|
|
#ifdef DEBUG_OSD
|
2000-08-06 14:08:33 +02:00
|
|
|
if (window) {
|
|
|
|
delwin(window);
|
|
|
|
window = 0;
|
|
|
|
}
|
2000-05-01 16:29:46 +02:00
|
|
|
#else
|
2000-10-03 10:34:48 +02:00
|
|
|
delete osd;
|
|
|
|
osd = NULL;
|
2000-03-11 11:22:37 +01:00
|
|
|
#endif
|
2000-02-19 13:36:48 +01:00
|
|
|
}
|
|
|
|
|
2000-04-15 17:38:11 +02:00
|
|
|
void cDvbApi::Clear(void)
|
2000-02-19 13:36:48 +01:00
|
|
|
{
|
2000-03-11 11:22:37 +01:00
|
|
|
#ifdef DEBUG_OSD
|
|
|
|
SetColor(clrBackground, clrBackground);
|
|
|
|
Fill(0, 0, cols, rows, clrBackground);
|
|
|
|
#else
|
2000-10-03 10:34:48 +02:00
|
|
|
osd->Clear();
|
2000-03-11 11:22:37 +01:00
|
|
|
#endif
|
2000-02-19 13:36:48 +01:00
|
|
|
}
|
|
|
|
|
2000-04-15 17:38:11 +02:00
|
|
|
void cDvbApi::Fill(int x, int y, int w, int h, eDvbColor color)
|
2000-02-19 13:36:48 +01:00
|
|
|
{
|
2000-03-11 11:22:37 +01:00
|
|
|
if (x < 0) x = cols + x;
|
|
|
|
if (y < 0) y = rows + y;
|
|
|
|
#ifdef DEBUG_OSD
|
|
|
|
SetColor(color, color);
|
|
|
|
for (int r = 0; r < h; r++) {
|
|
|
|
wmove(window, y + r, x); // ncurses wants 'y' before 'x'!
|
|
|
|
whline(window, ' ', w);
|
|
|
|
}
|
2000-04-22 13:51:48 +02:00
|
|
|
wsyncup(window); // shouldn't be necessary because of 'syncok()', but w/o it doesn't work
|
2000-03-11 11:22:37 +01:00
|
|
|
#else
|
2000-10-03 10:34:48 +02:00
|
|
|
osd->Fill(x * charWidth, y * lineHeight, (x + w) * charWidth - 1, (y + h) * lineHeight - 1, color);
|
2000-03-11 11:22:37 +01:00
|
|
|
#endif
|
2000-02-19 13:36:48 +01:00
|
|
|
}
|
|
|
|
|
2000-12-09 11:13:00 +01:00
|
|
|
void cDvbApi::SetBitmap(int x, int y, const cBitmap &Bitmap)
|
|
|
|
{
|
|
|
|
#ifndef DEBUG_OSD
|
|
|
|
osd->SetBitmap(x, y, Bitmap);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2000-04-15 17:38:11 +02:00
|
|
|
void cDvbApi::ClrEol(int x, int y, eDvbColor color)
|
2000-02-19 13:36:48 +01:00
|
|
|
{
|
2000-03-11 11:22:37 +01:00
|
|
|
Fill(x, y, cols - x, 1, color);
|
2000-02-19 13:36:48 +01:00
|
|
|
}
|
|
|
|
|
2000-11-01 11:45:05 +01:00
|
|
|
int cDvbApi::CellWidth(void)
|
|
|
|
{
|
|
|
|
#ifdef DEBUG_OSD
|
|
|
|
return 1;
|
|
|
|
#else
|
|
|
|
return charWidth;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2000-12-09 11:13:00 +01:00
|
|
|
int cDvbApi::LineHeight(void)
|
|
|
|
{
|
|
|
|
#ifdef DEBUG_OSD
|
|
|
|
return 1;
|
|
|
|
#else
|
|
|
|
return lineHeight;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2000-11-01 11:45:05 +01:00
|
|
|
int cDvbApi::Width(unsigned char c)
|
|
|
|
{
|
|
|
|
#ifdef DEBUG_OSD
|
|
|
|
return 1;
|
|
|
|
#else
|
|
|
|
return osd->Width(c);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2000-11-05 13:04:23 +01:00
|
|
|
int cDvbApi::WidthInCells(const char *s)
|
|
|
|
{
|
|
|
|
#ifdef DEBUG_OSD
|
|
|
|
return strlen(s);
|
|
|
|
#else
|
|
|
|
return (osd->Width(s) + charWidth - 1) / charWidth;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2000-11-18 15:46:00 +01:00
|
|
|
eDvbFont cDvbApi::SetFont(eDvbFont Font)
|
|
|
|
{
|
|
|
|
#ifdef DEBUG_OSD
|
|
|
|
return Font;
|
|
|
|
#else
|
|
|
|
return osd->SetFont(Font);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2000-04-15 17:38:11 +02:00
|
|
|
void cDvbApi::Text(int x, int y, const char *s, eDvbColor colorFg, eDvbColor colorBg)
|
2000-02-19 13:36:48 +01:00
|
|
|
{
|
2000-03-11 11:22:37 +01:00
|
|
|
if (x < 0) x = cols + x;
|
|
|
|
if (y < 0) y = rows + y;
|
|
|
|
#ifdef DEBUG_OSD
|
|
|
|
SetColor(colorFg, colorBg);
|
|
|
|
wmove(window, y, x); // ncurses wants 'y' before 'x'!
|
2000-10-03 13:37:24 +02:00
|
|
|
waddnstr(window, s, cols - x);
|
2000-03-11 11:22:37 +01:00
|
|
|
#else
|
2000-10-03 10:34:48 +02:00
|
|
|
osd->Text(x * charWidth, y * lineHeight, s, colorFg, colorBg);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void cDvbApi::Flush(void)
|
|
|
|
{
|
2002-02-16 12:55:33 +01:00
|
|
|
#ifdef DEBUG_OSD
|
|
|
|
refresh();
|
|
|
|
#else
|
2000-10-03 10:34:48 +02:00
|
|
|
if (osd)
|
|
|
|
osd->Flush();
|
2000-03-11 11:22:37 +01:00
|
|
|
#endif
|
2000-02-19 13:36:48 +01:00
|
|
|
}
|
2000-04-15 17:38:11 +02:00
|
|
|
|
2002-03-03 16:12:29 +01:00
|
|
|
int cDvbApi::Priority(void)
|
|
|
|
{
|
|
|
|
return (this == PrimaryDvbApi && !Recording()) ? Setup.PrimaryLimit - 1 : priority;
|
|
|
|
}
|
|
|
|
|
2001-06-02 10:47:40 +02:00
|
|
|
int cDvbApi::SetModeRecord(void)
|
|
|
|
{
|
|
|
|
// Sets up the DVB device for recording
|
|
|
|
|
|
|
|
SetPids(true);
|
|
|
|
if (fd_dvr >= 0)
|
|
|
|
close(fd_dvr);
|
2001-08-10 15:18:07 +02:00
|
|
|
fd_dvr = OstOpen(DEV_OST_DVR, CardIndex(), O_RDONLY | O_NONBLOCK);
|
2001-06-02 10:47:40 +02:00
|
|
|
if (fd_dvr < 0)
|
|
|
|
LOG_ERROR;
|
|
|
|
return fd_dvr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void cDvbApi::SetModeReplay(void)
|
|
|
|
{
|
|
|
|
// Sets up the DVB device for replay
|
|
|
|
|
|
|
|
if (fd_video >= 0 && fd_audio >= 0) {
|
|
|
|
if (siProcessor)
|
|
|
|
siProcessor->SetStatus(false);
|
|
|
|
CHECK(ioctl(fd_video, VIDEO_SET_BLANK, true));
|
|
|
|
CHECK(ioctl(fd_audio, AUDIO_SELECT_SOURCE, AUDIO_SOURCE_MEMORY));
|
|
|
|
CHECK(ioctl(fd_audio, AUDIO_SET_AV_SYNC, true));
|
|
|
|
CHECK(ioctl(fd_audio, AUDIO_PLAY));
|
|
|
|
CHECK(ioctl(fd_video, VIDEO_SELECT_SOURCE, VIDEO_SOURCE_MEMORY));
|
|
|
|
CHECK(ioctl(fd_video, VIDEO_PLAY));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void cDvbApi::SetModeNormal(bool FromRecording)
|
|
|
|
{
|
|
|
|
// Puts the DVB device back into "normal" viewing mode (after replay or recording)
|
|
|
|
|
|
|
|
if (FromRecording) {
|
|
|
|
close(fd_dvr);
|
|
|
|
fd_dvr = -1;
|
|
|
|
SetPids(false);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (fd_video >= 0 && fd_audio >= 0) {
|
|
|
|
CHECK(ioctl(fd_video, VIDEO_STOP, true));
|
|
|
|
CHECK(ioctl(fd_audio, AUDIO_STOP, true));
|
|
|
|
CHECK(ioctl(fd_video, VIDEO_CLEAR_BUFFER));
|
|
|
|
CHECK(ioctl(fd_audio, AUDIO_CLEAR_BUFFER));
|
|
|
|
CHECK(ioctl(fd_video, VIDEO_SELECT_SOURCE, VIDEO_SOURCE_DEMUX));
|
|
|
|
CHECK(ioctl(fd_audio, AUDIO_SELECT_SOURCE, AUDIO_SOURCE_DEMUX));
|
|
|
|
CHECK(ioctl(fd_audio, AUDIO_SET_AV_SYNC, true));
|
|
|
|
CHECK(ioctl(fd_audio, AUDIO_SET_MUTE, false));
|
|
|
|
if (siProcessor)
|
|
|
|
siProcessor->SetStatus(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-06-16 14:31:14 +02:00
|
|
|
void cDvbApi::SetVideoFormat(videoFormat_t Format)
|
|
|
|
{
|
2001-10-06 15:14:41 +02:00
|
|
|
if (fd_video >= 0)
|
2001-06-16 14:31:14 +02:00
|
|
|
CHECK(ioctl(fd_video, VIDEO_SET_FORMAT, Format));
|
|
|
|
}
|
|
|
|
|
2001-06-24 17:42:19 +02:00
|
|
|
bool cDvbApi::SetPid(int fd, dmxPesType_t PesType, int Pid, dmxOutput_t Output)
|
2001-06-02 10:47:40 +02:00
|
|
|
{
|
2001-06-24 17:42:19 +02:00
|
|
|
if (Pid) {
|
2001-06-14 08:22:30 +02:00
|
|
|
CHECK(ioctl(fd, DMX_STOP));
|
2002-04-21 12:11:00 +02:00
|
|
|
if (Pid != 0x1FFF) {
|
|
|
|
dmxPesFilterParams pesFilterParams;
|
|
|
|
pesFilterParams.pid = Pid;
|
|
|
|
pesFilterParams.input = DMX_IN_FRONTEND;
|
|
|
|
pesFilterParams.output = Output;
|
|
|
|
pesFilterParams.pesType = PesType;
|
|
|
|
pesFilterParams.flags = DMX_IMMEDIATE_START;
|
|
|
|
if (ioctl(fd, DMX_SET_PES_FILTER, &pesFilterParams) < 0) {
|
2001-06-24 17:42:19 +02:00
|
|
|
LOG_ERROR;
|
2002-04-21 12:11:00 +02:00
|
|
|
return false;
|
|
|
|
}
|
2001-06-24 17:42:19 +02:00
|
|
|
}
|
2001-06-02 10:47:40 +02:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool cDvbApi::SetPids(bool ForRecording)
|
|
|
|
{
|
2001-06-24 17:42:19 +02:00
|
|
|
return SetVpid(vPid, ForRecording ? DMX_OUT_TS_TAP : DMX_OUT_DECODER) &&
|
2001-06-14 15:57:30 +02:00
|
|
|
SetApid1(aPid1, ForRecording ? DMX_OUT_TS_TAP : DMX_OUT_DECODER) &&
|
2002-02-24 11:55:24 +01:00
|
|
|
SetApid2(ForRecording ? aPid2 : 0, DMX_OUT_TS_TAP) && (!Setup.RecordDolbyDigital ||
|
2001-06-24 17:42:19 +02:00
|
|
|
SetDpid1(ForRecording ? dPid1 : 0, DMX_OUT_TS_TAP) &&
|
2002-02-24 11:55:24 +01:00
|
|
|
SetDpid2(ForRecording ? dPid2 : 0, DMX_OUT_TS_TAP));
|
2001-06-02 10:47:40 +02:00
|
|
|
}
|
|
|
|
|
2001-11-24 11:42:43 +01:00
|
|
|
eSetChannelResult cDvbApi::SetChannel(int ChannelNumber, int Frequency, char Polarization, int Diseqc, int Srate, int Vpid, int Apid1, int Apid2, int Dpid1, int Dpid2, int Tpid, int Ca, int Pnr)
|
2000-04-15 17:38:11 +02:00
|
|
|
{
|
2001-06-02 10:47:40 +02:00
|
|
|
StopTransfer();
|
|
|
|
StopReplay();
|
|
|
|
|
2001-07-29 09:24:47 +02:00
|
|
|
// Must set this anyway to avoid getting stuck when switching through
|
|
|
|
// channels with 'Up' and 'Down' keys:
|
|
|
|
currentChannel = ChannelNumber;
|
|
|
|
vPid = Vpid;
|
|
|
|
aPid1 = Apid1;
|
|
|
|
aPid2 = Apid2;
|
|
|
|
dPid1 = Dpid1;
|
|
|
|
dPid2 = Dpid2;
|
|
|
|
|
2001-06-02 10:47:40 +02:00
|
|
|
// Avoid noise while switching:
|
|
|
|
|
|
|
|
if (fd_video >= 0 && fd_audio >= 0) {
|
|
|
|
CHECK(ioctl(fd_audio, AUDIO_SET_MUTE, true));
|
|
|
|
CHECK(ioctl(fd_video, VIDEO_SET_BLANK, true));
|
|
|
|
CHECK(ioctl(fd_video, VIDEO_CLEAR_BUFFER));
|
|
|
|
CHECK(ioctl(fd_audio, AUDIO_CLEAR_BUFFER));
|
|
|
|
}
|
|
|
|
|
2002-03-10 12:45:58 +01:00
|
|
|
// Stop setting system time:
|
|
|
|
|
|
|
|
if (siProcessor)
|
|
|
|
siProcessor->SetCurrentTransponder(0);
|
|
|
|
|
2001-07-29 09:24:47 +02:00
|
|
|
// If this card can't receive this channel, we must not actually switch
|
|
|
|
// the channel here, because that would irritate the driver when we
|
|
|
|
// start replaying in Transfer Mode immediately after switching the channel:
|
2002-03-03 16:12:29 +01:00
|
|
|
bool NeedsTransferMode = (this == PrimaryDvbApi && !ProvidesCa(Ca));
|
2001-06-12 21:50:40 +02:00
|
|
|
|
2001-07-29 09:24:47 +02:00
|
|
|
if (!NeedsTransferMode) {
|
2001-06-12 21:50:40 +02:00
|
|
|
|
2001-07-29 09:24:47 +02:00
|
|
|
// Turn off current PIDs:
|
2001-06-24 17:42:19 +02:00
|
|
|
|
2001-07-29 09:24:47 +02:00
|
|
|
SetVpid( 0x1FFF, DMX_OUT_DECODER);
|
|
|
|
SetApid1(0x1FFF, DMX_OUT_DECODER);
|
|
|
|
SetApid2(0x1FFF, DMX_OUT_DECODER);
|
|
|
|
SetDpid1(0x1FFF, DMX_OUT_DECODER);
|
|
|
|
SetDpid2(0x1FFF, DMX_OUT_DECODER);
|
|
|
|
SetTpid( 0x1FFF, DMX_OUT_DECODER);
|
2001-06-02 10:47:40 +02:00
|
|
|
|
2001-11-24 11:42:43 +01:00
|
|
|
FrontendParameters Frontend;
|
2001-06-02 10:47:40 +02:00
|
|
|
|
2001-10-27 13:01:33 +02:00
|
|
|
switch (frontendType) {
|
|
|
|
case FE_QPSK: { // DVB-S
|
2001-06-02 10:47:40 +02:00
|
|
|
|
2001-10-27 13:01:33 +02:00
|
|
|
// Frequency offsets:
|
2001-06-02 10:47:40 +02:00
|
|
|
|
2001-11-24 11:42:43 +01:00
|
|
|
unsigned int freq = Frequency;
|
2001-10-27 13:01:33 +02:00
|
|
|
int tone = SEC_TONE_OFF;
|
2001-07-29 09:24:47 +02:00
|
|
|
|
2001-10-27 13:01:33 +02:00
|
|
|
if (freq < (unsigned int)Setup.LnbSLOF) {
|
|
|
|
freq -= Setup.LnbFrequLo;
|
|
|
|
tone = SEC_TONE_OFF;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
freq -= Setup.LnbFrequHi;
|
|
|
|
tone = SEC_TONE_ON;
|
|
|
|
}
|
2001-06-02 10:47:40 +02:00
|
|
|
|
2001-10-27 13:01:33 +02:00
|
|
|
Frontend.Frequency = freq * 1000UL;
|
|
|
|
Frontend.Inversion = INVERSION_AUTO;
|
|
|
|
Frontend.u.qpsk.SymbolRate = Srate * 1000UL;
|
|
|
|
Frontend.u.qpsk.FEC_inner = FEC_AUTO;
|
2001-06-02 10:47:40 +02:00
|
|
|
|
2001-10-27 13:01:33 +02:00
|
|
|
int volt = (Polarization == 'v' || Polarization == 'V') ? SEC_VOLTAGE_13 : SEC_VOLTAGE_18;
|
2001-06-02 10:47:40 +02:00
|
|
|
|
2001-10-27 13:01:33 +02:00
|
|
|
// DiseqC:
|
2001-06-02 10:47:40 +02:00
|
|
|
|
2001-10-27 13:01:33 +02:00
|
|
|
secCommand scmd;
|
|
|
|
scmd.type = 0;
|
|
|
|
scmd.u.diseqc.addr = 0x10;
|
|
|
|
scmd.u.diseqc.cmd = 0x38;
|
|
|
|
scmd.u.diseqc.numParams = 1;
|
|
|
|
scmd.u.diseqc.params[0] = 0xF0 | ((Diseqc * 4) & 0x0F) | (tone == SEC_TONE_ON ? 1 : 0) | (volt == SEC_VOLTAGE_18 ? 2 : 0);
|
2001-06-02 10:47:40 +02:00
|
|
|
|
2001-10-27 13:01:33 +02:00
|
|
|
secCmdSequence scmds;
|
|
|
|
scmds.voltage = volt;
|
|
|
|
scmds.miniCommand = SEC_MINI_NONE;
|
|
|
|
scmds.continuousTone = tone;
|
|
|
|
scmds.numCommands = Setup.DiSEqC ? 1 : 0;
|
|
|
|
scmds.commands = &scmd;
|
2001-06-02 10:47:40 +02:00
|
|
|
|
2001-10-27 13:01:33 +02:00
|
|
|
CHECK(ioctl(fd_sec, SEC_SEND_SEQUENCE, &scmds));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case FE_QAM: { // DVB-C
|
2001-06-02 10:47:40 +02:00
|
|
|
|
2001-10-27 13:01:33 +02:00
|
|
|
// Frequency and symbol rate:
|
2001-06-02 10:47:40 +02:00
|
|
|
|
2001-11-24 11:42:43 +01:00
|
|
|
Frontend.Frequency = Frequency * 1000000UL;
|
2001-10-27 13:01:33 +02:00
|
|
|
Frontend.Inversion = INVERSION_AUTO;
|
|
|
|
Frontend.u.qam.SymbolRate = Srate * 1000UL;
|
|
|
|
Frontend.u.qam.FEC_inner = FEC_AUTO;
|
|
|
|
Frontend.u.qam.QAM = QAM_64;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case FE_OFDM: { // DVB-T
|
2001-11-24 11:42:43 +01:00
|
|
|
|
|
|
|
// Frequency and OFDM paramaters:
|
|
|
|
|
|
|
|
Frontend.Frequency = Frequency * 1000UL;
|
|
|
|
Frontend.Inversion = INVERSION_AUTO;
|
|
|
|
Frontend.u.ofdm.bandWidth=BANDWIDTH_8_MHZ;
|
|
|
|
Frontend.u.ofdm.HP_CodeRate=FEC_2_3;
|
|
|
|
Frontend.u.ofdm.LP_CodeRate=FEC_1_2;
|
|
|
|
Frontend.u.ofdm.Constellation=QAM_64;
|
|
|
|
Frontend.u.ofdm.TransmissionMode=TRANSMISSION_MODE_2K;
|
|
|
|
Frontend.u.ofdm.guardInterval=GUARD_INTERVAL_1_32;
|
|
|
|
Frontend.u.ofdm.HierarchyInformation=HIERARCHY_NONE;
|
2001-10-27 13:01:33 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
esyslog(LOG_ERR, "ERROR: attempt to set channel with unknown DVB frontend type");
|
|
|
|
return scrFailed;
|
|
|
|
}
|
2001-06-02 10:47:40 +02:00
|
|
|
|
2001-11-24 11:42:43 +01:00
|
|
|
// Tuning:
|
|
|
|
|
|
|
|
CHECK(ioctl(fd_frontend, FE_SET_FRONTEND, &Frontend));
|
|
|
|
|
|
|
|
// Wait for channel sync:
|
|
|
|
|
|
|
|
if (cFile::FileReady(fd_frontend, 5000)) {
|
|
|
|
FrontendEvent event;
|
|
|
|
int res = ioctl(fd_frontend, FE_GET_EVENT, &event);
|
|
|
|
if (res >= 0) {
|
|
|
|
if (event.type != FE_COMPLETION_EV) {
|
|
|
|
esyslog(LOG_ERR, "ERROR: channel %d not sync'ed on DVB card %d!", ChannelNumber, CardIndex() + 1);
|
|
|
|
if (this == PrimaryDvbApi)
|
|
|
|
cThread::RaisePanic();
|
|
|
|
return scrFailed;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2002-01-13 15:55:08 +01:00
|
|
|
esyslog(LOG_ERR, "ERROR %d in frontend get event (channel %d, card %d)", res, ChannelNumber, CardIndex() + 1);
|
2001-07-29 09:24:47 +02:00
|
|
|
}
|
2001-11-24 11:42:43 +01:00
|
|
|
else
|
|
|
|
esyslog(LOG_ERR, "ERROR: timeout while tuning");
|
2001-06-02 10:47:40 +02:00
|
|
|
|
2001-07-29 09:24:47 +02:00
|
|
|
// PID settings:
|
2001-06-02 10:47:40 +02:00
|
|
|
|
2001-07-29 09:24:47 +02:00
|
|
|
if (!SetPids(false)) {
|
|
|
|
esyslog(LOG_ERR, "ERROR: failed to set PIDs for channel %d", ChannelNumber);
|
2001-09-08 11:44:45 +02:00
|
|
|
return scrFailed;
|
2001-07-29 09:24:47 +02:00
|
|
|
}
|
|
|
|
SetTpid(Tpid, DMX_OUT_DECODER);
|
|
|
|
if (fd_audio >= 0)
|
|
|
|
CHECK(ioctl(fd_audio, AUDIO_SET_AV_SYNC, true));
|
2001-06-02 10:47:40 +02:00
|
|
|
}
|
2001-07-29 09:24:47 +02:00
|
|
|
|
2001-06-02 10:47:40 +02:00
|
|
|
if (this == PrimaryDvbApi && siProcessor)
|
|
|
|
siProcessor->SetCurrentServiceID(Pnr);
|
2001-07-29 09:24:47 +02:00
|
|
|
|
2001-09-08 11:44:45 +02:00
|
|
|
eSetChannelResult Result = scrOk;
|
|
|
|
|
2001-06-02 10:47:40 +02:00
|
|
|
// If this DVB card can't receive this channel, let's see if we can
|
|
|
|
// use the card that actually can receive it and transfer data from there:
|
|
|
|
|
2001-07-29 09:24:47 +02:00
|
|
|
if (NeedsTransferMode) {
|
2001-06-02 10:47:40 +02:00
|
|
|
cDvbApi *CaDvbApi = GetDvbApi(Ca, 0);
|
2001-09-08 11:44:45 +02:00
|
|
|
if (CaDvbApi && !CaDvbApi->Recording()) {
|
2001-11-24 11:42:43 +01:00
|
|
|
if ((Result = CaDvbApi->SetChannel(ChannelNumber, Frequency, Polarization, Diseqc, Srate, Vpid, Apid1, Apid2, Dpid1, Dpid2, Tpid, Ca, Pnr)) == scrOk) {
|
2001-09-08 11:44:45 +02:00
|
|
|
SetModeReplay();
|
|
|
|
transferringFromDvbApi = CaDvbApi->StartTransfer(fd_video);
|
2000-11-19 16:49:14 +01:00
|
|
|
}
|
2000-10-29 13:17:22 +01:00
|
|
|
}
|
2001-09-08 11:44:45 +02:00
|
|
|
else
|
|
|
|
Result = scrNoTransfer;
|
2000-04-15 17:38:11 +02:00
|
|
|
}
|
2001-07-29 09:24:47 +02:00
|
|
|
|
2001-06-02 10:47:40 +02:00
|
|
|
if (fd_video >= 0 && fd_audio >= 0) {
|
|
|
|
CHECK(ioctl(fd_audio, AUDIO_SET_MUTE, false));
|
|
|
|
CHECK(ioctl(fd_video, VIDEO_SET_BLANK, false));
|
|
|
|
}
|
|
|
|
|
2002-03-10 12:45:58 +01:00
|
|
|
// Start setting system time:
|
|
|
|
|
|
|
|
if (Result == scrOk && siProcessor)
|
|
|
|
siProcessor->SetCurrentTransponder(Frequency);
|
|
|
|
|
2001-09-08 11:44:45 +02:00
|
|
|
return Result;
|
2000-04-15 17:38:11 +02:00
|
|
|
}
|
|
|
|
|
2000-11-19 16:49:14 +01:00
|
|
|
bool cDvbApi::Transferring(void)
|
|
|
|
{
|
|
|
|
return transferBuffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
cDvbApi *cDvbApi::StartTransfer(int TransferToVideoDev)
|
|
|
|
{
|
|
|
|
StopTransfer();
|
2001-06-03 13:07:20 +02:00
|
|
|
transferBuffer = new cTransferBuffer(this, TransferToVideoDev, vPid, aPid1);
|
2000-11-19 16:49:14 +01:00
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
void cDvbApi::StopTransfer(void)
|
|
|
|
{
|
|
|
|
if (transferBuffer) {
|
|
|
|
delete transferBuffer;
|
|
|
|
transferBuffer = NULL;
|
|
|
|
}
|
2001-01-07 17:05:35 +01:00
|
|
|
if (transferringFromDvbApi) {
|
|
|
|
transferringFromDvbApi->StopTransfer();
|
|
|
|
transferringFromDvbApi = NULL;
|
|
|
|
}
|
2000-11-19 16:49:14 +01:00
|
|
|
}
|
|
|
|
|
2000-12-28 12:57:16 +01:00
|
|
|
int cDvbApi::SecondsToFrames(int Seconds)
|
|
|
|
{
|
|
|
|
return Seconds * FRAMESPERSEC;
|
|
|
|
}
|
|
|
|
|
2000-04-15 17:38:11 +02:00
|
|
|
bool cDvbApi::Recording(void)
|
|
|
|
{
|
2000-12-08 16:23:32 +01:00
|
|
|
if (recordBuffer && !recordBuffer->Active())
|
|
|
|
StopRecord();
|
|
|
|
return recordBuffer != NULL;
|
2000-04-15 17:38:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool cDvbApi::Replaying(void)
|
|
|
|
{
|
2000-12-08 16:23:32 +01:00
|
|
|
if (replayBuffer && !replayBuffer->Active())
|
|
|
|
StopReplay();
|
|
|
|
return replayBuffer != NULL;
|
2000-04-15 17:38:11 +02:00
|
|
|
}
|
|
|
|
|
2000-11-12 14:06:53 +01:00
|
|
|
bool cDvbApi::StartRecord(const char *FileName, int Ca, int Priority)
|
2000-04-15 17:38:11 +02:00
|
|
|
{
|
|
|
|
if (Recording()) {
|
|
|
|
esyslog(LOG_ERR, "ERROR: StartRecord() called while recording - ignored!");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2001-06-02 10:47:40 +02:00
|
|
|
StopTransfer();
|
2000-11-19 16:49:14 +01:00
|
|
|
|
2001-06-02 10:47:40 +02:00
|
|
|
StopReplay(); // TODO: remove this if the driver is able to do record and replay at the same time
|
2000-05-01 16:29:46 +02:00
|
|
|
|
2001-06-02 10:47:40 +02:00
|
|
|
// Check FileName:
|
2000-04-15 17:38:11 +02:00
|
|
|
|
2001-06-02 10:47:40 +02:00
|
|
|
if (!FileName) {
|
|
|
|
esyslog(LOG_ERR, "ERROR: StartRecord: file name is (null)");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
isyslog(LOG_INFO, "record %s", FileName);
|
2000-04-15 17:38:11 +02:00
|
|
|
|
2001-06-02 10:47:40 +02:00
|
|
|
// Create directories if necessary:
|
2000-04-15 17:38:11 +02:00
|
|
|
|
2001-06-02 10:47:40 +02:00
|
|
|
if (!MakeDirs(FileName, true))
|
|
|
|
return false;
|
2000-04-15 17:38:11 +02:00
|
|
|
|
2001-08-11 11:15:41 +02:00
|
|
|
// Make sure the disk is up and running:
|
|
|
|
|
|
|
|
SpinUpDisk(FileName);
|
|
|
|
|
2001-06-02 10:47:40 +02:00
|
|
|
// Create recording buffer:
|
2000-04-15 17:38:11 +02:00
|
|
|
|
2001-06-24 17:42:19 +02:00
|
|
|
recordBuffer = new cRecordBuffer(this, FileName, vPid, aPid1, aPid2, dPid1, dPid2);
|
2000-04-15 17:38:11 +02:00
|
|
|
|
2001-06-02 10:47:40 +02:00
|
|
|
if (recordBuffer) {
|
|
|
|
ca = Ca;
|
|
|
|
priority = Priority;
|
|
|
|
return true;
|
2000-04-15 17:38:11 +02:00
|
|
|
}
|
2001-06-02 10:47:40 +02:00
|
|
|
else
|
|
|
|
esyslog(LOG_ERR, "ERROR: can't allocate recording buffer");
|
|
|
|
|
2000-04-15 17:38:11 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void cDvbApi::StopRecord(void)
|
|
|
|
{
|
2000-12-08 16:23:32 +01:00
|
|
|
if (recordBuffer) {
|
|
|
|
delete recordBuffer;
|
|
|
|
recordBuffer = NULL;
|
2002-03-03 16:12:29 +01:00
|
|
|
ca = -1;
|
2002-03-08 14:24:19 +01:00
|
|
|
priority = DEFAULTPRIORITY;
|
2000-04-15 17:38:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-12-09 11:13:00 +01:00
|
|
|
bool cDvbApi::StartReplay(const char *FileName)
|
2000-04-15 17:38:11 +02:00
|
|
|
{
|
|
|
|
if (Recording()) {
|
|
|
|
esyslog(LOG_ERR, "ERROR: StartReplay() called while recording - ignored!");
|
|
|
|
return false;
|
|
|
|
}
|
2000-11-19 16:49:14 +01:00
|
|
|
StopTransfer();
|
2000-12-08 16:23:32 +01:00
|
|
|
StopReplay();
|
2001-06-02 10:47:40 +02:00
|
|
|
if (fd_video >= 0 && fd_audio >= 0) {
|
2000-04-15 17:38:11 +02:00
|
|
|
|
|
|
|
// Check FileName:
|
|
|
|
|
|
|
|
if (!FileName) {
|
|
|
|
esyslog(LOG_ERR, "ERROR: StartReplay: file name is (null)");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
isyslog(LOG_INFO, "replay %s", FileName);
|
|
|
|
|
2000-12-08 16:23:32 +01:00
|
|
|
// Create replay buffer:
|
2000-04-15 17:38:11 +02:00
|
|
|
|
2001-06-02 10:47:40 +02:00
|
|
|
replayBuffer = new cReplayBuffer(this, fd_video, fd_audio, FileName);
|
2000-12-08 16:23:32 +01:00
|
|
|
if (replayBuffer)
|
|
|
|
return true;
|
|
|
|
else
|
|
|
|
esyslog(LOG_ERR, "ERROR: can't allocate replaying buffer");
|
2000-04-15 17:38:11 +02:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2000-12-08 16:23:32 +01:00
|
|
|
void cDvbApi::StopReplay(void)
|
2000-04-15 17:38:11 +02:00
|
|
|
{
|
2000-12-08 16:23:32 +01:00
|
|
|
if (replayBuffer) {
|
|
|
|
delete replayBuffer;
|
|
|
|
replayBuffer = NULL;
|
2001-07-29 10:34:10 +02:00
|
|
|
if (this == PrimaryDvbApi) {
|
|
|
|
// let's explicitly switch the channel back in case it was in Transfer Mode:
|
|
|
|
cChannel *Channel = Channels.GetByNumber(currentChannel);
|
2001-09-16 10:11:32 +02:00
|
|
|
if (Channel) {
|
2001-07-29 10:34:10 +02:00
|
|
|
Channel->Switch(this, false);
|
2001-09-16 10:11:32 +02:00
|
|
|
usleep(100000); // allow driver to sync in case a new replay will start immediately
|
|
|
|
}
|
2001-07-29 10:34:10 +02:00
|
|
|
}
|
2000-04-15 17:38:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-07-30 16:14:22 +02:00
|
|
|
void cDvbApi::Pause(void)
|
|
|
|
{
|
2000-12-08 16:23:32 +01:00
|
|
|
if (replayBuffer)
|
|
|
|
replayBuffer->Pause();
|
2000-07-30 16:14:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void cDvbApi::Play(void)
|
2000-04-15 17:38:11 +02:00
|
|
|
{
|
2000-12-08 16:23:32 +01:00
|
|
|
if (replayBuffer)
|
|
|
|
replayBuffer->Play();
|
2000-04-15 17:38:11 +02:00
|
|
|
}
|
|
|
|
|
2000-07-30 16:14:22 +02:00
|
|
|
void cDvbApi::Forward(void)
|
2000-04-15 17:38:11 +02:00
|
|
|
{
|
2000-12-08 16:23:32 +01:00
|
|
|
if (replayBuffer)
|
|
|
|
replayBuffer->Forward();
|
2000-04-15 17:38:11 +02:00
|
|
|
}
|
|
|
|
|
2000-07-30 16:14:22 +02:00
|
|
|
void cDvbApi::Backward(void)
|
2000-04-15 17:38:11 +02:00
|
|
|
{
|
2000-12-08 16:23:32 +01:00
|
|
|
if (replayBuffer)
|
|
|
|
replayBuffer->Backward();
|
2000-04-15 17:38:11 +02:00
|
|
|
}
|
|
|
|
|
2000-12-28 12:57:16 +01:00
|
|
|
void cDvbApi::SkipSeconds(int Seconds)
|
2000-04-15 17:38:11 +02:00
|
|
|
{
|
2000-12-08 16:23:32 +01:00
|
|
|
if (replayBuffer)
|
|
|
|
replayBuffer->SkipSeconds(Seconds);
|
2000-04-15 17:38:11 +02:00
|
|
|
}
|
|
|
|
|
2000-12-28 12:57:16 +01:00
|
|
|
int cDvbApi::SkipFrames(int Frames)
|
|
|
|
{
|
|
|
|
if (replayBuffer)
|
|
|
|
return replayBuffer->SkipFrames(Frames);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool cDvbApi::GetIndex(int &Current, int &Total, bool SnapToIFrame)
|
2000-04-23 15:38:16 +02:00
|
|
|
{
|
2000-12-08 16:23:32 +01:00
|
|
|
if (replayBuffer) {
|
2000-12-28 12:57:16 +01:00
|
|
|
replayBuffer->GetIndex(Current, Total, SnapToIFrame);
|
2000-12-08 16:23:32 +01:00
|
|
|
return true;
|
2000-04-23 15:38:16 +02:00
|
|
|
}
|
2000-04-24 15:32:11 +02:00
|
|
|
return false;
|
2000-04-23 15:38:16 +02:00
|
|
|
}
|
|
|
|
|
2001-09-14 14:06:43 +02:00
|
|
|
bool cDvbApi::GetReplayMode(bool &Play, bool &Forward, int &Speed)
|
|
|
|
{
|
|
|
|
return replayBuffer && replayBuffer->GetReplayMode(Play, Forward, Speed);
|
|
|
|
}
|
|
|
|
|
2001-01-07 17:00:50 +01:00
|
|
|
void cDvbApi::Goto(int Position, bool Still)
|
2000-12-28 12:57:16 +01:00
|
|
|
{
|
|
|
|
if (replayBuffer)
|
2001-01-07 17:00:50 +01:00
|
|
|
replayBuffer->Goto(Position, Still);
|
2000-12-28 12:57:16 +01:00
|
|
|
}
|
|
|
|
|
2001-06-14 15:57:30 +02:00
|
|
|
bool cDvbApi::CanToggleAudioTrack(void)
|
|
|
|
{
|
|
|
|
return replayBuffer ? replayBuffer->CanToggleAudioTrack() : (aPid1 && aPid2 && aPid1 != aPid2);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool cDvbApi::ToggleAudioTrack(void)
|
|
|
|
{
|
|
|
|
if (replayBuffer) {
|
|
|
|
replayBuffer->ToggleAudioTrack();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
int a = aPid2;
|
|
|
|
aPid2 = aPid1;
|
|
|
|
aPid1 = a;
|
|
|
|
if (transferringFromDvbApi)
|
|
|
|
return transferringFromDvbApi->ToggleAudioTrack();
|
|
|
|
else {
|
|
|
|
if (transferBuffer)
|
|
|
|
transferBuffer->SetAudioPid(aPid1);
|
|
|
|
return SetPids(transferBuffer != NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2002-03-09 17:11:49 +01:00
|
|
|
bool cDvbApi::ToggleMute(void)
|
2001-09-16 15:06:54 +02:00
|
|
|
{
|
|
|
|
int OldVolume = volume;
|
|
|
|
mute = !mute;
|
|
|
|
SetVolume(0, mute);
|
|
|
|
volume = OldVolume;
|
2002-03-09 17:11:49 +01:00
|
|
|
return mute;
|
2001-09-16 15:06:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void cDvbApi::SetVolume(int Volume, bool Absolute)
|
|
|
|
{
|
|
|
|
if (fd_audio >= 0) {
|
2001-09-22 13:41:49 +02:00
|
|
|
volume = min(max(Absolute ? Volume : volume + Volume, 0), MAXVOLUME);
|
2001-09-16 15:06:54 +02:00
|
|
|
audioMixer_t am;
|
|
|
|
am.volume_left = am.volume_right = volume;
|
|
|
|
CHECK(ioctl(fd_audio, AUDIO_SET_MIXER, &am));
|
2002-03-09 10:16:16 +01:00
|
|
|
if (volume > 0)
|
|
|
|
mute = false;
|
2001-09-16 15:06:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-06-24 17:42:19 +02:00
|
|
|
void cDvbApi::SetAudioCommand(const char *Command)
|
|
|
|
{
|
|
|
|
delete audioCommand;
|
|
|
|
audioCommand = strdup(Command);
|
|
|
|
}
|
|
|
|
|
2000-11-18 13:57:32 +01:00
|
|
|
// --- cEITScanner -----------------------------------------------------------
|
|
|
|
|
|
|
|
cEITScanner::cEITScanner(void)
|
|
|
|
{
|
|
|
|
lastScan = lastActivity = time(NULL);
|
|
|
|
currentChannel = 0;
|
2001-01-20 09:55:23 +01:00
|
|
|
lastChannel = 0;
|
2001-02-03 17:44:25 +01:00
|
|
|
numTransponders = 0;
|
|
|
|
transponders = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
cEITScanner::~cEITScanner()
|
|
|
|
{
|
|
|
|
delete transponders;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool cEITScanner::TransponderScanned(cChannel *Channel)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < numTransponders; i++) {
|
|
|
|
if (transponders[i] == Channel->frequency)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
transponders = (int *)realloc(transponders, ++numTransponders * sizeof(int));
|
|
|
|
transponders[numTransponders - 1] = Channel->frequency;
|
|
|
|
return false;
|
2000-11-18 13:57:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void cEITScanner::Activity(void)
|
|
|
|
{
|
|
|
|
if (currentChannel) {
|
|
|
|
Channels.SwitchTo(currentChannel);
|
|
|
|
currentChannel = 0;
|
|
|
|
}
|
|
|
|
lastActivity = time(NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
void cEITScanner::Process(void)
|
|
|
|
{
|
2001-02-24 12:18:30 +01:00
|
|
|
if (Setup.EPGScanTimeout && Channels.MaxNumber() > 1) {
|
2000-11-18 13:57:32 +01:00
|
|
|
time_t now = time(NULL);
|
|
|
|
if (now - lastScan > ScanTimeout && now - lastActivity > ActivityTimeout) {
|
2001-08-10 15:18:07 +02:00
|
|
|
for (int i = 0; i < MAXDVBAPI; i++) {
|
2002-03-03 16:12:29 +01:00
|
|
|
cDvbApi *DvbApi = cDvbApi::GetDvbApi(i + 1, MAXPRIORITY + 1);
|
2000-11-18 13:57:32 +01:00
|
|
|
if (DvbApi) {
|
|
|
|
if (DvbApi != cDvbApi::PrimaryDvbApi || (cDvbApi::NumDvbApis == 1 && Setup.EPGScanTimeout && now - lastActivity > Setup.EPGScanTimeout * 3600)) {
|
2000-11-19 16:49:14 +01:00
|
|
|
if (!(DvbApi->Recording() || DvbApi->Replaying() || DvbApi->Transferring())) {
|
2000-11-18 13:57:32 +01:00
|
|
|
int oldCh = lastChannel;
|
|
|
|
int ch = oldCh + 1;
|
|
|
|
while (ch != oldCh) {
|
2001-02-03 17:44:25 +01:00
|
|
|
if (ch > Channels.MaxNumber()) {
|
2000-11-18 13:57:32 +01:00
|
|
|
ch = 1;
|
2001-02-03 17:44:25 +01:00
|
|
|
numTransponders = 0;
|
|
|
|
}
|
2000-11-18 13:57:32 +01:00
|
|
|
cChannel *Channel = Channels.GetByNumber(ch);
|
2002-04-06 13:21:47 +02:00
|
|
|
if (Channel) {
|
|
|
|
if (Channel->ca <= MAXDVBAPI && !DvbApi->ProvidesCa(Channel->ca))
|
|
|
|
break; // the channel says it explicitly needs a different card
|
|
|
|
if (Channel->pnr && !TransponderScanned(Channel)) {
|
|
|
|
if (DvbApi == cDvbApi::PrimaryDvbApi && !currentChannel)
|
|
|
|
currentChannel = DvbApi->Channel();
|
|
|
|
Channel->Switch(DvbApi, false);
|
|
|
|
lastChannel = ch;
|
|
|
|
break;
|
|
|
|
}
|
2000-11-18 13:57:32 +01:00
|
|
|
}
|
|
|
|
ch++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
lastScan = time(NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|