]> git.vomp.tv Git - vompclient.git/blob - recording.cc
VDR 1.7.7 compatibility
[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   start = 0;
39   progName = NULL;
40   fileName = NULL;
41   index = -1;
42   markList = NULL;
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     Log::getInstance()->log("Recording", Log::DEBUG, "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::setStartTime(ULONG tstartTime)
80 {
81   start = tstartTime;
82 }
83
84 void Recording::setProgName(char* tProgName)
85 {
86   if (progName) delete[] progName;
87
88   progName = new char[strlen(tProgName) + 1];
89   if (progName) strcpy(progName, tProgName);
90 }
91
92 void Recording::setFileName(char* tFileName)
93 {
94   if (fileName) delete[] fileName;
95
96   fileName = new char[strlen(tFileName) + 1];
97   if (fileName) strcpy(fileName, tFileName);
98 }
99
100 void Recording::loadRecInfo()
101 {
102   if (recInfoFor == this) return; // it already is loaded
103
104   if (recInfo) delete recInfo;
105   recInfoFor = this;
106   recInfo = vdr->getRecInfo(fileName);
107   Log::getInstance()->log("Recording", Log::DEBUG, "Recording has loaded recInfo %p", recInfo);
108   
109   if (!VDR::getInstance()->isConnected()) Command::getInstance()->connectionLost();
110 }
111
112 void Recording::dropRecInfo()
113 {
114   if (recInfo) delete recInfo;
115   recInfo = NULL;
116   recInfoFor = NULL;
117 }
118
119 void Recording::loadMarks()
120 {
121   markList = vdr->getMarks(fileName);
122   if (!VDR::getInstance()->isConnected()) Command::getInstance()->connectionLost();
123 }
124
125 bool Recording::isRadio()
126 {
127   ULONG lengthFrames = 0;
128   ULLONG lengthBytes = vdr->streamRecording(getFileName(), &lengthFrames, &IsPesRecording);
129   if (!lengthBytes || !lengthFrames) return false;
130
131   UINT thisRead;
132   UCHAR* buffer = vdr->getBlock(0ULL, 10000U, &thisRead);
133   if (!buffer) return false;
134
135   if (!thisRead)
136   {
137     free(buffer);
138     return false;
139   }
140
141   bool hasVideo = false;
142   if (IsPesRecording)
143     hasVideo = Demuxer::scanForVideo(buffer, thisRead);
144   else
145     hasVideo = DemuxerTS::scanForVideo(buffer, thisRead);
146
147   free(buffer);
148
149   vdr->stopStreaming();
150   if (!VDR::getInstance()->isConnected()) Command::getInstance()->connectionLost();
151   
152   Log::getInstance()->log("Recording", Log::DEBUG, "Recording has messed about and worked out radio = %u", !hasVideo);
153
154
155   if (!hasVideo) return true;
156   return false;
157 }
158
159 int Recording::getPrevMark(int currentFrame)
160 {
161   MarkList::reverse_iterator i;
162   Mark* loopMark = NULL;
163
164   if (!markList || !markList->size()) return 0;
165
166   for(i = markList->rbegin(); i != markList->rend(); i++)
167   {
168     loopMark = *i;
169     logger->log("Recording", Log::NOTICE, "findprev:comparing Frame %i with current Frame %i",loopMark->pos,currentFrame);
170
171     if (loopMark->pos < currentFrame)
172     {
173       logger->log("Recording", Log::NOTICE, "findprev:setting pos %i to jumpframe_target",loopMark->pos);
174       return loopMark->pos;
175     }
176   }
177
178   // No previous mark
179   return 0;
180 }
181
182 int Recording::getNextMark(int currentFrame)
183 {
184   MarkList::iterator i;
185   Mark* loopMark = NULL;
186
187   if (!markList || !markList->size()) return 0;
188
189   for(i = markList->begin(); i != markList->end(); i++)
190   {
191     loopMark = *i;
192     logger->log("Recording", Log::NOTICE, "findnext:comparing Frame %i with current Frame %i",loopMark->pos,currentFrame);
193
194     if (loopMark->pos > currentFrame)
195     {
196       logger->log("Recording", Log::NOTICE, "findnext:setting pos %i to jumpframe_target",loopMark->pos);
197       return loopMark->pos;
198     }
199   }
200
201   // No next mark
202   return 0;
203 }
204
205 bool Recording::hasMarks()
206 {
207   return (markList && markList->size());
208 }
209
210 MarkList* Recording::getMarkList()
211 {
212   return markList;
213 }