]> git.vomp.tv Git - vompclient.git/blob - recording.cc
Merge branch 'master' of ssh://git.vomp.tv:20022/vompclient into scraper_support
[vompclient.git] / recording.cc
1 /*
2     Copyright 2004-2005 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 "recording.h"
22
23 #include "recinfo.h"
24 #include "mark.h"
25 #include "log.h"
26 #include "demuxer.h"
27 #include "demuxerts.h"
28 #include "command.h"
29 #include "seriesinfo.h"
30 #include "movieinfo.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
130   vdr->getScraperEventType(fileName, movieID, seriesID, episodeID);
131   Log::getInstance()->log("Recording", Log::DEBUG, "Got Scraper EventType %d %d %d",
132                   movieID, seriesID, episodeID);
133
134   if (!vdr->isConnected()) Command::getInstance()->connectionLost();
135
136   if (movieID != 0)
137   {
138           movieInfo = vdr->getScraperMovieInfo(movieID);
139           Log::getInstance()->log("Recording", Log::DEBUG, "Got Scraper MovieInfo ");
140   }
141   else if (seriesID != 0)
142   {
143           seriesInfo = vdr->getScraperSeriesInfo(seriesID, episodeID);
144           Log::getInstance()->log("Recording", Log::DEBUG, "Got Scraper SeriesInfo ");
145   }
146
147
148   if (!vdr->isConnected()) Command::getInstance()->connectionLost();
149
150 }
151
152 void Recording::dropRecInfo()
153 {
154   if (recInfo) delete recInfo;
155   recInfo = NULL;
156   recInfoFor = NULL;
157   if (movieInfo) delete movieInfo;
158   if (seriesInfo) delete seriesInfo;
159
160   movieInfo = NULL;
161   seriesInfo = NULL;
162 }
163
164 void Recording::loadMarks()
165 {
166   markList = vdr->getMarks(fileName);
167   if (!VDR::getInstance()->isConnected()) Command::getInstance()->connectionLost();
168 }
169
170 bool Recording::isRadio(bool &h264)
171 {
172   ULONG lengthFrames = 0;
173   ULLONG lengthBytes = vdr->streamRecording(getFileName(), &lengthFrames, &IsPesRecording);
174   if (!lengthBytes || !lengthFrames) return false;
175
176   UINT thisRead;
177   UCHAR* buffer = vdr->getBlock(0ULL, 10000U, &thisRead);
178   if (!buffer) return false;
179
180   if (!thisRead)
181   {
182     free(buffer);
183     return false;
184   }
185
186   bool hasVideo = false;
187   bool ish264=false;
188   if (IsPesRecording)
189     hasVideo = Demuxer::scanForVideo(buffer, thisRead, ish264);
190   else
191     hasVideo = DemuxerTS::scanForVideo(buffer, thisRead,ish264);
192
193   h264=ish264;
194
195   free(buffer);
196
197   vdr->stopStreaming();
198   if (!VDR::getInstance()->isConnected()) Command::getInstance()->connectionLost();
199   
200   Log::getInstance()->log("Recording", Log::DEBUG, "Recording has messed about and worked out radio = %u", !hasVideo);
201
202
203   if (!hasVideo) return true;
204   return false;
205 }
206
207 int Recording::getPrevMark(int currentFrame)
208 {
209   MarkList::reverse_iterator i;
210   Mark* loopMark = NULL;
211
212   if (!markList || !markList->size()) return 0;
213
214   for(i = markList->rbegin(); i != markList->rend(); i++)
215   {
216     loopMark = *i;
217     logger->log("Recording", Log::NOTICE, "findprev:comparing Frame %i with current Frame %i",loopMark->pos,currentFrame);
218
219     if (loopMark->pos < currentFrame)
220     {
221       logger->log("Recording", Log::NOTICE, "findprev:setting pos %i to jumpframe_target",loopMark->pos);
222       return loopMark->pos;
223     }
224   }
225
226   // No previous mark
227   return 0;
228 }
229
230 int Recording::getNextMark(int currentFrame)
231 {
232   MarkList::iterator i;
233   Mark* loopMark = NULL;
234
235   if (!markList || !markList->size()) return 0;
236
237   for(i = markList->begin(); i != markList->end(); i++)
238   {
239     loopMark = *i;
240     logger->log("Recording", Log::NOTICE, "findnext:comparing Frame %i with current Frame %i",loopMark->pos,currentFrame);
241
242     if (loopMark->pos > currentFrame)
243     {
244       logger->log("Recording", Log::NOTICE, "findnext:setting pos %i to jumpframe_target",loopMark->pos);
245       return loopMark->pos;
246     }
247   }
248
249   // No next mark
250   return 0;
251 }
252
253 bool Recording::hasMarks()
254 {
255   return (markList && markList->size());
256 }
257
258 MarkList* Recording::getMarkList()
259 {
260   return markList;
261 }