Commit 5ada7fd6 authored by François Cartegnie's avatar François Cartegnie 🤞

demux: dash: split dash and adaptative specific code

also fixes includes, forward declarations
parent 6462aa5c
......@@ -245,37 +245,14 @@ demux_LTLIBRARIES += libts_plugin.la
endif
libdash_plugin_la_SOURCES = \
demux/dash/adaptationlogic/AbstractAdaptationLogic.cpp \
demux/dash/adaptationlogic/AbstractAdaptationLogic.h \
demux/dash/adaptationlogic/AdaptationLogicFactory.cpp \
demux/dash/adaptationlogic/AdaptationLogicFactory.h \
demux/dash/adaptationlogic/AlwaysBestAdaptationLogic.cpp \
demux/dash/adaptationlogic/AlwaysBestAdaptationLogic.h \
demux/dash/adaptationlogic/AlwaysLowestAdaptationLogic.cpp \
demux/dash/adaptationlogic/AlwaysLowestAdaptationLogic.hpp \
demux/dash/adaptationlogic/IDownloadRateObserver.h \
demux/dash/adaptationlogic/RateBasedAdaptationLogic.h \
demux/dash/adaptationlogic/RateBasedAdaptationLogic.cpp \
demux/dash/adaptationlogic/Representationselectors.hpp \
demux/dash/adaptationlogic/Representationselectors.cpp \
demux/dash/http/Chunk.cpp \
demux/dash/http/Chunk.h \
demux/dash/http/HTTPConnection.cpp \
demux/dash/http/HTTPConnection.h \
demux/dash/http/HTTPConnectionManager.cpp \
demux/dash/http/HTTPConnectionManager.h \
demux/dash/http/IHTTPConnection.cpp \
demux/dash/http/IHTTPConnection.h \
demux/dash/http/PersistentConnection.cpp \
demux/dash/http/PersistentConnection.h \
demux/dash/mpd/AdaptationSet.cpp \
demux/dash/mpd/AdaptationSet.h \
demux/dash/mpd/BaseUrl.h \
demux/dash/mpd/CommonAttributesElements.cpp \
demux/dash/mpd/CommonAttributesElements.h \
demux/dash/mpd/DASHCommonAttributesElements.cpp \
demux/dash/mpd/DASHCommonAttributesElements.h \
demux/dash/mpd/DASHSegment.cpp \
demux/dash/mpd/DASHSegment.h \
demux/dash/mpd/ContentDescription.cpp \
demux/dash/mpd/ContentDescription.h \
demux/dash/mpd/ICanonicalUrl.hpp \
demux/dash/mpd/IMPDParser.cpp \
demux/dash/mpd/IMPDParser.h \
demux/dash/mpd/IsoffMainParser.cpp \
......@@ -292,24 +269,8 @@ libdash_plugin_la_SOURCES = \
demux/dash/mpd/ProgramInformation.h \
demux/dash/mpd/Representation.cpp \
demux/dash/mpd/Representation.h \
demux/dash/mpd/Segment.cpp \
demux/dash/mpd/Segment.h \
demux/dash/mpd/SegmentBase.cpp \
demux/dash/mpd/SegmentBase.h \
demux/dash/mpd/SegmentInfoCommon.cpp \
demux/dash/mpd/SegmentInfoCommon.h \
demux/dash/mpd/SegmentInformation.cpp \
demux/dash/mpd/SegmentInformation.hpp \
demux/dash/mpd/SegmentList.cpp \
demux/dash/mpd/SegmentList.h \
demux/dash/mpd/SegmentTemplate.cpp \
demux/dash/mpd/SegmentTemplate.h \
demux/dash/mpd/SegmentTimeline.cpp \
demux/dash/mpd/SegmentTimeline.h \
demux/dash/mpd/TrickModeType.cpp \
demux/dash/mpd/TrickModeType.h \
demux/dash/mpd/Url.cpp \
demux/dash/mpd/Url.hpp \
demux/dash/mp4/AtomsReader.cpp \
demux/dash/mp4/AtomsReader.hpp \
demux/dash/xml/DOMHelper.cpp \
......@@ -321,15 +282,68 @@ libdash_plugin_la_SOURCES = \
demux/dash/dash.cpp \
demux/dash/dash.hpp \
demux/dash/DASHManager.cpp \
demux/dash/DASHManager.h \
demux/dash/Helper.cpp \
demux/dash/Helper.h \
demux/dash/Properties.hpp \
demux/dash/SegmentTracker.cpp \
demux/dash/SegmentTracker.hpp \
demux/dash/StreamsType.hpp \
demux/dash/Streams.cpp \
demux/dash/Streams.hpp
demux/dash/DASHManager.h
libdash_plugin_la_SOURCES += \
demux/adaptative/playlist/AbstractPlaylist.cpp \
demux/adaptative/playlist/AbstractPlaylist.hpp \
demux/adaptative/playlist/BaseAdaptationSet.cpp \
demux/adaptative/playlist/BaseAdaptationSet.h \
demux/adaptative/playlist/BasePeriod.cpp \
demux/adaptative/playlist/BasePeriod.h \
demux/adaptative/playlist/BaseRepresentation.cpp \
demux/adaptative/playlist/BaseRepresentation.h \
demux/adaptative/playlist/BaseUrl.h \
demux/adaptative/playlist/CommonAttributesElements.cpp \
demux/adaptative/playlist/CommonAttributesElements.h \
demux/adaptative/playlist/ICanonicalUrl.hpp \
demux/adaptative/playlist/Segment.cpp \
demux/adaptative/playlist/Segment.h \
demux/adaptative/playlist/SegmentBase.cpp \
demux/adaptative/playlist/SegmentBase.h \
demux/adaptative/playlist/SegmentInfoCommon.cpp \
demux/adaptative/playlist/SegmentInfoCommon.h \
demux/adaptative/playlist/SegmentList.cpp \
demux/adaptative/playlist/SegmentList.h \
demux/adaptative/playlist/SegmentTimeline.cpp \
demux/adaptative/playlist/SegmentTimeline.h \
demux/adaptative/playlist/SegmentInformation.cpp \
demux/adaptative/playlist/SegmentInformation.hpp \
demux/adaptative/playlist/SegmentTemplate.cpp \
demux/adaptative/playlist/SegmentTemplate.h \
demux/adaptative/playlist/Url.cpp \
demux/adaptative/playlist/Url.hpp \
demux/adaptative/logic/AbstractAdaptationLogic.cpp \
demux/adaptative/logic/AbstractAdaptationLogic.h \
demux/adaptative/logic/AlwaysBestAdaptationLogic.cpp \
demux/adaptative/logic/AlwaysBestAdaptationLogic.h \
demux/adaptative/logic/AlwaysLowestAdaptationLogic.cpp \
demux/adaptative/logic/AlwaysLowestAdaptationLogic.hpp \
demux/adaptative/logic/IDownloadRateObserver.h \
demux/adaptative/logic/RateBasedAdaptationLogic.h \
demux/adaptative/logic/RateBasedAdaptationLogic.cpp \
demux/adaptative/logic/Representationselectors.hpp \
demux/adaptative/logic/Representationselectors.cpp \
demux/adaptative/http/Chunk.cpp \
demux/adaptative/http/Chunk.h \
demux/adaptative/http/HTTPConnection.cpp \
demux/adaptative/http/HTTPConnection.h \
demux/adaptative/http/HTTPConnectionManager.cpp \
demux/adaptative/http/HTTPConnectionManager.h \
demux/adaptative/http/IHTTPConnection.cpp \
demux/adaptative/http/IHTTPConnection.h \
demux/adaptative/http/PersistentConnection.cpp \
demux/adaptative/http/PersistentConnection.h \
demux/adaptative/PlaylistManager.cpp \
demux/adaptative/PlaylistManager.h \
demux/adaptative/SegmentTracker.cpp \
demux/adaptative/SegmentTracker.hpp \
demux/adaptative/Streams.cpp \
demux/adaptative/Streams.hpp \
demux/adaptative/StreamsType.hpp \
demux/adaptative/tools/Helper.cpp \
demux/adaptative/tools/Helper.h \
demux/adaptative/tools/Properties.hpp
libdash_plugin_la_SOURCES += demux/mp4/libmp4.c demux/mp4/libmp4.h
......
/*
* PlaylistManager.cpp
*****************************************************************************
* Copyright © 2010 - 2011 Klagenfurt University
* 2015 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.
*****************************************************************************/
/* config.h may include inttypes.h, so make sure we define that option
* early enough. */
#define __STDC_FORMAT_MACROS
#define __STDC_CONSTANT_MACROS
#define __STDC_LIMIT_MACROS
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "PlaylistManager.h"
#include "SegmentTracker.hpp"
#include "playlist/AbstractPlaylist.hpp"
#include "playlist/BasePeriod.h"
#include "playlist/BaseAdaptationSet.h"
#include "http/HTTPConnectionManager.h"
#include "logic/AlwaysBestAdaptationLogic.h"
#include "logic/RateBasedAdaptationLogic.h"
#include "logic/AlwaysLowestAdaptationLogic.hpp"
#include <vlc_stream.h>
using namespace adaptative::http;
using namespace adaptative::logic;
using namespace adaptative;
PlaylistManager::PlaylistManager( AbstractPlaylist *pl,
AbstractAdaptationLogic::LogicType type,
stream_t *stream) :
conManager ( NULL ),
logicType ( type ),
playlist ( pl ),
stream ( stream ),
nextPlaylistupdate ( 0 )
{
for(int i=0; i<Streams::count; i++)
streams[i] = NULL;
}
PlaylistManager::~PlaylistManager ()
{
delete conManager;
for(int i=0; i<Streams::count; i++)
delete streams[i];
}
bool PlaylistManager::start(demux_t *demux)
{
const BasePeriod *period = playlist->getFirstPeriod();
if(!period)
return false;
for(int i=0; i<Streams::count; i++)
{
Streams::Type type = static_cast<Streams::Type>(i);
const BaseAdaptationSet *set = period->getAdaptationSet(type);
if(set)
{
streams[type] = new (std::nothrow) Streams::Stream(set->getMimeType());
if(!streams[type])
continue;
AbstractAdaptationLogic *logic = createLogic(logicType);
if(!logic)
{
delete streams[type];
streams[type] = NULL;
continue;
}
SegmentTracker *tracker = new (std::nothrow) SegmentTracker(logic, playlist);
try
{
if(!tracker)
throw VLC_ENOMEM;
streams[type]->create(demux, logic, tracker);
} catch (int) {
delete streams[type];
delete logic;
delete tracker;
streams[type] = NULL;
}
}
}
conManager = new (std::nothrow) HTTPConnectionManager(stream);
if(!conManager)
return false;
playlist->playbackStart.Set(time(NULL));
nextPlaylistupdate = playlist->playbackStart.Get();
return true;
}
size_t PlaylistManager::read()
{
size_t i_ret = 0;
for(int type=0; type<Streams::count; type++)
{
if(!streams[type])
continue;
i_ret += streams[type]->read(conManager);
}
return i_ret;
}
mtime_t PlaylistManager::getPCR() const
{
mtime_t pcr = VLC_TS_INVALID;
for(int type=0; type<Streams::count; type++)
{
if(!streams[type])
continue;
if(pcr == VLC_TS_INVALID || pcr > streams[type]->getPCR())
pcr = streams[type]->getPCR();
}
return pcr;
}
int PlaylistManager::getGroup() const
{
for(int type=0; type<Streams::count; type++)
{
if(!streams[type])
continue;
return streams[type]->getGroup();
}
return -1;
}
int PlaylistManager::esCount() const
{
int es = 0;
for(int type=0; type<Streams::count; type++)
{
if(!streams[type])
continue;
es += streams[type]->esCount();
}
return es;
}
mtime_t PlaylistManager::getDuration() const
{
if (playlist->isLive())
return 0;
else
return CLOCK_FREQ * playlist->duration.Get();
}
bool PlaylistManager::setPosition(mtime_t time)
{
bool ret = true;
for(int real = 0; real < 2; real++)
{
/* Always probe if we can seek first */
for(int type=0; type<Streams::count; type++)
{
if(!streams[type])
continue;
ret &= streams[type]->setPosition(time, !real);
}
if(!ret)
break;
}
return ret;
}
bool PlaylistManager::seekAble() const
{
if(playlist->isLive())
return false;
for(int type=0; type<Streams::count; type++)
{
if(!streams[type])
continue;
if(!streams[type]->seekAble())
return false;
}
return true;
}
bool PlaylistManager::updatePlaylist()
{
return true;
}
AbstractAdaptationLogic *PlaylistManager::createLogic(AbstractAdaptationLogic::LogicType type)
{
switch(type)
{
case AbstractAdaptationLogic::AlwaysBest:
return new (std::nothrow) AlwaysBestAdaptationLogic();
case AbstractAdaptationLogic::FixedRate:
case AbstractAdaptationLogic::AlwaysLowest:
return new (std::nothrow) AlwaysLowestAdaptationLogic();
case AbstractAdaptationLogic::Default:
case AbstractAdaptationLogic::RateBased:
return new (std::nothrow) RateBasedAdaptationLogic(0, 0);
default:
return NULL;
}
}
/*
* PlaylistManager.h
*****************************************************************************
* Copyright © 2010 - 2011 Klagenfurt University
* 2015 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 PLAYLISTMANAGER_H_
#define PLAYLISTMANAGER_H_
#include "logic/AbstractAdaptationLogic.h"
#include "Streams.hpp"
namespace adaptative
{
namespace playlist
{
class AbstractPlaylist;
}
namespace http
{
class HTTPConnectionManager;
}
using namespace playlist;
using namespace logic;
using namespace http;
class PlaylistManager
{
public:
PlaylistManager( AbstractPlaylist *,
AbstractAdaptationLogic::LogicType type, stream_t *stream);
virtual ~PlaylistManager ();
bool start (demux_t *);
size_t read();
mtime_t getDuration() const;
mtime_t getPCR() const;
int getGroup() const;
int esCount() const;
bool setPosition(mtime_t);
bool seekAble() const;
virtual bool updatePlaylist();
protected:
virtual AbstractAdaptationLogic *createLogic(AbstractAdaptationLogic::LogicType);
HTTPConnectionManager *conManager;
AbstractAdaptationLogic::LogicType logicType;
AbstractPlaylist *playlist;
stream_t *stream;
Streams::Stream *streams[Streams::count];
mtime_t nextPlaylistupdate;
};
}
#endif /* PLAYLISTMANAGER_H_ */
......@@ -18,21 +18,22 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#include "SegmentTracker.hpp"
#include "mpd/MPD.h"
#include "playlist/AbstractPlaylist.hpp"
#include "playlist/BaseRepresentation.h"
#include "logic/AbstractAdaptationLogic.h"
using namespace dash;
using namespace dash::logic;
using namespace dash::http;
using namespace dash::mpd;
using namespace adaptative;
using namespace adaptative::logic;
using namespace adaptative::playlist;
SegmentTracker::SegmentTracker(AbstractAdaptationLogic *logic_, mpd::MPD *mpd_)
SegmentTracker::SegmentTracker(AbstractAdaptationLogic *logic_, AbstractPlaylist *playlist_)
{
count = 0;
initializing = true;
prevRepresentation = NULL;
currentPeriod = mpd_->getFirstPeriod();
setAdaptationLogic(logic_);
mpd = mpd_;
playlist = playlist_;
currentPeriod = playlist->getFirstPeriod();
}
SegmentTracker::~SegmentTracker()
......@@ -53,7 +54,7 @@ void SegmentTracker::resetCounter()
Chunk * SegmentTracker::getNextChunk(Streams::Type type)
{
Representation *rep;
BaseRepresentation *rep;
ISegment *segment;
if(!currentPeriod)
......@@ -76,15 +77,15 @@ Chunk * SegmentTracker::getNextChunk(Streams::Type type)
if(initializing)
{
initializing = false;
segment = rep->getSegment(Representation::INFOTYPE_INIT);
segment = rep->getSegment(BaseRepresentation::INFOTYPE_INIT);
if(segment)
return segment->toChunk(count, rep);
}
segment = rep->getSegment(Representation::INFOTYPE_MEDIA, count);
segment = rep->getSegment(BaseRepresentation::INFOTYPE_MEDIA, count);
if(!segment)
{
currentPeriod = mpd->getNextPeriod(currentPeriod);
currentPeriod = playlist->getNextPeriod(currentPeriod);
resetCounter();
return getNextChunk(type);
}
......
......@@ -27,16 +27,8 @@
#include "StreamsType.hpp"
#include <vlc_common.h>
namespace dash
namespace adaptative
{
namespace mpd
{
class MPD;
class Period;
class Representation;
class Segment;
}
namespace logic
{
class AbstractAdaptationLogic;
......@@ -47,25 +39,36 @@ namespace dash
class Chunk;
}
namespace playlist
{
class AbstractPlaylist;
class BasePeriod;
class BaseRepresentation;
}
using namespace playlist;
using namespace logic;
using namespace http;
class SegmentTracker
{
public:
SegmentTracker(logic::AbstractAdaptationLogic *, mpd::MPD *);
SegmentTracker(AbstractAdaptationLogic *, AbstractPlaylist *);
~SegmentTracker();
void setAdaptationLogic(logic::AbstractAdaptationLogic *);
void setAdaptationLogic(AbstractAdaptationLogic *);
void resetCounter();
http::Chunk* getNextChunk(Streams::Type);
Chunk* getNextChunk(Streams::Type);
bool setPosition(mtime_t, bool);
mtime_t getSegmentStart() const;
private:
bool initializing;
uint64_t count;
logic::AbstractAdaptationLogic *logic;
mpd::MPD *mpd;
mpd::Period *currentPeriod;
mpd::Representation *prevRepresentation;
AbstractAdaptationLogic *logic;
AbstractPlaylist *playlist;
BasePeriod *currentPeriod;
BaseRepresentation *prevRepresentation;
};
}
......
......@@ -19,15 +19,20 @@
*****************************************************************************/
#define __STDC_CONSTANT_MACROS
#include "Streams.hpp"
#include "adaptationlogic/AbstractAdaptationLogic.h"
#include "adaptationlogic/AdaptationLogicFactory.h"
#include "StreamsType.hpp"
#include "http/HTTPConnection.h"
#include "http/HTTPConnectionManager.h"
#include "http/Chunk.h"
#include "logic/AbstractAdaptationLogic.h"
#include "SegmentTracker.hpp"
#include <vlc_stream.h>
#include <vlc_demux.h>
using namespace dash::Streams;
using namespace dash::http;
using namespace dash::logic;
using namespace adaptative::Streams;
using namespace adaptative::http;
using namespace adaptative::logic;
using namespace adaptative::Streams;
Stream::Stream(const std::string &mime)
{
......@@ -87,14 +92,14 @@ Format Stream::mimeToFormat(const std::string &mime)
return format;
}
void Stream::create(demux_t *demux, AbstractAdaptationLogic *logic, dash::SegmentTracker *tracker)
void Stream::create(demux_t *demux, AbstractAdaptationLogic *logic, SegmentTracker *tracker)
{
switch(format)
{
case dash::Streams::MP4:
case adaptative::Streams::MP4:
output = new MP4StreamOutput(demux);
break;
case dash::Streams::MPEG2TS:
case adaptative::Streams::MPEG2TS:
output = new MPEG2TSStreamOutput(demux);
break;
default:
......
......@@ -27,18 +27,29 @@
#include <string>
#include <vlc_common.h>
#include "StreamsType.hpp"
#include "adaptationlogic/AbstractAdaptationLogic.h"
#include "http/HTTPConnectionManager.h"
#include "http/Chunk.h"
namespace dash
namespace adaptative
{
class SegmentTracker;
namespace http
{
class HTTPConnectionManager;
class Chunk;
}
namespace logic
{
class AbstractAdaptationLogic;
}
namespace Streams
{
class AbstractStreamOutput;
using namespace http;
using namespace logic;
class Stream
{
public:
......@@ -48,23 +59,23 @@ namespace dash
bool operator==(const Stream &) const;
static Type mimeToType(const std::string &mime);
static Format mimeToFormat(const std::string &mime);
void create(demux_t *, logic::AbstractAdaptationLogic *, SegmentTracker *);
void create(demux_t *, AbstractAdaptationLogic *, SegmentTracker *);
bool isEOF() const;
mtime_t getPCR() const;
int getGroup() const;
int esCount() const;
bool seekAble() const;
size_t read(http::HTTPConnectionManager *);
size_t read(HTTPConnectionManager *);
bool setPosition(mtime_t, bool);
mtime_t getPosition() const;
private:
http::Chunk *getChunk();
Chunk *getChunk();
void init(const Type, const Format);
Type type;
Format format;
AbstractStreamOutput *output;
logic::AbstractAdaptationLogic *adaptationLogic;
AbstractAdaptationLogic *adaptationLogic;
SegmentTracker *segmentTracker;
http::Chunk *currentChunk;
bool eof;
......
......@@ -20,7 +20,7 @@
#ifndef STREAMSTYPE_HPP
#define STREAMSTYPE_HPP
namespace dash
namespace adaptative
{
namespace Streams
{
......
......@@ -27,7 +27,10 @@
#include "Chunk.h"
using namespace dash::http;
#include <vlc_common.h>
#include <vlc_url.h>
using namespace adaptative::http;
Chunk::Chunk (const std::string& url) :
startByte (0),
......