]> git.vomp.tv Git - vompclient.git/blob - recinfo.cc
Display channel name, duration, resume point and size on recording info screen
[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()
160 {
161   if (!summaryWithDetails)
162   {
163     Log* logger = Log::getInstance();
164
165     int swdLength = strlen(summary) +
166                     strlen(tr("Channel: ")) + strlen(channelName) +
167                     strlen(tr("Duration: ")) + 5 + /* 'hh:mm' */
168                     strlen(tr("Resume at: ")) + 5 + /* 'hh:mm' */
169                     strlen(tr("Size: ")) + 8 + /* '12345 MB' */
170                     6 + /* line endings */
171                     40 /* just in case (translation of New?) */ ;
172
173     int mins = duration / 60;
174     int hours = mins / 60;
175     mins = mins % 60;
176
177
178     char resumePointText[30];
179     if (resumePoint == 0)
180     {
181       strncpy(resumePointText, tr("New"), 30);
182       resumePointText[29] = '\0';
183     }
184     else
185     {
186       hmsf resumeHMSF = framesToHMSF(resumePoint);
187       SNPRINTF(resumePointText, 30, "%01u:%02u", resumeHMSF.hours, resumeHMSF.minutes);
188     }
189
190     summaryWithDetails = new char[swdLength];
191     SNPRINTF(summaryWithDetails, swdLength, "%s\n\n%s%s\n%s%01i:%02i\n%s%s\n%s%lu MB", summary,
192              tr("Channel: "), channelName,
193              tr("Duration: "), hours, mins,
194              tr("Resume at: "), resumePointText,
195              tr("Size: "), fileSize
196             );
197
198     logger->log("RecInfo", Log::DEBUG, "Build summary with details C: %i, A: %i", swdLength, strlen(summaryWithDetails));
199   }
200   return summaryWithDetails;
201 }
202
203 hmsf RecInfo::framesToHMSF(ULONG frames)
204 {
205   hmsf ret;
206   /* from vdr */
207   double Seconds;
208   ret.frames = int(modf((frames + 0.5) / fps, &Seconds) * fps + 1);
209   int s = int(Seconds);
210   ret.seconds = s % 60;
211   ret.minutes = s / 60 % 60;
212   ret.hours = s / 3600;
213
214   return ret;
215 }