]> git.vomp.tv Git - vompclient.git/blob - recinfo.cc
Compile fix for MVP re: location change of hmsf
[vompclient.git] / recinfo.cc
1 /*
2     Copyright 2019 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 //portions from vdr by Klaus Schmiding HSMF code
21
22 #include <math.h>
23
24 #include "log.h"
25 #include "i18n.h"
26
27 #include "recinfo.h"
28
29 RecInfo::RecInfo()
30 {
31   timerStart = 0;
32   timerEnd = 0;
33   resumePoint = 0;
34   summary = NULL;
35
36   numComponents = 0;
37   streams = NULL;
38   types = NULL;
39   languages = NULL;
40   descriptions = NULL;
41
42   title = NULL;
43
44   channelName = NULL;
45   duration = 0;
46   fileSize = 0;
47   priority = 0;
48   lifetime = 0;
49
50   summaryWithDetails = NULL;
51 }
52
53 RecInfo::~RecInfo()
54 {
55   Log::getInstance()->log("RecInfo", Log::CRAZY, "Deleting recinfo: %lu, %s", numComponents, summary);
56
57   if (summary) delete[] summary;
58
59   for (ULONG i = 0; i < numComponents; i++)
60   {
61     Log::getInstance()->log("RecInfo", Log::CRAZY, "i: %lu, languages[i]=%p:%s", i, languages[i], languages[i]);
62     Log::getInstance()->log("RecInfo", Log::CRAZY, "i: %lu, descripti[i]=%p:%s", i, descriptions[i], descriptions[i]);
63     if (languages[i]) delete[] (languages[i]);
64     if (descriptions[i]) delete[] (descriptions[i]);
65   }
66
67   if (numComponents)
68   {
69     delete[] languages;
70     delete[] descriptions;
71
72     delete[] streams;
73     delete[] types;
74   }
75
76   if (title) delete [] title;
77
78   timerStart = 0;
79   timerEnd = 0;
80   resumePoint = 0;
81   summary = NULL;
82
83   numComponents = 0;
84   streams = NULL;
85   types = NULL;
86   languages = NULL;
87   descriptions = NULL;
88
89   // TODO: Investigate why this is clearing instance vars
90
91   if (channelName) delete[] channelName;
92   channelName = NULL;
93   duration = 0;
94   fileSize = 0;
95   priority = 0;
96   lifetime = 0;
97
98   if (summaryWithDetails) delete[] summaryWithDetails;
99   summaryWithDetails = NULL;
100 }
101
102 void RecInfo::setNumComponents(ULONG tnumComponents)
103 {
104   numComponents = tnumComponents;
105   languages = new char*[numComponents];
106   descriptions = new char*[numComponents];
107   streams = new UCHAR[numComponents];
108   types = new UCHAR[numComponents];
109 }
110
111 void RecInfo::addComponent(ULONG componentNum, UCHAR tstream, UCHAR ttype, char* tlanguage, char* tdescription)
112 {
113   if (componentNum >= numComponents) return;
114   streams[componentNum] = tstream;
115   types[componentNum] = ttype;
116   languages[componentNum] = tlanguage;
117   descriptions[componentNum] = tdescription;
118 }
119
120 void RecInfo::print()
121 {
122   Log* logger = Log::getInstance();
123
124   logger->log("RecInfo", Log::DEBUG, "timerStart %lu", timerStart);
125   logger->log("RecInfo", Log::DEBUG, "timerEnd %lu", timerEnd);
126   logger->log("RecInfo", Log::DEBUG, "resumePoint %lu", resumePoint);
127   logger->log("RecInfo", Log::DEBUG, "Summary: %s", summary);
128   logger->log("RecInfo", Log::DEBUG, "numComponents: %lu", numComponents);
129
130   for (ULONG i = 0; i < numComponents; i++)
131   {
132     logger->log("RecInfo", Log::DEBUG, "streams[%lu]: %u", i, streams[i]);
133     logger->log("RecInfo", Log::DEBUG, "types[%lu]: %u", i, types[i]);
134     logger->log("RecInfo", Log::DEBUG, "languages[%lu]: %s", i, languages[i]);
135     logger->log("RecInfo", Log::DEBUG, "descriptions[%lu]: %s", i, descriptions[i]);
136   }
137
138   logger->log("RecInfo", Log::DEBUG, "Title: %s", title);
139   logger->log("RecInfo", Log::DEBUG, "Channel: %s", channelName);
140   logger->log("RecInfo", Log::DEBUG, "Duration: %lu", duration);
141   logger->log("RecInfo", Log::DEBUG, "Filesize: %lu", fileSize);
142   logger->log("RecInfo", Log::DEBUG, "Priority: %lu", priority);
143   logger->log("RecInfo", Log::DEBUG, "Lifetime: %lu", lifetime);
144 }
145
146 bool RecInfo::hasNoVideo()
147 {
148   // If no info (numComponents == 0) assume there is video
149   if (!numComponents) return false;
150
151   // video = 1, audio = 2
152
153   for (ULONG i = 0; i < numComponents; i++)
154     if (streams[i] == 1) return false;
155
156   return true;
157 }
158
159 char* RecInfo::buildSummaryWithDetails(bool forceRefresh)
160 {
161   if (!summaryWithDetails || forceRefresh)
162   {
163     if (forceRefresh && summaryWithDetails) delete[] summaryWithDetails;
164
165     Log* logger = Log::getInstance();
166
167     int swdLength = strlen(summary) +
168                     strlen(tr("Channel: ")) + strlen(channelName) +
169                     strlen(tr("Duration: ")) + 5 + /* 'hh:mm' */
170                     strlen(tr("Resume at: ")) + 5 + /* 'hh:mm' */
171                     strlen(tr("Size: ")) + 8 + /* '12345 MB' */
172                     6 + /* line endings */
173                     40 /* just in case (translation of New?) */ ;
174
175     int mins = duration / 60;
176     int hours = mins / 60;
177     mins = mins % 60;
178
179
180     char resumePointText[30];
181     if (resumePoint == 0)
182     {
183       strncpy(resumePointText, tr("New"), 30);
184       resumePointText[29] = '\0';
185     }
186     else
187     {
188       hmsf resumeHMSF = framesToHMSF(resumePoint);
189       SNPRINTF(resumePointText, 30, "%01u:%02u", resumeHMSF.hours, resumeHMSF.minutes);
190     }
191
192     summaryWithDetails = new char[swdLength];
193     SNPRINTF(summaryWithDetails, swdLength, "%s\n\n%s%s\n%s%01i:%02i\n%s%s\n%s%lu MB", summary,
194              tr("Channel: "), channelName,
195              tr("Duration: "), hours, mins,
196              tr("Resume at: "), resumePointText,
197              tr("Size: "), fileSize
198             );
199
200     logger->log("RecInfo", Log::DEBUG, "Build summary with details C: %i, A: %i", swdLength, strlen(summaryWithDetails));
201   }
202   return summaryWithDetails;
203 }
204
205 hmsf RecInfo::framesToHMSF(ULONG frames)
206 {
207   hmsf ret;
208   /* from vdr */
209   double Seconds;
210   ret.frames = int(modf((frames + 0.5) / fps, &Seconds) * fps + 1);
211   int s = int(Seconds);
212   ret.seconds = s % 60;
213   ret.minutes = s / 60 % 60;
214   ret.hours = s / 3600;
215
216   return ret;
217 }