Commit 69361064 authored by Francois Cartegnie's avatar Francois Cartegnie

demux: adaptative: use streams vector instead of static array

parent 3258f429
...@@ -51,16 +51,16 @@ PlaylistManager::PlaylistManager( AbstractPlaylist *pl, ...@@ -51,16 +51,16 @@ PlaylistManager::PlaylistManager( AbstractPlaylist *pl,
stream ( stream ), stream ( stream ),
nextPlaylistupdate ( 0 ) nextPlaylistupdate ( 0 )
{ {
for(int i=0; i<StreamTypeCount; i++)
streams[i] = NULL;
} }
PlaylistManager::~PlaylistManager () PlaylistManager::~PlaylistManager ()
{ {
delete conManager; delete conManager;
delete streamOutputFactory; delete streamOutputFactory;
for(int i=0; i<StreamTypeCount; i++) std::vector<Stream *>::iterator it;
delete streams[i]; for(it=streams.begin(); it!=streams.end(); ++it)
delete *it;
streams.clear();
} }
bool PlaylistManager::start(demux_t *demux) bool PlaylistManager::start(demux_t *demux)
...@@ -75,14 +75,13 @@ bool PlaylistManager::start(demux_t *demux) ...@@ -75,14 +75,13 @@ bool PlaylistManager::start(demux_t *demux)
const BaseAdaptationSet *set = period->getAdaptationSet(type); const BaseAdaptationSet *set = period->getAdaptationSet(type);
if(set) if(set)
{ {
streams[type] = new (std::nothrow) Stream(demux, type, set->getStreamFormat()); Stream *st = new (std::nothrow) Stream(demux, type, set->getStreamFormat());
if(!streams[type]) if(!st)
continue; continue;
AbstractAdaptationLogic *logic = createLogic(logicType); AbstractAdaptationLogic *logic = createLogic(logicType);
if(!logic) if(!logic)
{ {
delete streams[type]; delete st;
streams[type] = NULL;
continue; continue;
} }
...@@ -90,13 +89,15 @@ bool PlaylistManager::start(demux_t *demux) ...@@ -90,13 +89,15 @@ bool PlaylistManager::start(demux_t *demux)
try try
{ {
if(!tracker || !streamOutputFactory) if(!tracker || !streamOutputFactory)
{
delete tracker;
delete logic;
throw VLC_ENOMEM; throw VLC_ENOMEM;
streams[type]->create(logic, tracker, streamOutputFactory); }
st->create(logic, tracker, streamOutputFactory);
streams.push_back(st);
} catch (int) { } catch (int) {
delete streams[type]; delete st;
delete logic;
delete tracker;
streams[type] = NULL;
} }
} }
} }
...@@ -115,13 +116,10 @@ Stream::status PlaylistManager::demux(mtime_t nzdeadline, bool send) ...@@ -115,13 +116,10 @@ Stream::status PlaylistManager::demux(mtime_t nzdeadline, bool send)
{ {
Stream::status i_return = Stream::status_eof; Stream::status i_return = Stream::status_eof;
for(int type=0; type<StreamTypeCount; type++) std::vector<Stream *>::iterator it;
for(it=streams.begin(); it!=streams.end(); ++it)
{ {
if(!streams[type]) Stream::status i_ret = (*it)->demux(conManager, nzdeadline, send);
continue;
Stream::status i_ret =
streams[type]->demux(conManager, nzdeadline, send);
if(i_ret == Stream::status_buffering) if(i_ret == Stream::status_buffering)
{ {
...@@ -140,12 +138,11 @@ Stream::status PlaylistManager::demux(mtime_t nzdeadline, bool send) ...@@ -140,12 +138,11 @@ Stream::status PlaylistManager::demux(mtime_t nzdeadline, bool send)
mtime_t PlaylistManager::getPCR() const mtime_t PlaylistManager::getPCR() const
{ {
mtime_t pcr = VLC_TS_INVALID; mtime_t pcr = VLC_TS_INVALID;
for(int type=0; type<StreamTypeCount; type++) std::vector<Stream *>::const_iterator it;
for(it=streams.begin(); it!=streams.end(); ++it)
{ {
if(!streams[type]) if(pcr == VLC_TS_INVALID || pcr > (*it)->getPCR())
continue; pcr = (*it)->getPCR();
if(pcr == VLC_TS_INVALID || pcr > streams[type]->getPCR())
pcr = streams[type]->getPCR();
} }
return pcr; return pcr;
} }
...@@ -153,23 +150,21 @@ mtime_t PlaylistManager::getPCR() const ...@@ -153,23 +150,21 @@ mtime_t PlaylistManager::getPCR() const
mtime_t PlaylistManager::getFirstDTS() const mtime_t PlaylistManager::getFirstDTS() const
{ {
mtime_t dts = VLC_TS_INVALID; mtime_t dts = VLC_TS_INVALID;
for(int type=0; type<StreamTypeCount; type++) std::vector<Stream *>::const_iterator it;
for(it=streams.begin(); it!=streams.end(); ++it)
{ {
if(!streams[type]) if(dts == VLC_TS_INVALID || dts > (*it)->getFirstDTS())
continue; dts = (*it)->getFirstDTS();
if(dts == VLC_TS_INVALID || dts > streams[type]->getFirstDTS())
dts = streams[type]->getFirstDTS();
} }
return dts; return dts;
} }
int PlaylistManager::getGroup() const int PlaylistManager::getGroup() const
{ {
for(int type=0; type<StreamTypeCount; type++) std::vector<Stream *>::const_iterator it;
for(it=streams.begin(); it!=streams.end(); ++it)
{ {
if(!streams[type]) return (*it)->getGroup();
continue;
return streams[type]->getGroup();
} }
return -1; return -1;
} }
...@@ -177,11 +172,10 @@ int PlaylistManager::getGroup() const ...@@ -177,11 +172,10 @@ int PlaylistManager::getGroup() const
int PlaylistManager::esCount() const int PlaylistManager::esCount() const
{ {
int es = 0; int es = 0;
for(int type=0; type<StreamTypeCount; type++) std::vector<Stream *>::const_iterator it;
for(it=streams.begin(); it!=streams.end(); ++it)
{ {
if(!streams[type]) es += (*it)->esCount();
continue;
es += streams[type]->esCount();
} }
return es; return es;
} }
...@@ -200,11 +194,10 @@ bool PlaylistManager::setPosition(mtime_t time) ...@@ -200,11 +194,10 @@ bool PlaylistManager::setPosition(mtime_t time)
for(int real = 0; real < 2; real++) for(int real = 0; real < 2; real++)
{ {
/* Always probe if we can seek first */ /* Always probe if we can seek first */
for(int type=0; type<StreamTypeCount; type++) std::vector<Stream *>::iterator it;
for(it=streams.begin(); it!=streams.end(); ++it)
{ {
if(!streams[type]) ret &= (*it)->setPosition(time, !real);
continue;
ret &= streams[type]->setPosition(time, !real);
} }
if(!ret) if(!ret)
break; break;
...@@ -217,11 +210,10 @@ bool PlaylistManager::seekAble() const ...@@ -217,11 +210,10 @@ bool PlaylistManager::seekAble() const
if(playlist->isLive()) if(playlist->isLive())
return false; return false;
for(int type=0; type<StreamTypeCount; type++) std::vector<Stream *>::const_iterator it;
for(it=streams.begin(); it!=streams.end(); ++it)
{ {
if(!streams[type]) if(!(*it)->seekAble())
continue;
if(!streams[type]->seekAble())
return false; return false;
} }
return true; return true;
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#include "logic/AbstractAdaptationLogic.h" #include "logic/AbstractAdaptationLogic.h"
#include "Streams.hpp" #include "Streams.hpp"
#include <vector>
namespace adaptative namespace adaptative
{ {
...@@ -74,7 +75,7 @@ namespace adaptative ...@@ -74,7 +75,7 @@ namespace adaptative
AbstractPlaylist *playlist; AbstractPlaylist *playlist;
AbstractStreamOutputFactory *streamOutputFactory; AbstractStreamOutputFactory *streamOutputFactory;
stream_t *stream; stream_t *stream;
Stream *streams[StreamTypeCount]; std::vector<Stream *> streams;
mtime_t nextPlaylistupdate; mtime_t nextPlaylistupdate;
}; };
......
...@@ -107,11 +107,10 @@ bool DASHManager::updatePlaylist() ...@@ -107,11 +107,10 @@ bool DASHManager::updatePlaylist()
} }
mtime_t minsegmentTime = 0; mtime_t minsegmentTime = 0;
for(int type=0; type<StreamTypeCount; type++) std::vector<Stream *>::iterator it;
for(it=streams.begin(); it!=streams.end(); it++)
{ {
if(!streams[type]) mtime_t segmentTime = (*it)->getPosition();
continue;
mtime_t segmentTime = streams[type]->getPosition();
if(!minsegmentTime || segmentTime < minsegmentTime) if(!minsegmentTime || segmentTime < minsegmentTime)
minsegmentTime = segmentTime; minsegmentTime = segmentTime;
} }
......
...@@ -121,11 +121,10 @@ bool HLSManager::updatePlaylist() ...@@ -121,11 +121,10 @@ bool HLSManager::updatePlaylist()
delete updatedplaylist; delete updatedplaylist;
/* pruning */ /* pruning */
for(int type=0; type<StreamTypeCount; type++) std::vector<Stream *>::iterator it;
for(it=streams.begin(); it!=streams.end(); ++it)
{ {
if(!streams[type]) (*it)->prune();
continue;
streams[type]->prune();
} }
} }
else else
......
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