2 Copyright 2004-2005 Chris Tallon
4 This file is part of VOMP.
6 VOMP is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 VOMP is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with VOMP; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 #include "recording.h"
27 #include "demuxerts.h"
29 #include "seriesinfo.h"
30 #include "movieinfo.h"
32 Recording* Recording::recInfoFor = NULL;
33 RecInfo* Recording::recInfo = NULL;
34 MovieInfo* Recording::movieInfo = NULL;
35 SeriesInfo* Recording::seriesInfo = NULL;
37 Recording::Recording()
39 logger = Log::getInstance();
40 vdr = VDR::getInstance();
53 Recording::~Recording()
55 if (progName) { delete[] progName; progName = NULL; }
56 if (fileName) { delete[] fileName; fileName = NULL; }
57 index = -1; // just in case
59 if (markList && markList->size())
61 for(UINT i = 0; i < markList->size(); i++)
63 delete (*markList)[i];
66 Log::getInstance()->log("Recording", Log::DEBUG, "Recording destructor, marks list deleted");
69 if (markList) delete markList;
72 ULONG Recording::getStartTime() const
77 char* Recording::getProgName() const
82 char* Recording::getFileName() const
87 void Recording::setNew(bool param)
92 void Recording::setStartTime(ULONG tstartTime)
97 void Recording::setProgName(char* tProgName)
99 if (progName) delete[] progName;
101 progName = new char[strlen(tProgName) + 1];
102 if (progName) strcpy(progName, tProgName);
105 void Recording::setFileName(char* tFileName)
107 if (fileName) delete[] fileName;
109 fileName = new char[strlen(tFileName) + 1];
110 if (fileName) strcpy(fileName, tFileName);
113 void Recording::loadRecInfo()
115 if (recInfoFor == this) return; // it already is loaded
117 if (recInfo) delete recInfo;
119 recInfo = vdr->getRecInfo(fileName);
120 Log::getInstance()->log("Recording", Log::DEBUG, "Recording has loaded recInfo %p", recInfo);
122 if (!vdr->isConnected()) Command::getInstance()->connectionLost();
124 if (movieInfo) delete movieInfo;
125 if (seriesInfo) delete seriesInfo;
131 vdr->getScraperEventType(fileName, movieID, seriesID, episodeID);
132 Log::getInstance()->log("Recording", Log::DEBUG, "Got Scraper EventType %d %d %d",
133 movieID, seriesID, episodeID);
135 if (!vdr->isConnected()) Command::getInstance()->connectionLost();
139 movieInfo = vdr->getScraperMovieInfo(movieID);
140 Log::getInstance()->log("Recording", Log::DEBUG, "Got Scraper MovieInfo ");
142 else if (seriesID != 0)
144 seriesInfo = vdr->getScraperSeriesInfo(seriesID, episodeID);
145 Log::getInstance()->log("Recording", Log::DEBUG, "Got Scraper SeriesInfo ");
149 if (!vdr->isConnected()) Command::getInstance()->connectionLost();
153 void Recording::dropRecInfo()
155 if (recInfo) delete recInfo;
158 if (movieInfo) delete movieInfo;
159 if (seriesInfo) delete seriesInfo;
165 void Recording::loadMarks()
167 markList = vdr->getMarks(fileName);
168 if (!VDR::getInstance()->isConnected()) Command::getInstance()->connectionLost();
171 bool Recording::isRadio(bool &h264)
173 ULONG lengthFrames = 0;
174 ULLONG lengthBytes = vdr->streamRecording(getFileName(), &lengthFrames, &IsPesRecording);
175 if (!lengthBytes || !lengthFrames) return false;
178 UCHAR* buffer = vdr->getBlock(0ULL, 10000U, &thisRead);
179 if (!buffer) return false;
187 bool hasVideo = false;
190 hasVideo = Demuxer::scanForVideo(buffer, thisRead, ish264);
192 hasVideo = DemuxerTS::scanForVideo(buffer, thisRead,ish264);
198 vdr->stopStreaming();
199 if (!VDR::getInstance()->isConnected()) Command::getInstance()->connectionLost();
201 Log::getInstance()->log("Recording", Log::DEBUG, "Recording has messed about and worked out radio = %u", !hasVideo);
204 if (!hasVideo) return true;
208 int Recording::getPrevMark(int currentFrame)
210 MarkList::reverse_iterator i;
211 Mark* loopMark = NULL;
213 if (!markList || !markList->size()) return 0;
215 for(i = markList->rbegin(); i != markList->rend(); i++)
218 logger->log("Recording", Log::NOTICE, "findprev:comparing Frame %i with current Frame %i",loopMark->pos,currentFrame);
220 if (loopMark->pos < currentFrame)
222 logger->log("Recording", Log::NOTICE, "findprev:setting pos %i to jumpframe_target",loopMark->pos);
223 return loopMark->pos;
231 int Recording::getNextMark(int currentFrame)
233 MarkList::iterator i;
234 Mark* loopMark = NULL;
236 if (!markList || !markList->size()) return 0;
238 for(i = markList->begin(); i != markList->end(); i++)
241 logger->log("Recording", Log::NOTICE, "findnext:comparing Frame %i with current Frame %i",loopMark->pos,currentFrame);
243 if (loopMark->pos > currentFrame)
245 logger->log("Recording", Log::NOTICE, "findnext:setting pos %i to jumpframe_target",loopMark->pos);
246 return loopMark->pos;
254 bool Recording::hasMarks()
256 return (markList && markList->size());
259 MarkList* Recording::getMarkList()