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 static const char* TAG = "Recording";
34 Recording* Recording::recInfoFor = NULL;
35 RecInfo* Recording::recInfo = NULL;
36 MovieInfo* Recording::movieInfo = NULL;
37 SeriesInfo* Recording::seriesInfo = NULL;
39 Recording::Recording()
41 logger = LogNT::getInstance();
42 vdr = VDR::getInstance();
45 Recording::~Recording()
47 if (progName) { delete[] progName; progName = NULL; }
48 if (fileName) { delete[] fileName; fileName = NULL; }
49 index = -1; // just in case
51 if (markList && markList->size())
53 for(u4 i = 0; i < markList->size(); i++)
55 delete (*markList)[i];
58 logger->debug(TAG, "Recording destructor, marks list deleted");
61 if (markList) delete markList;
64 u4 Recording::getStartTime() const
69 char* Recording::getProgName() const
74 char* Recording::getFileName() const
79 void Recording::setNew(bool param)
84 void Recording::setStartTime(u4 tstartTime)
89 void Recording::setProgName(char* tProgName)
91 if (progName) delete[] progName;
93 progName = new char[strlen(tProgName) + 1];
94 if (progName) strcpy(progName, tProgName);
97 void Recording::setFileName(char* tFileName)
99 if (fileName) delete[] fileName;
101 fileName = new char[strlen(tFileName) + 1];
102 if (fileName) strcpy(fileName, tFileName);
105 void Recording::loadRecInfo()
107 if (recInfoFor == this) return; // it already is loaded
109 if (recInfo) delete recInfo;
111 recInfo = vdr->getRecInfo(fileName);
112 logger->debug(TAG, "Recording has loaded recInfo {}", static_cast<void*>(recInfo));
114 if (!vdr->isConnected()) Control::getInstance()->connectionLost();
116 if (movieInfo) delete movieInfo;
117 if (seriesInfo) delete seriesInfo;
123 vdr->getScraperEventType(fileName, movieID, seriesID, episodeID);
124 logger->debug(TAG, "Got Scraper EventType {} {} {}",
125 movieID, seriesID, episodeID);
127 if (!vdr->isConnected()) Control::getInstance()->connectionLost();
131 movieInfo = vdr->getScraperMovieInfo(movieID);
132 logger->debug(TAG, "Got Scraper MovieInfo");
134 else if (seriesID != 0)
136 seriesInfo = vdr->getScraperSeriesInfo(seriesID, episodeID);
137 logger->debug(TAG, "Got Scraper SeriesInfo");
141 if (!vdr->isConnected()) Control::getInstance()->connectionLost();
145 void Recording::dropRecInfo()
147 if (recInfo) delete recInfo;
150 if (movieInfo) delete movieInfo;
151 if (seriesInfo) delete seriesInfo;
157 void Recording::loadMarks()
159 markList = vdr->getMarks(fileName);
160 if (!VDR::getInstance()->isConnected()) Control::getInstance()->connectionLost();
163 bool Recording::isRadio(bool &h264)
166 u8 lengthBytes = vdr->streamRecording(getFileName(), &lengthFrames, &IsPesRecording);
167 if (!lengthBytes || !lengthFrames) return false;
170 u1* buffer = vdr->getBlock(0ULL, 10000U, &thisRead);
171 if (!buffer) return false;
179 bool hasVideo = false;
182 hasVideo = Demuxer::scanForVideo(buffer, thisRead, ish264);
184 hasVideo = DemuxerTS::scanForVideo(buffer, thisRead,ish264);
190 vdr->stopStreaming();
191 if (!VDR::getInstance()->isConnected()) Control::getInstance()->connectionLost();
193 logger->debug(TAG, "Recording has messed about and worked out radio = {}", !hasVideo);
196 if (!hasVideo) return true;
200 int Recording::getPrevMark(int currentFrame)
202 MarkList::reverse_iterator i;
203 Mark* loopMark = NULL;
205 if (!markList || !markList->size()) return 0;
207 for(i = markList->rbegin(); i != markList->rend(); i++)
210 logger->info(TAG, "findprev:comparing Frame {} with current Frame {}",loopMark->pos,currentFrame);
212 if (loopMark->pos < currentFrame)
214 logger->info(TAG, "findprev:setting pos {} to jumpframe_target",loopMark->pos);
215 return loopMark->pos;
223 int Recording::getNextMark(int currentFrame)
225 MarkList::iterator i;
226 Mark* loopMark = NULL;
228 if (!markList || !markList->size()) return 0;
230 for(i = markList->begin(); i != markList->end(); i++)
233 logger->info(TAG, "findnext:comparing Frame {} with current Frame {}",loopMark->pos,currentFrame);
235 if (loopMark->pos > currentFrame)
237 logger->info(TAG, "findnext:setting pos {} to jumpframe_target",loopMark->pos);
238 return loopMark->pos;
246 bool Recording::hasMarks()
248 return (markList && markList->size());
251 MarkList* Recording::getMarkList()
256 int Recording::resetResume()
258 return vdr->deleteRecResume(fileName);