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