Commit 84bff07d authored by Francois Cartegnie's avatar Francois Cartegnie

stream_filter: dash: deduplicate code

parent 3a87d56e
......@@ -57,6 +57,8 @@ libdash_plugin_la_SOURCES = \
stream_filter/dash/mpd/MPDManagerFactory.h \
stream_filter/dash/mpd/Period.cpp \
stream_filter/dash/mpd/Period.h \
stream_filter/dash/mpd/Profile.cpp \
stream_filter/dash/mpd/Profile.hpp \
stream_filter/dash/mpd/ProgramInformation.cpp \
stream_filter/dash/mpd/ProgramInformation.h \
stream_filter/dash/mpd/Representation.cpp \
......
......@@ -27,17 +27,12 @@
#include "BasicCMManager.h"
#include <cassert>
using namespace dash::mpd;
BasicCMManager::BasicCMManager (MPD *mpd)
{
this->mpd = mpd;
}
BasicCMManager::~BasicCMManager ()
BasicCMManager::BasicCMManager(MPD *mpd) :
IMPDManager(mpd)
{
delete this->mpd;
}
std::vector<Segment*> BasicCMManager::getSegments( const Representation *rep )
......@@ -52,85 +47,8 @@ std::vector<Segment*> BasicCMManager::getSegments( const Representation *rep )
info->getSegments().end() );
return retSegments;
}
const std::vector<Period*>& BasicCMManager::getPeriods () const
{
return this->mpd->getPeriods();
}
Representation* BasicCMManager::getBestRepresentation (Period *period)
{
std::vector<AdaptationSet *> adaptSet = period->getAdaptationSets();
uint64_t bitrate = 0;
Representation *best = NULL;
for(size_t i = 0; i < adaptSet.size(); i++)
{
std::vector<Representation *> reps = adaptSet.at(i)->getRepresentations();
for(size_t j = 0; j < reps.size(); j++)
{
uint64_t currentBitrate = reps.at(j)->getBandwidth();
if( currentBitrate > bitrate)
{
bitrate = currentBitrate;
best = reps.at(j);
}
}
}
return best;
}
Period* BasicCMManager::getFirstPeriod ()
{
std::vector<Period *> periods = this->mpd->getPeriods();
if(periods.size() == 0)
return NULL;
return periods.at(0);
}
Representation* BasicCMManager::getRepresentation(Period *period, uint64_t bitrate ) const
{
std::vector<AdaptationSet *> adaptSet = period->getAdaptationSets();
Representation *best = NULL;
for(size_t i = 0; i < adaptSet.size(); i++)
{
std::vector<Representation *> reps = adaptSet.at(i)->getRepresentations();
for( size_t j = 0; j < reps.size(); j++ )
{
uint64_t currentBitrate = reps.at(j)->getBandwidth();
if ( best == NULL ||
( currentBitrate > best->getBandwidth() &&
currentBitrate < bitrate ) )
{
best = reps.at( j );
}
}
}
return best;
}
Period* BasicCMManager::getNextPeriod (Period *period)
{
std::vector<Period *> periods = this->mpd->getPeriods();
for(size_t i = 0; i < periods.size(); i++)
{
if(periods.at(i) == period && (i + 1) < periods.size())
return periods.at(i + 1);
}
return NULL;
}
const MPD* BasicCMManager::getMPD() const
{
return this->mpd;
}
Representation* BasicCMManager::getRepresentation (Period *period, uint64_t bitrate, int, int ) const
{
return this->getRepresentation(period, bitrate);
return IMPDManager::getRepresentation(period, bitrate);
}
......@@ -29,12 +29,9 @@
#include <stdio.h>
#include <stdlib.h>
#include "mpd/MPD.h"
#include "mpd/Period.h"
#include "mpd/Representation.h"
#include "mpd/IMPDManager.h"
#include "mpd/SegmentInfo.h"
#include "mpd/Segment.h"
#include "mpd/IMPDManager.h"
namespace dash
{
......@@ -44,20 +41,10 @@ namespace dash
{
public:
BasicCMManager (MPD *mpd);
virtual ~BasicCMManager ();
const std::vector<Period *>& getPeriods() const;
Period* getFirstPeriod();
Period* getNextPeriod( Period *period );
Representation* getBestRepresentation( Period *period );
std::vector<Segment *> getSegments( const Representation *rep );
Representation* getRepresentation( Period *period, uint64_t bitrate ) const;
const MPD* getMPD() const;
Representation* getRepresentation (Period *period, uint64_t bitrate,
int width, int height) const;
private:
MPD *mpd;
};
}
}
......
......@@ -25,30 +25,100 @@
using namespace dash::mpd;
Profile::Name Profile::getNameByURN(std::string urn)
IMPDManager::IMPDManager(MPD *mpd_) :
mpd(mpd_)
{
struct
}
IMPDManager::~IMPDManager()
{
delete mpd;
}
const std::vector<Period*>& IMPDManager::getPeriods() const
{
return mpd->getPeriods();
}
Period* IMPDManager::getFirstPeriod() const
{
std::vector<Period *> periods = getPeriods();
if( !periods.empty() )
return periods.front();
else
return NULL;
}
Period* IMPDManager::getNextPeriod(Period *period)
{
std::vector<Period *> periods = getPeriods();
for(size_t i = 0; i < periods.size(); i++)
{
const Name name;
const char * urn;
if(periods.at(i) == period && (i + 1) < periods.size())
return periods.at(i + 1);
}
urnmap[] =
return NULL;
}
const MPD* IMPDManager::getMPD() const
{
return mpd;
}
Representation* IMPDManager::getBestRepresentation(Period *period) const
{
if (period == NULL)
return NULL;
std::vector<AdaptationSet *> adaptSet = period->getAdaptationSets();
uint64_t bitrate = 0;
Representation *best = NULL;
for(size_t i = 0; i < adaptSet.size(); i++)
{
{ Full, "urn:mpeg:dash:profile:full:2011" },
{ ISOOnDemand, "urn:mpeg:dash:profile:isoff-on-demand:2011" },
{ ISOOnDemand, "urn:mpeg:mpegB:profile:dash:isoff-basic-on-demand:cm" },
{ ISOOnDemand, "urn:mpeg:dash:profile:isoff-ondemand:2011" },
{ ISOMain, "urn:mpeg:dash:profile:isoff-main:2011" },
{ ISOLive, "urn:mpeg:dash:profile:isoff-live:2011" },
{ MPEG2TSMain, "urn:mpeg:dash:profile:mp2t-main:2011" },
{ MPEG2TSSimple,"urn:mpeg:dash:profile:mp2t-simple:2011" },
{ Unknown, "" },
};
for( int i=0; urnmap[i].name != Unknown; i++ )
std::vector<Representation *> reps = adaptSet.at(i)->getRepresentations();
for(size_t j = 0; j < reps.size(); j++)
{
uint64_t currentBitrate = reps.at(j)->getBandwidth();
if( currentBitrate > bitrate)
{
bitrate = currentBitrate;
best = reps.at(j);
}
}
}
return best;
}
Representation* IMPDManager::getRepresentation(Period *period, uint64_t bitrate ) const
{
if (period == NULL)
return NULL;
std::vector<AdaptationSet *> adaptSet = period->getAdaptationSets();
Representation *best = NULL;
for(size_t i = 0; i < adaptSet.size(); i++)
{
if ( urn == urnmap[i].urn )
return urnmap[i].name;
std::vector<Representation *> reps = adaptSet.at(i)->getRepresentations();
for( size_t j = 0; j < reps.size(); j++ )
{
uint64_t currentBitrate = reps.at(j)->getBandwidth();
if ( best == NULL ||
( currentBitrate > best->getBandwidth() &&
currentBitrate < bitrate ) )
{
best = reps.at( j );
}
}
}
return Unknown;
return best;
}
......@@ -25,6 +25,7 @@
#ifndef IMPDMANAGER_H_
#define IMPDMANAGER_H_
#include "mpd/MPD.h"
#include "mpd/Period.h"
#include "mpd/Representation.h"
......@@ -32,38 +33,23 @@ namespace dash
{
namespace mpd
{
class MPD;
class Profile
{
public:
enum Name
{
Unknown,
Full,
ISOOnDemand,
ISOMain,
ISOLive,
MPEG2TSMain,
MPEG2TSSimple,
};
static Name getNameByURN( std::string urn );
};
class IMPDManager
{
public:
virtual ~IMPDManager(){}
IMPDManager( MPD *mpd );
virtual ~IMPDManager();
virtual const std::vector<Period *>& getPeriods () const = 0;
virtual Period* getFirstPeriod () = 0;
virtual Period* getNextPeriod (Period *period) = 0;
virtual Representation* getBestRepresentation (Period *period) = 0;
virtual const std::vector<Period *>& getPeriods () const;
virtual Period* getFirstPeriod () const;
virtual Period* getNextPeriod (Period *period);
virtual Representation* getBestRepresentation (Period *period) const;
virtual std::vector<Segment *> getSegments (const Representation *rep) = 0;
virtual Representation* getRepresentation (Period *period, uint64_t bitrate) const = 0;
virtual const MPD* getMPD () const = 0;
virtual Representation* getRepresentation (Period *period, uint64_t bitrate) const;
virtual const MPD* getMPD () const;
virtual Representation* getRepresentation (Period *period, uint64_t bitrate,
int width, int height) const = 0;
protected:
MPD *mpd;
};
}
}
......
......@@ -30,13 +30,10 @@
using namespace dash::mpd;
IsoffMainManager::IsoffMainManager (MPD *mpd)
IsoffMainManager::IsoffMainManager(MPD *mpd) :
IMPDManager( mpd )
{
this->mpd = mpd;
}
IsoffMainManager::~IsoffMainManager ()
{
delete this->mpd;
}
std::vector<Segment*> IsoffMainManager::getSegments (const Representation *rep)
......@@ -56,82 +53,7 @@ std::vector<Segment*> IsoffMainManager::getSegments (const Repre
retSegments.insert(retSegments.end(), list->getSegments().begin(), list->getSegments().end());
return retSegments;
}
const std::vector<Period*>& IsoffMainManager::getPeriods () const
{
return this->mpd->getPeriods();
}
Representation* IsoffMainManager::getBestRepresentation (Period *period)
{
std::vector<AdaptationSet *> adaptationSets = period->getAdaptationSets();
int bitrate = 0;
Representation *best = NULL;
for(size_t i = 0; i < adaptationSets.size(); i++)
{
std::vector<Representation *> reps = adaptationSets.at(i)->getRepresentations();
for(size_t j = 0; j < reps.size(); j++)
{
int currentBitrate = reps.at(j)->getBandwidth();
if(currentBitrate > bitrate)
{
bitrate = currentBitrate;
best = reps.at(j);
}
}
}
return best;
}
Period* IsoffMainManager::getFirstPeriod ()
{
std::vector<Period *> periods = this->mpd->getPeriods();
if(periods.size() == 0)
return NULL;
return periods.at(0);
}
Representation* IsoffMainManager::getRepresentation (Period *period, uint64_t bitrate) const
{
if(period == NULL)
return NULL;
std::vector<AdaptationSet *> adaptationSets = period->getAdaptationSets();
Representation *best = NULL;
for(size_t i = 0; i < adaptationSets.size(); i++)
{
std::vector<Representation *> reps = adaptationSets.at(i)->getRepresentations();
for( size_t j = 0; j < reps.size(); j++ )
{
uint64_t currentBitrate = reps.at(j)->getBandwidth();
if(best == NULL || (currentBitrate > best->getBandwidth() && currentBitrate < bitrate))
{
best = reps.at( j );
}
}
}
return best;
}
Period* IsoffMainManager::getNextPeriod (Period *period)
{
std::vector<Period *> periods = this->mpd->getPeriods();
for(size_t i = 0; i < periods.size(); i++)
{
if(periods.at(i) == period && (i + 1) < periods.size())
return periods.at(i + 1);
}
return NULL;
}
const MPD* IsoffMainManager::getMPD () const
{
return this->mpd;
}
Representation* IsoffMainManager::getRepresentation (Period *period, uint64_t bitrate, int width, int height) const
{
if(period == NULL)
......@@ -151,7 +73,7 @@ Representation* IsoffMainManager::getRepresentation (Period *per
}
if(resMatchReps.size() == 0)
return this->getRepresentation(period, bitrate);
return IMPDManager::getRepresentation(period, bitrate);
Representation *best = NULL;
for( size_t j = 0; j < resMatchReps.size(); j++ )
......
......@@ -29,13 +29,10 @@
#include <stdio.h>
#include <stdlib.h>
#include "mpd/MPD.h"
#include "mpd/Period.h"
#include "mpd/IMPDManager.h"
#include "mpd/AdaptationSet.h"
#include "mpd/Representation.h"
#include "mpd/SegmentInfo.h"
#include "mpd/Segment.h"
#include "mpd/IMPDManager.h"
namespace dash
{
......@@ -45,20 +42,10 @@ namespace dash
{
public:
IsoffMainManager (MPD *mpd);
virtual ~IsoffMainManager ();
const std::vector<Period *>& getPeriods () const;
Period* getFirstPeriod ();
Period* getNextPeriod (Period *period);
Representation* getBestRepresentation (Period *period);
std::vector<Segment *> getSegments (const Representation *rep);
Representation* getRepresentation (Period *period, uint64_t bitrate) const;
const MPD* getMPD () const;
Representation* getRepresentation (Period *period, uint64_t bitrate,
int width, int height) const;
private:
MPD *mpd;
};
}
}
......
......@@ -32,7 +32,7 @@
#include "mpd/Period.h"
#include "mpd/BaseUrl.h"
#include "mpd/ProgramInformation.h"
#include "mpd/IMPDManager.h"
#include "mpd/Profile.hpp"
namespace dash
{
......
/*
* Profile.cpp
*****************************************************************************
* Copyright (C) 2010 - 2014 VideoLAN 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.
*****************************************************************************/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "Profile.hpp"
using namespace dash::mpd;
Profile::Name Profile::getNameByURN(std::string urn)
{
struct
{
const Name name;
const char * urn;
}
urnmap[] =
{
{ Full, "urn:mpeg:dash:profile:full:2011" },
{ ISOOnDemand, "urn:mpeg:dash:profile:isoff-on-demand:2011" },
{ ISOOnDemand, "urn:mpeg:mpegB:profile:dash:isoff-basic-on-demand:cm" },
{ ISOOnDemand, "urn:mpeg:dash:profile:isoff-ondemand:2011" },
{ ISOMain, "urn:mpeg:dash:profile:isoff-main:2011" },
{ ISOLive, "urn:mpeg:dash:profile:isoff-live:2011" },
{ MPEG2TSMain, "urn:mpeg:dash:profile:mp2t-main:2011" },
{ MPEG2TSSimple,"urn:mpeg:dash:profile:mp2t-simple:2011" },
{ Unknown, "" },
};
for( int i=0; urnmap[i].name != Unknown; i++ )
{
if ( urn == urnmap[i].urn )
return urnmap[i].name;
}
return Unknown;
}
/*
* Profile.hpp
*****************************************************************************
* Copyright (C) 2010 - 2014 VideoLAN 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 PROFILE_HPP
#define PROFILE_HPP
#include <string>
namespace dash
{
namespace mpd
{
class Profile
{
public:
enum Name
{
Unknown,
Full,
ISOOnDemand,
ISOMain,
ISOLive,
MPEG2TSMain,
MPEG2TSSimple,
};
static Name getNameByURN( std::string urn );
};
}
}
#endif // PROFILE_HPP
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