Commit e0ed2d06 authored by Francois Cartegnie's avatar Francois Cartegnie

demux: adaptative: move xml types conversion away from dash

parent 3a3e44f3
......@@ -320,6 +320,8 @@ libadaptative_plugin_la_SOURCES = \
demux/adaptative/Streams.cpp \
demux/adaptative/Streams.hpp \
demux/adaptative/Time.hpp \
demux/adaptative/tools/Conversions.hpp \
demux/adaptative/tools/Conversions.cpp \
demux/adaptative/tools/Debug.hpp \
demux/adaptative/tools/Helper.cpp \
demux/adaptative/tools/Helper.h \
......
/*
* Conversions.cpp
*****************************************************************************
* Copyright © 2015 - VideoLAN and VLC Authors
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#include "Conversions.hpp"
#include <vlc_strings.h>
#include <sstream>
IsoTime::IsoTime(const std::string &str)
{
time = str_duration(str.c_str());
}
IsoTime::operator time_t () const
{
return time;
}
/* i_year: year - 1900 i_month: 0-11 i_mday: 1-31 i_hour: 0-23 i_minute: 0-59 i_second: 0-59 */
static int64_t vlc_timegm( int i_year, int i_month, int i_mday, int i_hour, int i_minute, int i_second )
{
static const int pn_day[12+1] = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 };
int64_t i_day;
if( i_year < 70 ||
i_month < 0 || i_month > 11 || i_mday < 1 || i_mday > 31 ||
i_hour < 0 || i_hour > 23 || i_minute < 0 || i_minute > 59 || i_second < 0 || i_second > 59 )
return -1;
/* Count the number of days */
i_day = (int64_t)365 * (i_year-70) + pn_day[i_month] + i_mday - 1;
#define LEAP(y) ( ((y)%4) == 0 && (((y)%100) != 0 || ((y)%400) == 0) ? 1 : 0)
for( int i = 70; i < i_year; i++ )
i_day += LEAP(1900+i);
if( i_month > 1 )
i_day += LEAP(1900+i_year);
#undef LEAP
/**/
return ((24*i_day + i_hour)*60 + i_minute)*60 + i_second;
}
UTCTime::UTCTime(const std::string &str)
{
enum { YEAR = 0, MON, DAY, HOUR, MIN, SEC, TZ };
int values[7] = {0};
std::istringstream in(str);
try
{
/* Date */
for(int i=YEAR;i<=DAY && !in.eof();i++)
{
if(i!=YEAR)
in.ignore(1);
in >> values[i];
}
/* Time */
if (!in.eof() && in.peek() == 'T')
{
for(int i=HOUR;i<=SEC && !in.eof();i++)
{
in.ignore(1);
in >> values[i];
}
}
/* Timezone */
if (!in.eof() && in.peek() == 'Z')
{
in.ignore(1);
while(!in.eof())
{
if(in.peek() == '+')
continue;
in >> values[TZ];
break;
}
}
time = vlc_timegm( values[YEAR] - 1900, values[MON] - 1, values[DAY],
values[HOUR], values[MIN], values[SEC] );
time += values[TZ] * 3600;
} catch(int) {
time = 0;
}
}
UTCTime::operator time_t () const
{
return time;
}
/*
* Conversions.hpp
*****************************************************************************
* Copyright © 2015 - VideoLAN and VLC Authors
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#ifndef CONVERSIONS_HPP
#define CONVERSIONS_HPP
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <vlc_common.h>
#include <string>
class IsoTime
{
public:
IsoTime(const std::string&);
operator time_t() const;
private:
time_t time;
};
class UTCTime
{
public:
UTCTime(const std::string&);
operator time_t() const;
private:
time_t time;
};
template<typename T> class Integer
{
public:
Integer(const std::string &str)
{
try
{
std::istringstream in(str);
in >> value;
} catch (int) {
value = 0;
}
}
operator T() const
{
return value;
}
private:
T value;
};
#endif // CONVERSIONS_HPP
......@@ -42,7 +42,7 @@
#include "../adaptative/xml/DOMHelper.h"
#include "../adaptative/tools/Helper.h"
#include "../adaptative/tools/Debug.hpp"
#include <vlc_strings.h>
#include "../adaptative/tools/Conversions.hpp"
#include <vlc_stream.h>
#include <cstdio>
......@@ -525,86 +525,3 @@ Profile IsoffMainParser::getProfile() const
return res;
}
IsoTime::IsoTime(const std::string &str)
{
time = str_duration(str.c_str());
}
IsoTime::operator time_t () const
{
return time;
}
/* i_year: year - 1900 i_month: 0-11 i_mday: 1-31 i_hour: 0-23 i_minute: 0-59 i_second: 0-59 */
static int64_t vlc_timegm( int i_year, int i_month, int i_mday, int i_hour, int i_minute, int i_second )
{
static const int pn_day[12+1] = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 };
int64_t i_day;
if( i_year < 70 ||
i_month < 0 || i_month > 11 || i_mday < 1 || i_mday > 31 ||
i_hour < 0 || i_hour > 23 || i_minute < 0 || i_minute > 59 || i_second < 0 || i_second > 59 )
return -1;
/* Count the number of days */
i_day = (int64_t)365 * (i_year-70) + pn_day[i_month] + i_mday - 1;
#define LEAP(y) ( ((y)%4) == 0 && (((y)%100) != 0 || ((y)%400) == 0) ? 1 : 0)
for( int i = 70; i < i_year; i++ )
i_day += LEAP(1900+i);
if( i_month > 1 )
i_day += LEAP(1900+i_year);
#undef LEAP
/**/
return ((24*i_day + i_hour)*60 + i_minute)*60 + i_second;
}
UTCTime::UTCTime(const std::string &str)
{
enum { YEAR = 0, MON, DAY, HOUR, MIN, SEC, TZ };
int values[7] = {0};
std::istringstream in(str);
try
{
/* Date */
for(int i=YEAR;i<=DAY && !in.eof();i++)
{
if(i!=YEAR)
in.ignore(1);
in >> values[i];
}
/* Time */
if (!in.eof() && in.peek() == 'T')
{
for(int i=HOUR;i<=SEC && !in.eof();i++)
{
in.ignore(1);
in >> values[i];
}
}
/* Timezone */
if (!in.eof() && in.peek() == 'Z')
{
in.ignore(1);
while(!in.eof())
{
if(in.peek() == '+')
continue;
in >> values[TZ];
break;
}
}
time = vlc_timegm( values[YEAR] - 1900, values[MON] - 1, values[DAY],
values[HOUR], values[MIN], values[SEC] );
time += values[TZ] * 3600;
} catch(int) {
time = 0;
}
}
UTCTime::operator time_t () const
{
return time;
}
......@@ -33,7 +33,6 @@
#include "Profile.hpp"
#include <cstdlib>
#include <sstream>
#include <vlc_common.h>
......@@ -90,49 +89,6 @@ namespace dash
stream_t *p_stream;
std::string playlisturl;
};
class IsoTime
{
public:
IsoTime(const std::string&);
operator time_t() const;
private:
time_t time;
};
class UTCTime
{
public:
UTCTime(const std::string&);
operator time_t() const;
private:
time_t time;
};
template<typename T> class Integer
{
public:
Integer(const std::string &str)
{
try
{
std::istringstream in(str);
in >> value;
} catch (int) {
value = 0;
}
}
operator T() const
{
return value;
}
private:
T value;
};
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment