Commit 6d18161d authored by Francois Cartegnie's avatar Francois Cartegnie

demux: adaptative: use SegmentChunk as default Chunk for segments

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