Skip to content

Commit

Permalink
demux: adaptative: rework stream format setup
Browse files Browse the repository at this point in the history
  • Loading branch information
fcartegnie committed Jul 5, 2015
1 parent 9833215 commit bfdc2b6
Show file tree
Hide file tree
Showing 27 changed files with 336 additions and 81 deletions.
6 changes: 5 additions & 1 deletion modules/demux/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,8 @@ adaptative_SOURCES = \
demux/adaptative/PlaylistManager.h \
demux/adaptative/SegmentTracker.cpp \
demux/adaptative/SegmentTracker.hpp \
demux/adaptative/StreamFormat.cpp \
demux/adaptative/StreamFormat.hpp \
demux/adaptative/Streams.cpp \
demux/adaptative/Streams.hpp \
demux/adaptative/StreamsType.hpp \
Expand Down Expand Up @@ -343,7 +345,8 @@ libdash_plugin_la_SOURCES = \
demux/dash/dash.cpp \
demux/dash/dash.hpp \
demux/dash/DASHManager.cpp \
demux/dash/DASHManager.h
demux/dash/DASHManager.h \
demux/dash/DASHStreamFormat.hpp

libdash_plugin_la_SOURCES += $(adaptative_SOURCES)
libdash_plugin_la_SOURCES += demux/mp4/libmp4.c demux/mp4/libmp4.h
Expand All @@ -368,6 +371,7 @@ libhls_plugin_la_SOURCES = \
demux/hls/playlist/Tags.cpp \
demux/hls/HLSManager.hpp \
demux/hls/HLSManager.cpp \
demux/hls/HLSStreamFormat.hpp \
demux/hls/hls.cpp \
demux/hls/hls.hpp

Expand Down
12 changes: 6 additions & 6 deletions modules/demux/adaptative/PlaylistManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,13 @@ using namespace adaptative::logic;
using namespace adaptative;

