]> git.vomp.tv Git - vompclient.git/blob - recording.cc
Compile fix for MVP re: location change of hmsf
[vompclient.git] / recording.cc
1 /*
2     Copyright 2004-2019 Chris Tallon
3
4     This file is part of VOMP.
5
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.
10
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.
15
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.
19 */
20
21 #include "recinfo.h"
22 #include "mark.h"
23 #include "log.h"
24 #include "demuxer.h"
25 #include "demuxerts.h"
26 #include "command.h"
27 #include "seriesinfo.h"
28 #include "movieinfo.h"
29
30 #include "recording.h"
31
32 Recording* Recording::recInfoFor = NULL;
33 RecInfo* Recording::recInfo = NULL;
34 MovieInfo* Recording::movieInfo = NULL;
35 SeriesInfo* Recording::seriesInfo = NULL;
36
37 Recording::Recording()
38 {
39   logger = Log::getInstance();
40   vdr = VDR::getInstance();
41
42   isNew = false;
43   start = 0;
44   progName = NULL;
45   fileName = NULL;
46   index = -1;
47   markList = NULL;
48   movieID = 0;
49   seriesID = 0;
50   episodeID = 0;
51 }
52
53 Recording::~Recording()
54 {
55   if (progName) { delete[] progName; progName = NULL; }
56   if (fileName) { delete[] fileName; fileName = NULL; }
57   index = -1; // just in case
58
59   if (markList && markList->size())
60   {
61     for(UINT i = 0; i < markList->size(); i++)
62     {
63       delete (*markList)[i];
64     }
65     markList->clear();
66     Log::getInstance()->log("Recording", Log::DEBUG, "Recording destructor, marks list deleted");
67   }
68
69   if (markList) delete markList;
70 }
71
72 ULONG Recording::getStartTime() const
73 {
74   return start;
75 }
76
77 char* Recording::getProgName() const
78 {
79   return progName;
80 }
81
82 char* Recording::getFileName() const
83 {
84   return fileName;
85 }
86
87 void Recording::setNew(bool param)
88 {
89   isNew = param;
90 }
91
92 void Recording::setStartTime(ULONG tstartTime)
93 {
94   start = tstartTime;
95 }
96
97 void Recording::setProgName(char* tProgName)
98 {
99   if (progName) delete[] progName;
100
101   progName = new char[strlen(tProgName) + 1];
102   if (progName) strcpy(progName, tProgName);
103 }
104
105 void Recording::setFileName(char* tFileName)
106 {
107   if (fileName) delete[] fileName;
108
109   fileName = new char[strlen(tFileName) + 1];
110   if (fileName) strcpy(fileName, tFileName);
111 }
112
113 void Recording::loadRecInfo()
114 {
115   if (recInfoFor == this) return; // it already is loaded
116
117   if (recInfo) delete recInfo;
118   recInfoFor = this;
119   recInfo = vdr->getRecInfo(fileName);
120   Log::getInstance()->log("Recording", Log::DEBUG, "Recording has loaded recInfo %p", recInfo);
121   
122   if (!vdr->isConnected()) Command::getInstance()->connectionLost();
123
124   if (movieInfo) delete movieInfo;
125   if (seriesInfo) delete seriesInfo;
126
127   movieInfo = NULL;
128   seriesInfo = NULL;
129   movieID = 0;
130   seriesID =0;
131   vdr->getScraperEventType(fileName, movieID, seriesID, episodeID);
132   Log::getInstance()->log("Recording", Log::DEBUG, "Got Scraper EventType %d %d %d",
133                   movieID, seriesID, episodeID);
134
135   if (!vdr->isConnected()) Command::getInstance()->connectionLost();
136
137   if (movieID != 0)
138   {
139           movieInfo = vdr->getScraperMovieInfo(movieID);
140           Log::getInstance()->log("Recording", Log::DEBUG, "Got Scraper MovieInfo ");
141   }
142   else if (seriesID != 0)
143   {
144           seriesInfo = vdr->getScraperSeriesInfo(seriesID, episodeID);
145           Log::getInstance()->log("Recording", Log::DEBUG, "Got Scraper SeriesInfo ");
146   }
147
148
149   if (!vdr->isConnected()) Command::getInstance()->connectionLost();
150
151 }
152
153 void Recording::dropRecInfo()
154 {
155   if (recInfo) delete recInfo;
156   recInfo = NULL;
157   recInfoFor = NULL;
158   if (movieInfo) delete movieInfo;
159   if (seriesInfo) delete seriesInfo;
160
161   movieInfo = NULL;
162   seriesInfo = NULL;
163 }
164
165 void Recording::loadMarks()
166 {
167   markList = vdr->getMarks(fileName);
168   if (!VDR::getInstance()->isConnected()) Command::getInstance()->connectionLost();
169 }
170
171 bool Recording::isRadio(bool &h264)
172 {
173   ULONG lengthFrames = 0;
174   ULLONG lengthBytes = vdr->streamRecording(getFileName(), &lengthFrames, &IsPesRecording);
175   if (!lengthBytes || !lengthFrames) return false;
176
177   UINT thisRead;
178   UCHAR* buffer = vdr->getBlock(0ULL, 10000U, &thisRead);
179   if (!buffer) return false;
180
181   if (!thisRead)
182   {
183     free(buffer);
184     return false;
185   }
186
187   bool hasVideo = false;
188   bool ish264=false;
189   if (IsPesRecording)
190     hasVideo = Demuxer::scanForVideo(buffer, thisRead, ish264);
191   else
192     hasVideo = DemuxerTS::scanForVideo(buffer, thisRead,ish264);
193
194   h264=ish264;
195
196   free(buffer);
197
198   vdr->stopStreaming();
199   if (!VDR::getInstance()->isConnected()) Command::getInstance()->connectionLost();
200   
201   Log::getInstance()->log("Recording", Log::DEBUG, "Recording has messed about and worked out radio = %u", !hasVideo);
202
203
204   if (!hasVideo) return true;
205   return false;
206 }
207
208 int Recording::getPrevMark(int currentFrame)
209 {
210   MarkList::reverse_iterator i;
211   Mark* loopMark = NULL;
212
213   if (!markList || !markList->size()) return 0;
214
215   for(i = markList->rbegin(); i != markList->rend(); i++)
216   {
217     loopMark = *i;
218     logger->log("Recording", Log::NOTICE, "findprev:comparing Frame %i with current Frame %i",loopMark->pos,currentFrame);
219
220     if (loopMark->pos < currentFrame)
221     {
222       logger->log("Recording", Log::NOTICE, "findprev:setting pos %i to jumpframe_target",loopMark->pos);
223       return loopMark->pos;
224     }
225   }
226
227   // No previous mark
228   return 0;
229 }
230
231 int Recording::getNextMark(int currentFrame)
232 {
233   MarkList::iterator i;
234   Mark* loopMark = NULL;
235
236   if (!markList || !markList->size()) return 0;
237
238   for(i = markList->begin(); i != markList->end(); i++)
239   {
240     loopMark = *i;
241     logger->log("Recording", Log::NOTICE, "findnext:comparing Frame %i with current Frame %i",loopMark->pos,currentFrame);
242
243     if (loopMark->pos > currentFrame)
244     {
245       logger->log("Recording", Log::NOTICE, "findnext:setting pos %i to jumpframe_target",loopMark->pos);
246       return loopMark->pos;
247     }
248   }
249
250   // No next mark
251   return 0;
252 }
253
254 bool Recording::hasMarks()
255 {
256   return (markList && markList->size());
257 }
258
259 MarkList* Recording::getMarkList()
260 {
261   return markList;
262 }
263
264 int Recording::resetResume()
265 {
266   return vdr->deleteRecResume(fileName);
267 }