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