]> git.vomp.tv Git - vompclient.git/blob - recording.cc
Rewritten vomp discovery protocol
[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(bool &h264)
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   bool ish264=false;
143   if (IsPesRecording)
144     hasVideo = Demuxer::scanForVideo(buffer, thisRead, ish264);
145   else
146     hasVideo = DemuxerTS::scanForVideo(buffer, thisRead,ish264);
147
148   h264=ish264;
149
150   free(buffer);
151
152   vdr->stopStreaming();
153   if (!VDR::getInstance()->isConnected()) Command::getInstance()->connectionLost();
154   
155   Log::getInstance()->log("Recording", Log::DEBUG, "Recording has messed about and worked out radio = %u", !hasVideo);
156
157
158   if (!hasVideo) return true;
159   return false;
160 }
161
162 int Recording::getPrevMark(int currentFrame)
163 {
164   MarkList::reverse_iterator i;
165   Mark* loopMark = NULL;
166
167   if (!markList || !markList->size()) return 0;
168
169   for(i = markList->rbegin(); i != markList->rend(); i++)
170   {
171     loopMark = *i;
172     logger->log("Recording", Log::NOTICE, "findprev:comparing Frame %i with current Frame %i",loopMark->pos,currentFrame);
173
174     if (loopMark->pos < currentFrame)
175     {
176       logger->log("Recording", Log::NOTICE, "findprev:setting pos %i to jumpframe_target",loopMark->pos);
177       return loopMark->pos;
178     }
179   }
180
181   // No previous mark
182   return 0;
183 }
184
185 int Recording::getNextMark(int currentFrame)
186 {
187   MarkList::iterator i;
188   Mark* loopMark = NULL;
189
190   if (!markList || !markList->size()) return 0;
191
192   for(i = markList->begin(); i != markList->end(); i++)
193   {
194     loopMark = *i;
195     logger->log("Recording", Log::NOTICE, "findnext:comparing Frame %i with current Frame %i",loopMark->pos,currentFrame);
196
197     if (loopMark->pos > currentFrame)
198     {
199       logger->log("Recording", Log::NOTICE, "findnext:setting pos %i to jumpframe_target",loopMark->pos);
200       return loopMark->pos;
201     }
202   }
203
204   // No next mark
205   return 0;
206 }
207
208 bool Recording::hasMarks()
209 {
210   return (markList && markList->size());
211 }
212
213 MarkList* Recording::getMarkList()
214 {
215   return markList;
216 }