diff options
Diffstat (limited to 'dvbapi.c')
-rw-r--r-- | dvbapi.c | 87 |
1 files changed, 71 insertions, 16 deletions
@@ -7,7 +7,7 @@ * DVD support initially written by Andreas Schultz <aschultz@warp10.net> * based on dvdplayer-0.5 by Matjaz Thaler <matjaz.thaler@guest.arnes.si> * - * $Id: dvbapi.c 1.141 2001/11/25 16:38:09 kls Exp $ + * $Id: dvbapi.c 1.146 2002/01/26 15:39:48 kls Exp $ */ //#define DVDDEBUG 1 @@ -116,7 +116,7 @@ public: cIndexFile(const char *FileName, bool Record); ~cIndexFile(); bool Ok(void) { return index != NULL; } - void Write(uchar PictureType, uchar FileNumber, int FileOffset); + bool Write(uchar PictureType, uchar FileNumber, int FileOffset); bool Get(int Index, uchar *FileNumber, int *FileOffset, uchar *PictureType = NULL, int *Length = NULL); int GetNextIFrame(int Index, bool Forward, uchar *FileNumber = NULL, int *FileOffset = NULL, int *Length = NULL, bool StayOffEnd = false); int Get(uchar FileNumber, int FileOffset); @@ -146,7 +146,7 @@ cIndexFile::cIndexFile(const char *FileName, bool Record) delta = buf.st_size % sizeof(tIndex); if (delta) { delta = sizeof(tIndex) - delta; - esyslog(LOG_ERR, "ERROR: invalid file size (%d) in '%s'", buf.st_size, fileName); + esyslog(LOG_ERR, "ERROR: invalid file size (%ld) in '%s'", buf.st_size, fileName); } last = (buf.st_size + delta) / sizeof(tIndex) - 1; if (!Record && last >= 0) { @@ -249,7 +249,7 @@ bool cIndexFile::CatchUp(int Index) return false; } -void cIndexFile::Write(uchar PictureType, uchar FileNumber, int FileOffset) +bool cIndexFile::Write(uchar PictureType, uchar FileNumber, int FileOffset) { if (f >= 0) { tIndex i = { FileOffset, PictureType, FileNumber, 0 }; @@ -257,10 +257,11 @@ void cIndexFile::Write(uchar PictureType, uchar FileNumber, int FileOffset) esyslog(LOG_ERR, "ERROR: can't write to index file"); close(f); f = -1; - return; + return false; } last++; } + return f >= 0; } bool cIndexFile::Get(int Index, uchar *FileNumber, int *FileOffset, uchar *PictureType, int *Length) @@ -506,7 +507,7 @@ cRecordBuffer::~cRecordBuffer() bool cRecordBuffer::RunningLowOnDiskSpace(void) { if (time(NULL) > lastDiskSpaceCheck + DISKCHECKINTERVAL) { - uint Free = FreeDiskSpaceMB(fileName.Name()); + int Free = FreeDiskSpaceMB(fileName.Name()); lastDiskSpaceCheck = time(NULL); if (Free < MINFREEDISKSPACE) { dsyslog(LOG_INFO, "low disk space (%d MB, limit is %d MB)", Free, MINFREEDISKSPACE); @@ -2305,6 +2306,7 @@ void cTransferBuffer::Output(void) class cCuttingBuffer : public cThread { private: + const char *error; bool active; int fromFile, toFile; cFileName *fromFileName, *toFileName; @@ -2315,10 +2317,12 @@ protected: public: cCuttingBuffer(const char *FromFileName, const char *ToFileName); virtual ~cCuttingBuffer(); + const char *Error(void) { return error; } }; cCuttingBuffer::cCuttingBuffer(const char *FromFileName, const char *ToFileName) { + error = NULL; active = false; fromFile = toFile = -1; fromFileName = toFileName = NULL; @@ -2367,6 +2371,10 @@ void cCuttingBuffer::Action(void) int FileOffset, Length; uchar PictureType; + // Make sure there is enough disk space: + + AssertFreeDiskSpace(); + // Read one frame: if (fromIndex->Get(Index++, &FileNumber, &FileOffset, &PictureType, &Length)) { @@ -2376,11 +2384,15 @@ void cCuttingBuffer::Action(void) } if (fromFile >= 0) { Length = ReadFrame(fromFile, buffer, Length, sizeof(buffer)); - if (Length < 0) + if (Length < 0) { + error = "ReadFrame"; break; + } } - else + else { + error = "fromFile"; break; + } } else break; @@ -2392,14 +2404,22 @@ void cCuttingBuffer::Action(void) break; if (FileSize > MEGABYTE(Setup.MaxVideoFileSize)) { toFile = toFileName->NextFile(); - if (toFile < 0) + if (toFile < 0) { + error = "toFile 1"; break; + } FileSize = 0; } LastIFrame = 0; } - safe_write(toFile, buffer, Length); - toIndex->Write(PictureType, toFileName->Number(), FileSize); + if (safe_write(toFile, buffer, Length) != Length) { + error = "safe_write"; + break; + } + if (!toIndex->Write(PictureType, toFileName->Number(), FileSize)) { + error = "toIndex"; + break; + } FileSize += Length; if (!LastIFrame) LastIFrame = toIndex->Last(); @@ -2418,8 +2438,10 @@ void cCuttingBuffer::Action(void) CurrentFileNumber = 0; // triggers SetOffset before reading next frame if (Setup.SplitEditedFiles) { toFile = toFileName->NextFile(); - if (toFile < 0) + if (toFile < 0) { + error = "toFile 2"; break; + } FileSize = 0; } } @@ -2438,10 +2460,14 @@ void cCuttingBuffer::Action(void) char *cVideoCutter::editedVersionName = NULL; cCuttingBuffer *cVideoCutter::cuttingBuffer = NULL; +bool cVideoCutter::error = false; +bool cVideoCutter::ended = false; bool cVideoCutter::Start(const char *FileName) { if (!cuttingBuffer) { + error = false; + ended = false; cRecording Recording(FileName); const char *evn = Recording.PrefixFileName('%'); if (evn && RemoveVideoFile(evn) && MakeDirs(evn, true)) { @@ -2456,8 +2482,17 @@ bool cVideoCutter::Start(const char *FileName) void cVideoCutter::Stop(void) { + bool Interrupted = cuttingBuffer && cuttingBuffer->Active(); + const char *Error = cuttingBuffer ? cuttingBuffer->Error() : NULL; delete cuttingBuffer; cuttingBuffer = NULL; + 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? + } } bool cVideoCutter::Active(void) @@ -2465,16 +2500,32 @@ bool cVideoCutter::Active(void) if (cuttingBuffer) { if (cuttingBuffer->Active()) return true; + error = cuttingBuffer->Error(); Stop(); - cRecordingUserCommand::InvokeCommand(RUC_EDITEDRECORDING, editedVersionName); + if (!error) + cRecordingUserCommand::InvokeCommand(RUC_EDITEDRECORDING, editedVersionName); delete editedVersionName; editedVersionName = NULL; + ended = true; } return false; } -// --- cDvbApi --------------------------------------------------------------- +bool cVideoCutter::Error(void) +{ + bool result = error; + error = false; + return result; +} +bool cVideoCutter::Ended(void) +{ + bool result = ended; + ended = false; + return result; +} + +// --- cDvbApi --------------------------------------------------------------- static const char *OstName(const char *Name, int n) { @@ -2842,7 +2893,11 @@ void cDvbApi::Open(int w, int h) } else if (d == 0) { //XXX full menu osd->Create(0, 0, w, lineHeight, 2); - osd->Create(0, lineHeight, w, (Setup.OSDheight - 3) * lineHeight, 2, true, clrBackground, clrCyan, clrWhite, clrBlack); + osd->Create(0, lineHeight, w, (Setup.OSDheight - 3) * lineHeight, 2); + osd->AddColor(clrBackground); + osd->AddColor(clrCyan); + osd->AddColor(clrWhite); + osd->AddColor(clrBlack); osd->Create(0, (Setup.OSDheight - 2) * lineHeight, w, 2 * lineHeight, 4); } else { //XXX progress display @@ -3197,7 +3252,7 @@ eSetChannelResult cDvbApi::SetChannel(int ChannelNumber, int Frequency, char Pol } } else - esyslog(LOG_ERR, "ERROR %d in frontend get event", res); + esyslog(LOG_ERR, "ERROR %d in frontend get event (channel %d, card %d)", res, ChannelNumber, CardIndex() + 1); } else esyslog(LOG_ERR, "ERROR: timeout while tuning"); |