2 Copyright 2019 Chris Tallon
4 This file is part of VOMP.
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.
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.
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.
20 //portions from vdr by Klaus Schmiding HSMF code
50 summaryWithDetails = NULL;
55 Log::getInstance()->log("RecInfo", Log::CRAZY, "Deleting recinfo: %lu, %s", numComponents, summary);
57 if (summary) delete[] summary;
59 for (ULONG i = 0; i < numComponents; i++)
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]);
70 delete[] descriptions;
76 if (title) delete [] title;
89 // TODO: Investigate why this is clearing instance vars
91 if (channelName) delete[] channelName;
98 if (summaryWithDetails) delete[] summaryWithDetails;
99 summaryWithDetails = NULL;
102 void RecInfo::setNumComponents(ULONG tnumComponents)
104 numComponents = tnumComponents;
105 languages = new char*[numComponents];
106 descriptions = new char*[numComponents];
107 streams = new UCHAR[numComponents];
108 types = new UCHAR[numComponents];
111 void RecInfo::addComponent(ULONG componentNum, UCHAR tstream, UCHAR ttype, char* tlanguage, char* tdescription)
113 if (componentNum >= numComponents) return;
114 streams[componentNum] = tstream;
115 types[componentNum] = ttype;
116 languages[componentNum] = tlanguage;
117 descriptions[componentNum] = tdescription;
120 void RecInfo::print()
122 Log* logger = Log::getInstance();
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);
130 for (ULONG i = 0; i < numComponents; i++)
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]);
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);
146 bool RecInfo::hasNoVideo()
148 // If no info (numComponents == 0) assume there is video
149 if (!numComponents) return false;
151 // video = 1, audio = 2
153 for (ULONG i = 0; i < numComponents; i++)
154 if (streams[i] == 1) return false;
159 char* RecInfo::buildSummaryWithDetails(bool forceRefresh)
161 if (!summaryWithDetails || forceRefresh)
163 if (forceRefresh && summaryWithDetails) delete[] summaryWithDetails;
165 Log* logger = Log::getInstance();
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?) */ ;
175 int mins = duration / 60;
176 int hours = mins / 60;
180 char resumePointText[30];
181 if (resumePoint == 0)
183 strncpy(resumePointText, tr("New"), 30);
184 resumePointText[29] = '\0';
188 hmsf resumeHMSF = framesToHMSF(resumePoint);
189 SNPRINTF(resumePointText, 30, "%01u:%02u", resumeHMSF.hours, resumeHMSF.minutes);
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
200 logger->log("RecInfo", Log::DEBUG, "Build summary with details C: %i, A: %i", swdLength, strlen(summaryWithDetails));
202 return summaryWithDetails;
205 hmsf RecInfo::framesToHMSF(ULONG frames)
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;