Commit 6d18161d authored by François Cartegnie's avatar François Cartegnie 🤞

demux: adaptative: use SegmentChunk as default Chunk for segments

simplifies
parent 1f831316
...@@ -262,6 +262,8 @@ adaptative_SOURCES = \ ...@@ -262,6 +262,8 @@ adaptative_SOURCES = \
demux/adaptative/playlist/Segment.h \ demux/adaptative/playlist/Segment.h \
demux/adaptative/playlist/SegmentBase.cpp \ demux/adaptative/playlist/SegmentBase.cpp \
demux/adaptative/playlist/SegmentBase.h \ demux/adaptative/playlist/SegmentBase.h \
demux/adaptative/playlist/SegmentChunk.cpp \
demux/adaptative/playlist/SegmentChunk.hpp \
demux/adaptative/playlist/SegmentInfoCommon.cpp \ demux/adaptative/playlist/SegmentInfoCommon.cpp \
demux/adaptative/playlist/SegmentInfoCommon.h \ demux/adaptative/playlist/SegmentInfoCommon.h \
demux/adaptative/playlist/SegmentList.cpp \ demux/adaptative/playlist/SegmentList.cpp \
......
...@@ -54,7 +54,7 @@ void SegmentTracker::resetCounter() ...@@ -54,7 +54,7 @@ void SegmentTracker::resetCounter()
prevRepresentation = NULL; prevRepresentation = NULL;
} }
Chunk * SegmentTracker::getNextChunk(StreamType type, bool switch_allowed) SegmentChunk * SegmentTracker::getNextChunk(StreamType type, bool switch_allowed)
{ {
BaseRepresentation *rep; BaseRepresentation *rep;
ISegment *segment; ISegment *segment;
...@@ -101,7 +101,7 @@ Chunk * SegmentTracker::getNextChunk(StreamType type, bool switch_allowed) ...@@ -101,7 +101,7 @@ Chunk * SegmentTracker::getNextChunk(StreamType type, bool switch_allowed)
return getNextChunk(type, switch_allowed); return getNextChunk(type, switch_allowed);
} }
Chunk *chunk = segment->toChunk(count, rep); SegmentChunk *chunk = segment->toChunk(count, rep);
if(chunk) if(chunk)
count++; count++;
......
...@@ -34,21 +34,16 @@ namespace adaptative ...@@ -34,21 +34,16 @@ namespace adaptative
class AbstractAdaptationLogic; class AbstractAdaptationLogic;
} }
namespace http
{
class Chunk;
}
namespace playlist namespace playlist
{ {
class AbstractPlaylist; class AbstractPlaylist;
class BasePeriod; class BasePeriod;
class BaseRepresentation; class BaseRepresentation;
class SegmentChunk;
} }
using namespace playlist; using namespace playlist;
using namespace logic; using namespace logic;
using namespace http;
class SegmentTracker class SegmentTracker
{ {
...@@ -58,7 +53,7 @@ namespace adaptative ...@@ -58,7 +53,7 @@ namespace adaptative
void setAdaptationLogic(AbstractAdaptationLogic *); void setAdaptationLogic(AbstractAdaptationLogic *);
void resetCounter(); void resetCounter();
Chunk* getNextChunk(StreamType, bool); SegmentChunk* getNextChunk(StreamType, bool);
bool setPosition(mtime_t, bool, bool); bool setPosition(mtime_t, bool, bool);
mtime_t getSegmentStart() const; mtime_t getSegmentStart() const;
void pruneFromCurrent(); void pruneFromCurrent();
......
...@@ -21,8 +21,8 @@ ...@@ -21,8 +21,8 @@
#include "StreamsType.hpp" #include "StreamsType.hpp"
#include "http/HTTPConnection.hpp" #include "http/HTTPConnection.hpp"
#include "http/HTTPConnectionManager.h" #include "http/HTTPConnectionManager.h"
#include "http/Chunk.h"
#include "logic/AbstractAdaptationLogic.h" #include "logic/AbstractAdaptationLogic.h"
#include "playlist/SegmentChunk.hpp"
#include "SegmentTracker.hpp" #include "SegmentTracker.hpp"
#include <vlc_stream.h> #include <vlc_stream.h>
#include <vlc_demux.h> #include <vlc_demux.h>
...@@ -127,7 +127,7 @@ bool Stream::operator ==(const Stream &stream) const ...@@ -127,7 +127,7 @@ bool Stream::operator ==(const Stream &stream) const
return stream.type == type; return stream.type == type;
} }
Chunk * Stream::getChunk() SegmentChunk * Stream::getChunk()
{ {
if (currentChunk == NULL && output) if (currentChunk == NULL && output)
{ {
...@@ -165,7 +165,7 @@ Stream::status Stream::demux(HTTPConnectionManager *connManager, mtime_t nz_dead ...@@ -165,7 +165,7 @@ Stream::status Stream::demux(HTTPConnectionManager *connManager, mtime_t nz_dead
size_t Stream::read(HTTPConnectionManager *connManager) size_t Stream::read(HTTPConnectionManager *connManager)
{ {
Chunk *chunk = getChunk(); SegmentChunk *chunk = getChunk();
if(!chunk) if(!chunk)
return 0; return 0;
......
...@@ -38,7 +38,6 @@ namespace adaptative ...@@ -38,7 +38,6 @@ namespace adaptative
namespace http namespace http
{ {
class HTTPConnectionManager; class HTTPConnectionManager;
class Chunk;
} }
namespace logic namespace logic
...@@ -46,12 +45,18 @@ namespace adaptative ...@@ -46,12 +45,18 @@ namespace adaptative
class AbstractAdaptationLogic; class AbstractAdaptationLogic;
} }
namespace playlist
{
class SegmentChunk;
}
class AbstractStreamOutput; class AbstractStreamOutput;
class AbstractStreamOutputFactory; class AbstractStreamOutputFactory;
using namespace http; using namespace http;
using namespace logic; using namespace logic;
using namespace playlist;
class Stream class Stream
{ {
...@@ -76,7 +81,7 @@ namespace adaptative ...@@ -76,7 +81,7 @@ namespace adaptative
void prune(); void prune();
private: private:
Chunk *getChunk(); SegmentChunk *getChunk();
void init(const StreamType, const StreamFormat &); void init(const StreamType, const StreamFormat &);
size_t read(HTTPConnectionManager *); size_t read(HTTPConnectionManager *);
StreamType type; StreamType type;
...@@ -84,7 +89,7 @@ namespace adaptative ...@@ -84,7 +89,7 @@ namespace adaptative
AbstractStreamOutput *output; AbstractStreamOutput *output;
AbstractAdaptationLogic *adaptationLogic; AbstractAdaptationLogic *adaptationLogic;
SegmentTracker *segmentTracker; SegmentTracker *segmentTracker;
http::Chunk *currentChunk; SegmentChunk *currentChunk;
bool eof; bool eof;
}; };
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include "Segment.h" #include "Segment.h"
#include "BaseRepresentation.h" #include "BaseRepresentation.h"
#include "SegmentChunk.hpp"
#include <cassert> #include <cassert>
using namespace adaptative::http; using namespace adaptative::http;
...@@ -50,19 +51,19 @@ ISegment::~ISegment() ...@@ -50,19 +51,19 @@ ISegment::~ISegment()
assert(chunksuse.Get() == 0); assert(chunksuse.Get() == 0);
} }
Chunk * ISegment::getChunk(const std::string &url) SegmentChunk * ISegment::getChunk(const std::string &url)
{ {
return new (std::nothrow) SegmentChunk(this, url); return new (std::nothrow) SegmentChunk(this, url);
} }
void ISegment::onChunkDownload(block_t **, Chunk *, BaseRepresentation *) void ISegment::onChunkDownload(block_t **, SegmentChunk *, BaseRepresentation *)
{ {
} }
Chunk* ISegment::toChunk(size_t index, BaseRepresentation *ctxrep) SegmentChunk* ISegment::toChunk(size_t index, BaseRepresentation *ctxrep)
{ {
Chunk *chunk; SegmentChunk *chunk;
try try
{ {
chunk = getChunk(getUrlSegment().toString(index, ctxrep)); chunk = getChunk(getUrlSegment().toString(index, ctxrep));
...@@ -80,6 +81,8 @@ Chunk* ISegment::toChunk(size_t index, BaseRepresentation *ctxrep) ...@@ -80,6 +81,8 @@ Chunk* ISegment::toChunk(size_t index, BaseRepresentation *ctxrep)
chunk->setEndByte(endByte); chunk->setEndByte(endByte);
} }
chunk->setRepresentation(ctxrep);
return chunk; return chunk;
} }
...@@ -136,30 +139,6 @@ int ISegment::getClassId() const ...@@ -136,30 +139,6 @@ int ISegment::getClassId() const
return classId; return classId;
} }
ISegment::SegmentChunk::SegmentChunk(ISegment *segment_, const std::string &url) :
Chunk(url)
{
segment = segment_;
segment->chunksuse.Set(segment->chunksuse.Get() + 1);
rep = NULL;
}
ISegment::SegmentChunk::~SegmentChunk()
{
assert(segment->chunksuse.Get() > 0);
segment->chunksuse.Set(segment->chunksuse.Get() - 1);
}
void ISegment::SegmentChunk::setRepresentation(BaseRepresentation *rep_)
{
rep = rep_;
}
void ISegment::SegmentChunk::onDownload(block_t **pp_block)
{
segment->onChunkDownload(pp_block, this, rep);
}
Segment::Segment(ICanonicalUrl *parent) : Segment::Segment(ICanonicalUrl *parent) :
ISegment(parent) ISegment(parent)
{ {
...@@ -217,9 +196,9 @@ Url Segment::getUrlSegment() const ...@@ -217,9 +196,9 @@ Url Segment::getUrlSegment() const
} }
} }
Chunk* Segment::toChunk(size_t index, BaseRepresentation *ctxrep) SegmentChunk* Segment::toChunk(size_t index, BaseRepresentation *ctxrep)
{ {
Chunk *chunk = ISegment::toChunk(index, ctxrep); SegmentChunk *chunk = ISegment::toChunk(index, ctxrep);
if (chunk && ctxrep) if (chunk && ctxrep)
chunk->setBitrate(ctxrep->getBandwidth()); chunk->setBitrate(ctxrep->getBandwidth());
return chunk; return chunk;
......
...@@ -38,6 +38,7 @@ namespace adaptative ...@@ -38,6 +38,7 @@ namespace adaptative
{ {
class BaseRepresentation; class BaseRepresentation;
class SubSegment; class SubSegment;
class SegmentChunk;
using namespace http; using namespace http;
...@@ -51,7 +52,7 @@ namespace adaptative ...@@ -51,7 +52,7 @@ namespace adaptative
* That is basically true when using an Url, and false * That is basically true when using an Url, and false
* when using an UrlTemplate * when using an UrlTemplate
*/ */
virtual Chunk* toChunk (size_t, BaseRepresentation * = NULL); virtual SegmentChunk* toChunk (size_t, BaseRepresentation * = NULL);
virtual void setByteRange (size_t start, size_t end); virtual void setByteRange (size_t start, size_t end);
virtual size_t getOffset () const; virtual size_t getOffset () const;
virtual std::vector<ISegment*> subSegments () = 0; virtual std::vector<ISegment*> subSegments () = 0;
...@@ -65,6 +66,8 @@ namespace adaptative ...@@ -65,6 +66,8 @@ namespace adaptative
Property<unsigned> chunksuse; Property<unsigned> chunksuse;
static const int CLASSID_ISEGMENT = 0; static const int CLASSID_ISEGMENT = 0;
/* callbacks */
virtual void onChunkDownload (block_t **, SegmentChunk *, BaseRepresentation *);
protected: protected:
size_t startByte; size_t startByte;
...@@ -72,21 +75,7 @@ namespace adaptative ...@@ -72,21 +75,7 @@ namespace adaptative
std::string debugName; std::string debugName;
int classId; int classId;
class SegmentChunk : public Chunk virtual SegmentChunk * getChunk(const std::string &);
{
public:
SegmentChunk(ISegment *segment, const std::string &url);
virtual ~SegmentChunk();
void setRepresentation(BaseRepresentation *);
virtual void onDownload(block_t **); // reimpl
protected:
ISegment *segment;
BaseRepresentation *rep;
};
virtual Chunk * getChunk(const std::string &);
virtual void onChunkDownload(block_t **, Chunk *, BaseRepresentation *);
}; };
class Segment : public ISegment class Segment : public ISegment
...@@ -96,7 +85,7 @@ namespace adaptative ...@@ -96,7 +85,7 @@ namespace adaptative
~Segment(); ~Segment();
virtual void setSourceUrl( const std::string &url ); virtual void setSourceUrl( const std::string &url );
virtual Url getUrlSegment() const; /* impl */ virtual Url getUrlSegment() const; /* impl */
virtual Chunk* toChunk(size_t, BaseRepresentation * = NULL); virtual SegmentChunk* toChunk(size_t, BaseRepresentation * = NULL);
virtual std::vector<ISegment*> subSegments(); virtual std::vector<ISegment*> subSegments();
virtual void debug(vlc_object_t *,int = 0) const; virtual void debug(vlc_object_t *,int = 0) const;
virtual void addSubSegment(SubSegment *); virtual void addSubSegment(SubSegment *);
......
/*
* SegmentChunk.cpp
*****************************************************************************
* Copyright (C) 2014 - 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.
*****************************************************************************/
#include "SegmentChunk.hpp"
#include "Segment.h"
#include <cassert>
using namespace adaptative::playlist;
SegmentChunk::SegmentChunk(ISegment *segment_, const std::string &url) :
Chunk(url)
{
segment = segment_;
segment->chunksuse.Set(segment->chunksuse.Get() + 1);
rep = NULL;
}
SegmentChunk::~SegmentChunk()
{
assert(segment->chunksuse.Get() > 0);
segment->chunksuse.Set(segment->chunksuse.Get() - 1);
}
void SegmentChunk::setRepresentation(BaseRepresentation *rep_)
{
rep = rep_;
}
void SegmentChunk::onDownload(block_t **pp_block)
{
segment->onChunkDownload(pp_block, this, rep);
}
/*
* SegmentChunk.hpp
*****************************************************************************
* Copyright (C) 2014 - 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 SEGMENTCHUNK_HPP
#define SEGMENTCHUNK_HPP
#include <string>
#include "ICanonicalUrl.hpp"
#include "../http/Chunk.h"
namespace adaptative
{
namespace playlist
{
using namespace http;
class BaseRepresentation;
class ISegment;
class SegmentChunk : public Chunk
{
public:
SegmentChunk(ISegment *segment, const std::string &url);
virtual ~SegmentChunk();
void setRepresentation(BaseRepresentation *);
virtual void onDownload(block_t **); // reimpl
protected:
ISegment *segment;
BaseRepresentation *rep;
};
}
}
#endif // SEGMENTCHUNK_HPP
...@@ -29,8 +29,8 @@ ...@@ -29,8 +29,8 @@
#include "DASHSegment.h" #include "DASHSegment.h"
#include "../adaptative/playlist/BaseRepresentation.h" #include "../adaptative/playlist/BaseRepresentation.h"
#include "../mp4/AtomsReader.hpp" #include "../mp4/AtomsReader.hpp"
#include "../adaptative/http/Chunk.h"
#include "../adaptative/playlist/AbstractPlaylist.hpp" #include "../adaptative/playlist/AbstractPlaylist.hpp"
#include "../adaptative/playlist/SegmentChunk.hpp"
using namespace adaptative::playlist; using namespace adaptative::playlist;
using namespace dash::mpd; using namespace dash::mpd;
...@@ -41,14 +41,7 @@ DashIndexSegment::DashIndexSegment(ICanonicalUrl *parent) : ...@@ -41,14 +41,7 @@ DashIndexSegment::DashIndexSegment(ICanonicalUrl *parent) :
{ {
} }
Chunk* DashIndexSegment::toChunk(size_t index, BaseRepresentation *ctxrep) void DashIndexSegment::onChunkDownload(block_t **pp_block, SegmentChunk *, BaseRepresentation *rep)
{
SegmentChunk *chunk = dynamic_cast<SegmentChunk *>(Segment::toChunk(index, ctxrep));
chunk->setRepresentation(ctxrep);
return chunk;
}
void DashIndexSegment::onChunkDownload(block_t **pp_block, Chunk *, BaseRepresentation *rep)
{ {
if(!rep) if(!rep)
return; return;
......
...@@ -38,10 +38,9 @@ namespace dash ...@@ -38,10 +38,9 @@ namespace dash
{ {
public: public:
DashIndexSegment( ICanonicalUrl *parent ); DashIndexSegment( ICanonicalUrl *parent );
virtual Chunk* toChunk(size_t, BaseRepresentation * = NULL); //reimpl
protected: protected:
virtual void onChunkDownload(block_t **, Chunk *, BaseRepresentation *); //reimpl virtual void onChunkDownload(block_t **, SegmentChunk *, BaseRepresentation *); //reimpl
}; };
} }
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/ *****************************************************************************/
#include "HLSSegment.hpp" #include "HLSSegment.hpp"
#include "../adaptative/playlist/SegmentChunk.hpp"
#include <vlc_common.h> #include <vlc_common.h>
#include <vlc_block.h> #include <vlc_block.h>
...@@ -49,7 +50,7 @@ HLSSegment::~HLSSegment() ...@@ -49,7 +50,7 @@ HLSSegment::~HLSSegment()
#endif #endif
} }
void HLSSegment::onChunkDownload(block_t **pp_block, Chunk *chunk, BaseRepresentation *) void HLSSegment::onChunkDownload(block_t **pp_block, SegmentChunk *chunk, BaseRepresentation *)
{ {
block_t *p_block = *pp_block; block_t *p_block = *pp_block;
#ifdef HAVE_GCRYPT #ifdef HAVE_GCRYPT
......
...@@ -60,7 +60,7 @@ namespace hls ...@@ -60,7 +60,7 @@ namespace hls
virtual int compare(ISegment *) const; /* reimpl */ virtual int compare(ISegment *) const; /* reimpl */
protected: protected:
virtual void onChunkDownload(block_t **, Chunk *, BaseRepresentation *); /* reimpl */ virtual void onChunkDownload(block_t **, SegmentChunk *, BaseRepresentation *); /* reimpl */
uint64_t sequence; uint64_t sequence;
SegmentEncryption encryption; SegmentEncryption encryption;
......
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