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