Commit f3600cde authored by Christopher Mueller's avatar Christopher Mueller Committed by Jean-Baptiste Kempf

Added DASH stream filter

Signed-off-by: Jean-Baptiste Kempf's avatarJean-Baptiste Kempf <jb@videolan.org>
parent 3d0a5eb4
......@@ -4311,6 +4311,7 @@ AC_CONFIG_FILES([
modules/packetizer/Makefile
modules/services_discovery/Makefile
modules/stream_filter/Makefile
modules/stream_filter/dash/Makefile
modules/stream_out/Makefile
modules/stream_out/transcode/Makefile
modules/text_renderer/Makefile
......
SUBDIRS = dash
SOURCES_decomp = decomp.c
SOURCES_stream_filter_record = record.c
SOURCES_stream_filter_httplive = httplive.c
......
/*
* DASHManager.cpp
*****************************************************************************
* Copyright (C) 2010 - 2011 Klagenfurt University
*
* Created on: Aug 10, 2010
* Authors: Christopher Mueller <christopher.mueller@itec.uni-klu.ac.at>
* Christian Timmerer <christian.timmerer@itec.uni-klu.ac.at>
*
* 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 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 "DASHManager.h"
using namespace dash;
using namespace dash::http;
using namespace dash::xml;
using namespace dash::logic;
using namespace dash::mpd;
using namespace dash::exception;
DASHManager::DASHManager (HTTPConnectionManager *conManager, Node *node, IAdaptationLogic::LogicType type, Profile profile)
{
this->conManager = conManager;
this->node = node;
this->logicType = type;
this->profile = profile;
this->mpdManagerFactory = new MPDManagerFactory();
this->mpdManager = this->mpdManagerFactory->create(this->profile, this->node);
this->logicFactory = new AdaptationLogicFactory();
this->adaptationLogic = this->logicFactory->create(this->logicType, this->mpdManager);
this->currentChunk = NULL;
this->conManager->attach(this->adaptationLogic);
}
DASHManager::~DASHManager ()
{
delete(this->logicFactory);
delete(this->adaptationLogic);
delete(this->mpdManager);
}
int DASHManager::read (void *p_buffer, size_t len)
{
if(this->currentChunk == NULL)
{
try
{
this->currentChunk = this->adaptationLogic->getNextChunk();
}
catch(EOFException &e)
{
this->currentChunk = NULL;
return 0;
}
}
int ret = this->conManager->read(this->currentChunk, p_buffer, len);
if(ret <= 0)
{
this->currentChunk = NULL;
return this->read(p_buffer, len);
}
return ret;
}
int DASHManager::peek (const uint8_t **pp_peek, size_t i_peek)
{
if(this->currentChunk == NULL)
{
try
{
this->currentChunk = this->adaptationLogic->getNextChunk();
}
catch(EOFException &e)
{
return 0;
}
}
int ret = this->conManager->peek(this->currentChunk, pp_peek, i_peek);
return ret;
}
/*
* DASHManager.h
*****************************************************************************
* Copyright (C) 2010 - 2011 Klagenfurt University
*
* Created on: Aug 10, 2010
* Authors: Christopher Mueller <christopher.mueller@itec.uni-klu.ac.at>
* Christian Timmerer <christian.timmerer@itec.uni-klu.ac.at>
*
* 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 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 DASHMANAGER_H_
#define DASHMANAGER_H_
#include <stdint.h>
#include <stddef.h>
#include <iostream>
#include "http/HTTPConnectionManager.h"
#include "xml/Node.h"
#include "adaptationlogic/IAdaptationLogic.h"
#include "adaptationlogic/AdaptationLogicFactory.h"
#include "mpd/IMPDManager.h"
#include "mpd/MPDManagerFactory.h"
#include "exceptions/EOFException.h"
namespace dash
{
class DASHManager
{
public:
DASHManager (http::HTTPConnectionManager *conManager, xml::Node *node, logic::IAdaptationLogic::LogicType type, mpd::Profile profile);
virtual ~DASHManager ();
int read (void *p_buffer, size_t len);
int peek (const uint8_t **pp_peek, size_t i_peek);
private:
http::HTTPConnectionManager *conManager;
http::Chunk *currentChunk;
logic::AdaptationLogicFactory *logicFactory;
logic::IAdaptationLogic *adaptationLogic;
logic::IAdaptationLogic::LogicType logicType;
mpd::Profile profile;
xml::Node *node;
mpd::MPDManagerFactory *mpdManagerFactory;
mpd::IMPDManager *mpdManager;
};
}
#endif /* DASHMANAGER_H_ */
SOURCES_stream_filter_dash = \
adaptationlogic/AbstractAdaptationLogic.cpp \
adaptationlogic/AbstractAdaptationLogic.h \
adaptationlogic/AdaptationLogicFactory.cpp \
adaptationlogic/AdaptationLogicFactory.h \
adaptationlogic/AlwaysBestAdaptationLogic.cpp \
adaptationlogic/AlwaysBestAdaptationLogic.h \
adaptationlogic/IAdaptationLogic.h \
adaptationlogic/IDownloadRateObserver.h \
adaptationlogic/NullAdaptationLogic.h \
adaptationlogic/RateBasedAdaptationLogic.h \
adaptationlogic/RateBasedAdaptationLogic.cpp \
exceptions/AttributeNotPresentException.h \
exceptions/ElementNotPresentException.h \
exceptions/EOFException.h \
http/Chunk.cpp \
http/Chunk.h \
http/HTTPConnection.cpp \
http/HTTPConnection.h \
http/HTTPConnectionManager.cpp \
http/HTTPConnectionManager.h \
http/IHTTPConnection.h \
mpd/Accessibility.h \
mpd/BaseUrl.h \
mpd/BasicCMManager.cpp \
mpd/BasicCMManager.h \
mpd/BasicCMParser.cpp \
mpd/BasicCMParser.h \
mpd/ContentDescription.cpp \
mpd/ContentDescription.h \
mpd/ContentProtection.h \
mpd/Group.cpp \
mpd/Group.h \
mpd/IMPDManager.h \
mpd/IMPDParser.h \
mpd/InitSegment.cpp \
mpd/InitSegment.h \
mpd/ISegment.h \
mpd/MPD.cpp \
mpd/MPD.h \
mpd/MPDManagerFactory.cpp \
mpd/MPDManagerFactory.h \
mpd/NullManager.cpp \
mpd/NullManager.h \
mpd/Period.cpp \
mpd/Period.h \
mpd/ProgramInformation.cpp \
mpd/ProgramInformation.h \
mpd/Rating.h \
mpd/Representation.cpp \
mpd/Representation.h \
mpd/SchemeInformation.cpp \
mpd/SchemeInformation.h \
mpd/Segment.cpp \
mpd/Segment.h \
mpd/SegmentInfo.cpp \
mpd/SegmentInfo.h \
mpd/TrickModeType.cpp \
mpd/TrickModeType.h \
mpd/Viewpoint.h \
xml/DOMHelper.cpp \
xml/DOMHelper.h \
xml/DOMParser.cpp \
xml/DOMParser.h \
xml/Node.cpp \
xml/Node.h \
dash.cpp \
DASHManager.cpp \
DASHManager.h \
$(NULL)
libvlc_LTLIBRARIES += libstream_filter_dash_plugin.la
/*
* AbstractAdaptationLogic.cpp
*****************************************************************************
* Copyright (C) 2010 - 2011 Klagenfurt University
*
* Created on: Aug 10, 2010
* Authors: Christopher Mueller <christopher.mueller@itec.uni-klu.ac.at>
* Christian Timmerer <christian.timmerer@itec.uni-klu.ac.at>
*
* 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 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 "AbstractAdaptationLogic.h"
using namespace dash::logic;
using namespace dash::xml;
using namespace dash::mpd;
using namespace dash::exception;
AbstractAdaptationLogic::AbstractAdaptationLogic (IMPDManager *mpdManager)
{
this->bpsAvg = 0;
this->bpsLastChunk = 0;
this->mpdManager = mpdManager;
}
AbstractAdaptationLogic::~AbstractAdaptationLogic ()
{
}
void AbstractAdaptationLogic::downloadRateChanged (long bpsAvg, long bpsLastChunk)
{
this->bpsAvg = bpsAvg;
this->bpsLastChunk = bpsLastChunk;
}
long AbstractAdaptationLogic::getBpsAvg ()
{
return this->bpsAvg;
}
long AbstractAdaptationLogic::getBpsLastChunk ()
{
return this->bpsLastChunk;
}
/*
* AbstractAdaptationLogic.h
*****************************************************************************
* Copyright (C) 2010 - 2011 Klagenfurt University
*
* Created on: Aug 10, 2010
* Authors: Christopher Mueller <christopher.mueller@itec.uni-klu.ac.at>
* Christian Timmerer <christian.timmerer@itec.uni-klu.ac.at>
*
* 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 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 ABSTRACTADAPTATIONLOGIC_H_
#define ABSTRACTADAPTATIONLOGIC_H_
#include "adaptationlogic/IAdaptationLogic.h"
#include "xml/Node.h"
#include "http/Chunk.h"
#include "mpd/MPD.h"
#include "mpd/IMPDManager.h"
#include "mpd/Period.h"
#include "mpd/Representation.h"
#include "mpd/InitSegment.h"
#include "mpd/Segment.h"
#include "exceptions/AttributeNotPresentException.h"
#include "exceptions/EOFException.h"
namespace dash
{
namespace logic
{
class AbstractAdaptationLogic : public IAdaptationLogic
{
public:
AbstractAdaptationLogic (dash::mpd::IMPDManager *mpdManager);
virtual ~AbstractAdaptationLogic ();
virtual dash::http::Chunk* getNextChunk () throw(dash::exception::EOFException) = 0;
virtual void downloadRateChanged (long bpsAvg, long bpsLastChunk);
long getBpsAvg ();
long getBpsLastChunk ();
private:
long bpsAvg;
long bpsLastChunk;
dash::mpd::IMPDManager *mpdManager;
};
}
}
#endif /* ABSTRACTADAPTATIONLOGIC_H_ */
/*
* AdaptationLogicFactory.cpp
*****************************************************************************
* Copyright (C) 2010 - 2011 Klagenfurt University
*
* Created on: Aug 10, 2010
* Authors: Christopher Mueller <christopher.mueller@itec.uni-klu.ac.at>
* Christian Timmerer <christian.timmerer@itec.uni-klu.ac.at>
*
* 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 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 "AdaptationLogicFactory.h"
using namespace dash::logic;
using namespace dash::xml;
using namespace dash::mpd;
AdaptationLogicFactory::AdaptationLogicFactory ()
{
}
AdaptationLogicFactory::~AdaptationLogicFactory ()
{
}
IAdaptationLogic* AdaptationLogicFactory::create (IAdaptationLogic::LogicType logic, IMPDManager *mpdManager)
{
switch(logic)
{
case IAdaptationLogic::Default: return new NullAdaptationLogic (mpdManager);
case IAdaptationLogic::AlwaysBest: return new AlwaysBestAdaptationLogic (mpdManager);
case IAdaptationLogic::AlwaysLowest: return new NullAdaptationLogic (mpdManager);
case IAdaptationLogic::RateBased: return new RateBasedAdaptationLogic (mpdManager);
default: return new NullAdaptationLogic (mpdManager);
}
}
/*
* AdaptationLogicFactory.h
*****************************************************************************
* Copyright (C) 2010 - 2011 Klagenfurt University
*
* Created on: Aug 10, 2010
* Authors: Christopher Mueller <christopher.mueller@itec.uni-klu.ac.at>
* Christian Timmerer <christian.timmerer@itec.uni-klu.ac.at>
*
* 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 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 ADAPTATIONLOGICFACTORY_H_
#define ADAPTATIONLOGICFACTORY_H_
#include "adaptationlogic/IAdaptationLogic.h"
#include "xml/Node.h"
#include "mpd/IMPDManager.h"
#include "adaptationlogic/AlwaysBestAdaptationLogic.h"
#include "adaptationlogic/NullAdaptationLogic.h"
#include "adaptationlogic/RateBasedAdaptationLogic.h"
namespace dash
{
namespace logic
{
class AdaptationLogicFactory
{
public:
AdaptationLogicFactory ();
virtual ~AdaptationLogicFactory ();
IAdaptationLogic* create (IAdaptationLogic::LogicType logic, dash::mpd::IMPDManager *mpdManager);
};
}
}
#endif /* ADAPTATIONLOGICFACTORY_H_ */
/*
* AlwaysBestAdaptationLogic.cpp
*****************************************************************************
* Copyright (C) 2010 - 2011 Klagenfurt University
*
* Created on: Aug 10, 2010
* Authors: Christopher Mueller <christopher.mueller@itec.uni-klu.ac.at>
* Christian Timmerer <christian.timmerer@itec.uni-klu.ac.at>
*
* 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 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 "AlwaysBestAdaptationLogic.h"
using namespace dash::logic;
using namespace dash::xml;
using namespace dash::http;
using namespace dash::mpd;
using namespace dash::exception;
AlwaysBestAdaptationLogic::AlwaysBestAdaptationLogic (IMPDManager *mpdManager) : AbstractAdaptationLogic(mpdManager)
{
this->mpdManager = mpdManager;
this->count = 0;
this->initSchedule();
}
AlwaysBestAdaptationLogic::~AlwaysBestAdaptationLogic ()
{
}
Chunk* AlwaysBestAdaptationLogic::getNextChunk () throw(EOFException)
{
if(this->schedule.size() == 0)
throw EOFException();
if(this->count == this->schedule.size())
throw EOFException();
for(int i = 0; i < this->schedule.size(); i++)
{
if(this->count == i)
{
Chunk *chunk = new Chunk();
chunk->setUrl(this->schedule.at(i)->getSourceUrl());
this->count++;
return chunk;
}
}
return NULL;
}
void AlwaysBestAdaptationLogic::initSchedule ()
{
if(this->mpdManager != NULL)
{
std::vector<Period *> periods = this->mpdManager->getPeriods();
for(int i = 0; i < periods.size(); i++)
{
Representation *best = this->mpdManager->getBestRepresentation(periods.at(i));
if(best != NULL)
{
std::vector<ISegment *> segments = this->mpdManager->getSegments(best);
for(int j = 0; j < segments.size(); j++)
{
this->schedule.push_back(segments.at(j));
}
}
}
}
}
/*
* AlwaysBestAdaptationLogic.h
*****************************************************************************
* Copyright (C) 2010 - 2011 Klagenfurt University
*
* Created on: Aug 10, 2010
* Authors: Christopher Mueller <christopher.mueller@itec.uni-klu.ac.at>
* Christian Timmerer <christian.timmerer@itec.uni-klu.ac.at>
*
* 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 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 ALWAYSBESTADAPTATIONLOGIC_H_
#define ALWAYSBESTADAPTATIONLOGIC_H_
#include "adaptationlogic/AbstractAdaptationLogic.h"
#include "http/Chunk.h"
#include "xml/Node.h"
#include "mpd/IMPDManager.h"
#include "mpd/Period.h"
#include "mpd/Segment.h"
#include "exceptions/EOFException.h"
#include "mpd/BasicCMManager.h"
#include "mpd/ISegment.h"
#include <vector>
namespace dash
{
namespace logic
{
class AlwaysBestAdaptationLogic : public AbstractAdaptationLogic
{
public:
AlwaysBestAdaptationLogic (dash::mpd::IMPDManager *mpdManager);
virtual ~AlwaysBestAdaptationLogic ();
dash::http::Chunk* getNextChunk () throw(dash::exception::EOFException);
private:
std::vector<dash::mpd::ISegment *> schedule;
dash::mpd::IMPDManager *mpdManager;
int count;
void initSchedule();
};
}
}
#endif /* ALWAYSBESTADAPTATIONLOGIC_H_ */
/*
* IAdaptationLogic.h
*****************************************************************************
* Copyright (C) 2010 - 2011 Klagenfurt University
*
* Created on: Aug 10, 2010
* Authors: Christopher Mueller <christopher.mueller@itec.uni-klu.ac.at>
* Christian Timmerer <christian.timmerer@itec.uni-klu.ac.at>
*
* 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 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 IADAPTATIONLOGIC_H_
#define IADAPTATIONLOGIC_H_
#include <http/Chunk.h>
#include <adaptationlogic/IDownloadRateObserver.h>
#include <exceptions/EOFException.h>
namespace dash
{
namespace logic
{
class IAdaptationLogic : public IDownloadRateObserver
{
public:
enum LogicType
{
Default,
AlwaysBest,
AlwaysLowest,
RateBased,
};
virtual dash::http::Chunk* getNextChunk() throw(dash::exception::EOFException) = 0;
};
}
}
#endif /* IADAPTATIONLOGIC_H_ */