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;
132 vdr->getScraperEventType(fileName, movieID, seriesID, episodeID);
133 Log::getInstance()->log("Recording", Log::DEBUG, "Got Scraper EventType %d %d %d",
134 movieID, seriesID, episodeID);
136 if (!vdr->isConnected()) Command::getInstance()->connectionLost();
140 movieInfo = vdr->getScraperMovieInfo(movieID);
141 Log::getInstance()->log("Recording", Log::DEBUG, "Got Scraper MovieInfo ");
143 else if (seriesID != 0)
145 seriesInfo = vdr->getScraperSeriesInfo(seriesID, episodeID);
146 Log::getInstance()->log("Recording", Log::DEBUG, "Got Scraper SeriesInfo ");
150 if (!vdr->isConnected()) Command::getInstance()->connectionLost();
154 void Recording::dropRecInfo()
156 if (recInfo) delete recInfo;
159 if (movieInfo) delete movieInfo;
160 if (seriesInfo) delete seriesInfo;
166 void Recording::loadMarks()
168 markList = vdr->getMarks(fileName);
169 if (!VDR::getInstance()->isConnected()) Command::getInstance()->connectionLost();
172 bool Recording::isRadio(bool &h264)
174 ULONG lengthFrames = 0;
175 ULLONG lengthBytes = vdr->streamRecording(getFileName(), &lengthFrames, &IsPesRecording);
176 if (!lengthBytes || !lengthFrames) return false;
179 UCHAR* buffer = vdr->getBlock(0ULL, 10000U, &thisRead);
180 if (!buffer) return false;
188 bool hasVideo = false;
191 hasVideo = Demuxer::scanForVideo(buffer, thisRead, ish264);
193 hasVideo = DemuxerTS::scanForVideo(buffer, thisRead,ish264);
199 vdr->stopStreaming();
200 if (!VDR::getInstance()->isConnected()) Command::getInstance()->connectionLost();
202 Log::getInstance()->log("Recording", Log::DEBUG, "Recording has messed about and worked out radio = %u", !hasVideo);
205 if (!hasVideo) return true;
209 int Recording::getPrevMark(int currentFrame)
211 MarkList::reverse_iterator i;
212 Mark* loopMark = NULL;
214 if (!markList || !markList->size()) return 0;
216 for(i = markList->rbegin(); i != markList->rend(); i++)
219 logger->log("Recording", Log::NOTICE, "findprev:comparing Frame %i with current Frame %i",loopMark->pos,currentFrame);
221 if (loopMark->pos < currentFrame)
223 logger->log("Recording", Log::NOTICE, "findprev:setting pos %i to jumpframe_target",loopMark->pos);
224 return loopMark->pos;
232 int Recording::getNextMark(int currentFrame)
234 MarkList::iterator i;
235 Mark* loopMark = NULL;
237 if (!markList || !markList->size()) return 0;
239 for(i = markList->begin(); i != markList->end(); i++)
242 logger->log("Recording", Log::NOTICE, "findnext:comparing Frame %i with current Frame %i",loopMark->pos,currentFrame);
244 if (loopMark->pos > currentFrame)
246 logger->log("Recording", Log::NOTICE, "findnext:setting pos %i to jumpframe_target",loopMark->pos);
247 return loopMark->pos;
255 bool Recording::hasMarks()
257 return (markList && markList->size());
260 MarkList* Recording::getMarkList()