vlc | branch: master | Francois Cartegnie <[email protected]> | Sun Jul 19 16:38:00 2015 +0200| [69361064e9ab4d13d6e393ce5427701f2d8e5126] | committer: Francois Cartegnie
demux: adaptative: use streams vector instead of static array > http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=69361064e9ab4d13d6e393ce5427701f2d8e5126 --- modules/demux/adaptative/PlaylistManager.cpp | 82 ++++++++++++-------------- modules/demux/adaptative/PlaylistManager.h | 3 +- modules/demux/dash/DASHManager.cpp | 7 +-- modules/demux/hls/HLSManager.cpp | 7 +-- 4 files changed, 45 insertions(+), 54 deletions(-) diff --git a/modules/demux/adaptative/PlaylistManager.cpp b/modules/demux/adaptative/PlaylistManager.cpp index 6979925..6bba8db 100644 --- a/modules/demux/adaptative/PlaylistManager.cpp +++ b/modules/demux/adaptative/PlaylistManager.cpp @@ -51,16 +51,16 @@ PlaylistManager::PlaylistManager( AbstractPlaylist *pl, stream ( stream ), nextPlaylistupdate ( 0 ) { - for(int i=0; i<StreamTypeCount; i++) - streams[i] = NULL; } PlaylistManager::~PlaylistManager () { delete conManager; delete streamOutputFactory; - for(int i=0; i<StreamTypeCount; i++) - delete streams[i]; + std::vector<Stream *>::iterator it; + for(it=streams.begin(); it!=streams.end(); ++it) + delete *it; + streams.clear(); } bool PlaylistManager::start(demux_t *demux) @@ -75,14 +75,13 @@ bool PlaylistManager::start(demux_t *demux) const BaseAdaptationSet *set = period->getAdaptationSet(type); if(set) { - streams[type] = new (std::nothrow) Stream(demux, type, set->getStreamFormat()); - if(!streams[type]) + Stream *st = new (std::nothrow) Stream(demux, type, set->getStreamFormat()); + if(!st) continue; AbstractAdaptationLogic *logic = createLogic(logicType); if(!logic) { - delete streams[type]; - streams[type] = NULL; + delete st; continue; } @@ -90,13 +89,15 @@ bool PlaylistManager::start(demux_t *demux) try { if(!tracker || !streamOutputFactory) + { + delete tracker; + delete logic; throw VLC_ENOMEM; - streams[type]->create(logic, tracker, streamOutputFactory); + } + st->create(logic, tracker, streamOutputFactory); + streams.push_back(st); } catch (int) { - delete streams[type]; - delete logic; - delete tracker; - streams[type] = NULL; + delete st; } } } @@ -115,13 +116,10 @@ Stream::status PlaylistManager::demux(mtime_t nzdeadline, bool send) { 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]) - continue; - - Stream::status i_ret = - streams[type]->demux(conManager, nzdeadline, send); + Stream::status i_ret = (*it)->demux(conManager, nzdeadline, send); if(i_ret == Stream::status_buffering) { @@ -140,12 +138,11 @@ Stream::status PlaylistManager::demux(mtime_t nzdeadline, bool send) mtime_t PlaylistManager::getPCR() const { 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]) - continue; - if(pcr == VLC_TS_INVALID || pcr > streams[type]->getPCR()) - pcr = streams[type]->getPCR(); + if(pcr == VLC_TS_INVALID || pcr > (*it)->getPCR()) + pcr = (*it)->getPCR(); } return pcr; } @@ -153,23 +150,21 @@ mtime_t PlaylistManager::getPCR() const mtime_t PlaylistManager::getFirstDTS() const { 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]) - continue; - if(dts == VLC_TS_INVALID || dts > streams[type]->getFirstDTS()) - dts = streams[type]->getFirstDTS(); + if(dts == VLC_TS_INVALID || dts > (*it)->getFirstDTS()) + dts = (*it)->getFirstDTS(); } return dts; } 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]) - continue; - return streams[type]->getGroup(); + return (*it)->getGroup(); } return -1; } @@ -177,11 +172,10 @@ int PlaylistManager::getGroup() const int PlaylistManager::esCount() const { 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]) - continue; - es += streams[type]->esCount(); + es += (*it)->esCount(); } return es; } @@ -200,11 +194,10 @@ bool PlaylistManager::setPosition(mtime_t time) for(int real = 0; real < 2; real++) { /* 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]) - continue; - ret &= streams[type]->setPosition(time, !real); + ret &= (*it)->setPosition(time, !real); } if(!ret) break; @@ -217,11 +210,10 @@ bool PlaylistManager::seekAble() const if(playlist->isLive()) 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]) - continue; - if(!streams[type]->seekAble()) + if(!(*it)->seekAble()) return false; } return true; diff --git a/modules/demux/adaptative/PlaylistManager.h b/modules/demux/adaptative/PlaylistManager.h index 8281849..62e8d71 100644 --- a/modules/demux/adaptative/PlaylistManager.h +++ b/modules/demux/adaptative/PlaylistManager.h @@ -24,6 +24,7 @@ #include "logic/AbstractAdaptationLogic.h" #include "Streams.hpp" +#include <vector> namespace adaptative { @@ -74,7 +75,7 @@ namespace adaptative AbstractPlaylist *playlist; AbstractStreamOutputFactory *streamOutputFactory; stream_t *stream; - Stream *streams[StreamTypeCount]; + std::vector<Stream *> streams; mtime_t nextPlaylistupdate; }; diff --git a/modules/demux/dash/DASHManager.cpp b/modules/demux/dash/DASHManager.cpp index f894902..6188f9b 100644 --- a/modules/demux/dash/DASHManager.cpp +++ b/modules/demux/dash/DASHManager.cpp @@ -107,11 +107,10 @@ bool DASHManager::updatePlaylist() } 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]) - continue; - mtime_t segmentTime = streams[type]->getPosition(); + mtime_t segmentTime = (*it)->getPosition(); if(!minsegmentTime || segmentTime < minsegmentTime) minsegmentTime = segmentTime; } diff --git a/modules/demux/hls/HLSManager.cpp b/modules/demux/hls/HLSManager.cpp index a6e9b21..06f2d34 100644 --- a/modules/demux/hls/HLSManager.cpp +++ b/modules/demux/hls/HLSManager.cpp @@ -121,11 +121,10 @@ bool HLSManager::updatePlaylist() delete updatedplaylist; /* pruning */ - for(int type=0; type<StreamTypeCount; type++) + std::vector<Stream *>::iterator it; + for(it=streams.begin(); it!=streams.end(); ++it) { - if(!streams[type]) - continue; - streams[type]->prune(); + (*it)->prune(); } } else _______________________________________________ vlc-commits mailing list [email protected] https://mailman.videolan.org/listinfo/vlc-commits
