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