2 Copyright 2004-2019 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.
25 #include "demuxerts.h"
27 #include "seriesinfo.h"
28 #include "movieinfo.h"
30 #include "recording.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();
43 Recording::~Recording()
45 if (progName) { delete[] progName; progName = NULL; }
46 if (fileName) { delete[] fileName; fileName = NULL; }
47 index = -1; // just in case
49 if (markList && markList->size())
51 for(UINT i = 0; i < markList->size(); i++)
53 delete (*markList)[i];
56 Log::getInstance()->log("Recording", Log::DEBUG, "Recording destructor, marks list deleted");
59 if (markList) delete markList;
62 ULONG Recording::getStartTime() const
67 char* Recording::getProgName() const
72 char* Recording::getFileName() const
77 void Recording::setNew(bool param)
82 void Recording::setStartTime(ULONG tstartTime)
87 void Recording::setProgName(char* tProgName)
89 if (progName) delete[] progName;
91 progName = new char[strlen(tProgName) + 1];
92 if (progName) strcpy(progName, tProgName);
95 void Recording::setFileName(char* tFileName)
97 if (fileName) delete[] fileName;
99 fileName = new char[strlen(tFileName) + 1];
100 if (fileName) strcpy(fileName, tFileName);
103 void Recording::loadRecInfo()
105 if (recInfoFor == this) return; // it already is loaded
107 if (recInfo) delete recInfo;
109 recInfo = vdr->getRecInfo(fileName);
110 Log::getInstance()->log("Recording", Log::DEBUG, "Recording has loaded recInfo %p", recInfo);
112 if (!vdr->isConnected()) Control::getInstance()->connectionLost();
114 if (movieInfo) delete movieInfo;
115 if (seriesInfo) delete seriesInfo;
121 vdr->getScraperEventType(fileName, movieID, seriesID, episodeID);
122 Log::getInstance()->log("Recording", Log::DEBUG, "Got Scraper EventType %d %d %d",
123 movieID, seriesID, episodeID);
125 if (!vdr->isConnected()) Control::getInstance()->connectionLost();
129 movieInfo = vdr->getScraperMovieInfo(movieID);
130 Log::getInstance()->log("Recording", Log::DEBUG, "Got Scraper MovieInfo ");
132 else if (seriesID != 0)
134 seriesInfo = vdr->getScraperSeriesInfo(seriesID, episodeID);
135 Log::getInstance()->log("Recording", Log::DEBUG, "Got Scraper SeriesInfo ");
139 if (!vdr->isConnected()) Control::getInstance()->connectionLost();
143 void Recording::dropRecInfo()
145 if (recInfo) delete recInfo;
148 if (movieInfo) delete movieInfo;
149 if (seriesInfo) delete seriesInfo;
155 void Recording::loadMarks()
157 markList = vdr->getMarks(fileName);
158 if (!VDR::getInstance()->isConnected()) Control::getInstance()->connectionLost();
161 bool Recording::isRadio(bool &h264)
163 ULONG lengthFrames = 0;
164 ULLONG lengthBytes = vdr->streamRecording(getFileName(), &lengthFrames, &IsPesRecording);
165 if (!lengthBytes || !lengthFrames) return false;
168 UCHAR* buffer = vdr->getBlock(0ULL, 10000U, &thisRead);
169 if (!buffer) return false;
177 bool hasVideo = false;
180 hasVideo = Demuxer::scanForVideo(buffer, thisRead, ish264);
182 hasVideo = DemuxerTS::scanForVideo(buffer, thisRead,ish264);
188 vdr->stopStreaming();
189 if (!VDR::getInstance()->isConnected()) Control::getInstance()->connectionLost();
191 Log::getInstance()->log("Recording", Log::DEBUG, "Recording has messed about and worked out radio = %u", !hasVideo);
194 if (!hasVideo) return true;
198 int Recording::getPrevMark(int currentFrame)
200 MarkList::reverse_iterator i;
201 Mark* loopMark = NULL;
203 if (!markList || !markList->size()) return 0;
205 for(i = markList->rbegin(); i != markList->rend(); i++)
208 logger->log("Recording", Log::NOTICE, "findprev:comparing Frame %i with current Frame %i",loopMark->pos,currentFrame);
210 if (loopMark->pos < currentFrame)
212 logger->log("Recording", Log::NOTICE, "findprev:setting pos %i to jumpframe_target",loopMark->pos);
213 return loopMark->pos;
221 int Recording::getNextMark(int currentFrame)
223 MarkList::iterator i;
224 Mark* loopMark = NULL;
226 if (!markList || !markList->size()) return 0;
228 for(i = markList->begin(); i != markList->end(); i++)
231 logger->log("Recording", Log::NOTICE, "findnext:comparing Frame %i with current Frame %i",loopMark->pos,currentFrame);
233 if (loopMark->pos > currentFrame)
235 logger->log("Recording", Log::NOTICE, "findnext:setting pos %i to jumpframe_target",loopMark->pos);
236 return loopMark->pos;
244 bool Recording::hasMarks()
246 return (markList && markList->size());
249 MarkList* Recording::getMarkList()
254 int Recording::resetResume()
256 return vdr->deleteRecResume(fileName);