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