Child: [dd5fc4] (diff)

Download this file

upnpavutils.cxx    51 lines (45 with data), 1.8 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/* Copyright (C) 2014 J.F.Dockes
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the
* Free Software Foundation, Inc.,
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <string>
using namespace std;
#include "libupnpp/upnpavutils.hxx"
// Format duration in milliseconds into UPnP duration format
string upnpduration(int ms)
{
int hours = ms / (3600 * 1000);
ms -= hours * 3600 * 1000;
int minutes = ms / (60 * 1000);
ms -= minutes * 60 * 1000;
int secs = ms / 1000;
ms -= secs * 1000;
char cbuf[100];
// This is the format from the ref doc, but it appears that the
// decimal part in the seconds field is an issue with some control
// points. So drop it...
// sprintf(cbuf, "%d:%02d:%02d.%03d", hours, minutes, secs, ms);
sprintf(cbuf, "%d:%02d:%02d", hours, minutes, secs);
return cbuf;
}
// H:M:S to seconds
int upnpdurationtos(const string& dur)
{
int hours, minutes, seconds;
if (sscanf(dur.c_str(), "%d:%d:%d", &hours, &minutes, &seconds) != 3) {
return 0;
}
return 3600 * hours + 60 * minutes + seconds;
}