PlaylistManager::PlaylistManager( AbstractPlaylist *pl,
AbstractStreamOutputFactory *factory,
AbstractAdaptationLogic::LogicType type,
stream_t *stream) :
conManager ( NULL ),
logicType ( type ),
playlist ( pl ),
streamOutputFactory( NULL ),
streamOutputFactory( factory ),
stream ( stream ),
nextPlaylistupdate ( 0 )
{
Expand All @@ -57,6 +58,7 @@ PlaylistManager::PlaylistManager( AbstractPlaylist *pl,
PlaylistManager::~PlaylistManager ()
{
delete conManager;
delete streamOutputFactory;
for(int i=0; i<StreamTypeCount; i++)
delete streams[i];
}
Expand All @@ -73,7 +75,7 @@ bool PlaylistManager::start(demux_t *demux)
const BaseAdaptationSet *set = period->getAdaptationSet(type);
if(set)
{
streams[type] = new (std::nothrow) Stream(set->getMimeType());
streams[type] = new (std::nothrow) Stream(type, set->getStreamFormat());
if(!streams[type])
continue;
AbstractAdaptationLogic *logic = createLogic(logicType);
Expand All @@ -85,13 +87,11 @@ bool PlaylistManager::start(demux_t *demux)
}

SegmentTracker *tracker = new (std::nothrow) SegmentTracker(logic, playlist);
DefaultStreamOutputFactory defaultfactory;
try
{
if(!tracker)
if(!tracker || !streamOutputFactory)
throw VLC_ENOMEM;
streams[type]->create(demux, logic, tracker,
(streamOutputFactory) ? *streamOutputFactory : defaultfactory );
streams[type]->create(demux, logic, tracker, streamOutputFactory);
} catch (int) {
delete streams[type];
delete logic;
Expand Down
5 changes: 4 additions & 1 deletion modules/demux/adaptative/PlaylistManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,15 @@ namespace adaptative
using namespace http;

class AbstractStreamFactory;
class AbstractStreamOutputFactory;

class PlaylistManager
{
public:
PlaylistManager( AbstractPlaylist *,
AbstractAdaptationLogic::LogicType type, stream_t *stream);
AbstractStreamOutputFactory *,
AbstractAdaptationLogic::LogicType type,
stream_t *stream);
virtual ~PlaylistManager ();

bool start(demux_t *);
Expand Down
42 changes: 42 additions & 0 deletions modules/demux/adaptative/StreamFormat.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* StreamFormat.cpp
*****************************************************************************
* Copyright (C) 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 "StreamFormat.hpp"

using namespace adaptative;

StreamFormat::operator unsigned() const
{
return formatid;
}

StreamFormat::StreamFormat( int formatid_ )
{
formatid = formatid_;
}

StreamFormat::~StreamFormat()
{

}

bool StreamFormat::operator ==(const StreamFormat &other) const
{
return formatid == other.formatid;
}
42 changes: 42 additions & 0 deletions modules/demux/adaptative/StreamFormat.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* StreamFormat.hpp
*****************************************************************************
* Copyright (C) 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 STREAMFORMAT_HPP
#define STREAMFORMAT_HPP

namespace adaptative
{

class StreamFormat
{
public:
static const unsigned UNSUPPORTED = 0;

StreamFormat( int = UNSUPPORTED );
~StreamFormat();
operator unsigned() const;
bool operator==(const StreamFormat &) const;

private:
unsigned formatid;
};

}

#endif // STREAMFORMAT_HPP
79 changes: 35 additions & 44 deletions modules/demux/adaptative/Streams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,12 @@ using namespace adaptative;
using namespace adaptative::http;
using namespace adaptative::logic;

Stream::Stream(const std::string &mime)
{
init(mimeToType(mime), mimeToFormat(mime));
}

Stream::Stream(const StreamType type, const StreamFormat format)
Stream::Stream(const StreamType type, const StreamFormat &format)
{
init(type, format);
}

void Stream::init(const StreamType type_, const StreamFormat format_)
void Stream::init(const StreamType type_, const StreamFormat &format_)
{
type = type_;
format = format_;
Expand Down Expand Up @@ -74,51 +69,56 @@ StreamType Stream::mimeToType(const std::string &mime)
return mimetype;
}

StreamFormat Stream::mimeToFormat(const std::string &mime)
{
StreamFormat format = StreamFormat::UNSUPPORTED;
std::string::size_type pos = mime.find("/");
if(pos != std::string::npos)
{
std::string tail = mime.substr(pos + 1);
if(tail == "mp4")
format = StreamFormat::MP4;
else if (tail == "mp2t")
format = StreamFormat::MPEG2TS;
}
return format;
}

void Stream::create(demux_t *demux, AbstractAdaptationLogic *logic,
SegmentTracker *tracker, AbstractStreamOutputFactory &factory)
SegmentTracker *tracker, const AbstractStreamOutputFactory *factory)
{
output = factory.create(demux, format);
updateFormat(demux, format, factory);
adaptationLogic = logic;
segmentTracker = tracker;
}

void Stream::updateFormat(demux_t *demux, StreamFormat &newformat, const AbstractStreamOutputFactory *factory)
{
if( format == newformat && output )
return;

delete output;
format = newformat;
output = factory->create(demux, format);
if(!output)
throw VLC_EGENERIC;
}

bool Stream::isEOF() const
{
return false;
}

mtime_t Stream::getPCR() const
{
if(!output)
return 0;
return output->getPCR();
}

mtime_t Stream::getFirstDTS() const
{
if(!output)
return 0;
return output->getFirstDTS();
}

int Stream::getGroup() const
{
if(!output)
return 0;
return output->getGroup();
}

int Stream::esCount() const
{
if(!output)
return 0;
return output->esCount();
}

Expand All @@ -129,7 +129,7 @@ bool Stream::operator ==(const Stream &stream) const

Chunk * Stream::getChunk()
{
if (currentChunk == NULL)
if (currentChunk == NULL && output)
{
currentChunk = segmentTracker->getNextChunk(type, output->switchAllowed());
if (currentChunk == NULL)
Expand All @@ -145,6 +145,9 @@ bool Stream::seekAble() const

Stream::status Stream::demux(HTTPConnectionManager *connManager, mtime_t nz_deadline, bool send)
{
if(!output)
return Stream::status_eof;

if(nz_deadline + VLC_TS_0 > output->getPCR()) /* not already demuxed */
{
/* need to read, demuxer still buffering, ... */
Expand Down Expand Up @@ -225,13 +228,19 @@ size_t Stream::read(HTTPConnectionManager *connManager)

readsize = block->i_buffer;

output->pushBlock(block);
if(output)
output->pushBlock(block);
else
block_Release(block);

return readsize;
}

bool Stream::setPosition(mtime_t time, bool tryonly)
{
if(!output)
return false;

bool ret = segmentTracker->setPosition(time, output->reinitsOnSeek(), tryonly);
if(!tryonly && ret)
{
Expand Down Expand Up @@ -623,21 +632,3 @@ void BaseStreamOutput::esOutDestroy(es_out_t *fakees)
me->realdemux->out->pf_destroy(me->realdemux->out);
}
/* !Static callbacks */

AbstractStreamOutput *DefaultStreamOutputFactory::create(demux_t *demux, int format) const
{
switch(format)
{
case StreamFormat::MP4:
return new BaseStreamOutput(demux, "mp4");

case StreamFormat::MPEG2TS:
return new BaseStreamOutput(demux, "ts");

default:
throw VLC_EBADVAR;
break;
}
return NULL;
}

19 changes: 7 additions & 12 deletions modules/demux/adaptative/Streams.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <vlc_common.h>
#include <vlc_es.h>
#include "StreamsType.hpp"
#include "StreamFormat.hpp"

namespace adaptative
{
Expand All @@ -55,14 +56,13 @@ namespace adaptative
class Stream
{
public:
Stream(const std::string &mime);
Stream(const StreamType, const StreamFormat);
Stream(const StreamType, const StreamFormat &);
~Stream();
bool operator==(const Stream &) const;
static StreamType mimeToType(const std::string &mime);
static StreamFormat mimeToFormat(const std::string &mime);
void create(demux_t *, AbstractAdaptationLogic *,
SegmentTracker *, AbstractStreamOutputFactory &);
SegmentTracker *, const AbstractStreamOutputFactory *);
void updateFormat(demux_t *, StreamFormat &, const AbstractStreamOutputFactory *);
bool isEOF() const;
mtime_t getPCR() const;
mtime_t getFirstDTS() const;
Expand All @@ -77,7 +77,7 @@ namespace adaptative

private:
Chunk *getChunk();
void init(const StreamType, const StreamFormat);
void init(const StreamType, const StreamFormat &);
size_t read(HTTPConnectionManager *);
StreamType type;
StreamFormat format;
Expand Down Expand Up @@ -114,13 +114,8 @@ namespace adaptative
class AbstractStreamOutputFactory
{
public:
virtual AbstractStreamOutput *create(demux_t*, int streamType) const = 0;
};

class DefaultStreamOutputFactory : public AbstractStreamOutputFactory
{
public:
virtual AbstractStreamOutput *create(demux_t*, int streamType) const;
virtual ~AbstractStreamOutputFactory() {}
virtual AbstractStreamOutput *create(demux_t*, const StreamFormat &) const = 0;
};

class BaseStreamOutput : public AbstractStreamOutput
Expand Down
7 changes: 0 additions & 7 deletions modules/demux/adaptative/StreamsType.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,6 @@ namespace adaptative
APPLICATION
};

enum StreamFormat
{
UNSUPPORTED = 0,
MP4,
MPEG2TS
};

static const int StreamTypeCount = APPLICATION + 1;

}
Expand Down
Loading

0 comments on commit bfdc2b6

Please sign in to comment.