Commit 890887de authored by Francois Cartegnie's avatar Francois Cartegnie

stream_filter: dash: move representation selection into logic

parent eb2d6145
......@@ -19,6 +19,8 @@ libdash_plugin_la_SOURCES = \
stream_filter/dash/adaptationlogic/IDownloadRateObserver.h \
stream_filter/dash/adaptationlogic/RateBasedAdaptationLogic.h \
stream_filter/dash/adaptationlogic/RateBasedAdaptationLogic.cpp \
stream_filter/dash/adaptationlogic/Representationselectors.hpp \
stream_filter/dash/adaptationlogic/Representationselectors.cpp \
stream_filter/dash/buffer/BlockBuffer.cpp \
stream_filter/dash/buffer/BlockBuffer.h \
stream_filter/dash/buffer/IBufferObserver.h \
......
......@@ -70,20 +70,22 @@ const Representation *AlwaysBestAdaptationLogic::getCurrentRepresentation() cons
void AlwaysBestAdaptationLogic::initSchedule ()
{
if(this->mpdManager != NULL)
if(mpdManager)
{
std::vector<Period *> periods = this->mpdManager->getPeriods();
std::vector<Period *> periods = mpdManager->getPeriods();
std::vector<Period *>::const_iterator it;
RepresentationSelector selector;
for(size_t i = 0; i < periods.size(); i++)
for(it=periods.begin(); it!=periods.end(); it++)
{
Representation *best = this->mpdManager->getBestRepresentation(periods.at(i));
if(best != NULL)
Representation *best = selector.select(*it);
if(best)
{
std::vector<Segment *> segments = best->getSegments();
for(size_t j = 0; j < segments.size(); j++)
std::vector<Segment *>::const_iterator segIt;
for(segIt=segments.begin(); segIt!=segments.end(); segIt++)
{
this->schedule.push_back(segments.at(j));
schedule.push_back(*segIt);
}
}
}
......
......@@ -26,6 +26,7 @@
#define ALWAYSBESTADAPTATIONLOGIC_H_
#include "adaptationlogic/AbstractAdaptationLogic.h"
#include "Representationselectors.hpp"
#include "http/Chunk.h"
#include "xml/Node.h"
#include "mpd/IMPDManager.h"
......
......@@ -26,6 +26,7 @@
#endif
#include "RateBasedAdaptationLogic.h"
#include "Representationselectors.hpp"
using namespace dash::logic;
using namespace dash::xml;
......@@ -46,20 +47,11 @@ RateBasedAdaptationLogic::RateBasedAdaptationLogic (IMPDManager *mpdManager, st
Chunk* RateBasedAdaptationLogic::getNextChunk()
{
if(this->mpdManager == NULL)
return NULL;
if(this->currentPeriod == NULL)
return NULL;
uint64_t bitrate = this->getBpsAvg();
if(this->getBufferPercent() < MINBUFFER)
bitrate = 0;
Representation *rep = this->mpdManager->getRepresentation(this->currentPeriod, bitrate, this->width, this->height);
if ( rep == NULL )
const Representation *rep = getCurrentRepresentation();
if (!rep)
return NULL;
std::vector<Segment *> segments = rep->getSegments();
......@@ -86,5 +78,20 @@ Chunk* RateBasedAdaptationLogic::getNextChunk()
const Representation *RateBasedAdaptationLogic::getCurrentRepresentation() const
{
return this->mpdManager->getRepresentation( this->currentPeriod, this->getBpsAvg() );
if(currentPeriod == NULL)
return NULL;
uint64_t bitrate = this->getBpsAvg();
if(getBufferPercent() < MINBUFFER)
bitrate = 0;
RepresentationSelector selector;
Representation *rep = selector.select(currentPeriod, bitrate, width, height);
if ( rep == NULL )
{
rep = selector.select(currentPeriod);
if ( rep == NULL )
return NULL;
}
return rep;
}
/*
* Representationselectors.cpp
*****************************************************************************
* Copyright (C) 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.
*****************************************************************************/
#include "Representationselectors.hpp"
#include <limits>
using namespace dash::logic;
RepresentationSelector::RepresentationSelector()
{
}
Representation * RepresentationSelector::select(Period *period) const
{
return select(period, std::numeric_limits<uint64_t>::max());
}
Representation * RepresentationSelector::select(Period *period, uint64_t bitrate) const
{
if (period == NULL)
return NULL;
std::vector<AdaptationSet *> adaptSets = period->getAdaptationSets();
Representation *best = NULL;
std::vector<AdaptationSet *>::const_iterator adaptIt;
for(adaptIt=adaptSets.begin(); adaptIt!=adaptSets.end(); adaptIt++)
{
std::vector<Representation *> reps = (*adaptIt)->getRepresentations();
Representation *candidate = select(reps, (best)?best->getBandwidth():0, bitrate);
if (candidate)
best = candidate;
}
return best;
}
Representation * RepresentationSelector::select(Period *period, uint64_t bitrate,
int width, int height) const
{
if(period == NULL)
return NULL;
std::vector<Representation *> resMatchReps;
/* subset matching WxH */
std::vector<AdaptationSet *> adaptSets = period->getAdaptationSets();
std::vector<AdaptationSet *>::const_iterator adaptIt;
for(adaptIt=adaptSets.begin(); adaptIt!=adaptSets.end(); adaptIt++)
{
std::vector<Representation *> reps = (*adaptIt)->getRepresentations();
std::vector<Representation *>::const_iterator repIt;
for(repIt=reps.begin(); repIt!=reps.end(); repIt++)
{
if((*repIt)->getWidth() == width && (*repIt)->getHeight() == height)
resMatchReps.push_back(*repIt);
}
}
if(resMatchReps.empty())
return select(period, bitrate);
else
return select(resMatchReps, 0, bitrate);
}
Representation * RepresentationSelector::select(std::vector<Representation *>& reps,
uint64_t minbitrate, uint64_t maxbitrate) const
{
Representation *candidate = NULL;
std::vector<Representation *>::const_iterator repIt;
for(repIt=reps.begin(); repIt!=reps.end(); repIt++)
{
if ( (*repIt)->getBandwidth() < maxbitrate &&
(*repIt)->getBandwidth() > minbitrate )
{
candidate = (*repIt);
minbitrate = (*repIt)->getBandwidth();
}
}
return candidate;
}
/*
* Representationselectors.hpp
*****************************************************************************
* Copyright (C) 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 REPRESENTATIONSELECTORS_HPP
#define REPRESENTATIONSELECTORS_HPP
#include "mpd/Representation.h"
#include "mpd/Period.h"
using namespace dash::mpd;
namespace dash
{
namespace logic
{
class RepresentationSelector
{
public:
RepresentationSelector();
virtual ~RepresentationSelector() {}
virtual Representation * select(Period *period) const;
virtual Representation * select(Period *period, uint64_t bitrate) const;
virtual Representation * select(Period *period, uint64_t bitrate,
int width, int height) const;
protected:
virtual Representation * select(std::vector<Representation *>&reps,
uint64_t minbitrate, uint64_t maxbitrate) const;
};
}
}
#endif // REPRESENTATIONSELECTORS_HPP
......@@ -34,8 +34,3 @@ BasicCMManager::BasicCMManager(MPD *mpd) :
{
}
Representation* BasicCMManager::getRepresentation (Period *period, uint64_t bitrate, int, int ) const
{
return IMPDManager::getRepresentation(period, bitrate);
}
......@@ -42,8 +42,6 @@ namespace dash
public:
BasicCMManager (MPD *mpd);
Representation* getRepresentation (Period *period, uint64_t bitrate,
int width, int height) const;
};
}
}
......
......@@ -69,35 +69,3 @@ const MPD* IMPDManager::getMPD() const
{
return mpd;
}
Representation* IMPDManager::getBestRepresentation(Period *period) const
{
return getRepresentation(period, std::numeric_limits<uint64_t>::max());
}
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++)
{
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;
}
......@@ -42,11 +42,8 @@ namespace dash
virtual const std::vector<Period *>& getPeriods () const;
virtual Period* getFirstPeriod () const;
virtual Period* getNextPeriod (Period *period);
virtual Representation* getBestRepresentation (Period *period) const;
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;
};
......
......@@ -27,8 +27,10 @@
#endif
#include "IsoffMainManager.h"
#include "../adaptationlogic/Representationselectors.hpp"
using namespace dash::mpd;
using namespace dash::logic;
IsoffMainManager::IsoffMainManager(MPD *mpd) :
IMPDManager( mpd )
......@@ -36,37 +38,3 @@ IsoffMainManager::IsoffMainManager(MPD *mpd) :
}
Representation* IsoffMainManager::getRepresentation (Period *period, uint64_t bitrate, int width, int height) const
{
if(period == NULL)
return NULL;
std::vector<AdaptationSet *> adaptationSets = period->getAdaptationSets();
std::vector<Representation *> resMatchReps;
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++ )
{
if(reps.at(j)->getWidth() == width && reps.at(j)->getHeight() == height)
resMatchReps.push_back(reps.at(j));
}
}
if(resMatchReps.size() == 0)
return IMPDManager::getRepresentation(period, bitrate);
Representation *best = NULL;
for( size_t j = 0; j < resMatchReps.size(); j++ )
{
uint64_t currentBitrate = resMatchReps.at(j)->getBandwidth();
if(best == NULL || (currentBitrate > best->getBandwidth() && currentBitrate < bitrate))
{
best = resMatchReps.at(j);
}
}
return best;
}
......@@ -43,8 +43,6 @@ namespace dash
public:
IsoffMainManager (MPD *mpd);
Representation* getRepresentation (Period *period, uint64_t bitrate,
int width, int height) const;
};
}
}
......
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