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